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);
26 // - Modules/Display/VESA
27 extern void VBE_int_SetBootMode(Uint16 ModeID, const void *ModeInfo);
30 int kmain(Uint MbMagic, void *MbInfoPtr);
33 char *gsBootCmdLine = NULL;
34 tBootModule *gaArch_BootModules;
35 int giArch_NumBootModules = 0;
38 int kmain(Uint MbMagic, void *MbInfoPtr)
41 tPMemMapEnt pmemmap[MAX_PMEMMAP_ENTS];
44 LogF("%s\r\n", gsBuildInfo);
46 MM_PreinitVirtual(); // Initialise virtual mappings
53 case MULTIBOOT_MAGIC: {
54 // TODO: Handle when this isn't in the mapped area
55 ASSERT( mbInfo->CommandLine < 4*1024*1024 );
56 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
58 // Adjust Multiboot structure address
59 mbInfo = (void*)( (tVAddr)MbInfoPtr + KERNEL_BASE );
62 // - mbInfo->Flags is checked in this function
63 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
64 KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE);
68 Debug("mbInfo->Flags = 0x%x", mbInfo->Flags);
69 if( mbInfo->Flags & (1 << 11) )
71 // TODO: Ensure address is in mapped area
72 ASSERT( mbInfo->vbe_mode_info < 4*1024*1024 );
73 VBE_int_SetBootMode(mbInfo->vbe_mode, (void*)(mbInfo->vbe_mode_info + KERNEL_BASE));
79 case MULTIBOOT2_MAGIC:
80 Panic("Multiboot 2 not yet supported");
81 //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager
86 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
87 MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
91 // Set up physical memory manager
92 MM_Install(nPMemMapEnts, pmemmap);
94 MM_InstallVirtual(); // Clean up virtual address space
95 Heap_Install(); // Create initial heap
96 Time_Setup(); // Initialise timing
106 Log_Log("Arch", "Starting VFS...");
107 // Load Virtual Filesystem
110 // Load initial modules
111 gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules);
113 // Pass on to Independent Loader
114 Log_Log("Arch", "Starting system");
115 System_Init(gsBootCmdLine);
117 // Sleep forever (sleeping beauty)
123 void Arch_LoadBootModules(void)
125 for( int i = 0; i < giArch_NumBootModules; i ++ )
127 const tBootModule *mod = &gaArch_BootModules[i];
128 Log_Log("Arch", "Loading (%p[%P]+%x) '%s'",
129 mod->Base, mod->PBase, mod->Size,
132 if( !Module_LoadMem( mod->Base, mod->Size, mod->ArgString) ) {
133 Log_Warning("Arch", "Unable to load module");
139 int numPages = (mod->Size + ((tVAddr)mod->Base&0xFFF) + 0xFFF) >> 12;
140 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages );
142 //for( int j = 0; j < numPages; j++ )
143 // MM_DerefPhys( mod->PBase + (j << 12) );
145 if( (tVAddr) mod->ArgString > MAX_ARGSTR_POS )
146 MM_UnmapHWPages( (tVAddr)mod->ArgString, 2 );
149 Log_Log("Arch", "Boot modules loaded");
150 if( gaArch_BootModules )
151 free( gaArch_BootModules );