RISC-V: When to intialize PMP

I'm working on my senior design project researching security using Rust and RISC-V, which are both newer technologies (did I shoot myself in the foot? lol). The learning curve has been steep, but I am making progress slowly. Any insights are appreciated by this noob.

The riscv_rt crate offers two attributes #[entry] and #[pre_init]. My current goal is to setup my PMP (physical memory protection) registers, which will envelope the main function, then enter into my main function as user level privilege and never return. Does it makes sense to do this security setup in the runtime #[pre_init] and label the main function with #[entry]? The #[pre_init] is described in the doc as

to run code *before* `static` variables are initialized

It would look something like

#![no_std]
#![no_main]

extern crate panic_halt;

use riscv_rt::pre_init;
use riscv_rt::entry;

#[pre_init]
//code to intialize PMP registers

// use `main` as the entry point of this application
// `main` is not allowed to return
#[entry]
fn main() -> ! {
    // do something here
    loop { }
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.