Added support for dynamic registration of module loaders
authorJohn Hodge <tpg@prelude.(none)>
Sun, 17 Jan 2010 06:05:38 +0000 (14:05 +0800)
committerJohn Hodge <tpg@prelude.(none)>
Sun, 17 Jan 2010 06:05:38 +0000 (14:05 +0800)
- Also updated .gitignore to exclude more object files
- UDI is now a dynamic module

.gitignore
Kernel/Makefile
Kernel/Makefile.BuildNum
Kernel/include/modules.h
Kernel/modules.c
Makefile.cfg
Modules/UDI/main.c

index 0c72fdf..9c916b8 100644 (file)
@@ -5,3 +5,10 @@
 *.d
 *.ao
 *.ao.*
+*.so
+*.bin.*
+*.dsm.*
+*.dsm
+*.dmp
+Map.txt
+map.txt
index 1d0f363..279f251 100644 (file)
@@ -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)
index d026f56..e85c4e5 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1353
+BUILD_NUM = 1359
index bf2dd4c..591dbf9 100644 (file)
@@ -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
index a206cf9..e4f49b2 100644 (file)
@@ -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
index 3157e96..9363ff6 100644 (file)
@@ -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
index 75ff343..d114bdc 100644 (file)
@@ -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);

UCC git Repository :: git.ucc.asn.au