3 * - By John Hodge (thePowersGang)
6 * - Kernel C entrypoint
15 #define KERNEL_LOAD 0x100000
16 #define MAX_PMEMMAP_ENTS 16
17 #define MAX_ARGSTR_POS (0x200000-0x2000)
20 extern void Desctab_Init(void);
21 extern void MM_InitVirt(void);
22 extern void Heap_Install(void);
23 extern int Time_Setup(void);
25 extern char gKernelEnd[];
28 void kmain(Uint MbMagic, void *MbInfoPtr);
31 char *gsBootCmdLine = NULL;
32 tBootModule *gaArch_BootModules;
33 int giArch_NumBootModules = 0;
36 void kmain(Uint MbMagic, void *MbInfoPtr)
39 tPMemMapEnt pmemmap[MAX_PMEMMAP_ENTS];
42 LogF("%s\r\n", gsBuildInfo);
47 *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'C';
53 // Adjust Multiboot structure address
54 mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
55 gsBootCmdLine = (char*)( (Uint)mbInfo->CommandLine + KERNEL_BASE);
57 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
58 KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE
62 Panic("Multiboot magic invalid %08x, expected %08x\n",
63 MbMagic, MULTIBOOT_MAGIC);
67 MM_InitPhys( nPMemMapEnts, pmemmap ); // Set up physical memory manager
68 Log("gsBootCmdLine = '%s'", gsBootCmdLine);
73 MM_RefPhys( mbInfo->CommandLine );
77 *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'D';
80 *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'E';
84 *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'F';
86 // Load Virtual Filesystem
87 Log_Log("Arch", "Starting VFS...");
90 gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules);
92 *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'Z';
94 // Pass on to Independent Loader
95 Log_Log("Arch", "Starting system");
96 System_Init(gsBootCmdLine);
98 // Sleep forever (sleeping beauty)
103 void Arch_LoadBootModules(void)
106 Log("gsBootCmdLine = '%s'", gsBootCmdLine);
107 for( i = 0; i < giArch_NumBootModules; i ++ )
109 Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString);
111 if( !Module_LoadMem( gaArch_BootModules[i].Base,
112 gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString
115 Log_Warning("Arch", "Unable to load module");
119 numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12;
120 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages );
122 for( j = 0; j < numPages; j++ )
123 MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) );
125 if( (tVAddr) gaArch_BootModules[i].ArgString < KERNEL_BASE )
126 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 );
128 Log_Log("Arch", "Boot modules loaded");
129 if( gaArch_BootModules )
130 free( gaArch_BootModules );
133 void StartupPrint(const char *String)