Skip to content

Commit eda41d8

Browse files
HBeluscabinarymaster
authored andcommitted
[FREELDR] Add the possibility to change the boot load options from TXTSETUP.SIF
at runtime from the boot selection menu or from FREELDR.INI. CORE-17350, CORE-9023 For a proper override of the options by new user options, specify the /SIFOPTIONSOVERRIDE switch in addition. Otherwise, user options are merged with those retrieved from TXTSETUP.SIF, with priority given to the former ones. - Update the documentation for the 'ReactOSSetup' OS type in the FREELDR.INI file template. - Use a different prompt in the custom boot options editor for the 'ReactOSSetup' OS type, with adequate explanation. - Get rid of the ReactOS-specific TXTSETUP.SIF 'DbgOsLoadOptions' value, and use instead the Windows-compatible 'SetupDebugOptions' value that is added to the other load options when debugging is to be enabled.
1 parent 74fd487 commit eda41d8

File tree

6 files changed

+511
-44
lines changed

6 files changed

+511
-44
lines changed

boot/bootdata/txtsetup.sif

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ Cabinet=reactos.cab
208208

209209
[SetupData]
210210
DefaultPath = \ReactOS
211+
SetupDebugOptions = "/DEBUG /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE"
212+
;SetupDebugOptions = "/DEBUG /SOS /DEBUGPORT=SCREEN"
213+
;SetupDebugOptions = "/DEBUG /DEBUGPORT=BOCHS"
211214
OsLoadOptions = "/NOGUIBOOT /NODEBUG"
212-
DbgOsLoadOptions = "/NOGUIBOOT /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE"
213-
;DbgOsLoadOptions = "/SOS /DEBUGPORT=SCREEN"
214-
;DbgOsLoadOptions = "/NOGUIBOOT /DEBUGPORT=BOCHS"
215215

216216
[NLS]
217217
AnsiCodepage = c_1252.nls

boot/freeldr/FREELDR.INI

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@
112112
; will only be used to set the boot partition.
113113
; Initrd - specifies the optional init ramdisk file name to be used.
114114
; The same remarks about the path as for "Kernel" remain valid.
115-
; CommandLine - specifies the command line options for the kernel.
115+
; CommandLine - specifies the boot load options for the kernel.
116116

117117
; ["Windows(NT40|2003)" OSType] Section Commands:
118118
;
119119
; SystemPath - specifies the system root path (must be a valid ARC path):
120120
; multi(0)disk(0)rdisk(0)partition(1)\reactos
121121
; multi(0)disk(0)fdisk(0)
122-
; Options - specifies the command line options for the kernel being booted.
122+
; Options - specifies the boot load options for the kernel.
123123
; Kernel - specifies the kernel file name (default: ntoskrnl.exe)
124124
; Hal - specifies the HAL file name (default: hal.dll)
125125
;
@@ -130,8 +130,24 @@
130130

131131
; ["ReactOSSetup" OSType] Section Commands:
132132
;
133-
; No options defined for the moment. This OS type is used to tell FreeLdr
134-
; to start the SETUP portion of NT / ReactOS.
133+
; This OS type is used to start the SETUP portion of NT / ReactOS.
134+
;
135+
; SystemPath - specifies the system root path (must be a valid ARC path):
136+
; multi(0)disk(0)rdisk(0)partition(1)\reactos
137+
; multi(0)disk(0)fdisk(0)
138+
; Options - specifies extra boot load options for the kernel and the
139+
; setup environment (see REMARK 2 below).
140+
;
141+
; REMARK: Contrary to the "Windows" type, this OS type does not support separate
142+
; "Kernel" and "Hal" values. Instead, these values must be specified using the
143+
; NT-compatible "/HAL=filename" and "/KERNEL=filename" option switches.
144+
;
145+
; REMARK 2: The SETUP portion retrieves the default boot load options from the
146+
; TXTSETUP.SIF file present in the installation source (section "[SetupData]",
147+
; values "OsLoadOptions" and "SetupDebugOptions"). Thus, any options specified
148+
; using the "Options" value will supplement those already obtained from the
149+
; TXTSETUP.SIF file, unless the "/SIFOPTIONSOVERRIDE" option switch is specified,
150+
; in which case the "Options" value overrides those from TXTSETUP.SIF.
135151

136152

137153
[FREELOADER]

boot/freeldr/freeldr/custom.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const CHAR BootDrivePrompt[] = "Enter the boot drive.\n\nExamples:\nfd0 - first
3636
const CHAR BootPartitionPrompt[] = "Enter the boot partition.\n\nEnter 0 for the active (bootable) partition.";
3737
const CHAR ARCPathPrompt[] = "Enter the boot ARC path.\n\nExamples:\nmulti(0)disk(0)rdisk(0)partition(1)\nmulti(0)disk(0)fdisk(0)";
3838
const CHAR ReactOSSystemPathPrompt[] = "Enter the path to your ReactOS system directory.\n\nExamples:\n\\REACTOS\n\\ROS";
39-
const CHAR ReactOSOptionsPrompt[] = "Enter the options you want passed to the kernel.\n\nExamples:\n/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200\n/FASTDETECT /SOS /NOGUIBOOT\n/BASEVIDEO /MAXMEM=64\n/KERNEL=NTKRNLMP.EXE /HAL=HALMPS.DLL";
39+
const CHAR ReactOSOptionsPrompt[] = "Enter the load options you want passed to the kernel.\n\nExamples:\n/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200\n/FASTDETECT /SOS /NOGUIBOOT\n/BASEVIDEO /MAXMEM=64\n/KERNEL=NTKRNLMP.EXE /HAL=HALMPS.DLL";
40+
const CHAR ReactOSSetupOptionsPrompt[] = "Enter additional load options you want passed to the ReactOS Setup.\nThese options will supplement those obtained from the TXTSETUP.SIF\nfile, unless you also specify the /SIFOPTIONSOVERRIDE option switch.\n\nExample:\n/NOGUIBOOT /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200";
4041
const CHAR CustomBootPrompt[] = "Press ENTER to boot your custom boot setup.";
4142

