3 * Copyright (C) 1998-2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /* INCLUDES *******************************************************************/
25 DBG_DEFAULT_CHANNEL(INIFILE
);
27 /* GLOBALS ********************************************************************/
31 (*EDIT_OS_ENTRY_PROC
)(
32 IN ULONG_PTR SectionId OPTIONAL
);
35 EditCustomBootReactOSSetup(
36 IN ULONG_PTR SectionId OPTIONAL
)
38 EditCustomBootReactOS(SectionId
, TRUE
);
43 IN ULONG_PTR SectionId OPTIONAL
)
45 EditCustomBootReactOS(SectionId
, FALSE
);
51 EDIT_OS_ENTRY_PROC EditOsEntry
;
52 ARC_ENTRY_POINT OsLoader
;
53 } OSLoadingMethods
[] =
55 {"ReactOSSetup", EditCustomBootReactOSSetup
, LoadReactOSSetup
},
58 {"Drive" , EditCustomBootDisk
, LoadAndBootDrive
},
59 {"Partition" , EditCustomBootPartition
, LoadAndBootPartition
},
60 {"BootSector" , EditCustomBootSectorFile
, LoadAndBootBootSector
},
62 {"Linux" , EditCustomBootLinux
, LoadAndBootLinux
},
63 {"WindowsNT40" , EditCustomBootNTOS
, LoadAndBootWindows
},
65 {"Windows" , EditCustomBootNTOS
, LoadAndBootWindows
},
66 {"Windows2003" , EditCustomBootNTOS
, LoadAndBootWindows
},
69 /* FUNCTIONS ******************************************************************/
73 IN PCSTR LoadIdentifier
,
74 IN ULONG_PTR SectionId
,
83 PCHAR SettingName
, SettingValue
;
86 * Convert the list of key=value options in the given operating system section
87 * into a ARC-compatible argument vector.
92 /* Validate the LoadIdentifier (to make tests simpler later) */
93 if (LoadIdentifier
&& !*LoadIdentifier
)
94 LoadIdentifier
= NULL
;
96 /* Count the number of operating systems in the section */
97 Count
= IniGetNumSectionItems(SectionId
);
99 /* The argument vector contains the program name, the LoadIdentifier (optional), and the items in the OS section */
104 /* Calculate the total size needed for the string buffer of the argument vector */
106 /* i == 0: Program name */
107 /* i == 1: LoadIdentifier */
110 Size
+= (strlen("LoadIdentifier=") + strlen(LoadIdentifier
) + 1) * sizeof(CHAR
);
112 for (i
= 0; i
< Count
; ++i
)
114 Size
+= IniGetSectionSettingNameSize(SectionId
, i
); // Counts also the NULL-terminator, that we transform into the '=' sign separator.
115 Size
+= IniGetSectionSettingValueSize(SectionId
, i
); // Counts also the NULL-terminator.
117 Size
+= sizeof(ANSI_NULL
); // Final NULL-terminator.
119 /* Allocate memory to hold the argument vector: pointers and string buffer */
120 Argv
= FrLdrHeapAlloc(Argc
* sizeof(PCHAR
) + Size
, TAG_STRING
);
124 /* Initialize the argument vector: loop through the section and copy the key=value options */
125 SettingName
= (PCHAR
)((ULONG_PTR
)Argv
+ (Argc
* sizeof(PCHAR
)));
127 /* i == 0: Program name */
129 /* i == 1: LoadIdentifier */
132 strcpy(SettingName
, "LoadIdentifier=");
133 strcat(SettingName
, LoadIdentifier
);
135 *Args
++ = SettingName
;
136 SettingName
+= (strlen(SettingName
) + 1);
138 for (i
= 0; i
< Count
; ++i
)
140 Size
= IniGetSectionSettingNameSize(SectionId
, i
);
141 SettingValue
= SettingName
+ Size
;
142 IniReadSettingByNumber(SectionId
, i
,
144 SettingValue
, IniGetSectionSettingValueSize(SectionId
, i
));
145 SettingName
[Size
- 1] = '=';
147 *Args
++ = SettingName
;
148 SettingName
+= (strlen(SettingName
) + 1);
152 /* Dump the argument vector for debugging */
153 for (i
= 0; i
< Argc
; ++i
)
155 TRACE("Argv[%lu]: '%s'\n", i
, Argv
[i
]);
163 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
166 PCSTR SectionName
= OperatingSystem
->SectionName
;
172 /* Try to open the operating system section in the .ini file */
173 if (!IniOpenSection(SectionName
, &SectionId
))
175 UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName
);
179 /* Try to read the boot type */
180 *BootType
= ANSI_NULL
;
181 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
183 /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
187 /* Install the drive mapper according to this section drive mappings */
188 DriveMapMapDrivesInSection(SectionName
);
191 /* Loop through the OS loading method table and find a suitable OS to boot */
192 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
194 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
196 Argv
= BuildArgvForOsLoader(OperatingSystem
->LoadIdentifier
, SectionId
, &Argc
);
199 OSLoadingMethods
[i
].OsLoader(Argc
, Argv
, NULL
);
200 FrLdrHeapFree(Argv
, TAG_STRING
);
207 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
209 VOID
EditOperatingSystemEntry(IN OperatingSystemItem
* OperatingSystem
)
212 PCSTR SectionName
= OperatingSystem
->SectionName
;
216 /* Try to open the operating system section in the .ini file */
217 if (!IniOpenSection(SectionName
, &SectionId
))
219 UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName
);
223 /* Try to read the boot type */
224 *BootType
= ANSI_NULL
;
225 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
227 /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
230 /* Loop through the OS loading method table and find a suitable OS entry editor */
231 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
233 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
235 OSLoadingMethods
[i
].EditOsEntry(SectionId
);
241 #endif // HAS_OPTION_MENU_EDIT_CMDLINE
243 LONG
GetTimeOut(VOID
)
245 CHAR TimeOutText
[20];
249 TimeOut
= CmdLineGetTimeOut();
253 if (!IniOpenSection("FreeLoader", &SectionId
))
256 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
257 TimeOut
= atoi(TimeOutText
);
265 MainBootMenuKeyPressFilter(
267 IN ULONG SelectedMenuItem
,
268 IN PVOID Context OPTIONAL
)
273 DoOptionsMenu(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
276 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
278 EditOperatingSystemEntry(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
283 /* We didn't handle the key */
292 ULONG OperatingSystemCount
;
293 OperatingSystemItem
* OperatingSystemList
;
294 PCSTR
* OperatingSystemDisplayNames
;
295 ULONG DefaultOperatingSystem
;
296 ULONG SelectedOperatingSystem
;
299 if (!MachInitializeBootDevices())
301 UiMessageBoxCritical("Error when detecting hardware.");
306 /* Load additional SCSI driver (if any) */
307 if (LoadBootDeviceDriver() != ESUCCESS
)
309 UiMessageBoxCritical("Unable to load additional boot device drivers.");
313 if (!IniFileInitialize())
315 UiMessageBoxCritical("Error initializing .ini file.");
319 /* Debugger main initialization */
322 if (!IniOpenSection("FreeLoader", &SectionId
))
324 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
328 TimeOut
= GetTimeOut();
330 /* UI main initialization */
331 if (!UiInitialize(TRUE
))
333 UiMessageBoxCritical("Unable to initialize UI.");
337 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
,
338 &DefaultOperatingSystem
);
339 if (!OperatingSystemList
)
341 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
344 if (OperatingSystemCount
== 0)
346 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
350 /* Create list of display names */
351 OperatingSystemDisplayNames
= FrLdrTempAlloc(sizeof(PCSTR
) * OperatingSystemCount
, 'mNSO');
352 if (!OperatingSystemDisplayNames
)
355 for (i
= 0; i
< OperatingSystemCount
; i
++)
357 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
360 /* Find all the message box settings and run them */
361 UiShowMessageBoxesInSection("FreeLoader");
365 /* Redraw the backdrop */
368 /* Show the operating system list menu */
369 if (!UiDisplayMenu("Please select the operating system to start:",
370 "For troubleshooting and advanced startup options for "
371 "ReactOS, press F8.",
373 OperatingSystemDisplayNames
,
374 OperatingSystemCount
,
375 DefaultOperatingSystem
,
377 &SelectedOperatingSystem
,
379 MainBootMenuKeyPressFilter
,
380 OperatingSystemList
))
382 UiMessageBox("Press ENTER to reboot.");
388 /* Load the chosen operating system */
389 LoadOperatingSystem(&OperatingSystemList
[SelectedOperatingSystem
]);
393 UiUnInitialize("Rebooting...");