8 #include <multiboot2.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 Heap_Install(void);
23 extern void MM_PreinitVirtual(void);
24 extern void MM_Install(int NPMemRanges, tPMemMapEnt *PMemRanges);
25 extern void MM_InstallVirtual(void);
26 extern int Time_Setup(void);
27 //extern int ACPICA_Initialise(void);
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 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
57 // Adjust Multiboot structure address
58 mbInfo = (void*)( (tVAddr)MbInfoPtr + KERNEL_BASE );
60 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
61 KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE);
66 case MULTIBOOT2_MAGIC:
67 Panic("Multiboot 2 not yet supported");
68 //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager
73 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
74 MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
78 // Set up physical memory manager
79 MM_Install(nPMemMapEnts, pmemmap);
81 MM_InstallVirtual(); // Clean up virtual address space
82 Heap_Install(); // Create initial heap
83 Time_Setup(); // Initialise timing
89 // ACPICA_Initialise();
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)
111 for( i = 0; i < giArch_NumBootModules; i ++ )
113 Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString);
115 if( !Module_LoadMem( gaArch_BootModules[i].Base,
116 gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString
119 Log_Warning("Arch", "Unable to load module");
123 numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12;
124 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages );
126 for( j = 0; j < numPages; j++ )
127 MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) );
129 if( (tVAddr) gaArch_BootModules[i].ArgString > MAX_ARGSTR_POS )
130 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 );
132 Log_Log("Arch", "Boot modules loaded");
133 if( gaArch_BootModules )
134 free( gaArch_BootModules );