aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-01-01 08:37:35 -0500
committerRaghuram Subramani <raghus2247@gmail.com>2025-01-01 08:40:22 -0500
commitaed2678d037042065d29fc1df9484220ece2474f (patch)
treeccfde86fa3914146f63c99655308655a492351e4
parent54b3a60e84a6f4e2e664a75ba2782fada0967d58 (diff)
kernel: Add exit()
exit() uses a sketchy device (-isa-debug-exit) to shut down QEMU. It's better than manually shutting it down though :)
-rw-r--r--CMakeLists.txt6
-rw-r--r--kernel/include/kernel/halt.h1
-rw-r--r--kernel/kernel/halt.c7
-rw-r--r--kernel/kernel/kernel.c5
4 files changed, 18 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d07656d..b6b402e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,8 +15,11 @@ set(QEMU_SYSTEM_CMD qemu-system-i386)
set(QEMU_ARGUMENTS
-cdrom ${CMAKE_BINARY_DIR}/cmos.iso
-serial stdio
+ -device isa-debug-exit,iobase=0xf4,iosize=0x04
)
+set(IGNORE_EXIT || true)
+
add_custom_target(iso
rm -rf ${CMAKE_BINARY_DIR}/iso &&
mkdir -p ${CMAKE_BINARY_DIR}/iso/boot/grub &&
@@ -30,6 +33,7 @@ add_custom_target(iso
add_custom_target(run
${QEMU_SYSTEM_CMD}
${QEMU_ARGUMENTS}
+ ${IGNORE_EXIT}
DEPENDS iso
USES_TERMINAL
@@ -41,6 +45,8 @@ add_custom_target(run-gdb
-s
-S
+ ${IGNORE_EXIT}
+
DEPENDS iso
USES_TERMINAL
)
diff --git a/kernel/include/kernel/halt.h b/kernel/include/kernel/halt.h
index 901f807..e12dc86 100644
--- a/kernel/include/kernel/halt.h
+++ b/kernel/include/kernel/halt.h
@@ -20,5 +20,6 @@
#define __kernel_halt_h
void halt(void);
+void exit(void);
#endif
diff --git a/kernel/kernel/halt.c b/kernel/kernel/halt.c
index 96bb62c..e69040c 100644
--- a/kernel/kernel/halt.c
+++ b/kernel/kernel/halt.c
@@ -19,6 +19,7 @@
#include <libk/io.h>
#include <kernel/halt.h>
+#include <kernel/io.h>
void
halt(void)
@@ -28,3 +29,9 @@ halt(void)
for (;;)
;
}
+
+void
+exit(void)
+{
+ outb(0xf4, 0x1);
+}
diff --git a/kernel/kernel/kernel.c b/kernel/kernel/kernel.c
index 52e9b6e..046d008 100644
--- a/kernel/kernel/kernel.c
+++ b/kernel/kernel/kernel.c
@@ -17,6 +17,7 @@
*/
#include <kernel/halt.h>
+
#include <libk/io.h>
#include <drivers/serial.h>
@@ -29,5 +30,7 @@ kernel_main(void)
serial_initialize();
printk("kernel_main", "Started.");
- halt();
+
+ exit();
+ halt(); /* If exit() fails (on real hardware) */
}