diff options
author | dzwdz | 2022-04-14 12:19:51 +0200 |
---|---|---|
committer | dzwdz | 2022-04-14 12:19:51 +0200 |
commit | 2eead2f6eab2aa1fbc727ce28d9fa9a8e90a1eec (patch) | |
tree | d4bb0ae50e5f612a4fae67763414f72ea1a85b8a /src/kernel/arch | |
parent | dcb2ce6337f54a9821e3971976a07e767846e3c1 (diff) |
kernel: port init's `printf` implementation
Diffstat (limited to 'src/kernel/arch')
-rw-r--r-- | src/kernel/arch/generic.h | 4 | ||||
-rw-r--r-- | src/kernel/arch/i386/ata.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/i386/boot.c | 12 | ||||
-rw-r--r-- | src/kernel/arch/i386/interrupts/isr.c | 4 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/tty.c | 17 | ||||
-rw-r--r-- | src/kernel/arch/io.h | 29 |
6 files changed, 25 insertions, 43 deletions
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h index 84be937..f8dfe51 100644 --- a/src/kernel/arch/generic.h +++ b/src/kernel/arch/generic.h @@ -1,9 +1,9 @@ #pragma once #include <kernel/arch/i386/registers.h> -#include <kernel/arch/io.h> #include <shared/types.h> #include <stdbool.h> +#include <stdarg.h> // i have no idea where else to put it // some code assumes that it's a power of 2 @@ -37,3 +37,5 @@ void pagedir_switch(struct pagedir *); // return 0 on failure void *pagedir_virt2phys(struct pagedir *dir, const void __user *virt, bool user, bool writeable); + +int kprintf(const char *fmt, ...); diff --git a/src/kernel/arch/i386/ata.c b/src/kernel/arch/i386/ata.c index b546c07..56344e4 100644 --- a/src/kernel/arch/i386/ata.c +++ b/src/kernel/arch/i386/ata.c @@ -3,8 +3,6 @@ #include <kernel/panic.h> #include <stdbool.h> -#include <kernel/arch/io.h> - static struct { enum { DEV_UNKNOWN, diff --git a/src/kernel/arch/i386/boot.c b/src/kernel/arch/i386/boot.c index a2b4f01..a3716ee 100644 --- a/src/kernel/arch/i386/boot.c +++ b/src/kernel/arch/i386/boot.c @@ -8,24 +8,26 @@ #include <kernel/main.h> #include <kernel/panic.h> +void tty_init(void); // TODO put this in a header file + void kmain_early(struct multiboot_info *multiboot) { struct kmain_info info; // setup some basic stuff tty_init(); - tty_const("gdt..."); + kprintf("gdt..."); gdt_init(); - tty_const("idt..."); + kprintf("idt..."); idt_init(); - tty_const("irq..."); + kprintf("irq..."); irq_init(); - tty_const("ata..."); + kprintf("ata..."); ata_init(); { // find the init module struct multiboot_mod *module = &multiboot->mods[0]; if (multiboot->mods_count < 1) { - tty_const("can't find init! "); + kprintf("can't find init! "); panic_invalid_state(); // no init } info.init.at = module->start; diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c index 5bba43d..2d893cb 100644 --- a/src/kernel/arch/i386/interrupts/isr.c +++ b/src/kernel/arch/i386/interrupts/isr.c @@ -3,7 +3,7 @@ #include <kernel/arch/i386/interrupts/irq.h> #include <kernel/arch/i386/interrupts/isr.h> #include <kernel/arch/i386/port_io.h> -#include <kernel/arch/io.h> +#include <kernel/arch/generic.h> #include <kernel/panic.h> #include <kernel/proc.h> #include <stdbool.h> @@ -14,7 +14,7 @@ bool isr_test_interrupt_called = false; void isr_stage3(int interrupt) { switch (interrupt) { case 0x08: // double fault - tty_const("#DF"); + kprintf("#DF"); panic_invalid_state(); case 0x34: isr_test_interrupt_called = true; diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c index fa3ce72..d4a97fb 100644 --- a/src/kernel/arch/i386/tty/tty.c +++ b/src/kernel/arch/i386/tty/tty.c @@ -1,17 +1,26 @@ +#include <kernel/arch/generic.h> #include <kernel/arch/i386/driver/serial.h> #include <kernel/arch/i386/tty/vga.h> -#include <kernel/arch/io.h> +#include <shared/printf.h> void tty_init(void) { vga_clear(); serial_init(); - // write hearts - vga_write("\x03 ", 2); + vga_write("\x03 ", 2); // cp437 heart serial_write("<3 ", 3); } -void tty_write(const char *buf, size_t len) { +static void backend(void *arg, const char *buf, size_t len) { vga_write(buf, len); serial_write(buf, len); } + +int kprintf(const char *fmt, ...) { + int ret; + va_list argp; + va_start(argp, fmt); + ret = __printf_internal(fmt, argp, backend, NULL); + va_end(argp); + return ret; +} diff --git a/src/kernel/arch/io.h b/src/kernel/arch/io.h deleted file mode 100644 index ef8cb17..0000000 --- a/src/kernel/arch/io.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include <stddef.h> - -void tty_init(void); -void tty_write(const char *buf, size_t len); - -static inline void _tty_hex(const char *buf, size_t len) { - char hex[2]; - for (size_t i = 0; i < len; i++) { - hex[0] = (buf[i] & 0xF0) >> 4; - hex[0] += '0'; - if (hex[0] > '9') - hex[0] += 'a' - '9' - 1; - - hex[1] = buf[i] & 0xF; - hex[1] += '0'; - if (hex[1] > '9') - hex[1] += 'a' - '9' - 1; - - tty_write(hex, 2); - } -} - -// used for static strings -#define tty_const(str) tty_write(str, sizeof(str) - 1) - -// very hacky, shouldn't be actually used - only for debugging -// prints backwards -#define _tty_var(var) _tty_hex((void*)&var, sizeof(var)) |