[FREELDR]
[reactos.git] / reactos / 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 ommited 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 0, -1,
100 &SelectedMenuItem,
101 TRUE,
102 NULL))
103 {
104 /* The user pressed ESC */
105 return;
106 }
107
108 /* Clear the backdrop */
109 UiDrawBackdrop();
110
111 switch (SelectedMenuItem)
112 {
113 case 0: // Safe Mode
114 BootOptionChoice = SAFE_MODE;
115 BootLogging = TRUE;
116 break;
117 case 1: // Safe Mode with Networking
118 BootOptionChoice = SAFE_MODE_WITH_NETWORKING;
119 BootLogging = TRUE;
120 break;
121 case 2: // Safe Mode with Command Prompt
122 BootOptionChoice = SAFE_MODE_WITH_COMMAND_PROMPT;
123 BootLogging = TRUE;
124 break;
125 // case 3: // Separator
126 // break;
127 case 4: // Enable Boot Logging
128 BootLogging = TRUE;
129 break;
130 case 5: // Enable VGA Mode
131 VgaMode = TRUE;
132 break;
133 case 6: // Last Known Good Configuration
134 BootOptionChoice = LAST_KNOWN_GOOD_CONFIGURATION;
135 break;
136 case 7: // Directory Services Restore Mode
137 BootOptionChoice = DIRECTORY_SERVICES_RESTORE_MODE;
138 break;
139 case 8: // Debugging Mode
140 DebuggingMode = TRUE;
141 break;
142 case 9: // FreeLdr debugging
143 DebugChannelString[0] = 0;
144 if (UiEditBox(FrldrDbgMsg,
145 DebugChannelString,
146 sizeof(DebugChannelString) / sizeof(DebugChannelString[0])))
147 {
148 DbgParseDebugChannels(DebugChannelString);
149 }
150 break;
151 // case 10: // Separator
152 // break;
153 case 11: // Start ReactOS normally
154 // Reset all the parameters to their default values.
155 BootOptionChoice = NO_OPTION;
156 BootLogging = FALSE;
157 VgaMode = FALSE;
158 DebuggingMode = FALSE;
159 break;
160 #ifdef HAS_OPTION_MENU_CUSTOM_BOOT
161 case 12: // Custom Boot
162 OptionMenuCustomBoot();
163 break;
164 #endif
165 #ifdef HAS_OPTION_MENU_REBOOT
166 case 13: // Reboot
167 OptionMenuReboot();
168 break;
169 #endif
170 }
171 }
172
173 VOID DisplayBootTimeOptions(VOID)
174 {
175 CHAR BootOptions[260] = "";
176
177 switch (BootOptionChoice)
178 {
179 case SAFE_MODE:
180 strcat(BootOptions, OptionsMenuList[0]);
181 break;
182
183 case SAFE_MODE_WITH_NETWORKING:
184 strcat(BootOptions, OptionsMenuList[1]);
185 break;
186
187 case SAFE_MODE_WITH_COMMAND_PROMPT:
188 strcat(BootOptions, OptionsMenuList[2]);
189 break;
190
191 case LAST_KNOWN_GOOD_CONFIGURATION:
192 strcat(BootOptions, OptionsMenuList[6]);
193 break;
194
195 case DIRECTORY_SERVICES_RESTORE_MODE:
196 strcat(BootOptions, OptionsMenuList[7]);
197 break;
198
199 default:
200 break;
201 }
202
203 if (BootLogging)
204 {
205 if ( (BootOptionChoice != SAFE_MODE) &&
206 (BootOptionChoice != SAFE_MODE_WITH_NETWORKING) &&
207 (BootOptionChoice != SAFE_MODE_WITH_COMMAND_PROMPT) )
208 {
209 if (BootOptionChoice != NO_OPTION)
210 {
211 strcat(BootOptions, ", ");
212 }
213 strcat(BootOptions, OptionsMenuList[4]);
214 }
215 }
216
217 if (VgaMode)
218 {
219 if ((BootOptionChoice != NO_OPTION) ||
220 BootLogging)
221 {
222 strcat(BootOptions, ", ");
223 }
224 strcat(BootOptions, OptionsMenuList[5]);
225 }
226
227 if (DebuggingMode)
228 {
229 if ((BootOptionChoice != NO_OPTION) ||
230 BootLogging || VgaMode)
231 {
232 strcat(BootOptions, ", ");
233 }
234 strcat(BootOptions, OptionsMenuList[8]);
235 }
236
237 /* Display the chosen boot options */
238 UiDrawText(0,
239 UiScreenHeight - 2,
240 BootOptions,
241 ATTR(COLOR_LIGHTBLUE, UiMenuBgColor));
242 }
243
244 VOID AppendBootTimeOptions(PCHAR BootOptions)
245 {
246 switch (BootOptionChoice)
247 {
248 case SAFE_MODE:
249 strcat(BootOptions, " /SAFEBOOT:MINIMAL /SOS"); // FIXME: NOGUIBOOT should also be specified
250 break;
251
252 case SAFE_MODE_WITH_NETWORKING:
253 strcat(BootOptions, " /SAFEBOOT:NETWORK /SOS"); // FIXME: NOGUIBOOT should also be specified
254 break;
255
256 case SAFE_MODE_WITH_COMMAND_PROMPT:
257 strcat(BootOptions, " /SAFEBOOT:MINIMAL(ALTERNATESHELL) /SOS"); // FIXME: NOGUIBOOT should also be specified
258 break;
259
260 case LAST_KNOWN_GOOD_CONFIGURATION:
261 DbgPrint("Last known good configuration is not supported yet!\n");
262 break;
263
264 case DIRECTORY_SERVICES_RESTORE_MODE:
265 strcat(BootOptions, " /SAFEBOOT:DSREPAIR /SOS");
266 break;
267
268 default:
269 break;
270 }
271
272 if (BootLogging)
273 strcat(BootOptions, " /BOOTLOG");
274
275 if (VgaMode)
276 strcat(BootOptions, " /BASEVIDEO");
277
278 if (DebuggingMode)
279 strcat(BootOptions, " /DEBUG");
280 }