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>
40 LoadKernel(PCHAR szSourcePath
, PCHAR szFileName
)
49 if (szSourcePath
[0] != '\\')
51 strcpy(szFullName
, "\\");
52 strcat(szFullName
, szSourcePath
);
56 strcpy(szFullName
, szSourcePath
);
59 if (szFullName
[strlen(szFullName
)] != '\\')
61 strcat(szFullName
, "\\");
64 if (szFileName
[0] != '\\')
66 strcat(szFullName
, szFileName
);
70 strcat(szFullName
, szFileName
+ 1);
73 szShortName
= strrchr(szFileName
, '\\');
74 if (szShortName
== NULL
)
75 szShortName
= szFileName
;
77 szShortName
= szShortName
+ 1;
79 FilePointer
= FsOpenFile(szFullName
);
80 if (FilePointer
== NULL
)
82 printf("Could not find %s\n", szShortName
);
87 * Update the status bar with the current file
90 sprintf(szBuffer
, "Reading %s", szShortName
);
91 UiDrawStatusText(szBuffer
);
93 printf("Reading %s\n", szShortName
);
99 MultiBootLoadKernel(FilePointer
);
106 LoadDriver(PCHAR szSourcePath
, PCHAR szFileName
)
108 CHAR szFullName
[256];
115 if (szSourcePath
[0] != '\\')
117 strcpy(szFullName
, "\\");
118 strcat(szFullName
, szSourcePath
);
122 strcpy(szFullName
, szSourcePath
);
125 if (szFullName
[strlen(szFullName
)] != '\\')
127 strcat(szFullName
, "\\");
130 if (szFileName
[0] != '\\')
132 strcat(szFullName
, szFileName
);
136 strcat(szFullName
, szFileName
+ 1);
139 szShortName
= strrchr(szFileName
, '\\');
140 if (szShortName
== NULL
)
141 szShortName
= szFileName
;
143 szShortName
= szShortName
+ 1;
146 FilePointer
= FsOpenFile(szFullName
);
147 if (FilePointer
== NULL
)
149 printf("Could not find %s\n", szFileName
);
154 * Update the status bar with the current file
157 sprintf(szBuffer
, "Reading %s", szShortName
);
158 UiDrawStatusText(szBuffer
);
160 printf("Reading %s\n", szShortName
);
163 /* Load the driver */
164 MultiBootLoadModule(FilePointer
, szFileName
, NULL
);
171 LoadNlsFile(PCHAR szSourcePath
, PCHAR szFileName
, PCHAR szModuleName
)
173 CHAR szFullName
[256];
180 if (szSourcePath
[0] != '\\')
182 strcpy(szFullName
, "\\");
183 strcat(szFullName
, szSourcePath
);
187 strcpy(szFullName
, szSourcePath
);
190 if (szFullName
[strlen(szFullName
)] != '\\')
192 strcat(szFullName
, "\\");
195 if (szFileName
[0] != '\\')
197 strcat(szFullName
, szFileName
);
201 strcat(szFullName
, szFileName
+ 1);
204 szShortName
= strrchr(szFileName
, '\\');
205 if (szShortName
== NULL
)
206 szShortName
= szFileName
;
208 szShortName
= szShortName
+ 1;
211 FilePointer
= FsOpenFile(szFullName
);
212 if (FilePointer
== NULL
)
214 printf("Could not find %s\n", szFileName
);
219 * Update the status bar with the current file
222 sprintf(szBuffer
, "Reading %s", szShortName
);
223 UiDrawStatusText(szBuffer
);
225 printf("Reading %s\n", szShortName
);
228 /* Load the driver */
229 MultiBootLoadModule(FilePointer
, szModuleName
, NULL
);
244 INFCONTEXT InfContext
;
246 /* Setup multiboot information structure */
247 mb_info
.flags
= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
248 mb_info
.mem_lower
= GetConventionalMemorySize();
249 mb_info
.mem_upper
= GetExtendedMemorySize();
250 mb_info
.boot_device
= 0xffffffff;
251 mb_info
.cmdline
= (unsigned long)multiboot_kernel_cmdline
;
252 mb_info
.mods_count
= 0;
253 mb_info
.mods_addr
= (unsigned long)multiboot_modules
;
254 mb_info
.mmap_length
= (unsigned long)GetBiosMemoryMap((PBIOS_MEMORY_MAP
)&multiboot_memory_map
, 32) * sizeof(memory_map_t
);
255 if (mb_info
.mmap_length
)
257 mb_info
.mmap_addr
= (unsigned long)&multiboot_memory_map
;
258 mb_info
.flags
|= MB_INFO_FLAG_MEMORY_MAP
;
259 multiboot_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
263 printf("memory map length: %d\n", mb_info
.mmap_length
);
264 printf("dumping memory map:\n");
265 for (i
=0; i
<(mb_info
.mmap_length
/ sizeof(memory_map_t
)); i
++)
267 printf("start: %x\t size: %x\t type %d\n",
268 multiboot_memory_map
[i
].base_addr_low
,
269 multiboot_memory_map
[i
].length_low
,
270 multiboot_memory_map
[i
].type
);
277 printf("low_mem = %d\n", mb_info
.mem_lower
);
278 printf("high_mem = %d\n", mb_info
.mem_upper
);
284 UiDrawStatusText("");
287 /* Initialize registry */
288 RegInitializeRegistry();
290 /* Detect hardware */
292 UiDrawStatusText("Detecting hardware...");
294 printf("Detecting hardware...\n\n");
298 UiDrawStatusText("");
301 /* set boot drive and partition */
302 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
303 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
306 /* Open boot drive */
307 if (!FsOpenVolume(BootDrive
, BootPartition
))
310 UiMessageBox("Failed to open boot drive.");
312 printf("Failed to open boot drive.");
317 /* Open 'txtsetup.sif' */
318 if (!InfOpenFile (&InfHandle
,
319 (BootDrive
< 0x80) ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
322 printf("Failed to open 'txtsetup.sif'\n");
326 /* Get load options */
327 if (!InfFindFirstLine (InfHandle
,
332 printf("Failed to find 'SetupData/OsLoadOptions'\n");
336 if (!InfGetDataField (&InfContext
,
340 printf("Failed to get load options\n");
344 printf("LoadOptions: '%s'\n", LoadOptions
);
347 if (BootDrive
< 0x80)
349 /* Boot from floppy disk */
354 /* Boot from cdrom */
355 SourcePath
= "\\reactos";
358 /* Set kernel command line */
359 sprintf(multiboot_kernel_cmdline
,
360 "multi(0)disk(0)%s(%u)%s %s",
361 (BootDrive
< 0x80) ? "fdisk" : "cdrom",
362 (unsigned int)BootDrive
,
366 /* Load ntoskrnl.exe */
367 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
372 if (!LoadDriver(SourcePath
, "hal.dll"))
376 /* Export the hardware hive */
377 Base
= MultiBootCreateModule ("HARDWARE");
378 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", Base
, &Size
);
379 MultiBootCloseModule (Base
, Size
);
382 printf("Base: %x\n", Base
);
383 printf("Size: %u\n", Size
);
384 printf("*** System stopped ***\n");
388 /* Insert boot disk 2 */
389 if (BootDrive
< 0x80)
392 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
394 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
398 /* Open boot drive */
399 if (!FsOpenVolume(BootDrive
, BootPartition
))
402 UiMessageBox("Failed to open boot drive.");
404 printf("Failed to open boot drive.");
409 /* FIXME: check volume label or disk marker file */
413 /* Get ANSI codepage file */
414 if (!InfFindFirstLine (InfHandle
,
419 printf("Failed to find 'NLS/AnsiCodepage'\n");
423 if (!InfGetDataField (&InfContext
,
427 printf("Failed to get load options\n");
431 /* Load ANSI codepage file */
432 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
435 UiMessageBox("Failed to load the ANSI codepage file.");
437 printf("Failed to load the ANSI codepage file.");
442 /* Get OEM codepage file */
443 if (!InfFindFirstLine (InfHandle
,
448 printf("Failed to find 'NLS/AnsiCodepage'\n");
452 if (!InfGetDataField (&InfContext
,
456 printf("Failed to get load options\n");
460 /* Load OEM codepage file */
461 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
464 UiMessageBox("Failed to load the OEM codepage file.");
466 printf("Failed to load the OEM codepage file.");
471 /* Get Unicode Casemap file */
472 if (!InfFindFirstLine (InfHandle
,
477 printf("Failed to find 'NLS/AnsiCodepage'\n");
481 if (!InfGetDataField (&InfContext
,
485 printf("Failed to get load options\n");
489 /* Load Unicode casemap file */
490 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
493 UiMessageBox("Failed to load the Unicode casemap file.");
495 printf("Failed to load the Unicode casemap file.");
502 if (BootDrive
< 0x80)
507 if (!LoadDriver(SourcePath
, "floppy.sys"))
511 * Load vfatfs.sys (could be loaded by the setup prog!)
513 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
521 if (!LoadDriver(SourcePath
, "scsiport.sys"))
525 * Load atapi.sys (depends on hardware detection)
527 if (!LoadDriver(SourcePath
, "atapi.sys"))
533 if (!LoadDriver(SourcePath
, "class2.sys"))
539 if (!LoadDriver(SourcePath
, "cdrom.sys"))
545 if (!LoadDriver(SourcePath
, "cdfs.sys"))
551 if (!LoadDriver(SourcePath
, "disk.sys"))
555 * Load vfatfs.sys (could be loaded by the setup prog!)
557 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
563 * Load keyboard driver
565 if (!LoadDriver(SourcePath
, "keyboard.sys"))
571 if (!LoadDriver(SourcePath
, "blue.sys"))
575 UiUnInitialize("Booting ReactOS...");
579 * Now boot the kernel
581 DiskStopFloppyMotor();