From 7fcf928e38dc5913442c09aabc9979726aa9cfaa Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Mon, 2 Oct 2006 05:40:36 +0000 Subject: [PATCH] - Continue implementation of KiRosFrldrLpbToNtLpb by parsing the FreeLDR command line and: * Removing the ARC Boot path and splitting it into the ARC Boot Device Name, the ARC HAL Device Name, and the NT Boot and HAL Path Names, saved in their respective LoaderBlock pointers. * Converting every slash to a space. ("/DEBUGPORT" -> " DEBUGPORT") * Now we can fully parse and read NTLDR command lines. - Update various code in the kernel to: * Use LoaderBlock->ArcDeviceNamePath & friends instead of the command line. * Stop depending on slashes, and instead use strstr for parameters. svn path=/trunk/; revision=24358 --- reactos/ntoskrnl/ex/init.c | 91 ++-------------- reactos/ntoskrnl/include/internal/io.h | 2 +- reactos/ntoskrnl/include/internal/po.h | 2 +- reactos/ntoskrnl/io/iomgr/arcname.c | 41 ++------ reactos/ntoskrnl/io/iomgr/iomgr.c | 2 +- reactos/ntoskrnl/kd/kdinit.c | 137 ++++++++++++------------- reactos/ntoskrnl/kd/kdio.c | 9 +- reactos/ntoskrnl/ke/freeldr.c | 36 +++++++ reactos/ntoskrnl/po/power.c | 13 ++- 9 files changed, 143 insertions(+), 190 deletions(-) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 1ee785e56a4..4f07213eddd 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -29,7 +29,6 @@ extern LOADER_MODULE KeLoaderModules[64]; extern ULONG KeLoaderModuleCount; extern PRTL_MESSAGE_RESOURCE_DATA KiBugCodeMessages; BOOLEAN NoGuiBoot = FALSE; -static BOOLEAN ForceAcpiDisable = FALSE; /* Init flags and settings */ ULONG ExpInitializationPhase; @@ -48,7 +47,7 @@ NLSTABLEINFO ExpNlsTableInfo; static VOID INIT_FUNCTION -InitSystemSharedUserPage (PCSZ ParameterLine) +InitSystemSharedUserPage (IN PLOADER_PARAMETER_BLOCK LoaderBlock) { UNICODE_STRING ArcDeviceName; UNICODE_STRING ArcName; @@ -56,9 +55,7 @@ InitSystemSharedUserPage (PCSZ ParameterLine) UNICODE_STRING DriveDeviceName; UNICODE_STRING DriveName; WCHAR DriveNameBuffer[20]; - PCHAR ParamBuffer; PWCHAR ArcNameBuffer; - PCHAR p; NTSTATUS Status; ULONG Length; OBJECT_ATTRIBUTES ObjectAttributes; @@ -86,39 +83,16 @@ InitSystemSharedUserPage (PCSZ ParameterLine) * Format: "\ [options...]" */ - /* Create local parameter line copy */ - ParamBuffer = ExAllocatePool(PagedPool, 256); - strcpy (ParamBuffer, (const char *)ParameterLine); - DPRINT("%s\n", ParamBuffer); + RtlCreateUnicodeStringFromAsciiz(&BootPath, LoaderBlock->NtBootPathName); - /* Cut options off */ - p = strchr (ParamBuffer, ' '); - if (p) *p = 0; - DPRINT("%s\n", ParamBuffer); - - /* Extract path */ - p = strchr (ParamBuffer, '\\'); - if (p) { - - DPRINT("Boot path: %s\n", p); - RtlCreateUnicodeStringFromAsciiz (&BootPath, p); - *p = 0; - - } else { - - DPRINT("Boot path: %s\n", "\\"); - RtlCreateUnicodeStringFromAsciiz (&BootPath, "\\"); - } - DPRINT("Arc name: %s\n", ParamBuffer); + /* Remove the trailing backslash */ + BootPath.Length -= sizeof(WCHAR); + BootPath.MaximumLength -= sizeof(WCHAR); /* Only ARC Name left - Build full ARC Name */ ArcNameBuffer = ExAllocatePool (PagedPool, 256 * sizeof(WCHAR)); - swprintf (ArcNameBuffer, L"\\ArcName\\%S", ParamBuffer); + swprintf (ArcNameBuffer, L"\\ArcName\\%S", LoaderBlock->ArcBootDeviceName); RtlInitUnicodeString (&ArcName, ArcNameBuffer); - DPRINT("Arc name: %wZ\n", &ArcName); - - /* Free ParamBuffer */ - ExFreePool (ParamBuffer); /* Allocate ARC Device Name string */ ArcDeviceName.Length = 0; @@ -163,7 +137,6 @@ InitSystemSharedUserPage (PCSZ ParameterLine) CPRINT("NtQuerySymbolicLinkObject() failed (Status %x)\n", Status); KEBUGCHECK(0); } - DPRINT("Length: %lu ArcDeviceName: %wZ\n", Length, &ArcDeviceName); /* Allocate Device Name string */ DriveDeviceName.Length = 0; @@ -231,48 +204,6 @@ InitSystemSharedUserPage (PCSZ ParameterLine) } } -__inline -VOID -STDCALL -ParseCommandLine(PBOOLEAN NoGuiBoot, - PBOOLEAN ForceAcpiDisable) -{ - PCHAR p1, p2; - - p1 = KeLoaderBlock->LoadOptions; - while(*p1 && (p2 = strchr(p1, '/'))) { - - p2++; - if (!_strnicmp(p2, "NOGUIBOOT", 9)) { - - p2 += 9; - *NoGuiBoot = TRUE; - - } else if (!_strnicmp(p2, "CRASHDUMP", 9)) { - - p2 += 9; - if (*p2 == ':') { - - p2++; - if (!_strnicmp(p2, "FULL", 4)) { - - MmCoreDumpType = MM_CORE_DUMP_TYPE_FULL; - - } else { - - MmCoreDumpType = MM_CORE_DUMP_TYPE_NONE; - } - } - } else if (!_strnicmp(p2, "NOACPI", 6)) { - - p2 += 6; - *ForceAcpiDisable = TRUE; - } - - p1 = p2; - } -} - VOID FORCEINLINE ParseAndCacheLoadedModules(VOID) @@ -472,9 +403,6 @@ ExpInitializeExecutive(IN ULONG Cpu, { PNLS_DATA_BLOCK NlsData; - /* Parse Command Line Settings */ - ParseCommandLine(&NoGuiBoot, &ForceAcpiDisable); - /* FIXME: Deprecate soon */ ParseAndCacheLoadedModules(); @@ -630,7 +558,7 @@ ExPhase2Init(PVOID Context) IoInit(); /* TBD */ - PoInit(AcpiTableDetected, ForceAcpiDisable); + PoInit(AcpiTableDetected, KeLoaderBlock); /* Initialize the Registry (Hives are NOT yet loaded!) */ CmInitializeRegistry(); @@ -650,6 +578,9 @@ ExPhase2Init(PVOID Context) /* Clear the screen to blue */ HalInitSystem(2, KeLoaderBlock); + /* Check if GUI Boot is enabled */ + if (strstr(KeLoaderBlock->LoadOptions, "NOGUIBOOT")) NoGuiBoot = TRUE; + /* Display version number and copyright/warranty message */ if (NoGuiBoot) ExpDisplayNotice(); @@ -685,7 +616,7 @@ ExPhase2Init(PVOID Context) PsLocateSystemDll(); /* Initialize shared user page. Set dos system path, dos device map, etc. */ - InitSystemSharedUserPage (KeLoaderBlock->LoadOptions); + InitSystemSharedUserPage(KeLoaderBlock); /* Create 'ReactOSInitDone' event */ RtlInitUnicodeString(&EventName, L"\\ReactOSInitDone"); diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index 3bca882854f..e80adc1789f 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -568,7 +568,7 @@ IoCreateArcNames( NTSTATUS IoCreateSystemRootLink( - IN PCHAR ParameterLine + IN PLOADER_PARAMETER_BLOCK LoaderBlock ); // diff --git a/reactos/ntoskrnl/include/internal/po.h b/reactos/ntoskrnl/include/internal/po.h index def455703bc..3bd20aa259d 100644 --- a/reactos/ntoskrnl/include/internal/po.h +++ b/reactos/ntoskrnl/include/internal/po.h @@ -39,7 +39,7 @@ VOID NTAPI PoInit( BOOLEAN HaveAcpiTable, - BOOLEAN ForceAcpiDisable + IN PLOADER_PARAMETER_BLOCK LoaderBlock ); VOID diff --git a/reactos/ntoskrnl/io/iomgr/arcname.c b/reactos/ntoskrnl/io/iomgr/arcname.c index 59a9e95bf00..05d0f5f378a 100644 --- a/reactos/ntoskrnl/io/iomgr/arcname.c +++ b/reactos/ntoskrnl/io/iomgr/arcname.c @@ -679,7 +679,7 @@ IopCheckCdromDevices(PULONG DeviceNumber) NTSTATUS INIT_FUNCTION -IoCreateSystemRootLink(PCHAR ParameterLine) +IoCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock) { OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; @@ -694,33 +694,14 @@ IoCreateSystemRootLink(PCHAR ParameterLine) ULONG Length; HANDLE Handle; - /* Create local parameter line copy */ - ParamBuffer = ExAllocatePool(PagedPool, 256); - strcpy(ParamBuffer, (char *)ParameterLine); + RtlCreateUnicodeStringFromAsciiz(&BootPath, LoaderBlock->NtBootPathName); - DPRINT("%s\n", ParamBuffer); - /* Format: \ [options...] */ + /* Remove the trailing backslash */ + BootPath.Length -= sizeof(WCHAR); + BootPath.MaximumLength -= sizeof(WCHAR); - /* cut options off */ - p = strchr(ParamBuffer, ' '); - if (p) - *p = 0; - DPRINT("%s\n", ParamBuffer); - - /* extract path */ - p = strchr(ParamBuffer, '\\'); - if (p) - { - DPRINT("Boot path: %s\n", p); - RtlCreateUnicodeStringFromAsciiz(&BootPath, p); - *p = 0; - } - else - { - DPRINT("Boot path: %s\n", "\\"); - RtlCreateUnicodeStringFromAsciiz(&BootPath, "\\"); - } - DPRINT("ARC name: %s\n", ParamBuffer); + /* Only ARC Name left - Build full ARC Name */ + ParamBuffer = LoaderBlock->ArcBootDeviceName; p = strstr(ParamBuffer, "cdrom"); if (p != NULL) @@ -740,7 +721,7 @@ IoCreateSystemRootLink(PCHAR ParameterLine) DPRINT("New ARC name: %s\n", ParamBuffer); /* Adjust original command line */ - p = strstr(ParameterLine, "cdrom"); + p = strstr(LoaderBlock->ArcBootDeviceName, "cdrom"); if (p != NULL); { char temp[256]; @@ -763,10 +744,6 @@ IoCreateSystemRootLink(PCHAR ParameterLine) swprintf(ArcNameBuffer, L"\\ArcName\\%S", ParamBuffer); RtlInitUnicodeString(&ArcName, ArcNameBuffer); - DPRINT("Arc name: %wZ\n", &ArcName); - - /* free ParamBuffer */ - ExFreePool(ParamBuffer); /* allocate device name string */ DeviceName.Length = 0; @@ -808,13 +785,11 @@ IoCreateSystemRootLink(PCHAR ParameterLine) return(Status); } - DPRINT("Length: %lu DeviceName: %wZ\n", Length, &DeviceName); RtlAppendUnicodeStringToString(&DeviceName, &BootPath); RtlFreeUnicodeString(&BootPath); - DPRINT("DeviceName: %wZ\n", &DeviceName); /* create the '\SystemRoot' link */ Status = IoCreateSymbolicLink(&LinkName, diff --git a/reactos/ntoskrnl/io/iomgr/iomgr.c b/reactos/ntoskrnl/io/iomgr/iomgr.c index df34e60e937..a42a0d3a907 100644 --- a/reactos/ntoskrnl/io/iomgr/iomgr.c +++ b/reactos/ntoskrnl/io/iomgr/iomgr.c @@ -483,7 +483,7 @@ IoInit3(VOID) /* Create the SystemRoot symbolic link */ DPRINT("CommandLine: %s\n", KeLoaderBlock->LoadOptions); - Status = IoCreateSystemRootLink(KeLoaderBlock->LoadOptions); + Status = IoCreateSystemRootLink(KeLoaderBlock); if (!NT_SUCCESS(Status)) { CPRINT("IoCreateSystemRootLink FAILED: (0x%x) - ", Status); KEBUGCHECK(INACCESSIBLE_BOOT_DEVICE); diff --git a/reactos/ntoskrnl/kd/kdinit.c b/reactos/ntoskrnl/kd/kdinit.c index 71655be72c2..263faaa865a 100644 --- a/reactos/ntoskrnl/kd/kdinit.c +++ b/reactos/ntoskrnl/kd/kdinit.c @@ -166,87 +166,83 @@ KdInitSystem(ULONG BootPhase, { ULONG Value; ULONG i; - PCHAR p1, p2; - -#if 0 - /* NTLDR HACK */ - KdpSerialInit(&DispatchTable[KdSerial], 0); - KdpDebugMode.Serial = TRUE; - SerialPortInfo.ComPort = 1; - KdpPort = 1; - KdDebuggerEnabled = TRUE; -#endif + PCHAR CommandLine, Port, BaudRate, Irq; /* Set Default Port Options */ if (BootPhase == 0) { + /* Get the Command Line */ + CommandLine = LoaderBlock->LoadOptions; - /* Parse the Command Line */ - p1 = LoaderBlock->LoadOptions; - while (p1 && (p2 = strchr(p1, '/'))) + /* Upcase it */ + _strupr(CommandLine); + + /* Check for settings that we support */ + if (strstr(CommandLine, "BREAK")) KdpEarlyBreak = TRUE; + if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE; + if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE; + if (strstr(CommandLine, "DEBUG")) { - /* Move past the slash */ - p2++; + /* Enable on the serial port */ + KdDebuggerEnabled = TRUE; + KdpDebugMode.Serial = TRUE; + } - /* Identify the Debug Type being Used */ - if (!_strnicmp(p2, "DEBUGPORT=", 10)) - { - p2 += 10; - p2 = KdpGetDebugMode(p2); - p2 = KdpGetWrapperDebugMode(p2, LoaderBlock); - KdDebuggerEnabled = TRUE; - } - /* Check for early breakpoint */ - else if (!_strnicmp(p2, "BREAK", 5)) - { - p2 += 5; - KdpEarlyBreak = TRUE; - } - /* Check for Kernel Debugging Enable */ - else if (!_strnicmp(p2, "DEBUG", 5)) - { - /* Enable it on the Serial Port */ - p2 += 5; - KdDebuggerEnabled = TRUE; - KdpDebugMode.Serial = TRUE; - } - /* Check for Kernel Debugging Bypass */ - else if (!_strnicmp(p2, "NODEBUG", 7)) - { - /* Disable Debugging */ - p2 += 7; - KdDebuggerEnabled = FALSE; - } - /* Check for Kernel Debugging Bypass unless STOP Error */ - else if (!_strnicmp(p2, "CRASHDEBUG", 10)) - { - /* Disable Debugging */ - p2 += 10; - KdDebuggerEnabled = FALSE; - } - /* Check Serial Port Settings [Baud Rate] */ - else if (!_strnicmp(p2, "BAUDRATE=", 9)) - { - /* Get the Baud Rate */ - p2 += 9; - Value = (ULONG)atol(p2); + /* Get the port and baud rate */ + Port = strstr(CommandLine, "DEBUGPORT"); + BaudRate = strstr(CommandLine, "BAUDRATE"); + Irq = strstr(CommandLine, "IRQ"); - /* Check if it's valid and Set it */ - if (0 < Value) PortInfo.BaudRate = SerialPortInfo.BaudRate = Value; - } - /* Check Serial Port Settings [IRQ] */ - else if (!_strnicmp(p2, "IRQ=", 4)) + /* Check if we got the /DEBUGPORT parameter */ + if (Port) + { + /* Move past the actual string, to reach the port*/ + Port += strlen("DEBUGPORT"); + + /* Now get past any spaces and skip the equal sign */ + while (*Port == ' ') Port++; + Port++; + + /* Get the debug mode and wrapper */ + Port = KdpGetDebugMode(Port); + Port = KdpGetWrapperDebugMode(Port, LoaderBlock); + KdDebuggerEnabled = TRUE; + } + + /* Check if we got a baud rate */ + if (BaudRate) + { + /* Move past the actual string, to reach the rate */ + BaudRate += strlen("BAUDRATE"); + + /* Now get past any spaces */ + while (*BaudRate == ' ') BaudRate++; + + /* And make sure we have a rate */ + if (*BaudRate) { - /* Get the IRQ */ - p2 += 3; - Value = (ULONG)atol(p2); - - /* Check if it's valid and set it */ - if (0 < Value) KdpPortIrq = Value; + /* Read and set it */ + Value = atol(BaudRate + 1); + if (Value) PortInfo.BaudRate = SerialPortInfo.BaudRate = Value; } + } - /* Move to next */ - p1 = p2; + /* Check Serial Port Settings [IRQ] */ + if (Irq) + { + /* Move past the actual string, to reach the rate */ + Irq += strlen("IRQ"); + + /* Now get past any spaces */ + while (*Irq == ' ') Irq++; + + /* And make sure we have an IRQ */ + if (*Irq) + { + /* Read and set it */ + Value = atol(Irq + 1); + if (Value) KdpPortIrq = Value; + } } /* Call Providers at Phase 0 */ @@ -257,7 +253,6 @@ KdInitSystem(ULONG BootPhase, /* Call Wrapper at Phase 0 */ if (WrapperInitRoutine) WrapperInitRoutine(&WrapperTable, 0); - return; } diff --git a/reactos/ntoskrnl/kd/kdio.c b/reactos/ntoskrnl/kd/kdio.c index 811d22f7a64..c0c140493e0 100644 --- a/reactos/ntoskrnl/kd/kdio.c +++ b/reactos/ntoskrnl/kd/kdio.c @@ -188,10 +188,15 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable, /* Register as a Provider */ InsertTailList(&KdProviders, &DispatchTable->KdProvidersList); - + /* Display separator + ReactOS version at start of the debug log */ - DPRINT1("---------------------------------------------------------------\n"); + DPRINT1("-----------------------------------------------------\n"); DPRINT1("ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n"); + DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions); + DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, + KeLoaderBlock->NtHalPathName, + KeLoaderBlock->ArcHalDeviceName, + KeLoaderBlock->NtBootPathName); } else if (BootPhase == 2) { diff --git a/reactos/ntoskrnl/ke/freeldr.c b/reactos/ntoskrnl/ke/freeldr.c index 685293d924f..a7dadda2473 100644 --- a/reactos/ntoskrnl/ke/freeldr.c +++ b/reactos/ntoskrnl/ke/freeldr.c @@ -43,6 +43,10 @@ extern LDR_DATA_TABLE_ENTRY HalModuleObject; LOADER_PARAMETER_BLOCK BldrLoaderBlock; LOADER_PARAMETER_EXTENSION BldrExtensionBlock; CHAR BldrCommandLine[256]; +CHAR BldrArcBootPath[64]; +CHAR BldrArcHalPath[64]; +CHAR BldrNtHalPath[64]; +CHAR BldrNtBootPath[64]; LDR_DATA_TABLE_ENTRY BldrModules[64]; MEMORY_ALLOCATION_DESCRIPTOR BldrMemoryDescriptors[64]; WCHAR BldrModuleStrings[64][260]; @@ -63,6 +67,8 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, ULONG i, j, ModSize; PVOID ModStart; PCHAR DriverName; + PCHAR BootPath, HalPath; + CHAR CommandLine[256]; /* First get some kernel-loader globals */ AcpiTableDetected = (RosLoaderBlock->Flags & MB_FLAGS_ACPI_TABLE) ? TRUE : FALSE; @@ -256,6 +262,36 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, /* All we'll setup right now is the flag for text-mode setup */ LoaderBlock->SetupLdrBlock->Flags = 1; } + + /* Make a copy of the command line */ + strcpy(CommandLine, LoaderBlock->LoadOptions); + + /* Find the first \, separating the ARC path from NT path */ + BootPath = strchr(CommandLine, '\\'); + *BootPath = ANSI_NULL; + strncpy(BldrArcBootPath, CommandLine, 63); + LoaderBlock->ArcBootDeviceName = BldrArcBootPath; + + /* The rest of the string is the NT path */ + HalPath = strchr(BootPath + 1, ' '); + *HalPath = ANSI_NULL; + BldrNtBootPath[0] = '\\'; + strncat(BldrNtBootPath, BootPath + 1, 63); + strcat(BldrNtBootPath,"\\"); + LoaderBlock->NtBootPathName = BldrNtBootPath; + + /* Set the HAL paths */ + strncpy(BldrArcHalPath, BldrArcBootPath, 63); + LoaderBlock->ArcHalDeviceName = BldrArcHalPath; + strcpy(BldrNtHalPath, "\\"); + LoaderBlock->NtHalPathName = BldrNtHalPath; + + /* Use this new command line */ + strncpy(LoaderBlock->LoadOptions, HalPath + 2, 255); + + /* Parse it and change every slash to a space */ + BootPath = LoaderBlock->LoadOptions; + do {if (*BootPath == '/') *BootPath = ' ';} while (*BootPath++); } VOID diff --git a/reactos/ntoskrnl/po/power.c b/reactos/ntoskrnl/po/power.c index 1d336223195..ef7f7b8e37b 100644 --- a/reactos/ntoskrnl/po/power.c +++ b/reactos/ntoskrnl/po/power.c @@ -307,9 +307,20 @@ VOID INIT_FUNCTION NTAPI PoInit(BOOLEAN HaveAcpiTable, - BOOLEAN ForceAcpiDisable) + IN PLOADER_PARAMETER_BLOCK LoaderBlock) { PVOID NotificationEntry; + PCHAR CommandLine; + BOOLEAN ForceAcpiDisable = FALSE; + + /* Get the Command Line */ + CommandLine = KeLoaderBlock->LoadOptions; + + /* Upcase it */ + _strupr(CommandLine); + + /* Check for ACPI disable */ + if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE; if (ForceAcpiDisable) {