From 2eead2f6eab2aa1fbc727ce28d9fa9a8e90a1eec Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 14 Apr 2022 12:19:51 +0200 Subject: kernel: port init's `printf` implementation --- src/kernel/arch/i386/ata.c | 2 -- src/kernel/arch/i386/boot.c | 12 +++++++----- src/kernel/arch/i386/interrupts/isr.c | 4 ++-- src/kernel/arch/i386/tty/tty.c | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src/kernel/arch/i386') 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 #include -#include - 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 #include +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 #include #include -#include +#include #include #include #include @@ -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 #include #include -#include +#include 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; +} -- cgit v1.2.3