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];
110 if (szSourcePath
[0] != '\\')
112 strcpy(szFullName
, "\\");
113 strcat(szFullName
, szSourcePath
);
117 strcpy(szFullName
, szSourcePath
);
120 if (szFullName
[strlen(szFullName
)] != '\\')
122 strcat(szFullName
, "\\");
125 if (szFileName
[0] != '\\')
127 strcat(szFullName
, szFileName
);
131 strcat(szFullName
, szFileName
+ 1);
134 szShortName
= strrchr(szFileName
, '\\');
135 if (szShortName
== NULL
)
136 szShortName
= szFileName
;
138 szShortName
= szShortName
+ 1;
141 FilePointer
= FsOpenFile(szFullName
);
142 if (FilePointer
== NULL
)
144 printf("Could not find %s\n", szFileName
);
149 * Update the status bar with the current file
151 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
152 UiDrawStatusText(szBuffer
);
154 /* Load the driver */
155 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
164 const char *SourcePath
;
165 const char *LoadOptions
= "", *DbgLoadOptions
= "";
166 const char *sourcePaths
[] = {
167 "", /* Only for floppy boot */
170 #elif defined(_M_MPPC)
172 #elif defined(_M_MRX000)
177 char szKernelName
[256];
181 INFCONTEXT InfContext
;
183 /* Setup multiboot information structure */
184 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
185 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
186 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
187 LoaderBlock
.ModsCount
= 0;
188 LoaderBlock
.ModsAddr
= reactos_modules
;
189 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
190 if (LoaderBlock
.MmapLength
)
194 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
195 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
196 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
198 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
199 0 == reactos_memory_map
[i
].base_addr_low
)
201 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
202 if (640 < LoaderBlock
.MemLower
)
204 LoaderBlock
.MemLower
= 640;
207 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
208 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
209 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
211 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
219 UiDrawStatusText("");
221 extern BOOLEAN FrLdrBootType
;
222 FrLdrBootType
= TRUE
;
224 /* Initialize registry */
225 RegInitializeRegistry();
227 /* Detect hardware */
228 UiDrawStatusText("Detecting hardware...");
230 UiDrawStatusText("");
232 /* set boot device */
233 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
235 /* Open boot drive */
236 if (!FsOpenBootVolume())
238 UiMessageBox("Failed to open boot drive.");
242 /* Open 'txtsetup.sif' */
243 for (i
= MachDiskBootingFromFloppy() ? 0 : 1; ; i
++)
245 SourcePath
= sourcePaths
[i
];
248 printf("Failed to open 'txtsetup.sif'\n");
251 strcpy(szKernelName
, SourcePath
);
252 strcat(szKernelName
, "\\txtsetup.sif");
253 if (InfOpenFile (&InfHandle
, szKernelName
, &ErrorLine
))
260 /* Get load options */
261 if (InfFindFirstLine (InfHandle
,
266 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
270 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
275 printf("Failed to find 'SetupData/OsLoadOptions'\n");
279 if (!InfGetDataField (&InfContext
,
283 printf("Failed to get load options\n");
287 /* Set kernel command line */
288 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
289 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
290 LoadOptions
), DbgLoadOptions
);
292 strcpy(SystemRoot
, SourcePath
);
293 strcat(SystemRoot
, "\\");
295 /* Setup the boot path and kernel path */
296 strcpy(szBootPath
, SourcePath
);
297 strcpy(szKernelName
, szBootPath
);
298 strcat(szKernelName
, "\\ntoskrnl.exe");
300 /* Setup the HAL path */
301 strcpy(szHalName
, szBootPath
);
302 strcat(szHalName
, "\\hal.dll");
304 /* Load the kernel */
305 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
307 /* Export the hardware hive */
308 Base
= FrLdrCreateModule ("HARDWARE");
309 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
310 FrLdrCloseModule (Base
, Size
);
312 /* Insert boot disk 2 */
313 if (MachDiskBootingFromFloppy())
315 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
317 /* Open boot drive */
318 if (!FsOpenBootVolume())
320 UiMessageBox("Failed to open boot drive.");
324 /* FIXME: check volume label or disk marker file */
328 /* Get ANSI codepage file */
329 if (!InfFindFirstLine (InfHandle
,
334 printf("Failed to find 'NLS/AnsiCodepage'\n");
338 if (!InfGetDataField (&InfContext
,
342 printf("Failed to get load options\n");
346 /* Load ANSI codepage file */
347 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
349 UiMessageBox("Failed to load the ANSI codepage file.");
353 /* Get OEM codepage file */
354 if (!InfFindFirstLine (InfHandle
,
359 printf("Failed to find 'NLS/AnsiCodepage'\n");
363 if (!InfGetDataField (&InfContext
,
367 printf("Failed to get load options\n");
371 /* Load OEM codepage file */
372 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
374 UiMessageBox("Failed to load the OEM codepage file.");
378 /* Get Unicode Casemap file */
379 if (!InfFindFirstLine (InfHandle
,
384 printf("Failed to find 'NLS/AnsiCodepage'\n");
388 if (!InfGetDataField (&InfContext
,
392 printf("Failed to get load options\n");
396 /* Load Unicode casemap file */
397 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
399 UiMessageBox("Failed to load the Unicode casemap file.");
403 /* Load vfatfs.sys (could be loaded by the setup prog!) */
404 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
407 /* Load additional files specified in txtsetup.inf */
408 if (InfFindFirstLine(InfHandle
,
415 LPCSTR Media
, DriverName
;
416 if (InfGetDataField(&InfContext
, 7, &Media
) &&
417 InfGetDataField(&InfContext
, 0, &DriverName
))
419 if (strcmp(Media
, "x") == 0)
421 if (!LoadDriver(SourcePath
, DriverName
))
425 } while (InfFindNextLine(&InfContext
, &InfContext
));
428 UiUnInitialize("Booting ReactOS...");
430 /* Now boot the kernel */
431 DiskStopFloppyMotor();
432 MachVideoPrepareForReactOS(TRUE
);
433 FrLdrStartup(0x2badb002);