[−][src]Function rustsbi::ecall
pub fn ecall(extension: usize, function: usize, param: [usize; 4]) -> SbiRet
Supervisor environment call handler function
You should call this function in your runtime's exception handler.
If the incoming exception is caused by supervisor ecall
,
call this function with parameters extracted from trap frame.
After this function returns, store the return value into a0
and a1
parameters.
This function also adapts to the legacy functions.
If the supervisor called any of legacy function, the a0
and a1
parameter
is transferred to SbiRet
's error and value respectively.
So you should store the result into a0
and a1
in any function calls including legacy functions.
Example
A typical usage:
#[exception] fn handle_exception(ctx: &mut TrapFrame) { if mcause::read().cause() == Trap::Exception(Exception::SupervisorEnvCall) { let params = [ctx.a0, ctx.a1, ctx.a2, ctx.a3]; let ans = rustsbi::ecall(ctx.a7, ctx.a6, params); ctx.a0 = ans.error; ctx.a1 = ans.value; mepc::write(mepc::read().wrapping_add(4)); } // other conditions.. }
Do not forget to advance mepc
by 4 after an ecall is handled.
This skips the ecall
instruction itself which is 4-byte long in all conditions.