From dcda5731ecbbce70edeaa7662e9ea0fc190a1943 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 22 Nov 2024 15:46:59 +0100 Subject: Enable the timer from the SBI interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A basic interrupt handler has been implemented which tracks the seconds that have been elapsing along the way. Depending on the value of these seconds, then a task has to be called. Signed-off-by: Miquel Sabaté Solà --- include/fbos/compiler.h | 2 ++ include/fbos/init.h | 9 +++++++++ include/fbos/sbi.h | 7 +++++++ 3 files changed, 18 insertions(+) (limited to 'include') diff --git a/include/fbos/compiler.h b/include/fbos/compiler.h index c26c05c..95596dd 100644 --- a/include/fbos/compiler.h +++ b/include/fbos/compiler.h @@ -6,6 +6,8 @@ */ #define __noreturn __attribute__((__noreturn__)) +#define __s_interrupt __attribute__((interrupt("supervisor"))) +#define __aligned(x) __attribute__((aligned(x))) /* * Compiler attributes specific to linker sections. diff --git a/include/fbos/init.h b/include/fbos/init.h index 978eebe..711d2cf 100644 --- a/include/fbos/init.h +++ b/include/fbos/init.h @@ -3,10 +3,19 @@ #include +// Tracks the amount of seconds that have elapsed since activating timer +// interrupts. +// +// Instantiated in kernel/trap.c, initialized in main.c. +extern uint64_t seconds_elapsed; + // Extract the executables from the initrd that is located at `base_addr` and // has the given `size`. void extract_initrd(const unsigned char *const base_addr, uint64_t size); +// Setup the interrupt vectors and the SBI timer. +void setup_interrupts(void); + // The entry point for the kernel. void start_kernel(void *dtb); diff --git a/include/fbos/sbi.h b/include/fbos/sbi.h index 2575415..b1c99ea 100644 --- a/include/fbos/sbi.h +++ b/include/fbos/sbi.h @@ -18,6 +18,7 @@ enum sbi_ret_error { // SBI extensions supported by this kernel. enum sbi_ext { DBCN_EXT = 0x4442434E, + TIME_EXT = 0x54494D45, }; // Function IDs for the Debug Console Extension "DBCN". @@ -25,6 +26,11 @@ enum dbcn_actions { DBCN_WRITE = 0x00, }; +// Function IDs for the Timer Extension "TIME". +enum time_actions { + TIME_SET_TIMER = 0x00, +}; + // Return value for any SBI ecall. struct sbi_ret { long error; @@ -37,6 +43,7 @@ extern struct sbi_ret __sbi_ecall(unsigned long arg0, unsigned long arg1, unsign unsigned long arg3, unsigned long arg4, unsigned long arg5, int fid, int ext); +#define sbi_ecall1(ext, fid, arg0) __sbi_ecall(arg0, 0, 0, 0, 0, 0, fid, ext) #define sbi_ecall2(ext, fid, arg0, arg1) __sbi_ecall(arg0, arg1, 0, 0, 0, 0, fid, ext) #endif // __FBOS_SBI_H_ -- cgit v1.2.3