Skip to content

Commit 401721c

Browse files
HBeluscabinarymaster
authored andcommitted
[FREELDR] Support a "video=..." command-line option; use it in pcvideo.c (reactos#8529)
This command-line option can be used when chainloading freeldr.sys from another bootloader. In this case, pcvideo.c uses this option to set an initial display mode. settings.c: Simplify also parsing the separate options from the command-line.
1 parent 868c9d5 commit 401721c

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

boot/freeldr/freeldr/arch/i386/pc/pcvideo.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,59 +1025,70 @@ PcVideoInit(VOID)
10251025
/* Retrieve the initial display mode parameters */
10261026
PcVideoGetDisplayMode();
10271027

1028+
/* If any video options have been specified, try to set a display mode */
1029+
if (BootMgrInfo.VideoOptions && *BootMgrInfo.VideoOptions)
1030+
PcVideoSetDisplayMode(BootMgrInfo.VideoOptions, TRUE);
1031+
10281032
// FIXME: We don't support graphics modes yet!
10291033
// Revert to 80x25 text mode.
10301034
if (DisplayMode != VideoTextMode)
10311035
PcVideoSetMode(VIDEOMODE_NORMAL_TEXT);
10321036
}
10331037

1038+
#define TRACE_printf(Format, ...) \
1039+
do { \
1040+
TRACE(Format, ##__VA_ARGS__); \
1041+
printf(Format, ##__VA_ARGS__); \
1042+
} while (0)
1043+
10341044
VIDEODISPLAYMODE
10351045
PcVideoSetDisplayMode(PCSTR DisplayModeName, BOOLEAN Init)
10361046
{
10371047
USHORT VideoMode = VIDEOMODE_NORMAL_TEXT;
10381048

10391049
if (!DisplayModeName || *DisplayModeName == '\0')
1040-
{
1041-
PcVideoSetBlinkBit(!Init);
1042-
return DisplayMode;
1043-
}
1050+
goto Quit;
10441051

10451052
if (VideoCard == VIDEOCARD_CGA_OR_OTHER)
10461053
{
1047-
TRACE("CGA or other display adapter detected.\n");
1048-
printf("CGA or other display adapter detected.\n");
1049-
printf("Using 80x25 text mode.\n");
1054+
TRACE_printf("CGA or other display adapter detected.\n");
1055+
TRACE_printf("Using 80x25 text mode.\n");
10501056
VideoMode = VIDEOMODE_NORMAL_TEXT;
10511057
}
10521058
else if (VideoCard == VIDEOCARD_EGA)
10531059
{
1054-
TRACE("EGA display adapter detected.\n");
1055-
printf("EGA display adapter detected.\n");
1056-
printf("Using 80x25 text mode.\n");
1060+
TRACE_printf("EGA display adapter detected.\n");
1061+
TRACE_printf("Using 80x25 text mode.\n");
10571062
VideoMode = VIDEOMODE_NORMAL_TEXT;
10581063
}
10591064
else /* VIDEOCARD_VGA */
10601065
{
1061-
TRACE("VGA display adapter detected.\n");
1066+
TRACE_printf("VGA display adapter detected.\n");
1067+
1068+
/* Get the video option separator, if any */
1069+
size_t NameLen = strcspn(DisplayModeName, ",");
1070+
if (!NameLen)
1071+
goto Quit;
10621072

1063-
if (_stricmp(DisplayModeName, "NORMAL_VGA") == 0)
1073+
if (_strnicmp(DisplayModeName, "NORMAL_VGA", NameLen) == 0)
10641074
VideoMode = VIDEOMODE_NORMAL_TEXT;
1065-
else if (_stricmp(DisplayModeName, "EXTENDED_VGA") == 0)
1075+
else if (_strnicmp(DisplayModeName, "EXTENDED_VGA", NameLen) == 0)
10661076
VideoMode = VIDEOMODE_EXTENDED_TEXT;
10671077
else
10681078
VideoMode = (USHORT)strtoul(DisplayModeName, NULL, 0);
10691079
}
10701080

10711081
if (!PcVideoSetMode(VideoMode))
10721082
{
1073-
printf("Error: unable to set video display mode 0x%x\n", (int)VideoMode);
1074-
printf("Defaulting to 80x25 text mode.\n");
1083+
TRACE_printf("Error: unable to set video display mode 0x%x\n", VideoMode);
1084+
TRACE_printf("Defaulting to 80x25 text mode.\n");
10751085
printf("Press any key to continue.\n");
10761086
PcConsGetCh();
10771087

10781088
PcVideoSetMode(VIDEOMODE_NORMAL_TEXT);
10791089
}
10801090

1091+
Quit:
10811092
PcVideoSetBlinkBit(!Init);
10821093
return DisplayMode;
10831094
}

boot/freeldr/freeldr/include/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
typedef struct _BOOTMGRINFO
1111
{
1212
PCSTR DebugString;
13+
PCSTR VideoOptions;
1314
PCSTR DefaultOs;
1415
LONG TimeOut;
1516
ULONG_PTR FrLdrSection;

boot/freeldr/freeldr/settings.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
/* GLOBALS ********************************************************************/
1515

1616
static CCHAR DebugString[256];
17+
static CCHAR VideoOptions[256];
1718
static CCHAR DefaultOs[256];
18-
BOOTMGRINFO BootMgrInfo = {NULL, NULL, -1, 0};
19+
BOOTMGRINFO BootMgrInfo = {NULL, NULL, NULL, -1, 0};
1920

2021
/* FUNCTIONS ******************************************************************/
2122

2223
static VOID
2324
CmdLineParse(
2425
_In_ PCSTR CmdLine)
2526
{
26-
PCHAR End, Setting;
27-
ULONG_PTR Length, Offset = 0;
27+
PCHAR Setting;
28+
size_t Length;
29+
ULONG_PTR Offset = 0;
2830

2931
/*
3032
* Get the debug string, in the following format:
@@ -37,8 +39,7 @@ CmdLineParse(
3739
{
3840
/* Check if there are more command-line parameters following */
3941
Setting += sizeof("debug=") - sizeof(ANSI_NULL);
40-
End = strstr(Setting, " ");
41-
Length = (End ? (End - Setting) : strlen(Setting));
42+
Length = strcspn(Setting, " \t");
4243

4344
/* Copy the debug string and upcase it */
4445
RtlStringCbCopyNA(DebugString, sizeof(DebugString), Setting, Length);
@@ -55,6 +56,30 @@ CmdLineParse(
5556
BootMgrInfo.DebugString = DebugString;
5657
}
5758

59+
/* Get the video options */
60+
Setting = strstr(CmdLine, "video=");
61+
if (Setting)
62+
{
63+
Setting += sizeof("video=") - sizeof(ANSI_NULL);
64+
}
65+
#if (defined(_M_IX86) || defined(_M_AMD64)) && !defined(SARCH_XBOX) && !defined(SARCH_PC98)
66+
else
67+
{
68+
Setting = strstr(CmdLine, "vga=");
69+
if (Setting)
70+
Setting += sizeof("vga=") - sizeof(ANSI_NULL);
71+
}
72+
#endif
73+
if (Setting)
74+
{
75+
/* Check if there are more command-line parameters following */
76+
Length = strcspn(Setting, " \t");
77+
78+
/* Copy the string */
79+
RtlStringCbCopyNA(VideoOptions, sizeof(VideoOptions), Setting, Length);
80+
BootMgrInfo.VideoOptions = VideoOptions;
81+
}
82+
5883
/* Get the timeout */
5984
Setting = strstr(CmdLine, "timeout=");
6085
if (Setting)
@@ -69,8 +94,7 @@ CmdLineParse(
6994
{
7095
/* Check if there are more command-line parameters following */
7196
Setting += sizeof("defaultos=") - sizeof(ANSI_NULL);
72-
End = strstr(Setting, " ");
73-
Length = (End ? (End - Setting) : strlen(Setting));
97+
Length = strcspn(Setting, " \t");
7498

7599
/* Copy the default OS */
76100
RtlStringCbCopyNA(DefaultOs, sizeof(DefaultOs), Setting, Length);

0 commit comments

Comments
 (0)