From a68d8ae1a9840367f9ca749170b62fe84850bef9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 22 Sep 2013 19:09:01 +0800 Subject: [PATCH] Kernel/x86 - Added input support to serial terminal --- KernelLand/Kernel/arch/x86/irq.c | 6 +++--- KernelLand/Kernel/arch/x86/lib.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/KernelLand/Kernel/arch/x86/irq.c b/KernelLand/Kernel/arch/x86/irq.c index 7250debe..5230f214 100644 --- a/KernelLand/Kernel/arch/x86/irq.c +++ b/KernelLand/Kernel/arch/x86/irq.c @@ -25,12 +25,12 @@ void *gaIRQ_DataPointers[16][MAX_CALLBACKS_PER_IRQ]; */ void IRQ_Handler(tRegs *Regs) { - int i, irq = Regs->int_num - 0xF0; + int irq = Regs->int_num - 0xF0; int bHandled = 0; //Log("IRQ_Handler: (Regs={int_num:%i})", Regs->int_num); - for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ ) + for( int i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ ) { if( gIRQ_Handlers[irq][i] ) { gIRQ_Handlers[irq][i](irq, gaIRQ_DataPointers[irq][i]); @@ -63,7 +63,7 @@ int IRQ_AddHandler( int Num, void (*Callback)(int, void*), void *Ptr ) { if( gIRQ_Handlers[Num][i] == NULL ) { - Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback); + //Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback); gIRQ_Handlers[Num][i] = Callback; gaIRQ_DataPointers[Num][i] = Ptr; return Num * MAX_CALLBACKS_PER_IRQ + i; diff --git a/KernelLand/Kernel/arch/x86/lib.c b/KernelLand/Kernel/arch/x86/lib.c index f862afd2..2039924d 100644 --- a/KernelLand/Kernel/arch/x86/lib.c +++ b/KernelLand/Kernel/arch/x86/lib.c @@ -8,6 +8,7 @@ #include #include #include // GetCPUNum +#include #define TRACE_LOCKS 0 @@ -28,6 +29,7 @@ extern tMutex glPhysAlloc; Uint64 __divmod64(Uint64 Num, Uint64 Den, Uint64 *Rem); Uint64 __udivdi3(Uint64 Num, Uint64 Den); Uint64 __umoddi3(Uint64 Num, Uint64 Den); +void Debug_SerialIRQHandler(int irq, void *unused); // === GLOBALS === int gbDebug_SerialSetup = 0; @@ -189,7 +191,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); @@ -202,6 +206,17 @@ void Debug_PutStringDebug(const char *String) Debug_PutCharDebug(*String++); } +void Debug_SerialIRQHandler(int irq, void *unused) +{ + if( (inb(SERIAL_PORT+5) & 0x01) == 0 ) { + Debug("IRQ4, no data"); + return ; + } + + char ch = inb(SERIAL_PORT); + Serial_ByteReceived(gSerial_KernelDebugPort, ch); +} + // === IO Commands === void outb(Uint16 Port, Uint8 Data) { -- 2.20.1