Set the ACPI flag in loader block *after* performing the ACPI detection.
[reactos.git] / reactos / boot / freeldr / freeldr / reactos / reactos.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Freeloader
4 * FILE: boot/freeldr/freeldr/reactos/rosboot.c
5 * PURPOSE: ReactOS Loader
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 #include <freeldr.h>
10 #include <internal/i386/ke.h>
11 #include <reactos/rossym.h>
12
13 #include "registry.h"
14
15 #define NDEBUG
16 #include <debug.h>
17
18 #define IsRecognizedPartition(P) \
19 ((P) == PARTITION_FAT_12 || \
20 (P) == PARTITION_FAT_16 || \
21 (P) == PARTITION_HUGE || \
22 (P) == PARTITION_IFS || \
23 (P) == PARTITION_EXT2 || \
24 (P) == PARTITION_FAT32 || \
25 (P) == PARTITION_FAT32_XINT13 || \
26 (P) == PARTITION_XINT13)
27
28 BOOL
29 STDCALL
30 FrLdrLoadKernel(PCHAR szFileName,
31 INT nPos)
32 {
33 PFILE FilePointer;
34 PCHAR szShortName;
35 CHAR szBuffer[256];
36
37 /* Extract Kernel filename without path */
38 szShortName = strrchr(szFileName, '\\');
39 if (szShortName == NULL) {
40
41 /* No path, leave it alone */
42 szShortName = szFileName;
43
44 } else {
45
46 /* Skip the path */
47 szShortName = szShortName + 1;
48 }
49
50 /* Open the Kernel */
51 FilePointer = FsOpenFile(szFileName);
52
53 /* Make sure it worked */
54 if (FilePointer == NULL) {
55
56 /* Return failure on the short name */
57 strcpy(szBuffer, szShortName);
58 strcat(szBuffer, " not found.");
59 UiMessageBox(szBuffer);
60 return(FALSE);
61 }
62
63 /* Update the status bar with the current file */
64 strcpy(szBuffer, "Reading ");
65 strcat(szBuffer, szShortName);
66 UiDrawStatusText(szBuffer);
67
68 /* Do the actual loading */
69 FrLdrMapKernel(FilePointer);
70
71 /* Update Processbar and return success */
72 UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
73 return(TRUE);
74 }
75
76 static VOID
77 FreeldrFreeMem(PVOID Area)
78 {
79 MmFreeMemory(Area);
80 }
81
82 static PVOID
83 FreeldrAllocMem(ULONG_PTR Size)
84 {
85 return MmAllocateMemory((ULONG) Size);
86 }
87
88 static BOOLEAN
89 FreeldrReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
90 {
91 ULONG BytesRead;
92
93 return FsReadFile((PFILE) FileContext, (ULONG) Size, &BytesRead, Buffer)
94 && Size == BytesRead;
95 }
96
97 static BOOLEAN
98 FreeldrSeekFile(PVOID FileContext, ULONG_PTR Position)
99 {
100 FsSetFilePointer((PFILE) FileContext, (ULONG) Position);
101 return TRUE;
102 }
103
104 static BOOL
105 LoadKernelSymbols(PCHAR szKernelName, int nPos)
106 {
107 static ROSSYM_CALLBACKS FreeldrCallbacks =
108 {
109 FreeldrAllocMem,
110 FreeldrFreeMem,
111 FreeldrReadFile,
112 FreeldrSeekFile
113 };
114 PFILE FilePointer;
115 PROSSYM_INFO RosSymInfo;
116 ULONG Size;
117 ULONG_PTR Base;
118
119 RosSymInit(&FreeldrCallbacks);
120
121 FilePointer = FsOpenFile(szKernelName);
122 if (FilePointer == NULL)
123 {
124 return FALSE;
125 }
126 if (! RosSymCreateFromFile(FilePointer, &RosSymInfo))
127 {
128 return FALSE;
129 }
130 Base = FrLdrCreateModule("NTOSKRNL.SYM");
131 Size = RosSymGetRawDataLength(RosSymInfo);
132 RosSymGetRawData(RosSymInfo, (PVOID)Base);
133 FrLdrCloseModule(Base, Size);
134 RosSymDelete(RosSymInfo);
135 return TRUE;
136 }
137
138 BOOL
139 FrLdrLoadNlsFile(PCHAR szFileName,
140 PCHAR szModuleName)
141 {
142 PFILE FilePointer;
143 CHAR value[256];
144 LPSTR p;
145
146 /* Open the Driver */
147 FilePointer = FsOpenFile(szFileName);
148
149 /* Make sure we did */
150 if (FilePointer == NULL) {
151
152 /* Fail if file wasn't opened */
153 strcpy(value, szFileName);
154 strcat(value, " not found.");
155 UiMessageBox(value);
156 return(FALSE);
157 }
158
159 /* Update the status bar with the current file */
160 strcpy(value, "Reading ");
161 p = strrchr(szFileName, '\\');
162 if (p == NULL) {
163
164 strcat(value, szFileName);
165
166 } else {
167
168 strcat(value, p + 1);
169 }
170 UiDrawStatusText(value);
171
172 /* Load the driver */
173 FrLdrLoadModule(FilePointer, szModuleName, NULL);
174 return(TRUE);
175 }
176
177 BOOL
178 FrLdrLoadNlsFiles(PCHAR szSystemRoot,
179 PCHAR szErrorOut)
180 {
181 LONG rc = ERROR_SUCCESS;
182 FRLDRHKEY hKey;
183 CHAR szIdBuffer[80];
184 CHAR szNameBuffer[80];
185 CHAR szFileName[256];
186 ULONG BufferSize;
187
188 /* open the codepage key */
189 rc = RegOpenKey(NULL,
190 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
191 &hKey);
192 if (rc != ERROR_SUCCESS) {
193
194 strcpy(szErrorOut, "Couldn't open CodePage registry key");
195 return(FALSE);
196 }
197
198 /* get ANSI codepage */
199 BufferSize = 80;
200 rc = RegQueryValue(hKey, "ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
201 if (rc != ERROR_SUCCESS) {
202
203 strcpy(szErrorOut, "Couldn't get ACP NLS setting");
204 return(FALSE);
205 }
206
207 BufferSize = 80;
208 rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
209 if (rc != ERROR_SUCCESS) {
210
211 strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
212 return(FALSE);
213 }
214
215 /* load ANSI codepage table */
216 strcpy(szFileName, szSystemRoot);
217 strcat(szFileName, "system32\\");
218 strcat(szFileName, szNameBuffer);
219 DbgPrint((DPRINT_REACTOS, "ANSI file: %s\n", szFileName));
220 if (!FrLdrLoadNlsFile(szFileName, "ansi.nls")) {
221
222 strcpy(szErrorOut, "Couldn't load ansi.nls");
223 return(FALSE);
224 }
225
226 /* get OEM codepage */
227 BufferSize = 80;
228 rc = RegQueryValue(hKey, "OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
229 if (rc != ERROR_SUCCESS) {
230
231 strcpy(szErrorOut, "Couldn't get OEMCP NLS setting");
232 return(FALSE);
233 }
234
235 BufferSize = 80;
236 rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
237 if (rc != ERROR_SUCCESS) {
238
239 strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
240 return(FALSE);
241 }
242
243 /* load OEM codepage table */
244 strcpy(szFileName, szSystemRoot);
245 strcat(szFileName, "system32\\");
246 strcat(szFileName, szNameBuffer);
247 DbgPrint((DPRINT_REACTOS, "Oem file: %s\n", szFileName));
248 if (!FrLdrLoadNlsFile(szFileName, "oem.nls")) {
249
250 strcpy(szErrorOut, "Couldn't load oem.nls");
251 return(FALSE);
252 }
253
254 /* open the language key */
255 rc = RegOpenKey(NULL,
256 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
257 &hKey);
258 if (rc != ERROR_SUCCESS) {
259
260 strcpy(szErrorOut, "Couldn't open Language registry key");
261 return(FALSE);
262 }
263
264 /* get the Unicode case table */
265 BufferSize = 80;
266 rc = RegQueryValue(hKey, "Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
267 if (rc != ERROR_SUCCESS) {
268
269 strcpy(szErrorOut, "Couldn't get Language Default setting");
270 return(FALSE);
271 }
272
273 BufferSize = 80;
274 rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
275 if (rc != ERROR_SUCCESS) {
276
277 strcpy(szErrorOut, "Language Default setting exists, but isn't readable");
278 return(FALSE);
279 }
280
281 /* load Unicode case table */
282 strcpy(szFileName, szSystemRoot);
283 strcat(szFileName, "system32\\");
284 strcat(szFileName, szNameBuffer);
285 DbgPrint((DPRINT_REACTOS, "Casemap file: %s\n", szFileName));
286 if (!FrLdrLoadNlsFile(szFileName, "casemap.nls")) {
287
288 strcpy(szErrorOut, "casemap.nls");
289 return(FALSE);
290 }
291
292 return(TRUE);
293 }
294
295 BOOL
296 FrLdrLoadDriver(PCHAR szFileName,
297 INT nPos)
298 {
299 PFILE FilePointer;
300 CHAR value[256];
301 LPSTR p;
302
303 /* Open the Driver */
304 FilePointer = FsOpenFile(szFileName);
305
306 /* Make sure we did */
307 if (FilePointer == NULL) {
308
309 /* Fail if file wasn't opened */
310 strcpy(value, szFileName);
311 strcat(value, " not found.");
312 UiMessageBox(value);
313 return(FALSE);
314 }
315
316 /* Update the status bar with the current file */
317 strcpy(value, "Reading ");
318 p = strrchr(szFileName, '\\');
319 if (p == NULL) {
320
321 strcat(value, szFileName);
322
323 } else {
324
325 strcat(value, p + 1);
326
327 }
328 UiDrawStatusText(value);
329
330 /* Load the driver */
331 FrLdrLoadModule(FilePointer, szFileName, NULL);
332
333 /* Update status and return */
334 UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
335 return(TRUE);
336 }
337
338 VOID
339 FrLdrLoadBootDrivers(PCHAR szSystemRoot,
340 INT nPos)
341 {
342 LONG rc = 0;
343 FRLDRHKEY hGroupKey, hOrderKey, hServiceKey, hDriverKey;
344 CHAR GroupNameBuffer[512];
345 CHAR ServiceName[256];
346 ULONG OrderList[128];
347 ULONG BufferSize;
348 ULONG Index;
349 ULONG TagIndex;
350 LPSTR GroupName;
351
352 ULONG ValueSize;
353 ULONG ValueType;
354 ULONG StartValue;
355 ULONG TagValue;
356 UCHAR DriverGroup[256];
357 ULONG DriverGroupSize;
358
359 UCHAR ImagePath[256];
360 UCHAR TempImagePath[256];
361
362 /* get 'service group order' key */
363 rc = RegOpenKey(NULL,
364 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
365 &hGroupKey);
366 if (rc != ERROR_SUCCESS) {
367
368 DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
369 return;
370 }
371
372 /* get 'group order list' key */
373 rc = RegOpenKey(NULL,
374 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
375 &hOrderKey);
376 if (rc != ERROR_SUCCESS) {
377
378 DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
379 return;
380 }
381
382 /* enumerate drivers */
383 rc = RegOpenKey(NULL,
384 "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
385 &hServiceKey);
386 if (rc != ERROR_SUCCESS) {
387
388 DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
389 return;
390 }
391
392 /* Get the Name Group */
393 BufferSize = sizeof(GroupNameBuffer);
394 rc = RegQueryValue(hGroupKey, "List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
395 DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
396 if (rc != ERROR_SUCCESS) return;
397 DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
398 DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%s' \n", GroupNameBuffer));
399
400 /* Loop through each group */
401 GroupName = GroupNameBuffer;
402 while (*GroupName) {
403 DbgPrint((DPRINT_REACTOS, "Driver group: '%s'\n", GroupName));
404
405 /* Query the Order */
406 BufferSize = sizeof(OrderList);
407 rc = RegQueryValue(hOrderKey, GroupName, NULL, (PUCHAR)OrderList, &BufferSize);
408 if (rc != ERROR_SUCCESS) OrderList[0] = 0;
409
410 /* enumerate all drivers */
411 for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
412
413 Index = 0;
414
415 while (TRUE) {
416
417 /* Get the Driver's Name */
418 ValueSize = sizeof(ServiceName);
419 rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
420 DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
421
422 /* Makre sure it's valid, and check if we're done */
423 if (rc == ERROR_NO_MORE_ITEMS) break;
424 if (rc != ERROR_SUCCESS) return;
425 DbgPrint((DPRINT_REACTOS, "Service %d: '%s'\n", (int)Index, ServiceName));
426
427 /* open driver Key */
428 rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
429
430 /* Read the Start Value */
431 ValueSize = sizeof(ULONG);
432 rc = RegQueryValue(hDriverKey, "Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
433 DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
434
435 /* Read the Tag */
436 ValueSize = sizeof(ULONG);
437 rc = RegQueryValue(hDriverKey, "Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
438 if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
439 DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
440
441 /* Read the driver's group */
442 DriverGroupSize = 256;
443 rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
444 DbgPrint((DPRINT_REACTOS, " Group: '%s' \n", DriverGroup));
445
446 /* Make sure it should be started */
447 if ((StartValue == 0) &&
448 (TagValue == OrderList[TagIndex]) &&
449 (stricmp(DriverGroup, GroupName) == 0)) {
450
451 /* Get the Driver's Location */
452 ValueSize = 256;
453 rc = RegQueryValue(hDriverKey, "ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
454
455 /* Write the whole path if it suceeded, else prepare to fail */
456 if (rc != ERROR_SUCCESS) {
457 DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
458 strcpy(ImagePath, szSystemRoot);
459 strcat(ImagePath, "system32\\drivers\\");
460 strcat(ImagePath, ServiceName);
461 strcat(ImagePath, ".sys");
462 } else if (TempImagePath[0] != '\\') {
463 strcpy(ImagePath, szSystemRoot);
464 strcat(ImagePath, TempImagePath);
465 } else {
466 strcpy(ImagePath, TempImagePath);
467 DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
468 }
469
470 DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
471
472 /* Update the position if needed */
473 if (nPos < 100) nPos += 5;
474
475 FrLdrLoadDriver(ImagePath, nPos);
476
477 } else {
478
479 DbgPrint((DPRINT_REACTOS, " Skipping driver '%s' with Start %d, Tag %d and Group '%s' (Current Tag %d, current group '%s')\n",
480 ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName));
481 }
482
483 Index++;
484 }
485 }
486
487 Index = 0;
488 while (TRUE) {
489
490 /* Get the Driver's Name */
491 ValueSize = sizeof(ServiceName);
492 rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
493
494 DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
495 if (rc == ERROR_NO_MORE_ITEMS) break;
496 if (rc != ERROR_SUCCESS) return;
497 DbgPrint((DPRINT_REACTOS, "Service %d: '%s'\n", (int)Index, ServiceName));
498
499 /* open driver Key */
500 rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
501
502 /* Read the Start Value */
503 ValueSize = sizeof(ULONG);
504 rc = RegQueryValue(hDriverKey, "Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
505 DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
506
507 /* Read the Tag */
508 ValueSize = sizeof(ULONG);
509 rc = RegQueryValue(hDriverKey, "Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
510 if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
511 DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
512
513 /* Read the driver's group */
514 DriverGroupSize = 256;
515 rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
516 DbgPrint((DPRINT_REACTOS, " Group: '%s' \n", DriverGroup));
517
518 for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
519 if (TagValue == OrderList[TagIndex]) break;
520 }
521
522 if ((StartValue == 0) &&
523 (TagIndex > OrderList[0]) &&
524 (stricmp(DriverGroup, GroupName) == 0)) {
525
526 ValueSize = 256;
527 rc = RegQueryValue(hDriverKey, "ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
528 if (rc != ERROR_SUCCESS) {
529 DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
530 strcpy(ImagePath, szSystemRoot);
531 strcat(ImagePath, "system32\\drivers\\");
532 strcat(ImagePath, ServiceName);
533 strcat(ImagePath, ".sys");
534 } else if (TempImagePath[0] != '\\') {
535 strcpy(ImagePath, szSystemRoot);
536 strcat(ImagePath, TempImagePath);
537 } else {
538 strcpy(ImagePath, TempImagePath);
539 DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
540 }
541 DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
542
543 if (nPos < 100) nPos += 5;
544
545 FrLdrLoadDriver(ImagePath, nPos);
546
547 } else {
548
549 DbgPrint((DPRINT_REACTOS, " Skipping driver '%s' with Start %d, Tag %d and Group '%s' (Current group '%s')\n",
550 ServiceName, StartValue, TagValue, DriverGroup, GroupName));
551 }
552
553 Index++;
554 }
555
556 /* Move to the next group name */
557 GroupName = GroupName + strlen(GroupName) + 1;
558 }
559 }
560
561 VOID
562 LoadAndBootReactOS(PUCHAR OperatingSystemName)
563 {
564 PFILE FilePointer;
565 CHAR name[1024];
566 CHAR value[1024];
567 CHAR szKernelName[1024];
568 CHAR szHalName[1024];
569 CHAR szFileName[1024];
570 CHAR szBootPath[256];
571 INT i;
572 CHAR MsgBuffer[256];
573 ULONG SectionId;
574
575 ULONG_PTR Base;
576 ULONG Size;
577
578 PARTITION_TABLE_ENTRY PartitionTableEntry;
579 ULONG rosPartition;
580
581 extern ULONG PageDirectoryStart;
582 extern ULONG PageDirectoryEnd;
583 extern BOOLEAN AcpiPresent;
584
585 //
586 // Open the operating system section
587 // specified in the .ini file
588 //
589 if (!IniOpenSection(OperatingSystemName, &SectionId))
590 {
591 sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
592 UiMessageBox(MsgBuffer);
593 return;
594 }
595
596 /*
597 * Setup multiboot information structure
598 */
599 LoaderBlock.Flags = MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_BOOT_DEVICE | MB_INFO_FLAG_COMMAND_LINE | MB_INFO_FLAG_MODULES;
600 LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
601 LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
602 LoaderBlock.BootDevice = 0xffffffff;
603 LoaderBlock.CommandLine = (unsigned long)multiboot_kernel_cmdline;
604 LoaderBlock.ModsCount = 0;
605 LoaderBlock.ModsAddr = (unsigned long)multiboot_modules;
606 LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&multiboot_memory_map, 32) * sizeof(memory_map_t);
607 if (LoaderBlock.MmapLength)
608 {
609 LoaderBlock.MmapAddr = (unsigned long)&multiboot_memory_map;
610 LoaderBlock.Flags |= MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_MEMORY_MAP;
611 multiboot_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
612 DbgPrint((DPRINT_REACTOS, "memory map length: %d\n", LoaderBlock.MmapLength));
613 DbgPrint((DPRINT_REACTOS, "dumping memory map:\n"));
614 for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
615 {
616 if (MEMTYPE_USABLE == multiboot_memory_map[i].type &&
617 0 == multiboot_memory_map[i].base_addr_low)
618 {
619 LoaderBlock.MemLower = (multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low) / 1024;
620 if (640 < LoaderBlock.MemLower)
621 {
622 LoaderBlock.MemLower = 640;
623 }
624 }
625 if (MEMTYPE_USABLE == multiboot_memory_map[i].type &&
626 multiboot_memory_map[i].base_addr_low <= 1024 * 1024 &&
627 1024 * 1024 <= multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low)
628 {
629 LoaderBlock.MemHigher = (multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low) / 1024 - 1024;
630 }
631 DbgPrint((DPRINT_REACTOS, "start: %x\t size: %x\t type %d\n",
632 multiboot_memory_map[i].base_addr_low,
633 multiboot_memory_map[i].length_low,
634 multiboot_memory_map[i].type));
635 }
636 }
637 DbgPrint((DPRINT_REACTOS, "low_mem = %d\n", LoaderBlock.MemLower));
638 DbgPrint((DPRINT_REACTOS, "high_mem = %d\n", LoaderBlock.MemHigher));
639
640 /*
641 * Initialize the registry
642 */
643 RegInitializeRegistry();
644
645 /*
646 * Make sure the system path is set in the .ini file
647 */
648 if (!IniReadSettingByName(SectionId, "SystemPath", value, 1024))
649 {
650 UiMessageBox("System path not specified for selected operating system.");
651 return;
652 }
653
654 /*
655 * Special case for Live CD.
656 */
657 if (!stricmp(value, "LiveCD"))
658 {
659 strcpy(szBootPath, "\\reactos");
660
661 /* Set kernel command line */
662 sprintf(multiboot_kernel_cmdline,
663 "multi(0)disk(0)cdrom(%u)\\reactos /MININT",
664 (unsigned int)BootDrive);
665 }
666 else
667 {
668 /*
669 * Verify system path
670 */
671 if (!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition))
672 {
673 sprintf(MsgBuffer,"Invalid system path: '%s'", value);
674 UiMessageBox(MsgBuffer);
675 return;
676 }
677
678 /* recalculate the boot partition for freeldr */
679 i = 0;
680 rosPartition = 0;
681 while (1)
682 {
683 if (!MachDiskGetPartitionEntry(BootDrive, ++i, &PartitionTableEntry))
684 {
685 BootPartition = 0;
686 break;
687 }
688 if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
689 {
690 if (++rosPartition == BootPartition)
691 {
692 BootPartition = i;
693 break;
694 }
695 }
696 }
697
698 if (BootPartition == 0)
699 {
700 sprintf(MsgBuffer,"Invalid system path: '%s'", value);
701 UiMessageBox(MsgBuffer);
702 return;
703 }
704
705 /* copy ARC path into kernel command line */
706 strcpy(multiboot_kernel_cmdline, value);
707 }
708
709 /* Set boot drive and partition */
710 ((LPSTR )(&LoaderBlock.BootDevice))[0] = (CHAR)BootDrive;
711 ((LPSTR )(&LoaderBlock.BootDevice))[1] = (CHAR)BootPartition;
712
713 /*
714 * Read the optional kernel parameters (if any)
715 */
716 if (IniReadSettingByName(SectionId, "Options", value, 1024))
717 {
718 strcat(multiboot_kernel_cmdline, " ");
719 strcat(multiboot_kernel_cmdline, value);
720 }
721
722 /* append a backslash */
723 if ((strlen(szBootPath)==0) ||
724 szBootPath[strlen(szBootPath)] != '\\')
725 strcat(szBootPath, "\\");
726
727 DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
728
729
730 UiDrawBackdrop();
731 UiDrawStatusText("Detecting Hardware...");
732
733 /*
734 * Detect hardware
735 */
736 MachHwDetect();
737
738 if (AcpiPresent) LoaderBlock.Flags |= MB_INFO_FLAG_ACPI_TABLE;
739
740 UiDrawStatusText("Loading...");
741 UiDrawProgressBarCenter(0, 100, "Loading ReactOS...");
742
743 /*
744 * Try to open boot drive
745 */
746 if (!FsOpenVolume(BootDrive, BootPartition))
747 {
748 UiMessageBox("Failed to open boot drive.");
749 return;
750 }
751
752 /*
753 * Find the kernel image name
754 * and try to load the kernel off the disk
755 */
756 if(IniReadSettingByName(SectionId, "Kernel", value, 1024))
757 {
758 /*
759 * Set the name and
760 */
761 if (value[0] == '\\')
762 {
763 strcpy(szKernelName, value);
764 }
765 else
766 {
767 strcpy(szKernelName, szBootPath);
768 strcat(szKernelName, "SYSTEM32\\");
769 strcat(szKernelName, value);
770 }
771 }
772 else
773 {
774 strcpy(value, "NTOSKRNL.EXE");
775 strcpy(szKernelName, szBootPath);
776 strcat(szKernelName, "SYSTEM32\\");
777 strcat(szKernelName, value);
778 }
779
780 if (!FrLdrLoadKernel(szKernelName, 5)) return;
781
782 /*
783 * Find the HAL image name
784 * and try to load the kernel off the disk
785 */
786 if(IniReadSettingByName(SectionId, "Hal", value, 1024))
787 {
788 /*
789 * Set the name and
790 */
791 if (value[0] == '\\')
792 {
793 strcpy(szHalName, value);
794 }
795 else
796 {
797 strcpy(szHalName, szBootPath);
798 strcat(szHalName, "SYSTEM32\\");
799 strcat(szHalName, value);
800 }
801 }
802 else
803 {
804 strcpy(value, "HAL.DLL");
805 strcpy(szHalName, szBootPath);
806 strcat(szHalName, "SYSTEM32\\");
807 strcat(szHalName, value);
808 }
809
810 if (!FrLdrLoadDriver(szHalName, 10))
811 return;
812
813 /*
814 * Load the System hive from disk
815 */
816 strcpy(szFileName, szBootPath);
817 strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
818
819 DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
820
821 FilePointer = FsOpenFile(szFileName);
822 if (FilePointer == NULL)
823 {
824 UiMessageBox("Could not find the System hive!");
825 return;
826 }
827
828 /*
829 * Update the status bar with the current file
830 */
831 strcpy(name, "Reading ");
832 strcat(name, value);
833 while (strlen(name) < 80)
834 strcat(name, " ");
835 UiDrawStatusText(name);
836
837 /*
838 * Load the System hive
839 */
840 Base = FrLdrLoadModule(FilePointer, szFileName, &Size);
841 if (Base == 0 || Size == 0)
842 {
843 UiMessageBox("Could not load the System hive!\n");
844 return;
845 }
846 DbgPrint((DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size));
847
848 /*
849 * Import the loaded system hive
850 */
851 RegImportBinaryHive((PCHAR)Base, Size);
852
853 /*
854 * Initialize the 'CurrentControlSet' link
855 */
856 RegInitCurrentControlSet(FALSE);
857
858 UiDrawProgressBarCenter(15, 100, "Loading ReactOS...");
859
860 /*
861 * Export the hardware hive
862 */
863 Base = FrLdrCreateModule ("HARDWARE");
864 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", (PCHAR)Base, &Size);
865 FrLdrCloseModule (Base, Size);
866
867 UiDrawProgressBarCenter(20, 100, "Loading ReactOS...");
868
869 /*
870 * Load NLS files
871 */
872 if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
873 {
874 UiMessageBox(MsgBuffer);
875 return;
876 }
877 UiDrawProgressBarCenter(30, 100, "Loading ReactOS...");
878
879 /*
880 * Load kernel symbols
881 */
882 LoadKernelSymbols(szKernelName, 30);
883 UiDrawProgressBarCenter(40, 100, "Loading ReactOS...");
884
885 /*
886 * Load boot drivers
887 */
888 FrLdrLoadBootDrivers(szBootPath, 40);
889 UiUnInitialize("Booting ReactOS...");
890
891 /*
892 * Now boot the kernel
893 */
894 DiskStopFloppyMotor();
895 MachVideoPrepareForReactOS();
896 FrLdrStartup(0x2badb002);
897 }
898
899 #undef DbgPrint
900 ULONG
901 DbgPrint(char *Fmt, ...)
902 {
903 UiMessageBox(Fmt);
904 return 0;
905 }
906
907 /* EOF */