4 * Copyright (C) 1999, 2000, 2001 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.
27 #include <multiboot.h>
39 LoadKernel(PCHAR szFileName
, int nPos
)
45 szShortName
= strrchr(szFileName
, '\\');
46 if (szShortName
== NULL
)
47 szShortName
= szFileName
;
49 szShortName
= szShortName
+ 1;
51 FilePointer
= OpenFile(szFileName
);
52 if (FilePointer
== NULL
)
54 strcat(szBuffer
, szShortName
);
55 strcat(szBuffer
, " not found.");
61 * Update the status bar with the current file
63 strcpy(szBuffer
, " Reading ");
64 strcat(szBuffer
, szShortName
);
65 DrawStatusText(szBuffer
);
70 MultiBootLoadKernel(FilePointer
);
72 DrawProgressBar(nPos
);
79 LoadDriver(PCHAR szFileName
, int nPos
)
85 FilePointer
= OpenFile(szFileName
);
86 if (FilePointer
== NULL
)
88 strcat(value
, szFileName
);
89 strcat(value
, " not found.");
95 * Update the status bar with the current file
97 strcpy(value
, " Reading ");
98 p
= strrchr(szFileName
, '\\');
100 strcat(value
, szFileName
);
102 strcat(value
, p
+ 1);
103 while (strlen(value
) < 80)
105 DrawStatusText(value
);
110 MultiBootLoadModule(FilePointer
, szFileName
, NULL
);
112 DrawProgressBar(nPos
);
119 LoadBootDrivers(PCHAR szSystemRoot
, int nPos
)
122 HKEY hGroupKey
, hServiceKey
, hDriverKey
;
123 char ValueBuffer
[256];
124 char ServiceName
[256];
135 UCHAR DriverGroup
[256];
136 ULONG DriverGroupSize
;
138 UCHAR ImagePath
[256];
140 /* get 'service group order' key */
141 rc
= RegOpenKey(NULL
,
142 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
144 // printf("RegOpenKey(): rc %d\n", (int)rc);
145 if (rc
!= ERROR_SUCCESS
)
148 /* enumerate drivers */
149 rc
= RegOpenKey(NULL
,
150 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
152 // printf("RegOpenKey(): rc %d\n", (int)rc);
153 if (rc
!= ERROR_SUCCESS
)
156 // printf("hKey: %x\n", (int)hKey);
159 rc
= RegQueryValue(hGroupKey
, "List", NULL
, (PUCHAR
)ValueBuffer
, &BufferSize
);
160 // printf("RegQueryValue(): rc %d\n", (int)rc);
161 if (rc
!= ERROR_SUCCESS
)
165 // printf("BufferSize: %d \n", (int)BufferSize);
167 // printf("ValueBuffer: '%s' \n", ValueBuffer);
177 memcpy(GroupName
, s
, len
);
183 strcpy(GroupName
, s
);
186 // printf("Driver group: '%s'\n", GroupName);
188 /* enumerate all drivers */
193 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
194 // printf("RegEnumKey(): rc %d\n", (int)rc);
195 if (rc
== ERROR_NO_MORE_ITEMS
)
197 if (rc
!= ERROR_SUCCESS
)
199 // printf("Service %d: '%s'\n", (int)Index, ServiceName);
201 /* open driver Key */
202 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
204 ValueSize
= sizeof(ULONG
);
205 rc
= RegQueryValue(hDriverKey
, "Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
206 // printf(" Start: %x \n", (int)StartValue);
208 DriverGroupSize
= 256;
209 rc
= RegQueryValue(hDriverKey
, "Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
210 // printf(" Group: %s \n", DriverGroup);
212 if ((StartValue
== 0) && (stricmp(DriverGroup
, GroupName
) == 0))
215 rc
= RegQueryValue(hDriverKey
,
220 if (rc
!= ERROR_SUCCESS
)
222 // printf(" ImagePath: not found\n");
223 strcpy(ImagePath
, szSystemRoot
);
224 strcat(ImagePath
, "system32\\drivers\\");
225 strcat(ImagePath
, ServiceName
);
226 strcat(ImagePath
, ".sys");
230 // printf(" ImagePath: '%s'\n", ImagePath);
232 // printf(" Loading driver: '%s'\n", ImagePath);
234 LoadDriver(ImagePath
, nPos
);
242 while(done
== FALSE
);
246 void LoadAndBootReactOS(PUCHAR OperatingSystemName
)
251 char szFileName
[1024];
252 char szBootPath
[256];
254 // int nNumDriverFiles=0;
255 // int nNumFilesLoaded=0;
263 // Open the operating system section
264 // specified in the .ini file
266 if (!OpenSection(OperatingSystemName
, &SectionId
))
268 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
269 MessageBox(MsgBuffer
);
274 * Setup multiboot information structure
276 mb_info
.flags
= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
277 mb_info
.mem_lower
= GetConventionalMemorySize();
278 mb_info
.mem_upper
= GetExtendedMemorySize();
279 mb_info
.boot_device
= 0xffffffff;
280 mb_info
.cmdline
= (unsigned long)multiboot_kernel_cmdline
;
281 mb_info
.mods_count
= 0;
282 mb_info
.mods_addr
= (unsigned long)multiboot_modules
;
283 mb_info
.mmap_length
= GetBiosMemoryMap(&multiboot_memory_map
);
284 if (mb_info
.mmap_length
)
286 mb_info
.mmap_addr
= (unsigned long)&multiboot_memory_map
;
287 mb_info
.flags
|= MB_INFO_FLAG_MEMORY_MAP
;
288 //printf("memory map length: %d\n", mb_info.mmap_length);
289 //printf("dumping memory map:\n");
290 //for (i=0; i<(mb_info.mmap_length / 4); i++)
292 // printf("0x%x\n", ((unsigned long *)&multiboot_memory_map)[i]);
296 //printf("low_mem = %d\n", mb_info.mem_lower);
297 //printf("high_mem = %d\n", mb_info.mem_upper);
301 * Make sure the system path is set in the .ini file
303 if (!ReadSectionSettingByName(SectionId
, "SystemPath", value
, 1024))
305 MessageBox("System path not specified for selected operating system.");
312 if (!DissectArcPath(value
, szBootPath
, &BootDrive
, &BootPartition
))
314 sprintf(MsgBuffer
,"Invalid system path: '%s'", value
);
315 MessageBox(MsgBuffer
);
319 /* set boot drive and partition */
320 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
321 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
323 /* copy ARC path into kernel command line */
324 strcpy(multiboot_kernel_cmdline
, value
);
327 * Read the optional kernel parameters (if any)
329 if (ReadSectionSettingByName(SectionId
, "Options", value
, 1024))
331 strcat(multiboot_kernel_cmdline
, " ");
332 strcat(multiboot_kernel_cmdline
, value
);
335 /* append a backslash */
336 if ((strlen(szBootPath
)==0) ||
337 szBootPath
[strlen(szBootPath
)] != '\\')
338 strcat(szBootPath
, "\\");
341 sprintf(MsgBuffer
,"SystemRoot: '%s'", szBootPath
);
342 MessageBox(MsgBuffer
);
347 DrawStatusText(" Loading...");
351 * Try to open boot drive
353 if (!OpenDiskDrive(BootDrive
, BootPartition
))
355 MessageBox("Failed to open boot drive.");
360 * Find the kernel image name
361 * and try to load the kernel off the disk
363 if(ReadSectionSettingByName(SectionId
, "Kernel", value
, 1024))
368 if (value
[0] == '\\')
370 strcpy(szFileName
, value
);
374 strcpy(szFileName
, szBootPath
);
375 strcat(szFileName
, "SYSTEM32\\");
376 strcat(szFileName
, value
);
381 strcpy(value
, "NTOSKRNL.EXE");
382 strcpy(szFileName
, szBootPath
);
383 strcat(szFileName
, "SYSTEM32\\");
384 strcat(szFileName
, value
);
387 if (!LoadKernel(szFileName
, 5))
391 * Find the HAL image name
392 * and try to load the kernel off the disk
394 if(ReadSectionSettingByName(SectionId
, "Hal", value
, 1024))
399 if (value
[0] == '\\')
401 strcpy(szFileName
, value
);
405 strcpy(szFileName
, szBootPath
);
406 strcat(szFileName
, "SYSTEM32\\");
407 strcat(szFileName
, value
);
412 strcpy(value
, "HAL.DLL");
413 strcpy(szFileName
, szBootPath
);
414 strcat(szFileName
, "SYSTEM32\\");
415 strcat(szFileName
, value
);
418 if (!LoadDriver(szFileName
, 10))
422 * Find the System hive image name
423 * and try to load it off the disk
425 if(ReadSectionSettingByName(SectionId
, "SystemHive", value
, 1024))
430 if (value
[0] == '\\')
432 strcpy(szFileName
, value
);
436 strcpy(szFileName
, szBootPath
);
437 strcat(szFileName
, "SYSTEM32\\CONFIG\\");
438 strcat(szFileName
, value
);
443 strcpy(value
, "SYSTEM.HIV");
444 strcpy(szFileName
, szBootPath
);
445 strcat(szFileName
, "SYSTEM32\\CONFIG\\");
446 strcat(szFileName
, value
);
450 sprintf(MsgBuffer
,"SystemHive: '%s'", szFileName
);
451 MessageBox(MsgBuffer
);
454 FilePointer
= OpenFile(szFileName
);
455 if (FilePointer
== NULL
)
457 strcat(value
, " not found.");
463 * Update the status bar with the current file
465 strcpy(name
, " Reading ");
467 while (strlen(name
) < 80)
469 DrawStatusText(name
);
472 * Load the system hive
474 Base
= MultiBootLoadModule(FilePointer
, szFileName
, &Size
);
475 RegInitializeRegistry();
476 RegImportHive(Base
, Size
);
481 sprintf(MsgBuffer
,"SystemHive loaded at 0x%x size %u", (unsigned)Base
, (unsigned)Size
);
482 MessageBox(MsgBuffer
);
486 * retrieve hardware information and create the hardware hive
489 // Base = MultiBootCreateModule(HARDWARE.HIV);
490 // RegExportHardwareHive(Base, &Size);
491 // MultiBootCloseModule(Base, Size);
498 // LoadNlsFiles(szBootPath);
505 LoadBootDrivers(szBootPath
, 30);
509 * Clear the screen and redraw the backdrop and status bar
512 DrawStatusText(" Press any key to boot");
517 strcpy(name
, "Kernel and Drivers loaded.\nPress any key to boot ");
518 strcat(name
, OperatingSystemName
);
522 RestoreScreen(ScreenBuffer
);
525 * Now boot the kernel