From: John Hodge Date: Tue, 27 Oct 2009 05:00:05 +0000 (+0800) Subject: Implemented Dependency resolving for compile-time modules and Updated the README X-Git-Tag: rel0.06~375 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3c777e58e6baba6760f43b8fdde4daf62081048b;p=tpg%2Facess2.git Implemented Dependency resolving for compile-time modules and Updated the README - Added more early debug code (See arch/.../errors.c) - Added dependencies to drivers - Implemented dependcy resolving in modules.c - Disabled FAT chaching and fixed bugs that showed - Updated README to show how to configure and build --- diff --git a/Kernel/Makefile b/Kernel/Makefile index c538da54..5f155978 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -21,7 +21,7 @@ OBJ += binary.o bin/elf.o OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o OBJ += vfs/fs/root.o vfs/fs/devfs.o OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS))) -OBJ += drv/fifo.o drv/dma.o drv/pci.o drv/vterm.o drv/vga.o drv/kb.o +OBJ += drv/fifo.o drv/dma.o drv/pci.o drv/kb.o drv/vga.o drv/vterm.o OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS))) OBJ := $(addsuffix .$(ARCH), $(OBJ)) MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES))) diff --git a/Kernel/arch/x86/errors.c b/Kernel/arch/x86/errors.c index b9ff17d2..d87b1c62 100644 --- a/Kernel/arch/x86/errors.c +++ b/Kernel/arch/x86/errors.c @@ -112,3 +112,28 @@ void Error_Backtrace(Uint eip, Uint ebp) } LogF("\n"); } + +/** + * \fn void StartupPrint(char *Str) + */ +void StartupPrint(char *Str) +{ + Uint16 *buf = (void*)0xC00B8000; + int i = 0; + static int line = 0; + while(*Str) + { + buf[line*80 + i++] = *Str | 0x0700; + Str ++; + } + + while(i < 80) buf[line*80 + i++] = 0x0720; + + line ++; + if(line == 25) + { + line --; + memcpy(buf, &buf[80], 80*24*2); + memset(&buf[80*24], 0, 80*2); + } +} diff --git a/Kernel/drv/ata_x86.c b/Kernel/drv/ata_x86.c index 50404741..0c615bf9 100644 --- a/Kernel/drv/ata_x86.c +++ b/Kernel/drv/ata_x86.c @@ -120,7 +120,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); +MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, NULL); tDevFS_Driver gATA_DriverInfo = { NULL, "ata", { diff --git a/Kernel/drv/fdd.c b/Kernel/drv/fdd.c index a827ecda..3c86b08b 100644 --- a/Kernel/drv/fdd.c +++ b/Kernel/drv/fdd.c @@ -2,7 +2,7 @@ * AcessOS 0.1 * Floppy Disk Access Code */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -144,6 +144,8 @@ int FDD_Install(char **Arguments) gFDD_Devices[0].track[0] = -1; gFDD_Devices[1].track[1] = -1; + Log("[FDD ] Detected Disk 0: %s and Disk 1: %s\n", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); + // Clear FDD IRQ Flag FDD_SensInt(0x3F0, NULL, NULL); // Install IRQ6 Handler @@ -151,8 +153,6 @@ int FDD_Install(char **Arguments) // 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(); diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 608b058a..2da26ff1 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -24,7 +24,7 @@ void KB_UpdateLEDs(); int KB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === -MODULE_DEFINE(0, 0x0100, PS2Keybard, KB_Install, NULL, NULL); +MODULE_DEFINE(0, 0x0100, PS2Keyboard, KB_Install, NULL, NULL); tDevFS_Driver gKB_DevInfo = { NULL, "PS2Keyboard", { diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 54f78f44..afd53ffc 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -55,6 +55,9 @@ typedef struct { tVFS_Node Node; } tVTerm; +// === IMPORTS === +extern void Debug_SetKTerminal(char *File); + // === PROTOTYPES === int VT_Install(char **Arguments); char *VT_ReadDir(tVFS_Node *Node, int Pos); @@ -180,6 +183,9 @@ int VT_Install(char **Arguments) // Add to DevFS DevFS_AddDevice( &gVT_DrvInfo ); + // Set kernel output to VT0 + //Debug_SetKTerminal("/Devices/VTerm/0"); + return 0; } diff --git a/Kernel/modules.c b/Kernel/modules.c index b7209fff..71d76d4c 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -12,8 +12,9 @@ int Module_IsLoaded(char *Name); // === IMPORTS === +extern void StartupPrint(char *Str); extern tModule gKernelModules[]; -extern void gKernelModulesEnd; +extern void gKernelModulesEnd; // === GLOBALS === int giNumBuiltinModules = 0; @@ -23,18 +24,82 @@ tModule *gLoadedModules = NULL; // === CODE === int Modules_LoadBuiltins() { - int i; + int i, j, k; + int numToInit = 0; + Uint8 *baIsLoaded; + char **deps; + giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules; giNumBuiltinModules /= sizeof(tModule); + baIsLoaded = calloc( giNumBuiltinModules, sizeof(*baIsLoaded) ); + + // Pass 1 - Are the dependencies compiled in? for( i = 0; i < giNumBuiltinModules; i++ ) { - Log("Initialising %p '%s' v%i.%i...", - &gKernelModules[i], - gKernelModules[i].Name, - gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF - ); - gKernelModules[i].Init(NULL); + deps = gKernelModules[i].Dependencies; + if(deps) + { + for( j = 0; deps[j]; j++ ) + { + for( k = 0; k < giNumBuiltinModules; k++ ) { + if(strcmp(deps[j], gKernelModules[k].Name) == 0) + break; + } + if(k == giNumBuiltinModules) { + Warning("Unable to find dependency '%s' for '%s' in kernel", + deps[j], gKernelModules[i].Name); + + baIsLoaded[i] = -1; // Don't Load + break; + } + } + } + numToInit ++; + } + + // Pass 2 - Intialise + while(numToInit) + { + for( i = 0; i < giNumBuiltinModules; i++ ) + { + if( baIsLoaded[i] ) continue; // Ignore already loaded modules + + if( deps ) + { + for( j = 0; deps[j]; j++ ) + { + for( k = 0; k < giNumBuiltinModules; k++ ) { + if(strcmp(deps[j], gKernelModules[k].Name) == 0) + break; + } + // `k` is assumed to be less than `giNumBuiltinModules` + + // If a dependency failed, skip and mark as failed + if( baIsLoaded[k] == -1 ) { + baIsLoaded[i] = -1; + numToInit --; + break; + } + // If a dependency is not intialised, skip + if( !baIsLoaded[k] ) break; + } + // Check if we broke out + if( deps[j] ) continue; + } + + // All Dependencies OK? Initialise + StartupPrint(gKernelModules[i].Name); + Log("Initialising %p '%s' v%i.%i...", + &gKernelModules[i], + gKernelModules[i].Name, + gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF + ); + gKernelModules[i].Init(NULL); + // Mark as loaded + baIsLoaded[i] = 1; + numToInit --; + } } return 0; diff --git a/Kernel/system.c b/Kernel/system.c index 6154028d..49af4797 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -10,6 +10,7 @@ extern int Modules_LoadBuiltins(); extern int PCI_Install(); extern void DMA_Install(); extern void Debug_SetKTerminal(char *File); +extern void StartupPrint(char *Str); // === PROTOTYPES === void System_Init(char *ArgString); @@ -26,11 +27,15 @@ char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; void System_Init(char *ArgString) { // - Start Builtin Drivers & Filesystems + StartupPrint("Scanning PCI Bus..."); PCI_Install(); + StartupPrint("Loading DMA..."); DMA_Install(); + StartupPrint("Loading staticly compiled modules..."); Modules_LoadBuiltins(); // Set the debug to be echoed to the terminal + StartupPrint("Kernel now echoes to VT6 (Ctrl-Alt-F7)"); Debug_SetKTerminal("/Devices/VTerm/6"); // - Parse Kernel's Command Line diff --git a/Kernel/vfs/fs/ext2.c b/Kernel/vfs/fs/ext2.c index be50e6ca..0b60e542 100644 --- a/Kernel/vfs/fs/ext2.c +++ b/Kernel/vfs/fs/ext2.c @@ -5,9 +5,10 @@ /** * \file fs/ext2.c * \brief Second Extended Filesystem Driver - * \todo Implement file read support + * \todo Implement file full write support */ #define DEBUG 1 +#define VERBOSE 0 #include #include #include @@ -135,7 +136,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) disk->Groups ); - #if DEBUG + #if VERBOSE LOG("Block Group 0"); LOG(".bg_block_bitmap = 0x%x", disk->Groups[0].bg_block_bitmap); LOG(".bg_inode_bitmap = 0x%x", disk->Groups[0].bg_inode_bitmap); diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index 5712da91..fab89651 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -3,15 +3,16 @@ * FAT12/16/32 Driver Version (Incl LFN) */ #define DEBUG 0 +#define VERBOSE 1 + +#define CACHE_FAT 1 //!< Caches the FAT in memory +#define USE_LFN 1 //!< Enables the use of Long File Names + #include #include #include #include "fs_fat.h" -#define VERBOSE 1 - -#define CACHE_FAT 1 //!< Caches the FAT in memory -#define USE_LFN 1 //!< Enables the use of Long File Names // === TYPES === #if USE_LFN @@ -39,9 +40,6 @@ void FAT_CloseFile(tVFS_Node *node); MODULE_DEFINE(0, 0x51 /*v0.80*/, FAT32, FAT_Install, NULL, NULL); tFAT_VolInfo gFAT_Disks[8]; int giFAT_PartCount = 0; -#if CACHE_FAT -Uint32 *fat_cache[8]; -#endif #if USE_LFN t_lfncache *fat_lfncache; #endif @@ -159,8 +157,8 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) #if CACHE_FAT { Uint32 Ofs; - fat_cache[ giFAT_PartCount ] = (Uint32*)malloc(sizeof(Uint32)*CountofClusters); - if(fat_cache[giFAT_PartCount] == NULL) { + diskInfo->FATCache = (Uint32*)malloc(sizeof(Uint32)*CountofClusters); + if(diskInfo->FATCache == NULL) { Warning("FAT_InitDisk - Heap Exhausted\n"); return NULL; } @@ -176,8 +174,8 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) Ofs += 3*512; } val = *((int*)(buf+j*3)); - fat_cache[giFAT_PartCount][i*2] = val & 0xFFF; - fat_cache[giFAT_PartCount][i*2+1] = (val>>12) & 0xFFF; + diskInfo->FATCache[i*2] = val & 0xFFF; + diskInfo->FATCache[i*2+1] = (val>>12) & 0xFFF; } } if(diskInfo->type == FAT16) { @@ -187,7 +185,7 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) VFS_ReadAt(diskInfo->fileHandle, Ofs, 512, buf); Ofs += 512; } - fat_cache[giFAT_PartCount][i] = buf[i&255]; + diskInfo->FATCache[i] = buf[i&255]; } } if(diskInfo->type == FAT32) { @@ -197,7 +195,7 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) VFS_ReadAt(diskInfo->fileHandle, Ofs, 512, buf); Ofs += 512; } - fat_cache[giFAT_PartCount][i] = buf[i&127]; + diskInfo->FATCache[i] = buf[i&127]; } } LOG("FAT Fully Cached"); @@ -205,11 +203,11 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) #endif /*CACHE_FAT*/ //Initalise inode cache for FAT - gFAT_Disks[giFAT_PartCount].inodeHandle = Inode_GetHandle(); - LOG("Inode Cache handle is %i", gFAT_Disks[giFAT_PartCount].inodeHandle); + diskInfo->inodeHandle = Inode_GetHandle(); + LOG("Inode Cache handle is %i", diskInfo->inodeHandle); // == VFS Interface - node = &gFAT_Disks[giFAT_PartCount].rootNode; + node = &diskInfo->rootNode; node->Inode = diskInfo->rootOffset; node->Size = bs->files_in_root; // Unknown - To be set on readdir node->ImplInt = giFAT_PartCount; @@ -249,23 +247,26 @@ void FAT_Unmount(tVFS_Node *Node) } /** - * \fn static Uint32 FAT_int_GetFatValue(int handle, Uint32 cluster) + * \fn static Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) * \brief Fetches a value from the FAT */ -static Uint32 FAT_int_GetFatValue(int handle, Uint32 cluster) +static Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) { - Uint32 val; + Uint32 val = 0; + #if !CACHE_FAT + Uint32 ofs = Disk->bootsect.resvSectCount*512; + #endif ENTER("iHandle xCluster", handle, cluster); #if CACHE_FAT - val = fat_cache[handle][cluster]; + val = Disk->FATCache[cluster]; #else - if(gFAT_Disks[handle].type == FAT12) { - VFS_ReadAt(gFAT_Disks[handle].fileHandle, 512+(cluster&~1)*3, 3, &val); + if(Disk->type == FAT12) { + VFS_ReadAt(Disk->fileHandle, ofs+(cluster>>1)*3, 3, &val); val = (cluster&1 ? val&0xFFF : val>>12); - } else if(gFAT_Disks[handle].type == FAT16) { - VFS_ReadAt(gFAT_Disks[handle].fileHandle, 512+cluster*2, 2, &val); + } else if(Disk->type == FAT16) { + VFS_ReadAt(Disk->fileHandle, ofs+cluster*2, 2, &val); } else { - VFS_ReadAt(gFAT_Disks[handle].fileHandle, 512+cluster*4, 4, &val); + VFS_ReadAt(Disk->fileHandle, ofs+cluster*4, 4, &val); } #endif /*CACHE_FAT*/ LEAVE('x', val); @@ -325,6 +326,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) // Sanity Check offset if(offset > node->Size) { //LOG("Reading past EOF (%i > %i)", offset, node->Size); + LEAVE('i', 0); return 0; } // Clamp Size @@ -348,7 +350,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) //Skip previous clusters for(i=preSkip;i--;) { - cluster = FAT_int_GetFatValue(handle, cluster); + cluster = FAT_int_GetFatValue(disk, cluster); if(cluster == eocMarker) { Warning("FAT_Read - Offset is past end of cluster chain mark"); } @@ -374,7 +376,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) return length; } - cluster = FAT_int_GetFatValue(handle, cluster); + cluster = FAT_int_GetFatValue(disk, cluster); #if DEBUG LOG("pos=%i\n", pos); @@ -388,7 +390,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) FAT_int_ReadCluster(handle, cluster, bpc, tmpBuf); memcpy((void*)(buffer+pos), tmpBuf, bpc); pos += bpc; - cluster = FAT_int_GetFatValue(handle, cluster); + cluster = FAT_int_GetFatValue(disk, cluster); if(cluster == eocMarker) { Warning("FAT_Read - Read past End of Cluster Chain"); free(tmpBuf); @@ -619,15 +621,17 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) { //Skip previous clusters for(a=preSkip;a--;) { - cluster = FAT_int_GetFatValue(dirNode->ImplInt, cluster); + cluster = FAT_int_GetFatValue(disk, cluster); } } // Check for end of cluster chain if((disk->type == FAT12 && cluster == EOC_FAT12) || (disk->type == FAT16 && cluster == EOC_FAT16) - || (disk->type == FAT32 && cluster == EOC_FAT32)) + || (disk->type == FAT32 && cluster == EOC_FAT32)) { + LEAVE('n'); return NULL; + } // Bounds Checking (Used to spot heap overflows) if(cluster > disk->clusterCount + 2) @@ -852,7 +856,7 @@ tVFS_Node *FAT_FindDir(tVFS_Node *node, char *name) { if( dirCluster == disk->rootOffset && disk->type != FAT32 ) continue; - dirCluster = FAT_int_GetFatValue(node->ImplInt, dirCluster); + dirCluster = FAT_int_GetFatValue(disk, dirCluster); diskOffset = (disk->firstDataSect+(dirCluster-2)*disk->bootsect.spc)*512; } } diff --git a/Kernel/vfs/fs/fs_fat.h b/Kernel/vfs/fs/fs_fat.h index 67feb61c..6b7dfe76 100644 --- a/Kernel/vfs/fs/fs_fat.h +++ b/Kernel/vfs/fs/fs_fat.h @@ -130,6 +130,9 @@ struct drv_fat_volinfo_s { fat_bootsect bootsect; //!< Boot Sector tVFS_Node rootNode; //!< Root Node int inodeHandle; //!< Inode Cache Handle + #if CACHE_FAT + Uint32 *FATCache; //!< FAT Cache + #endif }; typedef struct drv_fat_volinfo_s tFAT_VolInfo; diff --git a/README b/README index 66d70f1b..61e69d24 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ Acess2 is [TPG]'s hobby operating system. -The Acess kernel is SEMI-posix compilant, but will be a comatability +The Acess kernel is SEMI-posix compilant, but there will be a comatability library that emulates the different functions. === Source Tree === @@ -29,3 +29,16 @@ The /Kernel tree contains the kernel sources. /Usermode/include - Required include files for the shared libraries. === Building === +Compiling Acess is relatively simple (at the moment) +First edit /Makefile.cfg and set the build programs (making sure they match + the architecture you are building for). +Then select the architecture to build (At the moment only x86:i386 works). +Edit the FILESYSTEMS variable to alter what filesystems are comipled in + (see /Kernel/vfs/fs for what filesystems are included). +DRIVERS defines what device drivers are to be included from the Kernel + tree (see /Kernel/drv for a list). +MODULES defines what modules should be statically linked with the kernel + (see /Modules for a list) + +Finally set the source root directory (ACESSDIR) and the destination + directory (DISTROOT) then call make in the source root.