From 586a47ab9343a85c944a2cf7b27a74cf459a8423 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 27 Jul 2010 15:41:17 +0800 Subject: [PATCH] Working on the x86 bit port (caused some changes to try and get it to compile on more strict warnings) - Also working on that *#@% Qemu ATA bug --- Kernel/arch/x86/errors.c | 15 ++++- Kernel/arch/x86/proc.c | 4 +- Kernel/arch/x86_64/include/arch.h | 3 + Kernel/arch/x86_64/include/mm_virt.h | 28 ++++---- Kernel/arch/x86_64/link.ld | 1 + Kernel/arch/x86_64/mm_phys.c | 4 +- Kernel/arch/x86_64/proc.c | 4 +- Kernel/drv/kb.c | 12 +++- Kernel/heap.c | 89 ++++++++++++++++++++++++++ Kernel/include/acess.h | 3 +- Kernel/lib.c | 6 +- Kernel/logging.c | 34 ++++++++-- Kernel/modules.c | 2 +- Kernel/system.c | 3 +- Makefile.x86_64.cfg | 2 +- Modules/Display/VESA/main.c | 11 +++- Modules/Filesystems/Ext2/dir.c | 6 +- Modules/Filesystems/Ext2/ext2.c | 2 +- Modules/Filesystems/Ext2/ext2_common.h | 2 +- Modules/Filesystems/Ext2/write.c | 2 +- Modules/Filesystems/FAT/fat.c | 16 +++-- Modules/IPStack/arp.c | 6 +- Modules/IPStack/link.c | 2 +- Modules/IPStack/main.c | 2 +- Modules/Network/NE2000/ne2000.c | 2 +- Modules/Storage/ATA/main.c | 31 ++++++--- Modules/Storage/ATA/mbr.c | 2 +- Modules/Storage/FDD/fdd.c | 11 ++-- 28 files changed, 232 insertions(+), 73 deletions(-) diff --git a/Kernel/arch/x86/errors.c b/Kernel/arch/x86/errors.c index 3ae4bb28..796300f6 100644 --- a/Kernel/arch/x86/errors.c +++ b/Kernel/arch/x86/errors.c @@ -16,7 +16,10 @@ extern void Threads_Dump(void); extern void Threads_Fault(int Num); // === PROTOTYPES === +void __stack_chk_fail(void); +void ErrorHandler(tRegs *Regs); void Error_Backtrace(Uint eip, Uint ebp); +void StartupPrint(char *Str); // === GLOBALS === const char *csaERROR_NAMES[] = { @@ -31,6 +34,9 @@ const char *csaERROR_NAMES[] = { }; // === CODE === +/** + * \brief Keeps GCC happy + */ void __stack_chk_fail(void) { Panic("FATAL ERROR: Stack Check Failed\n"); @@ -40,6 +46,7 @@ void __stack_chk_fail(void) /** * \fn void ErrorHandler(tRegs *Regs) * \brief General Error Handler + * \param Regs Register state at error */ void ErrorHandler(tRegs *Regs) { @@ -133,6 +140,8 @@ void ErrorHandler(tRegs *Regs) /** * \fn void Error_Backtrace(Uint eip, Uint ebp) * \brief Unrolls the stack to trace execution + * \param eip Current Instruction Pointer + * \param ebp Current Base Pointer (Stack Frame) */ void Error_Backtrace(Uint eip, Uint ebp) { @@ -185,6 +194,8 @@ void Error_Backtrace(Uint eip, Uint ebp) /** * \fn void StartupPrint(char *Str) + * \brief Str String to print + * \note WHY IS THIS HERE?!?! */ void StartupPrint(char *Str) { @@ -197,7 +208,9 @@ void StartupPrint(char *Str) Str ++; } - while(i < 80) buf[line*80 + i++] = 0x0720; + // Clear the rest of the line + while(i < 80) + buf[line*80 + i++] = 0x0720; line ++; if(line == 25) diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 9c1eb987..d510b982 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -17,8 +17,8 @@ // === CONSTANTS === #define SWITCH_MAGIC 0xFFFACE55 // There is no code in this area // Base is 1193182 -#define TIMER_BASE 1193182 -#define TIMER_DIVISOR 11931 //~100Hz +#define TIMER_BASE 1193182 +#define TIMER_DIVISOR 11931 //~100Hz // === TYPES === #if USE_MP diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index 41acd883..fd548987 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -10,6 +10,9 @@ #define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 +//#define INT_MAX 0x7FFFFFFF +//#define UINT_MAX 0xFFFFFFFF + // === Core Types === typedef signed char Sint8; typedef unsigned char Uint8; diff --git a/Kernel/arch/x86_64/include/mm_virt.h b/Kernel/arch/x86_64/include/mm_virt.h index 3c4240d7..12643d39 100644 --- a/Kernel/arch/x86_64/include/mm_virt.h +++ b/Kernel/arch/x86_64/include/mm_virt.h @@ -19,24 +19,26 @@ * START ADDRESS END ADDRESS BITS SIZE NAME * 0x00000000 00000000 - 0x00007FFF FFFFFFFF 47 128 TiB User Space * 0x00008000 00000000 - 0xFFFF7FFF FFFFFFFF --- SIGN EXTENSION NULL ZONE - * 0xFFFF8000 00000000 - 0xFFFFFFFF FFFFFFFF 47 128 TiB Kernel Range - * 8000 00000000 - 9000 00000000 44 16 TiB Kernel Heap - * 9000 00000000 - 9800 00000000 43 8 TiB Module Space - * 9800 00000000 - 9A00 00000000 41 2 TiB Kernel VFS - * A000 00000000 - B000 00000000 44 16 TiB Kernel Stacks - * C000 00000000 - D000 00000000 44 16 TiB Hardware Mappings + * 0xFFFF8000 00000000 - 0xFFFFFFFF FFFFFFFF 47 128 TiB Kernel Range + * 8000 00000000 - 9000 00000000 44 16 TiB Kernel Heap + * 9000 00000000 - 9800 00000000 43 8 TiB Module Space + * 9800 00000000 - 9A00 00000000 41 2 TiB Kernel VFS + * ---- GAP ---- + * A000 00000000 - B000 00000000 44 16 TiB Kernel Stacks + * C000 00000000 - D000 00000000 44 16 TiB Hardware Mappings * D000 00000000 - D080 00000000 39 512 GiB Per-Process Data * D080 00000000 - D100 00000000 39 512 GiB Kernel Supplied User Code + * ---- GAP ---- * E000 00000000 - E400 00000000 42 4 TiB Physical Page Reference Counts (2**40 = 2**52 bytes) * E400 00000000 - E480 00000000 39 512 GiB Physical Page Bitmap (1 page per bit) * E480 00000000 - E500 00000000 39 512 GiB Physical Page DblAlloc Bitmap (1 page per bit) * E500 00000000 - E500 80000000 31 2 GiB Physical Page Super Bitmap (64 pages per bit) - * FD00 00000000 - FD80 00000000 39 512 GiB Local APIC - * FE00 00000000 - FE80 00000000 39 512 GiB Fractal Mapping (PML4 508) - * FE80 00000000 - FF00 00000000 39 512 GiB Temp Fractal Mapping - * FF00 00000000 - FF80 00000000 39 512 GiB -- UNUSED -- - * FF80 00000000 - FFFF 80000000 ~39 GiB -- UNUSED -- - * FFFF 80000000 - FFFF 7FFFFFFF 31 2 GiB Identity Map + * ---- GAP ---- + * FE00 00000000 - FE80 00000000 39 512 GiB Fractal Mapping (PML4 508) + * FE80 00000000 - FF00 00000000 39 512 GiB Temp Fractal Mapping + * FF00 00000000 - FF80 00000000 39 512 GiB -- UNUSED -- + * FD00 00000000 - FD00 80000000 39 2 GiB Local APIC + * FFFF 80000000 - FFFF 7FFFFFFF 31 2 GiB Identity Map */ #define MM_USER_MIN 0x00000000##00010000 @@ -65,9 +67,9 @@ #define MM_PAGE_DBLBMP (MM_KERNEL_RANGE|(0xE480##00000000)) #define MM_PAGE_SUPBMP (MM_KERNEL_RANGE|(0xE500##00000000)) -#define MM_LOCALAPIC (MM_KERNEL_RANGE|(0xFD00##00000000)) #define MM_FRACTAL_BASE (MM_KERNEL_RANGE|(0xFE00##00000000)) #define MM_TMPFRAC_BASE (MM_KERNEL_RANGE|(0xFE80##00000000)) +#define MM_LOCALAPIC (MM_KERNEL_RANGE|(0xFF80##00000000)) // === FUNCTIONS === diff --git a/Kernel/arch/x86_64/link.ld b/Kernel/arch/x86_64/link.ld index f1df2299..eb84fcd7 100644 --- a/Kernel/arch/x86_64/link.ld +++ b/Kernel/arch/x86_64/link.ld @@ -35,6 +35,7 @@ SECTIONS { .rodata ALIGN(0x1000): AT(ADDR(.rodata) - _kernel_base) { *(.initpd) *(.rodata) + *(.rodata.*) *(.rdata) . = ALIGN(0x10); diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index ac1fea44..e5c28c2f 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -19,8 +19,8 @@ enum eMMPhys_Ranges }; // === IMPORTS === -extern void gKernelBase; -extern void gKernelEnd; +extern char gKernelBase[]; +extern char gKernelEnd[]; // === PROTOTYPES === void MM_InitPhys_Multiboot(tMBoot_Info *MBoot); diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 6c75aaaf..2ee2d4a5 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -22,10 +22,10 @@ // === IMPORTS === extern tGDT gGDT[]; -extern void APStartup(void); // 16-bit AP startup code +extern void APStartup(void); // 16-bit AP startup code extern Uint GetRIP(void); // start.asm extern Uint64 gInitialPML4[512]; // start.asm -extern void gInitialKernelStack; +extern char gInitialKernelStack[]; extern tSpinlock glThreadListLock; extern int giNumCPUs; extern int giNextTID; diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 3e461fd6..28feb05b 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -15,6 +15,7 @@ // === IMPORTS === void Threads_Dump(void); +void Heap_Stats(void); // === PROTOTYPES === int KB_Install(char **Arguments); @@ -183,9 +184,14 @@ void KB_IRQHandler(int IRQNum) { switch(ch) { - case 'q': *((int*)1) = 0; break; - case 'd': __asm__ __volatile__ ("xchg %bx, %bx"); break; - case 'p': Threads_Dump(); break; + // Kernel Panic (Page Fault) + case 'q': *((int*)1) = 0; return; + // Bochs Magic Breakpoint + case 'd': __asm__ __volatile__ ("xchg %bx, %bx"); return; + // Thread List Dump + case 'p': Threads_Dump(); return; + // Heap Statistics + case 'h': Heap_Stats(); return; } } #endif diff --git a/Kernel/heap.c b/Kernel/heap.c index 1863f56f..1e7ed464 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -26,6 +26,7 @@ void *Heap_Merge(tHeapHead *Head); void *malloc(size_t Bytes); void free(void *Ptr); void Heap_Dump(void); +void Heap_Stats(void); // === GLOBALS === tSpinlock glHeap; @@ -472,6 +473,94 @@ void Heap_Dump(void) } #endif +#if 1 +void Heap_Stats(void) +{ + tHeapHead *head; + int nBlocks = 0; + int nFree = 0; + int totalBytes = 0; + int freeBytes = 0; + int maxAlloc=0, minAlloc=-1; + int avgAlloc, frag, overhead; + + for(head = gHeapStart; + (Uint)head < (Uint)gHeapEnd; + head = (void*)( (Uint)head + head->Size ) + ) + { + nBlocks ++; + totalBytes += head->Size; + if( head->Magic == MAGIC_FREE ) + { + nFree ++; + freeBytes += head->Size; + } + else { + if(maxAlloc < head->Size) maxAlloc = head->Size; + if(minAlloc == -1 || minAlloc > head->Size) + minAlloc = head->Size; + } + } + + Log_Log("Heap", "%i blocks (0x%x bytes)", nBlocks, totalBytes); + Log_Log("Heap", "%i free blocks (0x%x bytes)", nFree, freeBytes); + frag = (nFree-1)*10000/nBlocks; + Log_Log("Heap", "%i.%02i%% Heap Fragmentation", frag/100, frag%100); + avgAlloc = (totalBytes-freeBytes)/(nBlocks-nFree); + overhead = (sizeof(tHeapFoot)+sizeof(tHeapHead))*10000/avgAlloc; + Log_Log("Heap", "Average allocation: %i bytes, Average Overhead: %i.%02i%%", + avgAlloc, overhead/100, overhead%100 + ); + Log_Log("Heap", "Smallest Block: %i bytes, Largest: %i bytes", + minAlloc, maxAlloc); + + // Scan and get distribution + #if 1 + { + struct { + Uint Size; + Uint Count; + } sizeCounts[nBlocks]; + int i; + + memset(sizeCounts, 0, nBlocks*sizeof(sizeCounts[0])); + + for(head = gHeapStart; + (Uint)head < (Uint)gHeapEnd; + head = (void*)( (Uint)head + head->Size ) + ) + { + for( i = 0; i < nBlocks; i ++ ) { + if( sizeCounts[i].Size == 0 ) + break; + if( sizeCounts[i].Size == head->Size ) + break; + } + // Should never reach this part (in a non-concurrent case) + if( i == nBlocks ) continue; + sizeCounts[i].Size = head->Size; + sizeCounts[i].Count ++; + #if 1 + //Log("Heap_Stats: %i %p - 0x%x bytes (%s) (%i)", nBlocks, head, + // head->Size, (head->Magic==MAGIC_FREE?"FREE":"used"), i + // ); + //Log("Heap_Stats: sizeCounts[%i] = {Size:0x%x, Count: %i}", i, + // sizeCounts[i].Size, sizeCounts[i].Count); + #endif + } + + for( i = 0; i < nBlocks && sizeCounts[i].Count; i ++ ) + { + Log("Heap_Stats: 0x%x - %i blocks", + sizeCounts[i].Size, sizeCounts[i].Count + ); + } + } + #endif +} +#endif + // === EXPORTS === EXPORT(malloc); EXPORT(realloc); diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 993aa1f6..0e67fb68 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -6,7 +6,8 @@ #define _COMMON_H #define NULL ((void*)0) -#define PACKED __attribute__ ((packed)) +#define PACKED __attribute__((packed)) +#define UNUSED(x) UNUSED_##x __attribute__((unused)) #define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 )) //#include diff --git a/Kernel/lib.c b/Kernel/lib.c index a7cffd63..9923d7c8 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -232,7 +232,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) pad = ' '; // - Minimum length - if(c == '*') { + if(c == '*') { // Dynamic length minSize = val; val = va_arg(args, Uint); c = *__format++; @@ -300,7 +300,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) // String - Null Terminated Array case 's': - p = (char*)(Uint)val; + p = (char*)(tVAddr)val; printString: if(!p) p = "(null)"; len = strlen(p); @@ -310,7 +310,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) break; case 'C': // Non-Null Terminated Character Array - p = (char*)(Uint)val; + p = (char*)(tVAddr)val; if(!p) goto printString; while(minSize--) PUTCH(*p++); break; diff --git a/Kernel/logging.c b/Kernel/logging.c index 1895b5b5..3d6351d8 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -7,6 +7,8 @@ #include #define PRINT_ON_APPEND 1 +#define USE_RING_BUFFER 1 +#define RING_BUFFER_SIZE 4096 // === CONSTANTS === enum eLogLevels @@ -66,8 +68,13 @@ EXPORT(Log_Debug); // === GLOBALS === tSpinlock glLog; tSpinlock glLogOutput; +#if USE_RING_BUFFER +Uint8 gaLog_RingBufferData[sizeof(tRingBuffer)+RING_BUFFER_SIZE]; +tRingBuffer *gpLog_RingBuffer = (void*)gaLog_RingBufferData; +#else tLogList gLog; tLogList gLog_Levels[NUM_LOG_LEVELS]; +#endif // === CODE === /** @@ -86,16 +93,31 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) //Log("len = %i", len); + #if USE_RING_BUFFER + { + char buf[sizeof(tLogEntry)+len+1]; + ent = (void*)buf; + #else ent = malloc(sizeof(tLogEntry)+len+1); + #endif ent->Time = now(); strncpy(ent->Ident, Ident, 8); ent->Level = Level; ent->Length = len; - vsnprintf( ent->Data, 256, Format, Args ); - - //Log("ent->Ident = '%s'", ent->Ident); - //Log("ent->Data = '%s'", ent->Data); + vsnprintf( ent->Data, len+1, Format, Args ); + #if USE_RING_BUFFER + { + #define LOG_HDR_LEN (14+1+2+8+2) + char newData[ LOG_HDR_LEN + len + 2 + 1 ]; + sprintf( newData, "%014lli%s [%+8s] ", + ent->Time, csaLevelCodes[Level], Ident); + strcpy( newData + LOG_HDR_LEN, ent->Data ); + strcpy( newData + LOG_HDR_LEN + len, "\r\n" ); + gpLog_RingBuffer->Space = RING_BUFFER_SIZE; // Needed to init the buffer + RingBuffer_Write( gpLog_RingBuffer, newData, LOG_HDR_LEN + len + 2 ); + } + #else LOCK( &glLog ); ent->Next = gLog.Tail; @@ -111,11 +133,15 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent; RELEASE( &glLog ); + #endif #if PRINT_ON_APPEND Log_Int_PrintMessage( ent ); #endif + #if USE_RING_BUFFER + } + #endif } /** diff --git a/Kernel/modules.c b/Kernel/modules.c index 92dd8d31..560a19ba 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -2,7 +2,7 @@ * Acess2 * - Module Loader */ -#define DEBUG 0 +#define DEBUG 1 #include #include diff --git a/Kernel/system.c b/Kernel/system.c index 5a2775db..df9ac414 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -99,7 +99,8 @@ void System_ParseCommandLine(char *ArgString) int i; char *str; - Log_Log("Config", "Kernel Invocation \"%s\"", ArgString); + Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString); + Log_Log("Config", "Kernel Invocation '0x%x 0x%x'", ArgString[0], ArgString[1]); // --- Get Arguments --- str = ArgString; diff --git a/Makefile.x86_64.cfg b/Makefile.x86_64.cfg index 0c32d718..024ef135 100644 --- a/Makefile.x86_64.cfg +++ b/Makefile.x86_64.cfg @@ -3,7 +3,7 @@ CC = x86_64-none-elf-gcc LD = x86_64-none-elf-ld DISASM = x86_64-none-elf-objdump -d -M x86-64 -KERNEL_CFLAGS := -mcmodel=kernel -nostdlib -mno-red-zone +KERNEL_CFLAGS := -mcmodel=kernel -nostdlib -mno-red-zone -Wall -Werror DYNMOD_CFLAGS := -mcmodel=small -fPIC -mno-red-zone ARCHDIR = x86_64 diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 9b3de8d1..c21ae6ba 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -253,12 +253,17 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ); // Sanity Check + if( Offset > (Uint64)(heightInChars*widthInChars) ) { + LEAVE('i', 0); + return 0; + } if(y >= heightInChars) { LEAVE('i', 0); return 0; } - if( Offset + Length > heightInChars*widthInChars ) { + + if( (int)Offset + (int)Length > heightInChars*widthInChars ) { Log_Debug("VESA", "%i + %i > %i*%i (%i)", (int)Offset, (int)Length, heightInChars, widthInChars, heightInChars*widthInChars); Length = heightInChars*widthInChars - Offset; @@ -270,7 +275,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) LOG("dest = %p", dest); - for( i = 0; i < Length; i++ ) + for( i = 0; i < (int)Length; i++ ) { VT_Font_Render( chars->Ch, @@ -513,7 +518,7 @@ void Vesa_FlipCursor(void *Arg) // Sanity 1 if(giVesaCursorX < 0 || giVesaCursorY < 0 - || y*pitch + x + giVT_CharHeight*pitch > gpVesaCurMode->fbSize/4) { + || y*pitch + x + giVT_CharHeight*pitch > (int)gpVesaCurMode->fbSize/4) { Debug("Cursor OOB (%i,%i)", x, y); giVesaCursorTimer = -1; return; diff --git a/Modules/Filesystems/Ext2/dir.c b/Modules/Filesystems/Ext2/dir.c index b0d85319..0cadca2b 100644 --- a/Modules/Filesystems/Ext2/dir.c +++ b/Modules/Filesystems/Ext2/dir.c @@ -34,7 +34,8 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) tExt2_Inode inode; tExt2_DirEnt dirent; Uint64 Base; // Block's Base Address - int block = 0, ofs = 0; + int block = 0; + Uint ofs = 0; int entNum = 0; tExt2_Disk *disk = Node->ImplPtr; Uint size; @@ -108,7 +109,8 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) tExt2_Inode inode; tExt2_DirEnt dirent; Uint64 Base; // Block's Base Address - int block = 0, ofs = 0; + int block = 0; + Uint ofs = 0; int entNum = 0; Uint size; int filenameLen = strlen(Filename); diff --git a/Modules/Filesystems/Ext2/ext2.c b/Modules/Filesystems/Ext2/ext2.c index aa15e103..4a2aece0 100644 --- a/Modules/Filesystems/Ext2/ext2.c +++ b/Modules/Filesystems/Ext2/ext2.c @@ -323,7 +323,7 @@ void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk) #define INT_MAX (((long long int)1<<(sizeof(int)*8))-1) // Powers of 3 - for( i = 3; i < ngrp && i < INT_MAX; i *= 3 ) + for( i = 3; i < ngrp && i < INT_MAX/3; i *= 3 ) VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock); // Powers of 5 diff --git a/Modules/Filesystems/Ext2/ext2_common.h b/Modules/Filesystems/Ext2/ext2_common.h index 290b273b..25d296c8 100644 --- a/Modules/Filesystems/Ext2/ext2_common.h +++ b/Modules/Filesystems/Ext2/ext2_common.h @@ -21,7 +21,7 @@ typedef struct { tVFS_Node RootNode; tExt2_SuperBlock SuperBlock; - int BlockSize; + Uint BlockSize; int GroupCount; tExt2_Group Groups[]; diff --git a/Modules/Filesystems/Ext2/write.c b/Modules/Filesystems/Ext2/write.c index e52ebf75..5a7cfc02 100644 --- a/Modules/Filesystems/Ext2/write.c +++ b/Modules/Filesystems/Ext2/write.c @@ -166,7 +166,7 @@ Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 PrevBlock) } // Fast Check - if( bitmap[j/32] == -1 ) { + if( bitmap[j/32] == 0xFFFFFFFF ) { j = (j + 31) & ~31; continue; } diff --git a/Modules/Filesystems/FAT/fat.c b/Modules/Filesystems/FAT/fat.c index bfe52a9e..e3a681af 100644 --- a/Modules/Filesystems/FAT/fat.c +++ b/Modules/Filesystems/FAT/fat.c @@ -340,7 +340,7 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu if(Cluster) *Cluster = cluster; cluster = FAT_int_GetFatValue(disk, cluster); // Check for end of cluster chain - if(cluster == -1) { LEAVE('i', 1); return 1;} + if(cluster == 0xFFFFFFFF) { LEAVE('i', 1); return 1;} } if(Cluster) *Cluster = cluster; } @@ -632,14 +632,14 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) cluster = Node->Inode & 0xFFFFFFFF; // Clamp Size - if(Offset + Length > Node->Size) { + if(Offset >= Node->Size || Offset + Length > Node->Size) { LOG("Reading past EOF (%lli + %lli > %lli), clamped to %lli", Offset, Length, Node->Size, Node->Size - Offset); Length = Node->Size - Offset; } // Reading from within the first cluster only? - if(Offset + Length < bpc) + if((int)Offset + (int)Length < bpc) { LOG("First cluster only"); FAT_int_ReadCluster(disk, cluster, bpc, tmpBuf); @@ -671,7 +671,7 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) pos = bpc - Offset%bpc; // Read 1st Cluster (performs alignment for us) - if( pos == bpc && Length >= bpc ) { + if( pos == bpc && (int)Length >= bpc ) { FAT_int_ReadCluster(disk, cluster, bpc, Buffer); } else { @@ -679,7 +679,7 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) memcpy( Buffer, (void*)( tmpBuf + (bpc-pos) ), - (pos < Length ? pos : Length) + (pos < (int)Length ? (Uint)pos : Length) ); } @@ -724,7 +724,7 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) } // Read final cluster - if( Length - pos == bpc ) + if( (int)Length - pos == bpc ) { FAT_int_ReadCluster( disk, cluster, bpc, (void*)(Buffer+pos) ); } @@ -936,12 +936,14 @@ char *FAT_int_CreateName(fat_filetable *ft, char *LongFileName) */ tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry, int Pos) { - tVFS_Node node = {0}; + tVFS_Node node; tVFS_Node *ret; tFAT_VolInfo *disk = Parent->ImplPtr; ENTER("pParent pFT", Parent, Entry); + memset(&node, 0, sizeof(tVFS_Node)); + // Set Other Data // 0-31: Cluster, 32-63: Parent Cluster node.Inode = Entry->cluster | (Entry->clusterHi<<16) | (Parent->Inode << 32); diff --git a/Modules/IPStack/arp.c b/Modules/IPStack/arp.c index fab74f85..8a18813d 100644 --- a/Modules/IPStack/arp.c +++ b/Modules/IPStack/arp.c @@ -209,7 +209,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe tInterface *iface; // Sanity Check Packet - if( Length < sizeof(tArpRequest4) ) { + if( Length < (int)sizeof(tArpRequest4) ) { Log_Log("ARP", "Recieved undersized packet"); return ; } @@ -276,7 +276,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe } break; case 6: - if( Length < sizeof(tArpRequest6) ) { + if( Length < (int)sizeof(tArpRequest6) ) { Log_Log("ARP", "Recieved undersized packet (IPv6)"); return ; } @@ -314,7 +314,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe ARP_UpdateCache4( req4->SourceIP, From ); break; case 6: - if( Length < sizeof(tArpRequest6) ) { + if( Length < (int)sizeof(tArpRequest6) ) { Log_Debug("ARP", "Recieved undersized packet (IPv6)"); return ; } diff --git a/Modules/IPStack/link.c b/Modules/IPStack/link.c index ef17c937..8316b638 100644 --- a/Modules/IPStack/link.c +++ b/Modules/IPStack/link.c @@ -125,7 +125,7 @@ void Link_WatchDevice(tAdapter *Adapter) ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf); if(ret == -1) break; - if(ret <= sizeof(tEthernetHeader)) { + if(ret <= (int)sizeof(tEthernetHeader)) { Log_Log("NET", "Recieved an undersized packet"); continue; } diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index da7441c4..13bc5615 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -175,7 +175,7 @@ tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name) for( iface = gIP_Interfaces; iface; iface = iface->Next ) { - if( iface->Node.ImplInt == num ) + if( (int)iface->Node.ImplInt == num ) { LEAVE('p', &iface->Node); return &iface->Node; diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index f3faddae..1ebe778f 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -29,7 +29,7 @@ static const struct { {0x10EC, 0x8029}, // Realtek 8029 {0x10EC, 0x8129} // Realtek 8129 }; -#define NUM_COMPAT_DEVICES (sizeof(csaCOMPAT_DEVICES)/sizeof(csaCOMPAT_DEVICES[0])) +#define NUM_COMPAT_DEVICES ((int)(sizeof(csaCOMPAT_DEVICES)/sizeof(csaCOMPAT_DEVICES[0]))) enum eNe2k_Page0Read { CMD = 0, //!< the master command register diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index ad550356..69d21215 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -3,6 +3,7 @@ * - main.c */ #define DEBUG 1 +#define VERSION 0x0032 #include #include #include @@ -75,7 +76,7 @@ void ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value); void ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value); // === GLOBALS === -MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, "PCI", NULL); +MODULE_DEFINE(0, VERSION, i386ATA, ATA_Install, NULL, "PCI", NULL); tDevFS_Driver gATA_DriverInfo = { NULL, "ata", { @@ -90,7 +91,7 @@ tDevFS_Driver gATA_DriverInfo = { tATA_Disk gATA_Disks[MAX_ATA_DISKS]; int giATA_NumNodes; tVFS_Node **gATA_Nodes; -Uint16 gATA_BusMasterBase = 0; +Uint32 gATA_BusMasterBase = 0; Uint8 *gATA_BusMasterBasePtr = 0; int gATA_IRQPri = 14; int gATA_IRQSec = 15; @@ -400,7 +401,7 @@ void ATA_int_MakePartition(tATA_Partition *Part, int Disk, int Num, Uint64 Start void ATA_ParseGPT(int Disk) { ///\todo Support GPT Disks - Warning("GPT Disks are currently unsupported"); + Warning("GPT Disks are currently unsupported (Disk %i)", Disk); } /** @@ -420,7 +421,7 @@ Uint16 ATA_GetBasePort(int Disk) /** * \fn char *ATA_ReadDir(tVFS_Node *Node, int Pos) */ -char *ATA_ReadDir(tVFS_Node *Node, int Pos) +char *ATA_ReadDir(tVFS_Node *UNUSED(Node), int Pos) { if(Pos >= giATA_NumNodes || Pos < 0) return NULL; return strdup( gATA_Nodes[Pos]->ImplPtr ); @@ -429,7 +430,7 @@ char *ATA_ReadDir(tVFS_Node *Node, int Pos) /** * \fn tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name) */ -tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *ATA_FindDir(tVFS_Node *UNUSED(Node), char *Name) { int part; tATA_Disk *disk; @@ -535,15 +536,22 @@ Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) return DrvUtil_WriteBlock(Offset, Length, Buffer, ATA_ReadRaw, ATA_WriteRaw, SECTOR_SIZE, disk); } +const char *csaATA_IOCtls[] = {DRV_IOCTLNAMES, DRV_DISK_IOCTLNAMES, NULL}; /** * \fn int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data) * \brief IO Control Funtion */ -int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data) +int ATA_IOCtl(tVFS_Node *UNUSED(Node), int Id, void *Data) { switch(Id) { - case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; + BASE_IOCTLS(DRV_TYPE_DISK, "i386ATA", VERSION, csaATA_IOCtls); + + case DISK_IOCTL_GETBLOCKSIZE: + return 512; + + default: + return 0; } return 0; } @@ -652,7 +660,6 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) gaATA_IRQs[cont] = 0; // Set up transfer - outb(base+0x01, 0x00); if( Address > 0x0FFFFFFF ) // Use LBA48 { outb(base+0x6, 0x40 | (disk << 4)); @@ -666,16 +673,19 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) outb(base+0x06, 0xE0 | (disk << 4) | ((Address >> 24) & 0x0F)); // Magic, Disk, High addr } + outb(base+0x01, 0x01); //? outb(base+0x02, (Uint8) Count); // Sector Count outb(base+0x03, (Uint8) Address); // Low Addr outb(base+0x04, (Uint8) (Address >> 8)); // Middle Addr outb(base+0x05, (Uint8) (Address >> 16)); // High Addr LOG("Starting Transfer"); + LOG("gATA_PRDTs[%i].Bytes = %i", cont, gATA_PRDTs[cont].Bytes); if( Address > 0x0FFFFFFF ) outb(base+0x07, HDD_DMA_R48); // Read Command (LBA48) else outb(base+0x07, HDD_DMA_R28); // Read Command (LBA28) + // Start transfer ATA_int_BusMasterWriteByte( cont << 3, 9 ); // Read and start @@ -688,6 +698,7 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) val = inb(base+0x7); LOG("Status byte = 0x%02x", val); + LOG("gATA_PRDTs[%i].Bytes = %i", cont, gATA_PRDTs[cont].Bytes); LOG("Transfer Completed & Acknowledged"); // Copy to destination buffer @@ -769,7 +780,7 @@ int ATA_WriteDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) /** * \fn void ATA_IRQHandlerPri(int unused) */ -void ATA_IRQHandlerPri(int unused) +void ATA_IRQHandlerPri(int UNUSED(IRQ)) { Uint8 val; @@ -787,7 +798,7 @@ void ATA_IRQHandlerPri(int unused) /** * \fn void ATA_IRQHandlerSec(int unused) */ -void ATA_IRQHandlerSec(int unused) +void ATA_IRQHandlerSec(int UNUSED(IRQ)) { Uint8 val; // IRQ bit set for Secondary Controller diff --git a/Modules/Storage/ATA/mbr.c b/Modules/Storage/ATA/mbr.c index e36d54b1..bfb488a1 100644 --- a/Modules/Storage/ATA/mbr.c +++ b/Modules/Storage/ATA/mbr.c @@ -54,7 +54,7 @@ void ATA_ParseMBR(int Disk, tMBR *MBR) while(extendedLBA != 0) { extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len); - if( extendedLBA == -1 ) return ; + if( extendedLBA == 0xFFFFFFFF ) return ; gATA_Disks[Disk].NumPartitions ++; } LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions); diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index cc75bfcd..b0bbf784 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -227,7 +227,7 @@ void FDD_UnloadModule() * \fn char *FDD_ReadDir(tVFS_Node *Node, int pos) * \brief Read Directory */ -char *FDD_ReadDir(tVFS_Node *Node, int Pos) +char *FDD_ReadDir(tVFS_Node *UNUSED(Node), int Pos) { char name[2] = "0\0"; @@ -244,7 +244,7 @@ char *FDD_ReadDir(tVFS_Node *Node, int Pos) * \fn tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename); * \brief Find File Routine (for vfs_node) */ -tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *Filename) +tVFS_Node *FDD_FindDir(tVFS_Node *UNUSED(Node), char *Filename) { int i; @@ -287,14 +287,11 @@ static const char *casIOCTLS[] = {DRV_IOCTLNAMES,DRV_DISK_IOCTLNAMES,NULL}; * \fn int FDD_IOCtl(tVFS_Node *Node, int id, void *data) * \brief Stub ioctl function */ -int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data) +int FDD_IOCtl(tVFS_Node *UNUSED(Node), int ID, void *Data) { switch(ID) { - case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; - case DRV_IOCTL_IDENT: return ModUtil_SetIdent(Data, "FDD"); - case DRV_IOCTL_VERSION: return FDD_VERSION; - case DRV_IOCTL_LOOKUP: return ModUtil_LookupString((char**)casIOCTLS, Data); + BASE_IOCTLS(DRV_TYPE_DISK, "FDD", FDD_VERSION, casIOCTLS); case DISK_IOCTL_GETBLOCKSIZE: return 512; -- 2.20.1