Skip to content

cortex-m-rt: consider enabling divide by zero trap by default #612

@jamesmunns

Description

@jamesmunns

In Cortex-M processors, (integer) divide by zero is not elevated to an exception/trap unless CCB->DIV_0_TRP is enabled, which is not the default setting. See https://developer.arm.com/documentation/100235/0004/the-cortex-m33-peripherals/system-control-block/configuration-and-control-register.

Instead, the result is undefined behavior/implementation defined. This is definitely surprising, if not unsound, under some expected behavior by Rust.

I'm not totally sure what happens on Cortex-M0/M0+ devices, or other devices without a hardware division unit.

We should probably set this bit in the cortex-m-rt init process (maybe toggled-off with an unsafe feature).

We might want to enable this to handle FFI or asm, but this is explicitly caught by Rust itself, rather than relying on the host to trap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions