4 * Copyright (C) 1998-2003 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>
41 LoadKernel(PCHAR szSourcePath
, PCHAR szFileName
)
50 if (szSourcePath
[0] != '\\')
52 strcpy(szFullName
, "\\");
53 strcat(szFullName
, szSourcePath
);
57 strcpy(szFullName
, szSourcePath
);
60 if (szFullName
[strlen(szFullName
)] != '\\')
62 strcat(szFullName
, "\\");
65 if (szFileName
[0] != '\\')
67 strcat(szFullName
, szFileName
);
71 strcat(szFullName
, szFileName
+ 1);
74 szShortName
= strrchr(szFileName
, '\\');
75 if (szShortName
== NULL
)
76 szShortName
= szFileName
;
78 szShortName
= szShortName
+ 1;
80 FilePointer
= FsOpenFile(szFullName
);
81 if (FilePointer
== NULL
)
83 printf("Could not find %s\n", szShortName
);
88 * Update the status bar with the current file
91 sprintf(szBuffer
, "Reading %s", szShortName
);
92 UiDrawStatusText(szBuffer
);
94 printf("Reading %s\n", szShortName
);
100 FrLdrMapKernel(FilePointer
);
107 LoadDriver(PCHAR szSourcePath
, PCHAR szFileName
)
109 CHAR szFullName
[256];
116 if (szSourcePath
[0] != '\\')
118 strcpy(szFullName
, "\\");
119 strcat(szFullName
, szSourcePath
);
123 strcpy(szFullName
, szSourcePath
);
126 if (szFullName
[strlen(szFullName
)] != '\\')
128 strcat(szFullName
, "\\");
131 if (szFileName
[0] != '\\')
133 strcat(szFullName
, szFileName
);
137 strcat(szFullName
, szFileName
+ 1);
140 szShortName
= strrchr(szFileName
, '\\');
141 if (szShortName
== NULL
)
142 szShortName
= szFileName
;
144 szShortName
= szShortName
+ 1;
147 FilePointer
= FsOpenFile(szFullName
);
148 if (FilePointer
== NULL
)
150 printf("Could not find %s\n", szFileName
);
155 * Update the status bar with the current file
158 sprintf(szBuffer
, "Reading %s", szShortName
);
159 UiDrawStatusText(szBuffer
);
161 printf("Reading %s\n", szShortName
);
164 /* Load the driver */
165 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
172 LoadNlsFile(PCHAR szSourcePath
, PCHAR szFileName
, PCHAR szModuleName
)
174 CHAR szFullName
[256];
181 if (szSourcePath
[0] != '\\')
183 strcpy(szFullName
, "\\");
184 strcat(szFullName
, szSourcePath
);
188 strcpy(szFullName
, szSourcePath
);
191 if (szFullName
[strlen(szFullName
)] != '\\')
193 strcat(szFullName
, "\\");
196 if (szFileName
[0] != '\\')
198 strcat(szFullName
, szFileName
);
202 strcat(szFullName
, szFileName
+ 1);
205 szShortName
= strrchr(szFileName
, '\\');
206 if (szShortName
== NULL
)
207 szShortName
= szFileName
;
209 szShortName
= szShortName
+ 1;
212 FilePointer
= FsOpenFile(szFullName
);
213 if (FilePointer
== NULL
)
215 printf("Could not find %s\n", szFileName
);
220 * Update the status bar with the current file
223 sprintf(szBuffer
, "Reading %s", szShortName
);
224 UiDrawStatusText(szBuffer
);
226 printf("Reading %s\n", szShortName
);
229 /* Load the driver */
230 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
246 INFCONTEXT InfContext
;
248 extern ULONG PageDirectoryStart
;
249 extern ULONG PageDirectoryEnd
;
251 /* Setup multiboot information structure */
252 LoaderBlock
.Flags
= MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
253 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
254 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
255 LoaderBlock
.BootDevice
= 0xffffffff;
256 LoaderBlock
.CommandLine
= (unsigned long)multiboot_kernel_cmdline
;
257 LoaderBlock
.ModsCount
= 0;
258 LoaderBlock
.ModsAddr
= (unsigned long)multiboot_modules
;
259 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&multiboot_memory_map
, 32) * sizeof(memory_map_t
);
260 if (LoaderBlock
.MmapLength
)
262 LoaderBlock
.MmapAddr
= (unsigned long)&multiboot_memory_map
;
263 LoaderBlock
.Flags
|= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_MEMORY_MAP
;
264 multiboot_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
265 for (i
= 0; i
< (LoaderBlock
.MmapLength
/ sizeof(memory_map_t
)); i
++)
267 if (MEMTYPE_USABLE
== multiboot_memory_map
[i
].type
&&
268 0 == multiboot_memory_map
[i
].base_addr_low
)
270 LoaderBlock
.MemLower
= (multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
) / 1024;
271 if (640 < LoaderBlock
.MemLower
)
273 LoaderBlock
.MemLower
= 640;
276 if (MEMTYPE_USABLE
== multiboot_memory_map
[i
].type
&&
277 multiboot_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
278 1024 * 1024 <= multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
)
280 LoaderBlock
.MemHigher
= (multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
) / 1024 - 1024;
283 printf("start: %x\t size: %x\t type %d\n",
284 multiboot_memory_map
[i
].base_addr_low
,
285 multiboot_memory_map
[i
].length_low
,
286 multiboot_memory_map
[i
].type
);
291 printf("low_mem = %d\n", LoaderBlock
.MemLower
);
292 printf("high_mem = %d\n", LoaderBlock
.MemHigher
);
298 UiDrawStatusText("");
301 /* Initialize registry */
302 RegInitializeRegistry();
304 /* Detect hardware */
306 UiDrawStatusText("Detecting hardware...");
308 printf("Detecting hardware...\n\n");
312 UiDrawStatusText("");
315 /* set boot device */
316 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
318 /* Open boot drive */
319 if (!FsOpenBootVolume())
322 UiMessageBox("Failed to open boot drive.");
324 printf("Failed to open boot drive.");
329 /* Open 'txtsetup.sif' */
330 if (!InfOpenFile (&InfHandle
,
331 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
334 printf("Failed to open 'txtsetup.sif'\n");
338 /* Get load options */
339 if (!InfFindFirstLine (InfHandle
,
344 printf("Failed to find 'SetupData/OsLoadOptions'\n");
348 if (!InfGetDataField (&InfContext
,
352 printf("Failed to get load options\n");
356 printf("LoadOptions: '%s'\n", LoadOptions
);
359 if (MachDiskBootingFromFloppy())
361 /* Boot from floppy disk */
366 /* Boot from cdrom */
367 SourcePath
= "\\reactos";
370 /* Set kernel command line */
371 MachDiskGetBootPath(multiboot_kernel_cmdline
, sizeof(multiboot_kernel_cmdline
));
372 strcat(strcat(strcat(multiboot_kernel_cmdline
, SourcePath
), " "),
375 /* Load ntoskrnl.exe */
376 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
381 if (!LoadDriver(SourcePath
, "hal.dll"))
385 /* Export the hardware hive */
386 Base
= FrLdrCreateModule ("HARDWARE");
387 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
388 FrLdrCloseModule (Base
, Size
);
391 printf("Base: %x\n", Base
);
392 printf("Size: %u\n", Size
);
393 printf("*** System stopped ***\n");
397 /* Insert boot disk 2 */
398 if (MachDiskBootingFromFloppy())
401 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
403 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
407 /* Open boot drive */
408 if (!FsOpenBootVolume())
411 UiMessageBox("Failed to open boot drive.");
413 printf("Failed to open boot drive.");
418 /* FIXME: check volume label or disk marker file */
422 /* Get ANSI codepage file */
423 if (!InfFindFirstLine (InfHandle
,
428 printf("Failed to find 'NLS/AnsiCodepage'\n");
432 if (!InfGetDataField (&InfContext
,
436 printf("Failed to get load options\n");
440 /* Load ANSI codepage file */
441 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
444 UiMessageBox("Failed to load the ANSI codepage file.");
446 printf("Failed to load the ANSI codepage file.");
451 /* Get OEM codepage file */
452 if (!InfFindFirstLine (InfHandle
,
457 printf("Failed to find 'NLS/AnsiCodepage'\n");
461 if (!InfGetDataField (&InfContext
,
465 printf("Failed to get load options\n");
469 /* Load OEM codepage file */
470 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
473 UiMessageBox("Failed to load the OEM codepage file.");
475 printf("Failed to load the OEM codepage file.");
480 /* Get Unicode Casemap file */
481 if (!InfFindFirstLine (InfHandle
,
486 printf("Failed to find 'NLS/AnsiCodepage'\n");
490 if (!InfGetDataField (&InfContext
,
494 printf("Failed to get load options\n");
498 /* Load Unicode casemap file */
499 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
502 UiMessageBox("Failed to load the Unicode casemap file.");
504 printf("Failed to load the Unicode casemap file.");
511 if (!LoadDriver(SourcePath
, "acpi.sys"))
516 /* Load isapnp.sys */
517 if (!LoadDriver(SourcePath
, "isapnp.sys"))
523 if (!LoadDriver(SourcePath
, "pci.sys"))
527 /* Load scsiport.sys */
528 if (!LoadDriver(SourcePath
, "scsiport.sys"))
531 /* Load atapi.sys (depends on hardware detection) */
532 if (!LoadDriver(SourcePath
, "atapi.sys"))
535 /* Load class2.sys */
536 if (!LoadDriver(SourcePath
, "class2.sys"))
540 if (!LoadDriver(SourcePath
, "cdrom.sys"))
544 if (!LoadDriver(SourcePath
, "cdfs.sys"))
548 if (!LoadDriver(SourcePath
, "disk.sys"))
551 /* Load floppy.sys */
552 if (!LoadDriver(SourcePath
, "floppy.sys"))
555 /* Load vfatfs.sys (could be loaded by the setup prog!) */
556 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
560 /* Load keyboard driver */
561 if (!LoadDriver(SourcePath
, "keyboard.sys"))
564 /* Load screen driver */
565 if (!LoadDriver(SourcePath
, "blue.sys"))
569 UiUnInitialize("Booting ReactOS...");
572 /* Now boot the kernel */
573 DiskStopFloppyMotor();
574 MachVideoPrepareForReactOS();
575 FrLdrStartup(0x2badb002);