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