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.
25 extern ULONG PageDirectoryStart
;
26 extern ULONG PageDirectoryEnd
;
28 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
29 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
30 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
31 char reactos_module_strings
[64][256]; // Array to hold module names
32 reactos_mem_data_t reactos_mem_data
;
36 extern ULONG_PTR KernelBase
, KernelEntryPoint
;
38 extern BOOLEAN
FrLdrLoadDriver(PCHAR szFileName
, INT nPos
);
44 static FrLdrLoadKernel(IN PCHAR szFileName
,
51 PIMAGE_NT_HEADERS NtHeader
;
53 /* Extract Kernel filename without path */
54 szShortName
= strrchr(szFileName
, '\\');
57 /* No path, leave it alone */
58 szShortName
= szFileName
;
63 szShortName
= szShortName
+ 1;
67 FilePointer
= FsOpenFile(szFileName
);
70 /* Return failure on the short name */
71 strcpy(szBuffer
, szShortName
);
72 strcat(szBuffer
, " not found.");
73 UiMessageBox(szBuffer
);
77 /* Update the status bar with the current file */
78 strcpy(szBuffer
, "Reading ");
79 strcat(szBuffer
, szShortName
);
80 UiDrawStatusText(szBuffer
);
82 /* Do the actual loading */
83 LoadBase
= FrLdrMapImage(FilePointer
, szShortName
, 1);
85 /* Get the NT header, kernel base and kernel entry */
86 NtHeader
= RtlImageNtHeader(LoadBase
);
87 KernelBase
= NtHeader
->OptionalHeader
.ImageBase
;
88 KernelEntryPoint
= KernelBase
+ NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
89 LoaderBlock
.KernelBase
= KernelBase
;
91 /* Update Processbar and return success */
96 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
98 return FrLdrLoadDriver((PCHAR
)szFileName
, 0);
103 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
105 CHAR szFullName
[256];
112 if (szSourcePath
[0] != '\\')
114 strcpy(szFullName
, "\\");
115 strcat(szFullName
, szSourcePath
);
119 strcpy(szFullName
, szSourcePath
);
122 if (szFullName
[strlen(szFullName
)] != '\\')
124 strcat(szFullName
, "\\");
127 if (szFileName
[0] != '\\')
129 strcat(szFullName
, szFileName
);
133 strcat(szFullName
, szFileName
+ 1);
136 szShortName
= strrchr(szFileName
, '\\');
137 if (szShortName
== NULL
)
138 szShortName
= szFileName
;
140 szShortName
= szShortName
+ 1;
143 FilePointer
= FsOpenFile(szFullName
);
144 if (FilePointer
== NULL
)
146 printf("Could not find %s\n", szFileName
);
151 * Update the status bar with the current file
154 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
155 UiDrawStatusText(szBuffer
);
157 printf("Reading %s\n", szShortName
);
160 /* Load the driver */
161 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
170 const char *SourcePath
;
171 const char *LoadOptions
= "", *DbgLoadOptions
= "";
172 const char *sourcePaths
[] = {
173 "", /* Only for floppy boot */
176 #elif defined(_M_MPPC)
178 #elif defined(_M_MRX000)
183 char szKernelName
[256];
187 INFCONTEXT InfContext
;
189 /* Setup multiboot information structure */
190 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
191 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
192 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
193 LoaderBlock
.ModsCount
= 0;
194 LoaderBlock
.ModsAddr
= reactos_modules
;
195 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
196 if (LoaderBlock
.MmapLength
)
200 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
201 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
202 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
204 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
205 0 == reactos_memory_map
[i
].base_addr_low
)
207 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
208 if (640 < LoaderBlock
.MemLower
)
210 LoaderBlock
.MemLower
= 640;
213 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
214 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
215 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
217 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
224 UiDrawStatusText("");
227 extern BOOLEAN FrLdrBootType
;
228 FrLdrBootType
= TRUE
;
230 /* Initialize registry */
231 RegInitializeRegistry();
233 /* Detect hardware */
235 UiDrawStatusText("Detecting hardware...");
237 printf("Detecting hardware...\n\n");
241 UiDrawStatusText("");
244 /* set boot device */
245 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
247 /* Open boot drive */
248 if (!FsOpenBootVolume())
251 UiMessageBox("Failed to open boot drive.");
253 printf("Failed to open boot drive.");
258 /* Open 'txtsetup.sif' */
259 for (i
= MachDiskBootingFromFloppy() ? 0 : 1; ; i
++)
261 SourcePath
= sourcePaths
[i
];
264 printf("Failed to open 'txtsetup.sif'\n");
267 strcpy(szKernelName
, SourcePath
);
268 strcat(szKernelName
, "\\txtsetup.sif");
269 if (InfOpenFile (&InfHandle
, szKernelName
, &ErrorLine
))
276 /* Get load options */
277 if (InfFindFirstLine (InfHandle
,
282 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
286 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
291 printf("Failed to find 'SetupData/OsLoadOptions'\n");
295 if (!InfGetDataField (&InfContext
,
299 printf("Failed to get load options\n");
303 printf("LoadOptions: '%s'\n", LoadOptions
);
306 /* Set kernel command line */
307 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
308 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
309 LoadOptions
), DbgLoadOptions
);
311 strcpy(SystemRoot
, SourcePath
);
312 strcat(SystemRoot
, "\\");
314 /* Setup the boot path and kernel path */
315 strcpy(szBootPath
, SourcePath
);
316 strcpy(szKernelName
, szBootPath
);
317 strcat(szKernelName
, "\\ntoskrnl.exe");
319 /* Setup the HAL path */
320 strcpy(szHalName
, szBootPath
);
321 strcat(szHalName
, "\\hal.dll");
323 /* Load the kernel */
324 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
326 /* Export the hardware hive */
327 Base
= FrLdrCreateModule ("HARDWARE");
328 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
329 FrLdrCloseModule (Base
, Size
);
332 printf("Base: %x\n", Base
);
333 printf("Size: %u\n", Size
);
334 printf("*** System stopped ***\n");
338 /* Insert boot disk 2 */
339 if (MachDiskBootingFromFloppy())
342 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
344 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
348 /* Open boot drive */
349 if (!FsOpenBootVolume())
352 UiMessageBox("Failed to open boot drive.");
354 printf("Failed to open boot drive.");
359 /* FIXME: check volume label or disk marker file */
363 /* Get ANSI codepage file */
364 if (!InfFindFirstLine (InfHandle
,
369 printf("Failed to find 'NLS/AnsiCodepage'\n");
373 if (!InfGetDataField (&InfContext
,
377 printf("Failed to get load options\n");
381 /* Load ANSI codepage file */
382 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
385 UiMessageBox("Failed to load the ANSI codepage file.");
387 printf("Failed to load the ANSI codepage file.");
392 /* Get OEM codepage file */
393 if (!InfFindFirstLine (InfHandle
,
398 printf("Failed to find 'NLS/AnsiCodepage'\n");
402 if (!InfGetDataField (&InfContext
,
406 printf("Failed to get load options\n");
410 /* Load OEM codepage file */
411 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
414 UiMessageBox("Failed to load the OEM codepage file.");
416 printf("Failed to load the OEM codepage file.");
421 /* Get Unicode Casemap file */
422 if (!InfFindFirstLine (InfHandle
,
427 printf("Failed to find 'NLS/AnsiCodepage'\n");
431 if (!InfGetDataField (&InfContext
,
435 printf("Failed to get load options\n");
439 /* Load Unicode casemap file */
440 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
443 UiMessageBox("Failed to load the Unicode casemap file.");
445 printf("Failed to load the Unicode casemap file.");
450 /* Load atapi.sys (depends on hardware detection) */
451 if (!LoadDriver(SourcePath
, "atapi.sys"))
454 /* Load buslogic.sys (depends on hardware detection) */
455 if (!LoadDriver(SourcePath
, "buslogic.sys"))
458 /* Load vfatfs.sys (could be loaded by the setup prog!) */
459 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
462 /* Load additional files specified in txtsetup.inf */
463 if (InfFindFirstLine(InfHandle
,
470 LPCSTR Media
, DriverName
;
471 if (InfGetDataField(&InfContext
, 7, &Media
) &&
472 InfGetDataField(&InfContext
, 0, &DriverName
))
474 if (strcmp(Media
, "x") == 0)
476 if (!LoadDriver(SourcePath
, DriverName
))
480 } while (InfFindNextLine(&InfContext
, &InfContext
));
484 UiUnInitialize("Booting ReactOS...");
487 /* Now boot the kernel */
488 DiskStopFloppyMotor();
489 MachVideoPrepareForReactOS(TRUE
);
490 FrLdrStartup(0x2badb002);