-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: Don't return any invalid error from SBI ecall
We should only return valid error codes from SBI ecalls as defined by the RISC-V SBI spec. To achieve this: 1. We use SBI_Exxxx defines for OpenSBI internal errors with error values starting from -1000 2. We use SBI_ERR_xxxx defines for errors defined by SBI spec 3. We map some of the SBI_Exxxx defines to SBI_ERR_xxxx defines which are semantically same 4. We throw a error print and force return error code to SBI_ERR_FAILED in sbi_ecall_handler() if we see an invalid error code being returned to S-mode Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
- Loading branch information
Showing
5 changed files
with
43 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* Anup Patel <[email protected]> | ||
*/ | ||
|
||
#include <sbi/sbi_console.h> | ||
#include <sbi/sbi_ecall.h> | ||
#include <sbi/sbi_ecall_interface.h> | ||
#include <sbi/sbi_error.h> | ||
|
@@ -124,6 +125,13 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs) | |
trap.epc = regs->mepc; | ||
sbi_trap_redirect(regs, &trap); | ||
} else { | ||
if (ret < SBI_LAST_ERR) { | ||
sbi_printf("%s: Invalid error %d for ext=0x%lx " | ||
"func=0x%lx\n", __func__, ret, | ||
extension_id, func_id); | ||
ret = SBI_ERR_FAILED; | ||
} | ||
|
||
/* | ||
* This function should return non-zero value only in case of | ||
* fatal error. However, there is no good way to distinguish | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters