diff --git a/reactos/ntoskrnl/hal/.cvsignore b/reactos/ntoskrnl/hal/.cvsignore deleted file mode 100644 index 36de49a073e..00000000000 --- a/reactos/ntoskrnl/hal/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.d \ No newline at end of file diff --git a/reactos/ntoskrnl/hal/x86/.cvsignore b/reactos/ntoskrnl/hal/x86/.cvsignore deleted file mode 100644 index 36de49a073e..00000000000 --- a/reactos/ntoskrnl/hal/x86/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.d \ No newline at end of file diff --git a/reactos/ntoskrnl/hal/x86/adapter.c b/reactos/ntoskrnl/hal/x86/adapter.c deleted file mode 100644 index a2ee32608a7..00000000000 --- a/reactos/ntoskrnl/hal/x86/adapter.c +++ /dev/null @@ -1,154 +0,0 @@ -/* $Id: adapter.c,v 1.7 2001/04/26 01:30:17 phreak Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: hal/x86/adapter.c (from ntoskrnl/io/adapter.c) - * PURPOSE: DMA handling - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include - -/* FUNCTIONS *****************************************************************/ - -/* NOTE: IoAllocateAdapterChannel in NTOSKRNL.EXE */ - -NTSTATUS STDCALL -HalAllocateAdapterChannel(PADAPTER_OBJECT AdapterObject, - PDEVICE_OBJECT DeviceObject, - ULONG NumberOfMapRegisters, - PDRIVER_CONTROL ExecutionRoutine, - PVOID Context ) -{ - KIRQL OldIrql; - PVOID Buffer; - int ret; - LARGE_INTEGER MaxAddress; - - MaxAddress.QuadPart = 0x1000000; - Buffer = MmAllocateContiguousAlignedMemory( NumberOfMapRegisters * PAGESIZE, - MaxAddress, - 0x10000 ); - if( !Buffer ) - return STATUS_INSUFFICIENT_RESOURCES; - KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); - if( AdapterObject->Inuse ) - { - // someone is already using it, we need to wait - // create a wait block, and add it to the chain - UNIMPLEMENTED; - } - else { - AdapterObject->Inuse = TRUE; - KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); - ret = ExecutionRoutine( DeviceObject, - NULL, - Buffer, - Context ); - KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); - if( ret == DeallocateObject ) - { - MmFreeContiguousMemory( Buffer ); - AdapterObject->Inuse = FALSE; - } - else AdapterObject->Buffer = Buffer; - } - KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); - return STATUS_SUCCESS; -} - - -BOOLEAN STDCALL -IoFlushAdapterBuffers (PADAPTER_OBJECT AdapterObject, - PMDL Mdl, - PVOID MapRegisterBase, - PVOID CurrentVa, - ULONG Length, - BOOLEAN WriteToDevice) -{ - // if this was a read from device, copy data back to caller buffer, otherwise, do nothing - if( !WriteToDevice ) - memcpy( (PVOID)((DWORD)MmGetSystemAddressForMdl( Mdl ) + (DWORD)CurrentVa - (DWORD)MmGetMdlVirtualAddress( Mdl )), MapRegisterBase, Length ); - return TRUE; -} - - -VOID STDCALL -IoFreeAdapterChannel (PADAPTER_OBJECT AdapterObject) -{ - KIRQL OldIrql; - - KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); - if( AdapterObject->Inuse == FALSE ) - { - DbgPrint( "Attempting to IoFreeAdapterChannel on a channel not in use\n" ); - KeBugCheck(0); - } - AdapterObject->Inuse = FALSE; - if( AdapterObject->Buffer ) - { - MmFreeContiguousMemory( AdapterObject->Buffer ); - AdapterObject->Buffer = 0; - } - KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); -} - - -VOID STDCALL -IoFreeMapRegisters (PADAPTER_OBJECT AdapterObject, - PVOID MapRegisterBase, - ULONG NumberOfMapRegisters) -{ - UNIMPLEMENTED; -} - - -PHYSICAL_ADDRESS STDCALL -IoMapTransfer (PADAPTER_OBJECT AdapterObject, - PMDL Mdl, - PVOID MapRegisterBase, - PVOID CurrentVa, - PULONG Length, - BOOLEAN WriteToDevice) -{ - PHYSICAL_ADDRESS Address; - // program up the dma controller, and return - // if it is a write to the device, copy the caller buffer to the low buffer - if( WriteToDevice ) - memcpy( MapRegisterBase, - MmGetSystemAddressForMdl( Mdl ) + ( (DWORD)CurrentVa - (DWORD)MmGetMdlVirtualAddress( Mdl ) ), - *Length ); - Address = MmGetPhysicalAddress( MapRegisterBase ); - // port 0xA is the dma mask register, or a 0x10 on to the channel number to mask it - WRITE_PORT_UCHAR( (PVOID)0x0A, AdapterObject->Channel | 0x10 ); - // write zero to the reset register - WRITE_PORT_UCHAR( (PVOID)0x0C, 0 ); - // mode register, or channel with 0x4 for write memory, 0x8 for read memory, 0x10 for non auto initialize - WRITE_PORT_UCHAR( (PVOID)0x0B, AdapterObject->Channel | ( WriteToDevice ? 0x8 : 0x4 ) ); - // set the 64k page register for the channel - WRITE_PORT_UCHAR( AdapterObject->PagePort, (UCHAR)(((ULONG)Address.QuadPart)>>16) ); - // low, then high address byte, which is always 0 for us, because we have a 64k alligned address - WRITE_PORT_UCHAR( AdapterObject->OffsetPort, 0 ); - WRITE_PORT_UCHAR( AdapterObject->OffsetPort, 0 ); - // count is 1 less than length, low then high - WRITE_PORT_UCHAR( AdapterObject->CountPort, (UCHAR)(*Length - 1) ); - WRITE_PORT_UCHAR( AdapterObject->CountPort, (UCHAR)((*Length - 1)>>8) ); - // unmask the channel to let it rip - WRITE_PORT_UCHAR( (PVOID)0x0A, AdapterObject->Channel ); - Address.QuadPart = (DWORD)MapRegisterBase; - return Address; -} - - -/* EOF */ - - - - diff --git a/reactos/ntoskrnl/hal/x86/beep.c b/reactos/ntoskrnl/hal/x86/beep.c deleted file mode 100644 index a0d8bfc1c01..00000000000 --- a/reactos/ntoskrnl/hal/x86/beep.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/beep.c - * PURPOSE: Speaker function (it's only one) - * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) - * UPDATE HISTORY: - * Created 31/01/99 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#define NDEBUG -#include - - -/* CONSTANTS *****************************************************************/ - -#define TIMER2 0x42 -#define TIMER3 0x43 -#define PORT_B 0x61 -#define CLOCKFREQ 1193167 - - -/* FUNCTIONS *****************************************************************/ -/* - * FUNCTION: Beeps the speaker. - * ARGUMENTS: - * Frequency = If 0, the speaker will be switched off, otherwise - * the speaker beeps with the specified frequency. - */ - -BOOLEAN -STDCALL -HalMakeBeep ( - ULONG Frequency - ) -{ - UCHAR b; - - /* save flags and disable interrupts */ - __asm__("pushf\n\t" \ - "cli\n\t"); - - /* speaker off */ - b = READ_PORT_UCHAR((PUCHAR)PORT_B); - WRITE_PORT_UCHAR((PUCHAR)PORT_B, b & 0xFC); - - if (Frequency) - { - DWORD Divider = CLOCKFREQ / Frequency; - - if (Divider > 0x10000) - { - /* restore flags */ - __asm__("popf\n\t"); - - return FALSE; - } - - /* set timer divider */ - WRITE_PORT_UCHAR((PUCHAR)TIMER3, 0xB6); - WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)(Divider & 0xFF)); - WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)((Divider>>8) & 0xFF)); - - /* speaker on */ - WRITE_PORT_UCHAR((PUCHAR)PORT_B, READ_PORT_UCHAR((PUCHAR)PORT_B) | 0x03); - } - - /* restore flags */ - __asm__("popf\n\t"); - - return TRUE; -} - diff --git a/reactos/ntoskrnl/hal/x86/bios32.c b/reactos/ntoskrnl/hal/x86/bios32.c deleted file mode 100644 index f972eebabc3..00000000000 --- a/reactos/ntoskrnl/hal/x86/bios32.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/pci - * PURPOSE: Interfaces to BIOS32 interface - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * 05/06/98: Created - */ - -/* - * NOTES: Sections copied from the Linux pci support - */ - -/* INCLUDES ***************************************************************/ - -#include -#include -#include - - -/* TYPES ******************************************************************/ - -typedef struct -{ - /* - * "_32_" if present - */ - unsigned int signature; - - /* - * Entry point (physical address) - */ - unsigned long int entry; - - /* - * Revision level - */ - unsigned char revision; - - /* - * Length in paragraphs - */ - unsigned char length; - - /* - * Checksum (so all bytes add up to zero) - */ - unsigned char checksum; - - unsigned char reserved[5]; -} bios32; - -BOOLEAN bios32_detected = FALSE; - -static struct -{ - unsigned long address; - unsigned short segment; -} bios32_indirect = {0,KERNEL_CS}; - -/* FUNCTIONS **************************************************************/ - -#define BIOS32_SIGNATURE (('_' << 0)+('3'<<8)+('2'<<16)+('_'<<24)) - -#if 0 -BOOL static checksum(bios32* service_entry) -/* - * FUNCTION: Checks the checksum of a bios32 service entry - * ARGUMENTS: - * service_entry = Pointer to the service entry - * RETURNS: True if the sum of the bytes in the entry was zero - * False otherwise - */ -{ - unsigned char* p = (unsigned char *)service_entry; - int i; - unsigned char sum=0; - - for (i=0; i<(service_entry->length*16); i++) - { - sum=sum+p[i]; - } -// DbgPrint("sum = %d\n",sum); - if (sum==0) - { - return(TRUE); - } - return(FALSE); -} -#endif - -BOOLEAN Hal_bios32_is_service_present(ULONG service) -{ - unsigned char return_code; - unsigned int address; - unsigned int length; - unsigned int entry; - - __asm__("lcall (%%edi)" - : "=a" (return_code), - "=b" (address), - "=c" (length), - "=d" (entry) - : "0" (service), - "1" (0), - "D" (&bios32_indirect)); - if (return_code==0) - { - return(address+entry); - } - return(0); -} - -VOID Hal_bios32_probe() -/* - * FUNCTION: Probes for an BIOS32 extension - * RETURNS: True if detected - */ -{ - DbgPrint ("Hal_bios32_probe()\n"); - - return; -#if 0 - int i; - - for (i=0xe0000;i<=0xffff0;i++) - { - bios32* service_entry = (bios32 *)physical_to_linear(i); - if ( service_entry->signature != BIOS32_SIGNATURE ) - { - continue; - } - DbgPrint("Signature detected at %x\n",i); - if (!checksum(service_entry)) - { - continue; - } - DbgPrint("ReactOS: BIOS32 detected at %x\n",i); - bios32_indirect.address = service_entry->entry; - bios32_detected=TRUE; - } -#endif -} diff --git a/reactos/ntoskrnl/hal/x86/bus.c b/reactos/ntoskrnl/hal/x86/bus.c deleted file mode 100644 index da8d398b530..00000000000 --- a/reactos/ntoskrnl/hal/x86/bus.c +++ /dev/null @@ -1,515 +0,0 @@ -/* $Id: bus.c,v 1.9 2001/08/01 10:39:50 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/bus.c - * PURPOSE: Bus functions - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - * - * - * TODO: - * - Add bus handler functions for all busses - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include - -#define NDEBUG -#include - -/* GLOBALS *******************************************************************/ - -#define TAG_BUS TAG('B', 'U', 'S', 'H') - -KSPIN_LOCK HalpBusHandlerSpinLock = {0,}; -LIST_ENTRY HalpBusHandlerList; - - -/* FUNCTIONS *****************************************************************/ - -static NTSTATUS STDCALL -HalpNoAdjustResourceList(PBUS_HANDLER BusHandler, - ULONG BusNumber, - PCM_RESOURCE_LIST Resources) -{ - return STATUS_UNSUCCESSFUL; -} - -static NTSTATUS STDCALL -HalpNoAssignSlotResources(PBUS_HANDLER BusHandler, - ULONG BusNumber, - PUNICODE_STRING RegistryPath, - PUNICODE_STRING DriverClassName, - PDRIVER_OBJECT DriverObject, - PDEVICE_OBJECT DeviceObject, - ULONG SlotNumber, - PCM_RESOURCE_LIST *AllocatedResources) -{ - return STATUS_NOT_SUPPORTED; -} - -static ULONG STDCALL -HalpNoBusData(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - return 0; -} - -static ULONG STDCALL -HalpNoGetInterruptVector(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity) -{ - return 0; -} - -static ULONG STDCALL -HalpNoTranslateBusAddress(PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress) -{ - return 0; -} - - -PBUS_HANDLER -HalpAllocateBusHandler(INTERFACE_TYPE InterfaceType, - BUS_DATA_TYPE BusDataType, - ULONG BusNumber) -{ - PBUS_HANDLER BusHandler = NULL; - - DPRINT("HalpAllocateBusHandler()\n"); - - BusHandler = ExAllocatePoolWithTag(NonPagedPool, - sizeof(BUS_HANDLER), - TAG_BUS); - if (BusHandler == NULL) - return NULL; - - RtlZeroMemory(BusHandler, - sizeof(BUS_HANDLER)); - - InsertTailList(&HalpBusHandlerList, - &BusHandler->Entry); - - BusHandler->InterfaceType = InterfaceType; - BusHandler->BusDataType = BusDataType; - BusHandler->BusNumber = BusNumber; - - /* initialize default bus handler functions */ - BusHandler->GetBusData = HalpNoBusData; - BusHandler->SetBusData = HalpNoBusData; - BusHandler->AdjustResourceList = HalpNoAdjustResourceList; - BusHandler->AssignSlotResources = HalpNoAssignSlotResources; - BusHandler->GetInterruptVector = HalpNoGetInterruptVector; - BusHandler->TranslateBusAddress = HalpNoTranslateBusAddress; - - /* any more ?? */ - - DPRINT("HalpAllocateBusHandler() done\n"); - - return BusHandler; -} - - -VOID -HalpInitBusHandlers(VOID) -{ - PBUS_HANDLER BusHandler; - - /* general preparations */ - KeInitializeSpinLock(&HalpBusHandlerSpinLock); - InitializeListHead(&HalpBusHandlerList); - - /* initialize hal dispatch tables */ -#if 0 - - - HalDispatchTable->HalQueryBusSlots = HaliQueryBusSlots; -#endif - - /* add system bus handler */ - BusHandler = HalpAllocateBusHandler(Internal, - ConfigurationSpaceUndefined, - 0); - if (BusHandler == NULL) - return; - BusHandler->GetInterruptVector = - (pGetInterruptVector)HalpGetSystemInterruptVector; - BusHandler->TranslateBusAddress = - (pTranslateBusAddress)HalpTranslateSystemBusAddress; - - /* add cmos bus handler */ - BusHandler = HalpAllocateBusHandler(InterfaceTypeUndefined, - Cmos, - 0); - if (BusHandler == NULL) - return; - BusHandler->GetBusData = (pGetSetBusData)HalpGetCmosData; - BusHandler->SetBusData = (pGetSetBusData)HalpSetCmosData; - - /* add isa bus handler */ - BusHandler = HalpAllocateBusHandler(Isa, - ConfigurationSpaceUndefined, - 0); - if (BusHandler == NULL) - return; - - BusHandler->TranslateBusAddress = - (pTranslateBusAddress)HalpTranslateIsaBusAddress; -} - - -PBUS_HANDLER FASTCALL -HaliHandlerForBus(INTERFACE_TYPE InterfaceType, - ULONG BusNumber) -{ - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; - - KeAcquireSpinLock(&HalpBusHandlerSpinLock, - &OldIrql); - - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->InterfaceType == InterfaceType && - BusHandler->BusNumber == BusNumber) - { - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - - return NULL; -} - - -PBUS_HANDLER FASTCALL -HaliHandlerForConfigSpace(BUS_DATA_TYPE BusDataType, - ULONG BusNumber) -{ - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; - - KeAcquireSpinLock(&HalpBusHandlerSpinLock, - &OldIrql); - - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->BusDataType == BusDataType && - BusHandler->BusNumber == BusNumber) - { - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - - return NULL; -} - - -PBUS_HANDLER FASTCALL -HaliReferenceHandlerForBus(INTERFACE_TYPE InterfaceType, - ULONG BusNumber) -{ - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; - - KeAcquireSpinLock(&HalpBusHandlerSpinLock, - &OldIrql); - - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->InterfaceType == InterfaceType && - BusHandler->BusNumber == BusNumber) - { - BusHandler->RefCount++; - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - - return NULL; -} - - -PBUS_HANDLER FASTCALL -HaliReferenceHandlerForConfigSpace(BUS_DATA_TYPE BusDataType, - ULONG BusNumber) -{ - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; - - KeAcquireSpinLock(&HalpBusHandlerSpinLock, - &OldIrql); - - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->BusDataType == BusDataType && - BusHandler->BusNumber == BusNumber) - { - BusHandler->RefCount++; - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); - - return NULL; -} - - -VOID FASTCALL -HaliDereferenceBusHandler(PBUS_HANDLER BusHandler) -{ - KIRQL OldIrql; - - KeAcquireSpinLock(&HalpBusHandlerSpinLock, - &OldIrql); - BusHandler->RefCount--; - KeReleaseSpinLock(&HalpBusHandlerSpinLock, - OldIrql); -} - - -NTSTATUS STDCALL -HalAdjustResourceList(PCM_RESOURCE_LIST Resources) -{ - PBUS_HANDLER BusHandler; - NTSTATUS Status; - - BusHandler = HaliReferenceHandlerForBus(Resources->List[0].InterfaceType, - Resources->List[0].BusNumber); - if (BusHandler == NULL) - return STATUS_SUCCESS; - - Status = BusHandler->AdjustResourceList(BusHandler, - Resources->List[0].BusNumber, - Resources); - HaliDereferenceBusHandler (BusHandler); - - return Status; -} - - -NTSTATUS STDCALL -HalAssignSlotResources(PUNICODE_STRING RegistryPath, - PUNICODE_STRING DriverClassName, - PDRIVER_OBJECT DriverObject, - PDEVICE_OBJECT DeviceObject, - INTERFACE_TYPE BusType, - ULONG BusNumber, - ULONG SlotNumber, - PCM_RESOURCE_LIST *AllocatedResources) -{ - PBUS_HANDLER BusHandler; - NTSTATUS Status; - - BusHandler = HaliReferenceHandlerForBus(BusType, - BusNumber); - if (BusHandler == NULL) - return STATUS_NOT_FOUND; - - Status = BusHandler->AssignSlotResources(BusHandler, - BusNumber, - RegistryPath, - DriverClassName, - DriverObject, - DeviceObject, - SlotNumber, - AllocatedResources); - - HaliDereferenceBusHandler(BusHandler); - - return Status; -} - - -ULONG STDCALL -HalGetBusData(BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Length) -{ - return (HalGetBusDataByOffset(BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length)); -} - - -ULONG STDCALL -HalGetBusDataByOffset(BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PBUS_HANDLER BusHandler; - ULONG Result; - - BusHandler = HaliReferenceHandlerForConfigSpace(BusDataType, - BusNumber); - if (BusHandler == NULL) - return 0; - - Result = BusHandler->GetBusData(BusHandler, - BusNumber, - SlotNumber, - Buffer, - Offset, - Length); - - HaliDereferenceBusHandler (BusHandler); - - return Result; -} - - -ULONG STDCALL -HalGetInterruptVector(INTERFACE_TYPE InterfaceType, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity) -{ - PBUS_HANDLER BusHandler; - ULONG Result; - - BusHandler = HaliReferenceHandlerForBus(InterfaceType, - BusNumber); - if (BusHandler == NULL) - return 0; - - Result = BusHandler->GetInterruptVector(BusHandler, - BusNumber, - BusInterruptLevel, - BusInterruptVector, - Irql, - Affinity); - - HaliDereferenceBusHandler(BusHandler); - - return Result; -} - - -ULONG STDCALL -HalSetBusData(BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Length) -{ - return (HalSetBusDataByOffset(BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length)); -} - - -ULONG STDCALL -HalSetBusDataByOffset(BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PBUS_HANDLER BusHandler; - ULONG Result; - - BusHandler = HaliReferenceHandlerForConfigSpace(BusDataType, - BusNumber); - if (BusHandler == NULL) - return 0; - - Result = BusHandler->SetBusData(BusHandler, - BusNumber, - SlotNumber, - Buffer, - Offset, - Length); - - HaliDereferenceBusHandler(BusHandler); - - return Result; -} - - -BOOLEAN STDCALL -HalTranslateBusAddress(INTERFACE_TYPE InterfaceType, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress) -{ - PBUS_HANDLER BusHandler; - BOOLEAN Result; - - BusHandler = HaliReferenceHandlerForBus(InterfaceType, - BusNumber); - if (BusHandler == NULL) - return FALSE; - - Result = BusHandler->TranslateBusAddress(BusHandler, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); - - HaliDereferenceBusHandler(BusHandler); - - return Result; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/display.c b/reactos/ntoskrnl/hal/x86/display.c deleted file mode 100644 index c5f6e1c6050..00000000000 --- a/reactos/ntoskrnl/hal/x86/display.c +++ /dev/null @@ -1,293 +0,0 @@ -/* $Id: display.c,v 1.15 2001/04/20 12:42:23 chorns Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/display.c - * PURPOSE: Blue screen display - * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) - * UPDATE HISTORY: - * Created 08/10/99 - */ - -#include -#include - -#define SCREEN_SYNCHRONIZATION - - -#define CRTC_COMMAND 0x3d4 -#define CRTC_DATA 0x3d5 - -#define CRTC_COLUMNS 0x01 -#define CRTC_OVERFLOW 0x07 -#define CRTC_ROWS 0x12 -#define CRTC_SCANLINES 0x09 - -#define CRTC_CURHI 0x0e -#define CRTC_CURLO 0x0f - - -#define CHAR_ATTRIBUTE 0x17 /* grey on blue */ - - -/* VARIABLES ****************************************************************/ - -static ULONG CursorX = 0; /* Cursor Position */ -static ULONG CursorY = 0; -static ULONG SizeX = 80; /* Display size */ -static ULONG SizeY = 25; - -static BOOLEAN DisplayInitialized = FALSE; -static BOOLEAN HalOwnsDisplay = TRUE; - -static WORD *VideoBuffer = NULL; - -static PHAL_RESET_DISPLAY_PARAMETERS HalResetDisplayParameters = NULL; - - -/* STATIC FUNCTIONS *********************************************************/ - -static VOID -HalClearDisplay (VOID) -{ - WORD *ptr = (WORD*)VideoBuffer; - ULONG i; - - for (i = 0; i < SizeX * SizeY; i++, ptr++) - *ptr = ((CHAR_ATTRIBUTE << 8) + ' '); - - CursorX = 0; - CursorY = 0; -} - - -VOID -HalScrollDisplay (VOID) -{ - WORD *ptr; - int i; - - ptr = VideoBuffer + SizeX; - RtlMoveMemory (VideoBuffer, - ptr, - SizeX * (SizeY - 1) * 2); - - ptr = VideoBuffer + (SizeX * (SizeY - 1)); - for (i = 0; i < SizeX; i++, ptr++) - { - *ptr = (CHAR_ATTRIBUTE << 8) + ' '; - } -} - - -static VOID -HalPutCharacter (CHAR Character) -{ - WORD *ptr; - - ptr = VideoBuffer + ((CursorY * SizeX) + CursorX); - *ptr = (CHAR_ATTRIBUTE << 8) + Character; -} - - -/* PRIVATE FUNCTIONS ********************************************************/ - -VOID -HalInitializeDisplay (PLOADER_PARAMETER_BLOCK LoaderBlock) -/* - * FUNCTION: Initalize the display - * ARGUMENTS: - * InitParameters = Parameters setup by the boot loader - */ -{ - if (DisplayInitialized == FALSE) - { - ULONG ScanLines; - ULONG Data; - - VideoBuffer = (WORD *)(0xd0000000 + 0xb8000); -// VideoBuffer = HalMapPhysicalMemory (0xb8000, 2); - - /* Set cursor position */ -// CursorX = LoaderBlock->cursorx; -// CursorY = LoaderBlock->cursory; - CursorX = 0; - CursorY = 0; - - /* read screen size from the crtc */ - /* FIXME: screen size should be read from the boot parameters */ - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_COLUMNS); - SizeX = READ_PORT_UCHAR((PUCHAR)CRTC_DATA) + 1; - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_ROWS); - SizeY = READ_PORT_UCHAR((PUCHAR)CRTC_DATA); - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_OVERFLOW); - Data = READ_PORT_UCHAR((PUCHAR)CRTC_DATA); - SizeY |= (((Data & 0x02) << 7) | ((Data & 0x40) << 3)); - SizeY++; - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_SCANLINES); - ScanLines = (READ_PORT_UCHAR((PUCHAR)CRTC_DATA) & 0x1F) + 1; - SizeY = SizeY / ScanLines; - -#ifdef BOCHS_30ROWS -SizeY=30; -#endif - HalClearDisplay (); - - DisplayInitialized = TRUE; - } -} - - -VOID -HalResetDisplay (VOID) -/* - * FUNCTION: Reset the display - * ARGUMENTS: - * None - */ -{ - if (HalResetDisplayParameters == NULL) - return; - - if (HalOwnsDisplay == TRUE) - return; - - if (HalResetDisplayParameters(SizeX, SizeY) == TRUE) - { - HalOwnsDisplay = TRUE; - HalClearDisplay (); - } -} - - -/* PUBLIC FUNCTIONS *********************************************************/ - -VOID -STDCALL -HalAcquireDisplayOwnership ( - IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters - ) -/* - * FUNCTION: - * ARGUMENTS: - * ResetDisplayParameters = Pointer to a driver specific - * reset routine. - */ -{ - HalOwnsDisplay = FALSE; - HalResetDisplayParameters = ResetDisplayParameters; -} - - -VOID STDCALL -HalDisplayString (IN PCH String) -/* - * FUNCTION: Switches the screen to HAL console mode (BSOD) if not there - * already and displays a string - * ARGUMENT: - * string = ASCII string to display - * NOTE: Use with care because there is no support for returning from BSOD - * mode - */ -{ - PCH pch; -#ifdef SCREEN_SYNCHRONIZATION - int offset; -#endif - static KSPIN_LOCK Lock; - ULONG Flags; - - pch = String; - - pushfl(Flags); - __asm__ ("cli\n\t"); - KeAcquireSpinLockAtDpcLevel(&Lock); - - if (HalOwnsDisplay == FALSE) - { - HalResetDisplay (); - } - -#ifdef SCREEN_SYNCHRONIZATION - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_CURHI); - offset = READ_PORT_UCHAR((PUCHAR)CRTC_DATA)<<8; - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_CURLO); - offset += READ_PORT_UCHAR((PUCHAR)CRTC_DATA); - - CursorY = offset / SizeX; - CursorX = offset % SizeX; -#endif - - while (*pch != 0) - { - if (*pch == '\n') - { - CursorY++; - CursorX = 0; - } - else - { - HalPutCharacter (*pch); - CursorX++; - - if (CursorX >= SizeX) - { - CursorY++; - CursorX = 0; - } - } - - if (CursorY >= SizeY) - { - HalScrollDisplay (); - CursorY = SizeY - 1; - } - - pch++; - } - -#ifdef SCREEN_SYNCHRONIZATION - offset = (CursorY * SizeX) + CursorX; - - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_CURLO); - WRITE_PORT_UCHAR((PUCHAR)CRTC_DATA, offset & 0xff); - WRITE_PORT_UCHAR((PUCHAR)CRTC_COMMAND, CRTC_CURHI); - WRITE_PORT_UCHAR((PUCHAR)CRTC_DATA, (offset >> 8) & 0xff); -#endif - KeReleaseSpinLockFromDpcLevel(&Lock); - popfl(Flags); -} - - -VOID -STDCALL -HalQueryDisplayParameters ( - PULONG DispSizeX, - PULONG DispSizeY, - PULONG CursorPosX, - PULONG CursorPosY - ) -{ - if (DispSizeX) - *DispSizeX = SizeX; - if (DispSizeY) - *DispSizeY = SizeY; - if (CursorPosX) - *CursorPosX = CursorX; - if (CursorPosY) - *CursorPosY = CursorY; -} - - -VOID -STDCALL -HalSetDisplayParameters ( - ULONG CursorPosX, - ULONG CursorPosY - ) -{ - CursorX = (CursorPosX < SizeX) ? CursorPosX : SizeX - 1; - CursorY = (CursorPosY < SizeY) ? CursorPosY : SizeY - 1; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/dma.c b/reactos/ntoskrnl/hal/x86/dma.c deleted file mode 100644 index 7b6e1d3f739..00000000000 --- a/reactos/ntoskrnl/hal/x86/dma.c +++ /dev/null @@ -1,115 +0,0 @@ -/* $Id: dma.c,v 1.11 2001/03/31 16:46:59 jfilby Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/dma.c - * PURPOSE: DMA functions - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include -#include - -ADAPTER_OBJECT AdapterObjects[] = { - { 0, (PVOID)0x87, (PVOID)0x1, (PVOID)0x0, { 0 }, NULL }, - { 1, (PVOID)0x83, (PVOID)0x3, (PVOID)0x2, { 0 }, NULL }, - { 2, (PVOID)0x81, (PVOID)0x5, (PVOID)0x4, { 0 }, NULL }, - { 3, (PVOID)0x82, (PVOID)0x7, (PVOID)0x6, { 0 }, NULL } }; - - -/* FUNCTIONS *****************************************************************/ - -PVOID STDCALL -HalAllocateCommonBuffer (PADAPTER_OBJECT AdapterObject, - ULONG Length, - PPHYSICAL_ADDRESS LogicalAddress, - BOOLEAN CacheEnabled) -/* - * FUNCTION: Allocates memory that is visible to both the processor(s) and - * a dma device - * ARGUMENTS: - * AdapterObject = Adapter object representing the bus master or - * system dma controller - * Length = Number of bytes to allocate - * LogicalAddress = Logical address the driver can use to access the - * buffer - * CacheEnabled = Specifies if the memory can be cached - * RETURNS: The base virtual address of the memory allocated - * NULL on failure - */ -{ - UNIMPLEMENTED; -} - -BOOLEAN STDCALL -HalFlushCommonBuffer (ULONG Unknown1, - ULONG Unknown2, - ULONG Unknown3, - ULONG Unknown4, - ULONG Unknown5, - ULONG Unknown6, - ULONG Unknown7, - ULONG Unknown8) -{ - return TRUE; -} - -VOID STDCALL -HalFreeCommonBuffer (PADAPTER_OBJECT AdapterObject, - ULONG Length, - PHYSICAL_ADDRESS LogicalAddress, - PVOID VirtualAddress, - BOOLEAN CacheEnabled) -{ - MmFreeContiguousMemory(VirtualAddress); -} - -PADAPTER_OBJECT STDCALL -HalGetAdapter (PDEVICE_DESCRIPTION DeviceDescription, - PULONG NumberOfMapRegisters) -/* - * FUNCTION: Returns a pointer to an adapter object for the DMA device - * defined in the device description structure - * ARGUMENTS: - * DeviceDescription = Structure describing the attributes of the device - * NumberOfMapRegisters (OUT) = Returns the maximum number of map - * registers the device driver can - * allocate for DMA transfer operations - * RETURNS: The allocated adapter object on success - * NULL on failure - */ -{ - /* Validate parameters in device description, and return a pointer to - the adapter object for the requested dma channel */ - if( DeviceDescription->Version != DEVICE_DESCRIPTION_VERSION ) - return NULL; - if( DeviceDescription->Master ) - return NULL; - if( DeviceDescription->ScatterGather ) - return NULL; - if( DeviceDescription->AutoInitialize ) - return NULL; - if( DeviceDescription->Dma32BitAddress ) - return NULL; - if( DeviceDescription->InterfaceType != Isa ) - return NULL; - /* if( DeviceDescription->DmaWidth != Width8Bits ) - return NULL;*/ - *NumberOfMapRegisters = 0x10; - AdapterObjects[DeviceDescription->DmaChannel].Buffer = 0; - return &AdapterObjects[DeviceDescription->DmaChannel]; -} - -ULONG STDCALL -HalReadDmaCounter (PADAPTER_OBJECT AdapterObject) -{ - UNIMPLEMENTED; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/drive.c b/reactos/ntoskrnl/hal/x86/drive.c deleted file mode 100644 index e0a5fb38ea6..00000000000 --- a/reactos/ntoskrnl/hal/x86/drive.c +++ /dev/null @@ -1,39 +0,0 @@ -/* $Id: drive.c,v 1.3 2001/06/08 15:08:36 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: hal/x86/drive.c - * PURPOSE: Drive letter assignment - * PROGRAMMER: - * UPDATE HISTORY: - * 2000-03-25 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -VOID STDCALL -IoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock, - IN PSTRING NtDeviceName, - OUT PUCHAR NtSystemPath, - OUT PSTRING NtSystemPathString) -{ -#ifdef __NTOSKRNL__ - HalDispatchTable.HalIoAssignDriveLetters(LoaderBlock, - NtDeviceName, - NtSystemPath, - NtSystemPathString); -#else - HalDispatchTable->HalIoAssignDriveLetters(LoaderBlock, - NtDeviceName, - NtSystemPath, - NtSystemPathString); -#endif -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/enum.c b/reactos/ntoskrnl/hal/x86/enum.c deleted file mode 100644 index 25440090eda..00000000000 --- a/reactos/ntoskrnl/hal/x86/enum.c +++ /dev/null @@ -1,34 +0,0 @@ -/* $Id: enum.c,v 1.2 2001/08/30 20:38:18 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/enum.c - * PURPOSE: Motherboard device enumerator - * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net) - * UPDATE HISTORY: - * Created 01/05/2001 - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - -#define NDEBUG -#include - -VOID -HalpStartEnumerator (VOID) -{ -#ifdef ACPI - - UNICODE_STRING DriverName; - - RtlInitUnicodeString(&DriverName, - L"\\SystemRoot\\system32\\drivers\\acpi.sys"); - NtLoadDriver(&DriverName); - -#endif /* ACPI */ -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/fmutex.c b/reactos/ntoskrnl/hal/x86/fmutex.c deleted file mode 100644 index f2f6d82fa5a..00000000000 --- a/reactos/ntoskrnl/hal/x86/fmutex.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $Id: fmutex.c,v 1.3 2001/06/20 12:59:18 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/fmutex.c - * PURPOSE: Implements fast mutexes - * PROGRAMMER: David Welch (welch@cwcom.net) - * Eric Kohl (ekohl@rz-online.de) - * UPDATE HISTORY: - * Created 09/06/2000 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -VOID FASTCALL -ExAcquireFastMutex (PFAST_MUTEX FastMutex) -{ - KeEnterCriticalRegion(); - if (InterlockedDecrement(&(FastMutex->Count))==0) - { - return; - } - FastMutex->Contention++; - KeWaitForSingleObject(&(FastMutex->Event), - Executive, - KernelMode, - FALSE, - NULL); - FastMutex->Owner=KeGetCurrentThread(); -} - - -VOID FASTCALL -ExReleaseFastMutex (PFAST_MUTEX FastMutex) -{ - assert(FastMutex->Owner == KeGetCurrentThread()); - FastMutex->Owner=NULL; - if (InterlockedIncrement(&(FastMutex->Count))<=0) - { - return; - } - KeSetEvent(&(FastMutex->Event),0,FALSE); - - KeLeaveCriticalRegion(); -} - - -BOOLEAN FASTCALL -ExTryToAcquireFastMutex (PFAST_MUTEX FastMutex) -{ - UNIMPLEMENTED; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/halinit.c b/reactos/ntoskrnl/hal/x86/halinit.c deleted file mode 100644 index 9b58c5a22ba..00000000000 --- a/reactos/ntoskrnl/hal/x86/halinit.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $Id: halinit.c,v 1.23 2001/08/30 20:38:18 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/halinit.c - * PURPOSE: Initalize the x86 hal - * PROGRAMMER: David Welch (welch@cwcom.net) - * UPDATE HISTORY: - * 11/06/98: Created - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include - -#ifdef MP -#include -#endif /* MP */ - -#define NDEBUG -#include - - -/* FUNCTIONS ***************************************************************/ - -BOOLEAN STDCALL -HalInitSystem (ULONG BootPhase, - PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - if (BootPhase == 0) - { - HalInitializeDisplay (LoaderBlock); - -#ifdef MP - - HalpInitMPS(); - -#else - - HalpInitPICs(); - - /* Setup busy waiting */ - HalpCalibrateStallExecution(); - -#endif /* MP */ - - } - else if (BootPhase == 1) - { - HalpInitBusHandlers (); - } - else - { - /* Enumerate the devices on the motherboard */ - HalpStartEnumerator(); - } - - return TRUE; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/irql.c b/reactos/ntoskrnl/hal/x86/irql.c deleted file mode 100644 index c54e27fdc1e..00000000000 --- a/reactos/ntoskrnl/hal/x86/irql.c +++ /dev/null @@ -1,452 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/irql.c - * PURPOSE: Implements IRQLs - * PROGRAMMER: David Welch (welch@cwcom.net) - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include - -#define NDEBUG -#include - -/* GLOBALS ******************************************************************/ - -/* FIXME: this should be in a header file */ -#define NR_IRQS (16) -#define IRQ_BASE (0x40) - -/* - * PURPOSE: Current irq level - */ -static KIRQL CurrentIrql = HIGH_LEVEL; - -extern ULONG DpcQueueSize; - -static VOID KeSetCurrentIrql(KIRQL newlvl); - -#define DIRQL_TO_IRQ(x) (PROFILE_LEVEL - x) -#define IRQ_TO_DIRQL(x) (PROFILE_LEVEL - x) - -/* FUNCTIONS ****************************************************************/ - -VOID HalpInitPICs(VOID) -{ - /* Initialization sequence */ - WRITE_PORT_UCHAR((PUCHAR)0x20, 0x11); - WRITE_PORT_UCHAR((PUCHAR)0xa0, 0x11); - /* Start of hardware irqs (0x24) */ - WRITE_PORT_UCHAR((PUCHAR)0x21, 0x40); - WRITE_PORT_UCHAR((PUCHAR)0xa1, 0x48); - /* 8259-1 is master */ - WRITE_PORT_UCHAR((PUCHAR)0x21, 0x4); - /* 8259-2 is slave */ - WRITE_PORT_UCHAR((PUCHAR)0xa1, 0x2); - /* 8086 mode */ - WRITE_PORT_UCHAR((PUCHAR)0x21, 0x1); - WRITE_PORT_UCHAR((PUCHAR)0xa1, 0x1); - /* Mask off all interrupts from PICs */ - WRITE_PORT_UCHAR((PUCHAR)0x21, 0xff); - WRITE_PORT_UCHAR((PUCHAR)0xa1, 0xff); - - /* We can know enable interrupts */ - __asm__ __volatile__ ("sti\n\t"); -} - -static ULONG -HiSetCurrentPICMask(unsigned int mask) -{ - WRITE_PORT_UCHAR((PUCHAR)0x21,mask & 0xff); - WRITE_PORT_UCHAR((PUCHAR)0xa1,(mask >> 8) & 0xff); - - return mask; -} - -static VOID HiSwitchIrql(KIRQL oldIrql) -/* - * FUNCTION: Switches to the current irql - * NOTE: Must be called with interrupt disabled - */ -{ - unsigned int i; - PKTHREAD CurrentThread; - - CurrentThread = KeGetCurrentThread(); - - /* - * Disable all interrupts - */ - if (CurrentIrql >= IPI_LEVEL) - { - HiSetCurrentPICMask(0xFFFF); - __asm__("sti\n\t"); - return; - } - - /* - * Disable all interrupts but the timer - */ - if (CurrentIrql == PROFILE_LEVEL || - CurrentIrql == CLOCK1_LEVEL || - CurrentIrql == CLOCK2_LEVEL) - { - HiSetCurrentPICMask(0xFFFE); - __asm__("sti\n\t"); - return; - } - - /* - * Disable all interrupts of lesser priority - */ - if (CurrentIrql > DISPATCH_LEVEL) - { - unsigned int current_mask = 0; - - for (i = CurrentIrql; i > (PROFILE_LEVEL - 15); i--) - { - current_mask = current_mask | (1 << (PROFILE_LEVEL - i)); - } - - HiSetCurrentPICMask(current_mask); - __asm__("sti\n\t"); - return; - } - - /* - * Enable all interrupts - */ - if (CurrentIrql == DISPATCH_LEVEL) - { - HiSetCurrentPICMask(0); - __asm__("sti\n\t"); - return; - } - - /* - * APCs are disabled but execute any pending DPCs - */ - if (CurrentIrql == APC_LEVEL) - { - HiSetCurrentPICMask(0); - __asm__("sti\n\t"); - if (DpcQueueSize > 0) - { - CurrentIrql = DISPATCH_LEVEL; - KiDispatchInterrupt(); - CurrentIrql = APC_LEVEL; - } - return; - } - - /* - * Execute any pending DPCs or APCs - */ - if (CurrentIrql == PASSIVE_LEVEL) - { - if (DpcQueueSize > 0) - { - CurrentIrql = DISPATCH_LEVEL; - KiDispatchInterrupt(); - CurrentIrql = PASSIVE_LEVEL; - } - if (CurrentThread != NULL && - CurrentThread->ApcState.KernelApcPending) - { - CurrentIrql = APC_LEVEL; - KiDeliverApc(0, 0, 0); - CurrentIrql = PASSIVE_LEVEL; - } - } -} - - -KIRQL STDCALL -KeGetCurrentIrql (VOID) -/* - * PURPOSE: Returns the current irq level - * RETURNS: The current irq level - */ -{ - return(CurrentIrql); -} - - -STATIC VOID -KeSetCurrentIrql(KIRQL newlvl) -/* - * PURPOSE: Sets the current irq level without taking any action - */ -{ - CurrentIrql = newlvl; -} - - -/********************************************************************** - * NAME EXPORTED - * KfLowerIrql - * - * DESCRIPTION - * Restores the irq level on the current processor - * - * ARGUMENTS - * NewIrql = Irql to lower to - * - * RETURN VALUE - * None - * - * NOTES - * Uses fastcall convention - */ - -VOID FASTCALL -KfLowerIrql (KIRQL NewIrql) -{ - KIRQL OldIrql; - - __asm__("cli\n\t"); - - DPRINT("KfLowerIrql(NewIrql %d)\n", NewIrql); - - if (NewIrql > CurrentIrql) - { - DbgPrint ("(%s:%d) NewIrql %x CurrentIrql %x\n", - __FILE__, __LINE__, NewIrql, CurrentIrql); - KeBugCheck(0); - for(;;); - } - - OldIrql = CurrentIrql; - CurrentIrql = NewIrql; - HiSwitchIrql(OldIrql); -} - - -/********************************************************************** - * NAME EXPORTED - * KeLowerIrql - * - * DESCRIPTION - * Restores the irq level on the current processor - * - * ARGUMENTS - * NewIrql = Irql to lower to - * - * RETURN VALUE - * None - * - * NOTES - */ - -VOID STDCALL -KeLowerIrql (KIRQL NewIrql) -{ - KfLowerIrql (NewIrql); -} - - -/********************************************************************** - * NAME EXPORTED - * KfRaiseIrql - * - * DESCRIPTION - * Raises the hardware priority (irql) - * - * ARGUMENTS - * NewIrql = Irql to raise to - * - * RETURN VALUE - * previous irq level - * - * NOTES - * Uses fastcall convention - */ - -KIRQL FASTCALL -KfRaiseIrql (KIRQL NewIrql) -{ - KIRQL OldIrql; - - DPRINT("KfRaiseIrql(NewIrql %d)\n", NewIrql); - - if (NewIrql < CurrentIrql) - { - DbgPrint ("%s:%d CurrentIrql %x NewIrql %x\n", - __FILE__,__LINE__,CurrentIrql,NewIrql); - KeBugCheck (0); - for(;;); - } - - __asm__("cli\n\t"); - OldIrql = CurrentIrql; - CurrentIrql = NewIrql; - - DPRINT ("NewIrql %x OldIrql %x CurrentIrql %x\n", - NewIrql, OldIrql, CurrentIrql); - HiSwitchIrql(OldIrql); - - return OldIrql; -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrql - * - * DESCRIPTION - * Raises the hardware priority (irql) - * - * ARGUMENTS - * NewIrql = Irql to raise to - * OldIrql (OUT) = Caller supplied storage for the previous irql - * - * RETURN VALUE - * None - * - * NOTES - * Calls KfRaiseIrql - */ -VOID STDCALL -KeRaiseIrql (KIRQL NewIrql, - PKIRQL OldIrql) -{ - *OldIrql = KfRaiseIrql (NewIrql); -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrqlToDpcLevel - * - * DESCRIPTION - * Raises the hardware priority (irql) to DISPATCH level - * - * ARGUMENTS - * None - * - * RETURN VALUE - * Previous irq level - * - * NOTES - * Calls KfRaiseIrql - */ - -KIRQL STDCALL -KeRaiseIrqlToDpcLevel (VOID) -{ - return KfRaiseIrql (DISPATCH_LEVEL); -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrqlToSynchLevel - * - * DESCRIPTION - * Raises the hardware priority (irql) to CLOCK2 level - * - * ARGUMENTS - * None - * - * RETURN VALUE - * Previous irq level - * - * NOTES - * Calls KfRaiseIrql - */ - -KIRQL STDCALL -KeRaiseIrqlToSynchLevel (VOID) -{ - // return KfRaiseIrql (CLOCK2_LEVEL); - UNIMPLEMENTED; -} - - -BOOLEAN STDCALL -HalBeginSystemInterrupt (ULONG Vector, - KIRQL Irql, - PKIRQL OldIrql) -{ - if (Vector < IRQ_BASE || Vector > IRQ_BASE + NR_IRQS) - return FALSE; - - /* Send EOI to the PICs */ - WRITE_PORT_UCHAR((PUCHAR)0x20,0x20); - if ((Vector-IRQ_BASE)>=8) - { - WRITE_PORT_UCHAR((PUCHAR)0xa0,0x20); - } - - *OldIrql = KeGetCurrentIrql(); - if (Vector-IRQ_BASE != 0) - { - DPRINT("old_level %d\n",*OldIrql); - } - KeSetCurrentIrql(Irql); - - return TRUE; -} - - -VOID STDCALL HalEndSystemInterrupt (KIRQL Irql, - ULONG Unknown2) -{ - KeSetCurrentIrql(Irql); -} - - -BOOLEAN STDCALL HalDisableSystemInterrupt (ULONG Vector, - ULONG Unknown2) -{ - ULONG irq; - - if (Vector < IRQ_BASE || Vector > IRQ_BASE + NR_IRQS) - return FALSE; - - irq = Vector - IRQ_BASE; - if (irq < 8) - { - WRITE_PORT_UCHAR((PUCHAR)0x21, - READ_PORT_UCHAR((PUCHAR)0x21)|(1< IRQ_BASE + NR_IRQS) - return FALSE; - - irq = Vector - IRQ_BASE; - if (irq < 8) - { - WRITE_PORT_UCHAR((PUCHAR)0x21, - READ_PORT_UCHAR((PUCHAR)0x21)&(~(1< -#include - - -/* FUNCTIONS *****************************************************************/ - -BOOL HalIsaProbe(VOID) -/* - * FUNCTION: Probes for an ISA bus - * RETURNS: True if detected - * NOTE: Since ISA is the default we are called last and always return - * true - */ -{ - DbgPrint("Assuming ISA bus\n"); - - /* - * Probe for plug and play support - */ - return(TRUE); -} - - -BOOLEAN STDCALL -HalpTranslateIsaBusAddress(PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress) -{ - BOOLEAN Result; - - Result = HalTranslateBusAddress(PCIBus, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); - if (Result != FALSE) - return Result; - - Result = HalTranslateBusAddress(Internal, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); - return Result; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/kdbg.c b/reactos/ntoskrnl/hal/x86/kdbg.c deleted file mode 100644 index 924a53c1257..00000000000 --- a/reactos/ntoskrnl/hal/x86/kdbg.c +++ /dev/null @@ -1,336 +0,0 @@ -/* $Id: kdbg.c,v 1.8 2000/03/04 22:01:17 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/kdbg.c - * PURPOSE: Serial i/o functions for the kernel debugger. - * PROGRAMMER: Emanuele Aliberti - * Eric Kohl - * UPDATE HISTORY: - * Created 05/09/99 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#define NDEBUG -#include - - -#define DEFAULT_BAUD_RATE 19200 - - -/* MACROS *******************************************************************/ - -#define SER_RBR(x) ((x)+0) -#define SER_THR(x) ((x)+0) -#define SER_DLL(x) ((x)+0) -#define SER_IER(x) ((x)+1) -#define SER_DLM(x) ((x)+1) -#define SER_IIR(x) ((x)+2) -#define SER_LCR(x) ((x)+3) -#define SR_LCR_CS5 0x00 -#define SR_LCR_CS6 0x01 -#define SR_LCR_CS7 0x02 -#define SR_LCR_CS8 0x03 -#define SR_LCR_ST1 0x00 -#define SR_LCR_ST2 0x04 -#define SR_LCR_PNO 0x00 -#define SR_LCR_POD 0x08 -#define SR_LCR_PEV 0x18 -#define SR_LCR_PMK 0x28 -#define SR_LCR_PSP 0x38 -#define SR_LCR_BRK 0x40 -#define SR_LCR_DLAB 0x80 -#define SER_MCR(x) ((x)+4) -#define SR_MCR_DTR 0x01 -#define SR_MCR_RTS 0x02 -#define SER_LSR(x) ((x)+5) -#define SR_LSR_DR 0x01 -#define SR_LSR_TBE 0x20 -#define SER_MSR(x) ((x)+6) -#define SR_MSR_CTS 0x10 -#define SR_MSR_DSR 0x20 -#define SER_SCR(x) ((x)+7) - - -/* GLOBAL VARIABLES *********************************************************/ - -ULONG -__declspec(dllexport) -KdComPortInUse = 0; /* EXPORTED */ - - -/* STATIC VARIABLES *********************************************************/ - -static ULONG ComPort = 0; -static ULONG BaudRate = 0; -static PUCHAR PortBase = (PUCHAR)0; - -/* The com port must only be initialized once! */ -static BOOLEAN PortInitialized = FALSE; - - -/* STATIC FUNCTIONS *********************************************************/ - -static BOOLEAN -KdpDoesComPortExist (PUCHAR BaseAddress) -{ - BOOLEAN found; - BYTE mcr; - BYTE msr; - - found = FALSE; - - /* save Modem Control Register (MCR) */ - mcr = READ_PORT_UCHAR (SER_MCR(BaseAddress)); - - /* enable loop mode (set Bit 4 of the MCR) */ - WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10); - - /* clear all modem output bits */ - WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10); - - /* read the Modem Status Register */ - msr = READ_PORT_UCHAR (SER_MSR(BaseAddress)); - - /* - * the upper nibble of the MSR (modem output bits) must be - * equal to the lower nibble of the MCR (modem input bits) - */ - if ((msr & 0xF0) == 0x00) - { - /* set all modem output bits */ - WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x1F); - - /* read the Modem Status Register */ - msr = READ_PORT_UCHAR (SER_MSR(BaseAddress)); - - /* - * the upper nibble of the MSR (modem output bits) must be - * equal to the lower nibble of the MCR (modem input bits) - */ - if ((msr & 0xF0) == 0xF0) - found = TRUE; - } - - /* restore MCR */ - WRITE_PORT_UCHAR (SER_MCR(BaseAddress), mcr); - - return (found); -} - - -/* FUNCTIONS ****************************************************************/ - -/* HAL.KdPortInitialize */ -BOOLEAN -STDCALL -KdPortInitialize ( - PKD_PORT_INFORMATION PortInformation, - DWORD Unknown1, - DWORD Unknown2 - ) -{ - ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8}; - char buffer[80]; - ULONG divisor; - BYTE lcr; - - if (PortInitialized == FALSE) - { - if (PortInformation->BaudRate != 0) - { - BaudRate = PortInformation->BaudRate; - } - else - { - BaudRate = DEFAULT_BAUD_RATE; - } - - if (PortInformation->ComPort == 0) - { - if (KdpDoesComPortExist ((PUCHAR)BaseArray[2])) - { - PortBase = (PUCHAR)BaseArray[2]; - ComPort = 2; - PortInformation->BaseAddress = (ULONG)PortBase; - PortInformation->ComPort = ComPort; -#ifndef NDEBUG - sprintf (buffer, - "\nSerial port COM%ld found at 0x%lx\n", - ComPort, - (ULONG)PortBase); - HalDisplayString (buffer); -#endif /* NDEBUG */ - } - else if (KdpDoesComPortExist ((PUCHAR)BaseArray[1])) - { - PortBase = (PUCHAR)BaseArray[1]; - ComPort = 1; - PortInformation->BaseAddress = (ULONG)PortBase; - PortInformation->ComPort = ComPort; -#ifndef NDEBUG - sprintf (buffer, - "\nSerial port COM%ld found at 0x%lx\n", - ComPort, - (ULONG)PortBase); - HalDisplayString (buffer); -#endif /* NDEBUG */ - } - else - { - sprintf (buffer, - "\nKernel Debugger: No COM port found!!!\n\n"); - HalDisplayString (buffer); - return FALSE; - } - } - else - { - if (KdpDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) - { - PortBase = (PUCHAR)BaseArray[PortInformation->ComPort]; - ComPort = PortInformation->ComPort; - PortInformation->BaseAddress = (ULONG)PortBase; -#ifndef NDEBUG - sprintf (buffer, - "\nSerial port COM%ld found at 0x%lx\n", - ComPort, - (ULONG)PortBase); - HalDisplayString (buffer); -#endif /* NDEBUG */ - } - else - { - sprintf (buffer, - "\nKernel Debugger: No serial port found!!!\n\n"); - HalDisplayString (buffer); - return FALSE; - } - } - - PortInitialized = TRUE; - } - - /* - * set baud rate and data format (8N1) - */ - - /* turn on DTR and RTS */ - WRITE_PORT_UCHAR (SER_MCR(PortBase), SR_MCR_DTR | SR_MCR_RTS); - - /* set DLAB */ - lcr = READ_PORT_UCHAR (SER_LCR(PortBase)) | SR_LCR_DLAB; - WRITE_PORT_UCHAR (SER_LCR(PortBase), lcr); - - /* set baud rate */ - divisor = 115200 / BaudRate; - WRITE_PORT_UCHAR (SER_DLL(PortBase), divisor & 0xff); - WRITE_PORT_UCHAR (SER_DLM(PortBase), (divisor >> 8) & 0xff); - - /* reset DLAB and set 8N1 format */ - WRITE_PORT_UCHAR (SER_LCR(PortBase), - SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO); - - /* read junk out of the RBR */ - lcr = READ_PORT_UCHAR (SER_RBR(PortBase)); - - /* - * set global info - */ - KdComPortInUse = (ULONG)PortBase; - - /* - * print message to blue screen - */ - sprintf (buffer, - "\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n", - ComPort, - (ULONG)PortBase, - BaudRate); - - HalDisplayString (buffer); - - return TRUE; -} - - -/* HAL.KdPortGetByte */ -BOOLEAN -STDCALL -KdPortGetByte ( - PUCHAR ByteRecieved - ) -{ - if (PortInitialized == FALSE) - return FALSE; - - if ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR)) - { - *ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase)); - return TRUE; - } - - return FALSE; -} - - -/* HAL.KdPortPollByte */ -BOOLEAN -STDCALL -KdPortPollByte ( - PUCHAR ByteRecieved - ) -{ - if (PortInitialized == FALSE) - return FALSE; - - while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR) == 0) - ; - - *ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase)); - - return TRUE; -} - - -/* HAL.KdPortPutByte */ -VOID -STDCALL -KdPortPutByte ( - UCHAR ByteToSend - ) -{ - if (PortInitialized == FALSE) - return; - - while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0) - ; - - WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend); -} - - -/* HAL.KdPortRestore */ -VOID -STDCALL -KdPortRestore ( - VOID - ) -{ -} - - -/* HAL.KdPortSave */ -VOID -STDCALL -KdPortSave ( - VOID - ) -{ -} - - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/mbr.c b/reactos/ntoskrnl/hal/x86/mbr.c deleted file mode 100644 index 5dc30a9e203..00000000000 --- a/reactos/ntoskrnl/hal/x86/mbr.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/mbr.c - * PURPOSE: Functions for reading the master boot record (MBR) - * PROGRAMMER: David Welch (welch@cwcom.net) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -VOID HalExamineMBR(PDEVICE_OBJECT DeviceObject, - ULONG SectorSize, - ULONG MBRTypeIdentifier, - PVOID Buffer) -{ - UNIMPLEMENTED; -} diff --git a/reactos/ntoskrnl/hal/x86/misc.c b/reactos/ntoskrnl/hal/x86/misc.c deleted file mode 100644 index c1ae73b67b7..00000000000 --- a/reactos/ntoskrnl/hal/x86/misc.c +++ /dev/null @@ -1,105 +0,0 @@ -/* $Id: misc.c,v 1.8 2001/03/16 18:11:21 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/misc.c - * PURPOSE: Miscellaneous hardware functions - * PROGRAMMER: Eric Kohl (ekohl@rz-online.de) - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - -/* FUNCTIONS ****************************************************************/ - -VOID STDCALL -HalHandleNMI (ULONG Unused) -{ - UCHAR ucStatus; - - ucStatus = READ_PORT_UCHAR((PUCHAR) 0x61); - - HalDisplayString ("\n*** Hardware Malfunction\n\n"); - HalDisplayString ("Call your hardware vendor for support\n\n"); - - if (ucStatus & 0x80) - HalDisplayString ("NMI: Parity Check / Memory Parity Error\n"); - - if (ucStatus & 0x40) - HalDisplayString ("NMI: Channel Check / IOCHK\n"); - - HalDisplayString ("\n*** The system has halted ***\n"); - KeEnterKernelDebugger (); -} - -VOID STDCALL -HalProcessorIdle (VOID) -{ -#if 1 - __asm__("sti\n\t" \ - "hlt\n\t"); -#else - -#endif -} - -VOID STDCALL -HalRequestIpi(ULONG Unknown) -{ - return; -} - -ULONG FASTCALL -HalSystemVectorDispatchEntry ( - ULONG Unknown1, - ULONG Unknown2, - ULONG Unknown3 - ) -{ - return 0; -} - -VOID STDCALL -KeFlushWriteBuffer ( - VOID - ) -{ - return; -} - -VOID STDCALL -HalReportResourceUsage ( - VOID - ) -{ - /* - * FIXME: Report all resources used by hal. - * Calls IoReportHalResourceUsage() - */ - - /* - * Initialize PCI bus. - */ - HalpInitPciBus (); -#if 0 - /* - * Initialize IsaPnP bus. - */ - HalpInitIsaPnpBus (); - - /* - * Initialize other busses??? - */ - - /* - * Probe for a BIOS32 extension - */ - Hal_bios32_probe(); -#endif - - return; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/mp.c b/reactos/ntoskrnl/hal/x86/mp.c deleted file mode 100644 index 09dd2271dda..00000000000 --- a/reactos/ntoskrnl/hal/x86/mp.c +++ /dev/null @@ -1,2368 +0,0 @@ -/* $Id: mp.c,v 1.16 2001/08/30 20:38:19 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/mp.c - * PURPOSE: Intel MultiProcessor specification support - * PROGRAMMER: David Welch (welch@cwcom.net) - * Casper S. Hornstrup (chorns@users.sourceforge.net) - * NOTES: Parts adapted from linux SMP code - * UPDATE HISTORY: - * 22/05/1998 DW Created - * 12/04/2001 CSH Added MultiProcessor specification support - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - -#define NDEBUG -#include - -#ifdef MP - -#include -#include -#include -#include -#include -#include - -/* - Address of area to be used for communication between Application - Processors (APs) and the BootStrap Processor (BSP) - */ -#define COMMON_AREA 0x2000 - -#define BIOS_AREA 0x0 - -typedef struct __attribute__((packed)) _COMMON_AREA_INFO -{ - ULONG Stack; /* Location of AP stack */ - ULONG Debug[16]; /* For debugging */ -} COMMON_AREA_INFO, *PCOMMON_AREA_INFO; - -extern PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS]; - -CPU_INFO CPUMap[MAX_CPU]; /* Map of all CPUs in the system */ -ULONG CPUCount; /* Total number of CPUs */ -ULONG OnlineCPUs; /* Bitmask of online CPUs */ - -UCHAR BUSMap[MAX_BUS]; /* Map of all buses in the system */ -UCHAR PCIBUSMap[MAX_BUS]; /* Map of all PCI buses in the system */ - -IOAPIC_INFO IOAPICMap[MAX_IOAPIC]; /* Map of all I/O APICs in the system */ -ULONG IOAPICCount; /* Number of I/O APICs in the system */ - -MP_CONFIGURATION_INTSRC IRQMap[MAX_IRQ_SOURCE]; /* Map of all IRQs */ -ULONG IRQVectorMap[MAX_IRQ_SOURCE]; /* IRQ to vector map */ -ULONG IRQCount; /* Number of IRQs */ - -ULONG APICMode; /* APIC mode at startup */ -ULONG BootCPU; /* Bootstrap processor */ -ULONG NextCPU; /* Next CPU to start */ -PULONG BIOSBase; /* Virtual address of BIOS data segment */ -PULONG APICBase; /* Virtual address of local APIC */ -PULONG CommonBase; /* Virtual address of common area */ - -extern CHAR *APstart, *APend; -extern VOID (*APflush)(VOID); - -extern VOID MpsTimerInterrupt(VOID); -extern VOID MpsErrorInterrupt(VOID); -extern VOID MpsSpuriousInterrupt(VOID); - -#define CMOS_READ(address) ({ \ - WRITE_PORT_UCHAR((PUCHAR)0x70, address)); \ - READ_PORT_UCHAR((PUCHAR)0x71)); \ -}) - -#define CMOS_WRITE(address, value) ({ \ - WRITE_PORT_UCHAR((PUCHAR)0x70, address); \ - WRITE_PORT_UCHAR((PUCHAR)0x71, value); \ -}) - -BOOLEAN MPSInitialized = FALSE; /* Is the MP system initialized? */ - -VOID APICDisable(VOID); -static VOID APICSyncArbIDs(VOID); - -/* For debugging */ -ULONG lastregr = 0; -ULONG lastvalr = 0; -ULONG lastregw = 0; -ULONG lastvalw = 0; - -#endif /* MP */ - - -BOOLEAN BSPInitialized = FALSE; /* Is the BSP initialized? */ - - -/* FUNCTIONS *****************************************************************/ - -#ifdef MP - -/* Functions for handling 8259A PICs */ - -VOID Disable8259AIrq( - ULONG irq) -{ - ULONG tmp; - - if (irq & 8) { - tmp = READ_PORT_UCHAR((PUCHAR)0xA1); - tmp |= (1 << irq); - WRITE_PORT_UCHAR((PUCHAR)0xA1, tmp); - } else { - tmp = READ_PORT_UCHAR((PUCHAR)0x21); - tmp |= (1 << irq); - WRITE_PORT_UCHAR((PUCHAR)0x21, tmp); - } -} - - -VOID Enable8259AIrq( - ULONG irq) -{ - ULONG tmp; - - if (irq & 8) { - tmp = READ_PORT_UCHAR((PUCHAR)0xA1); - tmp &= ~(1 << irq); - WRITE_PORT_UCHAR((PUCHAR)0xA1, tmp); - } else { - tmp = READ_PORT_UCHAR((PUCHAR)0x21); - tmp &= ~(1 << irq); - WRITE_PORT_UCHAR((PUCHAR)0x21, tmp); - } -} - - -/* Functions for handling I/O APICs */ - -volatile ULONG IOAPICRead( - ULONG Apic, - ULONG Offset) -{ - PULONG Base; - - Base = (PULONG)IOAPICMap[Apic].ApicAddress; - - *Base = Offset; - return *((PULONG)((ULONG)Base + IOAPIC_IOWIN)); -} - - -VOID IOAPICWrite( - ULONG Apic, - ULONG Offset, - ULONG Value) -{ - PULONG Base; - - Base = (PULONG)IOAPICMap[Apic].ApicAddress; - - *Base = Offset; - *((PULONG)((ULONG)Base + IOAPIC_IOWIN)) = Value; -} - - -VOID IOAPICClearPin( - ULONG Apic, - ULONG Pin) -{ - IOAPIC_ROUTE_ENTRY Entry; - - /* - * Disable it in the IO-APIC irq-routing table - */ - memset(&Entry, 0, sizeof(Entry)); - Entry.mask = 1; - IOAPICWrite(Apic, IOAPIC_REDTBL + 2 * Pin, *(((PULONG)&Entry) + 0)); - IOAPICWrite(Apic, IOAPIC_REDTBL + 1 + 2 * Pin, *(((PULONG)&Entry) + 1)); -} - -static VOID IOAPICClear( - ULONG Apic) -{ - ULONG Pin; - - for (Pin = 0; Pin < IOAPICMap[Apic].EntryCount; Pin++) - IOAPICClearPin(Apic, Pin); -} - -static VOID IOAPICClearAll( - VOID) -{ - ULONG Apic; - - for (Apic = 0; Apic < IOAPICCount; Apic++) - IOAPICClear(Apic); -} - -/* This is performance critical and should probably be done in assembler */ -VOID IOAPICMaskIrq( - ULONG Apic, - ULONG Irq) -{ - IOAPIC_ROUTE_ENTRY Entry; - - *((PULONG)&Entry) = IOAPICRead(Apic, IOAPIC_REDTBL+2*Irq); - Entry.mask = 1; - IOAPICWrite(Apic, IOAPIC_REDTBL+2*Irq, *((PULONG)&Entry)); -} - - -/* This is performance critical and should probably be done in assembler */ -VOID IOAPICUnmaskIrq( - ULONG Apic, - ULONG Irq) -{ - IOAPIC_ROUTE_ENTRY Entry; - - *((PULONG)&Entry) = IOAPICRead(Apic, IOAPIC_REDTBL+2*Irq); - Entry.mask = 0; - IOAPICWrite(Apic, IOAPIC_REDTBL+2*Irq, *((PULONG)&Entry)); -} - -static VOID -IOAPICSetupIds(VOID) -{ - ULONG tmp, apic, i; - UCHAR old_id; - - /* - * Set the IOAPIC ID to the value stored in the MPC table. - */ - for (apic = 0; apic < IOAPICCount; apic++) { - - /* Read the register 0 value */ - tmp = IOAPICRead(apic, IOAPIC_ID); - - old_id = IOAPICMap[apic].ApicId; - - if (IOAPICMap[apic].ApicId >= 0xf) { - DPRINT1("BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n", - apic, IOAPICMap[apic].ApicId); - DPRINT1("... fixing up to %d. (tell your hw vendor)\n", - GET_IOAPIC_ID(tmp)); - IOAPICMap[apic].ApicId = GET_IOAPIC_ID(tmp); - } - - /* - * We need to adjust the IRQ routing table - * if the ID changed. - */ - if (old_id != IOAPICMap[apic].ApicId) - for (i = 0; i < IRQCount; i++) - if (IRQMap[i].DstApicId == old_id) - IRQMap[i].DstApicId = IOAPICMap[apic].ApicId; - - /* - * Read the right value from the MPC table and - * write it into the ID register. - */ - DPRINT("Changing IO-APIC physical APIC ID to %d\n", - IOAPICMap[apic].ApicId); - - tmp &= ~IOAPIC_ID_MASK; - tmp |= SET_IOAPIC_ID(IOAPICMap[apic].ApicId); - - IOAPICWrite(apic, IOAPIC_ID, tmp); - - /* - * Sanity check - */ - tmp = IOAPICRead(apic, 0); - if (GET_IOAPIC_ID(tmp) != IOAPICMap[apic].ApicId) { - DPRINT1("Could not set I/O APIC ID!\n"); - KeBugCheck(0); - } - } -} - - -/* - * EISA Edge/Level control register, ELCR - */ -static ULONG EISA_ELCR( - ULONG irq) -{ - if (irq < 16) { - PUCHAR port = (PUCHAR)(0x4d0 + (irq >> 3)); - return (READ_PORT_UCHAR(port) >> (irq & 7)) & 1; - } - DPRINT("Broken MPtable reports ISA irq %d\n", irq); - return 0; -} - -/* EISA interrupts are always polarity zero and can be edge or level - * trigger depending on the ELCR value. If an interrupt is listed as - * EISA conforming in the MP table, that means its trigger type must - * be read in from the ELCR */ - -#define default_EISA_trigger(idx) (EISA_ELCR(IRQMap[idx].SrcBusIrq)) -#define default_EISA_polarity(idx) (0) - -/* ISA interrupts are always polarity zero edge triggered, - * when listed as conforming in the MP table. */ - -#define default_ISA_trigger(idx) (0) -#define default_ISA_polarity(idx) (0) - -/* PCI interrupts are always polarity one level triggered, - * when listed as conforming in the MP table. */ - -#define default_PCI_trigger(idx) (1) -#define default_PCI_polarity(idx) (1) - -/* MCA interrupts are always polarity zero level triggered, - * when listed as conforming in the MP table. */ - -#define default_MCA_trigger(idx) (1) -#define default_MCA_polarity(idx) (0) - -static ULONG IRQPolarity( - ULONG idx) -{ - ULONG bus = IRQMap[idx].SrcBusId; - ULONG polarity; - - /* - * Determine IRQ line polarity (high active or low active): - */ - switch (IRQMap[idx].IrqFlag & 3) - { - case 0: /* conforms, ie. bus-type dependent polarity */ - { - switch (BUSMap[bus]) - { - case MP_BUS_ISA: /* ISA pin */ - { - polarity = default_ISA_polarity(idx); - break; - } - case MP_BUS_EISA: /* EISA pin */ - { - polarity = default_EISA_polarity(idx); - break; - } - case MP_BUS_PCI: /* PCI pin */ - { - polarity = default_PCI_polarity(idx); - break; - } - case MP_BUS_MCA: /* MCA pin */ - { - polarity = default_MCA_polarity(idx); - break; - } - default: - { - DPRINT("Broken BIOS!!\n"); - polarity = 1; - break; - } - } - break; - } - case 1: /* high active */ - { - polarity = 0; - break; - } - case 2: /* reserved */ - { - DPRINT("Broken BIOS!!\n"); - polarity = 1; - break; - } - case 3: /* low active */ - { - polarity = 1; - break; - } - default: /* invalid */ - { - DPRINT("Broken BIOS!!\n"); - polarity = 1; - break; - } - } - return polarity; -} - -static ULONG IRQTrigger( - ULONG idx) -{ - ULONG bus = IRQMap[idx].SrcBusId; - ULONG trigger; - - /* - * Determine IRQ trigger mode (edge or level sensitive): - */ - switch ((IRQMap[idx].IrqFlag >> 2) & 3) - { - case 0: /* conforms, ie. bus-type dependent */ - { - switch (BUSMap[bus]) - { - case MP_BUS_ISA: /* ISA pin */ - { - trigger = default_ISA_trigger(idx); - break; - } - case MP_BUS_EISA: /* EISA pin */ - { - trigger = default_EISA_trigger(idx); - break; - } - case MP_BUS_PCI: /* PCI pin */ - { - trigger = default_PCI_trigger(idx); - break; - } - case MP_BUS_MCA: /* MCA pin */ - { - trigger = default_MCA_trigger(idx); - break; - } - default: - { - DPRINT("Broken BIOS!!\n"); - trigger = 1; - break; - } - } - break; - } - case 1: /* edge */ - { - trigger = 0; - break; - } - case 2: /* reserved */ - { - DPRINT("Broken BIOS!!\n"); - trigger = 1; - break; - } - case 3: /* level */ - { - trigger = 1; - break; - } - default: /* invalid */ - { - DPRINT("Broken BIOS!!\n"); - trigger = 0; - break; - } - } - return trigger; -} - - -static ULONG Pin2Irq( - ULONG idx, - ULONG apic, - ULONG pin) -{ - ULONG irq, i; - ULONG bus = IRQMap[idx].SrcBusId; - - /* - * Debugging check, we are in big trouble if this message pops up! - */ - if (IRQMap[idx].DstApicInt != pin) { - DPRINT("broken BIOS or MPTABLE parser, ayiee!!\n"); - } - - switch (BUSMap[bus]) - { - case MP_BUS_ISA: /* ISA pin */ - case MP_BUS_EISA: - case MP_BUS_MCA: - { - irq = IRQMap[idx].SrcBusIrq; - break; - } - case MP_BUS_PCI: /* PCI pin */ - { - /* - * PCI IRQs are mapped in order - */ - i = irq = 0; - while (i < apic) - irq += IOAPICMap[i++].EntryCount; - irq += pin; - break; - } - default: - { - DPRINT("Unknown bus type %d.\n",bus); - irq = 0; - break; - } - } - - return irq; -} - - -/* - * Rough estimation of how many shared IRQs there are, can - * be changed anytime. - */ -#define MAX_PLUS_SHARED_IRQS PIC_IRQS -#define PIN_MAP_SIZE (MAX_PLUS_SHARED_IRQS + PIC_IRQS) - -/* - * This is performance-critical, we want to do it O(1) - * - * the indexing order of this array favors 1:1 mappings - * between pins and IRQs. - */ - -static struct irq_pin_list { - ULONG apic, pin, next; -} irq_2_pin[PIN_MAP_SIZE]; - -/* - * The common case is 1:1 IRQ<->pin mappings. Sometimes there are - * shared ISA-space IRQs, so we have to support them. We are super - * fast in the common case, and fast for shared ISA-space IRQs. - */ -static VOID AddPinToIrq( - ULONG irq, - ULONG apic, - ULONG pin) -{ - static ULONG first_free_entry = PIC_IRQS; - struct irq_pin_list *entry = irq_2_pin + irq; - - while (entry->next) - entry = irq_2_pin + entry->next; - - if (entry->pin != -1) { - entry->next = first_free_entry; - entry = irq_2_pin + entry->next; - if (++first_free_entry >= PIN_MAP_SIZE) { - DPRINT1("Ohh no!"); - KeBugCheck(0); - } - } - entry->apic = apic; - entry->pin = pin; -} - - -/* - * Find the IRQ entry number of a certain pin. - */ -static ULONG IOAPICGetIrqEntry( - ULONG apic, - ULONG pin, - ULONG type) -{ - ULONG i; - - for (i = 0; i < IRQCount; i++) - if (IRQMap[i].IrqType == type && - (IRQMap[i].DstApicId == IOAPICMap[apic].ApicId || - IRQMap[i].DstApicId == MP_APIC_ALL) && - IRQMap[i].DstApicInt == pin) - return i; - - return -1; -} - - -static ULONG AssignIrqVector( - ULONG irq) -{ - static ULONG current_vector = FIRST_DEVICE_VECTOR, vector_offset = 0; - ULONG vector; - - /* There may already have been assigned a vector for this IRQ */ - vector = IRQVectorMap[irq]; - if (vector > 0) - return vector; - - current_vector += 8; - if (current_vector > FIRST_SYSTEM_VECTOR) { - vector_offset++; - current_vector = FIRST_DEVICE_VECTOR + vector_offset; - } else if (current_vector == FIRST_SYSTEM_VECTOR) { - DPRINT1("Ran out of interrupt sources!"); - KeBugCheck(0); - } - - IRQVectorMap[irq] = current_vector; - return current_vector; -} - - -VOID IOAPICSetupIrqs( - VOID) -{ - IOAPIC_ROUTE_ENTRY entry; - ULONG apic, pin, idx, irq, first_notcon = 1, vector; - - DPRINT("Init IO_APIC IRQs\n"); - - for (apic = 0; apic < IOAPICCount; apic++) { - for (pin = 0; pin < IOAPICMap[apic].EntryCount; pin++) { - - /* - * add it to the IO-APIC irq-routing table - */ - memset(&entry,0,sizeof(entry)); - - entry.delivery_mode = APIC_DM_LOWEST; - entry.dest_mode = 1; /* logical delivery */ - entry.mask = 0; /* enable IRQ */ - entry.dest.logical.logical_dest = OnlineCPUs; - - idx = IOAPICGetIrqEntry(apic,pin,INT_VECTORED); - if (idx == -1) { - if (first_notcon) { - DPRINT(" IO-APIC (apicid-pin) %d-%d\n", IOAPICMap[apic].ApicId, pin); - first_notcon = 0; - } else { - DPRINT(", %d-%d\n", IOAPICMap[apic].ApicId, pin); - } - continue; - } - - entry.trigger = IRQTrigger(idx); - entry.polarity = IRQPolarity(idx); - - if (entry.trigger) { - entry.trigger = 1; - entry.mask = 1; - entry.dest.logical.logical_dest = OnlineCPUs; - } - - irq = Pin2Irq(idx, apic, pin); - AddPinToIrq(irq, apic, pin); - - vector = AssignIrqVector(irq); - entry.vector = vector; - - if (irq == 0) - { - /* Mask timer IRQ */ - entry.mask = 1; - } - - if ((apic == 0) && (irq < 16)) - Disable8259AIrq(irq); - - IOAPICWrite(apic, IOAPIC_REDTBL+2*pin+1, *(((PULONG)&entry)+1)); - IOAPICWrite(apic, IOAPIC_REDTBL+2*pin, *(((PULONG)&entry)+0)); - } - } -} - - -static VOID IOAPICEnable( - VOID) -{ - ULONG i, tmp; - - for (i = 0; i < PIN_MAP_SIZE; i++) { - irq_2_pin[i].pin = -1; - irq_2_pin[i].next = 0; - } - - /* - * The number of IO-APIC IRQ registers (== #pins): - */ - for (i = 0; i < IOAPICCount; i++) { - tmp = IOAPICRead(i, IOAPIC_VER); - IOAPICMap[i].EntryCount = GET_IOAPIC_MRE(tmp) + 1; - } - - /* - * Do not trust the IO-APIC being empty at bootup - */ - IOAPICClearAll(); -} - -#if 0 -static VOID IOAPICDisable( - VOID) -{ - /* - * Clear the IO-APIC before rebooting - */ - IOAPICClearAll(); - - APICDisable(); -} -#endif - - -static VOID IOAPICSetup( - VOID) -{ - IOAPICEnable(); - IOAPICSetupIds(); - if (0) { - // FIXME: This causes application processors to not boot if asked to - APICSyncArbIDs(); - } - IOAPICSetupIrqs(); -} - - -VOID IOAPICDump(VOID) -{ - ULONG apic, i; - ULONG reg0, reg1, reg2; - - DbgPrint("Number of MP IRQ sources: %d.\n", IRQCount); - for (i = 0; i < IOAPICCount; i++) { - DbgPrint("Number of IO-APIC #%d registers: %d.\n", - IOAPICMap[i].ApicId, - IOAPICMap[i].EntryCount); - } - - /* - * We are a bit conservative about what we expect. We have to - * know about every hardware change ASAP. - */ - DbgPrint("Testing the IO APIC.......................\n"); - - for (apic = 0; apic < IOAPICCount; apic++) { - - reg0 = IOAPICRead(apic, IOAPIC_ID); - reg1 = IOAPICRead(apic, IOAPIC_VER); - if (GET_IOAPIC_VERSION(reg1) >= 0x10) { - reg2 = IOAPICRead(apic, IOAPIC_ARB); - } - - DbgPrint("\n"); - DbgPrint("IO APIC #%d......\n", IOAPICMap[apic].ApicId); - DbgPrint(".... register #00: %08X\n", reg0); - DbgPrint("....... : physical APIC id: %02X\n", GET_IOAPIC_ID(reg0)); - if (reg0 & 0xF0FFFFFF) { - DbgPrint(" WARNING: Unexpected IO-APIC\n"); - } - - DbgPrint(".... register #01: %08X\n", reg1); - i = GET_IOAPIC_MRE(reg1); - - DbgPrint("....... : max redirection entries: %04X\n", i); - if ((i != 0x0f) && /* older (Neptune) boards */ - (i != 0x17) && /* typical ISA+PCI boards */ - (i != 0x1b) && /* Compaq Proliant boards */ - (i != 0x1f) && /* dual Xeon boards */ - (i != 0x22) && /* bigger Xeon boards */ - (i != 0x2E) && - (i != 0x3F)) { - DbgPrint(" WARNING: Unexpected IO-APIC\n"); - } - - i = GET_IOAPIC_VERSION(reg1); - DbgPrint("....... : IO APIC version: %04X\n", i); - if ((i != 0x01) && /* 82489DX IO-APICs */ - (i != 0x10) && /* oldest IO-APICs */ - (i != 0x11) && /* Pentium/Pro IO-APICs */ - (i != 0x13)) { /* Xeon IO-APICs */ - DbgPrint(" WARNING: Unexpected IO-APIC\n"); - } - - if (reg1 & 0xFF00FF00) { - DbgPrint(" WARNING: Unexpected IO-APIC\n"); - } - - if (GET_IOAPIC_VERSION(reg1) >= 0x10) { - DbgPrint(".... register #02: %08X\n", reg2); - DbgPrint("....... : arbitration: %02X\n", - GET_IOAPIC_ARB(reg2)); - if (reg2 & 0xF0FFFFFF) { - DbgPrint(" WARNING: Unexpected IO-APIC\n"); - } - } - - DbgPrint(".... IRQ redirection table:\n"); - DbgPrint(" NR Log Phy Mask Trig IRR Pol" - " Stat Dest Deli Vect: \n"); - - for (i = 0; i <= GET_IOAPIC_MRE(reg1); i++) { - IOAPIC_ROUTE_ENTRY entry; - - *(((PULONG)&entry)+0) = IOAPICRead(apic, 0x10+i*2); - *(((PULONG)&entry)+1) = IOAPICRead(apic, 0x11+i*2); - - DbgPrint(" %02x %03X %02X ", - i, - entry.dest.logical.logical_dest, - entry.dest.physical.physical_dest - ); - - DbgPrint("%C %C %1d %C %C %C %03X %02X\n", - (entry.mask == 0) ? 'U' : 'M', // Unmasked/masked - (entry.trigger == 0) ? 'E' : 'L', // Edge/level sensitive - entry.irr, - (entry.polarity == 0) ? 'H' : 'L', // Active high/active low - (entry.delivery_status == 0) ? 'I' : 'S', // Idle / send pending - (entry.dest_mode == 0) ? 'P' : 'L', // Physical logical - entry.delivery_mode, - entry.vector - ); - } - } - DbgPrint("IRQ to pin mappings:\n"); - for (i = 0; i < PIC_IRQS; i++) { - struct irq_pin_list *entry = irq_2_pin + i; - if (entry->pin < 0) - continue; - DbgPrint("IRQ%d ", i); - for (;;) { - DbgPrint("-> %d", entry->pin); - if (!entry->next) - break; - entry = irq_2_pin + entry->next; - } - if (i % 2) { - DbgPrint("\n"); - } else { - DbgPrint(" "); - } - } - - DbgPrint(".................................... done.\n"); -} - - - -/* Functions for handling local APICs */ - -#if 0 -volatile inline ULONG APICRead( - ULONG Offset) -{ - PULONG p; - - p = (PULONG)((ULONG)APICBase + Offset); - return *p; -} -#else -volatile inline ULONG APICRead( - ULONG Offset) -{ - PULONG p; - - lastregr = Offset; - lastvalr = 0; - - //DPRINT1("R(0x%X)", Offset); - p = (PULONG)((ULONG)APICBase + Offset); - lastvalr = *p; - //DPRINT1("(0x%08X)\n", *p); - - return lastvalr; -} -#endif - -#if 0 -inline VOID APICWrite( - ULONG Offset, - ULONG Value) -{ - PULONG p; - - p = (PULONG)((ULONG)APICBase + Offset); - - *p = Value; -} -#else -inline VOID APICWrite( - ULONG Offset, - ULONG Value) -{ - PULONG p; - - lastregw = Offset; - lastvalw = Value; - - //DPRINT1("W(0x%X, 0x%08X)\n", Offset, Value); - p = (PULONG)((ULONG)APICBase + Offset); - - *p = Value; -} -#endif - - -inline VOID APICSendEOI(VOID) -{ - // Dummy read - APICRead(APIC_SIVR); - // Send the EOI - APICWrite(APIC_EOI, 0); -} - - -VOID DumpESR(VOID) -{ - ULONG tmp; - - if (CPUMap[ThisCPU()].MaxLVT > 3) - APICWrite(APIC_ESR, 0); - tmp = APICRead(APIC_ESR); - DbgPrint("ESR %08x\n", tmp); -} - - -ULONG APICGetMaxLVT(VOID) -{ - ULONG tmp, ver, maxlvt; - - tmp = APICRead(APIC_VER); - ver = GET_APIC_VERSION(tmp); - /* 82489DXs do not report # of LVT entries. */ - maxlvt = APIC_INTEGRATED(ver) ? GET_APIC_MAXLVT(tmp) : 2; - - return maxlvt; -} - - -static VOID APICClear( - VOID) -{ - ULONG tmp, maxlvt; - - maxlvt = CPUMap[ThisCPU()].MaxLVT; - - /* - * Careful: we have to set masks only first to deassert - * any level-triggered sources. - */ - tmp = APICRead(APIC_LVTT); - APICWrite(APIC_LVTT, tmp | APIC_LVT_MASKED); - - tmp = APICRead(APIC_LINT0); - APICWrite(APIC_LINT0, tmp | APIC_LVT_MASKED); - - tmp = APICRead(APIC_LINT1); - APICWrite(APIC_LINT1, tmp | APIC_LVT_MASKED); - - if (maxlvt >= 3) { - tmp = APICRead(APIC_LVT3); - APICWrite(APIC_LVT3, tmp | APIC_LVT3_MASKED); - } - - if (maxlvt >= 4) { - tmp = APICRead(APIC_LVTPC); - APICWrite(APIC_LVTPC, tmp | APIC_LVT_MASKED); - } - - /* - * Clean APIC state for other OSs: - */ - APICRead(APIC_SIVR); // Dummy read - APICWrite(APIC_LVTT, APIC_LVT_MASKED); - - APICRead(APIC_SIVR); // Dummy read - APICWrite(APIC_LINT0, APIC_LVT_MASKED); - - APICRead(APIC_SIVR); // Dummy read - APICWrite(APIC_LINT1, APIC_LVT_MASKED); - - if (maxlvt >= 3) { - APICRead(APIC_SIVR); // Dummy read - APICWrite(APIC_LVT3, APIC_LVT3_MASKED); - } - - if (maxlvt >= 4) { - APICRead(APIC_SIVR); // Dummy read - APICWrite(APIC_LVTPC, APIC_LVT_MASKED); - } -} - -/* Enable symetric I/O mode ie. connect the BSP's - local APIC to INT and NMI lines */ -inline VOID EnableSMPMode( - VOID) -{ - /* - * Do not trust the local APIC being empty at bootup. - */ - APICClear(); - - WRITE_PORT_UCHAR((PUCHAR)0x22, 0x70); - WRITE_PORT_UCHAR((PUCHAR)0x23, 0x01); -} - - -/* Disable symetric I/O mode ie. go to PIC mode */ -inline VOID DisableSMPMode( - VOID) -{ - /* - * Put the board back into PIC mode (has an effect - * only on certain older boards). Note that APIC - * interrupts, including IPIs, won't work beyond - * this point! The only exception are INIT IPIs. - */ - WRITE_PORT_UCHAR((PUCHAR)0x22, 0x70); - WRITE_PORT_UCHAR((PUCHAR)0x23, 0x00); -} - - -VOID APICDisable( - VOID) -{ - ULONG tmp; - - APICClear(); - - /* - * Disable APIC (implies clearing of registers for 82489DX!). - */ - tmp = APICRead(APIC_SIVR); - tmp &= ~APIC_SIVR_ENABLE; - APICWrite(APIC_SIVR, tmp); -} - - -inline ULONG ThisCPU( - VOID) -{ - return (APICRead(APIC_ID) & APIC_ID_MASK) >> 24; -} - - -static VOID APICDumpBit(ULONG base) -{ - ULONG v, i, j; - - DbgPrint("0123456789abcdef0123456789abcdef\n"); - for (i = 0; i < 8; i++) { - APICRead(base + i*0x10); - for (j = 0; j < 32; j++) { - if (v & (1< 3) /* Due to the Pentium erratum 3AP. */ - APICWrite(APIC_ESR, 0); - v = APICRead(APIC_ESR); - DbgPrint("... ESR : %08x\n", v); - } - - v = APICRead(APIC_ICR0); - DbgPrint("... ICR0 : %08x ! ", v); - v = APICRead(APIC_ICR1); - DbgPrint("... ICR1 : %08x ! ", v); - - v = APICRead(APIC_LVTT); - DbgPrint("... LVTT : %08x\n", v); - - if (maxlvt > 3) { /* PC is LVT#4. */ - v = APICRead(APIC_LVTPC); - DbgPrint("... LVTPC : %08x ! ", v); - } - v = APICRead(APIC_LINT0); - DbgPrint("... LINT0 : %08x ! ", v); - v = APICRead(APIC_LINT1); - DbgPrint("... LINT1 : %08x\n", v); - - if (maxlvt > 2) { - v = APICRead(APIC_LVT3); - DbgPrint("... LVT3 : %08x\n", v); - } - - v = APICRead(APIC_ICRT); - DbgPrint("... ICRT : %08x ! ", v); - v = APICRead(APIC_CCRT); - DbgPrint("... CCCT : %08x ! ", v); - v = APICRead(APIC_TDCR); - DbgPrint("... TDCR : %08x\n", v); - DbgPrint("\n"); - DbgPrint("Last register read (offset): 0x%08X\n", r1); - DbgPrint("Last register read (value): 0x%08X\n", r2); - DbgPrint("Last register written (offset): 0x%08X\n", w1); - DbgPrint("Last register written (value): 0x%08X\n", w2); - DbgPrint("\n"); -} - - -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; -} - - -VOID WaitFor8254Wraparound(VOID) -{ - ULONG CurCount, 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); -} - -#define HZ (100) -#define APIC_DIVISOR (16) - -VOID APICSetupLVTT( - ULONG ClockTicks) -{ - ULONG tmp; - - /* Periodic timer */ - tmp = SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV) | - APIC_LVT_PERIODIC | LOCAL_TIMER_VECTOR; - APICWrite(APIC_LVTT, tmp); - - tmp = APICRead(APIC_TDCR); - tmp &= ~(APIC_TDCR_1 | APIC_TDCR_TMBASE | APIC_TDCR_16); - APICWrite(APIC_TDCR, tmp); - APICWrite(APIC_ICRT, ClockTicks / APIC_DIVISOR); -} - - -VOID APICCalibrateTimer( - ULONG CPU) -{ - ULARGE_INTEGER t1, t2; - LONG tt1, tt2; - - DPRINT("Calibrating APIC timer...\n"); - - APICSetupLVTT(~0); - - /* - * The timer chip counts down to zero. Let's wait - * for a wraparound to start exact measurement: - * (the current tick might have been already half done) - */ - WaitFor8254Wraparound(); - - /* - * We wrapped around just now. Let's start - */ - ReadPentiumClock(&t1); - tt1 = APICRead(APIC_CCRT); - - WaitFor8254Wraparound(); - - tt2 = APICRead(APIC_CCRT); - ReadPentiumClock(&t2); - - CPUMap[CPU].BusSpeed = (HZ * (tt2 - tt1) * APIC_DIVISOR); - CPUMap[CPU].CoreSpeed = (HZ * (t2.QuadPart - t1.QuadPart)); - - /* Setup timer for normal operation */ - //APICSetupLVTT((CPUMap[CPU].BusSpeed / 1000000) * 100); // 100ns - APICSetupLVTT((CPUMap[CPU].BusSpeed / 1000000) * 15000); // 15ms - //APICSetupLVTT((CPUMap[CPU].BusSpeed / 1000000) * 100000); // 100ms - - DPRINT("CPU clock speed is %ld.%04ld MHz.\n", - CPUMap[CPU].CoreSpeed/1000000, - CPUMap[CPU].CoreSpeed%1000000); - - DPRINT("Host bus clock speed is %ld.%04ld MHz.\n", - CPUMap[CPU].BusSpeed/1000000, - CPUMap[CPU].BusSpeed%1000000); -} - - -static VOID APICSleep( - ULONG Count) -/* - PARAMETERS: - Count = Number of microseconds to busy wait - */ -{ - KeStallExecutionProcessor(Count); -} - - -static VOID APICSyncArbIDs( - VOID) -{ - ULONG i, tmp; - - /* Wait up to 100ms for the APIC to become ready */ - for (i = 0; i < 10000; i++) { - tmp = APICRead(APIC_ICR0); - /* Check Delivery Status */ - if ((tmp & APIC_ICR0_DS) == 0) - break; - APICSleep(10); - } - - if (i == 10000) { - DPRINT("CPU(%d) APIC busy for 100ms.\n", ThisCPU()); - } - - DPRINT("Synchronizing Arb IDs.\n"); - APICWrite(APIC_ICR0, APIC_ICR0_DESTS_ALL | APIC_ICR0_LEVEL | APIC_DM_INIT); -} - - -VOID APICSendIPI( - ULONG Target, - ULONG DeliveryMode, - ULONG IntNum, - ULONG Level) -{ - ULONG tmp, i, flags; - - pushfl(flags); - __asm__ ("\n\tcli\n\t"); - - /* Wait up to 100ms for the APIC to become ready */ - for (i = 0; i < 10000; i++) { - tmp = APICRead(APIC_ICR0); - /* Check Delivery Status */ - if ((tmp & APIC_ICR0_DS) == 0) - break; - APICSleep(10); - } - - if (i == 10000) { - DPRINT("CPU(%d) Previous IPI was not delivered after 100ms.\n", ThisCPU()); - } - - /* Setup the APIC to deliver the IPI */ - tmp = APICRead(APIC_ICR1); - tmp &= 0x00FFFFFF; - APICWrite(APIC_ICR1, tmp | SET_APIC_DEST_FIELD(Target)); - - tmp = APICRead(APIC_ICR0); - tmp &= ~(APIC_ICR0_LEVEL | APIC_ICR0_DESTM | APIC_ICR0_DM | APIC_ICR0_VECTOR); - tmp |= (DeliveryMode | IntNum | Level); - - if (Target == APIC_TARGET_SELF) { - tmp |= APIC_ICR0_DESTS_SELF; - } else if (Target == APIC_TARGET_ALL) { - tmp |= APIC_ICR0_DESTS_ALL; - } else if (Target == APIC_TARGET_ALL_BUT_SELF) { - tmp |= APIC_ICR0_DESTS_ALL_BUT_SELF; - } else { - tmp |= APIC_ICR0_DESTS_FIELD; - } - - /* Now, fire off the IPI */ - APICWrite(APIC_ICR0, tmp); - - popfl(flags); -} - - -BOOLEAN VerifyLocalAPIC( - VOID) -{ - UINT reg0, reg1; - - /* The version register is read-only in a real APIC */ - reg0 = APICRead(APIC_VER); - APICWrite(APIC_VER, reg0 ^ APIC_VER_MASK); - reg1 = APICRead(APIC_VER); - - if (reg1 != reg0) - return FALSE; - - /* The ID register is read/write in a real APIC */ - reg0 = APICRead(APIC_ID); - APICWrite(APIC_ID, reg0 ^ APIC_ID_MASK); - reg1 = APICRead(APIC_ID); - APICWrite(APIC_ID, reg0); - if (reg1 != (reg0 ^ APIC_ID_MASK)) - return FALSE; - - return TRUE; -} - - -static VOID SetInterruptGate( - ULONG index, - ULONG address) -{ - IDT_DESCRIPTOR *idt; - - idt = (IDT_DESCRIPTOR*)((ULONG)KeGetCurrentKPCR()->IDT + index * sizeof(IDT_DESCRIPTOR)); - idt->a = (((ULONG)address)&0xffff) + (KERNEL_CS << 16); - idt->b = 0x8f00 + (((ULONG)address)&0xffff0000); -} - - -VOID MpsTimerHandler( - VOID) -{ -#if 0 - KIRQL OldIrql; -#endif - - DPRINT("T1"); - - /* - * Acknowledge the interrupt - */ - APICSendEOI(); -#if 0 - /* - * Notify the rest of the kernel of the raised irq level - */ - OldIrql = KeRaiseIrqlToSynchLevel(); -#endif - __asm__("sti\n\t"); - - /* - * Call the dispatcher - */ - PsDispatchThread(THREAD_STATE_RUNNABLE); - -#if 0 - /* - * Lower irq level - */ - KeLowerIrql(OldIrql); -#endif -} - - -VOID MpsErrorHandler( - VOID) -{ - ULONG tmp1, tmp2; - - APICDump(); - - tmp1 = APICRead(APIC_ESR); - APICWrite(APIC_ESR, 0); - tmp2 = APICRead(APIC_ESR); - - /* - * Acknowledge the interrupt - */ - APICSendEOI(); - - /* Here is what the APIC error bits mean: - 0: Send CS error - 1: Receive CS error - 2: Send accept error - 3: Receive accept error - 4: Reserved - 5: Send illegal vector - 6: Received illegal vector - 7: Illegal register address - */ - DPRINT1("APIC error on CPU(%d) ESR(%x)(%x)\n", ThisCPU(), tmp1, tmp2); - for (;;); -} - - -VOID MpsSpuriousHandler( - VOID) -{ - DPRINT1("Spurious interrupt on CPU(%d)\n", ThisCPU()); - - /* - * Acknowledge the interrupt - */ - APICSendEOI(); - APICDump(); - for (;;); -} - - -VOID APICSetup( - VOID) -{ - ULONG CPU, tmp; - - CPU = ThisCPU(); - - /* - * Intel recommends to set DFR, LDR and TPR before enabling - * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel - * document number 292116). So here it goes... - */ - - /* - * Put the APIC into flat delivery mode. - * Must be "all ones" explicitly for 82489DX. - */ - APICWrite(APIC_DFR, 0xFFFFFFFF); - - /* - * Set up the logical destination ID. - */ - tmp = APICRead(APIC_LDR); - tmp &= ~APIC_LDR_MASK; - tmp |= (1 << (CPU + 24)); - APICWrite(APIC_LDR, tmp); - - /* Accept all interrupts */ - tmp = (APICRead(APIC_TPR) & ~APIC_TPR_PRI); - APICWrite(APIC_TPR, tmp); - - /* Enable local APIC */ - tmp = APICRead(APIC_SIVR) | APIC_SIVR_ENABLE | APIC_SIVR_FOCUS; // No focus processor - - /* Set spurious interrupt vector */ - tmp |= SPURIOUS_VECTOR; - - APICWrite(APIC_SIVR, tmp); - - /* - * Only the BP should see the LINT1 NMI signal, obviously. - */ - if (CPU == 0) - tmp = APIC_DM_NMI; - else - tmp = APIC_DM_NMI | APIC_LVT_MASKED; - if (!APIC_INTEGRATED(CPUMap[CPU].APICVersion)) /* 82489DX */ - tmp |= APIC_LVT_LEVEL_TRIGGER; - APICWrite(APIC_LINT1, tmp); - - if (APIC_INTEGRATED(CPUMap[CPU].APICVersion)) { /* !82489DX */ - if (CPUMap[CPU].MaxLVT > 3) { /* Due to the Pentium erratum 3AP */ - APICWrite(APIC_ESR, 0); - } - - tmp = APICRead(APIC_ESR); - DPRINT("ESR value before enabling vector: 0x%X\n", tmp); - - /* Enable sending errors */ - tmp = ERROR_VECTOR; - APICWrite(APIC_LVT3, tmp); - - /* - * Spec says clear errors after enabling vector - */ - if (CPUMap[CPU].MaxLVT > 3) - APICWrite(APIC_ESR, 0); - tmp = APICRead(APIC_ESR); - DPRINT("ESR value after enabling vector: 0x%X\n", tmp); - } -} - -VOID -HaliInitBSP( - VOID) -{ - PUSHORT ps; - - /* Only initialize the BSP once */ - if (BSPInitialized) - return; - - BSPInitialized = TRUE; - - DPRINT("APIC is mapped at 0x%X\n", APICBase); - - if (VerifyLocalAPIC()) { - DPRINT("APIC found\n"); - } else { - DPRINT1("No APIC found\n"); - KeBugCheck(0); - } - - CPUMap[BootCPU].MaxLVT = APICGetMaxLVT(); - - SetInterruptGate(LOCAL_TIMER_VECTOR, (ULONG)MpsTimerInterrupt); - SetInterruptGate(ERROR_VECTOR, (ULONG)MpsErrorInterrupt); - SetInterruptGate(SPURIOUS_VECTOR, (ULONG)MpsSpuriousInterrupt); - - if (APICMode == amPIC) { - EnableSMPMode(); - } - - APICSetup(); - - /* BIOS data segment */ - BIOSBase = (PULONG)BIOS_AREA; - - /* Area for communicating with the APs */ - CommonBase = (PULONG)COMMON_AREA; - - /* Copy bootstrap code to common area */ - memcpy((PVOID)((ULONG)CommonBase + PAGESIZE), - &APstart, - (ULONG)&APend - (ULONG)&APstart + 1); - - /* Set shutdown code */ - CMOS_WRITE(0xF, 0xA); - - /* Set warm reset vector */ - ps = (PUSHORT)((ULONG)BIOSBase + 0x467); - *ps = (COMMON_AREA + PAGESIZE) & 0xF; - - ps = (PUSHORT)((ULONG)BIOSBase + 0x469); - *ps = (COMMON_AREA + PAGESIZE) >> 4; - - /* Calibrate APIC timer */ - APICCalibrateTimer(0); - - /* The boot processor is online */ - OnlineCPUs = (1 << 0); -} - -#endif /* MP */ - -VOID -STDCALL -HalInitializeProcessor ( - ULONG ProcessorNumber) -{ - -#ifdef MP - - PCOMMON_AREA_INFO Common; - ULONG StartupCount; - ULONG DeliveryStatus; - ULONG AcceptStatus; - ULONG CPU, i, j; - ULONG tmp, maxlvt; - - if (ProcessorNumber == 0) { - /* Boot processor is already initialized */ - NextCPU = 1; - return; - } - - if (NextCPU < CPUCount) { - CPU = NextCPU; - - DPRINT("Attempting to boot CPU %d\n", CPU); - - /* Send INIT IPI */ - APICSendIPI(CPUMap[CPU].APICId, APIC_DM_INIT, 0, APIC_ICR0_LEVEL_ASSERT); - - APICSleep(200); - - /* Deassert INIT */ - APICSendIPI(CPUMap[CPU].APICId, APIC_DM_INIT, 0, APIC_ICR0_LEVEL_DEASSERT); - - if (APIC_INTEGRATED(CPUMap[CPU].APICVersion)) { - /* Clear APIC errors */ - APICWrite(APIC_ESR, 0); - tmp = (APICRead(APIC_ESR) & APIC_ESR_MASK); - } - - Common = (PCOMMON_AREA_INFO)CommonBase; - - /* Write the location of the AP stack */ - Common->Stack = (ULONG)ExAllocatePool(NonPagedPool, MM_STACK_SIZE) + MM_STACK_SIZE; - Ki386InitialStackArray[CPU] = (PVOID)(Common->Stack - MM_STACK_SIZE); - - DPRINT("CPU %d got stack at 0x%X\n", CPU, Common->Stack); -#if 0 - for (j = 0; j < 16; j++) { - Common->Debug[j] = 0; - } -#endif - - maxlvt = APICGetMaxLVT(); - - /* Is this a local APIC or an 82489DX? */ - StartupCount = (APIC_INTEGRATED(CPUMap[CPU].APICVersion)) ? 2 : 0; - - for (i = 1; i <= StartupCount; i++) - { - /* It's a local APIC, so send STARTUP IPI */ - DPRINT("Sending startup signal %d\n", i); - /* Clear errors */ - APICWrite(APIC_ESR, 0); - APICRead(APIC_ESR); - - APICSendIPI(CPUMap[CPU].APICId, - 0, - APIC_DM_STARTUP | ((COMMON_AREA + PAGESIZE) >> 12), - APIC_ICR0_LEVEL_DEASSERT); - - /* Wait up to 10ms for IPI to be delivered */ - j = 0; - do { - APICSleep(10); - - /* Check Delivery Status */ - DeliveryStatus = APICRead(APIC_ICR0) & APIC_ICR0_DS; - - j++; - } while ((DeliveryStatus) && (j < 1000)); - - APICSleep(200); - - /* - * Due to the Pentium erratum 3AP. - */ - if (maxlvt > 3) { - APICRead(APIC_SIVR); - APICWrite(APIC_ESR, 0); - } - - AcceptStatus = APICRead(APIC_ESR) & APIC_ESR_MASK; - - if (DeliveryStatus || AcceptStatus) { - break; - } - } - - if (DeliveryStatus) { - DPRINT("STARTUP IPI for CPU %d was never delivered.\n", CPU); - } - - if (AcceptStatus) { - DPRINT("STARTUP IPI for CPU %d was never accepted.\n", CPU); - } - - if (!(DeliveryStatus || AcceptStatus)) { - - /* Wait no more than 5 seconds for processor to boot */ - DPRINT("Waiting for 5 seconds for CPU %d to boot\n", CPU); - - /* Wait no more than 5 seconds */ - for (j = 0; j < 50000; j++) { - - if (CPUMap[CPU].Flags & CPU_ENABLED) - break; - - APICSleep(100); - } - } - - if (CPUMap[CPU].Flags & CPU_ENABLED) { - DbgPrint("CPU %d is now running\n", CPU); - } else { - DbgPrint("Initialization of CPU %d failed\n", CPU); - } - -#if 0 - DPRINT("Debug bytes are:\n"); - - for (j = 0; j < 4; j++) { - DPRINT("0x%08X 0x%08X 0x%08X 0x%08X.\n", - Common->Debug[j*4+0], - Common->Debug[j*4+1], - Common->Debug[j*4+2], - Common->Debug[j*4+3]); - } -#endif - NextCPU++; - } - -#endif /* MP */ - -} - -BOOLEAN -STDCALL -HalAllProcessorsStarted ( - VOID - ) -{ - -#ifdef MP - - return (NextCPU >= CPUCount); - -#else /* MP */ - - if (BSPInitialized) { - return TRUE; - } else { - BSPInitialized = TRUE; - return FALSE; - } - -#endif /* MP */ - -} - -BOOLEAN -STDCALL -HalStartNextProcessor ( - ULONG Unknown1, - ULONG Unknown2 - ) -{ -#ifdef MP - - /* Display the APIC registers for debugging */ - switch (Unknown1) { - case 0: - APICDump(); - break; - case 1: - IOAPICDump(); - } - for(;;); - - return (NextCPU >= CPUCount); - -#endif /* MP */ - - return FALSE; -} - - -#ifdef MP - -ULONG MPChecksum( - PUCHAR Base, - ULONG Size) -/* - * Checksum an MP configuration block - */ -{ - ULONG Sum = 0; - - while (Size--) - Sum += *Base++; - - return((UCHAR)Sum); -} - - -PCHAR HaliMPFamily( - ULONG Family, - ULONG Model) -{ - static CHAR str[32]; - static PCHAR CPUs[] = - { - "80486DX", "80486DX", - "80486SX", "80486DX/2 or 80487", - "80486SL", "Intel5X2(tm)", - "Unknown", "Unknown", - "80486DX/4" - }; - if (Family == 0x6) - return ("Pentium(tm) Pro"); - if (Family == 0x5) - return ("Pentium(tm)"); - if (Family == 0x0F && Model == 0x0F) - return("Special controller"); - if (Family == 0x0F && Model == 0x00) - return("Pentium 4(tm)"); - if (Family == 0x04 && Model < 9) - return CPUs[Model]; - sprintf(str, "Unknown CPU with family ID %ld and model ID %ld", Family, Model); - return str; -} - - -static VOID HaliMPProcessorInfo(PMP_CONFIGURATION_PROCESSOR m) -{ - ULONG ver; - - if (!(m->CpuFlags & CPU_FLAG_ENABLED)) - return; - - DPRINT("Processor #%d %s APIC version %d\n", - m->ApicId, - HaliMPFamily((m->FeatureFlags & CPU_FAMILY_MASK) >> 8, - (m->FeatureFlags & CPU_MODEL_MASK) >> 4), - m->ApicVersion); - - if (m->FeatureFlags & (1 << 0)) - DPRINT(" Floating point unit present.\n"); - if (m->FeatureFlags & (1 << 7)) - DPRINT(" Machine Exception supported.\n"); - if (m->FeatureFlags & (1 << 8)) - DPRINT(" 64 bit compare & exchange supported.\n"); - if (m->FeatureFlags & (1 << 9)) - DPRINT(" Internal APIC present.\n"); - if (m->FeatureFlags & (1 << 11)) - DPRINT(" SEP present.\n"); - if (m->FeatureFlags & (1 << 12)) - DPRINT(" MTRR present.\n"); - if (m->FeatureFlags & (1 << 13)) - DPRINT(" PGE present.\n"); - if (m->FeatureFlags & (1 << 14)) - DPRINT(" MCA present.\n"); - if (m->FeatureFlags & (1 << 15)) - DPRINT(" CMOV present.\n"); - if (m->FeatureFlags & (1 << 16)) - DPRINT(" PAT present.\n"); - if (m->FeatureFlags & (1 << 17)) - DPRINT(" PSE present.\n"); - if (m->FeatureFlags & (1 << 18)) - DPRINT(" PSN present.\n"); - if (m->FeatureFlags & (1 << 19)) - DPRINT(" Cache Line Flush Instruction present.\n"); - /* 20 Reserved */ - if (m->FeatureFlags & (1 << 21)) - DPRINT(" Debug Trace and EMON Store present.\n"); - if (m->FeatureFlags & (1 << 22)) - DPRINT(" ACPI Thermal Throttle Registers present.\n"); - if (m->FeatureFlags & (1 << 23)) - DPRINT(" MMX present.\n"); - if (m->FeatureFlags & (1 << 24)) - DPRINT(" FXSR present.\n"); - if (m->FeatureFlags & (1 << 25)) - DPRINT(" XMM present.\n"); - if (m->FeatureFlags & (1 << 26)) - DPRINT(" Willamette New Instructions present.\n"); - if (m->FeatureFlags & (1 << 27)) - DPRINT(" Self Snoop present.\n"); - /* 28 Reserved */ - if (m->FeatureFlags & (1 << 29)) - DPRINT(" Thermal Monitor present.\n"); - /* 30, 31 Reserved */ - - CPUMap[CPUCount].APICId = m->ApicId; - - CPUMap[CPUCount].Flags = CPU_USABLE; - - if (m->CpuFlags & CPU_FLAG_BSP) { - DPRINT(" Bootup CPU\n"); - CPUMap[CPUCount].Flags |= CPU_BSP; - BootCPU = m->ApicId; - } - - if (m->ApicId > MAX_CPU) { - DPRINT("Processor #%d INVALID. (Max ID: %d).\n", m->ApicId, MAX_CPU); - return; - } - ver = m->ApicVersion; - - /* - * Validate version - */ - if (ver == 0x0) { - DPRINT("BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m->ApicId); - ver = 0x10; - } - CPUMap[CPUCount].APICVersion = ver; - - CPUCount++; -} - -static VOID HaliMPBusInfo(PMP_CONFIGURATION_BUS m) -{ - static ULONG CurrentPCIBusId = 0; - CHAR str[7]; - - memcpy(str, m->BusType, 6); - str[6] = 0; - DPRINT("Bus #%d is %s\n", m->BusId, str); - - if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) { - BUSMap[m->BusId] = MP_BUS_ISA; - } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) { - BUSMap[m->BusId] = MP_BUS_EISA; - } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) { - BUSMap[m->BusId] = MP_BUS_PCI; - PCIBUSMap[m->BusId] = CurrentPCIBusId; - CurrentPCIBusId++; - } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA)-1) == 0) { - BUSMap[m->BusId] = MP_BUS_MCA; - } else { - DPRINT("Unknown bustype %s - ignoring\n", str); - } -} - -static VOID HaliMPIOApicInfo(PMP_CONFIGURATION_IOAPIC m) -{ - if (!(m->ApicFlags & CPU_FLAG_ENABLED)) - return; - - DPRINT("I/O APIC #%d Version %d at 0x%lX.\n", - m->ApicId, m->ApicVersion, m->ApicAddress); - if (IOAPICCount > MAX_IOAPIC) { - DPRINT("Max # of I/O APICs (%d) exceeded (found %d).\n", - MAX_IOAPIC, IOAPICCount); - DPRINT1("Recompile with bigger MAX_IOAPIC!.\n"); - KeBugCheck(0); - } - IOAPICMap[IOAPICCount].ApicId = m->ApicId; - IOAPICMap[IOAPICCount].ApicVersion = m->ApicVersion; - IOAPICMap[IOAPICCount].ApicAddress = m->ApicAddress; - IOAPICCount++; -} - -static VOID HaliMPIntSrcInfo(PMP_CONFIGURATION_INTSRC m) -{ - DPRINT("Int: type %d, pol %d, trig %d, bus %d," - " IRQ %02x, APIC ID %x, APIC INT %02x\n", - m->IrqType, m->IrqFlag & 3, - (m->IrqFlag >> 2) & 3, m->SrcBusId, - m->SrcBusIrq, m->DstApicId, m->DstApicInt); - if (IRQCount > MAX_IRQ_SOURCE) { - DPRINT1("Max # of irq sources exceeded!!\n"); - KeBugCheck(0); - } - - IRQMap[IRQCount] = *m; - IRQCount++; -} - -static VOID HaliMPIntLocalInfo(PMP_CONFIGURATION_INTLOCAL m) -{ - DPRINT("Lint: type %d, pol %d, trig %d, bus %d," - " IRQ %02x, APIC ID %x, APIC LINT %02x\n", - m->IrqType, m->IrqFlag & 3, - (m->IrqFlag >> 2) & 3, m->SrcBusId, - m->SrcBusIrq, m->DstApicId, m->DstApicLInt); - /* - * Well it seems all SMP boards in existence - * use ExtINT/LVT1 == LINT0 and - * NMI/LVT2 == LINT1 - the following check - * will show us if this assumptions is false. - * Until then we do not have to add baggage. - */ - if ((m->IrqType == INT_EXTINT) && (m->DstApicLInt != 0)) { - DPRINT1("Invalid MP table!\n"); - KeBugCheck(0); - } - if ((m->IrqType == INT_NMI) && (m->DstApicLInt != 1)) { - DPRINT1("Invalid MP table!\n"); - KeBugCheck(0); - } -} - - -VOID -HaliReadMPConfigTable( - PMP_CONFIGURATION_TABLE Table) -/* - PARAMETERS: - Table = Pointer to MP configuration table - */ -{ - PUCHAR Entry; - ULONG Count; - - if (Table->Signature != MPC_SIGNATURE) - { - PUCHAR pc = (PUCHAR)&Table->Signature; - - DbgPrint("Bad MP configuration block signature: %c%c%c%c\n", - pc[0], pc[1], pc[2], pc[3]); - KeBugCheck(0); - return; - } - - if (MPChecksum((PUCHAR)Table, Table->Length)) - { - DbgPrint("Bad MP configuration block checksum\n"); - KeBugCheck(0); - return; - } - - if (Table->Specification < 0x04) - { - DbgPrint("Bad MP configuration table version (%d)\n", - Table->Specification); - KeBugCheck(0); - return; - } - - APICBase = (PULONG)Table->LocalAPICAddress; - if (APICBase != (PULONG)APIC_DEFAULT_BASE) - { - DbgPrint("APIC base address is at 0x%X. " \ - "I cannot handle non-standard adresses\n", APICBase); - KeBugCheck(0); - } - - Entry = (PUCHAR)((PVOID)Table + sizeof(MP_CONFIGURATION_TABLE)); - Count = 0; - while (Count < (Table->Length - sizeof(MP_CONFIGURATION_TABLE))) - { - /* Switch on type */ - switch (*Entry) - { - case MPCTE_PROCESSOR: - { - HaliMPProcessorInfo((PMP_CONFIGURATION_PROCESSOR)Entry); - Entry += sizeof(MP_CONFIGURATION_PROCESSOR); - Count += sizeof(MP_CONFIGURATION_PROCESSOR); - break; - } - case MPCTE_BUS: - { - HaliMPBusInfo((PMP_CONFIGURATION_BUS)Entry); - Entry += sizeof(MP_CONFIGURATION_BUS); - Count += sizeof(MP_CONFIGURATION_BUS); - break; - } - case MPCTE_IOAPIC: - { - HaliMPIOApicInfo((PMP_CONFIGURATION_IOAPIC)Entry); - Entry += sizeof(MP_CONFIGURATION_IOAPIC); - Count += sizeof(MP_CONFIGURATION_IOAPIC); - break; - } - case MPCTE_INTSRC: - { - HaliMPIntSrcInfo((PMP_CONFIGURATION_INTSRC)Entry); - Entry += sizeof(MP_CONFIGURATION_INTSRC); - Count += sizeof(MP_CONFIGURATION_INTSRC); - break; - } - case MPCTE_LINTSRC: - { - HaliMPIntLocalInfo((PMP_CONFIGURATION_INTLOCAL)Entry); - Entry += sizeof(MP_CONFIGURATION_INTLOCAL); - Count += sizeof(MP_CONFIGURATION_INTLOCAL); - break; - } - default: - DbgPrint("Unknown entry in MPC table\n"); - KeBugCheck(0); - } - } -} - - -static VOID HaliConstructDefaultIOIrqMPTable( - ULONG Type) -{ - MP_CONFIGURATION_INTSRC intsrc; - ULONG i; - - intsrc.Type = MPCTE_INTSRC; - intsrc.IrqFlag = 0; /* conforming */ - intsrc.SrcBusId = 0; - intsrc.DstApicId = IOAPICMap[0].ApicId; - - intsrc.IrqType = INT_VECTORED; - for (i = 0; i < 16; i++) { - switch (Type) { - case 2: - if (i == 0 || i == 13) - continue; /* IRQ0 & IRQ13 not connected */ - /* Fall through */ - default: - if (i == 2) - continue; /* IRQ2 is never connected */ - } - - intsrc.SrcBusIrq = i; - intsrc.DstApicInt = i ? i : 2; /* IRQ0 to INTIN2 */ - HaliMPIntSrcInfo(&intsrc); - } - - intsrc.IrqType = INT_EXTINT; - intsrc.SrcBusIrq = 0; - intsrc.DstApicInt = 0; /* 8259A to INTIN0 */ - HaliMPIntSrcInfo(&intsrc); -} - - -static VOID HaliConstructDefaultISAMPTable( - ULONG Type) -{ - MP_CONFIGURATION_PROCESSOR processor; - MP_CONFIGURATION_BUS bus; - MP_CONFIGURATION_IOAPIC ioapic; - MP_CONFIGURATION_INTLOCAL lintsrc; - ULONG linttypes[2] = { INT_EXTINT, INT_NMI }; - ULONG i; - - APICBase = (PULONG)APIC_DEFAULT_BASE; - - /* - * 2 CPUs, numbered 0 & 1. - */ - processor.Type = MPCTE_PROCESSOR; - /* Either an integrated APIC or a discrete 82489DX. */ - processor.ApicVersion = Type > 4 ? 0x10 : 0x01; - processor.CpuFlags = CPU_FLAG_ENABLED | CPU_FLAG_BSP; - /* FIXME: Get this from the bootstrap processor */ - processor.CpuSignature = 0; - processor.FeatureFlags = 0; - processor.Reserved[0] = 0; - processor.Reserved[1] = 0; - for (i = 0; i < 2; i++) { - processor.ApicId = i; - HaliMPProcessorInfo(&processor); - processor.CpuFlags &= ~CPU_FLAG_BSP; - } - - bus.Type = MPCTE_BUS; - bus.BusId = 0; - switch (Type) { - default: - DPRINT("Unknown standard configuration %d\n", Type); - /* Fall through */ - case 1: - case 5: - memcpy(bus.BusType, "ISA ", 6); - break; - case 2: - case 6: - case 3: - memcpy(bus.BusType, "EISA ", 6); - break; - case 4: - case 7: - memcpy(bus.BusType, "MCA ", 6); - } - HaliMPBusInfo(&bus); - if (Type > 4) { - bus.Type = MPCTE_BUS; - bus.BusId = 1; - memcpy(bus.BusType, "PCI ", 6); - HaliMPBusInfo(&bus); - } - - ioapic.Type = MPCTE_IOAPIC; - ioapic.ApicId = 2; - ioapic.ApicVersion = Type > 4 ? 0x10 : 0x01; - ioapic.ApicFlags = MP_IOAPIC_USABLE; - ioapic.ApicAddress = IOAPIC_DEFAULT_BASE; - HaliMPIOApicInfo(&ioapic); - - /* - * We set up most of the low 16 IO-APIC pins according to MPS rules. - */ - HaliConstructDefaultIOIrqMPTable(Type); - - lintsrc.Type = MPCTE_LINTSRC; - lintsrc.IrqType = 0; - lintsrc.IrqFlag = 0; /* conforming */ - lintsrc.SrcBusId = 0; - lintsrc.SrcBusIrq = 0; - lintsrc.DstApicId = MP_APIC_ALL; - for (i = 0; i < 2; i++) { - lintsrc.IrqType = linttypes[i]; - lintsrc.DstApicLInt = i; - HaliMPIntLocalInfo(&lintsrc); - } -} - -BOOLEAN -HaliScanForMPConfigTable( - ULONG Base, - ULONG Size) -/* - PARAMETERS: - Base = Base address of region - Size = Length of region to check - RETURNS: - TRUE if a valid MP configuration table was found - */ -{ - PULONG bp = (PULONG)Base; - MP_FLOATING_POINTER* mpf; - - while (Size > 0) - { - if (*bp == MPF_SIGNATURE) - { - DbgPrint("Found MPF signature at %x, checksum %x\n", bp, - MPChecksum((PUCHAR)bp, 16)); - if (MPChecksum((PUCHAR)bp, 16) == 0) - { - mpf = (MP_FLOATING_POINTER*)bp; - - DbgPrint("Intel MultiProcessor Specification v1.%d compliant system.\n", - mpf->Specification); - - if (mpf->Feature2 & FEATURE2_IMCRP) { - APICMode = amPIC; - DPRINT("Running in IMCR and PIC compatibility mode.\n") - } else { - APICMode = amVWIRE; - DPRINT("Running in Virtual Wire compatibility mode.\n"); - } - - switch (mpf->Feature1) - { - case 0: - /* Non standard configuration */ - break; - case 1: - DPRINT("ISA\n"); - break; - case 2: - DPRINT("EISA with no IRQ8 chaining\n"); - break; - case 3: - DPRINT("EISA\n"); - break; - case 4: - DPRINT("MCA\n"); - break; - case 5: - DPRINT("ISA and PCI\n"); - break; - case 6: - DPRINT("EISA and PCI\n"); - break; - case 7: - DPRINT("MCA and PCI\n"); - break; - default: - DbgPrint("Unknown standard configuration %d\n", mpf->Feature1); - return FALSE; - } - - CPUCount = 0; - IOAPICCount = 0; - IRQCount = 0; - - if ((mpf->Feature1 == 0) && (mpf->Address)) { - HaliReadMPConfigTable((PMP_CONFIGURATION_TABLE)mpf->Address); - } else { - HaliConstructDefaultISAMPTable(mpf->Feature1); - } - - return TRUE; - } - } - bp += 4; - Size -= 16; - } - return FALSE; -} - - -VOID -HalpInitMPS( - VOID) -{ - USHORT EBDA; - ULONG CPU; - - /* Only initialize MP system once. Once called the first time, - each subsequent call is part of the initialization sequence - for an application processor. */ - if (MPSInitialized) { - CPU = ThisCPU(); - - DPRINT("CPU %d says it is now booted.\n", CPU); - - APICSetup(); - APICCalibrateTimer(CPU); - - /* This processor is now booted */ - CPUMap[CPU].Flags |= CPU_ENABLED; - OnlineCPUs |= (1 << CPU); - - return; - } - - MPSInitialized = TRUE; - - /* - Scan the system memory for an MP configuration table - 1) Scan the first KB of system base memory - 2) Scan the last KB of system base memory - 3) Scan the BIOS ROM address space between 0F0000h and 0FFFFFh - 4) Scan the Extended BIOS Data Area - */ - - if (!HaliScanForMPConfigTable(0x0, 0x400)) { - if (!HaliScanForMPConfigTable(0x9FC00, 0x400)) { - if (!HaliScanForMPConfigTable(0xF0000, 0x10000)) { - EBDA = *((PUSHORT)0x040E); - EBDA <<= 4; - if (!HaliScanForMPConfigTable((ULONG)EBDA, 0x1000)) { - DbgPrint("No multiprocessor compliant system found.\n"); - KeBugCheck(0); - } - } - } - } - - /* Setup IRQ to vector translation map */ - memset(&IRQVectorMap, sizeof(IRQVectorMap), 0); - - /* Initialize the bootstrap processor */ - HaliInitBSP(); - - /* Setup I/O APIC */ - IOAPICSetup(); - - /* Setup busy waiting */ - HalpCalibrateStallExecution(); - - /* We can now enable interrupts */ - __asm__ __volatile__ ("sti\n\t"); - - NextCPU = 0; -} - -#endif /* MP */ - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/mps.S b/reactos/ntoskrnl/hal/x86/mps.S deleted file mode 100644 index c5a33cf2351..00000000000 --- a/reactos/ntoskrnl/hal/x86/mps.S +++ /dev/null @@ -1,76 +0,0 @@ -/* $Id: mps.S,v 1.1 2001/04/13 16:12:25 chorns Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/mps.S - * PURPOSE: Intel MultiProcessor specification support - * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net) - * UPDATE HISTORY: - * Created 12/04/2001 - */ - -/* INCLUDES ******************************************************************/ - -#include - -/* FUNCTIONS *****************************************************************/ - -#define BEFORE \ - pusha; \ - pushl %ds; \ - pushl %es; \ - pushl %fs; \ - pushl %gs; \ - movl $(KERNEL_DS), %eax; \ - movl %eax, %ds; \ - movl %eax, %es; \ - movl %eax, %gs; \ - movl $(PCR_SELECTOR), %eax; \ - movl %eax, %fs; - -#define AFTER \ - popl %gs; \ - popl %fs; \ - popl %es; \ - popl %ds; \ - popa; - -.globl _MpsTimerInterrupt -_MpsTimerInterrupt: - /* Save registers */ - BEFORE - - /* Call the C handler */ - call _MpsTimerHandler - - /* Return to the caller */ - AFTER - iret - - -.globl _MpsErrorInterrupt -_MpsErrorInterrupt: - /* Save registers */ - BEFORE - - /* Call the C handler */ - call _MpsErrorHandler - - /* Return to the caller */ - AFTER - iret - - -.globl _MpsSpuriousInterrupt -_MpsSpuriousInterrupt: - /* Save registers */ - BEFORE - - /* Call the C handler */ - call _MpsSpuriousHandler - - /* Return to the caller */ - AFTER - iret - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/mpsboot.asm b/reactos/ntoskrnl/hal/x86/mpsboot.asm deleted file mode 100644 index 684b69ab823..00000000000 --- a/reactos/ntoskrnl/hal/x86/mpsboot.asm +++ /dev/null @@ -1,106 +0,0 @@ -; -; COPYRIGHT: See COPYING in the top level directory -; PROJECT: ReactOS kernel -; FILE: ntoskrnl/hal/x86/mpsboot.c -; PURPOSE: Bootstrap code for application processors -; PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net) -; UPDATE HISTORY: -; Created 12/04/2001 -; - -; -; Memory map at this stage is: -; 0x2000 Location of our stack -; 0x3000 Startup code for the APs (this code) -; - -; -; Base address of common area for BSP and APs -; -LOAD_BASE equ 00200000h - -; -; Magic value to be put in EAX when multiboot.S is called as part of the -; application processor initialization process -; -AP_MAGIC equ 12481020h - -; -; Segment selectors -; -%define KERNEL_CS (0x8) -%define KERNEL_DS (0x10) - -section .text - -global _APstart -global _APend - -; 16 bit code -BITS 16 - -_APstart: - cli ; Just in case - - xor ax, ax - mov ds, ax - mov ss, ax - - mov eax, 3000h + APgdt - _APstart - lgdt [eax] - - mov eax, cr0 - or eax, 00010001h ; Turn on protected mode and write protection - mov cr0, eax - - db 0eah - dw 3000h + flush - _APstart, KERNEL_CS - -; 32 bit code -BITS 32 - -flush: - mov ax, KERNEL_DS - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - - ; Setup a stack for the AP - mov eax, 2000h - mov eax, [eax] - mov esp, eax - - ; Jump to start of the kernel with AP magic in eax - mov eax, AP_MAGIC - jmp dword KERNEL_CS:(LOAD_BASE + 0x1000) - - ; Never get here - - -; Temporary GDT descriptor for the APs - -APgdt: -; Limit - dw (3*8)-1 -; Base - dd 3000h + gdt - _APstart - -gdt: - dw 0x0 ; Null descriptor - dw 0x0 - dw 0x0 - dw 0x0 - - dw 0xffff ; Kernel code descriptor - dw 0x0000 - dw 0x9a00 - dw 0x00cf - - dw 0xffff ; Kernel data descriptor - dw 0x0000 - dw 0x9200 - dw 0x00cf - -_APend: diff --git a/reactos/ntoskrnl/hal/x86/mpsirql.c b/reactos/ntoskrnl/hal/x86/mpsirql.c deleted file mode 100644 index 0a619162331..00000000000 --- a/reactos/ntoskrnl/hal/x86/mpsirql.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/mpsirql.c - * PURPOSE: Implements IRQLs for multiprocessor systems - * PROGRAMMERS: David Welch (welch@cwcom.net) - * Casper S. Hornstrup (chorns@users.sourceforge.net) - * UPDATE HISTORY: - * 12/04/2001 CSH Created - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include -#include - -#define NDEBUG -#include - -/* GLOBALS ******************************************************************/ - -extern ULONG DpcQueueSize; - -static VOID KeSetCurrentIrql(KIRQL newlvl); - -/* FUNCTIONS ****************************************************************/ - -#define IRQL2TPR(irql) (APIC_TPR_MIN + ((irql - DISPATCH_LEVEL - 1) * 8)) - -static VOID HiSetCurrentPriority( - ULONG Priority) -{ - //DbgPrint(" P(0x%X)\n", Priority); - APICWrite(APIC_TPR, Priority & APIC_TPR_PRI); -} - - -static VOID HiSwitchIrql(KIRQL OldIrql, ULONG Flags) -/* - * FUNCTION: Switches to the current irql - * NOTE: Must be called with interrupt disabled - */ -{ - PKTHREAD CurrentThread; - KIRQL CurrentIrql; - - //DbgPrint("HiSwitchIrql(OldIrql %d)\n", OldIrql); - - CurrentIrql = KeGetCurrentKPCR()->Irql; - - if (CurrentIrql >= IPI_LEVEL) - { - /* Block all interrupts */ - HiSetCurrentPriority(APIC_TPR_MAX); - return; - } - - if (CurrentIrql == CLOCK2_LEVEL) - { - HiSetCurrentPriority(APIC_TPR_MAX - 16); - popfl(Flags); - return; - } - - if (CurrentIrql > DISPATCH_LEVEL) - { - HiSetCurrentPriority(IRQL2TPR(CurrentIrql)); - popfl(Flags); - return; - } - - /* Pass all interrupts */ - HiSetCurrentPriority(0); - - if (CurrentIrql == DISPATCH_LEVEL) - { - popfl(Flags); - return; - } - - if (CurrentIrql == APC_LEVEL) - { - if (DpcQueueSize > 0 ) - { - KeSetCurrentIrql(DISPATCH_LEVEL); - __asm__("sti\n\t"); - KiDispatchInterrupt(); - __asm__("cli\n\t"); - KeSetCurrentIrql(PASSIVE_LEVEL); - } - popfl(Flags); - return; - } - - CurrentThread = KeGetCurrentThread(); - - if (CurrentIrql == PASSIVE_LEVEL && - CurrentThread != NULL && - CurrentThread->ApcState.KernelApcPending) - { - KeSetCurrentIrql(APC_LEVEL); - __asm__("sti\n\t"); - KiDeliverApc(0, 0, 0); - __asm__("cli\n\t"); - KeSetCurrentIrql(PASSIVE_LEVEL); - popfl(Flags); - } - else - { - popfl(Flags); - } -} - - -KIRQL STDCALL KeGetCurrentIrql (VOID) -/* - * PURPOSE: Returns the current irq level - * RETURNS: The current irq level - */ -{ - return(KeGetCurrentKPCR()->Irql); -} - - -static VOID KeSetCurrentIrql(KIRQL newlvl) -/* - * PURPOSE: Sets the current irq level without taking any action - */ -{ -// DPRINT("KeSetCurrentIrql(newlvl %x)\n",newlvl); - - KeGetCurrentKPCR()->Irql = newlvl; -} - - -/********************************************************************** - * NAME EXPORTED - * KfLowerIrql - * - * DESCRIPTION - * Restores the irq level on the current processor - * - * ARGUMENTS - * NewIrql = Irql to lower to - * - * RETURN VALUE - * None - * - * NOTES - * Uses fastcall convention - */ - -VOID FASTCALL -KfLowerIrql ( - KIRQL NewIrql - ) -{ - KIRQL CurrentIrql; - KIRQL OldIrql; - ULONG Flags; - - //DbgPrint("KfLowerIrql(NewIrql %d)\n", NewIrql); - - pushfl(Flags); - __asm__ ("\n\tcli\n\t"); - - CurrentIrql = KeGetCurrentKPCR()->Irql; - - if (NewIrql > CurrentIrql) - { - DbgPrint ("(%s:%d) NewIrql %x CurrentIrql %x\n", - __FILE__, __LINE__, NewIrql, CurrentIrql); - KeBugCheck(0); - for(;;); - } - - OldIrql = CurrentIrql; - KeGetCurrentKPCR()->Irql = NewIrql; - HiSwitchIrql(OldIrql, Flags); -} - - -/********************************************************************** - * NAME EXPORTED - * KeLowerIrql - * - * DESCRIPTION - * Restores the irq level on the current processor - * - * ARGUMENTS - * NewIrql = Irql to lower to - * - * RETURN VALUE - * None - * - * NOTES - */ - -VOID -STDCALL -KeLowerIrql ( - KIRQL NewIrql - ) -{ - KfLowerIrql (NewIrql); -} - - -/********************************************************************** - * NAME EXPORTED - * KfRaiseIrql - * - * DESCRIPTION - * Raises the hardware priority (irql) - * - * ARGUMENTS - * NewIrql = Irql to raise to - * - * RETURN VALUE - * previous irq level - * - * NOTES - * Uses fastcall convention - */ - -KIRQL -FASTCALL -KfRaiseIrql ( - KIRQL NewIrql - ) -{ - KIRQL CurrentIrql; - KIRQL OldIrql; - ULONG Flags; - - //DbgPrint("KfRaiseIrql(NewIrql %d)\n", NewIrql); - - pushfl(Flags); - __asm__ ("\n\tcli\n\t"); - - CurrentIrql = KeGetCurrentKPCR()->Irql; - - if (NewIrql < CurrentIrql) - { - DbgPrint ("%s:%d CurrentIrql %x NewIrql %x\n", - __FILE__,__LINE__,CurrentIrql,NewIrql); - KeBugCheck (0); - for(;;); - } - - OldIrql = CurrentIrql; - KeGetCurrentKPCR()->Irql = NewIrql; - - //DPRINT("NewIrql %x OldIrql %x\n", NewIrql, OldIrql); - HiSwitchIrql(OldIrql, Flags); - return OldIrql; -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrql - * - * DESCRIPTION - * Raises the hardware priority (irql) - * - * ARGUMENTS - * NewIrql = Irql to raise to - * OldIrql (OUT) = Caller supplied storage for the previous irql - * - * RETURN VALUE - * None - * - * NOTES - * Calls KfRaiseIrql - */ - -VOID -STDCALL -KeRaiseIrql ( - KIRQL NewIrql, - PKIRQL OldIrql - ) -{ - *OldIrql = KfRaiseIrql (NewIrql); -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrqlToDpcLevel - * - * DESCRIPTION - * Raises the hardware priority (irql) to DISPATCH level - * - * ARGUMENTS - * None - * - * RETURN VALUE - * Previous irq level - * - * NOTES - * Calls KfRaiseIrql - */ - -KIRQL -STDCALL -KeRaiseIrqlToDpcLevel (VOID) -{ - return KfRaiseIrql (DISPATCH_LEVEL); -} - - -/********************************************************************** - * NAME EXPORTED - * KeRaiseIrqlToSynchLevel - * - * DESCRIPTION - * Raises the hardware priority (irql) to CLOCK2 level - * - * ARGUMENTS - * None - * - * RETURN VALUE - * Previous irq level - * - * NOTES - * Calls KfRaiseIrql - */ - -KIRQL -STDCALL -KeRaiseIrqlToSynchLevel (VOID) -{ - return KfRaiseIrql (CLOCK2_LEVEL); -} - - -BOOLEAN STDCALL HalBeginSystemInterrupt (ULONG Vector, - KIRQL Irql, - PKIRQL OldIrql) -{ - DPRINT("Vector (0x%X) Irql (0x%X)\n", - Vector, Irql); - - if (Vector < FIRST_DEVICE_VECTOR || - Vector > FIRST_DEVICE_VECTOR + NUMBER_DEVICE_VECTORS) { - DPRINT("Not a device interrupt\n"); - return FALSE; - } - - /* - * Acknowledge the interrupt - */ - APICSendEOI(); - - *OldIrql = KeGetCurrentIrql(); - - KeSetCurrentIrql(Irql); - - return TRUE; -} - - -VOID STDCALL HalEndSystemInterrupt (KIRQL Irql, - ULONG Unknown2) -{ - KeSetCurrentIrql(Irql); -} - - -BOOLEAN STDCALL HalDisableSystemInterrupt (ULONG Vector, - ULONG Unknown2) -{ - ULONG irq; - - DPRINT("Vector (0x%X)\n", Vector); - - if (Vector < FIRST_DEVICE_VECTOR || - Vector > FIRST_DEVICE_VECTOR + NUMBER_DEVICE_VECTORS) { - DPRINT("Not a device interrupt\n"); - return FALSE; - } - - irq = VECTOR2IRQ(Vector); - - IOAPICMaskIrq(0, irq); - - return TRUE; -} - - -BOOLEAN STDCALL HalEnableSystemInterrupt (ULONG Vector, - ULONG Unknown2, - ULONG Unknown3) -{ - ULONG irq; - - DPRINT("Vector (0x%X)\n", Vector); - - if (Vector < FIRST_DEVICE_VECTOR || - Vector > FIRST_DEVICE_VECTOR + NUMBER_DEVICE_VECTORS) { - DPRINT("Not a device interrupt\n"); - return FALSE; - } - - irq = VECTOR2IRQ(Vector); - - IOAPICUnmaskIrq(0, irq); - - return TRUE; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/parttab.c b/reactos/ntoskrnl/hal/x86/parttab.c deleted file mode 100644 index e7101043f20..00000000000 --- a/reactos/ntoskrnl/hal/x86/parttab.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $Id: parttab.c,v 1.4 2001/06/08 15:08:36 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/parttab.c (was ntoskrnl/io/fdisk.c) - * PURPOSE: Handling fixed disks (partition table functions) - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - * 2000-03-25 (ea) - * Moved here from ntoskrnl/io/fdisk.c - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -NTSTATUS STDCALL -IoReadPartitionTable(PDEVICE_OBJECT DeviceObject, - ULONG SectorSize, - BOOLEAN ReturnRecognizedPartitions, - PDRIVE_LAYOUT_INFORMATION *PartitionBuffer) -{ -#ifdef __NTOSKRNL__ - return HalDispatchTable.HalIoReadPartitionTable(DeviceObject, - SectorSize, - ReturnRecognizedPartitions, - PartitionBuffer); -#else - return HalDispatchTable->HalIoReadPartitionTable(DeviceObject, - SectorSize, - ReturnRecognizedPartitions, - PartitionBuffer); -#endif -} - - -NTSTATUS STDCALL -IoSetPartitionInformation(PDEVICE_OBJECT DeviceObject, - ULONG SectorSize, - ULONG PartitionNumber, - ULONG PartitionType) -{ -#ifdef __NTOSKRNL__ - return HalDispatchTable.HalIoSetPartitionInformation(DeviceObject, - SectorSize, - PartitionNumber, - PartitionType); -#else - return HalDispatchTable->HalIoSetPartitionInformation(DeviceObject, - SectorSize, - PartitionNumber, - PartitionType); -#endif -} - - -NTSTATUS STDCALL -IoWritePartitionTable(PDEVICE_OBJECT DeviceObject, - ULONG SectorSize, - ULONG SectorsPerTrack, - ULONG NumberOfHeads, - PDRIVE_LAYOUT_INFORMATION PartitionBuffer) -{ -#ifdef __NTOSKRNL__ - return HalDispatchTable.HalIoWritePartitionTable(DeviceObject, - SectorSize, - SectorsPerTrack, - NumberOfHeads, - PartitionBuffer); -#else - return HalDispatchTable->HalIoWritePartitionTable(DeviceObject, - SectorSize, - SectorsPerTrack, - NumberOfHeads, - PartitionBuffer); -#endif -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/pci.c b/reactos/ntoskrnl/hal/x86/pci.c deleted file mode 100644 index 3918d77e618..00000000000 --- a/reactos/ntoskrnl/hal/x86/pci.c +++ /dev/null @@ -1,494 +0,0 @@ -/* $Id: pci.c,v 1.7 2001/06/13 22:17:01 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/pci.c - * PURPOSE: Interfaces to the PCI bus - * PROGRAMMER: David Welch (welch@mcmail.com) - * Eric Kohl (ekohl@rz-online.de) - * UPDATE HISTORY: - * 05/06/1998: Created - * 17/08/2000: Added preliminary pci bus scanner - * 13/06/2001: Implemented access to pci configuration space - */ - -/* - * NOTES: Sections copied from the Linux pci support - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - -#define NDEBUG -#include - - -/* MACROS ******************************************************************/ - -/* access type 1 macros */ -#define PCI_FUNC(devfn) \ - ((devfn) & 0x07) -#define CONFIG_CMD(bus, device_fn, where) \ - (0x80000000 | (bus << 16) | (device_fn << 8) | (where & ~3)) - -/* access type 2 macros */ -#define IOADDR(devfn, where) \ - ((0xC000 | ((devfn & 0x78) << 5)) + where) -#define FUNC(devfn) \ - (((devfn & 7) << 1) | 0xf0) - - -#define PCIBIOS_SUCCESSFUL 0x00 -#define PCIBIOS_DEVICE_NOT_FOUND 0x86 -#define PCIBIOS_BAD_REGISTER_NUMBER 0x87 - - -/* GLOBALS ******************************************************************/ - -static ULONG BusConfigType = 0; /* undetermined config type */ - - -/* FUNCTIONS ****************************************************************/ - -static NTSTATUS -ReadPciConfigUchar(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - PUCHAR Value) -{ - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - *Value = READ_PORT_UCHAR((PUCHAR)0xCFC + (Offset & 3)); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_UCHAR((PUCHAR)(IOADDR(Slot, Offset))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static NTSTATUS -ReadPciConfigUshort(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - PUSHORT Value) -{ - if ((Offset & 1) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - *Value = READ_PORT_USHORT((PUSHORT)0xCFC + (Offset & 1)); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_USHORT((PUSHORT)(IOADDR(Slot, Offset))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static NTSTATUS -ReadPciConfigUlong(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - PULONG Value) -{ - if ((Offset & 3) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - *Value = READ_PORT_ULONG((PULONG)0xCFC); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_ULONG((PULONG)(IOADDR(Slot, Offset))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static NTSTATUS -WritePciConfigUchar(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - UCHAR Value) -{ - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - WRITE_PORT_UCHAR((PUCHAR)0xCFC + (Offset&3), Value); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - WRITE_PORT_UCHAR((PUCHAR)(IOADDR(Slot,Offset)), Value); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static NTSTATUS -WritePciConfigUshort(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - USHORT Value) -{ - if ((Offset & 1) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - WRITE_PORT_USHORT((PUSHORT)0xCFC + (Offset & 1), Value); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - WRITE_PORT_USHORT((PUSHORT)(IOADDR(Slot, Offset)), Value); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static NTSTATUS -WritePciConfigUlong(UCHAR Bus, - UCHAR Slot, - UCHAR Offset, - ULONG Value) -{ - if ((Offset & 3) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - switch (BusConfigType) - { - case 1: - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); - WRITE_PORT_ULONG((PULONG)0xCFC, Value); - return STATUS_SUCCESS; - - case 2: - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - WRITE_PORT_ULONG((PULONG)(IOADDR(Slot, Offset)), Value); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; -} - - -static ULONG STDCALL -HalpGetPciData(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PVOID Ptr = Buffer; - ULONG Address = Offset; - ULONG Len = Length; - ULONG Vendor; - UCHAR HeaderType; - - DPRINT("HalpGetPciData() called.\n"); - DPRINT(" BusNumber %lu\n", BusNumber); - DPRINT(" SlotNumber %lu\n", SlotNumber); - DPRINT(" Offset 0x%lx\n", Offset); - DPRINT(" Length 0x%lx\n", Length); - - if ((Length == 0) || (BusConfigType == 0)) - return 0; - - /* 0E=PCI_HEADER_TYPE */ - ReadPciConfigUchar(BusNumber, - SlotNumber & 0xF8, - 0x0E, - &HeaderType); - if (((HeaderType & 0x80) == 0) && ((SlotNumber & 0x07) != 0)) - return 0; - - ReadPciConfigUlong(BusNumber, - SlotNumber, - 0x00, - &Vendor); - /* some broken boards return 0 if a slot is empty: */ - if (Vendor == 0xFFFFFFFF || Vendor == 0) - return 0; - - if ((Address & 1) && (Len >= 1)) - { - ReadPciConfigUchar(BusNumber, - SlotNumber, - Address, - Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - - if ((Address & 2) && (Len >= 2)) - { - ReadPciConfigUshort(BusNumber, - SlotNumber, - Address, - Ptr); - Ptr = Ptr + 2; - Address += 2; - Len -= 2; - } - - while (Len >= 4) - { - ReadPciConfigUlong(BusNumber, - SlotNumber, - Address, - Ptr); - Ptr = Ptr + 4; - Address += 4; - Len -= 4; - } - - if (Len >= 2) - { - ReadPciConfigUshort(BusNumber, - SlotNumber, - Address, - Ptr); - Ptr = Ptr + 2; - Address += 2; - Len -= 2; - } - - if (Len >= 1) - { - ReadPciConfigUchar(BusNumber, - SlotNumber, - Address, - Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - - return Length - Len; -} - - -static ULONG STDCALL -HalpSetPciData(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PVOID Ptr = Buffer; - ULONG Address = Offset; - ULONG Len = Length; - ULONG Vendor; - UCHAR HeaderType; - - DPRINT("HalpSetPciData() called.\n"); - DPRINT(" BusNumber %lu\n", BusNumber); - DPRINT(" SlotNumber %lu\n", SlotNumber); - DPRINT(" Offset 0x%lx\n", Offset); - DPRINT(" Length 0x%lx\n", Length); - - if ((Length == 0) || (BusConfigType == 0)) - return 0; - - /* 0E=PCI_HEADER_TYPE */ - ReadPciConfigUchar(BusNumber, - SlotNumber & 0xF8, - 0x0E, - &HeaderType); - if (((HeaderType & 0x80) == 0) && ((SlotNumber & 0x07) != 0)) - return 0; - - ReadPciConfigUlong(BusNumber, - SlotNumber, - 0x00, - &Vendor); - /* some broken boards return 0 if a slot is empty: */ - if (Vendor == 0xFFFFFFFF || Vendor == 0) - return 0; - - if ((Address & 1) && (Len >= 1)) - { - WritePciConfigUchar(BusNumber, - SlotNumber, - Address, - *(PUCHAR)Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - - if ((Address & 2) && (Len >= 2)) - { - WritePciConfigUshort(BusNumber, - SlotNumber, - Address, - *(PUSHORT)Ptr); - Ptr = Ptr + 2; - Address += 2; - Len -= 2; - } - - while (Len >= 4) - { - WritePciConfigUlong(BusNumber, - SlotNumber, - Address, - *(PULONG)Ptr); - Ptr = Ptr + 4; - Address += 4; - Len -= 4; - } - - if (Len >= 2) - { - WritePciConfigUshort(BusNumber, - SlotNumber, - Address, - *(PUSHORT)Ptr); - Ptr = Ptr + 2; - Address += 2; - Len -= 2; - } - - if (Len >= 1) - { - WritePciConfigUchar(BusNumber, - SlotNumber, - Address, - *(PUCHAR)Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - - return Length - Len; -} - - -static ULONG -GetBusConfigType(VOID) -{ - ULONG Value; - - DPRINT("GetBusConfigType() called\n"); - - DPRINT("Checking configuration type 1:"); - WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x01); - Value = READ_PORT_ULONG((PULONG)0xCF8); - WRITE_PORT_ULONG((PULONG)0xCF8, 0x80000000); - if (READ_PORT_ULONG((PULONG)0xCF8) == 0x80000000) - { - WRITE_PORT_ULONG((PULONG)0xCF8, Value); - DPRINT(" Success!\n"); - return 1; - } - WRITE_PORT_ULONG((PULONG)0xCF8, Value); - DPRINT(" Unsuccessful!\n"); - - DPRINT("Checking configuration type 2:"); - WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x00); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0x00); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, 0x00); - if (READ_PORT_UCHAR((PUCHAR)0xCF8) == 0x00 && - READ_PORT_UCHAR((PUCHAR)0xCFB) == 0x00) - { - DPRINT(" Success!\n"); - return 2; - } - DPRINT(" Unsuccessful!\n"); - - DPRINT("No pci bus found!\n"); - return 0; -} - - -VOID HalpInitPciBus (VOID) -{ - PBUS_HANDLER BusHandler; - - DPRINT("HalpInitPciBus() called.\n"); - - BusConfigType = GetBusConfigType(); - if (BusConfigType == 0) - return; - - DPRINT("Bus configuration %lu used\n", BusConfigType); - - /* pci bus (bus 0) handler */ - BusHandler = HalpAllocateBusHandler(PCIBus, - PCIConfiguration, - 0); - BusHandler->GetBusData = (pGetSetBusData)HalpGetPciData; - BusHandler->SetBusData = (pGetSetBusData)HalpSetPciData; -// BusHandler->GetInterruptVector = -// (pGetInterruptVector)HalpGetPciInterruptVector; -// BusHandler->AdjustResourceList = -// (pGetSetBusData)HalpAdjustPciResourceList; -// BusHandler->AssignSlotResources = -// (pGetSetBusData)HalpAssignPciSlotResources; - - - /* agp bus (bus 1) handler */ - BusHandler = HalpAllocateBusHandler(PCIBus, - PCIConfiguration, - 1); - BusHandler->GetBusData = (pGetSetBusData)HalpGetPciData; - BusHandler->SetBusData = (pGetSetBusData)HalpSetPciData; -// BusHandler->GetInterruptVector = -// (pGetInterruptVector)HalpGetPciInterruptVector; -// BusHandler->AdjustResourceList = -// (pGetSetBusData)HalpAdjustPciResourceList; -// BusHandler->AssignSlotResources = -// (pGetSetBusData)HalpAssignPciSlotResources; - - DPRINT("HalpInitPciBus() finished.\n"); -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/perfcnt.c b/reactos/ntoskrnl/hal/x86/perfcnt.c deleted file mode 100644 index 6154edc0123..00000000000 --- a/reactos/ntoskrnl/hal/x86/perfcnt.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $Id: perfcnt.c,v 1.2 2001/01/14 15:36:55 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/perfcnt.c - * PURPOSE: Performance counter functions - * PROGRAMMER: David Welch (welch@mcmail.com) - * Eric Kohl (ekohl@rz-online.de) - * UPDATE HISTORY: - * 09/06/2000: Created - */ - - -/* INCLUDES ***************************************************************/ - -#include - -/* FUNCTIONS **************************************************************/ - - -VOID STDCALL -HalCalibratePerformanceCounter(ULONG Count) -{ - ULONG i; - - /* save flags and disable interrupts */ - __asm__("pushf\n\t" \ - "cli\n\t"); - - for (i = 0; i < Count; i++); - - /* restore flags */ - __asm__("popf\n\t"); -} - - -LARGE_INTEGER STDCALL -KeQueryPerformanceCounter(PLARGE_INTEGER PerformanceFreq) -/* - * FUNCTION: Queries the finest grained running count avaiable in the system - * ARGUMENTS: - * PerformanceFreq (OUT) = The routine stores the number of - * performance counters tick per second here - * RETURNS: The performance counter value in HERTZ - * NOTE: Returns the system tick count or the time-stamp on the pentium - */ -{ - if (PerformanceFreq != NULL) - { - PerformanceFreq->QuadPart = 0; - } - - return *PerformanceFreq; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/portio.c b/reactos/ntoskrnl/hal/x86/portio.c deleted file mode 100644 index 65671c8e491..00000000000 --- a/reactos/ntoskrnl/hal/x86/portio.c +++ /dev/null @@ -1,182 +0,0 @@ -/* $Id: portio.c,v 1.5 2000/10/08 23:44:45 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/portio.c - * PURPOSE: Port I/O functions - * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) - * UPDATE HISTORY: - * Created 18/10/99 - */ - -#include - - -/* FUNCTIONS ****************************************************************/ - -/* - * This file contains the definitions for the x86 IO instructions - * inb/inw/inl/outb/outw/outl and the "string versions" of the same - * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing" - * versions of the single-IO instructions (inb_p/inw_p/..). - * - * This file is not meant to be obfuscating: it's just complicated - * to (a) handle it all in a way that makes gcc able to optimize it - * as well as possible and (b) trying to avoid writing the same thing - * over and over again with slight variations and possibly making a - * mistake somewhere. - */ - -/* - * Thanks to James van Artsdalen for a better timing-fix than - * the two short jumps: using outb's to a nonexistent port seems - * to guarantee better timings even on fast machines. - * - * On the other hand, I'd like to be sure of a non-existent port: - * I feel a bit unsafe about using 0x80 (should be safe, though) - * - * Linus - */ - -#ifdef SLOW_IO_BY_JUMPING -#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:") -#else -#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80") -#endif - -#ifdef REALLY_SLOW_IO -#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; } -#else -#define SLOW_DOWN_IO __SLOW_DOWN_IO -#endif - -VOID STDCALL -READ_PORT_BUFFER_UCHAR (PUCHAR Port, - PUCHAR Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; insb\n\t" - : "=D" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -VOID STDCALL -READ_PORT_BUFFER_USHORT (PUSHORT Port, - PUSHORT Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; insw" - : "=D" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -VOID STDCALL -READ_PORT_BUFFER_ULONG (PULONG Port, - PULONG Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; insl" - : "=D" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -UCHAR STDCALL -READ_PORT_UCHAR (PUCHAR Port) -{ - UCHAR Value; - - __asm__("inb %w1, %0\n\t" - : "=a" (Value) - : "d" (Port)); - SLOW_DOWN_IO; - return(Value); -} - -USHORT STDCALL -READ_PORT_USHORT (PUSHORT Port) -{ - USHORT Value; - - __asm__("inw %w1, %0\n\t" - : "=a" (Value) - : "d" (Port)); - SLOW_DOWN_IO; - return(Value); -} - -ULONG STDCALL -READ_PORT_ULONG (PULONG Port) -{ - ULONG Value; - - __asm__("inl %w1, %0\n\t" - : "=a" (Value) - : "d" (Port)); - SLOW_DOWN_IO; - return(Value); -} - -VOID STDCALL -WRITE_PORT_BUFFER_UCHAR (PUCHAR Port, - PUCHAR Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; outsb" - : "=S" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -VOID STDCALL -WRITE_PORT_BUFFER_USHORT (PUSHORT Port, - PUSHORT Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; outsw" - : "=S" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -VOID STDCALL -WRITE_PORT_BUFFER_ULONG (PULONG Port, - PULONG Buffer, - ULONG Count) -{ - __asm__ __volatile__ ("cld ; rep ; outsl" - : "=S" (Buffer), "=c" (Count) - : "d" (Port),"0" (Buffer),"1" (Count)); -} - -VOID STDCALL -WRITE_PORT_UCHAR (PUCHAR Port, - UCHAR Value) -{ - __asm__("outb %0, %w1\n\t" - : - : "a" (Value), - "d" (Port)); - SLOW_DOWN_IO; -} - -VOID STDCALL -WRITE_PORT_USHORT (PUSHORT Port, - USHORT Value) -{ - __asm__("outw %0, %w1\n\t" - : - : "a" (Value), - "d" (Port)); - SLOW_DOWN_IO; -} - -VOID STDCALL -WRITE_PORT_ULONG (PULONG Port, - ULONG Value) -{ - __asm__("outl %0, %w1\n\t" - : - : "a" (Value), - "d" (Port)); - SLOW_DOWN_IO; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/pwroff.c b/reactos/ntoskrnl/hal/x86/pwroff.c deleted file mode 100644 index 1cbb5affd7f..00000000000 --- a/reactos/ntoskrnl/hal/x86/pwroff.c +++ /dev/null @@ -1,114 +0,0 @@ -/* $Id: pwroff.c,v 1.1 2000/03/26 19:38:19 ea Exp $ - * - * FILE : reactos/hal/x86/apm.c - * DESCRIPTION: Turn CPU off... - * PROJECT : ReactOS Operating System - * AUTHOR : D. Lindauer (July 11 1997) - * NOTE : This program is public domain - * REVISIONS : - * 1999-12-26 - */ - -#define APM_FUNCTION_AVAILABLE 0x5300 -#define APM_FUNCTION_CONNREAL 0x5301 -#define APM_FUNCTION_POWEROFF 0x5307 -#define APM_FUNCTION_ENABLECPU 0x530d -#define APM_FUNCTION_ENABLEAPM 0x530e - -#define APM_DEVICE_BIOS 0 -#define APM_DEVICE_ALL 1 - -#define APM_MODE_DISABLE 0 -#define APM_MODE_ENABLE 1 - - - -nopm db 'No power management functionality',10,13,'$' -errmsg db 'Power management error',10,13,'$' -wrongver db 'Need APM version 1.1 or better',10,13,'$' -; -; Entry point -; -go: - mov dx,offset nopm - jc error - cmp ax,101h ; See if version 1.1 or greater - mov dx,offset wrongver - jc error - - mov [ver],ax - mov ax,5301h ; Do a real mode connection - mov bx,0 ; device = BIOS - int 15h - jnc noconerr - - cmp ah,2 ; Pass if already connected - mov dx,offset errmsg ; else error - jnz error -noconerr: - mov ax,530eh ; Enable latest version of APM - mov bx,0 ; device = BIOS - mov cx,[ver] ; version - int 15h - mov dx,offset errmsg - jc error - - mov ax,530dh ; Now engage and enable CPU management - mov bx,1 ; device = all - mov cx,1 ; enable - int 15h - mov dx,offset errmsg - jc error - - mov ax,530fh - mov bx,1 ; device = ALL - mov cx,1 ; enable - int 15h - mov dx,offset errmsg - jc error - - mov dx,offset errmsg -error: - call print - mov ax,4c01h - int 21h - int 3 - end start - - -BOOLEAN -ApmCall ( - DWORD Function, - DWORD Device, - DWORD Mode - ) -{ - /* AX <== Function */ - /* BX <== Device */ - /* CX <== Mode */ - __asm__("int 21\n"); /* 0x15 */ -} - - -BOOLEAN -HalPowerOff (VOID) -{ - ApmCall ( - APM_FUNCTION_AVAILABLE, - APM_DEVICE_BIOS, - 0 - ); - ApmCall ( - APM_FUNCTION_ENABLEAPM, - ); - /* Shutdown CPU */ - ApmCall ( - APM_FUNCTION_POWEROFF, - APM_DEVICE_ALL, - 3 - ); - return TRUE; -} - - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/reboot.c b/reactos/ntoskrnl/hal/x86/reboot.c deleted file mode 100644 index 2e8ccf28195..00000000000 --- a/reactos/ntoskrnl/hal/x86/reboot.c +++ /dev/null @@ -1,74 +0,0 @@ -/* $Id: reboot.c,v 1.7 2001/03/16 18:11:21 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/reboot.c - * PURPOSE: Reboot functions. - * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) - * UPDATE HISTORY: - * Created 11/10/99 - */ - - -#include -#include - - -static VOID -HalReboot (VOID) -{ - char data; - BYTE *mem; - - /* enable warm reboot */ - mem = (BYTE *)(0xd0000000 + 0x0000); -// mem = HalMapPhysicalMemory (0, 1); - mem[0x472] = 0x34; - mem[0x473] = 0x12; - - /* disable interrupts */ - __asm__("cli\n"); - - /* disable periodic interrupt (RTC) */ - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0b); - data = READ_PORT_UCHAR((PUCHAR)0x71); - WRITE_PORT_UCHAR((PUCHAR)0x71, data & 0xbf); - - /* */ - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0a); - data = READ_PORT_UCHAR((PUCHAR)0x71); - WRITE_PORT_UCHAR((PUCHAR)0x71, (data & 0xf0) | 0x06); - - /* */ - WRITE_PORT_UCHAR((PUCHAR)0x70, 0x15); - - /* generate RESET signal via keyboard controller */ - WRITE_PORT_UCHAR((PUCHAR)0x64, 0xfe); - - /* stop the processor */ -#if 1 - __asm__("hlt\n"); -#else - for(;;); -#endif -} - - -VOID STDCALL -HalReturnToFirmware ( - ULONG Action - ) -{ - if (Action == FIRMWARE_HALT) - { - DbgPrint ("HalReturnToFirmware called!\n"); - DbgBreakPoint (); - } - else if (Action == FIRMWARE_REBOOT) - { - HalResetDisplay (); - HalReboot (); - } -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/sources b/reactos/ntoskrnl/hal/x86/sources deleted file mode 100644 index e42f3afa07c..00000000000 --- a/reactos/ntoskrnl/hal/x86/sources +++ /dev/null @@ -1,40 +0,0 @@ -OBJECTS_HAL_COMMON = \ - hal/x86/adapter.o \ - hal/x86/beep.o \ - hal/x86/bios32.o \ - hal/x86/bus.o \ - hal/x86/display.o \ - hal/x86/dma.o \ - hal/x86/drive.o \ - hal/x86/enum.o \ - hal/x86/fmutex.o \ - hal/x86/halinit.o \ - hal/x86/isa.o \ - hal/x86/kdbg.o \ - hal/x86/mbr.o \ - hal/x86/misc.o \ - hal/x86/mp.o \ - hal/x86/parttab.o \ - hal/x86/pci.o \ - hal/x86/perfcnt.o \ - hal/x86/portio.o \ - hal/x86/reboot.o \ - hal/x86/spinlock.o \ - hal/x86/sysbus.o \ - hal/x86/sysinfo.o \ - hal/x86/time.o \ - hal/x86/udelay.o - -OBJECTS_HAL_UP = \ - hal/x86/irql.o - -OBJECTS_HAL_MP = \ - hal/x86/mps.o \ - hal/x86/mpsboot.o \ - hal/x86/mpsirql.o - -ifeq ($(MP), 1) -OBJECTS_HAL = $(OBJECTS_HAL_COMMON) $(OBJECTS_HAL_MP) -else -OBJECTS_HAL = $(OBJECTS_HAL_COMMON) $(OBJECTS_HAL_UP) -endif diff --git a/reactos/ntoskrnl/hal/x86/spinlock.c b/reactos/ntoskrnl/hal/x86/spinlock.c deleted file mode 100644 index 5751d349f06..00000000000 --- a/reactos/ntoskrnl/hal/x86/spinlock.c +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id: spinlock.c,v 1.12 2000/10/07 13:41:50 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/spinlock.c - * PURPOSE: Implements spinlocks - * PROGRAMMER: David Welch (welch@cwcom.net) - * Eric Kohl (ekohl@rz-online.de) - * UPDATE HISTORY: - * 09/06/2000 Created - */ - -/* - * NOTE: On a uniprocessor machine spinlocks are implemented by raising - * the irq level - */ - -/* INCLUDES ****************************************************************/ - -#include - -#include - -/* FUNCTIONS ***************************************************************/ - -VOID STDCALL -KeAcquireSpinLock ( - PKSPIN_LOCK SpinLock, - PKIRQL OldIrql - ) -/* - * FUNCTION: Acquires a spinlock - * ARGUMENTS: - * SpinLock = Spinlock to acquire - * OldIrql (OUT) = Caller supplied storage for the previous irql - */ -{ - KeRaiseIrql(DISPATCH_LEVEL,OldIrql); - KeAcquireSpinLockAtDpcLevel(SpinLock); -} - -KIRQL FASTCALL -KeAcquireSpinLockRaiseToSynch ( - PKSPIN_LOCK SpinLock - ) -{ - UNIMPLEMENTED; -} - -VOID STDCALL -KeReleaseSpinLock ( - PKSPIN_LOCK SpinLock, - KIRQL NewIrql - ) -/* - * FUNCTION: Releases a spinlock - * ARGUMENTS: - * SpinLock = Spinlock to release - * NewIrql = Irql level before acquiring the spinlock - */ -{ - KeReleaseSpinLockFromDpcLevel(SpinLock); - KeLowerIrql(NewIrql); -} - -KIRQL FASTCALL -KfAcquireSpinLock ( - PKSPIN_LOCK SpinLock - ) -{ - KIRQL OldIrql; - - KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); - KeAcquireSpinLockAtDpcLevel(SpinLock); - - return OldIrql; -} - -VOID FASTCALL -KfReleaseSpinLock ( - PKSPIN_LOCK SpinLock, - KIRQL NewIrql - ) -/* - * FUNCTION: Releases a spinlock - * ARGUMENTS: - * SpinLock = Spinlock to release - * NewIrql = Irql level before acquiring the spinlock - */ -{ - KeReleaseSpinLockFromDpcLevel(SpinLock); - KeLowerIrql(NewIrql); -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/sysbus.c b/reactos/ntoskrnl/hal/x86/sysbus.c deleted file mode 100644 index e955c72d72f..00000000000 --- a/reactos/ntoskrnl/hal/x86/sysbus.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $Id: sysbus.c,v 1.3 2001/06/13 22:17:01 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/sysbus.c - * PURPOSE: System bus handler functions - * PROGRAMMER: Eric Kohl (ekohl@rz-online.de) - * UPDATE HISTORY: - * 09/04/2000 Created - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - - -/* FUNCTIONS ****************************************************************/ - -ULONG STDCALL -HalpGetSystemInterruptVector(PVOID BusHandler, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity) -{ - *Irql = HIGH_LEVEL - BusInterruptVector; - *Affinity = 0xFFFFFFFF; - return BusInterruptVector; -} - - -BOOLEAN STDCALL -HalpTranslateSystemBusAddress(PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress) -{ - ULONG BaseAddress = 0; - - if (*AddressSpace == 0) - { - /* memory space */ - - } - else if (*AddressSpace == 1) - { - /* io space */ - - } - else - { - /* other */ - return FALSE; - } - - TranslatedAddress->QuadPart = BusAddress.QuadPart + BaseAddress; - - return TRUE; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/sysinfo.c b/reactos/ntoskrnl/hal/x86/sysinfo.c deleted file mode 100644 index 5d04be8449c..00000000000 --- a/reactos/ntoskrnl/hal/x86/sysinfo.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/sysinfo.c - * PURPOSE: Getting system information - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -VOID HalQuerySystemInformation() -{ - UNIMPLEMENTED; -} - diff --git a/reactos/ntoskrnl/hal/x86/time.c b/reactos/ntoskrnl/hal/x86/time.c deleted file mode 100644 index a6c4549bdde..00000000000 --- a/reactos/ntoskrnl/hal/x86/time.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/time.c - * PURPOSE: Getting time information - * UPDATE HISTORY: - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include - -//#define NDEBUG -#include - -/* MACROS and CONSTANTS ******************************************************/ - -/* macro BCD_INT : convert bcd to int */ -#define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f)) - -/* macro INT_BCD : convert int to bcd */ -#define INT_BCD(int) (((int / 10) << 4) + (int % 10)) - - -#define RTC_REGISTER_A 0x0A -#define RTC_REG_A_UIP 0x80 /* Update In Progress bit */ - -#define RTC_REGISTER_B 0x0B - -#define RTC_REGISTER_CENTURY 0x32 - - -/* FUNCTIONS *****************************************************************/ - - -static UCHAR -HalpQueryCMOS(UCHAR Reg) -{ - UCHAR Val; - ULONG Flags; - - Reg |= 0x80; - pushfl(Flags); - __asm__("cli\n"); // AP unsure as to whether to do this here - WRITE_PORT_UCHAR((PUCHAR)0x70, Reg); - Val = READ_PORT_UCHAR((PUCHAR)0x71); - WRITE_PORT_UCHAR((PUCHAR)0x70, 0); - popfl(Flags); - - return(Val); -} - - -static VOID -HalpSetCMOS(UCHAR Reg, - UCHAR Val) -{ - ULONG Flags; - - Reg |= 0x80; - pushfl(Flags); - __asm__("cli\n"); // AP unsure as to whether to do this here - WRITE_PORT_UCHAR((PUCHAR)0x70, Reg); - WRITE_PORT_UCHAR((PUCHAR)0x71, Val); - WRITE_PORT_UCHAR((PUCHAR)0x70, 0); - popfl(Flags); -} - - -static UCHAR -HalpQueryECMOS(USHORT Reg) -{ - UCHAR Val; - ULONG Flags; - - pushfl(Flags); - __asm__("cli\n"); // AP unsure as to whether to do this here - WRITE_PORT_UCHAR((PUCHAR)0x74, (UCHAR)(Reg & 0x00FF)); - WRITE_PORT_UCHAR((PUCHAR)0x75, (UCHAR)(Reg>>8)); - Val = READ_PORT_UCHAR((PUCHAR)0x76); - popfl(Flags); - - return(Val); -} - - -static VOID -HalpSetECMOS(USHORT Reg, - UCHAR Val) -{ - ULONG Flags; - - pushfl(Flags); - __asm__("cli\n"); // AP unsure as to whether to do this here - WRITE_PORT_UCHAR((PUCHAR)0x74, (UCHAR)(Reg & 0x00FF)); - WRITE_PORT_UCHAR((PUCHAR)0x75, (UCHAR)(Reg>>8)); - WRITE_PORT_UCHAR((PUCHAR)0x76, Val); - popfl(Flags); -} - - -VOID STDCALL -HalQueryRealTimeClock(PTIME_FIELDS Time) -{ - /* check 'Update In Progress' bit */ - while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP) - ; - - Time->Second = BCD_INT(HalpQueryCMOS (0)); - Time->Minute = BCD_INT(HalpQueryCMOS (2)); - Time->Hour = BCD_INT(HalpQueryCMOS (4)); - Time->Weekday = BCD_INT(HalpQueryCMOS (6)); - Time->Day = BCD_INT(HalpQueryCMOS (7)); - Time->Month = BCD_INT(HalpQueryCMOS (8)); - Time->Year = BCD_INT(HalpQueryCMOS (9)); - - if (Time->Year > 80) - Time->Year += 1900; - else - Time->Year += 2000; - -#if 0 - /* Century */ - Time->Year += BCD_INT(HalpQueryCMOS (RTC_REGISTER_CENTURY)) * 100; -#endif - -#ifndef NDEBUG - DbgPrint ("HalQueryRealTimeClock() %d:%d:%d %d/%d/%d\n", - Time->Hour, - Time->Minute, - Time->Second, - Time->Day, - Time->Month, - Time->Year - ); -#endif - - Time->Milliseconds = 0; -} - - -VOID STDCALL -HalSetRealTimeClock(PTIME_FIELDS Time) -{ - /* check 'Update In Progress' bit */ - while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP) - ; - - HalpSetCMOS (0, INT_BCD(Time->Second)); - HalpSetCMOS (2, INT_BCD(Time->Minute)); - HalpSetCMOS (4, INT_BCD(Time->Hour)); - HalpSetCMOS (6, INT_BCD(Time->Weekday)); - HalpSetCMOS (7, INT_BCD(Time->Day)); - HalpSetCMOS (8, INT_BCD(Time->Month)); - HalpSetCMOS (9, INT_BCD(Time->Year % 100)); - -#if 0 - /* Century */ - HalpSetCMOS (RTC_REGISTER_CENTURY, INT_BCD(Time->Year / 100)); -#endif -} - - -BOOLEAN STDCALL -HalGetEnvironmentVariable(PCH Name, - PCH Value, - USHORT ValueLength) -{ - if (_stricmp(Name, "LastKnownGood") != 0) - { - return FALSE; - } - - if (HalpQueryCMOS(RTC_REGISTER_B) & 0x01) - { - strncpy(Value, "FALSE", ValueLength); - } - else - { - strncpy(Value, "TRUE", ValueLength); - } - - return TRUE; -} - - -BOOLEAN STDCALL -HalSetEnvironmentVariable(PCH Name, - PCH Value) -{ - UCHAR Val; - - if (_stricmp(Name, "LastKnownGood") != 0) - return FALSE; - - Val = HalpQueryCMOS(RTC_REGISTER_B); - - if (_stricmp(Value, "TRUE") == 0) - HalpSetCMOS(RTC_REGISTER_B, Val | 0x01); - else if (_stricmp(Value, "FALSE") == 0) - HalpSetCMOS(RTC_REGISTER_B, Val & ~0x01); - else - return FALSE; - - return TRUE; -} - - -ULONG STDCALL -HalpGetCmosData(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PUCHAR Ptr = Buffer; - ULONG Address = SlotNumber; - ULONG Len = Length; - - DPRINT("HalpGetCmosData() called.\n"); - DPRINT(" BusNumber %lu\n", BusNumber); - DPRINT(" SlotNumber %lu\n", SlotNumber); - DPRINT(" Offset 0x%lx\n", Offset); - DPRINT(" Length 0x%lx\n", Length); - - if (Length == 0) - return 0; - - if (BusNumber == 0) - { - /* CMOS */ - while ((Len > 0) && (Address < 0x100)) - { - *Ptr = HalpQueryCMOS((UCHAR)Address); - Ptr = Ptr + 1; - Address++; - Len--; - } - } - else if (BusNumber == 1) - { - /* Extended CMOS */ - while ((Len > 0) && (Address < 0x1000)) - { - *Ptr = HalpQueryECMOS((USHORT)Address); - Ptr = Ptr + 1; - Address++; - Len--; - } - } - - return(Length - Len); -} - - -ULONG STDCALL -HalpSetCmosData(PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length) -{ - PUCHAR Ptr = (PUCHAR)Buffer; - ULONG Address = SlotNumber; - ULONG Len = Length; - - DPRINT("HalpSetCmosData() called.\n"); - DPRINT(" BusNumber %lu\n", BusNumber); - DPRINT(" SlotNumber %lu\n", SlotNumber); - DPRINT(" Offset 0x%lx\n", Offset); - DPRINT(" Length 0x%lx\n", Length); - - if (Length == 0) - return 0; - - if (BusNumber == 0) - { - /* CMOS */ - while ((Len > 0) && (Address < 0x100)) - { - HalpSetCMOS((UCHAR)Address, *Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - } - else if (BusNumber == 1) - { - /* Extended CMOS */ - while ((Len > 0) && (Address < 0x1000)) - { - HalpSetECMOS((USHORT)Address, *Ptr); - Ptr = Ptr + 1; - Address++; - Len--; - } - } - - return(Length - Len); -} - -/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/udelay.c b/reactos/ntoskrnl/hal/x86/udelay.c deleted file mode 100644 index d580c8aeff3..00000000000 --- a/reactos/ntoskrnl/hal/x86/udelay.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * ReactOS kernel - * Copyright (C) 2000 David Welch - * Copyright (C) 1999 Gareth Owen , Ramon von Handel - * Copyright (C) 1991, 1992 Linus Torvalds - * - * This software 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 software 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 software; see the file COPYING. If not, write - * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - * MA 02139, USA. - * - */ -/* $Id: udelay.c,v 1.9 2001/04/18 03:31:19 dwelch Exp $ - * - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/hal/x86/udelay.c - * PURPOSE: Busy waiting - * PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk) - * UPDATE HISTORY: - * 06/11/99 Created - */ - -/* INCLUDES ***************************************************************/ - -#include - -//#define NDEBUG -#include - -/* GLOBALS ******************************************************************/ - -static unsigned int delay_count = 1; - -#define MILLISEC (10) -#define FREQ (1000/MILLISEC) - -#define PRECISION (8) - -#define TMR_CTRL 0x43 /* I/O for control */ -#define TMR_CNT0 0x40 /* I/O for counter 0 */ -#define TMR_CNT1 0x41 /* I/O for counter 1 */ -#define TMR_CNT2 0x42 /* I/O for counter 2 */ - -#define TMR_SC0 0 /* Select channel 0 */ -#define TMR_SC1 0x40 /* Select channel 1 */ -#define TMR_SC2 0x80 /* Select channel 2 */ - -#define TMR_LOW 0x10 /* RW low byte only */ -#define TMR_HIGH 0x20 /* RW high byte only */ -#define TMR_BOTH 0x30 /* RW both bytes */ - -#define TMR_MD0 0 /* Mode 0 */ -#define TMR_MD1 0x2 /* Mode 1 */ -#define TMR_MD2 0x4 /* Mode 2 */ -#define TMR_MD3 0x6 /* Mode 3 */ -#define TMR_MD4 0x8 /* Mode 4 */ -#define TMR_MD5 0xA /* Mode 5 */ - -#define TMR_BCD 1 /* BCD mode */ - -#define TMR_LATCH 0 /* Latch command */ - -#define TMR_READ 0xF0 /* Read command */ -#define TMR_CNT 0x20 /* CNT bit (Active low, subtract it) */ -#define TMR_STAT 0x10 /* Status bit (Active low, subtract it) */ -#define TMR_CH2 0x8 /* Channel 2 bit */ -#define TMR_CH1 0x4 /* Channel 1 bit */ -#define TMR_CH0 0x2 /* Channel 0 bit */ - -static BOOLEAN UdelayCalibrated = FALSE; - -/* FUNCTIONS **************************************************************/ - -void init_pit(float h, unsigned char channel) -{ - unsigned int temp=0; - - temp = 1193180/h; - -// WRITE_PORT_UCHAR((PUCHAR)TMR_CTRL, -// (channel*0x40) + TMR_BOTH + TMR_MD3); - WRITE_PORT_UCHAR((PUCHAR)TMR_CTRL, - (channel*0x40) + TMR_BOTH + TMR_MD2); - WRITE_PORT_UCHAR((PUCHAR)(0x40+channel), - (unsigned char) temp); - WRITE_PORT_UCHAR((PUCHAR)(0x40+channel), - (unsigned char) (temp>>8)); -} - -VOID STDCALL -__KeStallExecutionProcessor(ULONG Loops) -{ - register unsigned int i; - for (i=0; i> 8); /* MSB */ - - /* Stage 1: Coarse calibration */ - - WaitFor8254Wraparound(); - - delay_count = 1; - - do { - delay_count <<= 1; /* Next delay count to try */ - - WaitFor8254Wraparound(); - - __KeStallExecutionProcessor(delay_count); /* Do the delay */ - - CurCount = Read8254Timer(); - } while (CurCount > LATCH / 2); - - delay_count >>= 1; /* Get bottom value for delay */ - - /* Stage 2: Fine calibration */ - DbgPrint("delay_count: %d", delay_count); - - 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(); - - __KeStallExecutionProcessor(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 */ - - DbgPrint("]\n"); - DbgPrint("delay_count: %d\n", delay_count); - DbgPrint("CPU speed: %d\n", delay_count/250); -#if 0 - DbgPrint("About to start delay loop test\n"); - DbgPrint("Waiting for five minutes..."); - for (i = 0; i < (5*60*1000*20); i++) - { - KeStallExecutionProcessor(50); - } - DbgPrint("finished\n"); - for(;;); -#endif -} - -/* EOF */