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 MultiBootLoadKernel(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 MultiBootLoadModule(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 MultiBootLoadModule(FilePointer
, szModuleName
, NULL
);
246 INFCONTEXT InfContext
;
248 /* Setup multiboot information structure */
249 mb_info
.flags
= MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
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)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&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_MEM_SIZE
| MB_INFO_FLAG_MEMORY_MAP
;
259 multiboot_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
260 for (i
= 0; i
< (mb_info
.mmap_length
/ sizeof(memory_map_t
)); i
++)
262 if (MEMTYPE_USABLE
== multiboot_memory_map
[i
].type
&&
263 0 == multiboot_memory_map
[i
].base_addr_low
)
265 mb_info
.mem_lower
= (multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
) / 1024;
266 if (640 < mb_info
.mem_lower
)
268 mb_info
.mem_lower
= 640;
271 if (MEMTYPE_USABLE
== multiboot_memory_map
[i
].type
&&
272 multiboot_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
273 1024 * 1024 <= multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
)
275 mb_info
.mem_upper
= (multiboot_memory_map
[i
].base_addr_low
+ multiboot_memory_map
[i
].length_low
) / 1024 - 1024;
278 printf("start: %x\t size: %x\t type %d\n",
279 multiboot_memory_map
[i
].base_addr_low
,
280 multiboot_memory_map
[i
].length_low
,
281 multiboot_memory_map
[i
].type
);
286 printf("low_mem = %d\n", mb_info
.mem_lower
);
287 printf("high_mem = %d\n", mb_info
.mem_upper
);
293 UiDrawStatusText("");
296 /* Initialize registry */
297 RegInitializeRegistry();
299 /* Detect hardware */
301 UiDrawStatusText("Detecting hardware...");
303 printf("Detecting hardware...\n\n");
307 UiDrawStatusText("");
310 /* set boot drive and partition */
311 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
312 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
315 /* Open boot drive */
316 if (!FsOpenVolume(BootDrive
, BootPartition
))
319 UiMessageBox("Failed to open boot drive.");
321 printf("Failed to open boot drive.");
326 /* Open 'txtsetup.sif' */
327 if (!InfOpenFile (&InfHandle
,
328 (BootDrive
< 0x80) ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
331 printf("Failed to open 'txtsetup.sif'\n");
335 /* Get load options */
336 if (!InfFindFirstLine (InfHandle
,
341 printf("Failed to find 'SetupData/OsLoadOptions'\n");
345 if (!InfGetDataField (&InfContext
,
349 printf("Failed to get load options\n");
353 printf("LoadOptions: '%s'\n", LoadOptions
);
356 if (BootDrive
< 0x80)
358 /* Boot from floppy disk */
363 /* Boot from cdrom */
364 SourcePath
= "\\reactos";
367 /* Set kernel command line */
368 sprintf(multiboot_kernel_cmdline
,
369 "multi(0)disk(0)%s(%u)%s %s",
370 (BootDrive
< 0x80) ? "fdisk" : "cdrom",
371 (unsigned int)BootDrive
,
375 /* Load ntoskrnl.exe */
376 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
381 if (!LoadDriver(SourcePath
, "hal.dll"))
385 /* Export the hardware hive */
386 Base
= MultiBootCreateModule ("HARDWARE");
387 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", Base
, &Size
);
388 MultiBootCloseModule (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 (BootDrive
< 0x80)
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 (!FsOpenVolume(BootDrive
, BootPartition
))
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();