From: John Hodge Date: Sat, 13 Mar 2010 10:27:57 +0000 (+0800) Subject: Changes to the module loader to handle specific errors from modules X-Git-Tag: rel0.06~284 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=156885e938b60fee9d061d989ae7711c9aeea493;p=tpg%2Facess2.git Changes to the module loader to handle specific errors from modules - Changed MODULE_INIT_SUCCESS to MODULE_ERR_OK and added other MODULE_ERR_* values --- diff --git a/Kernel/Makefile b/Kernel/Makefile index 8593d6fb..619d3ea0 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -27,11 +27,14 @@ endif OBJ = $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o drvutil.o +OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS))) +# These are first to make vterm be the first driver initialised (apart +# its dependencies), allowing logging to exist throughout the loading +# process. +OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o OBJ += binary.o bin/elf.o bin/pe.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/proc.o drv/fifo.o drv/dma.o drv/iocache.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/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 55c6592d..d15c45a5 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1513 +BUILD_NUM = 1518 diff --git a/Kernel/bin/pe.c b/Kernel/bin/pe.c index e7967e8f..0b74529d 100644 --- a/Kernel/bin/pe.c +++ b/Kernel/bin/pe.c @@ -29,7 +29,7 @@ tBinaryType gPE_Loader = { int PE_Install(char **Arguments) { Binary_RegisterType(&gPE_Loader); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/fifo.c b/Kernel/drv/fifo.c index 7bb4ca37..67b9a6d7 100644 --- a/Kernel/drv/fifo.c +++ b/Kernel/drv/fifo.c @@ -62,7 +62,7 @@ tPipe *gFIFO_NamedPipes = NULL; int FIFO_Install(char **Options) { DevFS_AddDevice( &gFIFO_DriverInfo ); - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 92f00a72..65d340e9 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -67,7 +67,7 @@ int KB_Install(char **Arguments) IRQ_AddHandler(1, KB_IRQHandler); DevFS_AddDevice( &gKB_DevInfo ); //Log("KB_Install: Installed"); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 8a86c35c..98232080 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -4,6 +4,7 @@ */ #define DEBUG 0 #include +#include #include #include #include @@ -89,7 +90,6 @@ int PCI_Install(char **Arguments) gaPCI_PortBitmap[i] = -1; for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ ) gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i; - //LogF("Done.\n"); // Scan Busses for( bus = 0; bus < giPCI_BusCount; bus++ ) @@ -140,11 +140,14 @@ int PCI_Install(char **Arguments) if(tmpPtr != gPCI_Devices) break; } + + if(giPCI_DeviceCount == 0) + return MODULE_ERR_NOTNEEDED; + tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(t_pciDevice)); if(tmpPtr == NULL) - return 0; + return MODULE_ERR_MALLOC; gPCI_Devices = tmpPtr; - //LogF("Done.\n"); // Complete Driver Structure gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount; @@ -152,7 +155,7 @@ int PCI_Install(char **Arguments) // And add to DevFS DevFS_AddDevice(&gPCI_DriverStruct); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c index 52a973c7..c968d526 100644 --- a/Kernel/drv/proc.c +++ b/Kernel/drv/proc.c @@ -108,7 +108,7 @@ tSysFS_Ent *gSysFS_FileList; int SysFS_Install(char **Options) { DevFS_AddDevice( &gSysFS_DriverInfo ); - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/vga.c b/Kernel/drv/vga.c index 11c799c7..b0c96623 100644 --- a/Kernel/drv/vga.c +++ b/Kernel/drv/vga.c @@ -50,7 +50,7 @@ int VGA_Install(char **Arguments) // Install DevFS DevFS_AddDevice( &gVGA_DevInfo ); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 7aebd28e..cedcb33e 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -190,7 +190,7 @@ int VT_Install(char **Arguments) // Set kernel output to VT0 Debug_SetKTerminal("/Devices/VTerm/0"); - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 2cd927b7..ddf69cba 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -8,6 +8,7 @@ #define NULL ((void*)0) #define PACKED __attribute__ ((packed)) +#include #include #include #include "errno.h" diff --git a/Kernel/include/modules.h b/Kernel/include/modules.h index d53f7749..8dc720a3 100644 --- a/Kernel/include/modules.h +++ b/Kernel/include/modules.h @@ -36,8 +36,15 @@ typedef struct sModule { char **Dependencies; // NULL Terminated List } __attribute__((packed)) tModule; -#define MODULE_INIT_SUCCESS 1 -#define MODULE_INIT_FAILURE 0 +enum eModuleErrors +{ + MODULE_ERR_OK, //!< No Error + MODULE_ERR_MISC, //!< Misc Error + MODULE_ERR_NOTNEEDED, //!< Module not needed + MODULE_ERR_MALLOC, //!< Error with malloc/realloc/calloc + + MODULE_ERR_MAX +}; /** * \brief Module Loader definition diff --git a/Kernel/modules.c b/Kernel/modules.c index e4f49b28..39c99661 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -33,16 +33,19 @@ tModuleLoader *gModule_Loaders = NULL; int Modules_LoadBuiltins() { int i, j, k; + int ret; int numToInit = 0; Uint8 *baIsLoaded; char **deps; + // Count modules giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules; giNumBuiltinModules /= sizeof(tModule); + // Allocate loaded array baIsLoaded = calloc( giNumBuiltinModules, sizeof(*baIsLoaded) ); - // Pass 1 - Are the dependencies compiled in? + // Pass 1 - Check for dependencies for( i = 0; i < giNumBuiltinModules; i++ ) { deps = gKernelModules[i].Dependencies; @@ -55,8 +58,10 @@ int Modules_LoadBuiltins() break; } if(k == giNumBuiltinModules) { - Warning("Unable to find dependency '%s' for '%s' in kernel", - deps[j], gKernelModules[i].Name); + Warning( + "[MOD ] Dependency '%s' for module '%s' was not compiled in", + deps[j], gKernelModules[i].Name + ); baIsLoaded[i] = -1; // Don't Load break; @@ -66,7 +71,7 @@ int Modules_LoadBuiltins() numToInit ++; } - // Pass 2 - Intialise + // Pass 2 - Intialise modules in order while(numToInit) { for( i = 0; i < giNumBuiltinModules; i++ ) @@ -84,6 +89,7 @@ int Modules_LoadBuiltins() break; } // `k` is assumed to be less than `giNumBuiltinModules` + // We checked this in pass 1 // If a dependency failed, skip and mark as failed if( baIsLoaded[k] == -1 ) { @@ -91,22 +97,40 @@ int Modules_LoadBuiltins() numToInit --; break; } - // If a dependency is not intialised, skip + // If a dependency is not intialised, skip this module + // and come back later if( !baIsLoaded[k] ) break; } - // Check if we broke out + // Check for breakouts if( deps[j] ) continue; } // All Dependencies OK? Initialise StartupPrint(gKernelModules[i].Name); - Log("Initialising %p '%s' v%i.%i...", + Log("[MOD ] Initialising %p '%s' v%i.%i...", &gKernelModules[i], gKernelModules[i].Name, gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF ); - if( gKernelModules[i].Init(NULL) == 0 ) { - Log("Loading Failed, all modules that depend on this will also fail"); + + ret = gKernelModules[i].Init(NULL); + if( ret != MODULE_ERR_OK ) { + Log("[MOD ] Loading Failed, all modules that depend on this will also fail"); + switch(ret) + { + case MODULE_ERR_MISC: + Log("[MOD ] Reason: Miscelanious"); + break; + case MODULE_ERR_NOTNEEDED: + Log("[MOD ] Reason: Module not needed (probably hardware not found)"); + break; + case MODULE_ERR_MALLOC: + Log("[MOD ] Reason: Error in malloc/realloc/calloc, probably not good"); + break; + default: + Log("[MOD ] Reason - Unknown code %i", ret); + break; + } baIsLoaded[i] = -1; } // Mark as loaded @@ -116,6 +140,8 @@ int Modules_LoadBuiltins() } } + free(baIsLoaded); + return 0; } diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index 3ebe89ad..32bff8d8 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -55,7 +55,7 @@ tVFS_Driver gFAT_FSInfo = { int FAT_Install(char **Arguments) { VFS_AddDriver( &gFAT_FSInfo ); - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** diff --git a/Modules/Display/BochsGA/bochsvbe.c b/Modules/Display/BochsGA/bochsvbe.c index 06d362cb..4b76c223 100644 --- a/Modules/Display/BochsGA/bochsvbe.c +++ b/Modules/Display/BochsGA/bochsvbe.c @@ -107,20 +107,20 @@ int BGA_Install(char **Arguments) // 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; + return MODULE_ERR_NOTNEEDED; } // Install Device giBGA_DriverId = DevFS_AddDevice( &gBGA_DriverStruct ); if(giBGA_DriverId == -1) { Warning("[BGA ] Unable to register with DevFS, maybe already loaded?"); - return 0; + return MODULE_ERR_MISC; } // Map Framebuffer to hardware address gBGA_Framebuffer = (void *) MM_MapHWPage(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb) - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/Filesystems/FS_Ext2/ext2.c b/Modules/Filesystems/FS_Ext2/ext2.c index 81dcef0b..68fd939a 100644 --- a/Modules/Filesystems/FS_Ext2/ext2.c +++ b/Modules/Filesystems/FS_Ext2/ext2.c @@ -41,7 +41,7 @@ tVFS_Driver gExt2_FSInfo = { int Ext2_Install(char **Arguments) { VFS_AddDriver( &gExt2_FSInfo ); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 6b6f8a93..e3803208 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -89,7 +89,7 @@ int IPStack_Install(char **Arguments) DevFS_AddDevice( &gIP_DriverInfo ); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/Interfaces/UDI/main.c b/Modules/Interfaces/UDI/main.c index d114bdc9..a6fed922 100644 --- a/Modules/Interfaces/UDI/main.c +++ b/Modules/Interfaces/UDI/main.c @@ -26,7 +26,7 @@ tModuleLoader gUDI_Loader = { int UDI_Install(char **Arguments) { Module_RegisterLoader( &gUDI_Loader ); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index 14314b83..700c35e7 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -127,6 +127,11 @@ int Ne2k_Install(char **Options) giNe2k_CardCount += PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, 0 ); } + if( giNe2k_CardCount == 0 ) { + Log("[Ne2k ] No cards detected\n"); + return MODULE_ERR_NOTNEEDED; + } + // Enumerate Cards k = 0; gpNe2k_Cards = calloc( giNe2k_CardCount, sizeof(tCard) ); @@ -216,7 +221,7 @@ int Ne2k_Install(char **Options) gNe2k_DriverInfo.RootNode.Size = giNe2k_CardCount; DevFS_AddDevice( &gNe2k_DriverInfo ); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index 1ba124b5..2bb151da 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -112,16 +112,16 @@ int ATA_Install() int ret; ret = ATA_SetupIO(); - if(ret != 1) return ret; + if(ret) return ret; ATA_SetupPartitions(); ATA_SetupVFS(); if( DevFS_AddDevice( &gATA_DriverInfo ) == 0 ) - return MODULE_INIT_FAILURE; + return MODULE_ERR_MISC; - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** @@ -141,9 +141,11 @@ int ATA_SetupIO() gATA_BusMasterBase = PCI_GetBAR4( ent ); if( gATA_BusMasterBase == 0 ) { Warning("It seems that there is no Bus Master Controller on this machine. Get one"); - LEAVE('i', MODULE_INIT_FAILURE); - return MODULE_INIT_FAILURE; + LEAVE('i', MODULE_ERR_NOTNEEDED); + return MODULE_ERR_NOTNEEDED; } + + // Map memory if( !(gATA_BusMasterBase & 1) ) { if( gATA_BusMasterBase < 0x100000 ) @@ -157,6 +159,7 @@ int ATA_SetupIO() LOG("gATA_BusMasterBase = 0x%x", gATA_BusMasterBase & ~1); } + // Register IRQs and get Buffers IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri ); IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec ); @@ -172,11 +175,13 @@ int ATA_SetupIO() LOG("addr = 0x%x", addr); ATA_int_BusMasterWriteDWord(12, addr); + // Enable controllers outb(IDE_PRI_BASE+1, 1); outb(IDE_SEC_BASE+1, 1); - LEAVE('i', MODULE_INIT_SUCCESS); - return MODULE_INIT_SUCCESS; + // return + LEAVE('i', MODULE_ERR_OK); + return MODULE_ERR_OK; } /** diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 58fb8246..412f71d5 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -200,7 +200,7 @@ int FDD_Install(char **Arguments) // Register with devfs DevFS_AddDevice(&gFDD_DriverInfo); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/USB/main.c b/Modules/USB/main.c index 28ce5e3b..5744c29d 100644 --- a/Modules/USB/main.c +++ b/Modules/USB/main.c @@ -44,7 +44,7 @@ int USB_Install(char **Arguments) { UHCI_Initialise(); Warning("[USB ] Not Complete - Devel Only"); - return 1; + return MODULE_ERR_OK; } /** diff --git a/Modules/USB/usb.c b/Modules/USB/usb.c index 4663ce28..934136a1 100644 --- a/Modules/USB/usb.c +++ b/Modules/USB/usb.c @@ -15,9 +15,9 @@ void USB_MakeToken(void *Buf, int PID, int Addr, int EndP) Uint8 *tok = Buf; int crc = 0; //USB_TokenCRC(); - tok[0] = PID; - tok[1] = Addr | ((EndP&1)<<7); - tok[2] = (EndP >> 1) | crc; + tok[0] = PID & 0xFF; + tok[1] = (Addr & 0x7F) | ((EndP&1)<<7); + tok[2] = ((EndP >> 1) & 0x7) | crc; } #if 0