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
);
41 extern BOOLEAN
FrLdrLoadNlsFile(PCSTR szFileName
, PCSTR szModuleName
);
45 VOID
LoadReactOSSetup(VOID
)
49 LPCSTR LoadOptions
, DbgLoadOptions
= "";
50 LPCSTR sourcePaths
[] = {
51 "", /* Only for floppy boot */
54 #elif defined(_M_MPPC)
56 #elif defined(_M_MRX000)
65 INFCONTEXT InfContext
;
66 PIMAGE_NT_HEADERS NtHeader
;
68 extern BOOLEAN FrLdrBootType
;
70 /* Setup multiboot information structure */
71 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
72 LoaderBlock
.PageDirectoryStart
= (ULONG_PTR
)&PageDirectoryStart
;
73 LoaderBlock
.PageDirectoryEnd
= (ULONG_PTR
)&PageDirectoryEnd
;
74 LoaderBlock
.ModsCount
= 0;
75 LoaderBlock
.ModsAddr
= reactos_modules
;
76 LoaderBlock
.MmapLength
= (unsigned long)MachVtbl
.GetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
77 if (LoaderBlock
.MmapLength
)
79 #if defined (_M_IX86) || defined (_M_AMD64)
82 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
83 LoaderBlock
.MmapAddr
= (ULONG_PTR
)&reactos_memory_map
;
84 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
85 #if defined (_M_IX86) || defined (_M_AMD64)
86 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
88 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
89 0 == reactos_memory_map
[i
].base_addr_low
)
91 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
92 if (640 < LoaderBlock
.MemLower
)
94 LoaderBlock
.MemLower
= 640;
97 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
98 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
99 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
101 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
110 UiDrawStatusText("");
112 FrLdrBootType
= TRUE
;
114 /* Detect hardware */
115 UiDrawStatusText("Detecting hardware...");
116 LoaderBlock
.ArchExtra
= (ULONG_PTR
)MachHwDetect();
117 UiDrawStatusText("");
119 /* set boot device */
120 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
122 /* Open boot drive */
123 if (!FsOpenBootVolume())
125 UiMessageBox("Failed to open boot drive.");
129 UiDrawStatusText("Loading txtsetup.sif...");
130 /* Open 'txtsetup.sif' */
131 for (i
= MachDiskBootingFromFloppy() ? 0 : 1; ; i
++)
133 SourcePath
= sourcePaths
[i
];
136 printf("Failed to open 'txtsetup.sif'\n");
139 sprintf(FileName
,"%s\\txtsetup.sif", SourcePath
);
140 if (InfOpenFile (&InfHandle
, FileName
, &ErrorLine
))
147 /* Get load options */
148 if (InfFindFirstLine (InfHandle
,
153 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
157 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
162 printf("Failed to find 'SetupData/OsLoadOptions'\n");
166 if (!InfGetDataField (&InfContext
,
170 printf("Failed to get load options\n");
174 /* Set kernel command line */
175 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
176 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
177 LoadOptions
), DbgLoadOptions
);
179 /* Setup the boot path and kernel path */
180 strcpy(szBootPath
, SourcePath
);
182 sprintf(SystemRoot
,"%s\\", SourcePath
);
183 sprintf(FileName
,"%s\\ntoskrnl.exe", SourcePath
);
184 sprintf(szHalName
,"%s\\hal.dll", SourcePath
);
186 /* Load the kernel */
187 LoadBase
= FrLdrLoadImage(FileName
, 5, 1);
190 DPRINT1("Loading the kernel failed!\n");
194 /* Get the NT header, kernel base and kernel entry */
195 NtHeader
= RtlImageNtHeader(LoadBase
);
196 KernelBase
= SWAPD(NtHeader
->OptionalHeader
.ImageBase
);
197 KernelEntryPoint
= (ROS_KERNEL_ENTRY_POINT
)(KernelBase
+ SWAPD(NtHeader
->OptionalHeader
.AddressOfEntryPoint
));
198 LoaderBlock
.KernelBase
= KernelBase
;
200 /* Insert boot disk 2 */
201 if (MachDiskBootingFromFloppy())
203 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
205 /* Open boot drive */
206 if (!FsOpenBootVolume())
208 UiMessageBox("Failed to open boot drive.");
212 /* FIXME: check volume label or disk marker file */
216 /* Get ANSI codepage file */
217 if (!InfFindFirstLine (InfHandle
,
222 printf("Failed to find 'NLS/AnsiCodepage'\n");
226 if (!InfGetDataField (&InfContext
,
230 printf("Failed to get load options\n");
234 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
235 /* Load ANSI codepage file */
236 if (!FrLdrLoadNlsFile(FileName
, "ansi.nls"))
238 UiMessageBox("Failed to load the ANSI codepage file.");
242 /* Get OEM codepage file */
243 if (!InfFindFirstLine (InfHandle
,
248 printf("Failed to find 'NLS/AnsiCodepage'\n");
252 if (!InfGetDataField (&InfContext
,
256 printf("Failed to get load options\n");
260 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
261 /* Load OEM codepage file */
262 if (!FrLdrLoadNlsFile(FileName
, "oem.nls"))
264 UiMessageBox("Failed to load the OEM codepage file.");
268 /* Get Unicode Casemap file */
269 if (!InfFindFirstLine (InfHandle
,
274 printf("Failed to find 'NLS/AnsiCodepage'\n");
278 if (!InfGetDataField (&InfContext
,
282 printf("Failed to get load options\n");
286 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
287 /* Load Unicode casemap file */
288 if (!FrLdrLoadNlsFile(FileName
, "casemap.nls"))
290 UiMessageBox("Failed to load the Unicode casemap file.");
294 /* Load additional files specified in txtsetup.inf */
295 if (InfFindFirstLine(InfHandle
,
302 LPCSTR Media
, DriverName
;
303 if (InfGetDataField(&InfContext
, 7, &Media
) &&
304 InfGetDataField(&InfContext
, 0, &DriverName
))
306 if (strcmp(Media
, "x") == 0)
308 if (!FrLdrLoadDriver((PCHAR
)DriverName
,0))
310 DPRINTM(DPRINT_WARNING
, "could not load %s, %s\n", SourcePath
, DriverName
);
315 } while (InfFindNextLine(&InfContext
, &InfContext
));
318 UiUnInitialize("Booting ReactOS...");
321 // Perform architecture-specific pre-boot configuration
323 MachPrepareForReactOS(TRUE
);
326 // Setup paging and jump to kernel
328 FrLdrStartup(0x2badb002);