From e1cf9b2cdbfe2b1f5c6c4042d1eee1b787c4e550 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Tue, 19 Dec 2006 16:44:14 +0000 Subject: [PATCH] - Unlock lower 1Mb for use by memory manager, and properly mark all "unusable" places (except one place which is marked as strange). - Get rid of in-memory hardware registry, hwdetect functions which has not been converted yet to use configuration lists are #if0ed or not used for now. Reduces memory requirements a little. svn path=/branches/winldr/; revision=25191 --- arch/i386/hardware.c | 243 +++-------------------------------- arch/i386/hwpci.c | 85 +----------- include/arch/i386/hardware.h | 3 +- mm/meminit.c | 17 +-- windows/peloader.c | 4 +- windows/winldr.c | 3 - 6 files changed, 34 insertions(+), 321 deletions(-) diff --git a/arch/i386/hardware.c b/arch/i386/hardware.c index dea2a35bb63..977ed8111b5 100644 --- a/arch/i386/hardware.c +++ b/arch/i386/hardware.c @@ -261,7 +261,7 @@ SetComponentInformation(FRLDRHKEY ComponentKey, } } - +#if 0 static VOID DetectPnpBios(FRLDRHKEY SystemKey, ULONG *BusNumber) { @@ -420,7 +420,7 @@ DetectPnpBios(FRLDRHKEY SystemKey, ULONG *BusNumber) (int)Error)); } } - +#endif static VOID @@ -530,9 +530,7 @@ SetHarddiskIdentifier(PCHAR Identifier, static PCONFIGURATION_COMPONENT_DATA -DetectBiosDisks(FRLDRHKEY SystemKey, - FRLDRHKEY BusKey, - PCONFIGURATION_COMPONENT_DATA ComponentRoot, +DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA ComponentRoot, PCONFIGURATION_COMPONENT_DATA PreviousComponent, BOOLEAN NextChild) { @@ -774,7 +772,7 @@ DetectBiosDisks(FRLDRHKEY SystemKey, return DiskComponentData; } - +#if 0 static ULONG GetFloppyCount(VOID) { @@ -1670,7 +1668,7 @@ DetectParallelPorts(FRLDRHKEY BusKey) DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() done\n")); } - +#endif static BOOLEAN DetectKeyboardDevice(VOID) @@ -2101,129 +2099,9 @@ DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA ParentComponent, /* Return pointer to the mouse controller */ return ControllerComponent; - -#if 0 - CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor; - FRLDRHKEY ControllerKey; - FRLDRHKEY PeripheralKey; - LONG Error; - - if (DetectPS2AuxPort()) - { - DbgPrint((DPRINT_HWDETECT, "Detected PS2 port\n")); - - /* Create controller key */ - Error = RegCreateKey(BusKey, - L"PointerController\\0", - &ControllerKey); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "Failed to create controller key\n")); - return; - } - DbgPrint((DPRINT_HWDETECT, "Created key: PointerController\\0\n")); - - /* Set 'ComponentInformation' value */ - SetComponentInformation(ControllerKey, - 0x20, - 0, - 0xFFFFFFFF); - - memset(&FullResourceDescriptor, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR)); - - /* Initialize resource descriptor */ - FullResourceDescriptor.InterfaceType = Isa; - FullResourceDescriptor.BusNumber = 0; - FullResourceDescriptor.PartialResourceList.Version = 1; - FullResourceDescriptor.PartialResourceList.Revision = 1; - FullResourceDescriptor.PartialResourceList.Count = 1; - - /* Set Interrupt */ - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeInterrupt; - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareUndetermined; - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_INTERRUPT_LATCHED; - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Level = 0; - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector = 12; - FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity = 0xFFFFFFFF; - - /* Set 'Configuration Data' value */ - Error = RegSetValue(ControllerKey, - L"Configuration Data", - REG_FULL_RESOURCE_DESCRIPTOR, - (PCHAR)&FullResourceDescriptor, - sizeof(CM_FULL_RESOURCE_DESCRIPTOR)); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, - "RegSetValue(Configuration Data) failed (Error %u)\n", - (int)Error)); - return; - } - - - if (DetectPS2AuxDevice()) - { - DbgPrint((DPRINT_HWDETECT, "Detected PS2 mouse\n")); - - /* Create peripheral key */ - Error = RegCreateKey(ControllerKey, - L"PointerPeripheral\\0", - &PeripheralKey); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "Failed to create peripheral key\n")); - return; - } - DbgPrint((DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n")); - - /* Set 'ComponentInformation' value */ - SetComponentInformation(PeripheralKey, - 0x20, - 0, - 0xFFFFFFFF); - - /* Initialize resource descriptor */ - memset(&FullResourceDescriptor, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR)); - FullResourceDescriptor.InterfaceType = Isa; - FullResourceDescriptor.BusNumber = 0; - FullResourceDescriptor.PartialResourceList.Version = 1; - FullResourceDescriptor.PartialResourceList.Revision = 1; - FullResourceDescriptor.PartialResourceList.Count = 0; - - /* Set 'Configuration Data' value */ - Error = RegSetValue(PeripheralKey, - L"Configuration Data", - REG_FULL_RESOURCE_DESCRIPTOR, - (PCHAR)&FullResourceDescriptor, - sizeof(CM_FULL_RESOURCE_DESCRIPTOR) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, - "RegSetValue(Configuration Data) failed (Error %u)\n", - (int)Error)); - return; - } - - /* Set 'Identifier' value */ - Error = RegSetValue(PeripheralKey, - L"Identifier", - REG_SZ, - (PCHAR)L"MICROSOFT PS2 MOUSE", - 20 * sizeof(WCHAR)); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, - "RegSetValue() failed (Error %u)\n", - (int)Error)); - return; - } - } - } -#endif } - +#if 0 static VOID DetectDisplayController(FRLDRHKEY BusKey) { @@ -2291,92 +2169,21 @@ DetectDisplayController(FRLDRHKEY BusKey) /* FIXME: Add display peripheral (monitor) data */ } - +#endif static VOID -DetectIsaBios(FRLDRHKEY SystemKey, - ULONG *BusNumber, +DetectIsaBios(ULONG *BusNumber, PCONFIGURATION_COMPONENT_DATA ComponentRoot, PCONFIGURATION_COMPONENT_DATA PreviousComponent, BOOLEAN NextChild) { - PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor; PCONFIGURATION_COMPONENT_DATA IsaAdapter, LastComponent; PCONFIGURATION_COMPONENT IsaComponent; PVOID Identifier; - WCHAR Buffer[80]; - FRLDRHKEY BusKey; - ULONG Size; - LONG Error; - - /* Create new bus key */ - swprintf(Buffer, - L"MultifunctionAdapter\\%u", *BusNumber); - Error = RegCreateKey(SystemKey, - Buffer, - &BusKey); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "RegCreateKey() failed (Error %u)\n", (int)Error)); - return; - } - - /* Set 'Component Information' value similar to my NT4 box */ - SetComponentInformation(BusKey, - 0x0, - 0x0, - 0xFFFFFFFF); /* Increment bus number */ (*BusNumber)++; - /* Set 'Identifier' value */ - Error = RegSetValue(BusKey, - L"Identifier", - REG_SZ, - (PCHAR)L"ISA", - 4 * sizeof(WCHAR)); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "RegSetValue() failed (Error %u)\n", (int)Error)); - return; - } - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - FullResourceDescriptor = MmAllocateMemory(Size); - if (FullResourceDescriptor == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(FullResourceDescriptor, 0, Size); - FullResourceDescriptor->InterfaceType = Isa; - FullResourceDescriptor->BusNumber = 0; - FullResourceDescriptor->PartialResourceList.Version = 1; - FullResourceDescriptor->PartialResourceList.Revision = 1; - FullResourceDescriptor->PartialResourceList.Count = 0; - - /* Set 'Configuration Data' value */ - Error = RegSetValue(BusKey, - L"Configuration Data", - REG_FULL_RESOURCE_DESCRIPTOR, - (PCHAR) FullResourceDescriptor, - Size); - MmFreeMemory(FullResourceDescriptor); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, - "RegSetValue(Configuration Data) failed (Error %u)\n", - (int)Error)); - return; - } - - /* Create adapter component */ IsaAdapter = MmAllocateMemory(sizeof(CONFIGURATION_COMPONENT_DATA)); RtlZeroMemory(IsaAdapter, sizeof(CONFIGURATION_COMPONENT_DATA)); @@ -2408,13 +2215,13 @@ DetectIsaBios(FRLDRHKEY SystemKey, /* DetectBiosDisks writes information both to the root entry and to its own entries */ - LastComponent = DetectBiosDisks(SystemKey, BusKey, ComponentRoot, IsaAdapter, TRUE); + LastComponent = DetectBiosDisks(ComponentRoot, IsaAdapter, TRUE); - DetectBiosFloppyController(SystemKey, BusKey); + //DetectBiosFloppyController(SystemKey, BusKey); - DetectSerialPorts(BusKey); + //DetectSerialPorts(BusKey); - DetectParallelPorts(BusKey); + //DetectParallelPorts(BusKey); /* Detect keyboard and mouse */ LastComponent = @@ -2424,7 +2231,7 @@ DetectIsaBios(FRLDRHKEY SystemKey, LastComponent = DetectPS2Mouse(LastComponent, (IsaAdapter == LastComponent) ? TRUE : FALSE); - DetectDisplayController(BusKey); + //DetectDisplayController(BusKey); /* FIXME: Detect more ISA devices */ } @@ -2433,25 +2240,13 @@ DetectIsaBios(FRLDRHKEY SystemKey, VOID PcHwDetect(PCONFIGURATION_COMPONENT_DATA *ComponentRoot) { - FRLDRHKEY SystemKey; ULONG BusNumber = 0; - LONG Error; PCONFIGURATION_COMPONENT Component; PCONFIGURATION_COMPONENT_DATA LastComponentData; DbgPrint((DPRINT_HWDETECT, "DetectHardware()\n")); - /* Create the 'System' key */ - Error = RegCreateKey(NULL, - L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System", - &SystemKey); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "RegCreateKey() failed (Error %u)\n", (int)Error)); - return; - } - /* Allocate root configuration component */ *ComponentRoot = MmAllocateMemory(sizeof(CONFIGURATION_COMPONENT_DATA)); RtlZeroMemory(*ComponentRoot, sizeof(CONFIGURATION_COMPONENT_DATA)); @@ -2464,16 +2259,16 @@ PcHwDetect(PCONFIGURATION_COMPONENT_DATA *ComponentRoot) #if 0 DetectSystemData(); #endif - DetectCPUs(SystemKey); + //DetectCPUs(SystemKey); /* Detect buses */ /* FIXME: Don't forget situation when some buses may be absent! (NextChild = TRUE then) */ - LastComponentData = DetectPciBios(SystemKey, &BusNumber, *ComponentRoot, *ComponentRoot, TRUE); - DetectApmBios(SystemKey, &BusNumber); - DetectPnpBios(SystemKey, &BusNumber); - DetectIsaBios(SystemKey, &BusNumber, *ComponentRoot, LastComponentData, + LastComponentData = DetectPciBios(&BusNumber, *ComponentRoot, *ComponentRoot, TRUE); + //DetectApmBios(SystemKey, &BusNumber); + //DetectPnpBios(SystemKey, &BusNumber); + DetectIsaBios(&BusNumber, *ComponentRoot, LastComponentData, (LastComponentData == *ComponentRoot) ? TRUE : FALSE); - DetectAcpiBios(SystemKey, &BusNumber); + //DetectAcpiBios(SystemKey, &BusNumber); DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n")); diff --git a/arch/i386/hwpci.c b/arch/i386/hwpci.c index dee4d65108b..6f5ddb46269 100644 --- a/arch/i386/hwpci.c +++ b/arch/i386/hwpci.c @@ -62,7 +62,7 @@ typedef struct _CM_PCI_BUS_DATA UCHAR HardwareMechanism; } __attribute__((packed)) CM_PCI_BUS_DATA, *PCM_PCI_BUS_DATA; - +#if 0 static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable(VOID) { @@ -104,7 +104,7 @@ GetPciIrqRoutingTable(VOID) return NULL; } - +#endif static BOOLEAN FindPciBios(PCM_PCI_BUS_DATA BusData) @@ -140,7 +140,7 @@ FindPciBios(PCM_PCI_BUS_DATA BusData) return FALSE; } - +#if 0 static VOID DetectPciIrqRoutingTable(FRLDRHKEY BusKey) { @@ -225,11 +225,10 @@ DetectPciIrqRoutingTable(FRLDRHKEY BusKey) } } } - +#endif PCONFIGURATION_COMPONENT_DATA -DetectPciBios(FRLDRHKEY SystemKey, - ULONG *BusNumber, +DetectPciBios(ULONG *BusNumber, PCONFIGURATION_COMPONENT_DATA ComponentRoot, PCONFIGURATION_COMPONENT_DATA PreviousComponent, BOOLEAN NextChild) @@ -237,12 +236,8 @@ DetectPciBios(FRLDRHKEY SystemKey, PCONFIGURATION_COMPONENT_DATA PciBusComponentData, PreviousBusData; PCONFIGURATION_COMPONENT PciBusComponent; PVOID Identifier; - PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor; CM_PCI_BUS_DATA BusData; - WCHAR Buffer[80]; - FRLDRHKEY BiosKey; ULONG Size; - LONG Error; ULONG i; BOOLEAN NextComponentChild; @@ -253,77 +248,11 @@ DetectPciBios(FRLDRHKEY SystemKey, /* Report the PCI BIOS */ if (FindPciBios(&BusData)) { - /* Create new bus key */ - swprintf(Buffer, - L"MultifunctionAdapter\\%u", *BusNumber); - Error = RegCreateKey(SystemKey, - Buffer, - &BiosKey); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "RegCreateKey() failed (Error %u)\n", (int)Error)); - //return NULL; - } - - /* Set 'Component Information' */ - SetComponentInformation(BiosKey, - 0x0, - 0x0, - 0xFFFFFFFF); - /* Increment bus number */ (*BusNumber)++; - /* Set 'Identifier' value */ - Error = RegSetValue(BiosKey, - L"Identifier", - REG_SZ, - (PCHAR)L"PCI BIOS", - 9 * sizeof(WCHAR)); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, "RegSetValue() failed (Error %u)\n", (int)Error)); - //return NULL; - } - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR); - FullResourceDescriptor = MmAllocateMemory(Size); - if (FullResourceDescriptor == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - //return NULL; - } - - /* Initialize resource descriptor */ - memset(FullResourceDescriptor, 0, Size); - FullResourceDescriptor->InterfaceType = PCIBus; - FullResourceDescriptor->BusNumber = 0; - FullResourceDescriptor->PartialResourceList.Version = 1; - FullResourceDescriptor->PartialResourceList.Revision = 1; - FullResourceDescriptor->PartialResourceList.Count = 1; - FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeBusNumber; - FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive; - FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.BusNumber.Start = 0; - FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.BusNumber.Length = 1; - - /* Set 'Configuration Data' value */ - Error = RegSetValue(BiosKey, - L"Configuration Data", - REG_FULL_RESOURCE_DESCRIPTOR, - (PCHAR) FullResourceDescriptor, - Size); - MmFreeMemory(FullResourceDescriptor); - if (Error != ERROR_SUCCESS) - { - DbgPrint((DPRINT_HWDETECT, - "RegSetValue(Configuration Data) failed (Error %u)\n", - (int)Error)); - //return NULL; - } - - DetectPciIrqRoutingTable(BiosKey); + /* Detect PCI IRQ routing table and store it */ + //DetectPciIrqRoutingTable(BiosKey); /* Attach to the component we've got -- as child */ PreviousBusData = PreviousComponent; diff --git a/include/arch/i386/hardware.h b/include/arch/i386/hardware.h index 9550c5d214f..71f51e8ea82 100644 --- a/include/arch/i386/hardware.h +++ b/include/arch/i386/hardware.h @@ -76,8 +76,7 @@ VOID DetectApmBios(FRLDRHKEY SystemKey, ULONG *BusNumber); VOID DetectCPUs(FRLDRHKEY SystemKey); /* hwpci.c */ -PCONFIGURATION_COMPONENT_DATA DetectPciBios(FRLDRHKEY SystemKey, - ULONG *BusNumber, +PCONFIGURATION_COMPONENT_DATA DetectPciBios(ULONG *BusNumber, PCONFIGURATION_COMPONENT_DATA ComponentRoot, PCONFIGURATION_COMPONENT_DATA PreviousComponent, BOOLEAN NextChild); diff --git a/mm/meminit.c b/mm/meminit.c index 1f71e745703..a214a62c17e 100644 --- a/mm/meminit.c +++ b/mm/meminit.c @@ -98,24 +98,17 @@ BOOLEAN MmInitializeMemoryManager(VOID) // Add machine-dependent stuff // FIXME: this is only for i386 -#if 0 MmMarkPagesInLookupTable(PageLookupTableAddress, 0x00, 1, LoaderFirmwarePermanent); // realmode int vectors MmMarkPagesInLookupTable(PageLookupTableAddress, 0x01, 7, LoaderFirmwareTemporary); // freeldr stack + cmdline MmMarkPagesInLookupTable(PageLookupTableAddress, 0x08, 0x70, LoaderLoadedProgram); // freeldr image (roughly max. 0x64 pages) - MmMarkPagesInLookupTable(PageLookupTableAddress, 0x78, 8, LoaderOsloaderStack); // prot mode stack - - MmMarkPagesInLookupTable(PageLookupTableAddress, 0x80, 0x10, LoaderOsloaderHeap); // File system read buffer - MmMarkPagesInLookupTable(PageLookupTableAddress, 0x90, 0x10, LoaderOsloaderHeap); // Disk read buffer for int 13h - + MmMarkPagesInLookupTable(PageLookupTableAddress, 0x78, 8, LoaderOsloaderStack); // prot mode stack. BIOSCALLBUFFER + MmMarkPagesInLookupTable(PageLookupTableAddress, 0x80, 0x10, LoaderOsloaderHeap); // File system read buffer. FILESYSBUFFER + MmMarkPagesInLookupTable(PageLookupTableAddress, 0x90, 0x10, LoaderOsloaderHeap); // Disk read buffer for int 13h. DISKREADBUFFER MmMarkPagesInLookupTable(PageLookupTableAddress, 0xA0, 0x60, LoaderFirmwarePermanent); // ROM / Video -#endif - //HACK: Temporary, for test, remove soon - MmMarkPagesInLookupTable(PageLookupTableAddress, 0x00, 0x100, LoaderFirmwarePermanent); - MmMarkPagesInLookupTable(PageLookupTableAddress, 0xFFF, 1, LoaderSpecialMemory); // unusable memory - //HACK: Needed for ReactOS only! (KERNEL_BASE_PHYS >> MM_PAGE_SHIFT) - //MmMarkPagesInLookupTable(PageLookupTableAddress, 0x200, 0x300, LoaderFirmwareTemporary); // ReactOS kernel sits here + // This one is strange, without it WinNT crashes with PHASE0_EXCEPTION + MmMarkPagesInLookupTable(PageLookupTableAddress, 0x59, 0x5, LoaderFirmwarePermanent); FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress, TotalPagesInLookupTable); diff --git a/windows/peloader.c b/windows/peloader.c index a72d910aedf..3634e3f9056 100644 --- a/windows/peloader.c +++ b/windows/peloader.c @@ -307,8 +307,8 @@ WinLdrLoadImage(IN PCHAR FileName, /* Try to allocate this memory, if fails - allocate somewhere else */ PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage, - (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)), - MemoryType); + (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)), + MemoryType); if (PhysicalBase == NULL) { diff --git a/windows/winldr.c b/windows/winldr.c index 0a845f13ce0..461e59a1096 100644 --- a/windows/winldr.c +++ b/windows/winldr.c @@ -390,9 +390,6 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion) UiDrawStatusText("Detecting Hardware..."); UiDrawProgressBarCenter(1, 100, "Loading Windows..."); - //FIXME: This is needed only for MachHwDetect() which performs registry operations! - RegInitializeRegistry(); - /* Make sure the system path is set in the .ini file */ if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath))) {