Intialize the size for the bios memory map.
[reactos.git] / freeldr / freeldr / reactos / setupldr.c
1 /*
2 * FreeLoader
3 *
4 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21 #include <freeldr.h>
22 #include <debug.h>
23 #include <arch.h>
24 #include <disk.h>
25 #include <reactos.h>
26 #include <rtl.h>
27 #include <fs.h>
28 #include <multiboot.h>
29 #include <mm.h>
30
31 #include "registry.h"
32 #include "hwdetect.h"
33
34 BOOL IsSetupLdr = TRUE;
35
36 static BOOL
37 LoadKernel(PCHAR szFileName)
38 {
39 PFILE FilePointer;
40 PCHAR szShortName;
41
42 szShortName = strrchr(szFileName, '\\');
43 if (szShortName == NULL)
44 szShortName = szFileName;
45 else
46 szShortName = szShortName + 1;
47
48 FilePointer = FsOpenFile(szFileName);
49 if (FilePointer == NULL)
50 {
51 printf("Could not find %s\n", szShortName);
52 return(FALSE);
53 }
54
55 /*
56 * Update the status bar with the current file
57 */
58 printf("Reading %s\n", szShortName);
59
60 /*
61 * Load the kernel
62 */
63 MultiBootLoadKernel(FilePointer);
64
65 return(TRUE);
66 }
67
68
69 static BOOL
70 LoadDriver(PCHAR szFileName)
71 {
72 PFILE FilePointer;
73 PCHAR szShortName;
74
75 szShortName = strrchr(szFileName, '\\');
76 if (szShortName == NULL)
77 szShortName = szFileName;
78 else
79 szShortName = szShortName + 1;
80
81
82 FilePointer = FsOpenFile(szFileName);
83 if (FilePointer == NULL)
84 {
85 printf("Could not find %s\n", szFileName);
86 return(FALSE);
87 }
88
89 /*
90 * Update the status bar with the current file
91 */
92 printf("Reading %s\n", szShortName);
93
94 /* Load the driver */
95 MultiBootLoadModule(FilePointer, szFileName, NULL);
96
97 return(TRUE);
98 }
99
100
101 VOID RunLoader(VOID)
102 {
103
104 /* Setup multiboot information structure */
105 mb_info.flags = MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_BOOT_DEVICE | MB_INFO_FLAG_COMMAND_LINE | MB_INFO_FLAG_MODULES;
106 mb_info.mem_lower = GetConventionalMemorySize();
107 mb_info.mem_upper = GetExtendedMemorySize();
108 mb_info.boot_device = 0xffffffff;
109 mb_info.cmdline = (unsigned long)multiboot_kernel_cmdline;
110 mb_info.mods_count = 0;
111 mb_info.mods_addr = (unsigned long)multiboot_modules;
112 mb_info.mmap_length = (unsigned long)GetBiosMemoryMap((PBIOS_MEMORY_MAP)&multiboot_memory_map) * sizeof(memory_map_t);
113 if (mb_info.mmap_length)
114 {
115 mb_info.mmap_addr = (unsigned long)&multiboot_memory_map;
116 mb_info.flags |= MB_INFO_FLAG_MEMORY_MAP;
117 multiboot_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
118 #if 0
119 {
120 int i;
121 printf("memory map length: %d\n", mb_info.mmap_length);
122 printf("dumping memory map:\n");
123 for (i=0; i<(mb_info.mmap_length / sizeof(memory_map_t)); i++)
124 {
125 printf("start: %x\t size: %x\t type %d\n",
126 multiboot_memory_map[i].base_addr_low,
127 multiboot_memory_map[i].length_low,
128 multiboot_memory_map[i].type);
129 }
130 getch();
131 }
132 #endif
133 }
134 #if 0
135 printf("low_mem = %d\n", mb_info.mem_lower);
136 printf("high_mem = %d\n", mb_info.mem_upper);
137 getch();
138 #endif
139
140 /* Initialize registry */
141 RegInitializeRegistry();
142
143 /* Detect hardware */
144 printf("Detecting hardware...\n\n");
145 DetectHardware();
146
147 /* set boot drive and partition */
148 ((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
149 ((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
150
151 /* Copy ARC path into kernel command line */
152 sprintf(multiboot_kernel_cmdline,
153 "multi(0)disk(0)cdrom(%u)\\reactos /DEBUGPORT=COM1",
154 (unsigned int)BootDrive);
155
156 /* Open boot drive */
157 if (!FsOpenVolume(BootDrive, BootPartition))
158 {
159 printf("Failed to open boot drive.");
160 return;
161 }
162
163 /* Load ntoskrnl.exe */
164 if (!LoadKernel("\\reactos\\ntoskrnl.exe"))
165 return;
166
167
168 /* Load hal.dll */
169 if (!LoadDriver("\\reactos\\hal.dll"))
170 return;
171
172
173 /* Export the system and hardware hives */
174 // Base = MultiBootCreateModule(SYSTEM.HIV);
175 // RegExportHive("\\Registry\\Machine\\SYSTEM", Base, &Size);
176 // MultiBootCloseModule(Base, Size);
177
178 // Base = MultiBootCreateModule(HARDWARE.HIV);
179 // RegExportHive("\\Registry\\Machine\\HARDWARE", Base, &Size);
180 // MultiBootCloseModule(Base, Size);
181
182
183
184
185 /* Load NLS files */
186 #if 0
187 if (!LoadNlsFiles(szBootPath))
188 {
189 MessageBox("Failed to load NLS files\n");
190 return;
191 }
192 #endif
193
194
195 /*
196 * Load scsiport.sys
197 */
198 if (!LoadDriver("\\reactos\\scsiport.sys"))
199 return;
200
201 /*
202 * Load atapi.sys (depends on hardware detection)
203 */
204 if (!LoadDriver("\\reactos\\atapi.sys"))
205 return;
206
207 /*
208 * Load class2.sys
209 */
210 if (!LoadDriver("\\reactos\\class2.sys"))
211 return;
212
213 /*
214 * Load cdrom.sys
215 */
216 if (!LoadDriver("\\reactos\\cdrom.sys"))
217 return;
218
219 /*
220 * Load cdfs.sys
221 */
222 if (!LoadDriver("\\reactos\\cdfs.sys"))
223 return;
224
225 /*
226 * Load floppy.sys (only in case of a floppy disk setup!)
227 */
228 // if (!LoadDriver("\\reactos\\floppy.sys"))
229 // return;
230
231 /*
232 * Load disk.sys
233 */
234 if (!LoadDriver("\\reactos\\disk.sys"))
235 return;
236
237 /*
238 * Load vfatfs.sys (could be loaded by the setup prog!)
239 */
240 if (!LoadDriver("\\reactos\\vfatfs.sys"))
241 return;
242
243 /*
244 * Load keyboard driver
245 */
246 if (!LoadDriver("\\reactos\\keyboard.sys"))
247 return;
248
249 /*
250 * Load screen driver
251 */
252 if (!LoadDriver("\\reactos\\blue.sys"))
253 return;
254
255 /*
256 * Now boot the kernel
257 */
258 DiskStopFloppyMotor();
259 boot_reactos();
260
261
262 // printf("*** System stopped ***\n");
263 // for(;;);
264 }