rustsbi / rustsbi-k210

Kendryte K210 SBI support using RustSBI, provides privileged spec 1.12 environment by emulating it using 1.9.1
36 stars 12 forks source link

Forward MSI/MTI to supervisor priv. #1

Closed wyfcyx closed 3 years ago

wyfcyx commented 3 years ago

Added two new types of machine traps:

Now the runtime is able to yield them:

impl Generator for Runtime {
            ...
            Trap::Interrupt(Interrupt::MachineTimer) => MachineTrap::MachineTimer(),
            Trap::Interrupt(Interrupt::MachineSoft) => MachineTrap::MachineSoft(),
            ...
}

When they are matched in two added arms in execute::execute_supervisor, two functions will be called:

            GeneratorState::Yielded(MachineTrap::MachineTimer()) => {
                feature::forward_supervisor_timer()
            },
            GeneratorState::Yielded(MachineTrap::MachineSoft()) => {
                feature::forward_supervisor_soft()
            },

You can find their implementation(I just copied & pasted legacy code) below:

// feature/supervisor_interrupt.rs

pub fn forward_supervisor_timer() {
    // Forward to S-level timer interrupt
    unsafe {
        mip::set_stimer(); // set S-timer interrupt flag
        mie::clear_mext(); // Ref: rustsbi Pull request #5
        mie::clear_mtimer(); // mask M-timer interrupt
    }
}
pub fn forward_supervisor_soft() {
    // Forward to S-level software interrupt
    unsafe {
        mip::set_ssoft(); // set S-soft interrupt flag
        mie::clear_msoft(); // mask M-soft interrupt
    }
}

The timer has passed the test in rCore-Tutorial-v3 while the soft has not been tested due to the lack of the SMP execution environment, I will apply myself to check it later.

luojia65 commented 3 years ago

Nice!