[FREELDR] Implement NOSERIALMICE and FASTDETECT options (#5886)

Enable FASTDETECT by default, as done in NT 5+. This is because
the serial mouse is recognized by the serial stack since NT 5.x.
This commit is contained in:
Dmitry Borisov 2023-11-05 14:23:43 +06:00 committed by Hermès Bélusca-Maïto
parent 10e7643c80
commit 8d7153c8ba
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 86 additions and 18 deletions

View file

@ -73,7 +73,7 @@ CreateFreeLoaderReactOSEntries(
/* ReactOS */ /* ReactOS */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS");
BootEntry->FriendlyName = L"\"ReactOS\""; BootEntry->FriendlyName = L"\"ReactOS\"";
Options->OsLoadOptions = NULL; // L""; Options->OsLoadOptions = L"/FASTDETECT";
AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS"));
/* ReactOS_Debug */ /* ReactOS_Debug */

View file

@ -18,34 +18,34 @@ LiveCD_LogFile="LiveCD (Log file)"
[LiveCD] [LiveCD]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/MININT Options=/FASTDETECT /MININT
[LiveCD_Debug] [LiveCD_Debug]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /MININT Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /FASTDETECT /MININT
[LiveCD_Macpi] [LiveCD_Macpi]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/HAL=halmacpi.dll /KERNEL=ntkrnlmp.exe /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /MININT Options=/HAL=halmacpi.dll /KERNEL=ntkrnlmp.exe /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /FASTDETECT /MININT
[LiveCD_Aacpi] [LiveCD_Aacpi]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/HAL=halaacpi.dll /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /MININT Options=/HAL=halaacpi.dll /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /FASTDETECT /MININT
[LiveCD_VBoxDebug] [LiveCD_VBoxDebug]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/DEBUG /DEBUGPORT=VBOX /SOS /MININT Options=/DEBUG /DEBUGPORT=VBOX /SOS /FASTDETECT /MININT
[LiveCD_Screen] [LiveCD_Screen]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/DEBUG /DEBUGPORT=SCREEN /SOS /MININT Options=/DEBUG /DEBUGPORT=SCREEN /SOS /FASTDETECT /MININT
[LiveCD_LogFile] [LiveCD_LogFile]
BootType=Windows2003 BootType=Windows2003
SystemPath=\reactos SystemPath=\reactos
Options=/DEBUG /DEBUGPORT=FILE:\Device\HarddiskX\PartitionY\debug.log /SOS /MININT Options=/DEBUG /DEBUGPORT=FILE:\Device\HarddiskX\PartitionY\debug.log /SOS /FASTDETECT /MININT

View file

@ -216,7 +216,7 @@ Cabinet=reactos.cab
DefaultPath = \ReactOS DefaultPath = \ReactOS
SetupDebugOptions = "/DEBUG /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE" SetupDebugOptions = "/DEBUG /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE"
;SetupDebugOptions = "/DEBUG /SOS /DEBUGPORT=SCREEN" ;SetupDebugOptions = "/DEBUG /SOS /DEBUGPORT=SCREEN"
OsLoadOptions = "/NOGUIBOOT /NODEBUG" OsLoadOptions = "/FASTDETECT /NOGUIBOOT /NODEBUG"
[NLS] [NLS]
AnsiCodepage = c_1252.nls AnsiCodepage = c_1252.nls

View file

@ -19,6 +19,8 @@
#include <freeldr.h> #include <freeldr.h>
#include <cportlib/cportlib.h> #include <cportlib/cportlib.h>
#include "../ntldr/ntldropts.h"
#include <debug.h> #include <debug.h>
DBG_DEFAULT_CHANNEL(HWDETECT); DBG_DEFAULT_CHANNEL(HWDETECT);
@ -710,6 +712,7 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
} }
} }
static
ULONG ULONG
PcGetSerialPort(ULONG Index, PULONG Irq) PcGetSerialPort(ULONG Index, PULONG Irq)
{ {
@ -727,8 +730,60 @@ PcGetSerialPort(ULONG Index, PULONG Irq)
return (ULONG) *(BasePtr + Index); return (ULONG) *(BasePtr + Index);
} }
/*
* Parse the serial mouse detection options.
* Format: /FASTDETECT
* or: /NOSERIALMICE=COM[0-9],[0-9],[0-9]...
* or: /NOSERIALMICE:COM[0-9]...
* If we have /FASTDETECT, then nothing can be detected.
*/
static
ULONG
GetSerialMouseDetectionBitmap(
_In_opt_ PCSTR Options)
{
PCSTR Option, c;
ULONG OptionLength, PortBitmap, i;
if (NtLdrGetOption(Options, "FASTDETECT"))
return (1 << MAX_COM_PORTS) - 1;
Option = NtLdrGetOptionEx(Options, "NOSERIALMICE=", &OptionLength);
if (!Option)
Option = NtLdrGetOptionEx(Options, "NOSERIALMICE:", &OptionLength);
if (!Option)
return 0;
/* Invalid port list */
if (OptionLength < (sizeof("NOSERIALMICE=COM9") - 1))
return (1 << MAX_COM_PORTS) - 1;
/* Move to the port list */
Option += sizeof("NOSERIALMICE=COM") - 1;
OptionLength -= sizeof("NOSERIALMICE=COM") - 1;
PortBitmap = 0;
c = Option;
for (i = 0; i < OptionLength; i += 2)
{
UCHAR PortNumber = *c - '0';
if (PortNumber > 0 && PortNumber <= 9)
PortBitmap |= 1 << (PortNumber - 1);
c += 2;
}
return PortBitmap;
}
VOID VOID
DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey, GET_SERIAL_PORT MachGetSerialPort, ULONG Count) DetectSerialPorts(
_In_opt_ PCSTR Options,
_Inout_ PCONFIGURATION_COMPONENT_DATA BusKey,
_In_ GET_SERIAL_PORT MachGetSerialPort,
_In_ ULONG Count)
{ {
PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
@ -740,9 +795,12 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey, GET_SERIAL_PORT MachGetS
PCONFIGURATION_COMPONENT_DATA ControllerKey; PCONFIGURATION_COMPONENT_DATA ControllerKey;
ULONG i; ULONG i;
ULONG Size; ULONG Size;
ULONG PortBitmap;
TRACE("DetectSerialPorts()\n"); TRACE("DetectSerialPorts()\n");
PortBitmap = GetSerialMouseDetectionBitmap(Options);
for (i = 0; i < Count; i++) for (i = 0; i < Count; i++)
{ {
Base = MachGetSerialPort(i, &Irq); Base = MachGetSerialPort(i, &Irq);
@ -813,7 +871,7 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey, GET_SERIAL_PORT MachGetS
Size, Size,
&ControllerKey); &ControllerKey);
if (!Rs232PortInUse(UlongToPtr(Base))) if (!(PortBitmap & (1 << i)) && !Rs232PortInUse(UlongToPtr(Base)))
{ {
/* Detect serial mouse */ /* Detect serial mouse */
DetectSerialPointerPeripheral(ControllerKey, UlongToPtr(Base)); DetectSerialPointerPeripheral(ControllerKey, UlongToPtr(Base));
@ -1561,7 +1619,10 @@ DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
static static
VOID VOID
DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) DetectIsaBios(
_In_opt_ PCSTR Options,
_Inout_ PCONFIGURATION_COMPONENT_DATA SystemKey,
_Out_ ULONG *BusNumber)
{ {
PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
PCONFIGURATION_COMPONENT_DATA BusKey; PCONFIGURATION_COMPONENT_DATA BusKey;
@ -1600,7 +1661,7 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
/* Detect ISA/BIOS devices */ /* Detect ISA/BIOS devices */
DetectBiosDisks(SystemKey, BusKey); DetectBiosDisks(SystemKey, BusKey);
DetectSerialPorts(BusKey, PcGetSerialPort, MAX_COM_PORTS); DetectSerialPorts(Options, BusKey, PcGetSerialPort, MAX_COM_PORTS);
DetectParallelPorts(BusKey); DetectParallelPorts(BusKey);
DetectKeyboardController(BusKey); DetectKeyboardController(BusKey);
DetectPS2Mouse(BusKey); DetectPS2Mouse(BusKey);
@ -1647,7 +1708,7 @@ PcHwDetect(
DetectPciBios(SystemKey, &BusNumber); DetectPciBios(SystemKey, &BusNumber);
DetectApmBios(SystemKey, &BusNumber); DetectApmBios(SystemKey, &BusNumber);
DetectPnpBios(SystemKey, &BusNumber); DetectPnpBios(SystemKey, &BusNumber);
DetectIsaBios(SystemKey, &BusNumber); // TODO: Detect first EISA or MCA, before ISA DetectIsaBios(Options, SystemKey, &BusNumber); // TODO: Detect first EISA or MCA, before ISA
DetectAcpiBios(SystemKey, &BusNumber); DetectAcpiBios(SystemKey, &BusNumber);
// TODO: Collect the ROM blocks from 0xC0000 to 0xF0000 and append their // TODO: Collect the ROM blocks from 0xC0000 to 0xF0000 and append their

View file

@ -73,7 +73,11 @@ XboxGetSerialPort(ULONG Index, PULONG Irq)
extern extern
VOID VOID
DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey, GET_SERIAL_PORT MachGetSerialPort, ULONG Count); DetectSerialPorts(
_In_opt_ PCSTR Options,
_Inout_ PCONFIGURATION_COMPONENT_DATA BusKey,
_In_ GET_SERIAL_PORT MachGetSerialPort,
_In_ ULONG Count);
VOID VOID
XboxGetExtendedBIOSData(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize) XboxGetExtendedBIOSData(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize)
@ -201,7 +205,10 @@ DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
static static
VOID VOID
DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) DetectIsaBios(
_In_opt_ PCSTR Options,
_Inout_ PCONFIGURATION_COMPONENT_DATA SystemKey,
_Out_ ULONG *BusNumber)
{ {
PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
PCONFIGURATION_COMPONENT_DATA BusKey; PCONFIGURATION_COMPONENT_DATA BusKey;
@ -240,7 +247,7 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
/* Detect ISA/BIOS devices */ /* Detect ISA/BIOS devices */
DetectBiosDisks(SystemKey, BusKey); DetectBiosDisks(SystemKey, BusKey);
DetectSerialPorts(BusKey, XboxGetSerialPort, MAX_XBOX_COM_PORTS); DetectSerialPorts(Options, BusKey, XboxGetSerialPort, MAX_XBOX_COM_PORTS);
DetectDisplayController(BusKey); DetectDisplayController(BusKey);
/* FIXME: Detect more ISA devices */ /* FIXME: Detect more ISA devices */
@ -279,7 +286,7 @@ XboxHwDetect(
/* TODO: Build actual xbox's hardware configuration tree */ /* TODO: Build actual xbox's hardware configuration tree */
DetectPciBios(SystemKey, &BusNumber); DetectPciBios(SystemKey, &BusNumber);
DetectIsaBios(SystemKey, &BusNumber); DetectIsaBios(Options, SystemKey, &BusNumber);
TRACE("DetectHardware() Done\n"); TRACE("DetectHardware() Done\n");
return SystemKey; return SystemKey;