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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 extern ULONG PageDirectoryStart
;
26 extern ULONG PageDirectoryEnd
;
28 extern CHAR szBootPath
[255];
29 extern CHAR SystemRoot
[255];
30 extern CHAR szHalName
[255];
32 extern char reactos_arc_hardware_data
[HW_MAX_ARC_HEAP_SIZE
];
33 extern ULONG_PTR KernelBase
;
34 extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint
;
36 extern BOOLEAN
FrLdrLoadDriver(PCHAR szFileName
, INT nPos
);
37 extern BOOLEAN
FrLdrLoadNlsFile(PCSTR szFileName
, PCSTR szModuleName
);
41 VOID
LoadReactOSSetup(VOID
)
45 LPCSTR LoadOptions
, DbgLoadOptions
= "";
46 BOOLEAN BootFromFloppy
;
47 LPCSTR sourcePaths
[] = {
48 "", /* Only for floppy boot */
51 #elif defined(_M_MPPC)
53 #elif defined(_M_MRX000)
62 INFCONTEXT InfContext
;
63 PIMAGE_NT_HEADERS NtHeader
;
65 extern BOOLEAN FrLdrBootType
;
67 /* Setup multiboot information structure */
68 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
69 LoaderBlock
.PageDirectoryStart
= (ULONG_PTR
)&PageDirectoryStart
;
70 LoaderBlock
.PageDirectoryEnd
= (ULONG_PTR
)&PageDirectoryEnd
;
71 LoaderBlock
.ModsCount
= 0;
72 LoaderBlock
.ModsAddr
= reactos_modules
;
73 LoaderBlock
.MmapLength
= (unsigned long)MachVtbl
.GetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
74 if (LoaderBlock
.MmapLength
)
76 #if defined (_M_IX86) || defined (_M_AMD64)
79 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
80 LoaderBlock
.MmapAddr
= (ULONG_PTR
)&reactos_memory_map
;
81 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
82 #if defined (_M_IX86) || defined (_M_AMD64)
83 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
85 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
86 0 == reactos_memory_map
[i
].base_addr_low
)
88 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
89 if (640 < LoaderBlock
.MemLower
)
91 LoaderBlock
.MemLower
= 640;
94 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
95 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
96 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
98 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
107 UiDrawStatusText("");
109 FrLdrBootType
= TRUE
;
111 /* Detect hardware */
112 UiDrawStatusText("Detecting hardware...");
113 LoaderBlock
.ArchExtra
= (ULONG_PTR
)MachHwDetect();
114 UiDrawStatusText("");
116 /* Check if we booted from floppy */
117 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
118 BootFromFloppy
= strstr(reactos_kernel_cmdline
, "fdisk") != NULL
;
120 UiDrawStatusText("Loading txtsetup.sif...");
121 /* Open 'txtsetup.sif' */
122 for (i
= BootFromFloppy
? 0 : 1; ; i
++)
124 SourcePath
= sourcePaths
[i
];
127 printf("Failed to open 'txtsetup.sif'\n");
130 sprintf(FileName
,"%s\\txtsetup.sif", SourcePath
);
131 if (InfOpenFile (&InfHandle
, FileName
, &ErrorLine
))
138 /* Get load options */
139 if (InfFindFirstLine (InfHandle
,
144 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
148 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
153 printf("Failed to find 'SetupData/OsLoadOptions'\n");
157 if (!InfGetDataField (&InfContext
,
161 printf("Failed to get load options\n");
165 /* Set kernel command line */
166 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
167 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
168 LoadOptions
), DbgLoadOptions
);
170 /* Setup the boot path and kernel path */
171 strcpy(szBootPath
, SourcePath
);
173 sprintf(SystemRoot
,"%s\\", SourcePath
);
174 sprintf(FileName
,"%s\\ntoskrnl.exe", SourcePath
);
175 sprintf(szHalName
,"%s\\hal.dll", SourcePath
);
177 /* Load the kernel */
178 LoadBase
= FrLdrLoadImage(FileName
, 5, 1);
181 DPRINT1("Loading the kernel failed!\n");
185 /* Get the NT header, kernel base and kernel entry */
186 NtHeader
= RtlImageNtHeader(LoadBase
);
187 KernelBase
= SWAPD(NtHeader
->OptionalHeader
.ImageBase
);
188 KernelEntryPoint
= (ROS_KERNEL_ENTRY_POINT
)(KernelBase
+ SWAPD(NtHeader
->OptionalHeader
.AddressOfEntryPoint
));
189 LoaderBlock
.KernelBase
= KernelBase
;
191 /* Insert boot disk 2 */
194 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
196 /* FIXME: check volume label or disk marker file */
200 /* Get ANSI codepage file */
201 if (!InfFindFirstLine (InfHandle
,
206 printf("Failed to find 'NLS/AnsiCodepage'\n");
210 if (!InfGetDataField (&InfContext
,
214 printf("Failed to get load options\n");
218 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
219 /* Load ANSI codepage file */
220 if (!FrLdrLoadNlsFile(FileName
, "ansi.nls"))
222 UiMessageBox("Failed to load the ANSI codepage file.");
226 /* Get OEM codepage file */
227 if (!InfFindFirstLine (InfHandle
,
232 printf("Failed to find 'NLS/AnsiCodepage'\n");
236 if (!InfGetDataField (&InfContext
,
240 printf("Failed to get load options\n");
244 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
245 /* Load OEM codepage file */
246 if (!FrLdrLoadNlsFile(FileName
, "oem.nls"))
248 UiMessageBox("Failed to load the OEM codepage file.");
252 /* Get Unicode Casemap file */
253 if (!InfFindFirstLine (InfHandle
,
258 printf("Failed to find 'NLS/AnsiCodepage'\n");
262 if (!InfGetDataField (&InfContext
,
266 printf("Failed to get load options\n");
270 sprintf(FileName
,"%s\\%s", SourcePath
,LoadOptions
);
271 /* Load Unicode casemap file */
272 if (!FrLdrLoadNlsFile(FileName
, "casemap.nls"))
274 UiMessageBox("Failed to load the Unicode casemap file.");
278 /* Load additional files specified in txtsetup.inf */
279 if (InfFindFirstLine(InfHandle
,
286 LPCSTR Media
, DriverName
;
287 if (InfGetDataField(&InfContext
, 7, &Media
) &&
288 InfGetDataField(&InfContext
, 0, &DriverName
))
290 if (strcmp(Media
, "x") == 0)
292 if (!FrLdrLoadDriver((PCHAR
)DriverName
,0))
294 DPRINTM(DPRINT_WARNING
, "could not load %s, %s\n", SourcePath
, DriverName
);
299 } while (InfFindNextLine(&InfContext
, &InfContext
));
302 UiUnInitialize("Booting ReactOS...");
305 // Perform architecture-specific pre-boot configuration
307 MachPrepareForReactOS(TRUE
);
310 // Setup paging and jump to kernel
312 FrLdrStartup(0x2badb002);