4243
/* FUNCTIONS ******************************************************************/
@@ -659,7 +660,7 @@ EditCustomBootReactOS(
659660
return;
660661
}
661662

662-
if (!UiEditBox(ReactOSOptionsPrompt, ReactOSOptions, sizeof(ReactOSOptions)))
663+
if (!UiEditBox(IsSetup ? ReactOSSetupOptionsPrompt : ReactOSOptionsPrompt, ReactOSOptions, sizeof(ReactOSOptions)))
663664
return;
664665

665666
/* Modify the settings values and return if we were in edit mode */
@@ -686,7 +687,9 @@ EditCustomBootReactOS(
686687
return;
687688

688689
/* Construct the ReactOS ARC system path */
689-
ConstructArcPath(ReactOSARCPath, ReactOSSystemPath, DriveMapGetBiosDriveNumber(BootDriveString), atoi(BootPartitionString));
690+
ConstructArcPath(ReactOSARCPath, ReactOSSystemPath,
691+
DriveMapGetBiosDriveNumber(BootDriveString),
692+
atoi(BootPartitionString));
690693

691694
/* Add the system path */
692695
if (!IniAddSettingValueToSection(SectionId, "SystemPath", ReactOSARCPath))

boot/freeldr/freeldr/ntldr/ntldropts.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,83 @@ NtLdrGetOption(
131131
{
132132
return NtLdrGetOptionEx(Options, OptionName, NULL);
133133
}
134+
135+
/*
136+
* Appends or prepends new options to the ones originally contained
137+
* in the buffer pointed by LoadOptions, of maximum size BufferSize.
138+
*/
139+
VOID
140+
NtLdrAddOptions(
141+
IN OUT PSTR LoadOptions,
142+
IN ULONG BufferSize,
143+
IN BOOLEAN Append,
144+
IN PCSTR NewOptions OPTIONAL)
145+
{
146+
ULONG OptionsLength;
147+
ULONG NewOptsLength;
148+
BOOLEAN AddSeparator;
149+
150+
if (!LoadOptions || (BufferSize == 0))
151+
return;
152+
// ASSERT(strlen(LoadOptions) + 1 <= BufferSize);
153+
154+
if (!NewOptions || !*NewOptions)
155+
return;
156+
157+
if (Append)
158+
{
159+
OptionsLength = (ULONG)strlen(LoadOptions);
160+
OptionsLength = min(OptionsLength, BufferSize-1);
161+
162+
/* Add a whitespace separator if needed */
163+
if (OptionsLength != 0 &&
164+
(LoadOptions[OptionsLength-1] != ' ') &&
165+
(LoadOptions[OptionsLength-1] != '\t') &&
166+
(*NewOptions != '\0') &&
167+
(*NewOptions != ' ') &&
168+
(*NewOptions != '\t'))
169+
{
170+
RtlStringCbCatA(LoadOptions, BufferSize * sizeof(CHAR), " ");
171+
}
172+
173+
/* Append the options */
174+
RtlStringCbCatA(LoadOptions, BufferSize * sizeof(CHAR), NewOptions);
175+
}
176+
else
177+
{
178+
NewOptsLength = (ULONG)strlen(NewOptions);
179+
NewOptsLength = min(NewOptsLength, BufferSize-1);
180+
181+
/* Add a whitespace separator if needed */
182+
AddSeparator = FALSE;
183+
if (NewOptsLength != 0 &&
184+
(NewOptions[NewOptsLength-1] != ' ') &&
185+
(NewOptions[NewOptsLength-1] != '\t') &&
186+
(*LoadOptions != '\0') &&
187+
(*LoadOptions != ' ') &&
188+
(*LoadOptions != '\t'))
189+
{
190+
AddSeparator = TRUE;
191+
++NewOptsLength;
192+
}
193+
194+
/*
195+
* Move the original load options forward (possibly truncating them
196+
* at the end if the buffer is not large enough) to make place for
197+
* the options to prepend.
198+
*/
199+
OptionsLength = (ULONG)strlen(LoadOptions) + 1;
200+
OptionsLength = min(OptionsLength, BufferSize - NewOptsLength);
201+
RtlMoveMemory(LoadOptions + NewOptsLength,
202+
LoadOptions,
203+
OptionsLength * sizeof(CHAR));
204+
/* NULL-terminate */
205+
(LoadOptions + NewOptsLength)[OptionsLength-1] = '\0';
206+
207+
/* Restore the new options length back to its original value */
208+
if (AddSeparator) --NewOptsLength;
209+
/* Prepend the options and add the whitespace separator if needed */
210+
strncpy(LoadOptions, NewOptions, NewOptsLength);
211+
if (AddSeparator) LoadOptions[NewOptsLength] = ' ';
212+
}
213+
}

boot/freeldr/freeldr/ntldr/ntldropts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ PCSTR
2929
NtLdrGetOption(
3030
IN PCSTR Options,
3131
IN PCSTR OptionName);
32+
33+
VOID
34+
NtLdrAddOptions(
35+
IN OUT PSTR LoadOptions,
36+
IN ULONG BufferSize,
37+
IN BOOLEAN Append,
38+
IN PCSTR NewOptions OPTIONAL);

0 commit comments

Comments
 (0)