X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdebug.c;h=8404fc1d21a848a3cd2cd7bdde467805da57dd78;hb=0df427777a3ab005eaeebc1ee4a326c8dfe91b29;hp=a23c4c419302a50a1d0e523f891bcda40b1bcaaf;hpb=47e9dfd89189fc6b150bd6b20229cb047c7e0858;p=tpg%2Facess2.git diff --git a/Kernel/debug.c b/Kernel/debug.c index a23c4c41..8404fc1d 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -2,22 +2,79 @@ * AcessOS Microkernel Version * debug.c */ -#include +#include #include +#define DEBUG_TO_E9 1 +#define DEBUG_TO_SERIAL 1 +#define SERIAL_PORT 0x3F8 +#define GDB_SERIAL_PORT 0x2F8 + // === IMPORTS === extern void Threads_Dump(); // === GLOBALS === int gDebug_Level = 0; int giDebug_KTerm = -1; + int gbDebug_SerialSetup = 0; + int gbGDB_SerialSetup = 0; // === CODE === +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, 0x03); // Set divisor to 3 (lo byte) 38400 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; + } + while( (inb(GDB_SERIAL_PORT + 5) & 0x20) == 0 ); + outb(GDB_SERIAL_PORT, ch); + return 0; +} +int getDebugChar() +{ + 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, 0x03); // Set divisor to 3 (lo byte) 38400 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; + } + while( (inb(GDB_SERIAL_PORT + 5) & 1) == 0) ; + return inb(GDB_SERIAL_PORT); +} + static void E9(char ch) { if(giDebug_KTerm != -1) VFS_Write(giDebug_KTerm, 1, &ch); + + #if DEBUG_TO_SERIAL + if(!gbDebug_SerialSetup) { + outb(SERIAL_PORT + 1, 0x00); // Disable all interrupts + outb(SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + outb(SERIAL_PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + outb(SERIAL_PORT + 1, 0x00); // (hi byte) + 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 + gbDebug_SerialSetup = 1; + } + while( (inb(SERIAL_PORT + 5) & 0x20) == 0 ); + outb(SERIAL_PORT, ch); + #endif + + #if DEBUG_TO_E9 __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) ); + #endif } static void E9_Str(char *Str) @@ -33,7 +90,7 @@ void E9_Fmt(const char *format, va_list *args) char *p = NULL; int isLongLong = 0; Uint64 arg; - + while((c = *format++) != 0) { // Non control character @@ -129,7 +186,18 @@ void E9_Fmt(const char *format, va_list *args) if(!p) p = "(null)"; while(*p) E9(*p++); break; - + + // Single Character / Array + case 'c': + if(minSize == 1) { + E9(arg); + break; + } + p = (char*)(Uint)arg; + if(!p) goto printString; + while(minSize--) E9(*p++); + break; + default: E9(arg); break; } } @@ -200,7 +268,7 @@ void Debug_SetKTerminal(char *File) if(giDebug_KTerm != -1) VFS_Close(giDebug_KTerm); giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE); - Log("Opened '%s' as %i\n", File, giDebug_KTerm); + Log("Opened '%s' as 0x%x", File, giDebug_KTerm); } void Debug_Enter(char *FuncName, char *ArgTypes, ...) @@ -271,6 +339,10 @@ void Debug_Leave(char *FuncName, char RetType, ...) va_start(args, RetType); + if( i == -1 ) { + gDebug_Level = 0; + i = 0; + } // Indenting while(i--) E9(' ');