summaryrefslogtreecommitdiff
path: root/kernel/x86/kernel.c
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-09-20 21:12:49 -0500
committerNathan Lee <me@nwlee.tech>2026-09-20 21:12:49 -0500
commit50e526d72f1fd9cb895d743a1353b54505b48025 (patch)
tree3442b2bd7b3b6ba6db3d972f89cf575ce1201278 /kernel/x86/kernel.c
parent09be8ace254a7f8bb69542d09a6b2013636123a2 (diff)
add x86 supportHEADmaster
Diffstat (limited to 'kernel/x86/kernel.c')
-rw-r--r--kernel/x86/kernel.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/kernel/x86/kernel.c b/kernel/x86/kernel.c
new file mode 100644
index 0000000..296d966
--- /dev/null
+++ b/kernel/x86/kernel.c
@@ -0,0 +1,30 @@
+#include <sys/stddef.h>
+#include <early/uart.h>
+#include <sys/log.h>
+
+#define COM1_PORT 0x3F8
+
+void serial_init(void) {
+ outb(COM1_PORT + 1, 0x00); // Disable interrupts
+ outb(COM1_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ outb(COM1_PORT + 0, 0x01); // Set divisor to 1 (lo byte) -> 115200 baud
+ outb(COM1_PORT + 1, 0x00); // (hi byte)
+ outb(COM1_PORT + 3, 0x03); // 8 bits, no parity, one stop bit
+ outb(COM1_PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
+ outb(COM1_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
+}
+
+static int serial_tx_ready(void) {
+ return inb(COM1_PORT + 5) & 0x20;
+}
+
+void serial_putchar(char c) {
+ while (serial_tx_ready() == 0);
+ outb(COM1_PORT, c);
+}
+
+void kernel_main(void) {
+ serial_init();
+ register_console_callback(serial_putchar);
+ printk("wkern version %s (Compiler %s, Linker %s) on %s\n", VERSION, COMPILER_NAME, LINKER_NAME, ARCH_NAME);
+}