Kernel - Adding network debugging, disabled
authorJohn Hodge <[email protected]>
Sun, 8 Jul 2012 01:28:52 +0000 (09:28 +0800)
committerJohn Hodge <[email protected]>
Sun, 8 Jul 2012 01:28:52 +0000 (09:28 +0800)
- Disabled because the RTL8139 driver doesn't get the TOK interrupt
  while the logging code is waiting for a TX desc

KernelLand/Kernel/arch/x86/irq.c
KernelLand/Kernel/debug.c
KernelLand/Kernel/drvutil.c
KernelLand/Kernel/logging.c
KernelLand/Modules/IPStack/adapters.c
KernelLand/Modules/Network/VIARhineII/rhine2.c

index eb89139..0a19510 100644 (file)
@@ -61,8 +61,9 @@ int IRQ_AddHandler( int Num, void (*Callback)(int, void*), void *Ptr )
         int    i;
        for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
        {
-               if( gIRQ_Handlers[Num][i] == NULL ) {
-//                     Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback);
+               if( gIRQ_Handlers[Num][i] == NULL )
+               {
+                       Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback);
                        gIRQ_Handlers[Num][i] = Callback;
                        gaIRQ_DataPointers[Num][i] = Ptr;
                        return 1;
index 6a50ca2..dab20ad 100644 (file)
@@ -13,6 +13,7 @@
 extern void    Threads_Dump(void);
 extern void    KernelPanic_SetMode(void);
 extern void    KernelPanic_PutChar(char Ch);
+extern void    IPStack_SendDebugText(const char *Text);
 
 // === PROTOTYPES ===
 static void    Debug_Putchar(char ch);
@@ -30,11 +31,14 @@ volatile int        gbInPutChar = 0;
 #if LOCK_DEBUG_OUTPUT
 tShortSpinlock glDebug_Lock;
 #endif
+// - Disabled because it breaks shit
+ int   gbSendNetworkDebug = 0;
 
 // === CODE ===
 static void Debug_Putchar(char ch)
 {
        Debug_PutCharDebug(ch);
+       
        if( !gbDebug_IsKPanic )
        {
                if(gbInPutChar) return ;
@@ -45,6 +49,12 @@ static void Debug_Putchar(char ch)
        }
        else
                KernelPanic_PutChar(ch);
+       
+       if( gbSendNetworkDebug )
+       {
+               char str[2] = {ch, 0};
+               IPStack_SendDebugText(str);
+       }
 }
 
 static void Debug_Puts(int UseKTerm, const char *Str)
@@ -60,7 +70,10 @@ static void Debug_Puts(int UseKTerm, const char *Str)
        }
        else
                for( len = 0; Str[len]; len ++ );
-       
+
+       if( gbSendNetworkDebug )
+               IPStack_SendDebugText(Str);
+
        // Output to the kernel terminal
        if( UseKTerm && !gbDebug_IsKPanic && giDebug_KTerm != -1)
        {
@@ -79,9 +92,9 @@ void Debug_DbgOnlyFmt(const char *format, va_list args)
 void Debug_Fmt(int bUseKTerm, const char *format, va_list args)
 {
        char    buf[DEBUG_MAX_LINE_LEN];
-        int    len;
+//      int    len;
        buf[DEBUG_MAX_LINE_LEN-1] = 0;
-       len = vsnprintf(buf, DEBUG_MAX_LINE_LEN-1, format, args);
+       /*len = */vsnprintf(buf, DEBUG_MAX_LINE_LEN-1, format, args);
        //if( len < DEBUG_MAX_LINE )
                // do something
        Debug_Puts(bUseKTerm, buf);
index df4fac9..750ea7c 100644 (file)
@@ -102,12 +102,13 @@ int DrvUtil_Video_2DStream(void *Ent, const void *Buffer, int Length,
                                tmp[4] | ((Uint32)tmp[5] << 16)
                                );
                        
-                       rem -= 10;
-                       stream += 10;
+                       rem -= 12;
+                       stream += 12;
                        break;
                
                case VIDEO_2DOP_BLIT:
                        if(rem < 12)    return Length-rem;
+                       memcpy(tmp, stream, 6*2);
                        
                        if(!Handlers->Blit) {
                                Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver"
index b419be3..d067e49 100644 (file)
@@ -156,6 +156,8 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args
  */
 void Log_Int_PrintMessage(tLogEntry *Entry)
 {
+       if( CPU_HAS_LOCK(&glLogOutput) )
+               return ;        // TODO: Error?
        SHORTLOCK( &glLogOutput );
        LogF("%s%014lli%s [%-8s] %i - %s",
                csaLevelColours[Entry->Level],
index ab054ba..83741df 100644 (file)
@@ -79,9 +79,10 @@ void *IPStack_Adapter_Add(const tIPStack_AdapterType *Type, void *Ptr, const voi
        ret->Node.Type = &gIP_AdapterType;
        ret->Node.ImplPtr = ret;
 
-       // TODO: Locking
+       Mutex_Acquire( &glIP_Adapters );
        gpIP_AdapterList_Last->Next = ret;
        gpIP_AdapterList_Last = ret;
+       Mutex_Release( &glIP_Adapters );
        
        // Watch the adapter for incoming packets
        tTID tid = Proc_SpawnWorker(Adapter_int_WatchThread, ret);
@@ -314,3 +315,83 @@ int Adapter_int_LoopbackSendPacket(void *Unused, tIPStackBuffer *Buffer)
        return 0;
 }
 
+// --- Broadcast Debugging ---
+extern Uint16  IPv4_Checksum(const void *Buf, size_t Length);
+void IPStack_SendDebugText(const char *Text)
+{
+       const Uint8     pkt_hdr[] = {
+               0xFF,0xFF, 0xFF,0xFF, 0xFF,0xFF,
+               0x00,0x00, 0x00,0x00, 0x00,0x00,
+               0x08,0x00,
+               
+               0x45,0x00,      // Version/Length, DiffServices
+               0xFF,0xFF,      // Total Length
+               0x00,0x00,      // Identifcation
+               0x00,0x00, 0xFF,0x11,   // Flags,Fragment, TTL=255,proto=UDP
+               0x00,0x00,      // Header checksum
+               0x00,0x00,0x00,0x00,    // Source
+               0xFF,0xFF,0xFF,0xFF,    // Destination
+               
+               0x80,0x00, 0x80,0x00,
+               0xFF,0xFF, 0xFF,0xFF,
+       };
+       static tShortSpinlock   lLock;
+
+       // Fast return if there's no avaliable adapters
+       if( !gpIP_AdapterList )
+               return ;
+
+       if( CPU_HAS_LOCK(&lLock) )
+               return ;        // Nested!
+       SHORTLOCK(&lLock);
+       __asm__ __volatile__ ("sti");   // Start interrupts (x86 specific)
+
+       // Cache packets until a newline
+       static char     cache[1500 - (sizeof(pkt_hdr) + 4)];
+       static int      cache_len;
+       
+        int    len = strlen(Text);
+
+       // Append to cache
+       strncpy(cache + cache_len, Text, sizeof(cache) - cache_len);
+       cache_len += len;
+       // TODO: Detect overflows.
+       
+       // If there's no newline, only buffer
+       if( strpos(Text, '\n') == -1 ) {
+               SHORTREL(&lLock);
+               return ;
+       }
+
+       // Build packet
+        int    link_checksum_ofs = sizeof(pkt_hdr) + cache_len;
+       char    buffer[sizeof(pkt_hdr) + cache_len + 4];
+
+       memcpy(buffer, pkt_hdr, sizeof(pkt_hdr));
+       memcpy(buffer + sizeof(pkt_hdr), cache, cache_len);
+       
+       *(Uint16*)&buffer[14+2] = BigEndian16( sizeof(pkt_hdr)-14 + cache_len );        // IP Size
+       *(Uint16*)&buffer[14+10] = BigEndian16( 0 );    // IP Header
+       *(Uint16*)&buffer[14+20+4] = BigEndian16( 8+cache_len );        // UDP Size
+       *(Uint16*)&buffer[14+20+6] = BigEndian16( 0 );  // UDP Checksum
+       *(Uint32*)&buffer[link_checksum_ofs] = BigEndian32( 0 );        // 802.3 checksum?
+       // TODO: Calculate checksums
+       *(Uint16*)&buffer[14+10] = BigEndian16( IPv4_Checksum(buffer+14,20) );  // IP Header
+       
+       // Create buffer
+       tIPStackBuffer  *buf = IPStack_Buffer_CreateBuffer(1);
+       IPStack_Buffer_AppendSubBuffer(buf, link_checksum_ofs+4, 0, buffer, NULL, NULL);
+
+       // Send 'er off
+       for( tAdapter *a = gpIP_AdapterList; a; a = a->Next )
+       {
+               a->Type->SendPacket( a->CardHandle, buf );
+       }
+
+       IPStack_Buffer_DestroyBuffer(buf);
+
+       cache_len = 0;
+
+       SHORTREL(&lLock);
+}
+
index d0fe6c9..a1686f7 100644 (file)
@@ -84,6 +84,7 @@ int Rhine2_Install(char **Options)
        tCard   *card;
        
        giRhine2_CardCount = PCI_CountDevices(VENDOR_ID, DEVICE_ID);
+       Log_Debug("Rhine2", "giRhine2_CardCount = %i", giRhine2_CardCount);
        if( giRhine2_CardCount == 0 )   return MODULE_ERR_NOTNEEDED;
        
        gaRhine2_Cards = calloc( giRhine2_CardCount, sizeof(tCard) );

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