From: John Hodge Date: Sun, 8 Jul 2012 01:28:52 +0000 (+0800) Subject: Kernel - Adding network debugging, disabled X-Git-Tag: rel0.15~611^2~42 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=759315c5321e354458086e0fc28335c4c12ed194;p=tpg%2Facess2.git Kernel - Adding network debugging, disabled - Disabled because the RTL8139 driver doesn't get the TOK interrupt while the logging code is waiting for a TX desc --- diff --git a/KernelLand/Kernel/arch/x86/irq.c b/KernelLand/Kernel/arch/x86/irq.c index eb891398..0a195104 100644 --- a/KernelLand/Kernel/arch/x86/irq.c +++ b/KernelLand/Kernel/arch/x86/irq.c @@ -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; diff --git a/KernelLand/Kernel/debug.c b/KernelLand/Kernel/debug.c index 6a50ca2c..dab20add 100644 --- a/KernelLand/Kernel/debug.c +++ b/KernelLand/Kernel/debug.c @@ -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); diff --git a/KernelLand/Kernel/drvutil.c b/KernelLand/Kernel/drvutil.c index df4fac91..750ea7cd 100644 --- a/KernelLand/Kernel/drvutil.c +++ b/KernelLand/Kernel/drvutil.c @@ -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" diff --git a/KernelLand/Kernel/logging.c b/KernelLand/Kernel/logging.c index b419be3d..d067e499 100644 --- a/KernelLand/Kernel/logging.c +++ b/KernelLand/Kernel/logging.c @@ -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], diff --git a/KernelLand/Modules/IPStack/adapters.c b/KernelLand/Modules/IPStack/adapters.c index ab054ba2..83741dfe 100644 --- a/KernelLand/Modules/IPStack/adapters.c +++ b/KernelLand/Modules/IPStack/adapters.c @@ -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); +} + diff --git a/KernelLand/Modules/Network/VIARhineII/rhine2.c b/KernelLand/Modules/Network/VIARhineII/rhine2.c index d0fe6c93..a1686f7e 100644 --- a/KernelLand/Modules/Network/VIARhineII/rhine2.c +++ b/KernelLand/Modules/Network/VIARhineII/rhine2.c @@ -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) );