From 6749674b892a0865abc22f9a6ec9a624ff40a283 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 Oct 2009 19:19:57 +0800 Subject: [PATCH] Multiple changes (Module Interopability, Timers, FDD Driver, VFS Bugs) - Changed kernel to be compiled withough -fleading-underscore to allow modules to be statically linked with the kernel successfully. - Moved the BochsVBE driver to the Modules tree - Cleaned up and disabled debug in the FDD driver - Fixed bugs in VFS_MkNod that caused an infinite loop - Cleanup in FAT and EXT2 Drivers --- Kernel/Makefile | 2 +- Kernel/arch/x86/desctab.asm | 72 +++--- Kernel/arch/x86/lib.c | 8 + Kernel/arch/x86/link.ld | 10 +- Kernel/arch/x86/start.asm | 42 ++-- Kernel/arch/x86/time.c | 8 +- Kernel/drv/bochsvbe.c | 435 ------------------------------------ Kernel/drv/fdd.c | 400 ++++++++++++++++++--------------- Kernel/include/common.h | 11 +- Kernel/include/modules.h | 8 +- Kernel/vfs/dir.c | 17 +- Kernel/vfs/fs/ext2.c | 33 +-- Kernel/vfs/fs/fat.c | 4 +- 13 files changed, 333 insertions(+), 717 deletions(-) delete mode 100644 Kernel/drv/bochsvbe.c diff --git a/Kernel/Makefile b/Kernel/Makefile index 5aeee685..45d2f023 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -11,7 +11,7 @@ MAKEDEP = $(CC) -M CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -DARCH=$(ARCH) -CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin -fleading-underscore +CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin ASFLAGS += -D ARCH=\"$(ARCH)\" LDFLAGS += -T arch/$(ARCHDIR)/link.ld diff --git a/Kernel/arch/x86/desctab.asm b/Kernel/arch/x86/desctab.asm index f4039501..969752c7 100644 --- a/Kernel/arch/x86/desctab.asm +++ b/Kernel/arch/x86/desctab.asm @@ -12,8 +12,8 @@ GDT_SIZE equ (1+2*2+1+MAX_CPUS)*8 [section .data] ; GDT -[global _gGDT] -_gGDT: +[global gGDT] +gGDT: ; PL0 - Kernel ; PL3 - User dd 0x00000000, 0x00000000 ; 00 NULL Entry @@ -23,22 +23,22 @@ _gGDT: dd 0x0000FFFF, 0x00CFF200 ; 20 PL3 Data dd 0, 0 ; Double Fault TSS times MAX_CPUS dd 0, 0 -_gGDTptr: +gGDTptr: dw GDT_SIZE-1 - dd _gGDT + dd gGDT ; IDT ALIGN 8 -_gIDT: +gIDT: times 256 dd 0x00080000,0x00000F00 -_gIDTPtr: +gIDTPtr: dw 256 * 16 - 1 ; Limit - dd _gIDT ; Base + dd gIDT ; Base [section .text] -[global _Desctab_Install] -_Desctab_Install: +[global Desctab_Install] +Desctab_Install: ; Set GDT - lgdt [_gGDTptr] + lgdt [gGDTptr] mov ax, 0x10 ; PL0 Data mov ss, ax mov ds, ax @@ -50,18 +50,18 @@ _Desctab_Install: ; Set IDT %macro SETISR 1 - mov eax, _Isr%1 - mov WORD [_gIDT + %1*8], ax + mov eax, Isr%1 + mov WORD [gIDT + %1*8], ax shr eax, 16 - mov WORD [_gIDT + %1*8+6], ax - mov ax, WORD [_gIDT + %1*8 + 4] + mov WORD [gIDT + %1*8+6], ax + mov ax, WORD [gIDT + %1*8 + 4] or ax, 0x8000 - mov WORD [_gIDT + %1*8 + 4], ax + mov WORD [gIDT + %1*8 + 4], ax %endmacro %macro SETUSER 1 - mov ax, WORD [_gIDT + %1*8 + 4] + mov ax, WORD [gIDT + %1*8 + 4] or ax, 0x6000 - mov WORD [_gIDT + %1*8 + 4], ax + mov WORD [gIDT + %1*8 + 4], ax %endmacro %assign i 0 %rep 32 @@ -79,7 +79,7 @@ _Desctab_Install: %endrep ; Load IDT - lidt [_gIDTPtr] + lidt [gIDTPtr] ; Remap PIC push edx ; Save EDX @@ -117,15 +117,15 @@ _Desctab_Install: ; = Define ISRs = ; =============== %macro ISR_ERRNO 1 -[global _Isr%1] -_Isr%1: +[global Isr%1] +Isr%1: ;xchg bx, bx push %1 jmp ErrorCommon %endmacro %macro ISR_NOERR 1 -[global _Isr%1] -_Isr%1: +[global Isr%1] +Isr%1: xchg bx, bx push 0 push %1 @@ -133,16 +133,16 @@ _Isr%1: %endmacro %macro DEF_SYSCALL 1 -[global _Isr%1] -_Isr%1: +[global Isr%1] +Isr%1: push 0 push %1 jmp SyscallCommon %endmacro %macro DEF_IRQ 1 -[global _Isr%1] -_Isr%1: +[global Isr%1] +Isr%1: ;cli ; HACK! push 0 push %1 @@ -186,8 +186,8 @@ DEF_SYSCALL 0xAC ; Acess System Call ; IRQs ; - Timer -[global _Isr240] -_Isr240: +[global Isr240] +Isr240: push 0 jmp SchedulerBase ; - Assignable @@ -200,7 +200,7 @@ _Isr240: ; --------------------- ; Common error handling ; --------------------- -[extern _ErrorHandler] +[extern ErrorHandler] ErrorCommon: pusha push ds @@ -209,7 +209,7 @@ ErrorCommon: push gs push esp - call _ErrorHandler + call ErrorHandler add esp, 4 pop gs @@ -223,7 +223,7 @@ ErrorCommon: ; -------------------------- ; Common System Call Handler ; -------------------------- -[extern _SyscallHandler] +[extern SyscallHandler] SyscallCommon: pusha push ds @@ -232,7 +232,7 @@ SyscallCommon: push gs push esp - call _SyscallHandler + call SyscallHandler add esp, 4 pop gs @@ -246,7 +246,7 @@ SyscallCommon: ; ------------ ; IRQ Handling ; ------------ -[extern _IRQ_Handler] +[extern IRQ_Handler] IRQCommon: pusha push ds @@ -255,7 +255,7 @@ IRQCommon: push gs push esp - call _IRQ_Handler + call IRQ_Handler add esp, 4 pop gs @@ -269,7 +269,7 @@ IRQCommon: ; -------------- ; Task Scheduler ; -------------- -[extern _Proc_Scheduler] +[extern Proc_Scheduler] SchedulerBase: pusha push ds @@ -280,7 +280,7 @@ SchedulerBase: mov eax, [esp+12*4] ; CPU Number push eax ; Pus as argument - call _Proc_Scheduler + call Proc_Scheduler add esp, 4 ; Remove Argument diff --git a/Kernel/arch/x86/lib.c b/Kernel/arch/x86/lib.c index 1bbdeabb..7e79c711 100644 --- a/Kernel/arch/x86/lib.c +++ b/Kernel/arch/x86/lib.c @@ -176,6 +176,14 @@ Uint16 BigEndian16(Uint16 Val) { return ((Val&0xFF)<<8) | ((Val>>8)&0xFF); } +Uint32 LittleEndian32(Uint32 Val) +{ + return Val; +} +Uint32 BigEndian32(Uint32 Val) +{ + return ((Val&0xFF)<<24) | ((Val&0xFF00)<<8) | ((Val>>8)&0xFF00) | ((Val>>24)&0xFF); +} // --- EXPORTS --- EXPORT(memcpy); EXPORT(memset); diff --git a/Kernel/arch/x86/link.ld b/Kernel/arch/x86/link.ld index 93066bce..7bce7196 100644 --- a/Kernel/arch/x86/link.ld +++ b/Kernel/arch/x86/link.ld @@ -28,13 +28,13 @@ SECTIONS { *(.initpd) *(.rodata) *(.rdata) - _gKernelModules = .; + gKernelModules = .; *(KMODULES) - _gKernelModulesEnd = .; + gKernelModulesEnd = .; . = ALIGN(4); - _gKernelSymbols = .; + gKernelSymbols = .; *(KEXPORT) - _gKernelSymbolsEnd = .; + gKernelSymbolsEnd = .; } @@ -52,5 +52,5 @@ SECTIONS { *(.bss) _ebss = .; } - _gKernelEnd = (. + 0xFFF)&0xFFFFF000; + gKernelEnd = (. + 0xFFF)&0xFFFFF000; } diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index 0c2508b9..41351600 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -21,14 +21,14 @@ mboot: dd mboot - KERNEL_BASE ;Location of Multiboot Header [section .text] -[extern _kmain] +[extern kmain] [global start] start: ; Set up stack - mov esp, _Kernel_Stack_Top + mov esp, Kernel_Stack_Top ; Start Paging - mov ecx, _gaInitPageDir - KERNEL_BASE + mov ecx, gaInitPageDir - KERNEL_BASE mov cr3, ecx mov ecx, cr0 @@ -39,12 +39,12 @@ start: jmp ecx .higherHalf: - mov DWORD [_gaInitPageDir], 0 + mov DWORD [gaInitPageDir], 0 ; Call the kernel push ebx ; Multiboot Info push eax ; Multiboot Magic Value - call _kmain + call kmain ; Halt the Machine cli @@ -52,20 +52,20 @@ start: hlt jmp .hlt -[global _GetEIP] -_GetEIP: +[global GetEIP] +GetEIP: mov eax, [esp] ret -[extern _Proc_Clone] -[extern _Threads_Exit] -[global _SpawnTask] -_SpawnTask: +[extern Proc_Clone] +[extern Threads_Exit] +[global SpawnTask] +SpawnTask: ; Call Proc_Clone with Flags=0 xor eax, eax push eax push eax - call _Proc_Clone + call Proc_Clone add esp, 8 ; Remove arguments from stack test eax, eax @@ -77,29 +77,29 @@ _SpawnTask: ; Child push edx ; Argument call ebx ; Function - call _Threads_Exit ; Kill Thread + call Threads_Exit ; Kill Thread .parent: ret [section .initpd] -[global _gaInitPageDir] -[global _gaInitPageTable] +[global gaInitPageDir] +[global gaInitPageTable] align 0x1000 -_gaInitPageDir: - dd _gaInitPageTable-KERNEL_BASE+3 ; 0x00 +gaInitPageDir: + dd gaInitPageTable-KERNEL_BASE+3 ; 0x00 times 1024-256-1 dd 0 - dd _gaInitPageTable-KERNEL_BASE+3 ; 0xC0 + dd gaInitPageTable-KERNEL_BASE+3 ; 0xC0 times 256-1 dd 0 align 0x1000 -_gaInitPageTable: +gaInitPageTable: %assign i 0 %rep 1024 dd i*0x1000+3 %assign i i+1 %endrep -[global _Kernel_Stack_Top] +[global Kernel_Stack_Top] ALIGN 0x1000 times 1024 dd 0 -_Kernel_Stack_Top: +Kernel_Stack_Top: diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 9cccec7c..79ea4d08 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -80,7 +80,7 @@ void Time_Interrupt() //Log("giTimestamp = %lli", giTimestamp); - //Timer_CallTimers(); + Timer_CallTimers(); // Make sure the RTC Fires again outb(0x70, 0x0C); // Select register C @@ -127,9 +127,7 @@ void Timer_CallTimers() i < NUM_TIMERS; i ++) { - //Log("Timer %i", i); if(gTimers[i].Callback == NULL) continue; - Log("%i - %lli < %lli", i, giTimestamp, gTimers[i].FiresAfter); if(giTimestamp < gTimers[i].FiresAfter) continue; callback = gTimers[i].Callback; gTimers[i].Callback = NULL; @@ -154,8 +152,8 @@ int Time_CreateTimer(int Delta, void *Callback, void *Argument) gTimers[ret].Callback = Callback; gTimers[ret].FiresAfter = giTimestamp + Delta; gTimers[ret].Argument = Argument; - Log("Callback = %p", Callback); - Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter); + //Log("Callback = %p", Callback); + //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter); return ret; } return -1; diff --git a/Kernel/drv/bochsvbe.c b/Kernel/drv/bochsvbe.c deleted file mode 100644 index 2014cb85..00000000 --- a/Kernel/drv/bochsvbe.c +++ /dev/null @@ -1,435 +0,0 @@ -/** - * \file drv_bochsvbe.c - * \brief BGA (Bochs Graphic Adapter) Driver - * \note for AcessOS Version 1 - * \warning This driver does NOT support the Bochs PCI VGA driver -*/ -#include -#include -#include -#include -#include -#include - -#define DEBUG 0 -#if DEBUG -# define DEBUGS(v...) SysDebug(v) -#else -# define DEBUGS(v...) -#endif - -//#define INT static -#define INT - -// === TYPEDEFS === -typedef struct { - Uint16 width; - Uint16 height; - Uint16 bpp; - Uint16 flags; - Uint32 fbSize; -} t_bga_mode; - -// === CONSTANTS === -enum eMode_Flags { - MODEFLAG_TEXT = 1 -}; -#define BGA_LFB_MAXSIZE (1024*768*4) -#define VBE_DISPI_BANK_ADDRESS 0xA0000 -#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000 -#define VBE_DISPI_IOPORT_INDEX 0x01CE -#define VBE_DISPI_IOPORT_DATA 0x01CF -#define VBE_DISPI_DISABLED 0x00 -#define VBE_DISPI_ENABLED 0x01 -#define VBE_DISPI_LFB_ENABLED 0x40 -#define VBE_DISPI_NOCLEARMEM 0x80 -enum { - VBE_DISPI_INDEX_ID, - VBE_DISPI_INDEX_XRES, - VBE_DISPI_INDEX_YRES, - VBE_DISPI_INDEX_BPP, - VBE_DISPI_INDEX_ENABLE, - VBE_DISPI_INDEX_BANK, - VBE_DISPI_INDEX_VIRT_WIDTH, - VBE_DISPI_INDEX_VIRT_HEIGHT, - VBE_DISPI_INDEX_X_OFFSET, - VBE_DISPI_INDEX_Y_OFFSET -}; - - -// === PROTOTYPES === -// Driver - int BGA_Install(char **Arguments); -void BGA_Uninstall(); -// Internal -void BGA_int_WriteRegister(Uint16 reg, Uint16 value); -Uint16 BGA_int_ReadRegister(Uint16 reg); -void BGA_int_SetBank(Uint16 bank); -void BGA_int_SetMode(Uint16 width, Uint16 height); - int BGA_int_UpdateMode(int id); - int BGA_int_FindMode(tVideo_IOCtl_Mode *info); - int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info); - int BGA_int_MapFB(void *Dest); -// Filesystem -Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); -Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); - int BGA_Ioctl(tVFS_Node *node, int id, void *data); - -// === GLOBALS === -MODULE_DEFINE(0, 0x0032, BochsVBE, BGA_Install, NULL, NULL); -tDevFS_Driver gBGA_DriverStruct = { - NULL, "BochsGA", - { - .Read = BGA_Read, - .Write = BGA_Write, - .IOCtl = BGA_Ioctl - } -}; - int giBGA_CurrentMode = -1; - int giBGA_DriverId = -1; -Uint *gBGA_Framebuffer; -t_bga_mode gBGA_Modes[] = { - {}, - { 80,25, 32, MODEFLAG_TEXT, 80*25*8}, // 640 x 480 - {100,37, 32, MODEFLAG_TEXT, 100*37*8}, // 800 x 600 - {640,480,8, 0, 640*480}, - {640,480,32, 0, 640*480*4}, - {800,600,8, 0, 800*600}, - {800,600,32, 0, 800*600*4}, -}; -#define BGA_MODE_COUNT (sizeof(gBGA_Modes)/sizeof(gBGA_Modes[0])) - -// === CODE === -/** - * \fn int BGA_Install(char **Arguments) - */ -int BGA_Install(char **Arguments) -{ - int bga_version = 0; - - // Check BGA Version - bga_version = BGA_int_ReadRegister(VBE_DISPI_INDEX_ID); - // NOTE: This driver was written for 0xB0C4, but they seem to be backwards compatable - if(bga_version < 0xB0C4 || bga_version > 0xB0C5) { - Warning("[BGA ] Bochs Adapter Version is not 0xB0C4 or 0xB0C5, instead 0x%x", bga_version); - return 0; - } - - // Install Device - giBGA_DriverId = DevFS_AddDevice( &gBGA_DriverStruct ); - if(giBGA_DriverId == -1) { - Warning("[BGA ] Unable to register with DevFS, maybe already loaded?"); - return 0; - } - - // Map Framebuffer to hardware address - gBGA_Framebuffer = (void *) MM_MapHWPage(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb) - - return 1; -} - -/** - * \fn void BGA_Uninstall() - */ -void BGA_Uninstall() -{ - //DevFS_DelDevice( giBGA_DriverId ); - MM_UnmapHWPage( VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768 ); -} - -/** - * \fn Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) - * \brief Read from the framebuffer - */ -Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) -{ - // Check Mode - if(giBGA_CurrentMode == -1) return -1; - - // Check Offset and Length against Framebuffer Size - if(off+len > gBGA_Modes[giBGA_CurrentMode].fbSize) - return -1; - - // Copy from Framebuffer - memcpy(buffer, (void*)((Uint)gBGA_Framebuffer + (Uint)off), len); - return len; -} - -/** - * \fn Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) - * \brief Write to the framebuffer - */ -Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) -{ - ENTER("xoff xlen", off, len); - - // Check Mode - if(giBGA_CurrentMode == -1) { - LEAVE('i', -1); - return -1; - } - - // Check Input against Frambuffer Size - if(off+len > gBGA_Modes[giBGA_CurrentMode].fbSize) { - LEAVE('i', -1); - return -1; - } - - // Text Mode - if( gBGA_Modes[giBGA_CurrentMode].flags & MODEFLAG_TEXT ) - { - tVT_Char *chars = buffer; - int pitch = gBGA_Modes[giBGA_CurrentMode].width * giVT_CharWidth; - Uint32 *dest; - dest = (void*)gBGA_Framebuffer; - dest += off * giVT_CharWidth; - len /= sizeof(tVT_Char); - while(len--) - { - VT_Font_Render( - chars->Ch, - dest, pitch, - VT_Colour12to24(chars->BGCol), - VT_Colour12to24(chars->FGCol) - ); - dest += giVT_CharWidth; - chars++; - } - } - else - { - Uint8 *destBuf = (Uint8*) ((Uint)gBGA_Framebuffer + (Uint)off); - - LOG("buffer = %p\n", buffer); - LOG("Updating Framebuffer (%p to %p)\n", - destBuf, destBuf + (Uint)len); - - - // Copy to Frambuffer - memcpy(destBuf, buffer, len); - - LOG("BGA Framebuffer updated\n"); - } - - LEAVE('i', len); - return len; -} - -/** - * \fn INT int BGA_Ioctl(tVFS_Node *node, int id, void *data) - * \brief Handle messages to the device - */ -INT int BGA_Ioctl(tVFS_Node *node, int id, void *data) -{ - int ret = -2; - ENTER("pNode iId pData", node, id, data); - - switch(id) - { - case DRV_IOCTL_TYPE: - ret = DRV_TYPE_VIDEO; - break; - case DRV_IOCTL_IDENT: - memcpy(data, "BGA1", 4); - ret = 1; - break; - case DRV_IOCTL_VERSION: - ret = 0x100; - break; - case DRV_IOCTL_LOOKUP: // TODO: Implement - ret = 0; - break; - - case VIDEO_IOCTL_SETMODE: - ret = BGA_int_UpdateMode(*(int*)(data)); - break; - - case VIDEO_IOCTL_GETMODE: - ret = giBGA_CurrentMode; - break; - - case VIDEO_IOCTL_FINDMODE: - ret = BGA_int_FindMode((tVideo_IOCtl_Mode*)data); - break; - - case VIDEO_IOCTL_MODEINFO: - ret = BGA_int_ModeInfo((tVideo_IOCtl_Mode*)data); - break; - - // Request Access to LFB - case VIDEO_IOCTL_REQLFB: - ret = BGA_int_MapFB( *(void**)data ); - break; - - default: - LEAVE('i', -2); - return -2; - } - - LEAVE('i', ret); - return ret; -} - -//== Internal Functions == -/** - * \fn void BGA_int_WriteRegister(Uint16 reg, Uint16 value) - * \brief Writes to a BGA register - */ -void BGA_int_WriteRegister(Uint16 reg, Uint16 value) -{ - outw(VBE_DISPI_IOPORT_INDEX, reg); - outw(VBE_DISPI_IOPORT_DATA, value); -} - -INT Uint16 BGA_int_ReadRegister(Uint16 reg) -{ - outw(VBE_DISPI_IOPORT_INDEX, reg); - return inw(VBE_DISPI_IOPORT_DATA); -} - -#if 0 -INT void BGA_int_SetBank(Uint16 bank) -{ - BGA_int_WriteRegister(VBE_DISPI_INDEX_BANK, bank); -} -#endif - -/** - * \fn void BGA_int_SetMode(Uint16 width, Uint16 height, Uint16 bpp) - * \brief Sets the video mode from the dimensions and bpp given - */ -void BGA_int_SetMode(Uint16 width, Uint16 height) -{ - DEBUGS("BGA_int_SetMode: (width=%i, height=%i, bpp=%i)\n", width, height, bpp); - BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED); - BGA_int_WriteRegister(VBE_DISPI_INDEX_XRES, width); - BGA_int_WriteRegister(VBE_DISPI_INDEX_YRES, height); - BGA_int_WriteRegister(VBE_DISPI_INDEX_BPP, 32); - BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM | VBE_DISPI_LFB_ENABLED); - //BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM); -} - -/** - * \fn int BGA_int_UpdateMode(int id) - * \brief Set current vide mode given a mode id - */ -int BGA_int_UpdateMode(int id) -{ - // Sanity Check - if(id < 0 || id >= BGA_MODE_COUNT) return -1; - - // Check if it is a text mode - if( gBGA_Modes[id].flags & MODEFLAG_TEXT ) - BGA_int_SetMode( - gBGA_Modes[id].width*giVT_CharWidth, - gBGA_Modes[id].height*giVT_CharHeight); - else // Graphics? - BGA_int_SetMode( - gBGA_Modes[id].width, - gBGA_Modes[id].height); - - giBGA_CurrentMode = id; - return id; -} - -/** - * \fn int BGA_int_FindMode(tVideo_IOCtl_Mode *info) - * \brief Find a mode matching the given options - */ -int BGA_int_FindMode(tVideo_IOCtl_Mode *info) -{ - int i; - int best = -1, bestFactor = 1000; - int factor, tmp; - int rqdProduct = info->width * info->height * info->bpp; - - DEBUGS("BGA_int_FindMode: (info={width:%i,height:%i,bpp:%i})\n", info->width, info->height, info->bpp); - - for(i = 0; i < BGA_MODE_COUNT; i++) - { - #if DEBUG >= 2 - LogF("Mode %i (%ix%ix%i), ", i, gBGA_Modes[i].width, gBGA_Modes[i].height, gBGA_Modes[i].bpp); - #endif - - if(gBGA_Modes[i].width == info->width - && gBGA_Modes[i].height == info->height - && gBGA_Modes[i].bpp == info->bpp) - { - #if DEBUG >= 2 - LogF("Perfect!\n"); - #endif - best = i; - break; - } - - tmp = gBGA_Modes[i].width * gBGA_Modes[i].height * gBGA_Modes[i].bpp; - tmp -= rqdProduct; - tmp = tmp < 0 ? -tmp : tmp; - factor = tmp * 100 / rqdProduct; - - #if DEBUG >= 2 - LogF("factor = %i\n", factor); - #endif - - if(factor < bestFactor) - { - bestFactor = factor; - best = i; - } - } - info->id = best; - info->width = gBGA_Modes[best].width; - info->height = gBGA_Modes[best].height; - info->bpp = gBGA_Modes[best].bpp; - return best; -} - -/** - * \fn int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info) - * \brief Get mode information - */ -int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info) -{ - if(!info) return -1; - if(MM_GetPhysAddr((Uint)info) == 0) - return -1; - - if(info->id < 0 || info->id >= BGA_MODE_COUNT) return -1; - - info->width = gBGA_Modes[info->id].width; - info->height = gBGA_Modes[info->id].height; - info->bpp = gBGA_Modes[info->id].bpp; - - return 1; -} - -/** - * \fn int BGA_int_MapFB(void *Dest) - * \brief Map the framebuffer into a process's space - * \param Dest User address to load to - */ -int BGA_int_MapFB(void *Dest) -{ - Uint i; - Uint pages; - - // Sanity Check - if((Uint)Dest > 0xC0000000) return 0; - if(gBGA_Modes[giBGA_CurrentMode].bpp < 15) return 0; // Only non-pallete modes are supported - - // Count required pages - pages = (gBGA_Modes[giBGA_CurrentMode].fbSize + 0xFFF) >> 12; - - // Check if there is space - for( i = 0; i < pages; i++ ) - { - if(MM_GetPhysAddr( (Uint)Dest + (i << 12) )) - return 0; - } - - // Map - for( i = 0; i < pages; i++ ) - MM_Map( (Uint)Dest + (i<<12), VBE_DISPI_LFB_PHYSICAL_ADDRESS + (i<<12) ); - - return 1; -} diff --git a/Kernel/drv/fdd.c b/Kernel/drv/fdd.c index 448e87d0..a827ecda 100644 --- a/Kernel/drv/fdd.c +++ b/Kernel/drv/fdd.c @@ -2,7 +2,7 @@ * AcessOS 0.1 * Floppy Disk Access Code */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include @@ -11,10 +11,11 @@ #define WARN 0 -// Version Information -#define FDD_VER_MAJ 0 -#define FDD_VER_MIN 75 +// === CONSTANTS === +// --- Current Version +#define FDD_VERSION ((0<<8)|(75)) +// --- Options #define USE_CACHE 1 // Use Sector Cache #define CACHE_SIZE 32 // Number of cachable sectors #define FDD_SEEK_TIMEOUT 10 // Timeout for a seek operation @@ -22,26 +23,31 @@ #define MOTOR_OFF_DELAY 2000 // Miliseconds // === TYPEDEFS === +/** + * \brief Representation of a floppy drive + */ typedef struct { int type; volatile int motorState; //2 - On, 1 - Spinup, 0 - Off int track[2]; int timer; - char Name[2]; tVFS_Node Node; } t_floppyDevice; +/** + * \brief Cached Sector + */ typedef struct { Uint64 timestamp; Uint16 disk; Uint16 sector; // Allows 32Mb of addressable space (Plenty for FDD) - char data[512]; + Uint8 data[512]; } t_floppySector; // === CONSTANTS === -static const char *cFDD_TYPES[] = {"None", "360kB 5.25\"", "1.2MB 5.25\"", "720kB 3.5\"", "1.44MB 3.5\"", "2.88MB 3.5\"" }; -static const int cFDD_SIZES[] = { 0, 360*1024, 1200*1024, 720*1024, 1440*1024, 2880*1024 }; -static const short cPORTBASE[] = {0x3F0, 0x370 }; +static const char *cFDD_TYPES[] = {"None", "360kB 5.25\"", "1.2MB 5.25\"", "720kB 3.5\"", "1.44MB 3.5\"", "2.88MB 3.5\"" }; +static const int cFDD_SIZES[] = { 0, 360*1024, 1200*1024, 720*1024, 1440*1024, 2880*1024 }; +static const short cPORTBASE[] = { 0x3F0, 0x370 }; enum FloppyPorts { PORT_STATUSA = 0x0, @@ -70,32 +76,39 @@ enum FloppyCommands { }; // === PROTOTYPES === +// --- Filesystem + int FDD_Install(char **Arguments); char *FDD_ReadDir(tVFS_Node *Node, int pos); tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, char *Name); -static int fdd_readSector(int disk, int lba, void *buf); + int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data); +Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); +// --- Raw Disk Access + int FDD_ReadSector(int disk, int lba, void *buf); +// --- Helpers +void FDD_IRQHandler(int Num); void FDD_WaitIRQ(); void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl); -static void FDD_AquireSpinlock(); -static void inline FDD_FreeSpinlock(); +inline void FDD_AquireSpinlock(); +inline void FDD_FreeSpinlock(); #if USE_CACHE -static inline void FDD_AquireCacheSpinlock(); -static inline void FDD_FreeCacheSpinlock(); +inline void FDD_AquireCacheSpinlock(); +inline void FDD_FreeCacheSpinlock(); #endif -static void sendbyte(int base, char byte); -static int getbyte(int base); -static int seekTrack(int disk, int head, int track); -static void stop_motor(int disk); -static void start_motor(int disk); -static int get_dims(int type, int lba, int *c, int *h, int *s, int *spt); - int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data); -Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); - int FDD_Install(char **Arguments); +void FDD_int_SendByte(int base, char byte); + int FDD_int_GetByte(int base); +void FDD_Reset(int id); +void FDD_Recalibrate(int disk); + int FDD_int_SeekTrack(int disk, int head, int track); +void FDD_int_TimerCallback(int arg); +void FDD_int_StopMotor(int disk); +void FDD_int_StartMotor(int disk); + int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt); // === GLOBALS === -MODULE_DEFINE(0, 0x004B, FDD, FDD_Install, NULL, NULL); -static t_floppyDevice fdd_devices[2]; -static volatile int fdd_inUse = 0; -static volatile int fdd_irq6 = 0; +MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, NULL); +t_floppyDevice gFDD_Devices[2]; +volatile int fdd_inUse = 0; +volatile int fdd_irq6 = 0; tDevFS_Driver gFDD_DriverInfo = { NULL, "fdd", { @@ -109,18 +122,74 @@ tDevFS_Driver gFDD_DriverInfo = { } }; #if USE_CACHE -static int siFDD_CacheInUse = 0; -static int siFDD_SectorCacheSize = CACHE_SIZE; -static t_floppySector sFDD_SectorCache[CACHE_SIZE]; +int siFDD_CacheInUse = 0; +int siFDD_SectorCacheSize = CACHE_SIZE; +t_floppySector sFDD_SectorCache[CACHE_SIZE]; #endif // === CODE === +/** + * \fn int FDD_Install(char **Arguments) + * \brief Installs floppy driver + */ +int FDD_Install(char **Arguments) +{ + Uint8 data; + + // Determine Floppy Types (From CMOS) + outb(0x70, 0x10); + data = inb(0x71); + gFDD_Devices[0].type = data >> 4; + gFDD_Devices[1].type = data & 0xF; + gFDD_Devices[0].track[0] = -1; + gFDD_Devices[1].track[1] = -1; + + // Clear FDD IRQ Flag + FDD_SensInt(0x3F0, NULL, NULL); + // Install IRQ6 Handler + IRQ_AddHandler(6, FDD_IRQHandler); + // Reset Primary FDD Controller + FDD_Reset(0); + + Log("[FDD ] Detected Disk 0: %s and Disk 1: %s\n", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); + + // Initialise Root Node + gFDD_DriverInfo.RootNode.CTime = gFDD_DriverInfo.RootNode.MTime + = gFDD_DriverInfo.RootNode.ATime = now(); + + // Initialise Child Nodes + gFDD_Devices[0].Node.Inode = 0; + gFDD_Devices[0].Node.Flags = 0; + gFDD_Devices[0].Node.NumACLs = 0; + gFDD_Devices[0].Node.Read = FDD_ReadFS; + gFDD_Devices[0].Node.Write = NULL;//fdd_writeFS; + memcpy(&gFDD_Devices[1].Node, &gFDD_Devices[0].Node, sizeof(tVFS_Node)); + + gFDD_Devices[1].Node.Inode = 1; + + // Set Lengths + gFDD_Devices[0].Node.Size = cFDD_SIZES[data >> 4]; + gFDD_Devices[1].Node.Size = cFDD_SIZES[data & 0xF]; + + // Create Sector Cache + #if USE_CACHE + //sFDD_SectorCache = malloc(sizeof(*sFDD_SectorCache)*CACHE_SIZE); + //siFDD_SectorCacheSize = CACHE_SIZE; + #endif + + // Register with devfs + DevFS_AddDevice(&gFDD_DriverInfo); + + return 0; +} + /** * \fn char *FDD_ReadDir(tVFS_Node *Node, int pos) * \brief Read Directory */ char *FDD_ReadDir(tVFS_Node *Node, int pos) { + char name[2] = "0\0"; //Update Accessed Time //gFDD_DrvInfo.rootNode.atime = now(); @@ -128,11 +197,13 @@ char *FDD_ReadDir(tVFS_Node *Node, int pos) if(pos >= 2 || pos < 0) return NULL; - if(fdd_devices[pos].type == 0) + if(gFDD_Devices[pos].type == 0) return VFS_SKIP; + name[0] += pos; + //Return - return fdd_devices[pos].Name; + return strdup(name); } /** @@ -141,31 +212,57 @@ char *FDD_ReadDir(tVFS_Node *Node, int pos) */ tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename) { - int i; + int i; ENTER("sfilename", filename); - if(filename == NULL) return NULL; + // Sanity check string + if(filename == NULL) { + LEAVE('n'); + return NULL; + } - //Check string length (should be 1) - if(filename[0] == '\0') return NULL; - if(filename[1] != '\0') return NULL; + // Check string length (should be 1) + if(filename[0] == '\0' || filename[1] != '\0') { + LEAVE('n'); + return NULL; + } - //Get First char + // Get First character i = filename[0] - '0'; // Check for 1st disk and if it is present return - if(i == 0 && fdd_devices[0].type != 0) - return &fdd_devices[0].Node; + if(i == 0 && gFDD_Devices[0].type != 0) { + LEAVE('p', &gFDD_Devices[0].Node); + return &gFDD_Devices[0].Node; + } // Check for 2nd disk and if it is present return - if(i == 1 && fdd_devices[1].type != 0) - return &fdd_devices[1].Node; + if(i == 1 && gFDD_Devices[1].type != 0) { + LEAVE('p', &gFDD_Devices[1].Node); + return &gFDD_Devices[1].Node; + } // Else return null + LEAVE('n'); return 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) +{ + switch(id) + { + case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; + case DRV_IOCTL_IDENT: memcpy(data, "FDD\0", 4); return 1; + case DRV_IOCTL_VERSION: return FDD_VERSION; + default: return 0; + } +} + /** * \fn Uint64 fdd_readFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) * \brief Read Data from a disk @@ -203,7 +300,7 @@ Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) LOG("Non-aligned Read"); //Read Starting Sector - if(!fdd_readSector(disk, startOff, buf)) + if(!FDD_ReadSector(disk, startOff, buf)) return 0; memcpy(buffer, (char*)(buf+sectOff), len>512-sectOff?512-sectOff:len); @@ -216,7 +313,7 @@ Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) //Read Middle Sectors for(i=1;i>1]; // Check if seeking is needed - if(fdd_devices[disk].track[head] == track) + if(gFDD_Devices[disk].track[head] == track) return 1; // - Seek Head 0 - sendbyte(base, SEEK_TRACK); - sendbyte(base, (head<<2)|(disk&1)); - sendbyte(base, track); // Send Seek command + FDD_int_SendByte(base, SEEK_TRACK); + FDD_int_SendByte(base, (head<<2)|(disk&1)); + FDD_int_SendByte(base, track); // Send Seek command FDD_WaitIRQ(); FDD_SensInt(base, &sr0, &cyl); // Wait for IRQ if((sr0 & 0xF0) != 0x20) { @@ -405,15 +502,15 @@ static int seekTrack(int disk, int head, int track) if(cyl != track) return 0; // Set Track in structure - fdd_devices[disk].track[head] = track; + gFDD_Devices[disk].track[head] = track; return 1; } /** - * \fn static int get_dims(int type, int lba, int *c, int *h, int *s, int *spt) + * \fn int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt) * \brief Get Dimensions of a disk */ -static int get_dims(int type, int lba, int *c, int *h, int *s, int *spt) +int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt) { switch(type) { case 0: @@ -466,25 +563,10 @@ static int get_dims(int type, int lba, int *c, int *h, int *s, int *spt) } /** - * \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) -{ - switch(id) - { - case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; - case DRV_IOCTL_IDENT: memcpy(data, "FDD\0", 4); return 1; - case DRV_IOCTL_VERSION: return (FDD_VER_MAJ<<8)|FDD_VER_MIN; - default: return 0; - } -} - -/** - * \fn void fdd_handler(int unused) + * \fn void FDD_IRQHandler(int Num) * \brief Handles IRQ6 */ -void fdd_handler(int unused) +void FDD_IRQHandler(int Num) { fdd_irq6 = 1; } @@ -502,11 +584,11 @@ void FDD_WaitIRQ() void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl) { - sendbyte(base, CHECK_INTERRUPT_STATUS); - if(sr0) *sr0 = getbyte(base); - else getbyte(base); - if(cyl) *cyl = getbyte(base); - else getbyte(base); + FDD_int_SendByte(base, CHECK_INTERRUPT_STATUS); + if(sr0) *sr0 = FDD_int_GetByte(base); + else FDD_int_GetByte(base); + if(cyl) *cyl = FDD_int_GetByte(base); + else FDD_int_GetByte(base); } void FDD_AquireSpinlock() @@ -534,10 +616,10 @@ inline void FDD_FreeCacheSpinlock() #endif /** - * void sendbyte(int base, char byte) + * void FDD_int_SendByte(int base, char byte) * \brief Sends a command to the controller */ -static void sendbyte(int base, char byte) +void FDD_int_SendByte(int base, char byte) { volatile int state; int timeout = 128; @@ -552,15 +634,15 @@ static void sendbyte(int base, char byte) inb(0x80); //Delay } #if WARN - Warning("FDD_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base); + Warning("FDD_int_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base); #endif } /** - * int getbyte(int base, char byte) + * int FDD_int_GetByte(int base, char byte) * \brief Receive data from fdd controller */ -static int getbyte(int base) +int FDD_int_GetByte(int base) { volatile int state; int timeout; @@ -574,28 +656,34 @@ static int getbyte(int base) return -1; } +/** + * \brief Recalibrate the specified disk + */ void FDD_Recalibrate(int disk) { ENTER("idisk", disk); LOG("Starting Motor"); - start_motor(disk); + FDD_int_StartMotor(disk); // Wait for Spinup - while(fdd_devices[disk].motorState == 1) Threads_Yield(); + while(gFDD_Devices[disk].motorState == 1) Threads_Yield(); LOG("Sending Calibrate Command"); - sendbyte(cPORTBASE[disk>>1], CALIBRATE_DRIVE); - sendbyte(cPORTBASE[disk>>1], disk&1); + FDD_int_SendByte(cPORTBASE[disk>>1], CALIBRATE_DRIVE); + FDD_int_SendByte(cPORTBASE[disk>>1], disk&1); LOG("Waiting for IRQ"); FDD_WaitIRQ(); FDD_SensInt(cPORTBASE[disk>>1], NULL, NULL); LOG("Stopping Motor"); - stop_motor(disk); + FDD_int_StopMotor(disk); LEAVE('-'); } +/** + * \brief Reset the specified FDD controller + */ void FDD_Reset(int id) { int base = cPORTBASE[id]; @@ -612,11 +700,11 @@ void FDD_Reset(int id) LOG("Setting Driver Info"); outb(base + PORT_DATARATE, 0); // Set data rate to 500K/s - sendbyte(base, FIX_DRIVE_DATA); // Step and Head Load Times - sendbyte(base, 0xDF); // Step Rate Time, Head Unload Time (Nibble each) - sendbyte(base, 0x02); // Head Load Time >> 1 - while(seekTrack(0, 0, 1) == 0); // set track - while(seekTrack(0, 1, 1) == 0); // set track + FDD_int_SendByte(base, FIX_DRIVE_DATA); // Step and Head Load Times + FDD_int_SendByte(base, 0xDF); // Step Rate Time, Head Unload Time (Nibble each) + FDD_int_SendByte(base, 0x02); // Head Load Time >> 1 + while(FDD_int_SeekTrack(0, 0, 1) == 0); // set track + while(FDD_int_SeekTrack(0, 1, 1) == 0); // set track LOG("Recalibrating Disk"); FDD_Recalibrate((id<<1)|0); @@ -626,100 +714,44 @@ void FDD_Reset(int id) } /** - * \fn void fdd_timer() + * \fn void FDD_int_TimerCallback() * \brief Called by timer */ -static void fdd_timer(int arg) +void FDD_int_TimerCallback(int arg) { ENTER("iarg", arg); - if(fdd_devices[arg].motorState == 1) - fdd_devices[arg].motorState = 2; - Time_RemoveTimer(fdd_devices[arg].timer); - fdd_devices[arg].timer = -1; + if(gFDD_Devices[arg].motorState == 1) + gFDD_Devices[arg].motorState = 2; + Time_RemoveTimer(gFDD_Devices[arg].timer); + gFDD_Devices[arg].timer = -1; LEAVE('-'); } /** - * \fn void start_motor(char disk) + * \fn void FDD_int_StartMotor(char disk) * \brief Starts FDD Motor */ -static void start_motor(int disk) +void FDD_int_StartMotor(int disk) { Uint8 state; state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT ); state |= 1 << (4+disk); outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state ); - fdd_devices[disk].motorState = 1; - fdd_devices[disk].timer = Time_CreateTimer(MOTOR_ON_DELAY, fdd_timer, (void*)disk); //One Shot Timer + gFDD_Devices[disk].motorState = 1; + gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_ON_DELAY, FDD_int_TimerCallback, (void*)disk); //One Shot Timer } /** - * \fn void stop_motor(int disk) + * \fn void FDD_int_StopMotor(int disk) * \brief Stops FDD Motor */ -static void stop_motor(int disk) +void FDD_int_StopMotor(int disk) { Uint8 state; state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT ); state &= ~( 1 << (4+disk) ); outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state ); - fdd_devices[disk].motorState = 0; -} - -/** - * \fn int FDD_Install(char **Arguments) - * \brief Installs floppy driver - */ -int FDD_Install(char **Arguments) -{ - Uint8 data; - - // Determine Floppy Types (From CMOS) - outb(0x70, 0x10); - data = inb(0x71); - fdd_devices[0].type = data >> 4; - fdd_devices[1].type = data & 0xF; - fdd_devices[0].track[0] = -1; - fdd_devices[1].track[1] = -1; - - // Clear FDD IRQ Flag - FDD_SensInt(0x3F0, NULL, NULL); - // Install IRQ6 Handler - IRQ_AddHandler(6, fdd_handler); - // Reset Primary FDD Controller - FDD_Reset(0); - - Log("[FDD ] Detected Disk 0: %s and Disk 1: %s\n", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); - - // Initialise Root Node - gFDD_DriverInfo.RootNode.CTime = gFDD_DriverInfo.RootNode.MTime - = gFDD_DriverInfo.RootNode.ATime = now(); - - // Initialise Child Nodes - fdd_devices[0].Name[0] = '0'; fdd_devices[0].Name[1] = '\0'; - fdd_devices[0].Node.Inode = 0; - fdd_devices[0].Node.Flags = 0; - fdd_devices[0].Node.NumACLs = 0; - fdd_devices[0].Node.Read = FDD_ReadFS; - fdd_devices[0].Node.Write = NULL;//fdd_writeFS; - memcpy(&fdd_devices[1].Node, &fdd_devices[0].Node, sizeof(tVFS_Node)); - fdd_devices[1].Name[0] = '1'; - fdd_devices[1].Node.Inode = 1; - - // Set Lengths - fdd_devices[0].Node.Size = cFDD_SIZES[data >> 4]; - fdd_devices[1].Node.Size = cFDD_SIZES[data & 0xF]; - - // Create Sector Cache - #if USE_CACHE - //sFDD_SectorCache = malloc(sizeof(*sFDD_SectorCache)*CACHE_SIZE); - //siFDD_SectorCacheSize = CACHE_SIZE; - #endif - - // Register with devfs - DevFS_AddDevice(&gFDD_DriverInfo); - - return 0; + gFDD_Devices[disk].motorState = 0; } /** @@ -731,8 +763,8 @@ void ModuleUnload() int i; FDD_AquireSpinlock(); for(i=0;i<4;i++) { - Time_RemoveTimer(fdd_devices[i].timer); - stop_motor(i); + Time_RemoveTimer(gFDD_Devices[i].timer); + FDD_int_StopMotor(i); } //IRQ_Clear(6); } diff --git a/Kernel/include/common.h b/Kernel/include/common.h index 16d089d2..3c2f8085 100644 --- a/Kernel/include/common.h +++ b/Kernel/include/common.h @@ -74,9 +74,10 @@ extern Uint32 ind(Uint16 Port); extern Uint64 inq(Uint16 Port); // --- Memory --- extern tPAddr MM_Allocate(Uint VAddr); -extern void MM_Deallocate(Uint VAddr); -extern int MM_Map(Uint VAddr, tPAddr PAddr); -extern tPAddr MM_GetPhysAddr(Uint VAddr); +extern void MM_Deallocate(Uint VAddr); //!< Deallocate a page +extern int MM_Map(Uint VAddr, tPAddr PAddr); //!< Map a page +extern tPAddr MM_GetPhysAddr(Uint VAddr); //!< Get the physical address of a page +extern int MM_IsUser(Uint VAddr, int Length); //!< Checks if a memory address is valid user memory extern void MM_SetFlags(Uint VAddr, Uint Flags, Uint Mask); extern Uint MM_MapTemp(tPAddr PAddr); extern void MM_FreeTemp(Uint PAddr); @@ -90,6 +91,10 @@ extern void *memcpy(void *dest, const void *src, Uint count); extern void *memcpyd(void *dest, const void *src, Uint count); extern void *memset(void *dest, int val, Uint count); extern void *memsetd(void *dest, Uint val, Uint count); +extern Uint16 LittleEndian16(Uint16 Val); +extern Uint16 BigEndian16(Uint16 Val); +extern Uint32 LittleEndian32(Uint32 Val); +extern Uint32 BigEndian32(Uint32 Val); // --- Strings --- extern Uint strlen(const char *Str); extern char *strcpy(char *__dest, const char *__src); diff --git a/Kernel/include/modules.h b/Kernel/include/modules.h index dcf34656..bf3171b3 100644 --- a/Kernel/include/modules.h +++ b/Kernel/include/modules.h @@ -17,15 +17,9 @@ # error "Unknown architecture when determining MODULE_ARCH_ID ('" #ARCH "')" #endif -#if BUILD_MODULE -# define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deps...) char *_DriverDeps[]={_deps};\ - tModule DriverInfo=\ - {MODULE_MAGIC,MODULE_ARCH_ID,_flags,_ver,NULL,#_ident,_entry,_DriverDeps} -#else -# define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deps...) char *_DriverDeps_##_ident[]={_deps};\ +#define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deps...) char *_DriverDeps_##_ident[]={_deps};\ tModule __attribute__ ((section ("KMODULES"),unused)) _DriverInfo_##_ident=\ {MODULE_MAGIC,MODULE_ARCH_ID,_flags,_ver,NULL,#_ident,_entry,_DriverDeps_##_ident} -#endif typedef struct sModule { Uint32 Magic; diff --git a/Kernel/vfs/dir.c b/Kernel/vfs/dir.c index 22249ef6..e87b5a31 100644 --- a/Kernel/vfs/dir.c +++ b/Kernel/vfs/dir.c @@ -2,7 +2,7 @@ * Acess2 VFS * - Directory Management Functions */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -34,18 +34,27 @@ int VFS_MkDir(char *Path) int VFS_MkNod(char *Path, Uint Flags) { char *absPath, *name; - int pos=0, oldpos = 0; + int pos = 0, oldpos = 0; + int next = 0; tVFS_Node *parent; int ret; ENTER("sPath xFlags", Path, Flags); absPath = VFS_GetAbsPath(Path); + LOG("absPath = '%s'", absPath); - while( (pos = strpos8(&absPath[pos+1], '/')) != -1 ) oldpos = pos; + while( (next = strpos(&absPath[pos+1], '/')) != -1 ) { + LOG("next = %i", next); + pos += next+1; + LOG("pos = %i", pos); + oldpos = pos; + } absPath[oldpos] = '\0'; // Mutilate path name = &absPath[oldpos+1]; + LOG("absPath = '%s', name = '%s'", absPath, name); + // Check for root if(absPath[0] == '\0') parent = VFS_ParsePath("/", NULL); @@ -62,7 +71,7 @@ int VFS_MkNod(char *Path, Uint Flags) return -1; } - LOG("parent = %p\n", parent); + LOG("parent = %p", parent); if(parent->MkNod == NULL) { Warning("VFS_MkNod - Directory has no MkNod method"); diff --git a/Kernel/vfs/fs/ext2.c b/Kernel/vfs/fs/ext2.c index 50be904a..8ee26aff 100644 --- a/Kernel/vfs/fs/ext2.c +++ b/Kernel/vfs/fs/ext2.c @@ -88,7 +88,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Open Disk fd = VFS_Open(Device, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE); //Open Device if(fd == -1) { - Warning("[EXT2 ] Unable to open '%s'\n", Device); + Warning("[EXT2 ] Unable to open '%s'", Device); LEAVE('n'); return NULL; } @@ -98,7 +98,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Sanity Check Magic value if(sb.s_magic != 0xEF53) { - Warning("[EXT2 ] Volume '%s' is not an EXT2 volume\n", Device); + Warning("[EXT2 ] Volume '%s' is not an EXT2 volume", Device); VFS_Close(fd); LEAVE('n'); return NULL; @@ -111,7 +111,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Allocate Disk Information disk = malloc(sizeof(tExt2_Disk) + sizeof(tExt2_Group)*groupCount); if(!disk) { - Warning("[EXT2 ] Unable to allocate disk structure\n"); + Warning("[EXT2 ] Unable to allocate disk structure"); VFS_Close(fd); LEAVE('n'); return NULL; @@ -218,7 +218,7 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) Offset = Offset / disk->BlockSize; base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); if(base == 0) { - Warning("[EXT2 ] NULL Block Detected in INode 0x%llx\n", Node->Inode); + Warning("[EXT2 ] NULL Block Detected in INode 0x%llx", Node->Inode); LEAVE('i', 0); return 0; } @@ -243,7 +243,7 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); if(base == 0) { - Warning("[EXT2 ] NULL Block Detected in INode 0x%llx\n", Node->Inode); + Warning("[EXT2 ] NULL Block Detected in INode 0x%llx", Node->Inode); LEAVE('i', 0); return 0; } @@ -367,7 +367,7 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) Ext2_int_GetInode(Node, &inode); size = inode.i_size; - LOG("inode.i_block[0] = 0x%x\n", inode.i_block[0]); + LOG("inode.i_block[0] = 0x%x", inode.i_block[0]); // Find Entry // Get First Block @@ -383,7 +383,7 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) if(ofs >= disk->BlockSize) { block ++; if( ofs > disk->BlockSize ) { - Warning("[EXT2] Directory Entry %i of inode %i extends over a block boundary, ignoring\n", + Warning("[EXT2] Directory Entry %i of inode %i extends over a block boundary, ignoring", entNum-1, Node->Inode); } ofs = 0; @@ -391,13 +391,17 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) } } - if(size <= 0) return NULL; + // Check for the end of the list + if(size <= 0) { + LEAVE('n'); + return NULL; + } // Read Entry VFS_ReadAt( disk->FD, Base+ofs, sizeof(tExt2_DirEnt), &dirent ); - //LOG("dirent.inode = %i\n", dirent.inode); - //LOG("dirent.rec_len = %i\n", dirent.rec_len); - //LOG("dirent.name_len = %i\n", dirent.name_len); + //LOG("dirent.inode = %i", dirent.inode); + //LOG("dirent.rec_len = %i", dirent.rec_len); + //LOG("dirent.name_len = %i", dirent.name_len); VFS_ReadAt( disk->FD, Base+ofs+sizeof(tExt2_DirEnt), dirent.name_len, namebuf ); namebuf[ dirent.name_len ] = '\0'; // Cap off string @@ -457,7 +461,7 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) if(ofs >= disk->BlockSize) { block ++; if( ofs > disk->BlockSize ) { - Warning("[EXT2 ] Directory Entry %i of inode %i extends over a block boundary, ignoring\n", + Warning("[EXT2 ] Directory Entry %i of inode %i extends over a block boundary, ignoring", entNum-1, Node->Inode); } ofs = 0; @@ -573,7 +577,8 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint InodeId, tExt2_Inode *Inode) { int group, subId; - //LogF("Ext2_int_ReadInode: (Disk=%p, InodeId=%i, Inode=%p)\n", Disk, InodeId, Inode); + //LogF("Ext2_int_ReadInode: (Disk=%p, InodeId=%i, Inode=%p)", Disk, InodeId, Inode); + //ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode); if(InodeId == 0) return 0; @@ -582,7 +587,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint InodeId, tExt2_Inode *Inode) group = InodeId / Disk->SuperBlock.s_inodes_per_group; subId = InodeId % Disk->SuperBlock.s_inodes_per_group; - //LogF(" Ext2_int_ReadInode: group=%i, subId = %i\n", group, subId); + //LOG("group=%i, subId = %i", group, subId); // Read Inode VFS_ReadAt(Disk->FD, diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index d70fae0c..7c5eefcd 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -324,12 +324,12 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) // Sanity Check offset if(offset > node->Size) { - //Log("FAT_Read: Reading past EOF (%i > %i)", offset, node->Size); + //LOG("Reading past EOF (%i > %i)", offset, node->Size); return 0; } // Clamp Size if(offset + length > node->Size) { - //Log("FAT_Read: Reading past EOF (%lli + %lli > %lli), clamped to %lli", + //LOG("Reading past EOF (%lli + %lli > %lli), clamped to %lli", // offset, length, node->Size, node->Size - offset); length = node->Size - offset; } -- 2.20.1