Show
Ignore:
Timestamp:
05/24/08 09:54:46 (6 months ago)
Author:
mwhitworth
Message:

Create startup module.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/kernel/module.c

    r490 r538  
    2929#include <sys.h> 
    3030#include <task.h> 
     31#include <imports.h> 
    3132 
    3233LIST_HEAD(moduleList); 
     34 
     35static struct Module bootModules[20]; 
     36int bootIndex=0; 
    3337 
    3438#define MODULE_START    0xD8000000 
     
    8387 
    8488                if (name) 
    85                         printf("%s+%#X/%#X\n", name, offset, size); 
     89                        KePrint("%s+%#X/%#X\n", name, offset, size); 
    8690                else 
    87                         printf("%#X\n", address); 
     91                        KePrint("%#X\n", address); 
    8892        }else 
    89                 printf("%#X\n", address); 
     93                KePrint("%#X\n", address); 
    9094} 
    9195 
     
    106110void ModuleSymbolPrint(DWORD address) 
    107111{ 
    108         printf("%#X\n", address); 
     112        KePrint("%#X\n", address); 
    109113} 
    110114 
     
    148152        } 
    149153 
    150         printf("Could not resolve %s\n", name); 
     154        KePrint("Could not resolve %s\n", name); 
    151155 
    152156        return 0; 
     
    191195                                        break; 
    192196 
    193                                 printf("Could not resolve %s\n", symName); 
     197                                KePrint("Could not resolve %s\n", symName); 
    194198                                return -ENOENT; 
    195199 
     
    200204                        /* Common symbols aren't supported by the module loading code. */ 
    201205                        case STN_COMMON: 
    202                                 printf("Please recompile the module with -fno-common.\n"); 
     206                                KePrint("Please recompile the module with -fno-common.\n"); 
    203207                                return -ENOENT; 
    204208 
     
    240244 
    241245                        default: 
    242                                 printf("ModuleSymbolResolve: type = %u, %u\n", ELF_R_TYPE(reloc->info), symbol->symIndex); 
     246                                KePrint("ModuleSymbolResolve: type = %u, %u\n", ELF_R_TYPE(reloc->info), symbol->symIndex); 
    243247                } 
    244248        } 
     
    286290 
    287291        /* Get basic information about the module. */ 
    288         module=(struct Module*)malloc(sizeof(struct Module)); 
     292        if (MemAlloc) 
     293                module=(struct Module*)MemAlloc(sizeof(struct Module)); 
     294        else 
     295                module=&bootModules[bootIndex++]; 
     296 
    289297        module->loadAddr=loadAddr; 
    290298        module->sectionHeaders=sectionHeaders; 
     
    362370} 
    363371 
     372#define SYS_MODULE_BASE         51 
     373 
     374int SysModuleAdd(void* data, unsigned long length); 
     375int SysModuleRemove(const char* name); 
     376 
     377struct SysCall moduleSysCalls[]={ 
     378        { SysModuleAdd, 8 }, 
     379        { SysModuleRemove, 4}, 
     380        { 0, 0 } 
     381}; 
     382 
     383void ModulesBootLoad() 
     384{ 
     385        /* The modules are located above the kernel in memory. */ 
     386        BYTE* numModules=(BYTE*)0x2FFFF; 
     387        int i=0; 
     388        DWORD* length=(DWORD*)0x40000; 
     389        char* names=(char*)0x30000; 
     390 
     391        for (i=0; i<*numModules; i++) 
     392        { 
     393                /* Load each module, one at a time. */ 
     394                BYTE* data=(BYTE*)(length+1); 
     395                void* kData=(void*)VirtMapPhysRange(MODULE_START, MODULE_END, PAGE_ALIGN_UP(*length) >> PAGE_SHIFT, 3); 
     396                char buf[32]; 
     397 
     398                int j=0; 
     399 
     400                while (names[j] != '\n') 
     401                        j++; 
     402 
     403                names[j]='\0'; 
     404 
     405                strcpy(buf, names); 
     406                strcat(buf, ".sys"); 
     407 
     408                if (ModuleAdd(data, kData, *length, 0)) 
     409                        KernelPanic("Could not initialize the kernel"); 
     410 
     411                KePrint("MODULES: Loaded %s, %dkb\n", buf, (*length)/1024); 
     412 
     413                names+=strlen(names)+1; 
     414 
     415                length+=(*length/4)+1; 
     416        } 
     417 
     418        /* Free the low pages. */ 
     419 
     420        /* Add the calls to the system table. */ 
     421        SysRegisterRange(SYS_MODULE_BASE, moduleSysCalls); 
     422} 
     423 
    364424int SysModuleAdd(void* data, unsigned long length) 
    365425{ 
     
    374434int SysModuleRemove(const char* name) 
    375435{ 
    376         printf("SysModuleRemove\n"); 
     436        KePrint("SysModuleRemove\n"); 
    377437        return 0; 
    378438}