rust-embedded / riscv

Low level access to RISC-V processors
841 stars 162 forks source link

asm: set unsafety of `nop` and `delay` functions to safe #141

Closed luojia65 closed 1 year ago

luojia65 commented 1 year ago

The NOP instruction does not change architecturally visible state, including operations that would break memory safety boundaries; thus nop instruction wrapper should be safe to call. The delay function uses ADDI and BNE instructions which would form a function internal loop, which is safe under Rust constraints.

This pull request also includes an explanation on NOP instruction under Rust docs, and a small codestyle fix in Cargo.toml file.

I modified internal macro instruction to allow wrapping instruction with safe functions. If it's inappropriate, please reply and I'll change to other ways of implementation.