8 #include <multiboot2.h>
15 #define MAX_ARGSTR_POS (0x400000-0x2000)
18 extern void Heap_Install(void);
19 extern void Desctab_Install(void);
20 extern void MM_PreinitVirtual(void);
21 extern void MM_Install(tMBoot_Info *MBoot);
22 extern void MM_InstallVirtual(void);
23 extern void Threads_Init(void);
24 extern int Time_Setup(void);
25 extern Uint Proc_Clone(Uint *Err, Uint Flags);
26 extern void Threads_Sleep(void);
28 extern void System_Init(char *Commandline);
31 void Arch_LoadBootModules(void);
34 char *gsBootCmdLine = NULL;
39 } *gaArch_BootModules;
40 int giArch_NumBootModules = 0;
43 int kmain(Uint MbMagic, void *MbInfoPtr)
49 Log("MbMagic = %08x", MbMagic);
50 Log("MbInfoPtr = %p", MbInfoPtr);
52 // Set up non-boot info dependent stuff
53 Desctab_Install(); // Set up GDT and IDT
54 MM_PreinitVirtual(); // Initialise virtual mappings
60 // Adjust Multiboot structure address
61 mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
62 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
64 MM_Install( mbInfo ); // Set up physical memory manager
68 case MULTIBOOT2_MAGIC:
69 Warning("Multiboot 2 Not yet supported");
70 //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager
75 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
76 MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
80 MM_InstallVirtual(); // Clean up virtual address space
81 Heap_Install(); // Create initial heap
83 //Log_Log("Arch", "Starting Multitasking...");
90 Log_Log("Arch", "Starting VFS...");
91 // Load Virtual Filesystem
94 // Load initial modules
95 mods = (void*)( mbInfo->Modules + KERNEL_BASE );
96 giArch_NumBootModules = mbInfo->ModuleCount;
97 gaArch_BootModules = malloc( giArch_NumBootModules * sizeof(*gaArch_BootModules) );
98 for( i = 0; i < mbInfo->ModuleCount; i ++ )
102 Log_Log("Arch", "Multiboot Module at 0x%08x, 0x%08x bytes (String at 0x%08x)",
103 mods[i].Start, mods[i].End-mods[i].Start, mods[i].String);
105 // Always HW map the module data
106 gaArch_BootModules[i].Size = mods[i].End - mods[i].Start;
108 ofs = mods[i].Start&0xFFF;
109 gaArch_BootModules[i].Base = (void*)( MM_MapHWPages(mods[i].Start,
110 (gaArch_BootModules[i].Size+ofs+0xFFF) / 0x1000
113 // Only map the string if needed
114 if( (tVAddr)mods[i].String > MAX_ARGSTR_POS )
116 // Assumes the string is < 4096 bytes long)
117 gaArch_BootModules[i].ArgString = (void*)(
118 MM_MapHWPages(mods[i].String, 2) + (mods[i].String&0xFFF)
122 gaArch_BootModules[i].ArgString = (char *)mods[i].String + KERNEL_BASE;
125 // Pass on to Independent Loader
126 Log_Log("Arch", "Starting system");
127 System_Init(gsBootCmdLine);
129 // Sleep forever (sleeping beauty)
135 void Arch_LoadBootModules(void)
138 for( i = 0; i < giArch_NumBootModules; i ++ )
140 Log_Debug("Arch", "Module %i: %p - %p 0x%x",
141 i, gaArch_BootModules[i].ArgString,
142 gaArch_BootModules[i].Base, gaArch_BootModules[i].Size
144 Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString);
146 if( !Module_LoadMem( gaArch_BootModules[i].Base, gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString ) )
148 Log_Warning("Arch", "Unable to load module");
152 (tVAddr)gaArch_BootModules[i].Base,
153 (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12
156 if( (tVAddr) gaArch_BootModules[i].ArgString > MAX_ARGSTR_POS )
157 MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 );
159 Log_Log("Arch", "Boot modules loaded");
160 free( gaArch_BootModules );