From 50e526d72f1fd9cb895d743a1353b54505b48025 Mon Sep 17 00:00:00 2001 From: Nathan Lee Date: Sun, 20 Sep 2026 21:12:49 -0500 Subject: add x86 support --- kernel/x86/kernel.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 kernel/x86/kernel.c (limited to 'kernel/x86/kernel.c') 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 +#include +#include + +#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); +} -- cgit v1.2.3