X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86_64%2Fmain.c;h=bd8bb4a4b04c16cf51ec6a8248b71306796fe831;hb=d7dcea0e5a8df0f479e99f168a10b9a9535c7ad6;hp=4fb667012548ff57031d23f9f0281a446ea669fd;hpb=188021d7737255ce5f4f26b9f047b578b4a8969d;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/arch/x86_64/main.c b/KernelLand/Kernel/arch/x86_64/main.c index 4fb66701..bd8bb4a4 100644 --- a/KernelLand/Kernel/arch/x86_64/main.c +++ b/KernelLand/Kernel/arch/x86_64/main.c @@ -1,31 +1,44 @@ /* - * Acess2 x86_64 Project + * Acess2 Kernel x86_64 + * - By John Hodge (thePowersGang) + * + * main.c + * - Kernel C entrypoint */ #include #include #include +#include +#include + +// === CONSTANTS === +#define KERNEL_LOAD 0x100000 +#define MAX_PMEMMAP_ENTS 16 +#define MAX_ARGSTR_POS (0x200000-0x2000) // === IMPORTS === extern void Desctab_Init(void); extern void MM_InitVirt(void); -extern void Heap_Install(void); extern int Time_Setup(void); -extern void MM_InitPhys_Multiboot(tMBoot_Info *MBoot); +extern char gKernelEnd[]; // === PROTOTYPES === void kmain(Uint MbMagic, void *MbInfoPtr); // === GLOBALS == char *gsBootCmdLine = NULL; +tBootModule *gaArch_BootModules; + int giArch_NumBootModules = 0; // === CODE === void kmain(Uint MbMagic, void *MbInfoPtr) { tMBoot_Info *mbInfo; + tPMemMapEnt pmemmap[MAX_PMEMMAP_ENTS]; + int nPMemMapEnts; - LogF("Acess2 x86_64 v"EXPAND_STR(KERNEL_VERSION)"\n"); - LogF(" Build %i, Git Hash %s\n", BUILD_NUM, gsGitHash); + LogF("%s\r\n", gsBuildInfo); Desctab_Init(); @@ -39,7 +52,9 @@ void kmain(Uint MbMagic, void *MbInfoPtr) // Adjust Multiboot structure address mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE ); gsBootCmdLine = (char*)( (Uint)mbInfo->CommandLine + KERNEL_BASE); - MM_InitPhys_Multiboot( mbInfo ); // Set up physical memory manager + nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS, + KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE + ); break; default: Panic("Multiboot magic invalid %08x, expected %08x\n", @@ -47,8 +62,16 @@ void kmain(Uint MbMagic, void *MbInfoPtr) return ; } + MM_InitPhys( nPMemMapEnts, pmemmap ); // Set up physical memory manager Log("gsBootCmdLine = '%s'", gsBootCmdLine); + switch(MbMagic) + { + case MULTIBOOT_MAGIC: + MM_RefPhys( mbInfo->CommandLine ); + break; + } + *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'D'; Heap_Install(); @@ -62,6 +85,10 @@ void kmain(Uint MbMagic, void *MbInfoPtr) Log_Log("Arch", "Starting VFS..."); VFS_Init(); + // Multiboot_InitFramebuffer(mbInfo); + + gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules); + *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'Z'; // Pass on to Independent Loader @@ -75,7 +102,33 @@ void kmain(Uint MbMagic, void *MbInfoPtr) void Arch_LoadBootModules(void) { - + int i, j, numPages; + Log("gsBootCmdLine = '%s'", gsBootCmdLine); + for( i = 0; i < giArch_NumBootModules; i ++ ) + { + Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString); + + if( !Module_LoadMem( gaArch_BootModules[i].Base, + gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString + ) ) + { + Log_Warning("Arch", "Unable to load module"); + } + + // Unmap and free + numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12; + MM_UnmapHWPages( gaArch_BootModules[i].Base, numPages ); + + for( j = 0; j < numPages; j++ ) + MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) ); + + // TODO: What the fuck? + if( (tVAddr) gaArch_BootModules[i].ArgString < KERNEL_BASE ) + MM_UnmapHWPages( gaArch_BootModules[i].ArgString, 2 ); + } + Log_Log("Arch", "Boot modules loaded"); + if( gaArch_BootModules ) + free( gaArch_BootModules ); } void StartupPrint(const char *String)