aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-19 15:22:35 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-19 15:22:35 +0100
commitd3afdd9284f7e9838fbde4c941193ec2032d6a26 (patch)
tree7213edfef8eb6b523642401772653cc46b7aa20f
parent52a4afca71aee5c150c6c63e7c1a510501fce6f3 (diff)
downloadfbos-d3afdd9284f7e9838fbde4c941193ec2032d6a26.tar.gz
fbos-d3afdd9284f7e9838fbde4c941193ec2032d6a26.zip
Check the return value from SBI ecalls
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rw-r--r--include/fbos/compiler.h7
-rw-r--r--include/fbos/sbi.h29
-rw-r--r--kernel/printk.c5
3 files changed, 29 insertions, 12 deletions
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);
diff --git a/kernel/printk.c b/kernel/printk.c
index c0eedd9..51c1a7a 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -19,5 +19,8 @@ void __kernel printk(const char *const message)
return;
}
- sbi_ecall2(DBCN_EXT, DBCN_WRITE, len, (unsigned long)message);
+ struct sbi_ret ret = sbi_ecall2(DBCN_EXT, DBCN_WRITE, len, (unsigned long)message);
+ if (ret.error != SBI_SUCCESS) {
+ die(nullptr);
+ }
}