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
;
33 extern char reactos_arc_hardware_data
[HW_MAX_ARC_HEAP_SIZE
];
37 extern ULONG_PTR KernelBase
;
38 extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint
;
40 extern BOOLEAN
FrLdrLoadDriver(PCHAR szFileName
, INT nPos
);
46 static FrLdrLoadKernel(IN PCHAR szFileName
,
53 PIMAGE_NT_HEADERS NtHeader
;
55 /* Extract Kernel filename without path */
56 szShortName
= strrchr(szFileName
, '\\');
59 /* No path, leave it alone */
60 szShortName
= szFileName
;
65 szShortName
= szShortName
+ 1;
69 FilePointer
= FsOpenFile(szFileName
);
72 /* Return failure on the short name */
73 strcpy(szBuffer
, szShortName
);
74 strcat(szBuffer
, " not found.");
75 UiMessageBox(szBuffer
);
79 /* Update the status bar with the current file */
80 strcpy(szBuffer
, "Reading ");
81 strcat(szBuffer
, szShortName
);
82 UiDrawStatusText(szBuffer
);
84 /* Do the actual loading */
85 LoadBase
= FrLdrReadAndMapImage(FilePointer
, szShortName
, 1);
87 /* Get the NT header, kernel base and kernel entry */
88 NtHeader
= RtlImageNtHeader(LoadBase
);
89 KernelBase
= NtHeader
->OptionalHeader
.ImageBase
;
90 KernelEntryPoint
= (ROS_KERNEL_ENTRY_POINT
)(KernelBase
+ NtHeader
->OptionalHeader
.AddressOfEntryPoint
);
91 LoaderBlock
.KernelBase
= KernelBase
;
93 /* Update Processbar and return success */
98 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
100 return FrLdrLoadDriver((PCHAR
)szFileName
, 0);
105 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
107 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
153 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
154 UiDrawStatusText(szBuffer
);
156 /* Load the driver */
157 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
165 const char *SourcePath
;
166 const char *LoadOptions
= "", *DbgLoadOptions
= "";
167 const char *sourcePaths
[] = {
168 "", /* Only for floppy boot */
171 #elif defined(_M_MPPC)
173 #elif defined(_M_MRX000)
178 char szKernelName
[256];
182 INFCONTEXT InfContext
;
184 /* Setup multiboot information structure */
185 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
186 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
187 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
188 LoaderBlock
.ModsCount
= 0;
189 LoaderBlock
.ModsAddr
= reactos_modules
;
190 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
191 if (LoaderBlock
.MmapLength
)
196 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
197 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
198 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
200 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
202 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
203 0 == reactos_memory_map
[i
].base_addr_low
)
205 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
206 if (640 < LoaderBlock
.MemLower
)
208 LoaderBlock
.MemLower
= 640;
211 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
212 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
213 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
215 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
224 UiDrawStatusText("");
226 extern BOOLEAN FrLdrBootType
;
227 FrLdrBootType
= TRUE
;
229 /* Initialize registry */
230 RegInitializeRegistry();
232 /* Detect hardware */
233 UiDrawStatusText("Detecting hardware...");
234 LoaderBlock
.ArchExtra
= (ULONG
)MachHwDetect();
235 UiDrawStatusText("");
237 /* set boot device */
238 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
240 /* Open boot drive */
241 if (!FsOpenBootVolume())
243 UiMessageBox("Failed to open boot drive.");
247 /* Open 'txtsetup.sif' */
248 for (i
= MachDiskBootingFromFloppy() ? 0 : 1; ; i
++)
250 SourcePath
= sourcePaths
[i
];
253 printf("Failed to open 'txtsetup.sif'\n");
256 strcpy(szKernelName
, SourcePath
);
257 strcat(szKernelName
, "\\txtsetup.sif");
258 if (InfOpenFile (&InfHandle
, szKernelName
, &ErrorLine
))
265 /* Get load options */
266 if (InfFindFirstLine (InfHandle
,
271 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
275 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
280 printf("Failed to find 'SetupData/OsLoadOptions'\n");
284 if (!InfGetDataField (&InfContext
,
288 printf("Failed to get load options\n");
292 /* Set kernel command line */
293 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
294 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
295 LoadOptions
), DbgLoadOptions
);
297 strcpy(SystemRoot
, SourcePath
);
298 strcat(SystemRoot
, "\\");
300 /* Setup the boot path and kernel path */
301 strcpy(szBootPath
, SourcePath
);
302 strcpy(szKernelName
, szBootPath
);
303 strcat(szKernelName
, "\\ntoskrnl.exe");
305 /* Setup the HAL path */
306 strcpy(szHalName
, szBootPath
);
307 strcat(szHalName
, "\\hal.dll");
309 /* Load the kernel */
310 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
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 fastfat.sys (could be loaded by the setup prog!) */
404 if (!LoadDriver(SourcePath
, "fastfat.sys"))
407 /* Load ext2.sys (could be loaded by the setup prog!) */
408 if (!LoadDriver(SourcePath
, "ext2.sys"))
411 /* Load additional files specified in txtsetup.inf */
412 if (InfFindFirstLine(InfHandle
,
419 LPCSTR Media
, DriverName
;
420 if (InfGetDataField(&InfContext
, 7, &Media
) &&
421 InfGetDataField(&InfContext
, 0, &DriverName
))
423 if (strcmp(Media
, "x") == 0)
425 if (!LoadDriver(SourcePath
, DriverName
))
429 } while (InfFindNextLine(&InfContext
, &InfContext
));
432 UiUnInitialize("Booting ReactOS...");
435 // Perform architecture-specific pre-boot configuration
437 MachPrepareForReactOS(TRUE
);
440 // Setup paging and jump to kernel
442 FrLdrStartup(0x2badb002);