RISC-V atomic emulation trap handler
A replacement trap handler to emulate the atomic extension on silicon that does not have it. To be used in conjunction with the riscv-rt
crate.
We need to tell the Rust compiler to enable atomic code generation. We can achieve this by either setting some rustflags
, like so
```toml rustflags = [
"-C", "target-feature=+a",
"--cfg", 'targethasatomic="8"', "--cfg", 'targethasatomic="16"', "--cfg", 'targethasatomic="32"', "--cfg", 'targethasatomic="ptr"', ] ```
or it is also possible to compile for a similiar target that has the atomic extension enabled. For example, a riscv32imc
could use the riscv32imac
target.
Finally, include this line in main.rs
rust
use riscv_atomic_emulation_trap as _;
The final binary will have (atomic) instructions that the hardware does not support; when the hardware finds on of these instructions it will trap, this is where this crate comes in.
This crate overrides the default trap handler of the riscv-rt
crate. By doing so it is possible to decode the instruction, check if is an instruction we can emulate,
emulate it, and finally move the pc (program counter) forward to continue on with the program. Any instructions that cannot be emulated will be reported to the
users exception handler.
Advantages of this crate
Disadvantages of this crate