ABI for Ecall?

1,265 views
Skip to first unread message

poweihuang17

unread,
Jun 29, 2017, 11:47:31 AM6/29/17
to RISC-V SW Dev
Hi, 
Could I asked a question about ecall?
The latest spec said:
"The ECALL instruction is used to make a request to the supporting execution environment, which is usually an operating system. The ABI for the system will define how parameters for the environment request are passed, but usually these will be in defined locations in the integer register file."

So, is the so called "ABI for the system" referring to psABI doc?
Moreover, is the ecall used to implement syscalls in Linux? If so, could I get a example to know how ECALL is used in user level?

Sorry for the bothering, but there are very few description for ecall in the user level spec, which made me a little bit confused.

Best
Po-wei

Bruce Hoult

unread,
Jun 29, 2017, 12:04:13 PM6/29/17
to poweihuang17, RISC-V SW Dev
On Thu, Jun 29, 2017 at 6:47 PM, poweihuang17 <poweih...@gmail.com> wrote:
Hi, 
Could I asked a question about ecall?
The latest spec said:
"The ECALL instruction is used to make a request to the supporting execution environment, which is usually an operating system. The ABI for the system will define how parameters for the environment request are passed, but usually these will be in defined locations in the integer register file."

So, is the so called "ABI for the system" referring to psABI doc?

No. The processor specific ABI is about how functions call each other within a user problem .. or more exactly how functions from separately compiled object files/libraries call each other, as "static" functions can use a custom ABI if the compiler wants to.

The system call ABI is nothing to do with the hardware, or even the compiler usually. Most of the time system calls look to a compiler the same as function calls, and the called function does whatever is necessary to call the OS, and might be written in assembly language (or inline assembler).

There are advantages to having the syscall ABI resemble the function call ABI, but usually system calls are much simpler than function calls. For example, the linux kernel has no system calls that api floating point values directly as arguments, all arguments are exactly the size of one register/pointer, there are never more than seven (?) arguments etc. 
 
Moreover, is the ecall used to implement syscalls in Linux? If so, could I get a example to know how ECALL is used in user level?

Current Linux implementations on RISC-V pass arguments in a0-a6, just as for normal function calls, but in addition put the system call number in a7. There has been some discussion of instead putting the system call number in t1.

 
Sorry for the bothering, but there are very few description for ecall in the user level spec, which made me a little bit confused.

Because it has absolutely nothing to do with the user-level specification. :-)

Po-wei Huang

unread,
Jun 29, 2017, 1:06:25 PM6/29/17
to Bruce Hoult, RISC-V SW Dev
Hi Bruce,
Thanks for your help! After your guide, I went to riscv-linux and found the ecall. Thank you.
I left the information here for the followers to understand ecall better.
Best
Po-wei


——Information about ecall in riscv-linux.
The SBI_CALL is the only place I found that uses ecall. It uses a0-a6, and behaves just as Bruce said. 


#define SBI_CALL(which, arg0, arg1, arg2) ({ \
register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \
register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \
register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \
register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \
asm volatile ("ecall" \
: "+r" (a0) \
: "r" (a1), "r" (a2), "r" (a7) \
: "memory"); \
a0; \
})
Reply all
Reply to author
Forward
0 new messages