From 195336fd535170200b6a38c9d5e71848dab3c72a Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Thu, 5 Feb 2026 17:47:02 -0300 Subject: [PATCH] hal: add system reboot abstraction and route shell reboot through HAL --- include/hal/system.h | 6 ++++++ src/hal/arm/system.c | 4 ++++ src/hal/mips/system.c | 4 ++++ src/hal/riscv/system.c | 4 ++++ src/hal/x86/system.c | 15 +++++++++++++++ src/kernel/shell.c | 6 +++--- 6 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 include/hal/system.h create mode 100644 src/hal/arm/system.c create mode 100644 src/hal/mips/system.c create mode 100644 src/hal/riscv/system.c create mode 100644 src/hal/x86/system.c diff --git a/include/hal/system.h b/include/hal/system.h new file mode 100644 index 0000000..18b1c4b --- /dev/null +++ b/include/hal/system.h @@ -0,0 +1,6 @@ +#ifndef HAL_SYSTEM_H +#define HAL_SYSTEM_H + +void hal_system_reboot(void); + +#endif diff --git a/src/hal/arm/system.c b/src/hal/arm/system.c new file mode 100644 index 0000000..abfdb09 --- /dev/null +++ b/src/hal/arm/system.c @@ -0,0 +1,4 @@ +#include "hal/system.h" + +void hal_system_reboot(void) { +} diff --git a/src/hal/mips/system.c b/src/hal/mips/system.c new file mode 100644 index 0000000..abfdb09 --- /dev/null +++ b/src/hal/mips/system.c @@ -0,0 +1,4 @@ +#include "hal/system.h" + +void hal_system_reboot(void) { +} diff --git a/src/hal/riscv/system.c b/src/hal/riscv/system.c new file mode 100644 index 0000000..abfdb09 --- /dev/null +++ b/src/hal/riscv/system.c @@ -0,0 +1,4 @@ +#include "hal/system.h" + +void hal_system_reboot(void) { +} diff --git a/src/hal/x86/system.c b/src/hal/x86/system.c new file mode 100644 index 0000000..c6fe056 --- /dev/null +++ b/src/hal/x86/system.c @@ -0,0 +1,15 @@ +#include "hal/system.h" + +#if defined(__i386__) || defined(__x86_64__) +#include "io.h" +#include + +void hal_system_reboot(void) { + uint8_t good = 0x02; + while (good & 0x02) good = inb(0x64); + outb(0x64, 0xFE); +} +#else +void hal_system_reboot(void) { +} +#endif diff --git a/src/kernel/shell.c b/src/kernel/shell.c index acabec1..c710020 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -8,6 +8,8 @@ #include "fs.h" #include "heap.h" +#include "hal/system.h" + #define MAX_CMD_LEN 256 static char cmd_buffer[MAX_CMD_LEN]; static int cmd_index = 0; @@ -80,9 +82,7 @@ void execute_command(char* cmd) { int a = 1; int b = 0; int c = a / b; (void)c; } else if (strcmp(cmd, "reboot") == 0) { - uint8_t good = 0x02; - while (good & 0x02) good = inb(0x64); - outb(0x64, 0xFE); + hal_system_reboot(); } else if (strlen(cmd) > 0) { uart_print("Unknown command: "); -- 2.43.0