Skip to content

riscv-rt: Pre initialization trap handling #156

@piegamesde

Description

@piegamesde

At the moment, the trap handler is initialized rather late in the boot procedure (it is more or less the last thing to happen before jumping to main). However, traps may happen before this, and they will not be handled appropriately (as far as I can tell, my CPU lands in a reset loop).

The most prominent situation in which this may happen is when I accidentally run the software compiled with multiplication instructions on a machine without them, because of these lines: https://github.com/rust-embedded/riscv-rt/blob/master/asm.S#L99-L110

I see multiple different approaches to improve the current situation:

  • Simply hardcode the non-mul branch in the asm.S. Since the factor against we are multiplying is rather low (it's the number of harts of the machine), the run time overhead shouldn't hit that hard.
  • Going one step further, I suggest compiling asm.S for the rv32i and rv64i targets only. Most of these extensions aren't needed anyways during initialization.
  • Alternatively, define a pre-Rust trap handler which is initialized first in _start. Once the Rust runtime is ready, default_setup_interrupts will override it to the actual implementation.

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