Syscall Help

I’ve got a user application running in u-mode with it’s stack frame protected by PMP.

PMP permissions:
pmp0cfg: 0x2004_0000 TOR RWX  //These values are before the bit shift 
pmp1cfg: 0x8000_2EE0 TOR RW
pmp2cfg: 0x8000_36E0 TOR RW

In user mode I call a syscall function (Rust)

let p1: usize = 22;
let p2: usize = 44;
unsafe{syscall(1,p1, p2)}

The only thing in the body of syscall() is inline assembly ecall
I figure the function call would put 1 into a0, p1 into a1, and p2 into a2 register where I could retrieve them from the trap_frame (where registers are saved on trap) to determine the syscall type and have a couple of parameters to use inside my trap handler.

However when I call my syscall function in u mode I get IllegalInstruction and the values of a0,a1,and a2 are all 0.

MTVAL = 0x30200073

mtval does not make sense to me, any ideas?

Oh, the mtval is the instruction itself for IllegalInstruction exception and is the address for address exceptions. The 0x30200073 makes more sense now

Machine Code
imm[11:0]    rs1  fn3   rd   opcode   

I think that is right, but I don’t see 1110011 opcode in the base instruction set table? Plus
The source and destination registers don’t make sense either…hmm

Hi DK,

That opcode (0x30200073) is for MRET which can only be executed in machine mode. Could you be executing it from user mode?

We have a small syscall example here that might help:

Hey Ralph, thanks for the clarification. I don’t call mret until the end of my trap handler (if user ecall) which it is in m-mode at that point. I will check out the example code and see if I can spot my error. Thanks

From that example, it looks like all it is doing is an ecall. I can simply ecall without issue, I’m trying to pass parameters along with the ecall in the a0…a[n] registers, that is what causes the problem.

Just wanted to come back and update this thread. This has been solved and was not a risc-v issue. I had a double dependency on a rust crate where the dependencies were of different versions. Once this was fixed, everything works as expected.