From 975f0f89b7a643abd7cc463d788dad34ac014b65 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 17 Jan 2010 14:05:38 +0800 Subject: [PATCH] Added support for dynamic registration of module loaders - Also updated .gitignore to exclude more object files - UDI is now a dynamic module --- .gitignore | 7 +++++++ Kernel/Makefile | 4 ++-- Kernel/Makefile.BuildNum | 2 +- Kernel/include/modules.h | 26 +++++++++++++++++++++++--- Kernel/modules.c | 30 +++++++++++++++++++++++------- Makefile.cfg | 5 ++--- Modules/UDI/main.c | 21 ++++++++++++++++++++- 7 files changed, 78 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 0c72fdfb..9c916b87 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,10 @@ *.d *.ao *.ao.* +*.so +*.bin.* +*.dsm.* +*.dsm +*.dmp +Map.txt +map.txt diff --git a/Kernel/Makefile b/Kernel/Makefile index 1d0f363f..279f251d 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -15,9 +15,9 @@ KERNEL_VERSION = 0.5 MAKEDEP = $(CC) -M CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -CPPFLAGS += -DARCH=$(ARCH) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) +CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin -ASFLAGS += -D ARCH=\"$(ARCH)\" +ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\" LDFLAGS += -T arch/$(ARCHDIR)/link.ld ifeq ($(DEBUG_BUILD),yes) diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index d026f564..e85c4e56 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1353 +BUILD_NUM = 1359 diff --git a/Kernel/include/modules.h b/Kernel/include/modules.h index bf2dd4c5..591dbf92 100644 --- a/Kernel/include/modules.h +++ b/Kernel/include/modules.h @@ -8,13 +8,13 @@ #define MODULE_MAGIC ('A'|('M'<<8)|('D'<<16)|('\2'<<24)) // IA32 - Architecture 1 -#if ARCH == i386 || ARCH == i586 +#if ARCHDIR == x86 # define MODULE_ARCH_ID 1 // IA64 - Architecture 2 -#elif ARCH == x64 || ARCH == x86_64 +#elif ARCHDIR == x64 # define MODULE_ARCH_ID 2 #else -# error "Unknown architecture when determining MODULE_ARCH_ID ('" #ARCH "')" +# error "Unknown architecture when determining MODULE_ARCH_ID ('" #ARCHDIR "')" #endif #define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deinit,_deps...) char *_DriverDeps_##_ident[]={_deps};\ @@ -36,4 +36,24 @@ typedef struct sModule { #define MODULE_INIT_SUCCESS 1 #define MODULE_INIT_FAILURE 0 +/** + * \brief Module Loader definition + * + * Allows a module to extend the loader to recognise other module types + * E.g. EDI, UDI, Windows, Linux, ... + */ +typedef struct sModuleLoader { + struct sModuleLoader *Next; //!< Kernel Only - Next loader in list + char *Name; //!< Friendly name for the loader + int (*Detector)(void *Base); //!< Simple detector function + int (*Loader)(void *Base); //!< Initialises the module + int (*Unloader)(void *Base); //!< Calls module's cleanup +} PACKED tModuleLoader; + +/** + * \brief Registers a tModuleLoader with the kernel + * \param Loader Pointer to loader structure (must be persistent) + */ +extern int Module_RegisterLoader(tModuleLoader *Loader); + #endif diff --git a/Kernel/modules.c b/Kernel/modules.c index a206cf97..e4f49b28 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -27,6 +27,7 @@ extern void gKernelModulesEnd; int giNumBuiltinModules = 0; int giModuleSpinlock = 0; tModule *gLoadedModules = NULL; +tModuleLoader *gModule_Loaders = NULL; // === CODE === int Modules_LoadBuiltins() @@ -118,6 +119,20 @@ int Modules_LoadBuiltins() return 0; } +/** + * \brief Registers a tModuleLoader with the kernel + * \param Loader Pointer to loader structure (must be persistent) + */ +int Module_RegisterLoader(tModuleLoader *Loader) +{ + if(!Loader) return 1; + + Loader->Next = gModule_Loaders; + gModule_Loaders = Loader; + + return 0; +} + /** * \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString) * \brief Load a module from a memory location @@ -152,6 +167,14 @@ int Module_LoadFile(char *Path, char *ArgString) // Check for Acess Driver if( Binary_FindSymbol(base, "DriverInfo", (Uint*)&info ) == 0 ) { + tModuleLoader *tmp; + for( tmp = gModule_Loaders; tmp; tmp = tmp->Next) + { + if( tmp->Detector(base) == 0 ) continue; + + return tmp->Loader(base); + } + #if USE_EDI // Check for EDI Driver if( Binary_FindSymbol(base, "driver_init", NULL ) != 0 ) @@ -160,13 +183,6 @@ int Module_LoadFile(char *Path, char *ArgString) } #endif - #if USE_UDI - if( Binary_FindSymbol(base, "udi_init_info", NULL ) != 0 ) - { - return UDI_LoadDriver( base ); // And intialise - } - #endif - // Unknown module type?, return error Binary_Unload(base); #if USE_EDI diff --git a/Makefile.cfg b/Makefile.cfg index 3157e962..9363ff68 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -25,9 +25,8 @@ endif FILESYSTEMS = fat DRIVERS = ata_x86 -MODULES = FS_Ext2 FDD NE2000 BochsGA IPStack UDI -DYNMODS = USB -# UDI +MODULES = FS_Ext2 FDD NE2000 BochsGA IPStack +DYNMODS = USB UDI #DISTROOT = /mnt/AcessHDD/Acess2 #DISTROOT = ~/Projects/Acess2/Filesystem diff --git a/Modules/UDI/main.c b/Modules/UDI/main.c index 75ff3431..d114bdc9 100644 --- a/Modules/UDI/main.c +++ b/Modules/UDI/main.c @@ -9,10 +9,14 @@ // === PROTOTYPES === int UDI_Install(char **Arguments); + int UDI_DetectDriver(void *Base); int UDI_LoadDriver(void *Base); // === GLOBALS === MODULE_DEFINE(0, VERSION, UDI, UDI_Install, NULL, NULL); +tModuleLoader gUDI_Loader = { + NULL, "UDI", UDI_DetectDriver, UDI_LoadDriver, NULL +}; // === CODE === /** @@ -21,6 +25,19 @@ MODULE_DEFINE(0, VERSION, UDI, UDI_Install, NULL, NULL); */ int UDI_Install(char **Arguments) { + Module_RegisterLoader( &gUDI_Loader ); + return 1; +} + +/** + * \brief Detects if a driver should be loaded by the UDI subsystem + */ +int UDI_DetectDriver(void *Base) +{ + if( Binary_FindSymbol(Base, "udi_init_info", NULL) == 0) { + return 0; + } + return 1; } @@ -31,7 +48,7 @@ int UDI_LoadDriver(void *Base) { udi_init_t *info; char *udiprops = NULL; - int udiprops_size; + int udiprops_size = 0; int i; // int j; @@ -47,8 +64,10 @@ int UDI_LoadDriver(void *Base) } else { Binary_FindSymbol(Base, "_udiprops_size", (Uint*)&udiprops_size); + Log("udiprops = %p, udiprops_size = 0x%x", udiprops, udiprops_size); } + Log("primary_init_info = %p = {", info->primary_init_info); { Log(" .mgmt_ops = %p = {", info->primary_init_info->mgmt_ops); -- 2.20.1