[EXT2] Upgrade to 0.69
[reactos.git] / boot / freeldr / freeldr / options.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 /* INCLUDES *******************************************************************/
21
22 #include <freeldr.h>
23 #include <debug.h>
24
25 /* GLOBALS ********************************************************************/
26
27 PCSTR OptionsMenuList[] =
28 {
29 "Safe Mode",
30 "Safe Mode with Networking",
31 "Safe Mode with Command Prompt",
32
33 NULL,
34
35 "Enable Boot Logging",
36 "Enable VGA Mode",
37 "Last Known Good Configuration",
38 "Directory Services Restore Mode",
39 "Debugging Mode",
40 "FreeLdr debugging",
41
42 NULL,
43
44 "Start ReactOS normally",
45 #ifdef HAS_OPTION_MENU_CUSTOM_BOOT
46 "Custom Boot",
47 #endif
48 #ifdef HAS_OPTION_MENU_REBOOT
49 "Reboot",
50 #endif
51 };
52
53 PCSTR FrldrDbgMsg = "Enable FreeLdr debug channels\n"
54 "Acceptable syntax: [level1]#channel1[,[level2]#channel2]\n"
55 "level can be one of: trace,warn,fixme,err\n"
56 " if the level is omitted all levels\n"
57 " are enabled for the specified channel\n"
58 "# can be either + or -\n"
59 "channel can be one of the following:\n"
60 " all,warning,memory,filesystem,inifile,ui,disk,cache,registry,\n"
61 " reactos,linux,hwdetect,windows,peloader,scsiport,heap\n"
62 "Examples:\n"
63 " trace+windows,trace+reactos\n"
64 " +hwdetect,err-disk\n"
65 " +peloader\n"
66 "NOTE: all letters must be lowercase, no spaces allowed.";
67
68 /* The boot options are mutually exclusive */
69 enum BootOption
70 {
71 NO_OPTION = 0,
72
73 SAFE_MODE,
74 SAFE_MODE_WITH_NETWORKING,
75 SAFE_MODE_WITH_COMMAND_PROMPT,
76
77 LAST_KNOWN_GOOD_CONFIGURATION,
78 DIRECTORY_SERVICES_RESTORE_MODE,
79 };
80
81 ULONG OptionsMenuItemCount = sizeof(OptionsMenuList) / sizeof(OptionsMenuList[0]);
82
83 static enum BootOption BootOptionChoice = NO_OPTION;
84 static BOOLEAN BootLogging = FALSE;
85 static BOOLEAN VgaMode = FALSE;
86 static BOOLEAN DebuggingMode = FALSE;
87
88 /* FUNCTIONS ******************************************************************/
89
90 VOID DoOptionsMenu(VOID)
91 {
92 ULONG SelectedMenuItem;
93 CHAR DebugChannelString[100];
94
95 if (!UiDisplayMenu("Select an option:", "",
96 TRUE,
97 OptionsMenuList,
98 OptionsMenuItemCount,
99 11, // Use "Start ReactOS normally" as default; see the switch below.
100 -1,
101 &SelectedMenuItem,
102 TRUE,
103 NULL))
104 {
105 /* The user pressed ESC */
106 return;
107 }
108
109 /* Clear the backdrop */
110 UiDrawBackdrop();
111
112 switch (SelectedMenuItem)
113 {
114 case 0: // Safe Mode
115 BootOptionChoice = SAFE_MODE;
116 BootLogging = TRUE;
117 break;
118 case 1: // Safe Mode with Networking
119 BootOptionChoice = SAFE_MODE_WITH_NETWORKING;
120 BootLogging = TRUE;
121 break;
122 case 2: // Safe Mode with Command Prompt
123 BootOptionChoice = SAFE_MODE_WITH_COMMAND_PROMPT;
124 BootLogging = TRUE;
125 break;
126 // case 3: // Separator
127 // break;
128 case 4: // Enable Boot Logging
129 BootLogging = TRUE;
130 break;
131 case 5: // Enable VGA Mode
132 VgaMode = TRUE;
133 break;
134 case 6: // Last Known Good Configuration
135 BootOptionChoice = LAST_KNOWN_GOOD_CONFIGURATION;
136 break;
137 case 7: // Directory Services Restore Mode
138 BootOptionChoice = DIRECTORY_SERVICES_RESTORE_MODE;
139 break;
140 case 8: // Debugging Mode
141 DebuggingMode = TRUE;
142 break;
143 case 9: // FreeLdr debugging
144 DebugChannelString[0] = 0;
145 if (UiEditBox(FrldrDbgMsg,
146 DebugChannelString,
147 sizeof(DebugChannelString) / sizeof(DebugChannelString[0])))
148 {
149 DbgParseDebugChannels(DebugChannelString);
150 }
151 break;
152 // case 10: // Separator
153 // break;
154 case 11: // Start ReactOS normally
155 // Reset all the parameters to their default values.
156 BootOptionChoice = NO_OPTION;
157 BootLogging = FALSE;
158 VgaMode = FALSE;
159 DebuggingMode = FALSE;
160 break;
161 #ifdef HAS_OPTION_MENU_CUSTOM_BOOT
162 case 12: // Custom Boot
163 OptionMenuCustomBoot();
164 break;
165 #endif
166 #ifdef HAS_OPTION_MENU_REBOOT
167 case 13: // Reboot
168 OptionMenuReboot();
169 break;
170 #endif
171 }
172 }
173
174 VOID DisplayBootTimeOptions(VOID)
175 {
176 CHAR BootOptions[260] = "";
177
178 switch (BootOptionChoice)
179 {
180 case SAFE_MODE:
181 strcat(BootOptions, OptionsMenuList[0]);
182 break;
183
184 case SAFE_MODE_WITH_NETWORKING:
185 strcat(BootOptions, OptionsMenuList[1]);
186 break;
187
188 case SAFE_MODE_WITH_COMMAND_PROMPT:
189 strcat(BootOptions, OptionsMenuList[2]);
190 break;
191
192 case LAST_KNOWN_GOOD_CONFIGURATION:
193 strcat(BootOptions, OptionsMenuList[6]);
194 break;
195
196 case DIRECTORY_SERVICES_RESTORE_MODE:
197 strcat(BootOptions, OptionsMenuList[7]);
198 break;
199
200 default:
201 break;
202 }
203
204 if (BootLogging)
205 {
206 if ( (BootOptionChoice != SAFE_MODE) &&
207 (BootOptionChoice != SAFE_MODE_WITH_NETWORKING) &&
208 (BootOptionChoice != SAFE_MODE_WITH_COMMAND_PROMPT) )
209 {
210 if (BootOptionChoice != NO_OPTION)
211 {
212 strcat(BootOptions, ", ");
213 }
214 strcat(BootOptions, OptionsMenuList[4]);
215 }
216 }
217
218 if (VgaMode)
219 {
220 if ((BootOptionChoice != NO_OPTION) ||
221 BootLogging)
222 {
223 strcat(BootOptions, ", ");
224 }
225 strcat(BootOptions, OptionsMenuList[5]);
226 }
227
228 if (DebuggingMode)
229 {
230 if ((BootOptionChoice != NO_OPTION) ||
231 BootLogging || VgaMode)
232 {
233 strcat(BootOptions, ", ");
234 }
235 strcat(BootOptions, OptionsMenuList[8]);
236 }
237
238 /* Display the chosen boot options */
239 UiDrawText(0,
240 UiScreenHeight - 2,
241 BootOptions,
242 ATTR(COLOR_LIGHTBLUE, UiMenuBgColor));
243 }
244
245 VOID AppendBootTimeOptions(PCHAR BootOptions)
246 {
247 switch (BootOptionChoice)
248 {
249 case SAFE_MODE:
250 strcat(BootOptions, " /SAFEBOOT:MINIMAL /SOS"); // FIXME: NOGUIBOOT should also be specified
251 break;
252
253 case SAFE_MODE_WITH_NETWORKING:
254 strcat(BootOptions, " /SAFEBOOT:NETWORK /SOS"); // FIXME: NOGUIBOOT should also be specified
255 break;
256
257 case SAFE_MODE_WITH_COMMAND_PROMPT:
258 strcat(BootOptions, " /SAFEBOOT:MINIMAL(ALTERNATESHELL) /SOS"); // FIXME: NOGUIBOOT should also be specified
259 break;
260
261 case LAST_KNOWN_GOOD_CONFIGURATION:
262 DbgPrint("Last known good configuration is not supported yet!\n");
263 break;
264
265 case DIRECTORY_SERVICES_RESTORE_MODE:
266 strcat(BootOptions, " /SAFEBOOT:DSREPAIR /SOS");
267 break;
268
269 default:
270 break;
271 }
272
273 if (BootLogging)
274 strcat(BootOptions, " /BOOTLOG");
275
276 if (VgaMode)
277 strcat(BootOptions, " /BASEVIDEO");
278
279 if (DebuggingMode)
280 strcat(BootOptions, " /DEBUG");
281 }