8 #include <multiboot2.h>
15 #define KERNEL_LOAD 0x100000 // 1MiB
16 #define MAX_ARGSTR_POS (0x400000-0x2000)
17 #define MAX_PMEMMAP_ENTS 16
20 extern char gKernelEnd[];
21 extern void MM_PreinitVirtual(void);
22 extern void MM_Install(int NPMemRanges, tPMemMapEnt *PMemRanges);
23 extern void MM_InstallVirtual(void);
24 extern int Time_Setup(void);
25 extern int ACPICA_Initialise(void);
28 int kmain(Uint MbMagic, void *MbInfoPtr);
31 char *gsBootCmdLine = NULL;
32 tBootModule *gaArch_BootModules;
33 int giArch_NumBootModules = 0;
36 int kmain(Uint MbMagic, void *MbInfoPtr)
39 tPMemMapEnt pmemmap[MAX_PMEMMAP_ENTS];
42 LogF("%s\r\n", gsBuildInfo);
44 MM_PreinitVirtual(); // Initialise virtual mappings
51 case MULTIBOOT_MAGIC: {
52 // TODO: Handle when this isn't in the mapped area
53 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
55 // Adjust Multiboot structure address
56 mbInfo = (void*)( (tVAddr)MbInfoPtr + KERNEL_BASE );
58 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
59 KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE);
64 case MULTIBOOT2_MAGIC:
65 Panic("Multiboot 2 not yet supported");
66 //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager
71 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
72 MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
76 // Set up physical memory manager
77 MM_Install(nPMemMapEnts, pmemmap);
79 MM_InstallVirtual(); // Clean up virtual address space
80 Heap_Install(); // Create initial heap
81 Time_Setup(); // Initialise timing
91 Log_Log("Arch", "Starting VFS...");
92 // Load Virtual Filesystem
95 // Load initial modules
96 gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules);
98 // Pass on to Independent Loader
99 Log_Log("Arch", "Starting system");
100 System_Init(gsBootCmdLine);
102 // Sleep forever (sleeping beauty)
108 void Arch_LoadBootModules(void)
110 for( int i = 0; i < giArch_NumBootModules; i ++ )
112 const tBootModule *mod = &gaArch_BootModules[i];
113 Log_Log("Arch", "Loading (%p[%P]+%x) '%s'",
114 mod->Base, mod->PBase, mod->Size,
117 if( !Module_LoadMem( mod->Base, mod->Size, mod->ArgString) ) {
118 Log_Warning("Arch", "Unable to load module");
124 int numPages = (mod->Size + ((tVAddr)mod->Base&0xFFF) + 0xFFF) >> 12;
125 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages );
127 //for( int j = 0; j < numPages; j++ )
128 // MM_DerefPhys( mod->PBase + (j << 12) );
130 if( (tVAddr) mod->ArgString > MAX_ARGSTR_POS )
131 MM_UnmapHWPages( (tVAddr)mod->ArgString, 2 );
134 Log_Log("Arch", "Boot modules loaded");
135 if( gaArch_BootModules )
136 free( gaArch_BootModules );