8 #include <multiboot2.h>
16 extern void Heap_Install(void);
17 extern void Desctab_Install(void);
18 extern void MM_PreinitVirtual(void);
19 extern void MM_Install(tMBoot_Info *MBoot);
20 extern void MM_InstallVirtual(void);
21 extern void Threads_Init(void);
22 extern int Time_Setup(void);
23 extern Uint Proc_Clone(Uint *Err, Uint Flags);
24 extern void Threads_Sleep(void);
26 extern void System_Init(char *Commandline);
29 void Arch_LoadBootModules(void);
32 char *gsBootCmdLine = NULL;
37 } *gaArch_BootModules;
38 int giArch_NumBootModules = 0;
41 int kmain(Uint MbMagic, void *MbInfoPtr)
47 Log("MbMagic = %08x", MbMagic);
48 Log("MbInfoPtr = %p", MbInfoPtr);
50 // Set up non-boot info dependent stuff
51 Desctab_Install(); // Set up GDT and IDT
52 MM_PreinitVirtual(); // Initialise virtual mappings
58 // Adjust Multiboot structure address
59 mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
60 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
62 MM_Install( mbInfo ); // Set up physical memory manager
66 case MULTIBOOT2_MAGIC:
67 Warning("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 MM_InstallVirtual(); // Clean up virtual address space
79 Heap_Install(); // Create initial heap
81 //Log_Log("Arch", "Starting Multitasking...");
88 Log_Log("Arch", "Starting VFS...");
89 // Load Virtual Filesystem
92 // Load initial modules
93 mods = (void*)( mbInfo->Modules + KERNEL_BASE );
94 giArch_NumBootModules = mbInfo->ModuleCount;
95 gaArch_BootModules = malloc( giArch_NumBootModules * sizeof(*gaArch_BootModules) );
96 for( i = 0; i < mbInfo->ModuleCount; i ++ )
99 // TODO: Handle this better by using MM_MapHW/MM_MapTemp
100 // Adjust into higher half
101 //mods[i].Start += KERNEL_BASE;
102 //mods[i].End += KERNEL_BASE;
103 mods[i].String += KERNEL_BASE;
105 gaArch_BootModules[i].Size = mods[i].End - mods[i].Start;
107 ofs = mods[i].Start&0xFFF;
108 gaArch_BootModules[i].Base = (void*)( MM_MapHWPages(mods[i].Start,
109 (gaArch_BootModules[i].Size+ofs+0xFFF) / 0x1000
111 //gaArch_BootModules[i].ArgString = MM_MapHW(mods[i].String, 1)
112 // + (mods[i].String&0xFFF);
114 //gaArch_BootModules[i].Base = (void *)mods[i].Start;
115 gaArch_BootModules[i].ArgString = (char *)mods[i].String + KERNEL_BASE;
118 // Pass on to Independent Loader
119 Log_Log("Arch", "Starting system");
120 System_Init(gsBootCmdLine);
122 // Sleep forever (sleeping beauty)
128 void Arch_LoadBootModules(void)
131 for( i = 0; i < giArch_NumBootModules; i ++ )
133 Log_Debug("Arch", "Module %i: %p - %p 0x%x",
134 i, gaArch_BootModules[i].ArgString,
135 gaArch_BootModules[i].Base, gaArch_BootModules[i].Size
137 Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString);
139 if( !Module_LoadMem( gaArch_BootModules[i].Base, gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString ) )
141 Log_Warning("Arch", "Unable to load module");
145 (tVAddr)gaArch_BootModules[i].Base,
146 (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12
149 Log_Log("Arch", "Boot modules loaded");
150 free( gaArch_BootModules );