From: John Hodge Date: Tue, 20 Jul 2010 13:51:45 +0000 (+0800) Subject: Bit of debug cleanup, fixing bugs found on GrUB2 X-Git-Tag: rel0.06~96 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f5ee3595addf2954bbbd5dcb9d7de72b069750e7;p=tpg%2Facess2.git Bit of debug cleanup, fixing bugs found on GrUB2 - NOTE: Grub 2 does not pass the kernel binary path in the command line Hence, the argc code breaks in system.c - Starting on a RTL8139 driver - Fixed logging/debug calls to use \r\n, fixing serial debugging --- diff --git a/Kernel/arch/x86/desctab.asm b/Kernel/arch/x86/desctab.asm index b80c355c..615d6a27 100644 --- a/Kernel/arch/x86/desctab.asm +++ b/Kernel/arch/x86/desctab.asm @@ -129,14 +129,14 @@ Desctab_Install: %macro ISR_ERRNO 1 [global Isr%1] Isr%1: - xchg bx, bx + ;xchg bx, bx push %1 jmp ErrorCommon %endmacro %macro ISR_NOERR 1 [global Isr%1] Isr%1: - xchg bx, bx + ;xchg bx, bx push 0 push %1 jmp ErrorCommon diff --git a/Kernel/debug.c b/Kernel/debug.c index 1fe332cc..13b65363 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -181,6 +181,7 @@ void Debug(char *Fmt, ...) va_start(args, Fmt); Debug_DbgOnlyFmt(Fmt, args); va_end(args); + Debug_PutCharDebug('\r'); Debug_PutCharDebug('\n'); } /** @@ -194,6 +195,7 @@ void Log(char *Fmt, ...) va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); + Debug_Putchar('\r'); Debug_Putchar('\n'); } void Warning(char *Fmt, ...) @@ -203,6 +205,7 @@ void Warning(char *Fmt, ...) va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); + Debug_Putchar('\r'); Debug_Putchar('\n'); } void Panic(char *Fmt, ...) @@ -215,6 +218,7 @@ void Panic(char *Fmt, ...) va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); + Debug_Putchar('\r'); Debug_Putchar('\n'); Threads_Dump(); @@ -279,7 +283,7 @@ void Debug_Enter(char *FuncName, char *ArgTypes, ...) } va_end(args); - Debug_Putchar(')'); Debug_Putchar('\n'); + Debug_Putchar(')'); Debug_Putchar('\n'); Debug_Putchar('\r'); } void Debug_Log(char *FuncName, char *Fmt, ...) @@ -295,6 +299,7 @@ void Debug_Log(char *FuncName, char *Fmt, ...) Debug_Fmt(Fmt, args); va_end(args); + Debug_Putchar('\r'); Debug_Putchar('\n'); } @@ -316,6 +321,7 @@ void Debug_Leave(char *FuncName, char RetType, ...) // No Return if(RetType == '-') { + Debug_Putchar('\r'); Debug_Putchar('\n'); return; } @@ -332,6 +338,7 @@ void Debug_Leave(char *FuncName, char RetType, ...) // Extended (64-Bit) case 'X': Debug_Fmt("0x%llx", args); break; } + Debug_Putchar('\r'); Debug_Putchar('\n'); va_end(args); @@ -342,7 +349,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) Uint8 *cdat = Data; Uint pos = 0; Debug_Puts(1, Header); - LogF(" (Hexdump of %p)\n", Data); + LogF(" (Hexdump of %p)\r\n", Data); while(Length >= 16) { @@ -369,6 +376,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) Length--; cdat ++; } + Debug_Putchar('\r'); Debug_Putchar('\n'); } diff --git a/Kernel/logging.c b/Kernel/logging.c index 6ba68bff..1895b5b5 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -124,7 +124,7 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) void Log_Int_PrintMessage(tLogEntry *Entry) { //LOCK( &glLogOutput ); - LogF("%s%014lli%s [%+8s] %s\x1B[0m\n", + LogF("%s%014lli%s [%+8s] %s\x1B[0m\r\n", csaLevelColours[Entry->Level], Entry->Time, csaLevelCodes[Entry->Level], diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 02b9008a..97459c2b 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -40,11 +40,18 @@ void SyscallHandler(tSyscallRegs *Regs) { Uint64 ret = 0; Uint err = -EOK; + int callNum = Regs->Num; - ENTER("iThread iNum", Threads_GetTID(), Regs->Num); - if(Regs->Num < NUM_SYSCALLS) - LOG("Syscall %s", cSYSCALL_NAMES[Regs->Num]); + #if DEBUG < 2 + if(callNum != SYS_READ && callNum != SYS_WRITE) { + #endif + ENTER("iThread iNum", Threads_GetTID(), callNum); + if(callNum < NUM_SYSCALLS) + LOG("Syscall %s", cSYSCALL_NAMES[callNum]); LOG("Arg1: 0x%x, Arg2: 0x%x, Arg3: 0x%x, Arg4: 0x%x", Regs->Arg1, Regs->Arg2, Regs->Arg3, Regs->Arg4); + #if DEBUG < 2 + } + #endif switch(Regs->Num) { @@ -192,10 +199,12 @@ void SyscallHandler(tSyscallRegs *Regs) ret = -1; break; } + LOG("VFS_Open(\"%s\", 0x%x)", (char*)Regs->Arg1, Regs->Arg2 | VFS_OPENFLAG_USER); ret = VFS_Open((char*)Regs->Arg1, Regs->Arg2 | VFS_OPENFLAG_USER); break; case SYS_CLOSE: + LOG("VFS_Close(%i)", Regs->Arg1); VFS_Close( Regs->Arg1 ); break; @@ -328,11 +337,17 @@ void SyscallHandler(tSyscallRegs *Regs) #endif Regs->Error = err; #if DEBUG + # if DEBUG < 2 + if( callNum != SYS_READ && callNum != SYS_WRITE ) { + # endif LOG("err = %i", err); if(Regs->Num != SYS_EXECVE) LEAVE('x', ret); else LOG("Actual %i", ret); + # if DEBUG < 2 + } + # endif #endif } diff --git a/Kernel/system.c b/Kernel/system.c index 9ff5fd9f..5a2775db 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -126,7 +126,7 @@ void System_ParseCommandLine(char *ArgString) argc ++; // Count last argument // --- Parse Arguments (Pass 1) --- - for( i = 1; i < argc; i++ ) + for( i = 0; i < argc; i++ ) { switch(argv[i][0]) { @@ -152,8 +152,9 @@ void System_ParseCommandLine(char *ArgString) void System_ExecuteCommandLine(void) { int i; - for( i = 1; i < argc; i++ ) + for( i = 0; i < argc; i++ ) { + Log("argv[%i] = '%s'", i, argv[i]); switch(argv[i][0]) { // --- VFS --- diff --git a/Modules/Filesystems/InitRD/main.c b/Modules/Filesystems/InitRD/main.c index 08835bf7..97b40cca 100644 --- a/Modules/Filesystems/InitRD/main.c +++ b/Modules/Filesystems/InitRD/main.c @@ -5,6 +5,8 @@ #include "initrd.h" #include +#define DUMP_ON_MOUNT 1 + // === IMPORTS == extern tVFS_Node gInitRD_RootNode; @@ -15,6 +17,7 @@ void InitRD_Unmount(tVFS_Node *Node); Uint64 InitRD_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Size, void *Buffer); char *InitRD_ReadDir(tVFS_Node *Node, int ID); tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name); +void InitRD_DumpDir(tVFS_Node *Node, int Indent); // === GLOBALS === MODULE_DEFINE(0, 0x0A, FS_InitRD, InitRD_Install, NULL); @@ -28,6 +31,7 @@ tVFS_Driver gInitRD_FSInfo = { int InitRD_Install(char **Arguments) { VFS_AddDriver( &gInitRD_FSInfo ); + return MODULE_ERR_OK; } @@ -36,6 +40,9 @@ int InitRD_Install(char **Arguments) */ tVFS_Node *InitRD_InitDevice(char *Device, char **Arguments) { + #if DUMP_ON_MOUNT + InitRD_DumpDir( &gInitRD_RootNode, 0 ); + #endif return &gInitRD_RootNode; } @@ -92,3 +99,20 @@ tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name) return NULL; } + +void InitRD_DumpDir(tVFS_Node *Node, int Indent) +{ + int i; + char indent[Indent+1]; + tInitRD_File *dir = Node->ImplPtr; + + for( i = 0; i < Indent; i++ ) indent[i] = ' '; + indent[i] = '\0'; + + for( i = 0; i < Node->Size; i++ ) + { + //Log("%s- %p %s", indent, dir[i].Node, dir[i].Name); + if(dir[i].Node->Flags & VFS_FFLAG_DIRECTORY) + InitRD_DumpDir(dir[i].Node, Indent+1); + } +} diff --git a/Modules/Network/RTL8139/main.c b/Modules/Network/RTL8139/main.c index aa7a4443..b458cdae 100644 --- a/Modules/Network/RTL8139/main.c +++ b/Modules/Network/RTL8139/main.c @@ -1,4 +1,5 @@ -/* Acess2 RTL8139 Driver +/* + * Acess2 RTL8139 Driver * - By John Hodge (thePowersGang) * * main.c - Driver Core @@ -48,11 +49,29 @@ typedef struct sCard } tCard; // === PROTOTYPES === + int RTL8139_Install(char **Options); +char *RTL8139_ReadDir(tVFS_Node *Node, int Pos); +tVFS_Node *RTL8139_FindDir(tVFS_Node *Node, const char *Filename); + int RTL8139_RootIOCtl(tVFS_Node *Node, int ID, void *Arg); +Uint64 RTL8139_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +void RTL8139_IRQHandler(int Num); // === GLOBALS === MODULE_DEFINE(0, VERSION, RTL8139, RTL8139_Install, NULL, NULL); +tDevFS_Driver gRTL8139_DriverInfo = { + NULL, "RTL8139", + { + .NumACLs = 1, + .ACLs = &gVFS_ACL_EveryoneRX, + .Flags = VFS_FFLAG_DIRECTORY, + .ReadDir = RTL8139_ReadDir, + .FindDir = RTL8139_FindDir, + .IOCtl = RTL8139_RootIOCtl + } +}; int giRTL8139_CardCount; -tCard gpRTL8139_Cards; +tCard *gpRTL8139_Cards; // === CODE === /** @@ -83,17 +102,21 @@ int RTL8139_Install(char **Options) // Reset (0x10 to CMD) outb( base + CMD, 0x10 ); - gpRTL8139_Cards[i].ReceiveBuffer = MM_AllocDMA( 2, 32, &gpRTL8139_Cards[i].PhysReceiveBuffer ); + while( inb(base + CMD) & 0x10 ) ; + + // Allocate 3 pages below 4GiB for the recieve buffer (Allows 8k+16+1500) + gpRTL8139_Cards[i].ReceiveBuffer = MM_AllocDMA( 3, 32, &gpRTL8139_Cards[i].PhysReceiveBuffer ); // Set up recieve buffer outl(base + RBSTART, (Uint32)gpRTL8139_Cards[i].PhysReceiveBuffer); // Set IMR to Transmit OK and Receive OK outw(base + IMR, 0x5); - // Set recieve buffer size, buffer wrap and recieve mask - outl(base + RCR, 0x8F); + // Set recieve buffer size and recieve mask + outl(base + RCR, 0x0F); outb(base + CMD, 0x0C); // Recive Enable and Transmit Enable + // Get the card's MAC address gpRTL8139_Cards[ i ].MacAddr[0] = inb(base+MAC0); gpRTL8139_Cards[ i ].MacAddr[1] = inb(base+MAC1); gpRTL8139_Cards[ i ].MacAddr[2] = inb(base+MAC2); @@ -122,3 +145,35 @@ int RTL8139_Install(char **Options) } return MODULE_ERR_OK; } + +// --- Root Functions --- +char *RTL8139_ReadDir(tVFS_Node *Node, int Pos) +{ + return NULL; +} + +tVFS_Node *RTL8139_FindDir(tVFS_Node *Node, const char *Filename) +{ + return NULL; +} + +int RTL8139_RootIOCtl(tVFS_Node *Node, int ID, void *Arg) +{ + return 0; +} + +// --- File Functions --- +Uint64 RTL8139_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +{ + return 0; +} + +Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +{ + return 0; +} + +int RTL8139_IOCtl(tVFS_Node *Node, int ID, void *Arg) +{ + return 0; +}