8 #include <multiboot2.h>
12 #include <semaphore.h>
16 #define KERNEL_LOAD 0x100000 // 1MiB
17 #define MAX_ARGSTR_POS (0x400000-0x2000)
18 #define MAX_PMEMMAP_ENTS 16
21 extern char gKernelEnd[];
22 extern void MM_PreinitVirtual(void);
23 extern void MM_Install(int NPMemRanges, tPMemMapEnt *PMemRanges);
24 extern void MM_InstallVirtual(void);
25 extern int Time_Setup(void);
26 extern int ACPICA_Initialise(void);
27 // - Modules/Display/VESA
28 extern void VBE_int_SetBootMode(Uint16 ModeID, const void *ModeInfo);
31 int kmain(Uint MbMagic, void *MbInfoPtr);
34 char *gsBootCmdLine = NULL;
35 tBootModule *gaArch_BootModules;
36 int giArch_NumBootModules = 0;
39 int kmain(Uint MbMagic, void *MbInfoPtr)
42 tPMemMapEnt pmemmap[MAX_PMEMMAP_ENTS];
45 LogF("%s\r\n", gsBuildInfo);
47 MM_PreinitVirtual(); // Initialise virtual mappings
54 case MULTIBOOT_MAGIC: {
55 // TODO: Handle when this isn't in the mapped area
56 ASSERT( mbInfo->CommandLine < 4*1024*1024 );
57 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
59 // Adjust Multiboot structure address
60 mbInfo = (void*)( (tVAddr)MbInfoPtr + KERNEL_BASE );
63 // - mbInfo->Flags is checked in this function
64 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
65 KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE);
69 Debug("mbInfo->Flags = 0x%x", mbInfo->Flags);
70 if( mbInfo->Flags & (1 << 11) )
72 // TODO: Ensure address is in mapped area
73 ASSERT( mbInfo->vbe_mode_info < 4*1024*1024 );
74 VBE_int_SetBootMode(mbInfo->vbe_mode, (void*)(mbInfo->vbe_mode_info + KERNEL_BASE));
80 case MULTIBOOT2_MAGIC:
81 Panic("Multiboot 2 not yet supported");
82 //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager
87 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
88 MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
92 // Set up physical memory manager
93 MM_Install(nPMemMapEnts, pmemmap);
95 MM_InstallVirtual(); // Clean up virtual address space
96 Heap_Install(); // Create initial heap
97 Time_Setup(); // Initialise timing
107 Log_Log("Arch", "Starting VFS...");
108 // Load Virtual Filesystem
111 // Load initial modules
112 gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules);
114 // Pass on to Independent Loader
115 Log_Log("Arch", "Starting system");
116 System_Init(gsBootCmdLine);
118 // Sleep forever (sleeping beauty)
124 void Arch_LoadBootModules(void)
126 for( int i = 0; i < giArch_NumBootModules; i ++ )
128 const tBootModule *mod = &gaArch_BootModules[i];
129 Log_Log("Arch", "Loading (%p[%P]+%x) '%s'",
130 mod->Base, mod->PBase, mod->Size,
133 if( !Module_LoadMem( mod->Base, mod->Size, mod->ArgString) ) {
134 Log_Warning("Arch", "Unable to load module");
138 Log_Log("Arch", "Boot modules loaded");
139 Multiboot_FreeModules(giArch_NumBootModules, gaArch_BootModules);
140 giArch_NumBootModules = 0;
141 gaArch_BootModules = NULL;