What is the calling convention for a syscall in a program that runs under the RISC-V pseudo-kernel (pk) or Linux?
Looking at the code generated by the riscv-gnu-toolchain the rules seem to be:
- syscall number is passed in
a7
- syscall arguments are passed in
a0
toa5
- unused arguments are set to
0
- return value is returned in
a0
Is this it?
Is it really necessary to zero-out the unused arguments?
What about register a6
? Can this be used for yet another sycall argument?
Example that calls the exit()
syscall:
li a0, 1 # argument that is used by the syscall
li a1, 0 # unused arguments
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a7, 93 # exit syscall number