From 50e4e842d87975295f0b4cc9989cca9372a439e8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 22 Sep 2013 19:09:42 +0800 Subject: [PATCH] Kernel/x86_64 - Added input on debug serial --- KernelLand/Kernel/arch/x86_64/lib.c | 44 ++++++++++++++++--------- KernelLand/Kernel/arch/x86_64/mm_virt.c | 2 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/KernelLand/Kernel/arch/x86_64/lib.c b/KernelLand/Kernel/arch/x86_64/lib.c index 385b677a..cbcf769f 100644 --- a/KernelLand/Kernel/arch/x86_64/lib.c +++ b/KernelLand/Kernel/arch/x86_64/lib.c @@ -2,6 +2,7 @@ */ #include #include +#include #define DEBUG_TO_E9 1 #define DEBUG_TO_SERIAL 1 @@ -146,17 +147,21 @@ void SHORTREL(struct sShortSpinlock *Lock) // === DEBUG IO === #if USE_GDB_STUB +void initGdbSerial(void) +{ + outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts + outb(GDB_SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + outb(GDB_SERIAL_PORT + 0, 0x0C); // Set divisor to 12 (lo byte) 9600 baud + outb(GDB_SERIAL_PORT + 1, 0x00); // (base is (hi byte) + outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit (8N1) + outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it + outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + gbDebug_SerialSetup = 1; +} int putDebugChar(char ch) { if(!gbGDB_SerialSetup) { - outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts - outb(GDB_SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - outb(GDB_SERIAL_PORT + 0, 0x0C); // Set divisor to 12 (lo byte) 9600 baud - outb(GDB_SERIAL_PORT + 1, 0x00); // (base is (hi byte) - outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit (8N1) - outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it - outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - gbDebug_SerialSetup = 1; + initGdbSerial(); } while( (inb(GDB_SERIAL_PORT + 5) & 0x20) == 0 ); outb(GDB_SERIAL_PORT, ch); @@ -165,20 +170,25 @@ int putDebugChar(char ch) int getDebugChar(void) { if(!gbGDB_SerialSetup) { - outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts - outb(GDB_SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - outb(GDB_SERIAL_PORT + 0, 0x0C); // Set divisor to 12 (lo byte) 9600 baud - outb(GDB_SERIAL_PORT + 1, 0x00); // (hi byte) - outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit - outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it - outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - gbDebug_SerialSetup = 1; + initGdbSerial(); } while( (inb(GDB_SERIAL_PORT + 5) & 1) == 0) ; return inb(GDB_SERIAL_PORT); } #endif +void Debug_SerialIRQHandler(int irq, void *unused) +{ + if( (inb(SERIAL_PORT+5) & 0x01) == 0 ) { + Debug("Serial no data"); + return ; + } + + char ch = inb(SERIAL_PORT); + //Debug("Serial RX 0x%x", ch); + Serial_ByteReceived(gSerial_KernelDebugPort, ch); +} + void Debug_PutCharDebug(char ch) { #if DEBUG_TO_E9 @@ -194,7 +204,9 @@ void Debug_PutCharDebug(char ch) outb(SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit outb(SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it outb(SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + outb(SERIAL_PORT + 1, 0x05); // Enable ERBFI (Rx Full), ELSI (Line Status) gbDebug_SerialSetup = 1; + IRQ_AddHandler(4, Debug_SerialIRQHandler, NULL); } while( (inb(SERIAL_PORT + 5) & 0x20) == 0 ); outb(SERIAL_PORT, ch); diff --git a/KernelLand/Kernel/arch/x86_64/mm_virt.c b/KernelLand/Kernel/arch/x86_64/mm_virt.c index 83e1d1fb..e2e779db 100644 --- a/KernelLand/Kernel/arch/x86_64/mm_virt.c +++ b/KernelLand/Kernel/arch/x86_64/mm_virt.c @@ -1050,7 +1050,7 @@ void MM_int_ClearTableLevel(tVAddr VAddr, int LevelBits, int MaxEnts) void MM_ClearUser(void) { - MM_int_ClearTableLevel(0, 39, 256); + MM_int_ClearTableLevel(0, 39, 256); } tVAddr MM_NewWorkerStack(void *StackData, size_t StackSize) -- 2.20.1