3 * Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "multiboot.h"
32 BOOL
LoadReactOSKernel(PUCHAR OperatingSystemName
);
33 BOOL
LoadReactOSDrivers(PUCHAR OperatingSystemName
);
35 void LoadAndBootReactOS(PUCHAR OperatingSystemName
)
40 char szFileName
[1024];
43 int nNumDriverFiles
=0;
44 int nNumFilesLoaded
=0;
49 // Open the operating system section
50 // specified in the .ini file
52 if (!OpenSection(OperatingSystemName
, &SectionId
))
54 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
55 MessageBox(MsgBuffer
);
60 * Setup multiboot information structure
62 mb_info
.flags
= MB_INFO_FLAG_MEM_SIZE
| MB_INFO_FLAG_BOOT_DEVICE
| MB_INFO_FLAG_COMMAND_LINE
| MB_INFO_FLAG_MODULES
;
63 mb_info
.mem_lower
= GetConventionalMemorySize();
64 mb_info
.mem_upper
= GetExtendedMemorySize();
65 mb_info
.boot_device
= 0xffffffff;
66 mb_info
.cmdline
= (unsigned long)multiboot_kernel_cmdline
;
67 mb_info
.mods_count
= 0;
68 mb_info
.mods_addr
= (unsigned long)multiboot_modules
;
69 mb_info
.mmap_length
= GetBiosMemoryMap(&multiboot_memory_map
);
70 if (mb_info
.mmap_length
)
72 mb_info
.mmap_addr
= (unsigned long)&multiboot_memory_map
;
73 mb_info
.flags
|= MB_INFO_FLAG_MEMORY_MAP
;
74 //printf("memory map length: %d\n", mb_info.mmap_length);
75 //printf("dumping memory map:\n");
76 //for (i=0; i<(mb_info.mmap_length / 4); i++)
78 // printf("0x%x\n", ((unsigned long *)&multiboot_memory_map)[i]);
82 //printf("low_mem = %d\n", mb_info.mem_lower);
83 //printf("high_mem = %d\n", mb_info.mem_upper);
86 * Make sure the system path is set in the .ini file
88 if (!ReadSectionSettingByName(SectionId
, "SystemPath", value
, 1024))
90 MessageBox("System path not specified for selected operating system.");
97 if (!DissectArcPath(value
, szBootPath
, &BootDrive
, &BootPartition
))
99 sprintf(MsgBuffer
,"Invalid system path: '%s'", value
);
100 MessageBox(MsgBuffer
);
104 /* set boot drive and partition */
105 ((char *)(&mb_info
.boot_device
))[0] = (char)BootDrive
;
106 ((char *)(&mb_info
.boot_device
))[1] = (char)BootPartition
;
108 /* copy ARC path into kernel command line */
109 strcpy(multiboot_kernel_cmdline
, value
);
112 * Read the optional kernel parameters (if any)
114 if (ReadSectionSettingByName(SectionId
, "Options", value
, 1024))
116 strcat(multiboot_kernel_cmdline
, " ");
117 strcat(multiboot_kernel_cmdline
, value
);
120 /* append a backslash */
121 if ((strlen(szBootPath
)==0) ||
122 szBootPath
[strlen(szBootPath
)] != '\\')
123 strcat(szBootPath
, "\\");
126 * Find the kernel image name
128 if(!ReadSectionSettingByName(SectionId
, "Kernel", value
, 1024))
130 MessageBox("Kernel image file not specified for selected operating system.");
136 DrawStatusText(" Loading...");
140 * Try to open boot drive
142 if (!OpenDiskDrive(BootDrive
, BootPartition
))
144 MessageBox("Failed to open boot drive.");
149 * Parse the ini file and count the kernel and drivers
151 for (i
=1; i
<=GetNumSectionItems(SectionId
); i
++)
154 * Read the setting and check if it's a driver
156 ReadSectionSettingByNumber(SectionId
, i
, name
, 1024, value
, 1024);
157 if ((stricmp(name
, "Kernel") == 0) || (stricmp(name
, "Driver") == 0))
162 * Find the kernel image name
163 * and try to load the kernel off the disk
165 if(ReadSectionSettingByName(SectionId
, "Kernel", value
, 1024))
168 * Set the name and try to open the PE image
170 //strcpy(szFileName, szBootPath);
171 //strcat(szFileName, value);
172 strcpy(szFileName
, value
);
174 FilePointer
= OpenFile(szFileName
);
175 if (FilePointer
== NULL
)
177 strcat(value
, " not found.");
183 * Update the status bar with the current file
185 strcpy(name
, " Reading ");
187 while (strlen(name
) < 80)
189 DrawStatusText(name
);
192 * Load the kernel image
194 MultiBootLoadKernel(FilePointer
);
197 DrawProgressBar((nNumFilesLoaded
* 100) / nNumDriverFiles
);
201 * Parse the ini file and load the kernel and
202 * load all the drivers specified
204 for (i
=1; i
<=GetNumSectionItems(SectionId
); i
++)
207 * Read the setting and check if it's a driver
209 ReadSectionSettingByNumber(SectionId
, i
, name
, 1024, value
, 1024);
210 if (stricmp(name
, "Driver") == 0)
213 * Set the name and try to open the PE image
215 //strcpy(szFileName, szBootPath);
216 //strcat(szFileName, value);
217 strcpy(szFileName
, value
);
219 FilePointer
= OpenFile(szFileName
);
220 if (FilePointer
== NULL
)
222 strcat(value
, " not found.");
228 * Update the status bar with the current file
230 strcpy(name
, " Reading ");
232 while (strlen(name
) < 80)
234 DrawStatusText(name
);
239 MultiBootLoadModule(FilePointer
, szFileName
);
243 DrawProgressBar((nNumFilesLoaded
* 100) / nNumDriverFiles
);
245 else if (stricmp(name
, "MessageBox") == 0)
247 DrawStatusText(" Press ENTER to continue");
250 else if (stricmp(name
, "MessageLine") == 0)
252 else if (stricmp(name
, "ReOpenBootDrive") == 0)
254 if (!OpenDiskDrive(BootDrive
, BootPartition
))
256 MessageBox("Failed to open boot drive.");
263 * Clear the screen and redraw the backdrop and status bar
266 DrawStatusText(" Press any key to boot");
271 strcpy(name
, "Kernel and Drivers loaded.\nPress any key to boot ");
272 strcat(name
, OperatingSystemName
);
276 RestoreScreen(ScreenBuffer
);
279 * Now boot the kernel