4 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <multiboot.h>
40 LoadKernel(PCHAR szFileName
, int nPos
)
46 szShortName
= strrchr(szFileName
, '\\');
47 if (szShortName
== NULL
)
48 szShortName
= szFileName
;
50 szShortName
= szShortName
+ 1;
52 FilePointer
= OpenFile(szFileName
);
53 if (FilePointer
== NULL
)
55 strcpy(szBuffer
, szShortName
);
56 strcat(szBuffer
, " not found.");
57 UiMessageBox(szBuffer
);
62 * Update the status bar with the current file
64 strcpy(szBuffer
, "Reading ");
65 strcat(szBuffer
, szShortName
);
66 UiDrawStatusText(szBuffer
);
71 MultiBootLoadKernel(FilePointer
);
73 UiDrawProgressBarCenter(nPos
, 100);
80 LoadDriver(PCHAR szFileName
, int nPos
)
86 FilePointer
= OpenFile(szFileName
);
87 if (FilePointer
== NULL
)
89 strcpy(value
, szFileName
);
90 strcat(value
, " not found.");
96 * Update the status bar with the current file
98 strcpy(value
, "Reading ");
99 p
= strrchr(szFileName
, '\\');
101 strcat(value
, szFileName
);
103 strcat(value
, p
+ 1);
104 UiDrawStatusText(value
);
109 MultiBootLoadModule(FilePointer
, szFileName
, NULL
);
111 UiDrawProgressBarCenter(nPos
, 100);
119 LoadNlsFile(PCHAR szFileName
, PCHAR szModuleName
)
125 FilePointer
= OpenFile(szFileName
);
126 if (FilePointer
== NULL
)
128 strcpy(value
, szFileName
);
129 strcat(value
, " not found.");
135 * Update the status bar with the current file
137 strcpy(value
, "Reading ");
138 p
= strrchr(szFileName
, '\\');
140 strcat(value
, szFileName
);
142 strcat(value
, p
+ 1);
143 UiDrawStatusText(value
);
148 MultiBootLoadModule(FilePointer
, szModuleName
, NULL
);
156 LoadBootDrivers(PCHAR szSystemRoot
, int nPos
)
159 HKEY hGroupKey
, hServiceKey
, hDriverKey
;
160 char ValueBuffer
[256];
161 char ServiceName
[256];
169 UCHAR DriverGroup
[256];
170 ULONG DriverGroupSize
;
172 UCHAR ImagePath
[256];
174 /* get 'service group order' key */
175 rc
= RegOpenKey(NULL
,
176 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
178 // printf("RegOpenKey(): rc %d\n", (int)rc);
179 if (rc
!= ERROR_SUCCESS
)
182 /* enumerate drivers */
183 rc
= RegOpenKey(NULL
,
184 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
186 // printf("RegOpenKey(): rc %d\n", (int)rc);
187 if (rc
!= ERROR_SUCCESS
)
190 // printf("hKey: %x\n", (int)hKey);
193 rc
= RegQueryValue(hGroupKey
, "List", NULL
, (PUCHAR
)ValueBuffer
, &BufferSize
);
194 // printf("RegQueryValue(): rc %d\n", (int)rc);
195 if (rc
!= ERROR_SUCCESS
)
199 // printf("BufferSize: %d \n", (int)BufferSize);
201 // printf("ValueBuffer: '%s' \n", ValueBuffer);
203 GroupName
= ValueBuffer
;
206 // printf("Driver group: '%s'\n", GroupName);
208 /* enumerate all drivers */
213 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
214 // printf("RegEnumKey(): rc %d\n", (int)rc);
215 if (rc
== ERROR_NO_MORE_ITEMS
)
217 if (rc
!= ERROR_SUCCESS
)
219 // printf("Service %d: '%s'\n", (int)Index, ServiceName);
221 /* open driver Key */
222 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
224 ValueSize
= sizeof(ULONG
);
225 rc
= RegQueryValue(hDriverKey
, "Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
226 // printf(" Start: %x \n", (int)StartValue);
228 DriverGroupSize
= 256;
229 rc
= RegQueryValue(hDriverKey
, "Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
230 // printf(" Group: %s \n", DriverGroup);
232 if ((StartValue
== 0) && (stricmp(DriverGroup
, GroupName
) == 0))
235 rc
= RegQueryValue(hDriverKey
,
240 if (rc
!= ERROR_SUCCESS
)
242 // printf(" ImagePath: not found\n");
243 strcpy(ImagePath
, szSystemRoot
);
244 strcat(ImagePath
, "system32\\drivers\\");
245 strcat(ImagePath
, ServiceName
);
246 strcat(ImagePath
, ".sys");
250 // printf(" ImagePath: '%s'\n", ImagePath);
252 // printf(" Loading driver: '%s'\n", ImagePath);
257 LoadDriver(ImagePath
, nPos
);
262 GroupName
= GroupName
+ strlen(GroupName
) + 1;
269 LoadNlsFiles(PCHAR szSystemRoot
)
271 LONG rc
= ERROR_SUCCESS
;
274 char szNameBuffer
[80];
275 char szFileName
[256];
278 /* open the codepage key */
279 rc
= RegOpenKey(NULL
,
280 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
282 if (rc
!= ERROR_SUCCESS
)
286 /* get ANSI codepage */
288 rc
= RegQueryValue(hKey
, "ACP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
289 if (rc
!= ERROR_SUCCESS
)
293 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
294 if (rc
!= ERROR_SUCCESS
)
298 /* load ANSI codepage table */
299 strcpy(szFileName
, szSystemRoot
);
300 strcat(szFileName
, "system32\\");
301 strcat(szFileName
, szNameBuffer
);
302 if (!LoadNlsFile(szFileName
, "ANSI.NLS"))
306 /* get OEM codepage */
308 rc
= RegQueryValue(hKey
, "OEMCP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
309 if (rc
!= ERROR_SUCCESS
)
313 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
314 if (rc
!= ERROR_SUCCESS
)
317 /* load OEM codepage table */
318 strcpy(szFileName
, szSystemRoot
);
319 strcat(szFileName
, "system32\\");
320 strcat(szFileName
, szNameBuffer
);
321 if (!LoadNlsFile(szFileName
, "OEM.NLS"))
325 /* open the language key */
326 rc
= RegOpenKey(NULL
,
327 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
329 if (rc
!= ERROR_SUCCESS
)
333 /* get the Unicode case table */
335 rc
= RegQueryValue(hKey
, "Default", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
336 if (rc
!= ERROR_SUCCESS
)
340 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
341 if (rc
!= ERROR_SUCCESS
)
344 /* load Unicode case table */
345 strcpy(szFileName
, szSystemRoot
);
346 strcat(szFileName
, "system32\\");
347 strcat(szFileName
, szNameBuffer
);
348 if (!LoadNlsFile(szFileName
, "UNICASE.NLS"))
357 LoadAndBootReactOS(PUCHAR OperatingSystemName
)
362 char szFileName
[1024];
363 char szBootPath
[256];
365 // int nNumDriverFiles=0;
366 // int nNumFilesLoaded=0;
374 // Open the operating system section
375 // specified in the .ini file
377 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
379 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
380 UiMessageBox(MsgBuffer
);
385 * Setup multiboot information structure
387 mb_info
.flags
= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
388 mb_info
.mem_lower
= GetConventionalMemorySize();
389 mb_info
.mem_upper
= GetExtendedMemorySize();
390 mb_info
.boot_device
= 0xffffffff;
391 mb_info
.cmdline
= (unsigned long)multiboot_kernel_cmdline
;
392 mb_info
.mods_count
= 0;
393 mb_info
.mods_addr
= (unsigned long)multiboot_modules
;
394 mb_info
.mmap_length
= GetBiosMemoryMap(&multiboot_memory_map
);
395 if (mb_info
.mmap_length
)
397 mb_info
.mmap_addr
= (unsigned long)&multiboot_memory_map
;
398 mb_info
.flags
|= MB_INFO_FLAG_MEMORY_MAP
;
399 //printf("memory map length: %d\n", mb_info.mmap_length);
400 //printf("dumping memory map:\n");
401 //for (i=0; i<(mb_info.mmap_length / 4); i++)
403 // printf("0x%x\n", ((unsigned long *)&multiboot_memory_map)[i]);
407 //printf("low_mem = %d\n", mb_info.mem_lower);
408 //printf("high_mem = %d\n", mb_info.mem_upper);
412 * Make sure the system path is set in the .ini file
414 if (!IniReadSettingByName(SectionId
, "SystemPath", value
, 1024))
416 UiMessageBox("System path not specified for selected operating system.");
423 if (!DissectArcPath(value
, szBootPath
, &BootDrive
, &BootPartition
))
425 sprintf(MsgBuffer
,"Invalid system path: '%s'", value
);
426 UiMessageBox(MsgBuffer
);
430 /* set boot drive and partition */
431 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
432 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
434 /* copy ARC path into kernel command line */
435 strcpy(multiboot_kernel_cmdline
, value
);
438 * Read the optional kernel parameters (if any)
440 if (IniReadSettingByName(SectionId
, "Options", value
, 1024))
442 strcat(multiboot_kernel_cmdline
, " ");
443 strcat(multiboot_kernel_cmdline
, value
);
446 /* append a backslash */
447 if ((strlen(szBootPath
)==0) ||
448 szBootPath
[strlen(szBootPath
)] != '\\')
449 strcat(szBootPath
, "\\");
451 DebugPrint(DPRINT_REACTOS
,"SystemRoot: '%s'", szBootPath
);
455 UiDrawStatusText("Loading...");
456 UiDrawProgressBarCenter(0, 100);
459 * Try to open boot drive
461 if (!OpenDiskDrive(BootDrive
, BootPartition
))
463 UiMessageBox("Failed to open boot drive.");
468 * Find the kernel image name
469 * and try to load the kernel off the disk
471 if(IniReadSettingByName(SectionId
, "Kernel", value
, 1024))
476 if (value
[0] == '\\')
478 strcpy(szFileName
, value
);
482 strcpy(szFileName
, szBootPath
);
483 strcat(szFileName
, "SYSTEM32\\");
484 strcat(szFileName
, value
);
489 strcpy(value
, "NTOSKRNL.EXE");
490 strcpy(szFileName
, szBootPath
);
491 strcat(szFileName
, "SYSTEM32\\");
492 strcat(szFileName
, value
);
495 if (!LoadKernel(szFileName
, 5))
499 * Find the HAL image name
500 * and try to load the kernel off the disk
502 if(IniReadSettingByName(SectionId
, "Hal", value
, 1024))
507 if (value
[0] == '\\')
509 strcpy(szFileName
, value
);
513 strcpy(szFileName
, szBootPath
);
514 strcat(szFileName
, "SYSTEM32\\");
515 strcat(szFileName
, value
);
520 strcpy(value
, "HAL.DLL");
521 strcpy(szFileName
, szBootPath
);
522 strcat(szFileName
, "SYSTEM32\\");
523 strcat(szFileName
, value
);
526 if (!LoadDriver(szFileName
, 10))
530 * Find the System hive image name
531 * and try to load it off the disk
533 if(IniReadSettingByName(SectionId
, "SystemHive", value
, 1024))
538 if (value
[0] == '\\')
540 strcpy(szFileName
, value
);
544 strcpy(szFileName
, szBootPath
);
545 strcat(szFileName
, "SYSTEM32\\CONFIG\\");
546 strcat(szFileName
, value
);
551 strcpy(value
, "SYSTEM.HIV");
552 strcpy(szFileName
, szBootPath
);
553 strcat(szFileName
, "SYSTEM32\\CONFIG\\");
554 strcat(szFileName
, value
);
557 DebugPrint(DPRINT_REACTOS
, "SystemHive: '%s'", szFileName
);
559 FilePointer
= OpenFile(szFileName
);
560 if (FilePointer
== NULL
)
562 strcat(value
, " not found.");
568 * Update the status bar with the current file
570 strcpy(name
, "Reading ");
572 while (strlen(name
) < 80)
574 UiDrawStatusText(name
);
577 * Load the system hive
579 Base
= MultiBootLoadModule(FilePointer
, szFileName
, &Size
);
580 RegInitializeRegistry();
581 RegImportHive(Base
, Size
);
583 UiDrawProgressBarCenter(15, 100);
585 DebugPrint(DPRINT_REACTOS
, "SystemHive loaded at 0x%x size %u", (unsigned)Base
, (unsigned)Size
);
588 * Retrieve hardware information and create the hardware hive
592 Base
= MultiBootCreateModule(HARDWARE
.HIV
);
593 RegExportHive("\\Registry\\Machine\\HARDWARE", Base
, &Size
);
594 MultiBootCloseModule(Base
, Size
);
596 UiDrawProgressBarCenter(20, 100);
602 if (!LoadNlsFiles(szBootPath
))
604 MessageBox("Failed to load NLS files\n");
609 UiDrawProgressBarCenter(25, 100);
614 LoadBootDrivers(szBootPath
, 25);
618 * Clear the screen and redraw the backdrop and status bar
621 UiDrawStatusText("Press any key to boot");
626 strcpy(name
, "Kernel and Drivers loaded.\nPress any key to boot ");
627 strcat(name
, OperatingSystemName
);
632 * Now boot the kernel