3 * Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "multiboot.h"
31 BOOL
LoadReactOSKernel(PUCHAR OperatingSystemName
);
32 BOOL
LoadReactOSDrivers(PUCHAR OperatingSystemName
);
34 void LoadAndBootReactOS(PUCHAR OperatingSystemName
)
39 char szFileName
[1024];
42 int nNumDriverFiles
=0;
43 int nNumFilesLoaded
=0;
48 // Open the operating system section
49 // specified in the .ini file
51 if (!OpenSection(OperatingSystemName
, &SectionId
))
53 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
54 MessageBox(MsgBuffer
);
59 * Setup multiboot information structure
61 mb_info
.flags
= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
62 mb_info
.mem_lower
= GetConventionalMemorySize();
63 mb_info
.mem_upper
= GetExtendedMemorySize();
64 mb_info
.boot_device
= 0xffffffff;
65 mb_info
.cmdline
= (unsigned long)multiboot_kernel_cmdline
;
66 mb_info
.mods_count
= 0;
67 mb_info
.mods_addr
= (unsigned long)multiboot_modules
;
68 mb_info
.mmap_length
= GetBiosMemoryMap(&multiboot_memory_map
);
69 if (mb_info
.mmap_length
)
71 mb_info
.mmap_addr
= (unsigned long)&multiboot_memory_map
;
72 mb_info
.flags
|= MB_INFO_FLAG_MEMORY_MAP
;
73 //printf("memory map length: %d\n", mb_info.mmap_length);
74 //printf("dumping memory map:\n");
75 //for (i=0; i<(mb_info.mmap_length / 4); i++)
77 // printf("0x%x\n", ((unsigned long *)&multiboot_memory_map)[i]);
81 //printf("low_mem = %d\n", mb_info.mem_lower);
82 //printf("high_mem = %d\n", mb_info.mem_upper);
85 * Make sure the system path is set in the .ini file
87 if (!ReadSectionSettingByName(SectionId
, "SystemPath", value
, 1024))
89 MessageBox("System path not specified for selected operating system.");
96 if (!DissectArcPath(value
, szBootPath
, &BootDrive
, &BootPartition
))
98 sprintf(MsgBuffer
,"Invalid system path: '%s'", value
);
99 MessageBox(MsgBuffer
);
103 /* set boot drive and partition */
104 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
105 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
107 /* copy ARC path into kernel command line */
108 strcpy(multiboot_kernel_cmdline
, value
);
111 * Read the optional kernel parameters (if any)
113 if (ReadSectionSettingByName(SectionId
, "Options", value
, 1024))
115 strcat(multiboot_kernel_cmdline
, " ");
116 strcat(multiboot_kernel_cmdline
, value
);
119 /* append a backslash */
120 if ((strlen(szBootPath
)==0) ||
121 szBootPath
[strlen(szBootPath
)] != '\\')
122 strcat(szBootPath
, "\\");
125 * Find the kernel image name
127 if(!ReadSectionSettingByName(SectionId
, "Kernel", value
, 1024))
129 MessageBox("Kernel image file not specified for selected operating system.");
134 * Find the hal image name
136 if(!ReadSectionSettingByName(SectionId
, "Hal", value
, 1024))
138 MessageBox("HAL image file not specified for selected operating system.");
144 DrawStatusText(" Loading...");
148 * Try to open boot drive
150 if (!OpenDiskDrive(BootDrive
, BootPartition
))
152 MessageBox("Failed to open boot drive.");
157 * Parse the ini file and count the kernel, hal and drivers
159 for (i
=1; i
<=GetNumSectionItems(SectionId
); i
++)
162 * Read the setting and check if it's a driver
164 ReadSectionSettingByNumber(SectionId
, i
, name
, 1024, value
, 1024);
165 if ((stricmp(name
, "Kernel") == 0) ||
166 (stricmp(name
, "Hal") == 0) ||
167 (stricmp(name
, "Driver") == 0))
172 * Find the kernel image name
173 * and try to load the kernel off the disk
175 if(ReadSectionSettingByName(SectionId
, "Kernel", value
, 1024))
178 * Set the name and try to open the PE image
180 //strcpy(szFileName, szBootPath);
181 //strcat(szFileName, value);
182 strcpy(szFileName
, value
);
184 FilePointer
= OpenFile(szFileName
);
185 if (FilePointer
== NULL
)
187 strcat(value
, " not found.");
193 * Update the status bar with the current file
195 strcpy(name
, " Reading ");
197 while (strlen(name
) < 80)
199 DrawStatusText(name
);
202 * Load the kernel image
204 MultiBootLoadKernel(FilePointer
);
207 DrawProgressBar((nNumFilesLoaded
* 100) / nNumDriverFiles
);
211 * Find the HAL image name
212 * and try to load the kernel off the disk
214 if(ReadSectionSettingByName(SectionId
, "Hal", value
, 1024))
217 * Set the name and try to open the PE image
219 //strcpy(szFileName, szBootPath);
220 //strcat(szFileName, value);
221 strcpy(szFileName
, value
);
223 FilePointer
= OpenFile(szFileName
);
224 if (FilePointer
== NULL
)
226 strcat(value
, " not found.");
232 * Update the status bar with the current file
234 strcpy(name
, " Reading ");
236 while (strlen(name
) < 80)
238 DrawStatusText(name
);
243 MultiBootLoadModule(FilePointer
, szFileName
);
246 DrawProgressBar((nNumFilesLoaded
* 100) / nNumDriverFiles
);
250 * Parse the ini file and load the kernel and
251 * load all the drivers specified
253 for (i
=1; i
<=GetNumSectionItems(SectionId
); i
++)
256 * Read the setting and check if it's a driver
258 ReadSectionSettingByNumber(SectionId
, i
, name
, 1024, value
, 1024);
259 if (stricmp(name
, "Driver") == 0)
262 * Set the name and try to open the PE image
264 //strcpy(szFileName, szBootPath);
265 //strcat(szFileName, value);
266 strcpy(szFileName
, value
);
268 FilePointer
= OpenFile(szFileName
);
269 if (FilePointer
== NULL
)
271 strcat(value
, " not found.");
277 * Update the status bar with the current file
279 strcpy(name
, " Reading ");
281 while (strlen(name
) < 80)
283 DrawStatusText(name
);
288 MultiBootLoadModule(FilePointer
, szFileName
);
292 DrawProgressBar((nNumFilesLoaded
* 100) / nNumDriverFiles
);
294 else if (stricmp(name
, "MessageBox") == 0)
296 DrawStatusText(" Press ENTER to continue");
299 else if (stricmp(name
, "MessageLine") == 0)
301 else if (stricmp(name
, "ReOpenBootDrive") == 0)
303 if (!OpenDiskDrive(BootDrive
, BootPartition
))
305 MessageBox("Failed to open boot drive.");
312 * Clear the screen and redraw the backdrop and status bar
315 DrawStatusText(" Press any key to boot");
320 strcpy(name
, "Kernel and Drivers loaded.\nPress any key to boot ");
321 strcat(name
, OperatingSystemName
);
325 RestoreScreen(ScreenBuffer
);
328 * Now boot the kernel