From 5424397b47c2ad14fb227cdfe71d0d0b9e7f6286 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:39:41 +0200 Subject: [PATCH] debug kernel messages over virtual uart port in qemu use 'telnet localhost 12346' to listen --- Makefile.example | 2 +- arch/x86/include/asm/io.h | 2 +- drivers/char/stdio.c | 9 +++++---- include/metalsvm/config.h.example | 14 +++++++------- libkern/stdio.c | 18 ++++++++---------- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Makefile.example b/Makefile.example index 78c82edd..7745279a 100644 --- a/Makefile.example +++ b/Makefile.example @@ -96,7 +96,7 @@ $(NAME).elf: $Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf qemu: newlib tools $(NAME).elf - $(QEMU) -monitor stdio -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img + $(QEMU) -monitor stdio -serial tcp::12346,server -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img qemudbg: newlib tools $(NAME).elf $(QEMU) -s -S -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h index 0a97a187..fb997aae 100644 --- a/arch/x86/include/asm/io.h +++ b/arch/x86/include/asm/io.h @@ -102,7 +102,7 @@ inline static void outportl(unsigned short _port, unsigned int _data) inline static void uart_putchar(unsigned char _data) { - outportb(0x2F8, _data); + outportb(UART_PORT, _data); } /** diff --git a/drivers/char/stdio.c b/drivers/char/stdio.c index 35d6ddb5..54c309da 100644 --- a/drivers/char/stdio.c +++ b/drivers/char/stdio.c @@ -86,11 +86,12 @@ static ssize_t stdio_write(fildes_t* file, uint8_t* buffer, size_t size) for (i = 0; ioffset += size; diff --git a/include/metalsvm/config.h.example b/include/metalsvm/config.h.example index 299e1782..8a45f88d 100644 --- a/include/metalsvm/config.h.example +++ b/include/metalsvm/config.h.example @@ -34,14 +34,14 @@ extern "C" { #define PAGE_SHIFT 12 #define CACHE_LINE 64 #define MAILBOX_SIZE 32 -#define TIMER_FREQ 100 /* in HZ */ -#define CLOCK_TICK_RATE 1193182 /* 8254 chip's internal oscillator frequency */ +#define TIMER_FREQ 100 // in HZ +#define CLOCK_TICK_RATE 1193182 // 8254 chip's internal oscillator frequency #define INT_SYSCALL 0x80 #define KERNEL_SPACE (1*1024*1024*1024) -#define VIDEO_MEM_ADDR 0xB8000 // the video memora address +#define VIDEO_MEM_ADDR 0xB8000 // the video memory address #define SMP_SETUP_ADDR 0x07000 - -#define BYTE_ORDER LITTLE_ENDIAN +#define UART_PORT 0x3F8 // 0x2F8 for SCC +#define BYTE_ORDER LITTLE_ENDIAN /* * address space / (page_size * sizeof(uint8_t)) @@ -52,7 +52,7 @@ extern "C" { #define CONFIG_PCI #define CONFIG_LWIP #define CONFIG_VGA -//#define CONFIG_UART +#define CONFIG_UART #define CONFIG_KEYBOARD #define CONFIG_MULTIBOOT //#define CONFIG_ROCKCREEK @@ -72,7 +72,7 @@ extern "C" { //#define SHMADD #define SHMDBG //#define SHMADD_CACHEABLE -#define SCC_BOOTINFO 0x80000 +#define SCC_BOOTINFO 0x80000 #define BUILTIN_EXPECT(exp, b) __builtin_expect((exp), (b)) //#define BUILTIN_EXPECT(exp, b) (exp) diff --git a/libkern/stdio.c b/libkern/stdio.c index 10b09854..2d8ca43f 100644 --- a/libkern/stdio.c +++ b/libkern/stdio.c @@ -34,13 +34,7 @@ #define VGA_EARLY_PRINT 1 #define UART_EARLY_PRINT 2 -#ifdef CONFIG_VGA -static uint32_t early_print = VGA_EARLY_PRINT; -#elif defined(CONFIG_UART) -static uint32_t early_print = UART_EARLY_PRINT; -#else static uint32_t early_print = NO_EARLY_PRINT; -#endif static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT; static atomic_int32_t kmsg_counter = ATOMIC_INIT(0); static unsigned char kmessages[KMSG_SIZE] __attribute__ ((section(".kmsg"))) = {[0 ... KMSG_SIZE-1] = 0x00}; @@ -145,6 +139,10 @@ int koutput_init(void) { #ifdef CONFIG_VGA vga_init(); + early_print |= VGA_EARLY_PRINT; +#endif +#ifdef CONFIG_UART + early_print |= UART_EARLY_PRINT; #endif return 0; @@ -161,11 +159,11 @@ int kputchar(int c) kmessages[pos % KMSG_SIZE] = (unsigned char) c; #ifdef CONFIG_VGA - if (early_print == VGA_EARLY_PRINT) + if (early_print & VGA_EARLY_PRINT) vga_putchar(c); #endif #ifdef CONFIG_UART - if (early_print == UART_EARLY_PRINT) + if (early_print & UART_EARLY_PRINT) uart_putchar(c); #endif @@ -186,11 +184,11 @@ int kputs(const char *str) pos = atomic_int32_inc(&kmsg_counter); kmessages[pos % KMSG_SIZE] = str[i]; #ifdef CONFIG_VGA - if (early_print == VGA_EARLY_PRINT) + if (early_print & VGA_EARLY_PRINT) vga_putchar(str[i]); #endif #ifdef CONFIG_UART - if (early_print == UART_EARLY_PRINT) + if (early_print & UART_EARLY_PRINT) uart_putchar(str[i]); #endif }