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