[FREELDR] EMS boot options: Parse NT kernel load options in a consistent manner. Addendum to d887308b.

In particular the parsing should not care about the letter case.
This commit is contained in:
Hermès Bélusca-Maïto 2020-12-13 21:49:59 +01:00
parent fb9d8e5239
commit 5dd0b32799
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -10,6 +10,7 @@
#include <freeldr.h> #include <freeldr.h>
#include <cportlib/cportlib.h> #include <cportlib/cportlib.h>
#include "ntldropts.h"
/* Note: Move these to some smbios.h header */ /* Note: Move these to some smbios.h header */
#define SYSID_TYPE_UUID "_UUID_" #define SYSID_TYPE_UUID "_UUID_"
@ -206,7 +207,7 @@ WinLdrInitializeHeadlessPort(VOID)
{ {
ULONG PortNumber, BaudRate; ULONG PortNumber, BaudRate;
PUCHAR PortAddress; PUCHAR PortAddress;
PCHAR AnsiReset = "\x1B[m"; PCSTR AnsiReset = "\x1B[m";
ULONG i; ULONG i;
PortNumber = LoaderRedirectionInformation.PortNumber; PortNumber = LoaderRedirectionInformation.PortNumber;
@ -267,13 +268,11 @@ WinLdrInitializeHeadlessPort(VOID)
/* Call arch code to initialize the port */ /* Call arch code to initialize the port */
PortAddress = LoaderRedirectionInformation.PortAddress; PortAddress = LoaderRedirectionInformation.PortAddress;
WinLdrTerminalConnected = WinLdrPortInitialize( WinLdrTerminalConnected = WinLdrPortInitialize(BaudRate,
BaudRate, PortNumber,
PortNumber, PortAddress,
PortAddress, WinLdrTerminalConnected,
WinLdrTerminalConnected, &WinLdrTerminalDeviceId);
&WinLdrTerminalDeviceId);
if (WinLdrTerminalConnected) if (WinLdrTerminalConnected)
{ {
/* Port seems usable, set it up and get the BIOS GUID */ /* Port seems usable, set it up and get the BIOS GUID */
@ -302,55 +301,54 @@ WinLdrInitializeHeadlessPort(VOID)
VOID VOID
WinLdrSetupEms(IN PCSTR BootOptions) WinLdrSetupEms(IN PCSTR BootOptions)
{ {
PCHAR Settings, RedirectPort; PCSTR Option;
/* Start fresh */ /* Start fresh */
RtlZeroMemory(&LoaderRedirectionInformation, sizeof(HEADLESS_LOADER_BLOCK)); RtlZeroMemory(&LoaderRedirectionInformation, sizeof(HEADLESS_LOADER_BLOCK));
LoaderRedirectionInformation.PciDeviceId = PCI_INVALID_VENDORID; LoaderRedirectionInformation.PciDeviceId = PCI_INVALID_VENDORID;
/* Use a direction port if one was given, or use ACPI to detect one instead */ /* Use a direction port if one was given, or use ACPI to detect one instead */
Settings = strstr(BootOptions, "/redirect="); Option = NtLdrGetOption(BootOptions, "redirect=");
if (Settings) if (Option)
{ {
RedirectPort = strstr(Settings, "com"); Option += 9;
if (RedirectPort) if (_strnicmp(Option, "com", 3) == 0)
{ {
RedirectPort += sizeof("com") - 1; Option += 3;
LoaderRedirectionInformation.PortNumber = atoi(RedirectPort); LoaderRedirectionInformation.PortNumber = atoi(Option);
LoaderRedirectionInformation.TerminalType = 1; // HeadlessSerialPort LoaderRedirectionInformation.TerminalType = 1; // VT100+
}
else if (_strnicmp(Option, "usebiossettings", 15) == 0)
{
// FIXME: TODO!
UiDrawStatusText("ACPI SRT/SPCR Table Not Supported...");
return;
} }
else else
{ {
RedirectPort = strstr(Settings, "usebiossettings"); LoaderRedirectionInformation.PortAddress = (PUCHAR)strtoul(Option, 0, 16);
if (RedirectPort) if (LoaderRedirectionInformation.PortAddress)
{ {
UiDrawStatusText("ACPI SRT Table Not Supported..."); LoaderRedirectionInformation.PortNumber = 3;
return;
}
else
{
LoaderRedirectionInformation.PortAddress = (PUCHAR)strtoul(Settings, 0, 16);
if (LoaderRedirectionInformation.PortAddress)
{
LoaderRedirectionInformation.PortNumber = 3;
}
} }
} }
} }
/* Use a direction baudrate if one was given */ /* Use a direction baudrate if one was given */
Settings = strstr(BootOptions, "/redirectbaudrate="); Option = NtLdrGetOption(BootOptions, "redirectbaudrate=");
if (Settings) if (Option)
{ {
if (strstr(Settings, "115200")) Option += 17;
// LoaderRedirectionInformation.BaudRate = atoi(Option);
if (strncmp(Option, "115200", 6) == 0)
{ {
LoaderRedirectionInformation.BaudRate = 115200; LoaderRedirectionInformation.BaudRate = 115200;
} }
else if (strstr(Settings, "57600")) else if (strncmp(Option, "57600", 5) == 0)
{ {
LoaderRedirectionInformation.BaudRate = 57600; LoaderRedirectionInformation.BaudRate = 57600;
} }
else if (strstr(Settings, "19200")) else if (strncmp(Option, "19200", 5) == 0)
{ {
LoaderRedirectionInformation.BaudRate = 19200; LoaderRedirectionInformation.BaudRate = 19200;
} }