From 2d834b1bdde5ceba4f28a04bc5ee8b44429c9052 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 9 Jul 2009 21:41:58 +0000 Subject: [PATCH] freeldr: Remove duplicated / unused files for amd64 architecture See issue #4672 for more details. svn path=/trunk/; revision=41834 --- .../freeldr/freeldr/arch/amd64/hardware.c | 1893 ----------------- .../boot/freeldr/freeldr/arch/amd64/hwacpi.c | 5 - .../boot/freeldr/freeldr/arch/amd64/hwapm.c | 98 - .../boot/freeldr/freeldr/arch/amd64/hwpci.c | 346 --- .../freeldr/freeldr/arch/amd64/i386disk.c | 199 -- .../boot/freeldr/freeldr/arch/amd64/i386rtl.c | 87 - .../boot/freeldr/freeldr/arch/amd64/i386vid.c | 244 --- .../boot/freeldr/freeldr/arch/amd64/mach.c | 70 - .../boot/freeldr/freeldr/arch/amd64/pccons.c | 128 -- .../boot/freeldr/freeldr/arch/amd64/pcdisk.c | 455 ---- .../boot/freeldr/freeldr/arch/amd64/pcmem.c | 249 --- .../boot/freeldr/freeldr/arch/amd64/pcrtc.c | 5 - .../boot/freeldr/freeldr/arch/amd64/pcvideo.c | 1122 ---------- 13 files changed, 4901 deletions(-) delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/hardware.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/hwacpi.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/hwapm.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/hwpci.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/i386disk.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/i386rtl.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/i386vid.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/mach.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/pccons.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/pcdisk.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/pcmem.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c delete mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/pcvideo.c diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/hardware.c b/reactos/boot/freeldr/freeldr/arch/amd64/hardware.c deleted file mode 100644 index f3a890d3b14..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/hardware.c +++ /dev/null @@ -1,1893 +0,0 @@ -/* - * FreeLoader - * - * Copyright (C) 2003, 2004 Eric Kohl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -#define MILLISEC (10) -#define PRECISION (8) - -#define HZ (100) -#define CLOCK_TICK_RATE (1193182) -#define LATCH (CLOCK_TICK_RATE / HZ) - - -/* No Mouse */ -#define MOUSE_TYPE_NONE 0 -/* Microsoft Mouse with 2 buttons */ -#define MOUSE_TYPE_MICROSOFT 1 -/* Logitech Mouse with 3 buttons */ -#define MOUSE_TYPE_LOGITECH 2 -/* Microsoft Wheel Mouse (aka Z Mouse) */ -#define MOUSE_TYPE_WHEELZ 3 -/* Mouse Systems Mouse */ -#define MOUSE_TYPE_MOUSESYSTEMS 4 - - -/* PS2 stuff */ - -/* Controller registers. */ -#define CONTROLLER_REGISTER_STATUS 0x64 -#define CONTROLLER_REGISTER_CONTROL 0x64 -#define CONTROLLER_REGISTER_DATA 0x60 - -/* Controller commands. */ -#define CONTROLLER_COMMAND_READ_MODE 0x20 -#define CONTROLLER_COMMAND_WRITE_MODE 0x60 -#define CONTROLLER_COMMAND_GET_VERSION 0xA1 -#define CONTROLLER_COMMAND_MOUSE_DISABLE 0xA7 -#define CONTROLLER_COMMAND_MOUSE_ENABLE 0xA8 -#define CONTROLLER_COMMAND_TEST_MOUSE 0xA9 -#define CONTROLLER_COMMAND_SELF_TEST 0xAA -#define CONTROLLER_COMMAND_KEYBOARD_TEST 0xAB -#define CONTROLLER_COMMAND_KEYBOARD_DISABLE 0xAD -#define CONTROLLER_COMMAND_KEYBOARD_ENABLE 0xAE -#define CONTROLLER_COMMAND_WRITE_MOUSE_OUTPUT_BUFFER 0xD3 -#define CONTROLLER_COMMAND_WRITE_MOUSE 0xD4 - -/* Controller status */ -#define CONTROLLER_STATUS_OUTPUT_BUFFER_FULL 0x01 -#define CONTROLLER_STATUS_INPUT_BUFFER_FULL 0x02 -#define CONTROLLER_STATUS_SELF_TEST 0x04 -#define CONTROLLER_STATUS_COMMAND 0x08 -#define CONTROLLER_STATUS_UNLOCKED 0x10 -#define CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL 0x20 -#define CONTROLLER_STATUS_GENERAL_TIMEOUT 0x40 -#define CONTROLLER_STATUS_PARITY_ERROR 0x80 -#define AUX_STATUS_OUTPUT_BUFFER_FULL (CONTROLLER_STATUS_OUTPUT_BUFFER_FULL | \ - CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL) - -/* Timeout in ms for sending to keyboard controller. */ -#define CONTROLLER_TIMEOUT 250 - -static CHAR Hex[] = "0123456789abcdef"; -static unsigned int delay_count = 1; - -extern ULONG reactos_disk_count; -extern ARC_DISK_SIGNATURE reactos_arc_disk_info[]; -extern char reactos_arc_strings[32][256]; - -/* FUNCTIONS ****************************************************************/ - - -static VOID -__StallExecutionProcessor(ULONG Loops) -{ - volatile register unsigned int i; - for (i = 0; i < Loops; i++); -} - - -VOID StallExecutionProcessor(ULONG Microseconds) -{ - ULONGLONG LoopCount = ((ULONGLONG)delay_count * (ULONGLONG)Microseconds) / 1000ULL; - __StallExecutionProcessor((ULONG)LoopCount); -} - - -static ULONG -Read8254Timer(VOID) -{ - ULONG Count; - - WRITE_PORT_UCHAR((PUCHAR)0x43, 0x00); - Count = READ_PORT_UCHAR((PUCHAR)0x40); - Count |= READ_PORT_UCHAR((PUCHAR)0x40) << 8; - - return Count; -} - - -static VOID -WaitFor8254Wraparound(VOID) -{ - ULONG CurCount; - ULONG PrevCount = ~0; - LONG Delta; - - CurCount = Read8254Timer(); - - do - { - PrevCount = CurCount; - CurCount = Read8254Timer(); - Delta = CurCount - PrevCount; - - /* - * This limit for delta seems arbitrary, but it isn't, it's - * slightly above the level of error a buggy Mercury/Neptune - * chipset timer can cause. - */ - } - while (Delta < 300); -} - - -VOID -HalpCalibrateStallExecution(VOID) -{ - ULONG i; - ULONG calib_bit; - ULONG CurCount; - - /* Initialise timer interrupt with MILLISECOND ms interval */ - WRITE_PORT_UCHAR((PUCHAR)0x43, 0x34); /* binary, mode 2, LSB/MSB, ch 0 */ - WRITE_PORT_UCHAR((PUCHAR)0x40, LATCH & 0xff); /* LSB */ - WRITE_PORT_UCHAR((PUCHAR)0x40, LATCH >> 8); /* MSB */ - - /* Stage 1: Coarse calibration */ - - WaitFor8254Wraparound(); - - delay_count = 1; - - do { - delay_count <<= 1; /* Next delay count to try */ - - WaitFor8254Wraparound(); - - __StallExecutionProcessor(delay_count); /* Do the delay */ - - CurCount = Read8254Timer(); - } while (CurCount > LATCH / 2); - - delay_count >>= 1; /* Get bottom value for delay */ - - /* Stage 2: Fine calibration */ - - calib_bit = delay_count; /* Which bit are we going to test */ - - for(i=0;i>= 1; /* Next bit to calibrate */ - if(!calib_bit) break; /* If we have done all bits, stop */ - - delay_count |= calib_bit; /* Set the bit in delay_count */ - - WaitFor8254Wraparound(); - - __StallExecutionProcessor(delay_count); /* Do the delay */ - - CurCount = Read8254Timer(); - if (CurCount <= LATCH / 2) /* If a tick has passed, turn the */ - delay_count &= ~calib_bit; /* calibrated bit back off */ - } - - /* We're finished: Do the finishing touches */ - delay_count /= (MILLISEC / 2); /* Calculate delay_count for 1ms */ -} - -static VOID -DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PNP_BIOS_DEVICE_NODE DeviceNode; - PCM_PNP_BIOS_INSTALLATION_CHECK InstData; - PCONFIGURATION_COMPONENT_DATA BusKey; - ULONG x; - ULONG NodeSize = 0; - ULONG NodeCount = 0; - UCHAR NodeNumber; - ULONG FoundNodeCount; - int i; - ULONG PnpBufferSize; - ULONG Size; - char *Ptr; - - InstData = (PCM_PNP_BIOS_INSTALLATION_CHECK)PnpBiosSupported(); - if (InstData == NULL || strncmp((CHAR*)InstData->Signature, "$PnP", 4)) - { - DbgPrint((DPRINT_HWDETECT, "PnP-BIOS not supported\n")); - return; - } - DbgPrint((DPRINT_HWDETECT, "Signature '%c%c%c%c'\n", - InstData->Signature[0], InstData->Signature[1], - InstData->Signature[2], InstData->Signature[3])); - - - x = PnpBiosGetDeviceNodeCount(&NodeSize, &NodeCount); - NodeCount &= 0xFF; // needed since some fscked up BIOSes return - // wrong info (e.g. Mac Virtual PC) - // e.g. look: http://my.execpc.com/~geezer/osd/pnp/pnp16.c - if (x != 0 || NodeSize == 0 || NodeCount == 0) - { - DbgPrint((DPRINT_HWDETECT, "PnP-BIOS failed to enumerate device nodes\n")); - return; - } - DbgPrint((DPRINT_HWDETECT, "PnP-BIOS supported\n")); - DbgPrint((DPRINT_HWDETECT, "MaxNodeSize %u NodeCount %u\n", NodeSize, NodeCount)); - DbgPrint((DPRINT_HWDETECT, "Estimated buffer size %u\n", NodeSize * NodeCount)); - - /* Create component key */ - FldrCreateComponentKey(SystemKey, - L"MultifunctionAdapter", - *BusNumber, - AdapterClass, - MultiFunctionAdapter, - &BusKey); - (*BusNumber)++; - - /* Set the component information */ - FldrSetComponentInformation(BusKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Set the identifier */ - FldrSetIdentifier(BusKey, "PNP BIOS"); - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + (NodeSize * NodeCount); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - memset(PartialResourceList, 0, Size); - - /* Initialize resource descriptor */ - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - PartialResourceList->PartialDescriptors[0].Type = - CmResourceTypeDeviceSpecific; - PartialResourceList->PartialDescriptors[0].ShareDisposition = - CmResourceShareUndetermined; - - Ptr = (char *)(((ULONG_PTR)&PartialResourceList->PartialDescriptors[0]) + - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); - - /* Set instalation check data */ - memcpy (Ptr, InstData, sizeof(CM_PNP_BIOS_INSTALLATION_CHECK)); - Ptr += sizeof(CM_PNP_BIOS_INSTALLATION_CHECK); - - /* Copy device nodes */ - FoundNodeCount = 0; - PnpBufferSize = sizeof(CM_PNP_BIOS_INSTALLATION_CHECK); - for (i = 0; i < 0xFF; i++) - { - NodeNumber = (UCHAR)i; - - x = PnpBiosGetDeviceNode(&NodeNumber, (PVOID)DISKREADBUFFER); - if (x == 0) - { - DeviceNode = (PCM_PNP_BIOS_DEVICE_NODE)DISKREADBUFFER; - - DbgPrint((DPRINT_HWDETECT, - "Node: %u Size %u (0x%x)\n", - DeviceNode->Node, - DeviceNode->Size, - DeviceNode->Size)); - - memcpy (Ptr, - DeviceNode, - DeviceNode->Size); - - Ptr += DeviceNode->Size; - PnpBufferSize += DeviceNode->Size; - - FoundNodeCount++; - if (FoundNodeCount >= NodeCount) - break; - } - } - - /* Set real data size */ - PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize = - PnpBufferSize; - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + PnpBufferSize; - - DbgPrint((DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize)); - DbgPrint((DPRINT_HWDETECT, "Resource size: %u\n", Size)); - - FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); -} - - - -static VOID -SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey, - ULONG DriveNumber) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; - EXTENDED_GEOMETRY ExtGeometry; - GEOMETRY Geometry; - ULONG Size; - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - sizeof(CM_DISK_GEOMETRY_DEVICE_DATA); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate a full resource descriptor\n")); - return; - } - - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - PartialResourceList->PartialDescriptors[0].Type = - CmResourceTypeDeviceSpecific; -// PartialResourceList->PartialDescriptors[0].ShareDisposition = -// PartialResourceList->PartialDescriptors[0].Flags = - PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize = - sizeof(CM_DISK_GEOMETRY_DEVICE_DATA); - - /* Get pointer to geometry data */ - DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); - - /* Get the disk geometry */ - ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY); - if (DiskGetExtendedDriveParameters(DriveNumber, &ExtGeometry, ExtGeometry.Size)) - { - DiskGeometry->BytesPerSector = ExtGeometry.BytesPerSector; - DiskGeometry->NumberOfCylinders = ExtGeometry.Cylinders; - DiskGeometry->SectorsPerTrack = ExtGeometry.SectorsPerTrack; - DiskGeometry->NumberOfHeads = ExtGeometry.Heads; - } - else if(MachDiskGetDriveGeometry(DriveNumber, &Geometry)) - { - DiskGeometry->BytesPerSector = Geometry.BytesPerSector; - DiskGeometry->NumberOfCylinders = Geometry.Cylinders; - DiskGeometry->SectorsPerTrack = Geometry.Sectors; - DiskGeometry->NumberOfHeads = Geometry.Heads; - } - else - { - DbgPrint((DPRINT_HWDETECT, "Reading disk geometry failed\n")); - MmHeapFree(PartialResourceList); - return; - } - DbgPrint((DPRINT_HWDETECT, - "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n", - DriveNumber, - DiskGeometry->NumberOfCylinders, - DiskGeometry->NumberOfHeads, - DiskGeometry->SectorsPerTrack, - DiskGeometry->BytesPerSector)); - - FldrSetConfigurationData(DiskKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); -} - - -static VOID -SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey, - ULONG DriveNumber) -{ - PMASTER_BOOT_RECORD Mbr; - ULONG *Buffer; - ULONG i; - ULONG Checksum; - ULONG Signature; - CHAR Identifier[20]; - CHAR ArcName[256]; - - /* Read the MBR */ - if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, (PVOID)DISKREADBUFFER)) - { - DbgPrint((DPRINT_HWDETECT, "Reading MBR failed\n")); - return; - } - - Buffer = (ULONG*)DISKREADBUFFER; - Mbr = (PMASTER_BOOT_RECORD)DISKREADBUFFER; - - Signature = Mbr->Signature; - DbgPrint((DPRINT_HWDETECT, "Signature: %x\n", Signature)); - - /* Calculate the MBR checksum */ - Checksum = 0; - for (i = 0; i < 128; i++) - { - Checksum += Buffer[i]; - } - Checksum = ~Checksum + 1; - DbgPrint((DPRINT_HWDETECT, "Checksum: %x\n", Checksum)); - - /* Fill out the ARC disk block */ - reactos_arc_disk_info[reactos_disk_count].Signature = Signature; - reactos_arc_disk_info[reactos_disk_count].CheckSum = Checksum; - sprintf(ArcName, "multi(0)disk(0)rdisk(%lu)", reactos_disk_count); - strcpy(reactos_arc_strings[reactos_disk_count], ArcName); - reactos_arc_disk_info[reactos_disk_count].ArcName = - reactos_arc_strings[reactos_disk_count]; - reactos_disk_count++; - - /* Convert checksum and signature to identifier string */ - Identifier[0] = Hex[(Checksum >> 28) & 0x0F]; - Identifier[1] = Hex[(Checksum >> 24) & 0x0F]; - Identifier[2] = Hex[(Checksum >> 20) & 0x0F]; - Identifier[3] = Hex[(Checksum >> 16) & 0x0F]; - Identifier[4] = Hex[(Checksum >> 12) & 0x0F]; - Identifier[5] = Hex[(Checksum >> 8) & 0x0F]; - Identifier[6] = Hex[(Checksum >> 4) & 0x0F]; - Identifier[7] = Hex[Checksum & 0x0F]; - Identifier[8] = '-'; - Identifier[9] = Hex[(Signature >> 28) & 0x0F]; - Identifier[10] = Hex[(Signature >> 24) & 0x0F]; - Identifier[11] = Hex[(Signature >> 20) & 0x0F]; - Identifier[12] = Hex[(Signature >> 16) & 0x0F]; - Identifier[13] = Hex[(Signature >> 12) & 0x0F]; - Identifier[14] = Hex[(Signature >> 8) & 0x0F]; - Identifier[15] = Hex[(Signature >> 4) & 0x0F]; - Identifier[16] = Hex[Signature & 0x0F]; - Identifier[17] = '-'; - Identifier[18] = 'A'; - Identifier[19] = 0; - DbgPrint((DPRINT_HWDETECT, "Identifier: %s\n", Identifier)); - - /* Set identifier */ - FldrSetIdentifier(DiskKey, Identifier); -} - -static ULONG -GetFloppyCount(VOID) -{ - UCHAR Data; - - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x10); - Data = READ_PORT_UCHAR((PUCHAR)0x71); - - return ((Data & 0xF0) ? 1 : 0) + ((Data & 0x0F) ? 1 : 0); -} - - -static UCHAR -GetFloppyType(UCHAR DriveNumber) -{ - UCHAR Data; - - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x10); - Data = READ_PORT_UCHAR((PUCHAR)0x71); - - if (DriveNumber == 0) - return Data >> 4; - else if (DriveNumber == 1) - return Data & 0x0F; - - return 0; -} - - -static PVOID -GetInt1eTable(VOID) -{ - PUSHORT SegPtr = (PUSHORT)0x7A; - PUSHORT OfsPtr = (PUSHORT)0x78; - - return (PVOID)((ULONG_PTR)(((ULONG)(*SegPtr)) << 4) + (ULONG)(*OfsPtr)); -} - - -static VOID -DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCM_FLOPPY_DEVICE_DATA FloppyData; - CHAR Identifier[20]; - PCONFIGURATION_COMPONENT_DATA PeripheralKey; - ULONG Size; - ULONG FloppyNumber; - UCHAR FloppyType; - ULONG MaxDensity[6] = {0, 360, 1200, 720, 1440, 2880}; - PUCHAR Ptr; - - for (FloppyNumber = 0; FloppyNumber < 2; FloppyNumber++) - { - FloppyType = GetFloppyType(FloppyNumber); - - if ((FloppyType > 5) || (FloppyType == 0)) - continue; - - DiskResetController(FloppyNumber); - - Ptr = GetInt1eTable(); - - FldrCreateComponentKey(ControllerKey, - L"FloppyDiskPeripheral", - FloppyNumber, - PeripheralClass, - FloppyDiskPeripheral, - &PeripheralKey); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(PeripheralKey, - Input | Output, - FloppyNumber, - 0xFFFFFFFF); - - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - sizeof(CM_FLOPPY_DEVICE_DATA); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypeDeviceSpecific; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_FLOPPY_DEVICE_DATA); - - FloppyData = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); - FloppyData->Version = 2; - FloppyData->Revision = 0; - FloppyData->MaxDensity = MaxDensity[FloppyType]; - FloppyData->MountDensity = 0; - RtlCopyMemory(&FloppyData->StepRateHeadUnloadTime, - Ptr, - 11); - FloppyData->MaximumTrackValue = (FloppyType == 1) ? 39 : 79; - FloppyData->DataTransferRate = 0; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Set 'Identifier' value */ - sprintf(Identifier, "FLOPPY%ld", FloppyNumber + 1); - FldrSetIdentifier(PeripheralKey, Identifier); - } -} - - -static VOID -DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey, - PCONFIGURATION_COMPONENT_DATA ControllerKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - ULONG Size; - ULONG FloppyCount; - - FloppyCount = GetFloppyCount(); - DbgPrint((DPRINT_HWDETECT, - "Floppy count: %u\n", - FloppyCount)); - - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - memset(PartialResourceList, 0, Size); - - /* Initialize resource descriptor */ - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 3; - - /* Set IO Port */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = CM_RESOURCE_PORT_IO; - PartialDescriptor->u.Port.Start.LowPart = 0x03F0; - PartialDescriptor->u.Port.Start.HighPart = 0x0; - PartialDescriptor->u.Port.Length = 8; - - /* Set Interrupt */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; - PartialDescriptor->Type = CmResourceTypeInterrupt; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED; - PartialDescriptor->u.Interrupt.Level = 6; - PartialDescriptor->u.Interrupt.Vector = 6; - PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF; - - /* Set DMA channel */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[2]; - PartialDescriptor->Type = CmResourceTypeDma; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = 0; - PartialDescriptor->u.Dma.Channel = 2; - PartialDescriptor->u.Dma.Port = 0; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - if (FloppyCount) DetectBiosFloppyPeripheral(ControllerKey); -} - -static VOID -DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey, - PCONFIGURATION_COMPONENT_DATA BusKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_INT13_DRIVE_PARAMETER Int13Drives; - GEOMETRY Geometry; - PCONFIGURATION_COMPONENT_DATA DiskKey, ControllerKey; - ULONG DiskCount; - ULONG Size; - ULONG i; - BOOLEAN Changed; - - /* Count the number of visible drives */ - DiskReportError(FALSE); - DiskCount = 0; - - /* There are some really broken BIOSes out there. There are even BIOSes - * that happily report success when you ask them to read from non-existent - * harddisks. So, we set the buffer to known contents first, then try to - * read. If the BIOS reports success but the buffer contents haven't - * changed then we fail anyway */ - memset((PVOID) DISKREADBUFFER, 0xcd, 512); - while (MachDiskReadLogicalSectors(0x80 + DiskCount, 0ULL, 1, (PVOID)DISKREADBUFFER)) - { - Changed = FALSE; - for (i = 0; ! Changed && i < 512; i++) - { - Changed = ((PUCHAR)DISKREADBUFFER)[i] != 0xcd; - } - if (! Changed) - { - DbgPrint((DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n", - (int)DiskCount)); - break; - } - DiskCount++; - memset((PVOID) DISKREADBUFFER, 0xcd, 512); - } - DiskReportError(TRUE); - DbgPrint((DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n", - (int)DiskCount, (DiskCount == 1) ? "": "s")); - - FldrCreateComponentKey(BusKey, - L"DiskController", - 0, - ControllerClass, - DiskController, - &ControllerKey); - DbgPrint((DPRINT_HWDETECT, "Created key: DiskController\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - Output | Input | Removable, - 0, - 0xFFFFFFFF); - - DetectBiosFloppyController(BusKey, ControllerKey); - - /* Allocate resource descriptor */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount; - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - PartialResourceList->PartialDescriptors[0].Type = CmResourceTypeDeviceSpecific; - PartialResourceList->PartialDescriptors[0].ShareDisposition = 0; - PartialResourceList->PartialDescriptors[0].Flags = 0; - PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize = - sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount; - - /* Get harddisk Int13 geometry data */ - Int13Drives = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); - for (i = 0; i < DiskCount; i++) - { - if (MachDiskGetDriveGeometry(0x80 + i, &Geometry)) - { - Int13Drives[i].DriveSelect = 0x80 + i; - Int13Drives[i].MaxCylinders = Geometry.Cylinders - 1; - Int13Drives[i].SectorsPerTrack = Geometry.Sectors; - Int13Drives[i].MaxHeads = Geometry.Heads - 1; - Int13Drives[i].NumberDrives = DiskCount; - - DbgPrint((DPRINT_HWDETECT, - "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n", - 0x80 + i, - Geometry.Cylinders - 1, - Geometry.Heads -1, - Geometry.Sectors, - Geometry.BytesPerSector)); - } - } - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(SystemKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Create and fill subkey for each harddisk */ - for (i = 0; i < DiskCount; i++) - { - /* Create disk key */ - FldrCreateComponentKey(ControllerKey, - L"DiskPeripheral", - i, - PeripheralClass, - DiskPeripheral, - &DiskKey); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(DiskKey, - Output | Input, - 0, - 0xFFFFFFFF); - - /* Set disk values */ - SetHarddiskConfigurationData(DiskKey, 0x80 + i); - SetHarddiskIdentifier(DiskKey, 0x80 + i); - } -} - -static VOID -InitializeSerialPort(ULONG Port, - ULONG LineControl) -{ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 3, 0x80); /* set DLAB on */ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port, 0x60); /* speed LO byte */ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 1, 0); /* speed HI byte */ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 3, LineControl); - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 1, 0); /* set comm and DLAB to 0 */ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4, 0x09); /* DR int enable */ - READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 5); /* clear error bits */ -} - - -static ULONG -DetectSerialMouse(ULONG Port) -{ - CHAR Buffer[4]; - ULONG i; - ULONG TimeOut; - UCHAR LineControl; - - /* Shutdown mouse or something like that */ - LineControl = READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4); - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4, (LineControl & ~0x02) | 0x01); - StallExecutionProcessor(100000); - - /* - * Clear buffer - * Maybe there is no serial port although BIOS reported one (this - * is the case on Apple hardware), or the serial port is misbehaving, - * therefore we must give up after some time. - */ - TimeOut = 200; - while (READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 5) & 0x01) - { - if (--TimeOut == 0) - return MOUSE_TYPE_NONE; - READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port); - } - - /* - * Send modem control with 'Data Terminal Ready', 'Request To Send' and - * 'Output Line 2' message. This enables mouse to identify. - */ - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4, 0x0b); - - /* Wait 10 milliseconds for the mouse getting ready */ - StallExecutionProcessor(10000); - - /* Read first four bytes, which contains Microsoft Mouse signs */ - TimeOut = 200; - for (i = 0; i < 4; i++) - { - while (((READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 5) & 1) == 0) && (TimeOut > 0)) - { - StallExecutionProcessor(1000); - --TimeOut; - if (TimeOut == 0) - return MOUSE_TYPE_NONE; - } - Buffer[i] = READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port); - } - - DbgPrint((DPRINT_HWDETECT, - "Mouse data: %x %x %x %x\n", - Buffer[0],Buffer[1],Buffer[2],Buffer[3])); - - /* Check that four bytes for signs */ - for (i = 0; i < 4; ++i) - { - if (Buffer[i] == 'B') - { - /* Sign for Microsoft Ballpoint */ -// DbgPrint("Microsoft Ballpoint device detected\n"); -// DbgPrint("THIS DEVICE IS NOT SUPPORTED, YET\n"); - return MOUSE_TYPE_NONE; - } - else if (Buffer[i] == 'M') - { - /* Sign for Microsoft Mouse protocol followed by button specifier */ - if (i == 3) - { - /* Overflow Error */ - return MOUSE_TYPE_NONE; - } - - switch (Buffer[i + 1]) - { - case '3': - DbgPrint((DPRINT_HWDETECT, - "Microsoft Mouse with 3-buttons detected\n")); - return MOUSE_TYPE_LOGITECH; - - case 'Z': - DbgPrint((DPRINT_HWDETECT, - "Microsoft Wheel Mouse detected\n")); - return MOUSE_TYPE_WHEELZ; - - /* case '2': */ - default: - DbgPrint((DPRINT_HWDETECT, - "Microsoft Mouse with 2-buttons detected\n")); - return MOUSE_TYPE_MICROSOFT; - } - } - } - - return MOUSE_TYPE_NONE; -} - - -static ULONG -GetSerialMousePnpId(ULONG Port, char *Buffer) -{ - ULONG TimeOut; - ULONG i = 0; - char c; - char x; - - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4, 0x09); - - /* Wait 10 milliseconds for the mouse getting ready */ - StallExecutionProcessor(10000); - - WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 4, 0x0b); - - StallExecutionProcessor(10000); - - for (;;) - { - TimeOut = 200; - while (((READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 5) & 1) == 0) && (TimeOut > 0)) - { - StallExecutionProcessor(1000); - --TimeOut; - if (TimeOut == 0) - { - return 0; - } - } - - c = READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port); - if (c == 0x08 || c == 0x28) - break; - } - - Buffer[i++] = c; - x = c + 1; - - for (;;) - { - TimeOut = 200; - while (((READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port + 5) & 1) == 0) && (TimeOut > 0)) - { - StallExecutionProcessor(1000); - --TimeOut; - if (TimeOut == 0) - return 0; - } - c = READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)Port); - Buffer[i++] = c; - if (c == x) - break; - if (i >= 256) - break; - } - - return i; -} - - -static VOID -DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey, - ULONG Base) -{ - CM_PARTIAL_RESOURCE_LIST PartialResourceList; - char Buffer[256]; - CHAR Identifier[256]; - PCONFIGURATION_COMPONENT_DATA PeripheralKey; - ULONG MouseType; - ULONG Length; - ULONG i; - ULONG j; - ULONG k; - - DbgPrint((DPRINT_HWDETECT, - "DetectSerialPointerPeripheral()\n")); - - Identifier[0] = 0; - - InitializeSerialPort(Base, 2); - MouseType = DetectSerialMouse(Base); - - if (MouseType != MOUSE_TYPE_NONE) - { - Length = GetSerialMousePnpId(Base, Buffer); - DbgPrint((DPRINT_HWDETECT, - "PnP ID length: %u\n", - Length)); - - if (Length != 0) - { - /* Convert PnP sting to ASCII */ - if (Buffer[0] == 0x08) - { - for (i = 0; i < Length; i++) - Buffer[i] += 0x20; - } - Buffer[Length] = 0; - - DbgPrint((DPRINT_HWDETECT, - "PnP ID string: %s\n", - Buffer)); - - /* Copy PnpId string */ - for (i = 0; i < 7; i++) - { - Identifier[i] = Buffer[3+i]; - } - memcpy(&Identifier[7], - L" - ", - 3 * sizeof(WCHAR)); - - /* Skip device serial number */ - i = 10; - if (Buffer[i] == '\\') - { - for (j = ++i; i < Length; ++i) - { - if (Buffer[i] == '\\') - break; - } - if (i >= Length) - i -= 3; - } - - /* Skip PnP class */ - if (Buffer[i] == '\\') - { - for (j = ++i; i < Length; ++i) - { - if (Buffer[i] == '\\') - break; - } - - if (i >= Length) - i -= 3; - } - - /* Skip compatible PnP Id */ - if (Buffer[i] == '\\') - { - for (j = ++i; i < Length; ++i) - { - if (Buffer[i] == '\\') - break; - } - if (Buffer[j] == '*') - ++j; - if (i >= Length) - i -= 3; - } - - /* Get product description */ - if (Buffer[i] == '\\') - { - for (j = ++i; i < Length; ++i) - { - if (Buffer[i] == ';') - break; - } - if (i >= Length) - i -= 3; - if (i > j + 1) - { - for (k = 0; k < i - j; k++) - { - Identifier[k + 10] = Buffer[k + j]; - } - Identifier[10 + (i-j)] = 0; - } - } - - DbgPrint((DPRINT_HWDETECT, - "Identifier string: %s\n", - Identifier)); - } - - if (Length == 0 || strlen(Identifier) < 11) - { - switch (MouseType) - { - case MOUSE_TYPE_LOGITECH: - strcpy (Identifier, - "LOGITECH SERIAL MOUSE"); - break; - - case MOUSE_TYPE_WHEELZ: - strcpy (Identifier, - "MICROSOFT SERIAL MOUSE WITH WHEEL"); - break; - - case MOUSE_TYPE_MICROSOFT: - default: - strcpy (Identifier, - "MICROSOFT SERIAL MOUSE"); - break; - } - } - - /* Create 'PointerPeripheral' key */ - FldrCreateComponentKey(ControllerKey, - L"PointerPeripheral", - 0, - PeripheralClass, - PointerPeripheral, - &PeripheralKey); - DbgPrint((DPRINT_HWDETECT, - "Created key: PointerPeripheral\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(PeripheralKey, - Input, - 0, - 0xFFFFFFFF); - - /* Set 'Configuration Data' value */ - memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST)); - PartialResourceList.Version = 1; - PartialResourceList.Revision = 1; - PartialResourceList.Count = 0; - - FldrSetConfigurationData(PeripheralKey, - &PartialResourceList, - sizeof(CM_PARTIAL_RESOURCE_LIST) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); - - /* Set 'Identifier' value */ - FldrSetIdentifier(PeripheralKey, Identifier); - } -} - - -static VOID -DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCM_SERIAL_DEVICE_DATA SerialDeviceData; - ULONG Irq[4] = {4, 3, 4, 3}; - ULONG Base; - CHAR Buffer[80]; - PUSHORT BasePtr; - ULONG ControllerNumber = 0; - PCONFIGURATION_COMPONENT_DATA ControllerKey; - ULONG i; - ULONG Size; - - DbgPrint((DPRINT_HWDETECT, "DetectSerialPorts()\n")); - - ControllerNumber = 0; - BasePtr = (PUSHORT)0x400; - for (i = 0; i < 4; i++, BasePtr++) - { - Base = (ULONG)*BasePtr; - if (Base == 0) - continue; - - DbgPrint((DPRINT_HWDETECT, - "Found COM%u port at 0x%x\n", - i + 1, - Base)); - - /* Create controller key */ - FldrCreateComponentKey(BusKey, - L"SerialController", - ControllerNumber, - ControllerClass, - SerialController, - &ControllerKey); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - Output | Input | ConsoleIn | ConsoleOut, - ControllerNumber, - 0xFFFFFFFF); - - /* Build full device descriptor */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + - sizeof(CM_SERIAL_DEVICE_DATA); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - continue; - } - memset(PartialResourceList, 0, Size); - - /* Initialize resource descriptor */ - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 3; - - /* Set IO Port */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = CM_RESOURCE_PORT_IO; - PartialDescriptor->u.Port.Start.LowPart = Base; - PartialDescriptor->u.Port.Start.HighPart = 0x0; - PartialDescriptor->u.Port.Length = 7; - - /* Set Interrupt */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; - PartialDescriptor->Type = CmResourceTypeInterrupt; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED; - PartialDescriptor->u.Interrupt.Level = Irq[i]; - PartialDescriptor->u.Interrupt.Vector = 0; - PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF; - - /* Set serial data (device specific) */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[2]; - PartialDescriptor->Type = CmResourceTypeDeviceSpecific; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = 0; - PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_SERIAL_DEVICE_DATA); - - SerialDeviceData = - (PCM_SERIAL_DEVICE_DATA)&PartialResourceList->PartialDescriptors[3]; - SerialDeviceData->BaudClock = 1843200; /* UART Clock frequency (Hertz) */ - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Set 'Identifier' value */ - sprintf(Buffer, "COM%ld", i + 1); - FldrSetIdentifier(ControllerKey, Buffer); - DbgPrint((DPRINT_HWDETECT, - "Created value: Identifier %s\n", - Buffer)); - - if (!Rs232PortInUse(Base)) - { - /* Detect serial mouse */ - DetectSerialPointerPeripheral(ControllerKey, Base); - } - - ControllerNumber++; - } -} - - -static VOID -DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - ULONG Irq[3] = {7, 5, (ULONG)-1}; - CHAR Buffer[80]; - PCONFIGURATION_COMPONENT_DATA ControllerKey; - PUSHORT BasePtr; - ULONG Base; - ULONG ControllerNumber; - ULONG i; - ULONG Size; - - DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() called\n")); - - ControllerNumber = 0; - BasePtr = (PUSHORT)0x408; - for (i = 0; i < 3; i++, BasePtr++) - { - Base = (ULONG)*BasePtr; - if (Base == 0) - continue; - - DbgPrint((DPRINT_HWDETECT, - "Parallel port %u: %x\n", - ControllerNumber, - Base)); - - /* Create controller key */ - FldrCreateComponentKey(BusKey, - L"ParallelController", - ControllerNumber, - ControllerClass, - ParallelController, - &ControllerKey); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - Output, - ControllerNumber, - 0xFFFFFFFF); - - /* Build full device descriptor */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST); - if (Irq[i] != (ULONG)-1) - Size += sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - continue; - } - memset(PartialResourceList, 0, Size); - - /* Initialize resource descriptor */ - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = (Irq[i] != (ULONG)-1) ? 2 : 1; - - /* Set IO Port */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = CM_RESOURCE_PORT_IO; - PartialDescriptor->u.Port.Start.LowPart = Base; - PartialDescriptor->u.Port.Start.HighPart = 0x0; - PartialDescriptor->u.Port.Length = 3; - - /* Set Interrupt */ - if (Irq[i] != (ULONG)-1) - { - PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; - PartialDescriptor->Type = CmResourceTypeInterrupt; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED; - PartialDescriptor->u.Interrupt.Level = Irq[i]; - PartialDescriptor->u.Interrupt.Vector = 0; - PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF; - } - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Set 'Identifier' value */ - sprintf(Buffer, "PARALLEL%ld", i + 1); - FldrSetIdentifier(ControllerKey, Buffer); - DbgPrint((DPRINT_HWDETECT, - "Created value: Identifier %s\n", - Buffer)); - - ControllerNumber++; - } - - DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() done\n")); -} - - -static BOOLEAN -DetectKeyboardDevice(VOID) -{ - UCHAR Status; - UCHAR Scancode; - ULONG Loops; - BOOLEAN Result = TRUE; - - /* Identify device */ - WRITE_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA, - 0xF2); - - /* Wait for reply */ - for (Loops = 0; Loops < 100; Loops++) - { - StallExecutionProcessor(10000); - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) != 0) - break; - } - - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) == 0) - { - /* PC/XT keyboard or no keyboard */ - Result = FALSE; - } - - Scancode = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - if (Scancode != 0xFA) - { - /* No ACK received */ - Result = FALSE; - } - - StallExecutionProcessor(10000); - - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) == 0) - { - /* Found AT keyboard */ - return Result; - } - - Scancode = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - if (Scancode != 0xAB) - { - /* No 0xAB received */ - Result = FALSE; - } - - StallExecutionProcessor(10000); - - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) == 0) - { - /* No byte in buffer */ - Result = FALSE; - } - - Scancode = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - if (Scancode != 0x41) - { - /* No 0x41 received */ - Result = FALSE; - } - - /* Found MF-II keyboard */ - return Result; -} - - -static VOID -DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCM_KEYBOARD_DEVICE_DATA KeyboardData; - PCONFIGURATION_COMPONENT_DATA PeripheralKey; - ULONG Size; - - /* HACK: don't call DetectKeyboardDevice() as it fails in Qemu 0.8.2 */ - if (TRUE || DetectKeyboardDevice()) - { - /* Create controller key */ - FldrCreateComponentKey(ControllerKey, - L"KeyboardPeripheral", - 0, - PeripheralClass, - KeyboardPeripheral, - &PeripheralKey); - DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(PeripheralKey, - Input | ConsoleIn, - 0, - 0xFFFFFFFF); - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - sizeof(CM_KEYBOARD_DEVICE_DATA); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypeDeviceSpecific; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_KEYBOARD_DEVICE_DATA); - - KeyboardData = (PCM_KEYBOARD_DEVICE_DATA)(PartialDescriptor + 1); - KeyboardData->Version = 1; - KeyboardData->Revision = 1; - KeyboardData->Type = 4; - KeyboardData->Subtype = 0; - KeyboardData->KeyboardFlags = 0x20; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Set 'Identifier' value */ - FldrSetIdentifier(PeripheralKey, "PCAT_ENHANCED"); - } -} - - -static VOID -DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCONFIGURATION_COMPONENT_DATA ControllerKey; - ULONG Size; - - /* Create controller key */ - FldrCreateComponentKey(BusKey, - L"KeyboardController", - 0, - ControllerClass, - KeyboardController, - &ControllerKey); - DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardController\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - Input | ConsoleIn, - 0, - 0xFFFFFFFF); - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + - 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 3; - - /* Set Interrupt */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypeInterrupt; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED; - PartialDescriptor->u.Interrupt.Level = 1; - PartialDescriptor->u.Interrupt.Vector = 0; - PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF; - - /* Set IO Port 0x60 */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = CM_RESOURCE_PORT_IO; - PartialDescriptor->u.Port.Start.LowPart = 0x60; - PartialDescriptor->u.Port.Start.HighPart = 0x0; - PartialDescriptor->u.Port.Length = 1; - - /* Set IO Port 0x64 */ - PartialDescriptor = &PartialResourceList->PartialDescriptors[2]; - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = CM_RESOURCE_PORT_IO; - PartialDescriptor->u.Port.Start.LowPart = 0x64; - PartialDescriptor->u.Port.Start.HighPart = 0x0; - PartialDescriptor->u.Port.Length = 1; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - DetectKeyboardPeripheral(ControllerKey); -} - - -static VOID -PS2ControllerWait(VOID) -{ - ULONG Timeout; - UCHAR Status; - - for (Timeout = 0; Timeout < CONTROLLER_TIMEOUT; Timeout++) - { - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_INPUT_BUFFER_FULL) == 0) - return; - - /* Sleep for one millisecond */ - StallExecutionProcessor(1000); - } -} - - -static BOOLEAN -DetectPS2AuxPort(VOID) -{ -#if 1 - /* Current detection is too unreliable. Just do as if - * the PS/2 aux port is always present - */ - return TRUE; -#else - ULONG Loops; - UCHAR Status; - - /* Put the value 0x5A in the output buffer using the - * "WriteAuxiliary Device Output Buffer" command (0xD3). - * Poll the Status Register for a while to see if the value really turns up - * in the Data Register. If the KEYBOARD_STATUS_MOUSE_OBF bit is also set - * to 1 in the Status Register, we assume this controller has an - * Auxiliary Port (a.k.a. Mouse Port). - */ - PS2ControllerWait(); - WRITE_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_CONTROL, - CONTROLLER_COMMAND_WRITE_MOUSE_OUTPUT_BUFFER); - PS2ControllerWait(); - - /* 0x5A is a random dummy value */ - WRITE_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA, - 0x5A); - - for (Loops = 0; Loops < 10; Loops++) - { - StallExecutionProcessor(10000); - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) != 0) - break; - } - - READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - - return (Status & CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL); -#endif -} - - -static BOOLEAN -DetectPS2AuxDevice(VOID) -{ - UCHAR Scancode; - UCHAR Status; - ULONG Loops; - BOOLEAN Result = TRUE; - - PS2ControllerWait(); - WRITE_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_CONTROL, - CONTROLLER_COMMAND_WRITE_MOUSE); - PS2ControllerWait(); - - /* Identify device */ - WRITE_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA, - 0xF2); - - /* Wait for reply */ - for (Loops = 0; Loops < 100; Loops++) - { - StallExecutionProcessor(10000); - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_OUTPUT_BUFFER_FULL) != 0) - break; - } - - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL) == 0) - Result = FALSE; - - Scancode = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - if (Scancode != 0xFA) - Result = FALSE; - - StallExecutionProcessor(10000); - - Status = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_STATUS); - if ((Status & CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL) == 0) - Result = FALSE; - - Scancode = READ_PORT_UCHAR((PUCHAR)CONTROLLER_REGISTER_DATA); - if (Scancode != 0x00) - Result = FALSE; - - return Result; -} - - -static VOID -DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - CM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCONFIGURATION_COMPONENT_DATA ControllerKey; - PCONFIGURATION_COMPONENT_DATA PeripheralKey; - - if (DetectPS2AuxPort()) - { - DbgPrint((DPRINT_HWDETECT, "Detected PS2 port\n")); - - /* Create controller key */ - FldrCreateComponentKey(BusKey, - L"PointerController", - 0, - ControllerClass, - PointerController, - &ControllerKey); - DbgPrint((DPRINT_HWDETECT, "Created key: PointerController\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - Input, - 0, - 0xFFFFFFFF); - - memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST)); - - /* Initialize resource descriptor */ - PartialResourceList.Version = 1; - PartialResourceList.Revision = 1; - PartialResourceList.Count = 1; - - /* Set Interrupt */ - PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeInterrupt; - PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareUndetermined; - PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_INTERRUPT_LATCHED; - PartialResourceList.PartialDescriptors[0].u.Interrupt.Level = 12; - PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector = 0; - PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity = 0xFFFFFFFF; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(ControllerKey, - &PartialResourceList, - sizeof(CM_PARTIAL_RESOURCE_LIST)); - - if (DetectPS2AuxDevice()) - { - DbgPrint((DPRINT_HWDETECT, "Detected PS2 mouse\n")); - - /* Create peripheral key */ - FldrCreateComponentKey(ControllerKey, - L"PointerPeripheral", - 0, - ControllerClass, - PointerPeripheral, - &PeripheralKey); - DbgPrint((DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(PeripheralKey, - Input, - 0, - 0xFFFFFFFF); - - /* Initialize resource descriptor */ - memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST)); - PartialResourceList.Version = 1; - PartialResourceList.Revision = 1; - PartialResourceList.Count = 0; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(PeripheralKey, - &PartialResourceList, - sizeof(CM_PARTIAL_RESOURCE_LIST) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); - - /* Set 'Identifier' value */ - FldrSetIdentifier(PeripheralKey, "MICROSOFT PS2 MOUSE"); - } - } -} - - -static VOID -DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - CHAR Buffer[80]; - PCONFIGURATION_COMPONENT_DATA ControllerKey; - USHORT VesaVersion; - - FldrCreateComponentKey(BusKey, - L"DisplayController", - 0, - ControllerClass, - DisplayController, - &ControllerKey); - DbgPrint((DPRINT_HWDETECT, "Created key: DisplayController\\0\n")); - - /* Set 'ComponentInformation' value */ - FldrSetComponentInformation(ControllerKey, - 0x00, - 0, - 0xFFFFFFFF); - - /* FIXME: Set 'ComponentInformation' value */ - - VesaVersion = BiosIsVesaSupported(); - if (VesaVersion != 0) - { - DbgPrint((DPRINT_HWDETECT, - "VESA version %c.%c\n", - (VesaVersion >> 8) + '0', - (VesaVersion & 0xFF) + '0')); - } - else - { - DbgPrint((DPRINT_HWDETECT, - "VESA not supported\n")); - } - - if (VesaVersion >= 0x0200) - { - strcpy(Buffer, - "VBE Display"); - } - else - { - strcpy(Buffer, - "VGA Display"); - } - - /* Set 'Identifier' value */ - FldrSetIdentifier(ControllerKey, Buffer); - - /* FIXME: Add display peripheral (monitor) data */ -} - - -static VOID -DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCONFIGURATION_COMPONENT_DATA BusKey; - ULONG Size; - - /* Create new bus key */ - FldrCreateComponentKey(SystemKey, - L"MultifunctionAdapter", - *BusNumber, - AdapterClass, - MultiFunctionAdapter, - &BusKey); - - /* Set 'Component Information' value similar to my NT4 box */ - FldrSetComponentInformation(BusKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Increment bus number */ - (*BusNumber)++; - - /* Set 'Identifier' value */ - FldrSetIdentifier(BusKey, "ISA"); - - /* Set 'Configuration Data' value */ - Size = sizeof(CM_PARTIAL_RESOURCE_LIST) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmHeapAlloc(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 0; - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmHeapFree(PartialResourceList); - - /* Detect ISA/BIOS devices */ - DetectBiosDisks(SystemKey, BusKey); - - DetectSerialPorts(BusKey); - - DetectParallelPorts(BusKey); - - DetectKeyboardController(BusKey); - - DetectPS2Mouse(BusKey); - - DetectDisplayController(BusKey); - - /* FIXME: Detect more ISA devices */ -} - - -PCONFIGURATION_COMPONENT_DATA -PcHwDetect(VOID) -{ - PCONFIGURATION_COMPONENT_DATA SystemKey; - ULONG BusNumber = 0; - - DbgPrint((DPRINT_HWDETECT, "DetectHardware()\n")); - - /* Create the 'System' key */ - FldrCreateSystemKey(&SystemKey); - - /* Set empty component information */ - FldrSetComponentInformation(SystemKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Detect buses */ - DetectPciBios(SystemKey, &BusNumber); - DetectApmBios(SystemKey, &BusNumber); - DetectPnpBios(SystemKey, &BusNumber); - DetectIsaBios(SystemKey, &BusNumber); - DetectAcpiBios(SystemKey, &BusNumber); - - DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n")); - - return SystemKey; -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/hwacpi.c b/reactos/boot/freeldr/freeldr/arch/amd64/hwacpi.c deleted file mode 100644 index cc7cdcd19af..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/hwacpi.c +++ /dev/null @@ -1,5 +0,0 @@ -/* No need to duplicate code ; import the i386 version */ - -#include "../i386/hwacpi.c" - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/hwapm.c b/reactos/boot/freeldr/freeldr/arch/amd64/hwapm.c deleted file mode 100644 index 4296c76164c..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/hwapm.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * FreeLoader - * - * Copyright (C) 2004 Eric Kohl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -static BOOLEAN -FindApmBios(VOID) -{ - REGS RegsIn; - REGS RegsOut; - - RegsIn.b.ah = 0x53; - RegsIn.b.al = 0x00; - RegsIn.w.bx = 0x0000; - - Int386(0x15, &RegsIn, &RegsOut); - - if (INT386_SUCCESS(RegsOut)) - { - DbgPrint((DPRINT_HWDETECT, "Found APM BIOS\n")); - DbgPrint((DPRINT_HWDETECT, "AH: %x\n", RegsOut.b.ah)); - DbgPrint((DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al)); - DbgPrint((DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh)); - DbgPrint((DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl)); - DbgPrint((DPRINT_HWDETECT, "CX: %x\n", RegsOut.w.cx)); - - return TRUE; - } - - DbgPrint((DPRINT_HWDETECT, "No APM BIOS found\n")); - - return FALSE; -} - - -VOID -DetectApmBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) -{ - PCONFIGURATION_COMPONENT_DATA BiosKey; - CM_PARTIAL_RESOURCE_LIST PartialResourceList; - - if (FindApmBios()) - { - /* Create new bus key */ - FldrCreateComponentKey(SystemKey, - L"MultifunctionAdapter", - *BusNumber, - AdapterClass, - MultiFunctionAdapter, - &BiosKey); - - /* Set 'Component Information' */ - FldrSetComponentInformation(BiosKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Set 'Configuration Data' value */ - memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST)); - PartialResourceList.Version = 0; - PartialResourceList.Revision = 0; - PartialResourceList.Count = 0; - FldrSetConfigurationData(BiosKey, - &PartialResourceList, - sizeof(CM_PARTIAL_RESOURCE_LIST) - - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); - - /* Increment bus number */ - (*BusNumber)++; - - /* Set 'Identifier' value */ - FldrSetIdentifier(BiosKey, "APM"); - } - - /* FIXME: Add configuration data */ -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/hwpci.c b/reactos/boot/freeldr/freeldr/arch/amd64/hwpci.c deleted file mode 100644 index de293334c5f..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/hwpci.c +++ /dev/null @@ -1,346 +0,0 @@ -/* - * FreeLoader - * - * Copyright (C) 2004 Eric Kohl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -typedef struct _ROUTING_SLOT -{ - UCHAR BusNumber; - UCHAR DeviceNumber; - UCHAR LinkA; - USHORT BitmapA; - UCHAR LinkB; - USHORT BitmapB; - UCHAR LinkC; - USHORT BitmapC; - UCHAR LinkD; - USHORT BitmapD; - UCHAR SlotNumber; - UCHAR Reserved; -} __attribute__((packed)) ROUTING_SLOT, *PROUTING_SLOT; - -typedef struct _PCI_IRQ_ROUTING_TABLE -{ - ULONG Signature; - USHORT Version; - USHORT Size; - UCHAR RouterBus; - UCHAR RouterSlot; - USHORT ExclusiveIRQs; - ULONG CompatibleRouter; - ULONG MiniportData; - UCHAR Reserved[11]; - UCHAR Checksum; - ROUTING_SLOT Slot[1]; -} __attribute__((packed)) PCI_IRQ_ROUTING_TABLE, *PPCI_IRQ_ROUTING_TABLE; - -typedef struct _PCI_REGISTRY_INFO -{ - UCHAR MajorRevision; - UCHAR MinorRevision; - UCHAR NoBuses; - UCHAR HardwareMechanism; -} PCI_REGISTRY_INFO, *PPCI_REGISTRY_INFO; - -static PPCI_IRQ_ROUTING_TABLE -GetPciIrqRoutingTable(VOID) -{ - PPCI_IRQ_ROUTING_TABLE Table; - PUCHAR Ptr; - ULONG Sum; - ULONG i; - - Table = (PPCI_IRQ_ROUTING_TABLE)0xF0000; - while ((ULONG_PTR)Table < 0x100000) - { - if (Table->Signature == 0x52495024) - { - DbgPrint((DPRINT_HWDETECT, - "Found signature\n")); - - Ptr = (PUCHAR)Table; - Sum = 0; - for (i = 0; i < Table->Size; i++) - { - Sum += Ptr[i]; - } - - if ((Sum & 0xFF) != 0) - { - DbgPrint((DPRINT_HWDETECT, - "Invalid routing table\n")); - return NULL; - } - - DbgPrint((DPRINT_HWDETECT, - "Valid checksum\n")); - - return Table; - } - - Table = (PPCI_IRQ_ROUTING_TABLE)((ULONG_PTR)Table + 0x10); - } - - return NULL; -} - - -static BOOLEAN -FindPciBios(PPCI_REGISTRY_INFO BusData) -{ - REGS RegsIn; - REGS RegsOut; - - RegsIn.b.ah = 0xB1; /* Subfunction B1h */ - RegsIn.b.al = 0x01; /* PCI BIOS present */ - - Int386(0x1A, &RegsIn, &RegsOut); - - if (INT386_SUCCESS(RegsOut) && RegsOut.d.edx == 0x20494350 && RegsOut.b.ah == 0) - { - DbgPrint((DPRINT_HWDETECT, "Found PCI bios\n")); - - DbgPrint((DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al)); - DbgPrint((DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh)); - DbgPrint((DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl)); - DbgPrint((DPRINT_HWDETECT, "CL: %x\n", RegsOut.b.cl)); - - BusData->NoBuses = RegsOut.b.cl + 1; - BusData->MajorRevision = RegsOut.b.bh; - BusData->MinorRevision = RegsOut.b.bl; - BusData->HardwareMechanism = RegsOut.b.cl; - - return TRUE; - } - - - DbgPrint((DPRINT_HWDETECT, "No PCI bios found\n")); - - return FALSE; -} - - -static VOID -DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PPCI_IRQ_ROUTING_TABLE Table; - PCONFIGURATION_COMPONENT_DATA TableKey; - ULONG Size; - - Table = GetPciIrqRoutingTable(); - if (Table != NULL) - { - DbgPrint((DPRINT_HWDETECT, "Table size: %u\n", Table->Size)); - - FldrCreateComponentKey(BusKey, - L"RealModeIrqRoutingTable", - 0, - PeripheralClass, - RealModeIrqRoutingTable, - &TableKey); - - /* Set 'Component Information' */ - FldrSetComponentInformation(TableKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Set 'Identifier' value */ - FldrSetIdentifier(TableKey, "PCI Real-mode IRQ Routing Table"); - - /* Set 'Configuration Data' value */ - Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) + - 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->Size; - PartialResourceList = MmAllocateMemory(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 2; - - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypeBusNumber; - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->u.BusNumber.Start = 0; - PartialDescriptor->u.BusNumber.Length = 1; - - PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; - PartialDescriptor->Type = CmResourceTypeDeviceSpecific; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->u.DeviceSpecificData.DataSize = Table->Size; - - memcpy(&PartialResourceList->PartialDescriptors[2], - Table, Table->Size); - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(TableKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); - } -} - - -VOID -DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) -{ - PCM_PARTIAL_RESOURCE_LIST PartialResourceList; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCI_REGISTRY_INFO BusData; - PCONFIGURATION_COMPONENT_DATA BiosKey; - ULONG Size; - PCONFIGURATION_COMPONENT_DATA BusKey; - ULONG i; - CHAR szPci[] = "PCI"; - - /* Report the PCI BIOS */ - if (FindPciBios(&BusData)) - { - /* Create new bus key */ - FldrCreateComponentKey(SystemKey, - L"MultifunctionAdapter", - *BusNumber, - AdapterClass, - MultiFunctionAdapter, - &BiosKey); - - /* Set 'Component Information' */ - FldrSetComponentInformation(BiosKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Increment bus number */ - (*BusNumber)++; - - /* Set 'Identifier' value */ - FldrSetIdentifier(BiosKey, "PCI BIOS"); - - /* Set 'Configuration Data' value */ - Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, - PartialDescriptors); - PartialResourceList = MmAllocateMemory(Size); - if (PartialResourceList == NULL) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(BiosKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); - - DetectPciIrqRoutingTable(BiosKey); - - /* Report PCI buses */ - for (i = 0; i < (ULONG)BusData.NoBuses; i++) - { - /* Create the bus key */ - FldrCreateComponentKey(SystemKey, - L"MultifunctionAdapter", - *BusNumber, - AdapterClass, - MultiFunctionAdapter, - &BusKey); - - /* Set 'Component Information' */ - FldrSetComponentInformation(BusKey, - 0x0, - 0x0, - 0xFFFFFFFF); - - /* Check if this is the first bus */ - if (i == 0) - { - /* Set 'Configuration Data' value */ - Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, - PartialDescriptors) + - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + - sizeof(PCI_REGISTRY_INFO); - PartialResourceList = MmAllocateMemory(Size); - if (!PartialResourceList) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - PartialResourceList->Version = 1; - PartialResourceList->Revision = 1; - PartialResourceList->Count = 1; - PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; - PartialDescriptor->Type = CmResourceTypeDeviceSpecific; - PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; - PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(PCI_REGISTRY_INFO); - memcpy(&PartialResourceList->PartialDescriptors[1], - &BusData, - sizeof(PCI_REGISTRY_INFO)); - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); - } - else - { - /* Set 'Configuration Data' value */ - Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, - PartialDescriptors); - PartialResourceList = MmAllocateMemory(Size); - if (!PartialResourceList) - { - DbgPrint((DPRINT_HWDETECT, - "Failed to allocate resource descriptor\n")); - return; - } - - /* Initialize resource descriptor */ - memset(PartialResourceList, 0, Size); - - /* Set 'Configuration Data' value */ - FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); - } - - /* Increment bus number */ - (*BusNumber)++; - - /* Set 'Identifier' value */ - FldrSetIdentifier(BusKey, szPci); - } - } -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/i386disk.c b/reactos/boot/freeldr/freeldr/arch/amd64/i386disk.c deleted file mode 100644 index 3a0874c84d3..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/i386disk.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -///////////////////////////////////////////////////////////////////////////////////////////// -// FUNCTIONS -///////////////////////////////////////////////////////////////////////////////////////////// - -BOOLEAN DiskResetController(ULONG DriveNumber) -{ - REGS RegsIn; - REGS RegsOut; - - DbgPrint((DPRINT_DISK, "DiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber)); - - // BIOS Int 13h, function 0 - Reset disk system - // AH = 00h - // DL = drive (if bit 7 is set both hard disks and floppy disks reset) - // Return: - // AH = status - // CF clear if successful - // CF set on error - RegsIn.b.ah = 0x00; - RegsIn.b.dl = DriveNumber; - - // Reset the disk controller - Int386(0x13, &RegsIn, &RegsOut); - - return INT386_SUCCESS(RegsOut); -} - -BOOLEAN DiskInt13ExtensionsSupported(ULONG DriveNumber) -{ - REGS RegsIn; - REGS RegsOut; - - DbgPrint((DPRINT_DISK, "DiskInt13ExtensionsSupported()\n")); - - // IBM/MS INT 13 Extensions - INSTALLATION CHECK - // AH = 41h - // BX = 55AAh - // DL = drive (80h-FFh) - // Return: - // CF set on error (extensions not supported) - // AH = 01h (invalid function) - // CF clear if successful - // BX = AA55h if installed - // AH = major version of extensions - // 01h = 1.x - // 20h = 2.0 / EDD-1.0 - // 21h = 2.1 / EDD-1.1 - // 30h = EDD-3.0 - // AL = internal use - // CX = API subset support bitmap - // DH = extension version (v2.0+ ??? -- not present in 1.x) - // - // Bitfields for IBM/MS INT 13 Extensions API support bitmap - // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported - // Bit 1, removable drive controller functions (AH=45h,46h,48h,49h,INT 15/AH=52h) supported - // Bit 2, enhanced disk drive (EDD) functions (AH=48h,AH=4Eh) supported - // extended drive parameter table is valid - // Bits 3-15 reserved - RegsIn.b.ah = 0x41; - RegsIn.w.bx = 0x55AA; - RegsIn.b.dl = DriveNumber; - - // Reset the disk controller - Int386(0x13, &RegsIn, &RegsOut); - - if (!INT386_SUCCESS(RegsOut)) - { - // CF set on error (extensions not supported) - return FALSE; - } - - if (RegsOut.w.bx != 0xAA55) - { - // BX = AA55h if installed - return FALSE; - } - - // Note: - // The original check is too strict because some BIOSes report that - // extended disk access functions are not suported when booting - // from a CD (e.g. Phoenix BIOS v6.00PG). Argh! -#if 0 - if (!(RegsOut.w.cx & 0x0001)) - { - // CX = API subset support bitmap - // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported - return FALSE; - } -#endif - - // Use this relaxed check instead - if (RegsOut.w.cx == 0x0000) - { - // CX = API subset support bitmap - return FALSE; - } - - return TRUE; -} - -VOID DiskStopFloppyMotor(VOID) -{ - WRITE_PORT_UCHAR((PUCHAR)0x3F2, 0); -} - -BOOLEAN DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT BufferSize) -{ - REGS RegsIn; - REGS RegsOut; - PUSHORT Ptr = (PUSHORT)(BIOSCALLBUFFER); - - DbgPrint((DPRINT_DISK, "DiskGetExtendedDriveParameters()\n")); - - // Initialize transfer buffer - *Ptr = BufferSize; - - // BIOS Int 13h, function 48h - Get drive parameters - // AH = 48h - // DL = drive (bit 7 set for hard disk) - // DS:SI = result buffer - // Return: - // CF set on error - // AH = status (07h) - // CF clear if successful - // AH = 00h - // DS:SI -> result buffer - RegsIn.b.ah = 0x48; - RegsIn.b.dl = DriveNumber; - RegsIn.x.ds = BIOSCALLBUFSEGMENT; // DS:SI -> result buffer - RegsIn.w.si = BIOSCALLBUFOFFSET; - - // Get drive parameters - Int386(0x13, &RegsIn, &RegsOut); - - if (!INT386_SUCCESS(RegsOut)) - { - return FALSE; - } - - memcpy(Buffer, Ptr, BufferSize); - - DbgPrint((DPRINT_DISK, "size of buffer: %x\n", Ptr[0])); - DbgPrint((DPRINT_DISK, "information flags: %x\n", Ptr[1])); - DbgPrint((DPRINT_DISK, "number of physical cylinders on drive: %u\n", *(PULONG)&Ptr[2])); - DbgPrint((DPRINT_DISK, "number of physical heads on drive: %u\n", *(PULONG)&Ptr[4])); - DbgPrint((DPRINT_DISK, "number of physical sectors per track: %u\n", *(PULONG)&Ptr[6])); - DbgPrint((DPRINT_DISK, "total number of sectors on drive: %I64u\n", *(unsigned long long*)&Ptr[8])); - DbgPrint((DPRINT_DISK, "bytes per sector: %u\n", Ptr[12])); - if (Ptr[0] >= 0x1e) - { - DbgPrint((DPRINT_DISK, "EED configuration parameters: %x:%x\n", Ptr[13], Ptr[14])); - if (Ptr[13] != 0xffff && Ptr[14] != 0xffff) - { - PUCHAR SpecPtr = (PUCHAR)(ULONG_PTR)((Ptr[13] << 4) + Ptr[14]); - DbgPrint((DPRINT_DISK, "SpecPtr: %x\n", SpecPtr)); - DbgPrint((DPRINT_DISK, "physical I/O port base address: %x\n", *(PUSHORT)&SpecPtr[0])); - DbgPrint((DPRINT_DISK, "disk-drive control port address: %x\n", *(PUSHORT)&SpecPtr[2])); - DbgPrint((DPRINT_DISK, "drive flags: %x\n", SpecPtr[4])); - DbgPrint((DPRINT_DISK, "proprietary information: %x\n", SpecPtr[5])); - DbgPrint((DPRINT_DISK, "IRQ for drive: %u\n", SpecPtr[6])); - DbgPrint((DPRINT_DISK, "sector count for multi-sector transfers: %u\n", SpecPtr[7])); - DbgPrint((DPRINT_DISK, "DMA control: %x\n", SpecPtr[8])); - DbgPrint((DPRINT_DISK, "programmed I/O control: %x\n", SpecPtr[9])); - DbgPrint((DPRINT_DISK, "drive options: %x\n", *(PUSHORT)&SpecPtr[10])); - } - } - if (Ptr[0] >= 0x42) - { - DbgPrint((DPRINT_DISK, "signature: %x\n", Ptr[15])); - } - - return TRUE; -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/i386rtl.c b/reactos/boot/freeldr/freeldr/arch/amd64/i386rtl.c deleted file mode 100644 index ff3ac988a37..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/i386rtl.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -void PcBeep(void) -{ - sound(700); - delay(200); - sound(0); -} - -void delay(unsigned msec) -{ - REGS Regs; - unsigned usec; - unsigned msec_this; - - // Int 15h AH=86h - // BIOS - WAIT (AT,PS) - // - // AH = 86h - // CX:DX = interval in microseconds - // Return: - // CF clear if successful (wait interval elapsed) - // CF set on error or AH=83h wait already in progress - // AH = status (see #00496) - - // Note: The resolution of the wait period is 977 microseconds on - // many systems because many BIOSes use the 1/1024 second fast - // interrupt from the AT real-time clock chip which is available on INT 70; - // because newer BIOSes may have much more precise timers available, it is - // not possible to use this function accurately for very short delays unless - // the precise behavior of the BIOS is known (or found through testing) - - while (msec) - { - msec_this = msec; - - if (msec_this > 4000) - { - msec_this = 4000; - } - - usec = msec_this * 1000; - - Regs.b.ah = 0x86; - Regs.w.cx = usec >> 16; - Regs.w.dx = usec & 0xffff; - Int386(0x15, &Regs, &Regs); - - msec -= msec_this; - } -} - -void sound(int freq) -{ - int scale; - - if (freq == 0) - { - WRITE_PORT_UCHAR((PUCHAR)0x61, READ_PORT_UCHAR((PUCHAR)0x61) & ~3); - return; - } - - scale = 1193046 / freq; - WRITE_PORT_UCHAR((PUCHAR)0x43, 0xb6); - WRITE_PORT_UCHAR((PUCHAR)0x42, scale & 0xff); - WRITE_PORT_UCHAR((PUCHAR)0x42, scale >> 8); - WRITE_PORT_UCHAR((PUCHAR)0x61, READ_PORT_UCHAR((PUCHAR)0x61) | 3); -} diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/i386vid.c b/reactos/boot/freeldr/freeldr/arch/amd64/i386vid.c deleted file mode 100644 index 1c33ee6804e..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/i386vid.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer - * Portions from Linux video.S - Display adapter & video mode setup, version 2.13 (14-May-99) - * Copyright (C) 1995 -- 1999 Martin Mares - * Based on the original setup.S code (C) Linus Torvalds and Mats Anderson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -typedef struct -{ - UCHAR Signature[4]; // (ret) signature ("VESA") - // (call) VESA 2.0 request signature ("VBE2"), required to receive - // version 2.0 info - USHORT VesaVersion; // VESA version number (one-digit minor version -- 0102h = v1.2) - ULONG OemNamePtr; // pointer to OEM name - // "761295520" for ATI - ULONG Capabilities; // capabilities flags (see #00078) - ULONG SupportedModeListPtr; // pointer to list of supported VESA and OEM video modes - // (list of words terminated with FFFFh) - USHORT TotalVideoMemory; // total amount of video memory in 64K blocks - - // ---VBE v1.x --- - //UCHAR Reserved[236]; - - // ---VBE v2.0 --- - USHORT OemSoftwareVersion; // OEM software version (BCD, high byte = major, low byte = minor) - ULONG VendorNamePtr; // pointer to vendor name - ULONG ProductNamePtr; // pointer to product name - ULONG ProductRevisionStringPtr; // pointer to product revision string - USHORT VBE_AF_Version; // (if capabilities bit 3 set) VBE/AF version (BCD) - // 0100h for v1.0P - ULONG AcceleratedModeListPtr; // (if capabilities bit 3 set) pointer to list of supported - // accelerated video modes (list of words terminated with FFFFh) - UCHAR Reserved[216]; // reserved for VBE implementation - UCHAR ScratchPad[256]; // OEM scratchpad (for OEM strings, etc.) -} PACKED VESA_SVGA_INFO, *PVESA_SVGA_INFO; - -// Bitfields for VESA capabilities: -// -// Bit(s) Description (Table 00078) -// 0 DAC can be switched into 8-bit mode -// 1 non-VGA controller -// 2 programmed DAC with blank bit (i.e. only during blanking interval) -// 3 (VBE v3.0) controller supports hardware stereoscopic signalling -// 3 controller supports VBE/AF v1.0P extensions -// 4 (VBE v3.0) if bit 3 set: -// =0 stereo signalling via external VESA stereo connector -// =1 stereo signalling via VESA EVC connector -// 4 (VBE/AF v1.0P) must call EnableDirectAccess to access framebuffer -// 5 (VBE/AF v1.0P) controller supports hardware mouse cursor -// 6 (VBE/AF v1.0P) controller supports hardware clipping -// 7 (VBE/AF v1.0P) controller supports transparent BitBLT -// 8-31 reserved (0) - -// Notes: The list of supported video modes is stored in the reserved -// portion of the SuperVGA information record by some implementations, -// and it may thus be necessary to either copy the mode list or use a -// different buffer for all subsequent VESA calls. Not all of the video -// modes in the list of mode numbers may be supported, e.g. if they require -// more memory than currently installed or are not supported by the -// attached monitor. Check any mode you intend to use through AX=4F01h first.. -// The 1.1 VESA document specifies 242 reserved bytes at the end, so the -// buffer should be 262 bytes to ensure that it is not overrun; for v2.0, -// the buffer should be 512 bytes. The S3 specific video modes will most -// likely follow the FFFFh terminator at the end of the standard modes. -// A search must then be made to find them, FFFFh will also terminate this -// second list. In some cases, only a "stub" VBE may be present, supporting -// only AX=4F00h; this case may be assumed if the list of supported video modes -// is empty (consisting of a single word of FFFFh) -#if 0 -static VOID BiosSetVideoFont8x16(VOID) -{ - REGS Regs; - - // Int 10h AX=1114h - // VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA) - // - // AX = 1114h - // BL = block to load - // Return: - // Nothing - Regs.w.ax = 0x1114; - Regs.b.bl = 0; - Int386(0x10, &Regs, &Regs); -} - -static VOID VideoSetTextCursorPosition(ULONG X, ULONG Y) -{ -} - -static ULONG VideoGetTextCursorPositionX(VOID) -{ - REGS Regs; - - // Int 10h AH=03h - // VIDEO - GET CURSOR POSITION AND SIZE - // - // AH = 03h - // BH = page number - // 0-3 in modes 2&3 - // 0-7 in modes 0&1 - // 0 in graphics modes - // Return: - // AX = 0000h (Phoenix BIOS) - // CH = start scan line - // CL = end scan line - // DH = row (00h is top) - // DL = column (00h is left) - Regs.b.ah = 0x03; - Regs.b.bh = 0x00; - Int386(0x10, &Regs, &Regs); - - return Regs.b.dl; -} - -static ULONG VideoGetTextCursorPositionY(VOID) -{ - REGS Regs; - - // Int 10h AH=03h - // VIDEO - GET CURSOR POSITION AND SIZE - // - // AH = 03h - // BH = page number - // 0-3 in modes 2&3 - // 0-7 in modes 0&1 - // 0 in graphics modes - // Return: - // AX = 0000h (Phoenix BIOS) - // CH = start scan line - // CL = end scan line - // DH = row (00h is top) - // DL = column (00h is left) - Regs.b.ah = 0x03; - Regs.b.bh = 0x00; - Int386(0x10, &Regs, &Regs); - - return Regs.b.dh; -} -#endif - -USHORT BiosIsVesaSupported(VOID) -{ - REGS Regs; - PVESA_SVGA_INFO SvgaInfo = (PVESA_SVGA_INFO)BIOSCALLBUFFER; - //USHORT* VideoModes; - //USHORT Index; - - DbgPrint((DPRINT_UI, "BiosIsVesaSupported()\n")); - - RtlZeroMemory(SvgaInfo, sizeof(VESA_SVGA_INFO)); - - // Make sure we receive version 2.0 info - SvgaInfo->Signature[0] = 'V'; - SvgaInfo->Signature[1] = 'B'; - SvgaInfo->Signature[2] = 'E'; - SvgaInfo->Signature[3] = '2'; - - // Int 10h AX=4F00h - // VESA SuperVGA BIOS (VBE) - GET SuperVGA INFORMATION - // - // AX = 4F00h - // ES:DI -> buffer for SuperVGA information (see #00077) - // Return: - // AL = 4Fh if function supported - // AH = status - // 00h successful - // ES:DI buffer filled - // 01h failed - // ---VBE v2.0--- - // 02h function not supported by current hardware configuration - // 03h function invalid in current video mode - // - // Determine whether VESA BIOS extensions are present and the - // capabilities supported by the display adapter - // - // Installation check;VESA SuperVGA - Regs.w.ax = 0x4F00; - Regs.w.es = BIOSCALLBUFSEGMENT; - Regs.w.di = BIOSCALLBUFOFFSET; - Int386(0x10, &Regs, &Regs); - - DbgPrint((DPRINT_UI, "AL = 0x%x\n", Regs.b.al)); - DbgPrint((DPRINT_UI, "AH = 0x%x\n", Regs.b.ah)); - - if (Regs.w.ax != 0x004F) - { - DbgPrint((DPRINT_UI, "Failed.\n")); - return 0x0000; - } - - DbgPrint((DPRINT_UI, "Supported.\n")); - DbgPrint((DPRINT_UI, "SvgaInfo->Signature[4] = %c%c%c%c\n", SvgaInfo->Signature[0], SvgaInfo->Signature[1], SvgaInfo->Signature[2], SvgaInfo->Signature[3])); - DbgPrint((DPRINT_UI, "SvgaInfo->VesaVersion = v%d.%d\n", ((SvgaInfo->VesaVersion >> 8) & 0xFF), (SvgaInfo->VesaVersion & 0xFF))); - DbgPrint((DPRINT_UI, "SvgaInfo->OemNamePtr = 0x%x\n", SvgaInfo->OemNamePtr)); - DbgPrint((DPRINT_UI, "SvgaInfo->Capabilities = 0x%x\n", SvgaInfo->Capabilities)); - DbgPrint((DPRINT_UI, "SvgaInfo->VideoMemory = %dK\n", SvgaInfo->TotalVideoMemory * 64)); - DbgPrint((DPRINT_UI, "---VBE v2.0 ---\n")); - DbgPrint((DPRINT_UI, "SvgaInfo->OemSoftwareVersion = v%d.%d\n", ((SvgaInfo->OemSoftwareVersion >> 8) & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 12) & 0x0F) * 10), (SvgaInfo->OemSoftwareVersion & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 4) & 0x0F) * 10))); - DbgPrint((DPRINT_UI, "SvgaInfo->VendorNamePtr = 0x%x\n", SvgaInfo->VendorNamePtr)); - DbgPrint((DPRINT_UI, "SvgaInfo->ProductNamePtr = 0x%x\n", SvgaInfo->ProductNamePtr)); - DbgPrint((DPRINT_UI, "SvgaInfo->ProductRevisionStringPtr = 0x%x\n", SvgaInfo->ProductRevisionStringPtr)); - DbgPrint((DPRINT_UI, "SvgaInfo->VBE/AF Version = 0x%x (BCD WORD)\n", SvgaInfo->VBE_AF_Version)); - - //DbgPrint((DPRINT_UI, "\nSupported VESA and OEM video modes:\n")); - //VideoModes = (USHORT*)SvgaInfo->SupportedModeListPtr; - //for (Index=0; VideoModes[Index]!=0xFFFF; Index++) - //{ - // DbgPrint((DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index])); - //} - - //if (SvgaInfo->VesaVersion >= 0x0200) - //{ - // DbgPrint((DPRINT_UI, "\nSupported accelerated video modes (VESA v2.0):\n")); - // VideoModes = (USHORT*)SvgaInfo->AcceleratedModeListPtr; - // for (Index=0; VideoModes[Index]!=0xFFFF; Index++) - // { - // DbgPrint((DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index])); - // } - //} - - DbgPrint((DPRINT_UI, "\n")); - - return SvgaInfo->VesaVersion; -} diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/mach.c b/reactos/boot/freeldr/freeldr/arch/amd64/mach.c deleted file mode 100644 index bd168ea69d2..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/mach.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $Id: machpc.c 32173 2008-02-07 00:43:09Z ros-arm-bringup $ - * - * FreeLoader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -VOID -MachInit(const char *CmdLine) -{ -// EnableA20(); -//DbgPrint((DPRINT_MEMORY, "MachInit.\n")); - /* Setup vtbl */ - MachVtbl.ConsPutChar = PcConsPutChar; - MachVtbl.ConsKbHit = PcConsKbHit; - MachVtbl.ConsGetCh = PcConsGetCh; - MachVtbl.VideoClearScreen = PcVideoClearScreen; - MachVtbl.VideoSetDisplayMode = PcVideoSetDisplayMode; - MachVtbl.VideoGetDisplaySize = PcVideoGetDisplaySize; - MachVtbl.VideoGetBufferSize = PcVideoGetBufferSize; - MachVtbl.VideoSetTextCursorPosition = PcVideoSetTextCursorPosition; - MachVtbl.VideoSetTextCursorPosition = PcVideoSetTextCursorPosition; - MachVtbl.VideoHideShowTextCursor = PcVideoHideShowTextCursor; - MachVtbl.VideoPutChar = PcVideoPutChar; - MachVtbl.VideoCopyOffScreenBufferToVRAM = PcVideoCopyOffScreenBufferToVRAM; - MachVtbl.VideoIsPaletteFixed = PcVideoIsPaletteFixed; - MachVtbl.VideoSetPaletteColor = PcVideoSetPaletteColor; - MachVtbl.VideoGetPaletteColor = PcVideoGetPaletteColor; - MachVtbl.VideoSync = PcVideoSync; - MachVtbl.Beep = PcBeep; - MachVtbl.PrepareForReactOS = PcPrepareForReactOS; - MachVtbl.GetMemoryMap = PcMemGetMemoryMap; - MachVtbl.DiskGetBootVolume = DiskGetBootVolume; - MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume; - MachVtbl.DiskGetBootPath = DiskGetBootPath; - MachVtbl.DiskGetBootDevice = DiskGetBootDevice; - MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy; - MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath; - MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors; - MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry; - MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; - MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount; - MachVtbl.GetTime = PcGetTime; - MachVtbl.HwDetect = PcHwDetect; -} - -VOID -PcPrepareForReactOS(IN BOOLEAN Setup) -{ - // - // On PC, prepare video and turn off the floppy motor - // -// PcVideoPrepareForReactOS(Setup); -// DiskStopFloppyMotor(); -} -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pccons.c b/reactos/boot/freeldr/freeldr/arch/amd64/pccons.c deleted file mode 100644 index a146f01b33f..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pccons.c +++ /dev/null @@ -1,128 +0,0 @@ -/* $Id: pccons.c 21917 2006-05-16 23:09:41Z hpoussin $ - * - * FreeLoader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define TEXTMODE_BUFFER 0xb8000 -#define TEXTMODE_BUFFER_SIZE 0x8000 - -#define TEXT_COLS 80 -#define TEXT_LINES 25 - -VOID -PcConsPutChar(int Ch) -{ - REGS Regs; - - /* If we are displaying a CR '\n' then do a LF also */ - if ('\n' == Ch) - { - /* Display the LF */ - PcConsPutChar('\r'); - } - - /* If we are displaying a TAB '\t' then display 8 spaces ' ' */ - if ('\t' == Ch) - { - /* Display the 8 spaces ' ' */ - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - PcConsPutChar(' '); - return; - } - - /* Int 10h AH=0Eh - * VIDEO - TELETYPE OUTPUT - * - * AH = 0Eh - * AL = character to write - * BH = page number - * BL = foreground color (graphics modes only) - */ - Regs.b.ah = 0x0E; - Regs.b.al = Ch; - Regs.w.bx = 1; - Int386(0x10, &Regs, &Regs); -} - -BOOLEAN -PcConsKbHit(VOID) -{ - REGS Regs; - - /* Int 16h AH=01h - * KEYBOARD - CHECK FOR KEYSTROKE - * - * AH = 01h - * Return: - * ZF set if no keystroke available - * ZF clear if keystroke available - * AH = BIOS scan code - * AL = ASCII character - */ - Regs.b.ah = 0x01; - Int386(0x16, &Regs, &Regs); - - return 0 == (Regs.x.eflags & I386FLAG_ZF); -} - -int -PcConsGetCh(void) -{ - REGS Regs; - static BOOLEAN ExtendedKey = FALSE; - static char ExtendedScanCode = 0; - - /* If the last time we were called an - * extended key was pressed then return - * that keys scan code. */ - if (ExtendedKey) - { - ExtendedKey = FALSE; - return ExtendedScanCode; - } - - /* Int 16h AH=00h - * KEYBOARD - GET KEYSTROKE - * - * AH = 00h - * Return: - * AH = BIOS scan code - * AL = ASCII character - */ - Regs.b.ah = 0x00; - Int386(0x16, &Regs, &Regs); - - /* Check for an extended keystroke */ - if (0 == Regs.b.al) - { - ExtendedKey = TRUE; - ExtendedScanCode = Regs.b.ah; - } - - /* Return keystroke */ - return Regs.b.al; -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pcdisk.c b/reactos/boot/freeldr/freeldr/arch/amd64/pcdisk.c deleted file mode 100644 index cd35497cc6b..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pcdisk.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -typedef struct -{ - UCHAR PacketSize; // 00h - Size of packet (10h or 18h) - UCHAR Reserved; // 01h - Reserved (0) - USHORT LBABlockCount; // 02h - Number of blocks to transfer (max 007Fh for Phoenix EDD) - USHORT TransferBufferOffset; // 04h - Transfer buffer offset (seg:off) - USHORT TransferBufferSegment; // Transfer buffer segment (seg:off) - ULONGLONG LBAStartBlock; // 08h - Starting absolute block number - //ULONGLONG TransferBuffer64; // 10h - (EDD-3.0, optional) 64-bit flat address of transfer buffer - // used if DWORD at 04h is FFFFh:FFFFh - // Commented since some earlier BIOSes refuse to work with - // such extended structure -} PACKED I386_DISK_ADDRESS_PACKET, *PI386_DISK_ADDRESS_PACKET; - -///////////////////////////////////////////////////////////////////////////////////////////// -// FUNCTIONS -///////////////////////////////////////////////////////////////////////////////////////////// - -static BOOLEAN PcDiskResetController(ULONG DriveNumber) -{ - REGS RegsIn; - REGS RegsOut; - - DbgPrint((DPRINT_DISK, "PcDiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber)); - - // BIOS Int 13h, function 0 - Reset disk system - // AH = 00h - // DL = drive (if bit 7 is set both hard disks and floppy disks reset) - // Return: - // AH = status - // CF clear if successful - // CF set on error - RegsIn.b.ah = 0x00; - RegsIn.b.dl = DriveNumber; - - // Reset the disk controller - Int386(0x13, &RegsIn, &RegsOut); - - return INT386_SUCCESS(RegsOut); -} - -static BOOLEAN PcDiskReadLogicalSectorsLBA(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) -{ - REGS RegsIn; - REGS RegsOut; - ULONG RetryCount; - PI386_DISK_ADDRESS_PACKET Packet = (PI386_DISK_ADDRESS_PACKET)(BIOSCALLBUFFER); - - DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsLBA() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer)); - - // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ - RegsIn.b.ah = 0x42; // Subfunction 42h - RegsIn.b.dl = DriveNumber; // Drive number in DL (0 - floppy, 0x80 - harddisk) - RegsIn.x.ds = BIOSCALLBUFSEGMENT; // DS:SI -> disk address packet - RegsIn.w.si = BIOSCALLBUFOFFSET; - - // Setup disk address packet - RtlZeroMemory(Packet, sizeof(I386_DISK_ADDRESS_PACKET)); - Packet->PacketSize = sizeof(I386_DISK_ADDRESS_PACKET); - Packet->Reserved = 0; - Packet->LBABlockCount = SectorCount; - Packet->TransferBufferOffset = ((ULONG_PTR)Buffer) & 0x0F; - Packet->TransferBufferSegment = ((ULONG_PTR)Buffer) >> 4; - Packet->LBAStartBlock = SectorNumber; - - // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ - // Return: - // CF clear if successful - // AH = 00h - // CF set on error - // AH = error code - // disk address packet's block count field set to the - // number of blocks successfully transferred - - // Retry 3 times - for (RetryCount=0; RetryCount<3; RetryCount++) - { - Int386(0x13, &RegsIn, &RegsOut); - - // If it worked return TRUE - if (INT386_SUCCESS(RegsOut)) - { - return TRUE; - } - // If it was a corrected ECC error then the data is still good - else if (RegsOut.b.ah == 0x11) - { - return TRUE; - } - // If it failed the do the next retry - else - { - PcDiskResetController(DriveNumber); - - continue; - } - } - - // If we get here then the read failed - DiskError("Disk Read Failed in LBA mode", RegsOut.b.ah); - - return FALSE; -} - -static BOOLEAN PcDiskReadLogicalSectorsCHS(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) -{ - ULONG PhysicalSector; - ULONG PhysicalHead; - ULONG PhysicalTrack; - GEOMETRY DriveGeometry; - ULONG NumberOfSectorsToRead; - REGS RegsIn; - REGS RegsOut; - ULONG RetryCount; - - DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsCHS()\n")); - - // - // Get the drive geometry - // - if (!MachDiskGetDriveGeometry(DriveNumber, &DriveGeometry) || - DriveGeometry.Sectors == 0 || - DriveGeometry.Heads == 0) - { - return FALSE; - } - - while (SectorCount) - { - - // - // Calculate the physical disk offsets - // - PhysicalSector = 1 + (SectorNumber % DriveGeometry.Sectors); - PhysicalHead = (SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads; - PhysicalTrack = (SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads; - - // - // Calculate how many sectors we need to read this round - // - if (PhysicalSector > 1) - { - if (SectorCount >= (DriveGeometry.Sectors - (PhysicalSector - 1))) - NumberOfSectorsToRead = (DriveGeometry.Sectors - (PhysicalSector - 1)); - else - NumberOfSectorsToRead = SectorCount; - } - else - { - if (SectorCount >= DriveGeometry.Sectors) - NumberOfSectorsToRead = DriveGeometry.Sectors; - else - NumberOfSectorsToRead = SectorCount; - } - - // - // Make sure the read is within the geometry boundaries - // - if ((PhysicalHead >= DriveGeometry.Heads) || - (PhysicalTrack >= DriveGeometry.Cylinders) || - ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.Sectors + 1)) || - (PhysicalSector > DriveGeometry.Sectors)) - { - DiskError("Disk read exceeds drive geometry limits.", 0); - return FALSE; - } - - // BIOS Int 13h, function 2 - Read Disk Sectors - // AH = 02h - // AL = number of sectors to read (must be nonzero) - // CH = low eight bits of cylinder number - // CL = sector number 1-63 (bits 0-5) - // high two bits of cylinder (bits 6-7, hard disk only) - // DH = head number - // DL = drive number (bit 7 set for hard disk) - // ES:BX -> data buffer - // Return: - // CF set on error - // if AH = 11h (corrected ECC error), AL = burst length - // CF clear if successful - // AH = status - // AL = number of sectors transferred - // (only valid if CF set for some BIOSes) - RegsIn.b.ah = 0x02; - RegsIn.b.al = NumberOfSectorsToRead; - RegsIn.b.ch = (PhysicalTrack & 0xFF); - RegsIn.b.cl = (PhysicalSector + ((PhysicalTrack & 0x300) >> 2)); - RegsIn.b.dh = PhysicalHead; - RegsIn.b.dl = DriveNumber; - RegsIn.w.es = ((ULONG_PTR)Buffer) >> 4; - RegsIn.w.bx = ((ULONG_PTR)Buffer) & 0x0F; - - // - // Perform the read - // Retry 3 times - // - for (RetryCount=0; RetryCount<3; RetryCount++) - { - Int386(0x13, &RegsIn, &RegsOut); - - // If it worked break out - if (INT386_SUCCESS(RegsOut)) - { - break; - } - // If it was a corrected ECC error then the data is still good - else if (RegsOut.b.ah == 0x11) - { - break; - } - // If it failed the do the next retry - else - { - PcDiskResetController(DriveNumber); - - continue; - } - } - - // If we retried 3 times then fail - if (RetryCount >= 3) - { - DiskError("Disk Read Failed in CHS mode, after retrying 3 times", RegsOut.b.ah); - return FALSE; - } - - // I have learned that not all bioses return - // the sector read count in the AL register (at least mine doesn't) - // even if the sectors were read correctly. So instead - // of checking the sector read count we will rely solely - // on the carry flag being set on error - - Buffer = (PVOID)((ULONG_PTR)Buffer + (NumberOfSectorsToRead * DriveGeometry.BytesPerSector)); - SectorCount -= NumberOfSectorsToRead; - SectorNumber += NumberOfSectorsToRead; - } - - return TRUE; -} - -static BOOLEAN PcDiskInt13ExtensionsSupported(ULONG DriveNumber) -{ - static ULONG LastDriveNumber = 0xffffffff; - static BOOLEAN LastSupported; - REGS RegsIn; - REGS RegsOut; - - DbgPrint((DPRINT_DISK, "PcDiskInt13ExtensionsSupported()\n")); - - if (DriveNumber == LastDriveNumber) - { - DbgPrint((DPRINT_DISK, "Using cached value %s for drive 0x%x\n", LastSupported ? "TRUE" : "FALSE", DriveNumber)); - return LastSupported; - } - - // Some BIOSes report that extended disk access functions are not supported - // when booting from a CD (e.g. Phoenix BIOS v6.00PG and Insyde BIOS shipping - // with Intel Macs). Therefore we just return TRUE if we're booting from a CD - - // we can assume that all El Torito capable BIOSes support INT 13 extensions. - // We simply detect whether we're booting from CD by checking whether the drive - // number is >= 0x90. It's 0x90 on the Insyde BIOS, and 0x9F on most other BIOSes. - if (DriveNumber >= 0x90) - { - LastSupported = TRUE; - return TRUE; - } - - LastDriveNumber = DriveNumber; - - // IBM/MS INT 13 Extensions - INSTALLATION CHECK - // AH = 41h - // BX = 55AAh - // DL = drive (80h-FFh) - // Return: - // CF set on error (extensions not supported) - // AH = 01h (invalid function) - // CF clear if successful - // BX = AA55h if installed - // AH = major version of extensions - // 01h = 1.x - // 20h = 2.0 / EDD-1.0 - // 21h = 2.1 / EDD-1.1 - // 30h = EDD-3.0 - // AL = internal use - // CX = API subset support bitmap - // DH = extension version (v2.0+ ??? -- not present in 1.x) - // - // Bitfields for IBM/MS INT 13 Extensions API support bitmap - // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported - // Bit 1, removable drive controller functions (AH=45h,46h,48h,49h,INT 15/AH=52h) supported - // Bit 2, enhanced disk drive (EDD) functions (AH=48h,AH=4Eh) supported - // extended drive parameter table is valid - // Bits 3-15 reserved - RegsIn.b.ah = 0x41; - RegsIn.w.bx = 0x55AA; - RegsIn.b.dl = DriveNumber; - - // Reset the disk controller - Int386(0x13, &RegsIn, &RegsOut); - - if (!INT386_SUCCESS(RegsOut)) - { - // CF set on error (extensions not supported) - LastSupported = FALSE; - return FALSE; - } - - if (RegsOut.w.bx != 0xAA55) - { - // BX = AA55h if installed - LastSupported = FALSE; - return FALSE; - } - - if (!(RegsOut.w.cx & 0x0001)) - { - // CX = API subset support bitmap - // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported - printf("Suspicious API subset support bitmap 0x%x on device 0x%lx\n", RegsOut.w.cx, DriveNumber); - LastSupported = FALSE; - return FALSE; - } - - LastSupported = TRUE; - return TRUE; -} - -BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) -{ - - DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer)); - - // - // Check to see if it is a fixed disk drive - // If so then check to see if Int13 extensions work - // If they do then use them, otherwise default back to BIOS calls - // - if ((DriveNumber >= 0x80) && PcDiskInt13ExtensionsSupported(DriveNumber)) - { - DbgPrint((DPRINT_DISK, "Using Int 13 Extensions for read. PcDiskInt13ExtensionsSupported(%d) = %s\n", DriveNumber, PcDiskInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE")); - - // - // LBA is easy, nothing to calculate - // Just do the read - // - return PcDiskReadLogicalSectorsLBA(DriveNumber, SectorNumber, SectorCount, Buffer); - } - else - { - // LBA is not supported default to the CHS calls - return PcDiskReadLogicalSectorsCHS(DriveNumber, SectorNumber, SectorCount, Buffer); - } - - return TRUE; -} - -BOOLEAN -PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry) -{ - REGS RegsIn; - REGS RegsOut; - ULONG Cylinders; - - DbgPrint((DPRINT_DISK, "DiskGetDriveGeometry()\n")); - - /* BIOS Int 13h, function 08h - Get drive parameters - * AH = 08h - * DL = drive (bit 7 set for hard disk) - * ES:DI = 0000h:0000h to guard against BIOS bugs - * Return: - * CF set on error - * AH = status (07h) - * CF clear if successful - * AH = 00h - * AL = 00h on at least some BIOSes - * BL = drive type (AT/PS2 floppies only) - * CH = low eight bits of maximum cylinder number - * CL = maximum sector number (bits 5-0) - * high two bits of maximum cylinder number (bits 7-6) - * DH = maximum head number - * DL = number of drives - * ES:DI -> drive parameter table (floppies only) - */ - RegsIn.b.ah = 0x08; - RegsIn.b.dl = DriveNumber; - RegsIn.w.es = 0x0000; - RegsIn.w.di = 0x0000; - - /* Get drive parameters */ - Int386(0x13, &RegsIn, &RegsOut); - - if (! INT386_SUCCESS(RegsOut)) - { - return FALSE; - } - - Cylinders = (RegsOut.b.cl & 0xC0) << 2; - Cylinders += RegsOut.b.ch; - Cylinders++; - Geometry->Cylinders = Cylinders; - Geometry->Heads = RegsOut.b.dh + 1; - Geometry->Sectors = RegsOut.b.cl & 0x3F; - Geometry->BytesPerSector = 512; /* Just assume 512 bytes per sector */ - - return TRUE; -} - -ULONG -PcDiskGetCacheableBlockCount(ULONG DriveNumber) -{ - GEOMETRY Geometry; - - /* If LBA is supported then the block size will be 64 sectors (32k) - * If not then the block size is the size of one track */ - if (DiskInt13ExtensionsSupported(DriveNumber)) - { - return 64; - } - /* Get the disk geometry - * If this fails then we will just return 1 sector to be safe */ - else if (! PcDiskGetDriveGeometry(DriveNumber, &Geometry)) - { - return 1; - } - else - { - return Geometry.Sectors; - } -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pcmem.c b/reactos/boot/freeldr/freeldr/arch/amd64/pcmem.c deleted file mode 100644 index 914a363cc9a..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pcmem.c +++ /dev/null @@ -1,249 +0,0 @@ -/* $Id: pcmem.c 24238 2006-09-23 16:50:39Z fireball $ - * - * FreeLoader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Note: Most of this code comes from the old file "i386mem.c", which - * was Copyright (C) 1998-2003 Brian Palmer - */ - -#include - -#define NDEBUG -#include - -static ULONG -PcMemGetExtendedMemorySize(VOID) -{ - REGS RegsIn; - REGS RegsOut; - ULONG MemorySize; - - DbgPrint((DPRINT_MEMORY, "GetExtendedMemorySize()\n")); - - /* Int 15h AX=E801h - * Phoenix BIOS v4.0 - GET MEMORY SIZE FOR >64M CONFIGURATIONS - * - * AX = E801h - * Return: - * CF clear if successful - * AX = extended memory between 1M and 16M, in K (max 3C00h = 15MB) - * BX = extended memory above 16M, in 64K blocks - * CX = configured memory 1M to 16M, in K - * DX = configured memory above 16M, in 64K blocks - * CF set on error - */ - RegsIn.w.ax = 0xE801; - Int386(0x15, &RegsIn, &RegsOut); - - DbgPrint((DPRINT_MEMORY, "Int15h AX=E801h\n")); - DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax)); - DbgPrint((DPRINT_MEMORY, "BX = 0x%x\n", RegsOut.w.bx)); - DbgPrint((DPRINT_MEMORY, "CX = 0x%x\n", RegsOut.w.cx)); - DbgPrint((DPRINT_MEMORY, "DX = 0x%x\n", RegsOut.w.dx)); - DbgPrint((DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE")); - - if (INT386_SUCCESS(RegsOut)) - { - /* If AX=BX=0000h the use CX and DX */ - if (RegsOut.w.ax == 0) - { - /* Return extended memory size in K */ - MemorySize = RegsOut.w.dx * 64; - MemorySize += RegsOut.w.cx; - return MemorySize; - } - else - { - /* Return extended memory size in K */ - MemorySize = RegsOut.w.bx * 64; - MemorySize += RegsOut.w.ax; - return MemorySize; - } - } - - /* If we get here then Int15 Func E801h didn't work */ - /* So try Int15 Func 88h */ - - /* Int 15h AH=88h - * SYSTEM - GET EXTENDED MEMORY SIZE (286+) - * - * AH = 88h - * Return: - * CF clear if successful - * AX = number of contiguous KB starting at absolute address 100000h - * CF set on error - * AH = status - * 80h invalid command (PC,PCjr) - * 86h unsupported function (XT,PS30) - */ - RegsIn.b.ah = 0x88; - Int386(0x15, &RegsIn, &RegsOut); - - DbgPrint((DPRINT_MEMORY, "Int15h AH=88h\n")); - DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax)); - DbgPrint((DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE")); - - if (INT386_SUCCESS(RegsOut) && RegsOut.w.ax != 0) - { - MemorySize = RegsOut.w.ax; - return MemorySize; - } - - /* If we get here then Int15 Func 88h didn't work */ - /* So try reading the CMOS */ - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x31); - MemorySize = READ_PORT_UCHAR((PUCHAR)0x71); - MemorySize = (MemorySize & 0xFFFF); - MemorySize = (MemorySize << 8); - - DbgPrint((DPRINT_MEMORY, "Int15h Failed\n")); - DbgPrint((DPRINT_MEMORY, "CMOS reports: 0x%x\n", MemorySize)); - - return MemorySize; -} - -static ULONG -PcMemGetConventionalMemorySize(VOID) -{ - REGS Regs; - - DbgPrint((DPRINT_MEMORY, "GetConventionalMemorySize()\n")); - - /* Int 12h - * BIOS - GET MEMORY SIZE - * - * Return: - * AX = kilobytes of contiguous memory starting at absolute address 00000h - * - * This call returns the contents of the word at 0040h:0013h; - * in PC and XT, this value is set from the switches on the motherboard - */ - Regs.w.ax = 0; - Int386(0x12, &Regs, &Regs); - - DbgPrint((DPRINT_MEMORY, "Int12h\n")); - DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n\n", Regs.w.ax)); - - return (ULONG)Regs.w.ax; -} - -static ULONG -PcMemGetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize) -{ - REGS Regs; - ULONG MapCount; - - DbgPrint((DPRINT_MEMORY, "GetBiosMemoryMap()\n")); - - /* Int 15h AX=E820h - * Newer BIOSes - GET SYSTEM MEMORY MAP - * - * AX = E820h - * EAX = 0000E820h - * EDX = 534D4150h ('SMAP') - * EBX = continuation value or 00000000h to start at beginning of map - * ECX = size of buffer for result, in bytes (should be >= 20 bytes) - * ES:DI -> buffer for result - * Return: - * CF clear if successful - * EAX = 534D4150h ('SMAP') - * ES:DI buffer filled - * EBX = next offset from which to copy or 00000000h if all done - * ECX = actual length returned in bytes - * CF set on error - * AH = error code (86h) - */ - Regs.x.eax = 0x0000E820; - Regs.x.edx = 0x534D4150; /* ('SMAP') */ - Regs.x.ebx = 0x00000000; - Regs.x.ecx = sizeof(BIOS_MEMORY_MAP); - Regs.w.es = BIOSCALLBUFSEGMENT; - Regs.w.di = BIOSCALLBUFOFFSET; - for (MapCount = 0; MapCount < MaxMemoryMapSize; MapCount++) - { - Int386(0x15, &Regs, &Regs); - - DbgPrint((DPRINT_MEMORY, "Memory Map Entry %d\n", MapCount)); - DbgPrint((DPRINT_MEMORY, "Int15h AX=E820h\n")); - DbgPrint((DPRINT_MEMORY, "EAX = 0x%x\n", Regs.x.eax)); - DbgPrint((DPRINT_MEMORY, "EBX = 0x%x\n", Regs.x.ebx)); - DbgPrint((DPRINT_MEMORY, "ECX = 0x%x\n", Regs.x.ecx)); - DbgPrint((DPRINT_MEMORY, "CF set = %s\n", (Regs.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE")); - - /* If the BIOS didn't return 'SMAP' in EAX then - * it doesn't support this call */ - if (Regs.x.eax != 0x534D4150) - { - break; - } - - /* Copy data to caller's buffer */ - RtlCopyMemory(&BiosMemoryMap[MapCount], (PVOID)BIOSCALLBUFFER, Regs.x.ecx); - - DbgPrint((DPRINT_MEMORY, "BaseAddress: 0x%p\n", (PVOID)BiosMemoryMap[MapCount].BaseAddress)); - DbgPrint((DPRINT_MEMORY, "Length: 0x%p\n", (PVOID)BiosMemoryMap[MapCount].Length)); - DbgPrint((DPRINT_MEMORY, "Type: 0x%x\n", BiosMemoryMap[MapCount].Type)); - DbgPrint((DPRINT_MEMORY, "Reserved: 0x%x\n", BiosMemoryMap[MapCount].Reserved)); - DbgPrint((DPRINT_MEMORY, "\n")); - - /* If the continuation value is zero or the - * carry flag is set then this was - * the last entry so we're done */ - if (Regs.x.ebx == 0x00000000 || !INT386_SUCCESS(Regs)) - { - MapCount++; - DbgPrint((DPRINT_MEMORY, "End Of System Memory Map!\n\n")); - break; - } - - /* Setup the registers for the next call */ - Regs.x.eax = 0x0000E820; - Regs.x.edx = 0x534D4150; /* ('SMAP') */ - /* Regs.x.ebx = 0x00000001; Continuation value already set by the BIOS */ - Regs.x.ecx = sizeof(BIOS_MEMORY_MAP); - Regs.w.es = BIOSCALLBUFSEGMENT; - Regs.w.di = BIOSCALLBUFOFFSET; - } - - return MapCount; -} - -ULONG -PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize) -{ - ULONG EntryCount; - - EntryCount = PcMemGetBiosMemoryMap(BiosMemoryMap, MaxMemoryMapSize); - - /* If the BIOS didn't provide a memory map, synthesize one */ - if (0 == EntryCount && 2 <= MaxMemoryMapSize) - { - /* Conventional memory */ - BiosMemoryMap[0].BaseAddress = 0; - BiosMemoryMap[0].Length = PcMemGetConventionalMemorySize() * 1024; - BiosMemoryMap[0].Type = BiosMemoryUsable; - /* Extended memory */ - BiosMemoryMap[1].BaseAddress = 1024 * 1024; - BiosMemoryMap[1].Length = PcMemGetExtendedMemorySize() * 1024; - BiosMemoryMap[1].Type = BiosMemoryUsable; - EntryCount = 2; - } - - return EntryCount; -} - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c b/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c deleted file mode 100644 index 1e9234fcdad..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c +++ /dev/null @@ -1,5 +0,0 @@ -/* No need to duplicate code ; import the i386 version */ - -#include "../i386/pcrtc.c" - -/* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pcvideo.c b/reactos/boot/freeldr/freeldr/arch/amd64/pcvideo.c deleted file mode 100644 index fd3668c38b4..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pcvideo.c +++ /dev/null @@ -1,1122 +0,0 @@ -/* $Id: pcvideo.c 31712 2008-01-11 11:35:09Z hpoussin $ - * - * FreeLoader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define NDEBUG -#include - -#define VIDEOPORT_PALETTE_READ 0x03C7 -#define VIDEOPORT_PALETTE_WRITE 0x03C8 -#define VIDEOPORT_PALETTE_DATA 0x03C9 -#define VIDEOPORT_VERTICAL_RETRACE 0x03DA - -#define VIDEOVGA_MEM_ADDRESS 0xA0000 -#define VIDEOTEXT_MEM_ADDRESS 0xB8000 -#define VIDEOTEXT_MEM_SIZE 0x8000 - -#define VIDEOCARD_CGA_OR_OTHER 0 -#define VIDEOCARD_EGA 1 -#define VIDEOCARD_VGA 2 - -#define VIDEOMODE_NORMAL_TEXT 0 -#define VIDEOMODE_EXTENDED_TEXT 1 -#define VIDEOMODE_80X28 0x501C -#define VIDEOMODE_80X30 0x501E -#define VIDEOMODE_80X34 0x5022 -#define VIDEOMODE_80X43 0x502B -#define VIDEOMODE_80X60 0x503C -#define VIDEOMODE_132X25 0x8419 -#define VIDEOMODE_132X43 0x842B -#define VIDEOMODE_132X50 0x8432 -#define VIDEOMODE_132X60 0x843C - -#define VERTRES_200_SCANLINES 0x00 -#define VERTRES_350_SCANLINES 0x01 -#define VERTRES_400_SCANLINES 0x02 - -typedef struct -{ - USHORT ModeAttributes; /* mode attributes (see #00080) */ - UCHAR WindowAttributesA; /* window attributes, window A (see #00081) */ - UCHAR WindowsAttributesB; /* window attributes, window B (see #00081) */ - USHORT WindowGranularity; /* window granularity in KB */ - USHORT WindowSize; /* window size in KB */ - USHORT WindowAStartSegment; /* start segment of window A (0000h if not supported) */ - USHORT WindowBStartSegment; /* start segment of window B (0000h if not supported) */ - ULONG WindowPositioningFunction; /* -> FAR window positioning function (equivalent to AX=4F05h) */ - USHORT BytesPerScanLine; /* bytes per scan line */ - /* ---remainder is optional for VESA modes in v1.0/1.1, needed for OEM modes--- */ - USHORT WidthInPixels; /* width in pixels (graphics) or characters (text) */ - USHORT HeightInPixels; /* height in pixels (graphics) or characters (text) */ - UCHAR CharacterWidthInPixels; /* width of character cell in pixels */ - UCHAR CharacterHeightInPixels; /* height of character cell in pixels */ - UCHAR NumberOfMemoryPlanes; /* number of memory planes */ - UCHAR BitsPerPixel; /* number of bits per pixel */ - UCHAR NumberOfBanks; /* number of banks */ - UCHAR MemoryModel; /* memory model type (see #00082) */ - UCHAR BankSize; /* size of bank in KB */ - UCHAR NumberOfImagePanes; /* number of image pages (less one) that will fit in video RAM */ - UCHAR Reserved1; /* reserved (00h for VBE 1.0-2.0, 01h for VBE 3.0) */ - /* ---VBE v1.2+ --- */ - UCHAR RedMaskSize; /* red mask size */ - UCHAR RedMaskPosition; /* red field position */ - UCHAR GreenMaskSize; /* green mask size */ - UCHAR GreenMaskPosition; /* green field size */ - UCHAR BlueMaskSize; /* blue mask size */ - UCHAR BlueMaskPosition; /* blue field size */ - UCHAR ReservedMaskSize; /* reserved mask size */ - UCHAR ReservedMaskPosition; /* reserved mask position */ - UCHAR DirectColorModeInfo; /* direct color mode info */ - /* bit 0:Color ramp is programmable */ - /* bit 1:Bytes in reserved field may be used by application */ - /* ---VBE v2.0+ --- */ - ULONG LinearVideoBufferAddress; /* physical address of linear video buffer */ - ULONG OffscreenMemoryPointer; /* pointer to start of offscreen memory */ - USHORT OffscreenMemorySize; /* KB of offscreen memory */ - /* ---VBE v3.0 --- */ - USHORT LinearBytesPerScanLine; /* bytes per scan line in linear modes */ - UCHAR BankedNumberOfImages; /* number of images (less one) for banked video modes */ - UCHAR LinearNumberOfImages; /* number of images (less one) for linear video modes */ - UCHAR LinearRedMaskSize; /* linear modes:Size of direct color red mask (in bits) */ - UCHAR LinearRedMaskPosition; /* linear modes:Bit position of red mask LSB (e.g. shift count) */ - UCHAR LinearGreenMaskSize; /* linear modes:Size of direct color green mask (in bits) */ - UCHAR LinearGreenMaskPosition; /* linear modes:Bit position of green mask LSB (e.g. shift count) */ - UCHAR LinearBlueMaskSize; /* linear modes:Size of direct color blue mask (in bits) */ - UCHAR LinearBlueMaskPosition; /* linear modes:Bit position of blue mask LSB (e.g. shift count) */ - UCHAR LinearReservedMaskSize; /* linear modes:Size of direct color reserved mask (in bits) */ - UCHAR LinearReservedMaskPosition; /* linear modes:Bit position of reserved mask LSB */ - ULONG MaximumPixelClock; /* maximum pixel clock for graphics video mode, in Hz */ - UCHAR Reserved2[190]; /* 190 BYTEs reserved (0) */ -} PACKED SVGA_MODE_INFORMATION, *PSVGA_MODE_INFORMATION; - -static ULONG BiosVideoMode; /* Current video mode as known by BIOS */ -static ULONG ScreenWidth = 80; /* Screen Width in characters */ -static ULONG ScreenHeight = 25; /* Screen Height in characters */ -static ULONG BytesPerScanLine = 160; /* Number of bytes per scanline (delta) */ -static VIDEODISPLAYMODE DisplayMode = VideoTextMode; /* Current display mode */ -static BOOLEAN VesaVideoMode = FALSE; /* Are we using a VESA mode? */ -static SVGA_MODE_INFORMATION VesaVideoModeInformation; /* Only valid when in VESA mode */ -static ULONG CurrentMemoryBank = 0; /* Currently selected VESA bank */ - -static ULONG -PcVideoDetectVideoCard(VOID) -{ - REGS Regs; - - /* Int 10h AH=12h BL=10h - * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - GET EGA INFO - * - * AH = 12h - * BL = 10h - * Return: - * BH = video state - * 00h color mode in effect (I/O port 3Dxh) - * 01h mono mode in effect (I/O port 3Bxh) - * BL = installed memory (00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K) - * CH = feature connector bits - * CL = switch settings - * AH destroyed (at least by Tseng ET4000 BIOS v8.00n) - * - * Installation check;EGA - */ - Regs.b.ah = 0x12; - Regs.b.bl = 0x10; - Int386(0x10, &Regs, &Regs); - - /* If BL is still equal to 0x10 then there is no EGA/VGA present */ - if (0x10 == Regs.b.bl) - { - return VIDEOCARD_CGA_OR_OTHER; - } - - /* Int 10h AX=1A00h - * VIDEO - GET DISPLAY COMBINATION CODE (PS,VGA/MCGA) - * - * AX = 1A00h - * Return: - * AL = 1Ah if function was supported - * BL = active display code - * BH = alternate display code - * - * This function is commonly used to check for the presence of a VGA. - * - * Installation check;VGA - * - * Values for display combination code: - * 00h no display - * 01h monochrome adapter w/ monochrome display - * 02h CGA w/ color display - * 03h reserved - * 04h EGA w/ color display - * 05h EGA w/ monochrome display - * 06h PGA w/ color display - * 07h VGA w/ monochrome analog display - * 08h VGA w/ color analog display - * 09h reserved - * 0Ah MCGA w/ digital color display - * 0Bh MCGA w/ monochrome analog display - * 0Ch MCGA w/ color analog display - * FFh unknown display type - */ - Regs.b.ah = 0x12; - Regs.b.bl = 0x10; - Int386(0x10, &Regs, &Regs); - - if (0x1a == Regs.b.al) - { - return VIDEOCARD_VGA; - } - else - { - return VIDEOCARD_EGA; - } -} - -static VOID PcVideoSetBiosMode(ULONG VideoMode) -{ - REGS Regs; - - /* Int 10h AH=00h - * VIDEO - SET VIDEO MODE - * - * AH = 00h - * AL = desired video mode - * Return: - * AL = video mode flag (Phoenix, AMI BIOS) - * 20h mode > 7 - * 30h modes 0-5 and 7 - * 3Fh mode 6 - * AL = CRT controller mode byte (Phoenix 386 BIOS v1.10) - */ - Regs.b.ah = 0x00; - Regs.b.al = VideoMode; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSetFont8x8(VOID) -{ - REGS Regs; - - /* Int 10h AX=1112h - * VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x8 DBL-DOT PATTERNS (PS,EGA,VGA) - * - * AX = 1112h - * BL = block to load - * Return: - * Nothing - */ - Regs.w.ax = 0x1112; - Regs.b.bl = 0x00; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSetFont8x14(VOID) -{ - REGS Regs; - - /* Int 10h AX=1111h - * VIDEO - TEXT-MODE CHARGEN - LOAD ROM MONOCHROME PATTERNS (PS,EGA,VGA) - * - * AX = 1111h - * BL = block to load - * Return: - * Nothing - */ - Regs.w.ax = 0x1111; - Regs.b.bl = 0; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSelectAlternatePrintScreen(VOID) -{ - REGS Regs; - - /* Int 10h AH=12h BL=20h - * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - ALTERNATE PRTSC - * - * AH = 12h - * BL = 20h select alternate print screen routine - * Return: - * Nothing - * - * Installs a PrtSc routine from the video card's BIOS to replace the - * default PrtSc handler from the ROM BIOS, which usually does not - * understand screen heights other than 25 lines. - * - * Some adapters disable print-screen instead of enhancing it. - */ - Regs.b.ah = 0x12; - Regs.b.bl = 0x20; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoDisableCursorEmulation(VOID) -{ - REGS Regs; - - /* Int 10h AH=12h BL=34h - * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - CURSOR EMULATION - * - * AH = 12h - * BL = 34h - * AL = new state - * 00h enable alphanumeric cursor emulation - * 01h disable alphanumeric cursor emulation - * Return: - * AL = 12h if function supported - * - * Specify whether the BIOS should automatically remap cursor start/end - * according to the current character height in text modes. - */ - Regs.b.ah = 0x12; - Regs.b.bl = 0x34; - Regs.b.al = 0x01; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoDefineCursor(ULONG StartScanLine, ULONG EndScanLine) -{ - REGS Regs; - - /* Int 10h AH=01h - * VIDEO - SET TEXT-MODE CURSOR SHAPE - * - * AH = 01h - * CH = cursor start and options - * CL = bottom scan line containing cursor (bits 0-4) - * Return: - * Nothing - * - * Specify the starting and ending scan lines to be occupied - * by the hardware cursor in text modes. - * - * AMI 386 BIOS and AST Premier 386 BIOS will lock up the - * system if AL is not equal to the current video mode. - * - * Bitfields for cursor start and options: - * - * Bit(s) Description - * 7 should be zero - * 6,5 cursor blink - * (00=normal, 01=invisible, 10=erratic, 11=slow). - * (00=normal, other=invisible on EGA/VGA) - * 4-0 topmost scan line containing cursor - */ - Regs.b.ah = 0x01; - Regs.b.al = 0x03; - Regs.b.ch = StartScanLine; - Regs.b.cl = EndScanLine; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSetVerticalResolution(ULONG ScanLines) -{ - REGS Regs; - - /* Int 10h AH=12h BL=30h - * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - SELECT VERTICAL RESOLUTION - * - * AH = 12h - * BL = 30h - * AL = vertical resolution - * 00h 200 scan lines - * 01h 350 scan lines - * 02h 400 scan lines - * Return: - * AL = 12h if function supported - * - * Specifiy the number of scan lines used to display text modes. - * - * The specified resolution will take effect on the next mode set. - */ - Regs.b.ah = 0x12; - Regs.b.bl = 0x30; - Regs.b.al = ScanLines; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSet480ScanLines(VOID) -{ - INT_PTR CRTC; - - /* Read CRTC port */ - CRTC = READ_PORT_UCHAR((PUCHAR)0x03CC); - - if (CRTC & 1) - { - CRTC = 0x3D4; - } - else - { - CRTC = 0x3B4; - } - - /* Vertical sync end (also unlocks CR0-7) */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x11); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0x0C); - - /* Vertical total */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x06); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0x0B); - - /* (vertical) overflow */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x07); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0x3E); - - /* Vertical sync start */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x10); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0xEA); - - /* Vertical display end */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x12); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0xDF); - - /* Vertical blank start */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x15); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0xE7); - - /* Vertical blank end */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x16); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0x04); - - /* Misc output register (read) */ - CRTC = READ_PORT_UCHAR((PUCHAR)0x03CC); - - /* Preserve clock select bits and color bit */ - CRTC = (CRTC & 0x0D); - /* Set correct sync polarity */ - CRTC = (CRTC | 0xE2); - - /* (write) */ - WRITE_PORT_UCHAR((PUCHAR)0x03C2, CRTC); -} - -static VOID -PcVideoSetDisplayEnd(VOID) -{ - INT_PTR CRTC; - - /* Read CRTC port */ - CRTC = READ_PORT_UCHAR((PUCHAR)0x03CC); - - if (CRTC & 1) - { - CRTC = 0x3D4; - } - else - { - CRTC = 0x3B4; - } - - /* Vertical display end */ - WRITE_PORT_UCHAR((PUCHAR)CRTC, 0x12); - WRITE_PORT_UCHAR((PUCHAR)CRTC+1, 0xDF); -} - -static BOOLEAN -PcVideoVesaGetSVGAModeInformation(USHORT Mode, PSVGA_MODE_INFORMATION ModeInformation) -{ - REGS Regs; - - RtlZeroMemory((PVOID)BIOSCALLBUFFER, 256); - - /* VESA SuperVGA BIOS - GET SuperVGA MODE INFORMATION - * AX = 4F01h - * CX = SuperVGA video mode (see #04082 for bitfields) - * ES:DI -> 256-byte buffer for mode information (see #00079) - * Return: - * AL = 4Fh if function supported - * AH = status - * 00h successful - * ES:DI buffer filled - * 01h failed - * - * Desc: Determine the attributes of the specified video mode - * - * Note: While VBE 1.1 and higher will zero out all unused bytes - * of the buffer, v1.0 did not, so applications that want to be - * backward compatible should clear the buffer before calling - */ - Regs.w.ax = 0x4F01; - Regs.w.cx = Mode; - Regs.w.es = BIOSCALLBUFSEGMENT; - Regs.w.di = BIOSCALLBUFOFFSET; - Int386(0x10, &Regs, &Regs); - - if (Regs.w.ax != 0x004F) - { - return FALSE; - } - - RtlCopyMemory(ModeInformation, (PVOID)BIOSCALLBUFFER, sizeof(SVGA_MODE_INFORMATION)); - - DbgPrint((DPRINT_UI, "\n")); - DbgPrint((DPRINT_UI, "BiosVesaGetSVGAModeInformation() mode 0x%x\n", Mode)); - DbgPrint((DPRINT_UI, "ModeAttributes = 0x%x\n", ModeInformation->ModeAttributes)); - DbgPrint((DPRINT_UI, "WindowAttributesA = 0x%x\n", ModeInformation->WindowAttributesA)); - DbgPrint((DPRINT_UI, "WindowAttributesB = 0x%x\n", ModeInformation->WindowsAttributesB)); - DbgPrint((DPRINT_UI, "WindowGranularity = %dKB\n", ModeInformation->WindowGranularity)); - DbgPrint((DPRINT_UI, "WindowSize = %dKB\n", ModeInformation->WindowSize)); - DbgPrint((DPRINT_UI, "WindowAStartSegment = 0x%x\n", ModeInformation->WindowAStartSegment)); - DbgPrint((DPRINT_UI, "WindowBStartSegment = 0x%x\n", ModeInformation->WindowBStartSegment)); - DbgPrint((DPRINT_UI, "WindowPositioningFunction = 0x%x\n", ModeInformation->WindowPositioningFunction)); - DbgPrint((DPRINT_UI, "BytesPerScanLine = %d\n", ModeInformation->BytesPerScanLine)); - DbgPrint((DPRINT_UI, "WidthInPixels = %d\n", ModeInformation->WidthInPixels)); - DbgPrint((DPRINT_UI, "HeightInPixels = %d\n", ModeInformation->HeightInPixels)); - DbgPrint((DPRINT_UI, "CharacterWidthInPixels = %d\n", ModeInformation->CharacterWidthInPixels)); - DbgPrint((DPRINT_UI, "CharacterHeightInPixels = %d\n", ModeInformation->CharacterHeightInPixels)); - DbgPrint((DPRINT_UI, "NumberOfMemoryPlanes = %d\n", ModeInformation->NumberOfMemoryPlanes)); - DbgPrint((DPRINT_UI, "BitsPerPixel = %d\n", ModeInformation->BitsPerPixel)); - DbgPrint((DPRINT_UI, "NumberOfBanks = %d\n", ModeInformation->NumberOfBanks)); - DbgPrint((DPRINT_UI, "MemoryModel = %d\n", ModeInformation->MemoryModel)); - DbgPrint((DPRINT_UI, "BankSize = %d\n", ModeInformation->BankSize)); - DbgPrint((DPRINT_UI, "NumberOfImagePlanes = %d\n", ModeInformation->NumberOfImagePanes)); - DbgPrint((DPRINT_UI, "---VBE v1.2+ ---\n")); - DbgPrint((DPRINT_UI, "RedMaskSize = %d\n", ModeInformation->RedMaskSize)); - DbgPrint((DPRINT_UI, "RedMaskPosition = %d\n", ModeInformation->RedMaskPosition)); - DbgPrint((DPRINT_UI, "GreenMaskSize = %d\n", ModeInformation->GreenMaskSize)); - DbgPrint((DPRINT_UI, "GreenMaskPosition = %d\n", ModeInformation->GreenMaskPosition)); - DbgPrint((DPRINT_UI, "BlueMaskSize = %d\n", ModeInformation->BlueMaskSize)); - DbgPrint((DPRINT_UI, "BlueMaskPosition = %d\n", ModeInformation->BlueMaskPosition)); - DbgPrint((DPRINT_UI, "ReservedMaskSize = %d\n", ModeInformation->ReservedMaskSize)); - DbgPrint((DPRINT_UI, "ReservedMaskPosition = %d\n", ModeInformation->ReservedMaskPosition)); - DbgPrint((DPRINT_UI, "\n")); - - return TRUE; -} - -static BOOLEAN -PcVideoSetBiosVesaMode(USHORT Mode) -{ - REGS Regs; - - /* Int 10h AX=4F02h - * VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE - * - * AX = 4F02h - * BX = new video mode - * ES:DI -> (VBE 3.0+) CRTC information block, bit mode bit 11 set - * Return: - * AL = 4Fh if function supported - * AH = status - * 00h successful - * 01h failed - * - * Values for VESA video mode: - * 00h-FFh OEM video modes (see #00010 at AH=00h) - * 100h 640x400x256 - * 101h 640x480x256 - * 102h 800x600x16 - * 103h 800x600x256 - * 104h 1024x768x16 - * 105h 1024x768x256 - * 106h 1280x1024x16 - * 107h 1280x1024x256 - * 108h 80x60 text - * 109h 132x25 text - * 10Ah 132x43 text - * 10Bh 132x50 text - * 10Ch 132x60 text - * ---VBE v1.2+ --- - * 10Dh 320x200x32K - * 10Eh 320x200x64K - * 10Fh 320x200x16M - * 110h 640x480x32K - * 111h 640x480x64K - * 112h 640x480x16M - * 113h 800x600x32K - * 114h 800x600x64K - * 115h 800x600x16M - * 116h 1024x768x32K - * 117h 1024x768x64K - * 118h 1024x768x16M - * 119h 1280x1024x32K (1:5:5:5) - * 11Ah 1280x1024x64K (5:6:5) - * 11Bh 1280x1024x16M - * ---VBE 2.0+ --- - * 120h 1600x1200x256 - * 121h 1600x1200x32K - * 122h 1600x1200x64K - * 81FFh special full-memory access mode - * - * Notes: The special mode 81FFh preserves the contents of the video memory and gives - * access to all of the memory; VESA recommends that the special mode be a packed-pixel - * mode. For VBE 2.0+, it is required that the VBE implement the mode, but not place it - * in the list of available modes (mode information for this mode can be queried - * directly, however).. As of VBE 2.0, VESA will no longer define video mode numbers - */ - Regs.w.ax = 0x4F02; - Regs.w.bx = Mode; - Int386(0x10, &Regs, &Regs); - - if (0x004F != Regs.w.ax) - { - return FALSE; - } - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x25(VOID) -{ - PcVideoSetBiosMode(0x03); - ScreenWidth = 80; - ScreenHeight = 25; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x50_80x43(VOID) -{ - if (VIDEOCARD_VGA == PcVideoDetectVideoCard()) - { - PcVideoSetBiosMode(0x12); - PcVideoSetFont8x8(); - PcVideoSelectAlternatePrintScreen(); - PcVideoDisableCursorEmulation(); - PcVideoDefineCursor(6, 7); - ScreenWidth = 80; - ScreenHeight = 50; - } - else if (VIDEOCARD_EGA == PcVideoDetectVideoCard()) - { - PcVideoSetBiosMode(0x03); - PcVideoSetFont8x8(); - PcVideoSelectAlternatePrintScreen(); - PcVideoDisableCursorEmulation(); - PcVideoDefineCursor(6, 7); - ScreenWidth = 80; - ScreenHeight = 43; - } - else /* VIDEOCARD_CGA_OR_OTHER */ - { - return FALSE; - } - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x28(VOID) -{ - /* FIXME: Is this VGA-only? */ - PcVideoSetMode80x25(); - PcVideoSetFont8x14(); - PcVideoDefineCursor(11, 12); - ScreenWidth = 80; - ScreenHeight = 28; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x30(VOID) -{ - /* FIXME: Is this VGA-only? */ - PcVideoSetMode80x25(); - PcVideoSet480ScanLines(); - ScreenWidth = 80; - ScreenHeight = 30; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x34(VOID) -{ - /* FIXME: Is this VGA-only? */ - PcVideoSetMode80x25(); - PcVideoSet480ScanLines(); - PcVideoSetFont8x14(); - PcVideoDefineCursor(11, 12); - PcVideoSetDisplayEnd(); - ScreenWidth = 80; - ScreenHeight = 34; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x43(VOID) -{ - /* FIXME: Is this VGA-only? */ - PcVideoSetVerticalResolution(VERTRES_350_SCANLINES); - PcVideoSetMode80x25(); - PcVideoSetFont8x8(); - PcVideoSelectAlternatePrintScreen(); - PcVideoDisableCursorEmulation(); - PcVideoDefineCursor(6, 7); - ScreenWidth = 80; - ScreenHeight = 43; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode80x60(VOID) -{ - /* FIXME: Is this VGA-only? */ - PcVideoSetMode80x25(); - PcVideoSet480ScanLines(); - PcVideoSetFont8x8(); - PcVideoSelectAlternatePrintScreen(); - PcVideoDisableCursorEmulation(); - PcVideoDefineCursor(6, 7); - PcVideoSetDisplayEnd(); - ScreenWidth = 80; - ScreenHeight = 60; - - return TRUE; -} - -static BOOLEAN -PcVideoSetMode(ULONG NewMode) -{ - CurrentMemoryBank = 0; - - /* Set the values for the default text modes - * If they are setting a graphics mode then - * these values will be changed. - */ - BiosVideoMode = NewMode; - ScreenWidth = 80; - ScreenHeight = 25; - BytesPerScanLine = 160; - DisplayMode = VideoTextMode; - VesaVideoMode = FALSE; - - switch (NewMode) - { - case VIDEOMODE_NORMAL_TEXT: - case 0x03: /* BIOS 80x25 text mode number */ - return PcVideoSetMode80x25(); - case VIDEOMODE_EXTENDED_TEXT: - return PcVideoSetMode80x50_80x43(); - case VIDEOMODE_80X28: - return PcVideoSetMode80x28(); - case VIDEOMODE_80X30: - return PcVideoSetMode80x30(); - case VIDEOMODE_80X34: - return PcVideoSetMode80x34(); - case VIDEOMODE_80X43: - return PcVideoSetMode80x43(); - case VIDEOMODE_80X60: - return PcVideoSetMode80x60(); - } - - if (0x12 == NewMode) - { - /* 640x480x16 */ - PcVideoSetBiosMode(NewMode); - WRITE_PORT_USHORT((USHORT*)0x03CE, 0x0F01); /* For some reason this is necessary? */ - ScreenWidth = 640; - ScreenHeight = 480; - BytesPerScanLine = 80; - BiosVideoMode = NewMode; - DisplayMode = VideoGraphicsMode; - - return TRUE; - } - else if (0x13 == NewMode) - { - /* 320x200x256 */ - PcVideoSetBiosMode(NewMode); - ScreenWidth = 320; - ScreenHeight = 200; - BytesPerScanLine = 320; - BiosVideoMode = NewMode; - DisplayMode = VideoGraphicsMode; - - return TRUE; - } - else if (0x0108 <= NewMode && NewMode <= 0x010C) - { - /* VESA Text Mode */ - if (! PcVideoVesaGetSVGAModeInformation(NewMode, &VesaVideoModeInformation)) - { - return FALSE; - } - - if (! PcVideoSetBiosVesaMode(NewMode)) - { - return FALSE; - } - - ScreenWidth = VesaVideoModeInformation.WidthInPixels; - ScreenHeight = VesaVideoModeInformation.HeightInPixels; - BytesPerScanLine = VesaVideoModeInformation.BytesPerScanLine; - BiosVideoMode = NewMode; - DisplayMode = VideoTextMode; - VesaVideoMode = TRUE; - - return TRUE; - } - else - { - /* VESA Graphics Mode */ - if (! PcVideoVesaGetSVGAModeInformation(NewMode, &VesaVideoModeInformation)) - { - return FALSE; - } - - if (! PcVideoSetBiosVesaMode(NewMode)) - { - return FALSE; - } - - ScreenWidth = VesaVideoModeInformation.WidthInPixels; - ScreenHeight = VesaVideoModeInformation.HeightInPixels; - BytesPerScanLine = VesaVideoModeInformation.BytesPerScanLine; - BiosVideoMode = NewMode; - DisplayMode = VideoTextMode; - VesaVideoMode = TRUE; - - return TRUE; - } - - return FALSE; -} - -static VOID -PcVideoSetBlinkBit(BOOLEAN Enable) -{ - REGS Regs; - - /* Int 10h AX=1003h - * VIDEO - TOGGLE INTENSITY/BLINKING BIT (Jr, PS, TANDY 1000, EGA, VGA) - * - * AX = 1003h - * BL = new state - * 00h background intensity enabled - * 01h blink enabled - * BH = 00h to avoid problems on some adapters - * Return: - * Nothing - * - * Note: although there is no function to get - * the current status, bit 5 of 0040h:0065h - * indicates the state. - */ - Regs.w.ax = 0x1003; - Regs.w.bx = Enable ? 0x0001 : 0x0000; - Int386(0x10, &Regs, &Regs); -} - -static VOID -PcVideoSetMemoryBank(USHORT BankNumber) -{ - REGS Regs; - - if (CurrentMemoryBank != BankNumber) - { - /* Int 10h AX=4F05h - * VESA SuperVGA BIOS - CPU VIDEO MEMORY CONTROL - * - * AX = 4F05h - * BH = subfunction - * 00h select video memory window - * 01h get video memory window - * DX = window address in video memory (in granularity units) - * Return: - * DX = window address in video memory (in gran. units) - * BL = window number - * 00h window A - * 01h window B. - * Return: - * AL = 4Fh if function supported - * AH = status - * 00h successful - * 01h failed - */ - Regs.w.ax = 0x4F05; - Regs.w.bx = 0x0000; - Regs.w.dx = BankNumber; - Int386(0x10, &Regs, &Regs); - - if (0x004F == Regs.w.ax) - { - CurrentMemoryBank = BankNumber; - } - } -} - -VIDEODISPLAYMODE -PcVideoSetDisplayMode(char *DisplayModeName, BOOLEAN Init) -{ - ULONG VideoMode = VIDEOMODE_NORMAL_TEXT; - - if (NULL == DisplayModeName || '\0' == *DisplayModeName) - { - PcVideoSetBlinkBit(! Init); - return DisplayMode; - } - - if (VIDEOCARD_CGA_OR_OTHER == PcVideoDetectVideoCard()) - { - DbgPrint((DPRINT_UI, "CGA or other display adapter detected.\n")); - printf("CGA or other display adapter detected.\n"); - printf("Using 80x25 text mode.\n"); - VideoMode = VIDEOMODE_NORMAL_TEXT; - } - else if (VIDEOCARD_EGA == PcVideoDetectVideoCard()) - { - DbgPrint((DPRINT_UI, "EGA display adapter detected.\n")); - printf("EGA display adapter detected.\n"); - printf("Using 80x25 text mode.\n"); - VideoMode = VIDEOMODE_NORMAL_TEXT; - } - else /* if (VIDEOCARD_VGA == PcVideoDetectVideoCard()) */ - { - DbgPrint((DPRINT_UI, "VGA display adapter detected.\n")); - - if (0 == _stricmp(DisplayModeName, "NORMAL_VGA")) - { - VideoMode = VIDEOMODE_NORMAL_TEXT; - } - else if (0 == _stricmp(DisplayModeName, "EXTENDED_VGA")) - { - VideoMode = VIDEOMODE_EXTENDED_TEXT; - } - else - { - VideoMode = atoi(DisplayModeName); - } - } - - if (! PcVideoSetMode(VideoMode)) - { - printf("Error: unable to set video display mode 0x%x\n", (int) VideoMode); - printf("Defaulting to 80x25 text mode.\n"); - printf("Press any key to continue.\n"); - PcConsGetCh(); - - PcVideoSetMode(VIDEOMODE_NORMAL_TEXT); - } - - PcVideoSetBlinkBit(! Init); - - - return DisplayMode; -} - -VOID -PcVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth) -{ - *Width = ScreenWidth; - *Height = ScreenHeight; - if (VideoGraphicsMode == DisplayMode && VesaVideoMode) - { - if (16 == VesaVideoModeInformation.BitsPerPixel) - { - /* 16-bit color modes give green an extra bit (5:6:5) - * 15-bit color modes have just 5:5:5 for R:G:B */ - *Depth = (6 == VesaVideoModeInformation.GreenMaskSize ? 16 : 15); - } - else - { - *Depth = VesaVideoModeInformation.BitsPerPixel; - } - } - else - { - *Depth = 0; - } -} - -ULONG -PcVideoGetBufferSize(VOID) -{ - return ScreenHeight * BytesPerScanLine; -} - -VOID -PcVideoSetTextCursorPosition(ULONG X, ULONG Y) -{ - REGS Regs; - - /* Int 10h AH=02h - * VIDEO - SET CURSOR POSITION - * - * AH = 02h - * BH = page number - * 0-3 in modes 2&3 - * 0-7 in modes 0&1 - * 0 in graphics modes - * DH = row (00h is top) - * DL = column (00h is left) - * Return: - * Nothing - */ - Regs.b.ah = 0x02; - Regs.b.bh = 0x00; - Regs.b.dh = Y; - Regs.b.dl = X; - Int386(0x10, &Regs, &Regs); -} - -VOID -PcVideoHideShowTextCursor(BOOLEAN Show) -{ - if (Show) - { - PcVideoDefineCursor(0x0D, 0x0E); - } - else - { - PcVideoDefineCursor(0x20, 0x00); - } -} - -VOID -PcVideoCopyOffScreenBufferToVRAM(PVOID Buffer) -{ - ULONG BanksToCopy; - ULONG BytesInLastBank; - ULONG CurrentBank; - ULONG BankSize; - - /* PcVideoWaitForVerticalRetrace(); */ - - /* Text mode (BIOS or VESA) */ - if (VideoTextMode == DisplayMode) - { - RtlCopyMemory((PVOID) VIDEOTEXT_MEM_ADDRESS, Buffer, PcVideoGetBufferSize()); - } - /* VESA graphics mode */ - else if (VideoGraphicsMode == DisplayMode && VesaVideoMode) - { - BankSize = VesaVideoModeInformation.WindowGranularity << 10; - BanksToCopy = (VesaVideoModeInformation.HeightInPixels * VesaVideoModeInformation.BytesPerScanLine) / BankSize; - BytesInLastBank = (VesaVideoModeInformation.HeightInPixels * VesaVideoModeInformation.BytesPerScanLine) % BankSize; - - /* Copy all the banks but the last one because - * it is probably a partial bank */ - for (CurrentBank = 0; CurrentBank < BanksToCopy; CurrentBank++) - { - PcVideoSetMemoryBank(CurrentBank); - RtlCopyMemory((PVOID) VIDEOVGA_MEM_ADDRESS, (char *) Buffer + CurrentBank * BankSize, BankSize); - } - - /* Copy the remaining bytes into the last bank */ - PcVideoSetMemoryBank(CurrentBank); - RtlCopyMemory((PVOID)VIDEOVGA_MEM_ADDRESS, (char *) Buffer + CurrentBank * BankSize, BytesInLastBank); - } - /* BIOS graphics mode */ - else - { - UNIMPLEMENTED; - } -} - -VOID -PcVideoClearScreen(UCHAR Attr) -{ - USHORT AttrChar; - USHORT *BufPtr; - - AttrChar = ((USHORT) Attr << 8) | ' '; - for (BufPtr = (USHORT *) VIDEOTEXT_MEM_ADDRESS; - BufPtr < (USHORT *) (VIDEOTEXT_MEM_ADDRESS + VIDEOTEXT_MEM_SIZE); - BufPtr++) - { - *BufPtr = AttrChar; - } -} - -VOID -PcVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y) -{ - USHORT *BufPtr; - - BufPtr = (USHORT *) (ULONG_PTR)(VIDEOTEXT_MEM_ADDRESS + Y * BytesPerScanLine + X * 2); - *BufPtr = ((USHORT) Attr << 8) | (Ch & 0xff); -} - -BOOLEAN -PcVideoIsPaletteFixed(VOID) -{ - return FALSE; -} - -VOID -PcVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue) -{ - WRITE_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_WRITE, Color); - WRITE_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA, Red); - WRITE_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA, Green); - WRITE_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA, Blue); -} - -VOID -PcVideoGetPaletteColor(UCHAR Color, UCHAR* Red, UCHAR* Green, UCHAR* Blue) -{ - WRITE_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_READ, Color); - *Red = READ_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA); - *Green = READ_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA); - *Blue = READ_PORT_UCHAR((UCHAR*) VIDEOPORT_PALETTE_DATA); -} - -VOID -PcVideoSync(VOID) -{ - while (1 == (READ_PORT_UCHAR((UCHAR*)VIDEOPORT_VERTICAL_RETRACE) & 0x08)) - { - /* - * Keep reading the port until bit 3 is clear - * This waits for the current retrace to end and - * we can catch the next one so we know we are - * getting a full retrace. - */ - } - - while (0 == (READ_PORT_UCHAR((UCHAR*)VIDEOPORT_VERTICAL_RETRACE) & 0x08)) - { - /* - * Keep reading the port until bit 3 is set - * Now that we know we aren't doing a vertical - * retrace we need to wait for the next one. - */ - } -} - -VOID -PcVideoPrepareForReactOS(IN BOOLEAN Setup) -{ - if (Setup) - { - PcVideoSetMode80x50_80x43(); - } - else - { - PcVideoSetBiosMode(0x12); - } - PcVideoHideShowTextCursor(FALSE); -} - -/* EOF */