From d3afdd9284f7e9838fbde4c941193ec2032d6a26 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 19 Nov 2024 15:22:35 +0100 Subject: Check the return value from SBI ecalls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- include/fbos/compiler.h | 7 +++++++ include/fbos/sbi.h | 29 ++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/fbos/compiler.h b/include/fbos/compiler.h index 5e61ebd..35091c0 100644 --- a/include/fbos/compiler.h +++ b/include/fbos/compiler.h @@ -24,6 +24,13 @@ typedef unsigned long size_t; typedef unsigned long uint64_t; typedef unsigned long uintptr_t; +/* + * NULL + */ + +#define NULL (void *)0 +#define nullptr NULL + // Helpful macro when prototyping. #define __unused(x) (void)x diff --git a/include/fbos/sbi.h b/include/fbos/sbi.h index a6b893d..2575415 100644 --- a/include/fbos/sbi.h +++ b/include/fbos/sbi.h @@ -1,31 +1,38 @@ #ifndef __FBOS_SBI_H_ #define __FBOS_SBI_H_ -// TODO -/* SBI_SUCCESS 0 Completed successfully */ -/* SBI_ERR_FAILED -1 Failed */ -/* SBI_ERR_NOT_SUPPORTED -2 Not supported */ -/* SBI_ERR_INVALID_PARAM -3 Invalid parameter(s) */ -/* SBI_ERR_DENIED -4 Denied or not allowed */ -/* SBI_ERR_INVALID_ADDRESS -5 Invalid address(s) */ -/* SBI_ERR_ALREADY_AVAILABLE -6 Already available */ -/* SBI_ERR_ALREADY_STARTED -7 Already started */ -/* SBI_ERR_ALREADY_STOPPED -8 Already stopped */ -/* SBI_ERR_NO_SHMEM -9 Shared memory not available */ +// Possible values for `sbi_ret.error` as defined in the SBI Specification 2.0. +enum sbi_ret_error { + SBI_SUCCESS = 0, // Completed successfully + SBI_ERR_FAILED = -1, // Failed + SBI_ERR_NOT_SUPPORTED = -2, // Not supported + SBI_ERR_INVALID_PARAM = -3, // Invalid parameter(s) + SBI_ERR_DENIED = -4, // Denied or not allowed + SBI_ERR_INVALID_ADDRESS = -5, // Invalid address(s) + SBI_ERR_ALREADY_AVAILABLE = -6, // Already available + SBI_ERR_ALREADY_STARTED = -7, // Already started + SBI_ERR_ALREADY_STOPPED = -8, // Already stopped + SBI_ERR_NO_SHMEM = -9, // Shared memory not available +}; +// SBI extensions supported by this kernel. enum sbi_ext { DBCN_EXT = 0x4442434E, }; +// Function IDs for the Debug Console Extension "DBCN". enum dbcn_actions { DBCN_WRITE = 0x00, }; +// Return value for any SBI ecall. struct sbi_ret { long error; long value; }; +// Perform an SBI ecall. Never call this directly, use any of the macros as +// defined below. extern struct sbi_ret __sbi_ecall(unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, int fid, int ext); -- cgit v1.2.3