ecall
Environment call
- Extension
- RV32I/RV64I base integer
- XLEN
- RV32 and RV64
- Assembly (riscv-unified-db)
ecall- Length
- 32-bit
Encoding
| 3120 | 197 | 62 | 10 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 000000000000 | 0000000000000 | 11100 | 11 | ||||||||||||||||||||||||||||
Match 0x00000073, mask 0xffffffff. Source: ecall 31..20=0x000 19..7=0 6..2=0x1C 1..0=3 in riscv-opcodes/extensions/rv_i.
Description
Makes a request to the supporting execution environment. When executed in U-mode, S-mode, or M-mode, it generates an environment-call-from-U-mode exception, environment-call-from-S-mode exception, or environment-call-from-M-mode exception, respectively, and performs no other operation.
Note: ECALL generates a different exception for each originating privilege mode so that environment call exceptions can be selectively delegated. A typical use case for Unix-like operating systems is to delegate to S-mode the environment-call-from-U-mode exception but not the others.
ECALL causes the receiving privilege mode's epc register to be set to the address of
the ECALL instruction itself, not the address of the following instruction.
As ECALL causes a synchronous exception, it is not considered to retire,
and should not increment the minstret CSR.
Description from riscv-unified-db, reformatted.
Operation
if (mode() == PrivilegeMode::M) {
if (TRAP_ON_ECALL_FROM_M) {
raise_precise(ExceptionCode::Mcall, PrivilegeMode::M, 0);
} else {
eei_ecall_from_m();
}
} else if (mode() == PrivilegeMode::S) {
if (TRAP_ON_ECALL_FROM_S) {
raise_precise(ExceptionCode::Scall, PrivilegeMode::S, 0);
} else {
eei_ecall_from_s();
}
} else if (mode() == PrivilegeMode::U || mode() == PrivilegeMode::VU) {
if (TRAP_ON_ECALL_FROM_U) {
raise_precise(ExceptionCode::Ucall, mode(), 0);
} else {
eei_ecall_from_u();
}
} else if (mode() == PrivilegeMode::VS) {
if (TRAP_ON_ECALL_FROM_VS) {
raise_precise(ExceptionCode::VScall, PrivilegeMode::VS, 0);
} else {
eei_ecall_from_vs();
}
}Pseudocode in riscv-unified-db’s IDL, quoted unchanged.