Bit of debug cleanup, fixing bugs found on GrUB2
authorJohn Hodge <[email protected]>
Tue, 20 Jul 2010 13:51:45 +0000 (21:51 +0800)
committerJohn Hodge <[email protected]>
Tue, 20 Jul 2010 13:51:45 +0000 (21:51 +0800)
- 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

Kernel/arch/x86/desctab.asm
Kernel/debug.c
Kernel/logging.c
Kernel/syscalls.c
Kernel/system.c
Modules/Filesystems/InitRD/main.c
Modules/Network/RTL8139/main.c

index b80c355..615d6a2 100644 (file)
@@ -129,14 +129,14 @@ Desctab_Install:
 %macro ISR_ERRNO       1
 [global Isr%1]
 Isr%1:
 %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:
        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
        push    0
        push    %1
        jmp     ErrorCommon
index 1fe332c..13b6536 100644 (file)
@@ -181,6 +181,7 @@ void Debug(char *Fmt, ...)
        va_start(args, Fmt);
        Debug_DbgOnlyFmt(Fmt, args);
        va_end(args);
        va_start(args, Fmt);
        Debug_DbgOnlyFmt(Fmt, args);
        va_end(args);
+       Debug_PutCharDebug('\r');
        Debug_PutCharDebug('\n');
 }
 /**
        Debug_PutCharDebug('\n');
 }
 /**
@@ -194,6 +195,7 @@ void Log(char *Fmt, ...)
        va_start(args, Fmt);
        Debug_Fmt(Fmt, args);
        va_end(args);
        va_start(args, Fmt);
        Debug_Fmt(Fmt, args);
        va_end(args);
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 }
 void Warning(char *Fmt, ...)
        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);
        va_start(args, Fmt);
        Debug_Fmt(Fmt, args);
        va_end(args);
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 }
 void Panic(char *Fmt, ...)
        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);
        va_start(args, Fmt);
        Debug_Fmt(Fmt, args);
        va_end(args);
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 
        Threads_Dump();
        Debug_Putchar('\n');
 
        Threads_Dump();
@@ -279,7 +283,7 @@ void Debug_Enter(char *FuncName, char *ArgTypes, ...)
        }
 
        va_end(args);
        }
 
        va_end(args);
-       Debug_Putchar(')');     Debug_Putchar('\n');
+       Debug_Putchar(')');     Debug_Putchar('\n');    Debug_Putchar('\r');
 }
 
 void Debug_Log(char *FuncName, char *Fmt, ...)
 }
 
 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_Fmt(Fmt, args);
 
        va_end(args);
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 }
 
        Debug_Putchar('\n');
 }
 
@@ -316,6 +321,7 @@ void Debug_Leave(char *FuncName, char RetType, ...)
 
        // No Return
        if(RetType == '-') {
 
        // No Return
        if(RetType == '-') {
+               Debug_Putchar('\r');
                Debug_Putchar('\n');
                return;
        }
                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;
        }
        // Extended (64-Bit)
        case 'X':       Debug_Fmt("0x%llx", args);      break;
        }
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 
        va_end(args);
        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);
        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)
        {
 
        while(Length >= 16)
        {
@@ -369,6 +376,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length)
                Length--;
                cdat ++;
        }
                Length--;
                cdat ++;
        }
+       Debug_Putchar('\r');
        Debug_Putchar('\n');
 }
 
        Debug_Putchar('\n');
 }
 
index 6ba68bf..1895b5b 100644 (file)
@@ -124,7 +124,7 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
 void Log_Int_PrintMessage(tLogEntry *Entry)
 {
        //LOCK( &glLogOutput );
 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],
                csaLevelColours[Entry->Level],
                Entry->Time,
                csaLevelCodes[Entry->Level],
index 02b9008..97459c2 100644 (file)
@@ -40,11 +40,18 @@ void SyscallHandler(tSyscallRegs *Regs)
 {
        Uint64  ret = 0;
        Uint    err = -EOK;
 {
        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);
        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)
        {
        
        switch(Regs->Num)
        {
@@ -192,10 +199,12 @@ void SyscallHandler(tSyscallRegs *Regs)
                        ret = -1;
                        break;
                }
                        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:
                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;
        
                VFS_Close( Regs->Arg1 );
                break;
        
@@ -328,11 +337,17 @@ void SyscallHandler(tSyscallRegs *Regs)
        #endif
        Regs->Error = err;
        #if DEBUG
        #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);
        LOG("err = %i", err);
        if(Regs->Num != SYS_EXECVE)
                LEAVE('x', ret);
        else
                LOG("Actual %i", ret);
+       # if DEBUG < 2
+       }
+       # endif
        #endif
 }
 
        #endif
 }
 
index 9ff5fd9..5a2775d 100644 (file)
@@ -126,7 +126,7 @@ void System_ParseCommandLine(char *ArgString)
                argc ++;        // Count last argument
        
        // --- Parse Arguments (Pass 1) ---
                argc ++;        // Count last argument
        
        // --- Parse Arguments (Pass 1) ---
-       for( i = 1; i < argc; i++ )
+       for( i = 0; i < argc; i++ )
        {
                switch(argv[i][0])
                {
        {
                switch(argv[i][0])
                {
@@ -152,8 +152,9 @@ void System_ParseCommandLine(char *ArgString)
 void System_ExecuteCommandLine(void)
 {
         int    i;
 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 ---
                switch(argv[i][0])
                {
                // --- VFS ---
index 08835bf..97b40cc 100644 (file)
@@ -5,6 +5,8 @@
 #include "initrd.h"
 #include <modules.h>
 
 #include "initrd.h"
 #include <modules.h>
 
+#define DUMP_ON_MOUNT  1
+
 // === IMPORTS ==
 extern tVFS_Node       gInitRD_RootNode;
 
 // === 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);
 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);
 
 // === 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 );
 int InitRD_Install(char **Arguments)
 {
        VFS_AddDriver( &gInitRD_FSInfo );
+       
        return MODULE_ERR_OK;
 }
 
        return MODULE_ERR_OK;
 }
 
@@ -36,6 +40,9 @@ int InitRD_Install(char **Arguments)
  */
 tVFS_Node *InitRD_InitDevice(char *Device, char **Arguments)
 {
  */
 tVFS_Node *InitRD_InitDevice(char *Device, char **Arguments)
 {
+       #if DUMP_ON_MOUNT
+       InitRD_DumpDir( &gInitRD_RootNode, 0 );
+       #endif
        return &gInitRD_RootNode;
 }
 
        return &gInitRD_RootNode;
 }
 
@@ -92,3 +99,20 @@ tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name)
        
        return NULL;
 }
        
        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);
+       }
+}
index aa7a444..b458cda 100644 (file)
@@ -1,4 +1,5 @@
-/* Acess2 RTL8139 Driver
+/*
+ * Acess2 RTL8139 Driver
  * - By John Hodge (thePowersGang)
  * 
  * main.c - Driver Core
  * - By John Hodge (thePowersGang)
  * 
  * main.c - Driver Core
@@ -48,11 +49,29 @@ typedef struct sCard
 }      tCard;
 
 // === PROTOTYPES ===
 }      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);
 
 // === 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;
  int   giRTL8139_CardCount;
-tCard  gpRTL8139_Cards;
+tCard  *gpRTL8139_Cards;
 
 // === CODE ===
 /**
 
 // === CODE ===
 /**
@@ -83,17 +102,21 @@ int RTL8139_Install(char **Options)
                // Reset (0x10 to CMD)
                outb( base + CMD, 0x10 );
                
                // 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 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
                
                
                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);
                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;
 }
        }
        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;
+}

UCC git Repository :: git.ucc.asn.au