Migrate HL subsystem to C++
All checks were successful
Builds / ExectOS (amd64, release) (push) Successful in 28s
Builds / ExectOS (amd64, debug) (push) Successful in 30s
Builds / ExectOS (i686, debug) (push) Successful in 29s
Builds / ExectOS (i686, release) (push) Successful in 27s

This commit is contained in:
2025-09-13 19:15:13 +02:00
parent a2fe39defd
commit 4592955da1
41 changed files with 1279 additions and 795 deletions

View File

@@ -15,38 +15,38 @@
#include <amd64/xtstruct.h> #include <amd64/xtstruct.h>
/* HAL library routines forward references */ /* Hardware layer routines forward references */
XTCLINK XTCLINK
XTCDECL XTCDECL
UCHAR UCHAR
HlIoPortInByte(IN USHORT Port); HlReadPort8(IN USHORT Port);
XTCLINK
XTCDECL
ULONG
HlIoPortInLong(IN USHORT Port);
XTCLINK XTCLINK
XTCDECL XTCDECL
USHORT USHORT
HlIoPortInShort(IN USHORT Port); HlReadPort16(IN USHORT Port);
XTCLINK
XTCDECL
ULONG
HlReadPort32(IN USHORT Port);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutByte(IN USHORT Port, HlWritePort8(IN USHORT Port,
IN UCHAR Data); IN UCHAR Data);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutLong(IN USHORT Port, HlWritePort16(IN USHORT Port,
IN ULONG Value); IN USHORT Value);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutShort(IN USHORT Port, HlWritePort32(IN USHORT Port,
IN USHORT Value); IN ULONG Value);
#endif /* __XTDK_AMD64_HLFUNCS_H */ #endif /* __XTDK_AMD64_HLFUNCS_H */

View File

@@ -18,7 +18,7 @@
XTCLINK XTCLINK
XTCDECL XTCDECL
XTSTATUS XTSTATUS
HlComPortPutByte(IN PCPPORT Port, HlWriteComPort(IN PCPPORT Port,
IN UCHAR Byte); IN UCHAR Byte);
XTCLINK XTCLINK
@@ -28,6 +28,7 @@ HlInitializeComPort(IN OUT PCPPORT Port,
IN PUCHAR PortAddress, IN PUCHAR PortAddress,
IN ULONG BaudRate); IN ULONG BaudRate);
/* Hardware layer routines forward references */
XTCLINK XTCLINK
XTAPI XTAPI
UCHAR UCHAR

View File

@@ -15,38 +15,38 @@
#include <i686/xtstruct.h> #include <i686/xtstruct.h>
/* HAL library routines forward references */ /* Hardware layer routines forward references */
XTCLINK XTCLINK
XTCDECL XTCDECL
UCHAR UCHAR
HlIoPortInByte(IN USHORT Port); HlReadPort8(IN USHORT Port);
XTCLINK
XTCDECL
ULONG
HlIoPortInLong(IN USHORT Port);
XTCLINK XTCLINK
XTCDECL XTCDECL
USHORT USHORT
HlIoPortInShort(IN USHORT Port); HlReadPort16(IN USHORT Port);
XTCLINK
XTCDECL
ULONG
HlReadPort32(IN USHORT Port);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutByte(IN USHORT Port, HlWritePort8(IN USHORT Port,
IN UCHAR Data); IN UCHAR Data);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutLong(IN USHORT Port, HlWritePort16(IN USHORT Port,
IN ULONG Value); IN USHORT Value);
XTCLINK XTCLINK
XTCDECL XTCDECL
VOID VOID
HlIoPortOutShort(IN USHORT Port, HlWritePort32(IN USHORT Port,
IN USHORT Value); IN ULONG Value);
#endif /* __XTDK_I686_HLFUNCS_H */ #endif /* __XTDK_I686_HLFUNCS_H */

View File

@@ -78,7 +78,7 @@ BlpDebugPutChar(IN WCHAR Character)
/* Write character to the serial console */ /* Write character to the serial console */
Buffer[0] = Character; Buffer[0] = Character;
Buffer[1] = 0; Buffer[1] = 0;
return HlComPortPutByte(&BlpStatus.SerialPort, Buffer[0]); return HlWriteComPort(&BlpStatus.SerialPort, Buffer[0]);
} }
/** /**

View File

@@ -29,8 +29,8 @@ BpDisableToneBeep()
UCHAR Status; UCHAR Status;
/* Stop the PC speaker */ /* Stop the PC speaker */
Status = HlIoPortInByte(0x61); Status = HlReadPort8(0x61);
HlIoPortOutByte(0x61, Status & 0xFC); HlWritePort8(0x61, Status & 0xFC);
} }
/** /**
@@ -62,14 +62,14 @@ BpEnableToneBeep(IN UINT Pitch)
/* Set the desired frequency of the PIT clock */ /* Set the desired frequency of the PIT clock */
Counter = 0x1234DD / Pitch; Counter = 0x1234DD / Pitch;
HlIoPortOutByte(0x43, 0xB6); HlWritePort8(0x43, 0xB6);
HlIoPortOutByte(0x43, 0xB6); HlWritePort8(0x43, 0xB6);
HlIoPortOutByte(0x42, (UCHAR) Counter & 0xFF); HlWritePort8(0x42, (UCHAR) Counter & 0xFF);
HlIoPortOutByte(0x42, (UCHAR) (Counter >> 8) & 0xFF); HlWritePort8(0x42, (UCHAR) (Counter >> 8) & 0xFF);
/* Start the PC speaker */ /* Start the PC speaker */
Status = HlIoPortInByte(0x61); Status = HlReadPort8(0x61);
HlIoPortOutByte(0x61, Status | 0x03); HlWritePort8(0x61, Status | 0x03);
} }
/** /**

View File

@@ -17,17 +17,17 @@ list(APPEND XTOSKRNL_SOURCE
${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/traps.cc ${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/traps.cc
${XTOSKRNL_SOURCE_DIR}/ex/exports.cc ${XTOSKRNL_SOURCE_DIR}/ex/exports.cc
${XTOSKRNL_SOURCE_DIR}/ex/rundown.cc ${XTOSKRNL_SOURCE_DIR}/ex/rundown.cc
${XTOSKRNL_SOURCE_DIR}/hl/acpi.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/cpu.cc
${XTOSKRNL_SOURCE_DIR}/hl/cport.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/pic.cc
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/ioport.cc
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/runlevel.cc
${XTOSKRNL_SOURCE_DIR}/hl/acpi.cc
${XTOSKRNL_SOURCE_DIR}/hl/cport.cc
${XTOSKRNL_SOURCE_DIR}/hl/data.cc
${XTOSKRNL_SOURCE_DIR}/hl/exports.cc ${XTOSKRNL_SOURCE_DIR}/hl/exports.cc
${XTOSKRNL_SOURCE_DIR}/hl/fbdev.c ${XTOSKRNL_SOURCE_DIR}/hl/fbdev.cc
${XTOSKRNL_SOURCE_DIR}/hl/globals.c ${XTOSKRNL_SOURCE_DIR}/hl/init.cc
${XTOSKRNL_SOURCE_DIR}/hl/init.c
${XTOSKRNL_SOURCE_DIR}/hl/ioreg.cc ${XTOSKRNL_SOURCE_DIR}/hl/ioreg.cc
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/cpu.c
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/pic.c
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/ioport.c
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/runlevel.c
${XTOSKRNL_SOURCE_DIR}/kd/dbginit.c ${XTOSKRNL_SOURCE_DIR}/kd/dbginit.c
${XTOSKRNL_SOURCE_DIR}/kd/dbgio.c ${XTOSKRNL_SOURCE_DIR}/kd/dbgio.c
${XTOSKRNL_SOURCE_DIR}/kd/globals.c ${XTOSKRNL_SOURCE_DIR}/kd/globals.c

View File

@@ -159,7 +159,7 @@ AR::ProcSup::InitializeProcessor(IN PVOID ProcessorStructures)
CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS); CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS);
/* Enter passive IRQ level */ /* Enter passive IRQ level */
HlSetRunLevel(PASSIVE_LEVEL); HL::RunLevel::SetRunLevel(PASSIVE_LEVEL);
/* Initialize segment registers */ /* Initialize segment registers */
InitializeSegments(); InitializeSegments();

View File

@@ -159,7 +159,7 @@ AR::ProcSup::InitializeProcessor(IN PVOID ProcessorStructures)
CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS); CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS);
/* Enter passive IRQ level */ /* Enter passive IRQ level */
HlSetRunLevel(PASSIVE_LEVEL); HL::RunLevel::SetRunLevel(PASSIVE_LEVEL);
/* Initialize segment registers */ /* Initialize segment registers */
InitializeSegments(); InitializeSegments();

View File

@@ -1,14 +1,35 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/x86/acpi.c * FILE: xtoskrnl/hl/x86/acpi.cc
* DESCRIPTION: Advanced Configuration and Power Interface (ACPI) support * DESCRIPTION: Advanced Configuration and Power Interface (ACPI) support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/**
* Stores given ACPI table in the kernel local cache.
*
* @param AcpiTable
* Supplies a pointer to ACPI table that will be stored in the cache.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HL::Acpi::CacheAcpiTable(IN PACPI_DESCRIPTION_HEADER AcpiTable)
{
PACPI_CACHE_LIST AcpiCache;
/* Create new ACPI table cache entry */
AcpiCache = CONTAIN_RECORD(AcpiTable, ACPI_CACHE_LIST, Header);
RTL::LinkedList::InsertTailList(&CacheList, &AcpiCache->ListEntry);
}
/** /**
* Gets a pointer to the ACPI system description pointer (RSDP). * Gets a pointer to the ACPI system description pointer (RSDP).
* *
@@ -21,10 +42,10 @@
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlGetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp) HL::Acpi::GetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp)
{ {
/* Get RSDP and return success */ /* Get RSDP and return success */
*Rsdp = HlpAcpiRsdp; *Rsdp = RsdpStructure;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@@ -43,21 +64,21 @@ HlGetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlGetAcpiTable(IN ULONG Signature, HL::Acpi::GetAcpiTable(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable) OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
{ {
PACPI_DESCRIPTION_HEADER Table; PACPI_DESCRIPTION_HEADER Table;
XTSTATUS Status; XTSTATUS Status;
/* Assume ACPI table not found */ /* Assume ACPI table not found */
*AcpiTable = NULL; *AcpiTable = nullptr;
/* Attempt to get ACPI table from the cache */ /* Attempt to get ACPI table from the cache */
Status = HlpQueryAcpiCache(Signature, &Table); Status = QueryAcpiCache(Signature, &Table);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Table not found in the cache, query ACPI tables */ /* Table not found in the cache, query ACPI tables */
Status = HlpQueryAcpiTables(Signature, &Table); Status = QueryAcpiTables(Signature, &Table);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* ACPI table not found, return error */ /* ACPI table not found, return error */
@@ -70,27 +91,6 @@ HlGetAcpiTable(IN ULONG Signature,
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/**
* Stores given ACPI table in the kernel local cache.
*
* @param AcpiTable
* Supplies a pointer to ACPI table that will be stored in the cache.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlpCacheAcpiTable(IN PACPI_DESCRIPTION_HEADER AcpiTable)
{
PACPI_CACHE_LIST AcpiCache;
/* Create new ACPI table cache entry */
AcpiCache = CONTAIN_RECORD(AcpiTable, ACPI_CACHE_LIST, Header);
RtlInsertTailList(&HlpAcpiCacheList, &AcpiCache->ListEntry);
}
/** /**
* Performs an initialization of the ACPI subsystem. * Performs an initialization of the ACPI subsystem.
* *
@@ -100,13 +100,13 @@ HlpCacheAcpiTable(IN PACPI_DESCRIPTION_HEADER AcpiTable)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpi(VOID) HL::Acpi::InitializeAcpi(VOID)
{ {
PACPI_FADT Fadt; PACPI_FADT Fadt;
XTSTATUS Status; XTSTATUS Status;
/* Initialize ACPI cache */ /* Initialize ACPI cache */
Status = HlpInitializeAcpiCache(); Status = InitializeAcpiCache();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* ACPI cache initialization failed, return error */ /* ACPI cache initialization failed, return error */
@@ -114,7 +114,7 @@ HlpInitializeAcpi(VOID)
} }
/* Get Fixed ACPI Description Table (FADT) */ /* Get Fixed ACPI Description Table (FADT) */
Status = HlGetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt); Status = GetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt);
if(Status != STATUS_SUCCESS || !Fadt) if(Status != STATUS_SUCCESS || !Fadt)
{ {
/* Failed to get FADT, return error */ /* Failed to get FADT, return error */
@@ -122,7 +122,7 @@ HlpInitializeAcpi(VOID)
} }
/* Initialize ACPI timer */ /* Initialize ACPI timer */
HlpInitializeAcpiTimer(); InitializeAcpiTimer();
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@@ -137,16 +137,16 @@ HlpInitializeAcpi(VOID)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpiCache(VOID) HL::Acpi::InitializeAcpiCache(VOID)
{ {
PACPI_DESCRIPTION_HEADER Rsdt; PACPI_DESCRIPTION_HEADER Rsdt;
XTSTATUS Status; XTSTATUS Status;
/* Initialize ACPI cache list */ /* Initialize ACPI cache list */
RtlInitializeListHead(&HlpAcpiCacheList); RTL::LinkedList::InitializeListHead(&CacheList);
/* Get XSDT/RSDT */ /* Get XSDT/RSDT */
Status = HlpInitializeAcpiSystemDescriptionTable(&Rsdt); Status = InitializeAcpiSystemDescriptionTable(&Rsdt);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to get XSDT/RSDT, return error */ /* Failed to get XSDT/RSDT, return error */
@@ -154,7 +154,7 @@ HlpInitializeAcpiCache(VOID)
} }
/* Cache XSDT/RSDT table */ /* Cache XSDT/RSDT table */
HlpCacheAcpiTable(Rsdt); CacheAcpiTable(Rsdt);
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@@ -172,7 +172,7 @@ HlpInitializeAcpiCache(VOID)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable) HL::Acpi::InitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
{ {
PHYSICAL_ADDRESS RsdpAddress, RsdtAddress; PHYSICAL_ADDRESS RsdpAddress, RsdtAddress;
PSYSTEM_RESOURCE_HEADER ResourceHeader; PSYSTEM_RESOURCE_HEADER ResourceHeader;
@@ -182,7 +182,7 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
XTSTATUS Status; XTSTATUS Status;
/* Assume ACPI table not found */ /* Assume ACPI table not found */
*AcpiTable = NULL; *AcpiTable = nullptr;
/* Get ACPI system resource */ /* Get ACPI system resource */
Status = KeGetSystemResource(SystemResourceAcpi, &ResourceHeader); Status = KeGetSystemResource(SystemResourceAcpi, &ResourceHeader);
@@ -197,26 +197,26 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
RsdpAddress.QuadPart = (LONGLONG)AcpiResource->Header.PhysicalAddress; RsdpAddress.QuadPart = (LONGLONG)AcpiResource->Header.PhysicalAddress;
/* Map RSDP and mark it as CD/WT to avoid delays in write-back cache */ /* Map RSDP and mark it as CD/WT to avoid delays in write-back cache */
Status = MmMapHardwareMemory(RsdpAddress, 1, TRUE, (PVOID *)&HlpAcpiRsdp); Status = MmMapHardwareMemory(RsdpAddress, 1, TRUE, (PVOID *)&RsdpStructure);
MmMarkHardwareMemoryWriteThrough(HlpAcpiRsdp, 1); MmMarkHardwareMemoryWriteThrough(RsdpStructure, 1);
/* Validate RSDP signature */ /* Validate RSDP signature */
if(Status != STATUS_SUCCESS || HlpAcpiRsdp->Signature != ACPI_RSDP_SIGNATURE) if(Status != STATUS_SUCCESS || RsdpStructure->Signature != ACPI_RSDP_SIGNATURE)
{ {
/* Not mapped correctly or invalid RSDP signature, return error */ /* Not mapped correctly or invalid RSDP signature, return error */
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Check RSDP revision to determine RSDT/XSDT address */ /* Check RSDP revision to determine RSDT/XSDT address */
if(HlpAcpiRsdp->Revision >= 2) if(RsdpStructure->Revision >= 2)
{ {
/* Get XSDT address */ /* Get XSDT address */
RsdtAddress.QuadPart = (LONGLONG)HlpAcpiRsdp->XsdtAddress; RsdtAddress.QuadPart = (LONGLONG)RsdpStructure->XsdtAddress;
} }
else else
{ {
/* Get RSDT address */ /* Get RSDT address */
RsdtAddress.QuadPart = (LONGLONG)HlpAcpiRsdp->RsdtAddress; RsdtAddress.QuadPart = (LONGLONG)RsdpStructure->RsdtAddress;
} }
/* Map RSDT/XSDT as CD/WT */ /* Map RSDT/XSDT as CD/WT */
@@ -263,7 +263,7 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpiSystemInformation(VOID) HL::Acpi::InitializeAcpiSystemInformation(VOID)
{ {
PACPI_MADT_LOCAL_X2APIC LocalX2Apic; PACPI_MADT_LOCAL_X2APIC LocalX2Apic;
PACPI_MADT_LOCAL_APIC LocalApic; PACPI_MADT_LOCAL_APIC LocalApic;
@@ -273,7 +273,7 @@ HlpInitializeAcpiSystemInformation(VOID)
USHORT CpuCount; USHORT CpuCount;
/* Allocate memory for ACPI system information structure */ /* Allocate memory for ACPI system information structure */
Status = HlpInitializeAcpiSystemStructure(); Status = InitializeAcpiSystemStructure();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to allocate memory, return error */ /* Failed to allocate memory, return error */
@@ -281,7 +281,7 @@ HlpInitializeAcpiSystemInformation(VOID)
} }
/* Get Multiple APIC Description Table (MADT) */ /* Get Multiple APIC Description Table (MADT) */
Status = HlGetAcpiTable(ACPI_MADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Madt); Status = GetAcpiTable(ACPI_MADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Madt);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to get MADT, return error */ /* Failed to get MADT, return error */
@@ -306,9 +306,9 @@ HlpInitializeAcpiSystemInformation(VOID)
if(LocalApic->Flags & ACPI_MADT_PLAOC_ENABLED) if(LocalApic->Flags & ACPI_MADT_PLAOC_ENABLED)
{ {
/* Store CPU number, APIC ID and CPU ID */ /* Store CPU number, APIC ID and CPU ID */
HlpSystemInfo.CpuInfo[CpuCount].AcpiId = LocalApic->AcpiId; SystemInfo.CpuInfo[CpuCount].AcpiId = LocalApic->AcpiId;
HlpSystemInfo.CpuInfo[CpuCount].ApicId = LocalApic->ApicId; SystemInfo.CpuInfo[CpuCount].ApicId = LocalApic->ApicId;
HlpSystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount; SystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
/* Increment number of CPUs */ /* Increment number of CPUs */
CpuCount++; CpuCount++;
@@ -327,9 +327,9 @@ HlpInitializeAcpiSystemInformation(VOID)
if(LocalX2Apic->Flags & ACPI_MADT_PLAOC_ENABLED) if(LocalX2Apic->Flags & ACPI_MADT_PLAOC_ENABLED)
{ {
/* Store CPU number, APIC ID and CPU ID */ /* Store CPU number, APIC ID and CPU ID */
HlpSystemInfo.CpuInfo[CpuCount].AcpiId = LocalX2Apic->AcpiId; SystemInfo.CpuInfo[CpuCount].AcpiId = LocalX2Apic->AcpiId;
HlpSystemInfo.CpuInfo[CpuCount].ApicId = LocalX2Apic->ApicId; SystemInfo.CpuInfo[CpuCount].ApicId = LocalX2Apic->ApicId;
HlpSystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount; SystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
/* Increment number of CPUs */ /* Increment number of CPUs */
CpuCount++; CpuCount++;
@@ -346,7 +346,7 @@ HlpInitializeAcpiSystemInformation(VOID)
} }
/* Store number of CPUs */ /* Store number of CPUs */
HlpSystemInfo.CpuCount = CpuCount; SystemInfo.CpuCount = CpuCount;
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@@ -361,7 +361,7 @@ HlpInitializeAcpiSystemInformation(VOID)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpiSystemStructure(VOID) HL::Acpi::InitializeAcpiSystemStructure(VOID)
{ {
PHYSICAL_ADDRESS PhysicalAddress; PHYSICAL_ADDRESS PhysicalAddress;
PFN_NUMBER PageCount; PFN_NUMBER PageCount;
@@ -371,7 +371,7 @@ HlpInitializeAcpiSystemStructure(VOID)
ULONG CpuCount; ULONG CpuCount;
/* Get Multiple APIC Description Table (MADT) */ /* Get Multiple APIC Description Table (MADT) */
Status = HlGetAcpiTable(ACPI_MADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Madt); Status = GetAcpiTable(ACPI_MADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Madt);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to get MADT, return error */ /* Failed to get MADT, return error */
@@ -420,7 +420,7 @@ HlpInitializeAcpiSystemStructure(VOID)
} }
/* Zero the ACPI system information structure */ /* Zero the ACPI system information structure */
RtlZeroMemory(&HlpSystemInfo, sizeof(ACPI_SYSTEM_INFO)); RTL::Memory::ZeroMemory(&SystemInfo, sizeof(ACPI_SYSTEM_INFO));
/* Calculate number of pages needed to store CPU information */ /* Calculate number of pages needed to store CPU information */
PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY)); PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY));
@@ -434,7 +434,7 @@ HlpInitializeAcpiSystemStructure(VOID)
} }
/* Map physical address to the virtual memory area */ /* Map physical address to the virtual memory area */
Status = MmMapHardwareMemory(PhysicalAddress, PageCount, TRUE, (PVOID *)&HlpSystemInfo.CpuInfo); Status = MmMapHardwareMemory(PhysicalAddress, PageCount, TRUE, (PVOID *)&SystemInfo.CpuInfo);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to map memory, return error */ /* Failed to map memory, return error */
@@ -442,7 +442,7 @@ HlpInitializeAcpiSystemStructure(VOID)
} }
/* Zero the CPU information structure */ /* Zero the CPU information structure */
RtlZeroMemory(HlpSystemInfo.CpuInfo, PAGES_TO_SIZE(PageCount)); RTL::Memory::ZeroMemory(SystemInfo.CpuInfo, PAGES_TO_SIZE(PageCount));
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@@ -457,13 +457,13 @@ HlpInitializeAcpiSystemStructure(VOID)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpInitializeAcpiTimer(VOID) HL::Acpi::InitializeAcpiTimer(VOID)
{ {
PACPI_FADT Fadt; PACPI_FADT Fadt;
XTSTATUS Status; XTSTATUS Status;
/* Get Fixed ACPI Description Table (FADT) */ /* Get Fixed ACPI Description Table (FADT) */
Status = HlGetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt); Status = GetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt);
if(Status != STATUS_SUCCESS || !Fadt) if(Status != STATUS_SUCCESS || !Fadt)
{ {
/* Failed to get FADT, return error */ /* Failed to get FADT, return error */
@@ -471,18 +471,18 @@ HlpInitializeAcpiTimer(VOID)
} }
/* Set ACPI timer port address */ /* Set ACPI timer port address */
HlpAcpiTimerInfo.TimerPort = Fadt->PmTmrBlkIoPort; TimerInfo.TimerPort = Fadt->PmTmrBlkIoPort;
/* Determine whether 32-bit or 24-bit timer is used */ /* Determine whether 32-bit or 24-bit timer is used */
if(Fadt->Flags & ACPI_FADT_32BIT_TIMER) if(Fadt->Flags & ACPI_FADT_32BIT_TIMER)
{ {
/* 32-bit timer */ /* 32-bit timer */
HlpAcpiTimerInfo.MsbMask = ACPI_FADT_TIMER_32BIT; TimerInfo.MsbMask = ACPI_FADT_TIMER_32BIT;
} }
else else
{ {
/* 24-bit timer */ /* 24-bit timer */
HlpAcpiTimerInfo.MsbMask = ACPI_FADT_TIMER_24BIT; TimerInfo.MsbMask = ACPI_FADT_TIMER_24BIT;
} }
/* Return success */ /* Return success */
@@ -504,7 +504,7 @@ HlpInitializeAcpiTimer(VOID)
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpQueryAcpiCache(IN ULONG Signature, HL::Acpi::QueryAcpiCache(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable) OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
{ {
PACPI_DESCRIPTION_HEADER TableHeader; PACPI_DESCRIPTION_HEADER TableHeader;
@@ -512,11 +512,11 @@ HlpQueryAcpiCache(IN ULONG Signature,
PLIST_ENTRY ListEntry; PLIST_ENTRY ListEntry;
/* Initialize variables */ /* Initialize variables */
TableHeader = NULL; TableHeader = nullptr;
/* Iterate through ACPI tables cache list */ /* Iterate through ACPI tables cache list */
ListEntry = HlpAcpiCacheList.Flink; ListEntry = CacheList.Flink;
while(ListEntry != &HlpAcpiCacheList) while(ListEntry != &CacheList)
{ {
/* Get cached ACPI table header */ /* Get cached ACPI table header */
AcpiCache = CONTAIN_RECORD(ListEntry, ACPI_CACHE_LIST, ListEntry); AcpiCache = CONTAIN_RECORD(ListEntry, ACPI_CACHE_LIST, ListEntry);
@@ -561,7 +561,7 @@ HlpQueryAcpiCache(IN ULONG Signature,
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlpQueryAcpiTables(IN ULONG Signature, HL::Acpi::QueryAcpiTables(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable) OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
{ {
ULONG TableCount, TableIndex, TablePages; ULONG TableCount, TableIndex, TablePages;
@@ -580,13 +580,13 @@ HlpQueryAcpiTables(IN ULONG Signature,
} }
/* Ensure that table header is not set before attempting to find ACPI table */ /* Ensure that table header is not set before attempting to find ACPI table */
TableHeader = NULL; TableHeader = nullptr;
/* Check if DSDT or FACS table requested */ /* Check if DSDT or FACS table requested */
if(Signature == ACPI_DSDT_SIGNATURE || Signature == ACPI_FACS_SIGNATURE) if(Signature == ACPI_DSDT_SIGNATURE || Signature == ACPI_FACS_SIGNATURE)
{ {
/* Get FADT as it contains a pointer to DSDT and FACS */ /* Get FADT as it contains a pointer to DSDT and FACS */
Status = HlGetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt); Status = GetAcpiTable(ACPI_FADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Fadt);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Failed to get FADT, return error */ /* Failed to get FADT, return error */
@@ -619,11 +619,11 @@ HlpQueryAcpiTables(IN ULONG Signature,
else else
{ {
/* Query cache for XSDP table */ /* Query cache for XSDP table */
Status = HlpQueryAcpiCache(ACPI_XSDT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Xsdt); Status = QueryAcpiCache(ACPI_XSDT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Xsdt);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* XSDP not found, query cache for RSDP table */ /* XSDP not found, query cache for RSDP table */
Status = HlpQueryAcpiCache(ACPI_RSDT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Rsdt); Status = QueryAcpiCache(ACPI_RSDT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Rsdt);
} }
/* Check if XSDT or RSDT table found */ /* Check if XSDT or RSDT table found */
@@ -703,7 +703,7 @@ HlpQueryAcpiTables(IN ULONG Signature,
if(TableHeader->Signature != ACPI_FADT_SIGNATURE || TableHeader->Revision > 2) if(TableHeader->Signature != ACPI_FADT_SIGNATURE || TableHeader->Revision > 2)
{ {
/* Validate table checksum */ /* Validate table checksum */
if(!HlpValidateAcpiTable(TableHeader, TableHeader->Length)) if(!ValidateAcpiTable(TableHeader, TableHeader->Length))
{ {
/* Checksum mismatch, unmap table and return error */ /* Checksum mismatch, unmap table and return error */
MmUnmapHardwareMemory(TableHeader, 2, TRUE); MmUnmapHardwareMemory(TableHeader, 2, TRUE);
@@ -729,7 +729,7 @@ HlpQueryAcpiTables(IN ULONG Signature,
/* Mark table as write through and store it in local cache */ /* Mark table as write through and store it in local cache */
MmMarkHardwareMemoryWriteThrough(TableHeader, TablePages); MmMarkHardwareMemoryWriteThrough(TableHeader, TablePages);
HlpCacheAcpiTable(TableHeader); CacheAcpiTable(TableHeader);
/* Store ACPI table and return success */ /* Store ACPI table and return success */
*AcpiTable = TableHeader; *AcpiTable = TableHeader;
@@ -751,7 +751,7 @@ HlpQueryAcpiTables(IN ULONG Signature,
*/ */
XTAPI XTAPI
BOOLEAN BOOLEAN
HlpValidateAcpiTable(IN PVOID Buffer, HL::Acpi::ValidateAcpiTable(IN PVOID Buffer,
IN UINT_PTR Size) IN UINT_PTR Size)
{ {
PUCHAR Pointer; PUCHAR Pointer;
@@ -759,7 +759,7 @@ HlpValidateAcpiTable(IN PVOID Buffer,
/* Initialize variables */ /* Initialize variables */
Sum = 0; Sum = 0;
Pointer = Buffer; Pointer = (PUCHAR)Buffer;
/* Calculate checksum of given table */ /* Calculate checksum of given table */
while(Size != 0) while(Size != 0)

View File

@@ -1,13 +1,13 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/amd64/cpu.c * FILE: xtoskrnl/hl/amd64/cpu.cc
* DESCRIPTION: HAL AMD64 processor support * DESCRIPTION: HAL AMD64 processor support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/* Include common CPU interface */ /* Include common CPU interface */
#include ARCH_COMMON(cpu.c) #include ARCH_COMMON(cpu.cc)

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/amd64/ioport.c * FILE: xtoskrnl/hl/amd64/ioport.cc
* DESCRIPTION: I/O port access routines for AMD64 platform * DESCRIPTION: I/O port access routines for AMD64 platform
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -21,7 +21,7 @@
*/ */
XTCDECL XTCDECL
UCHAR UCHAR
HlIoPortInByte(IN USHORT Port) HL::IoPort::ReadPort8(IN USHORT Port)
{ {
UCHAR Value; UCHAR Value;
__asm__ volatile("inb %1, %0" __asm__ volatile("inb %1, %0"
@@ -30,27 +30,6 @@ HlIoPortInByte(IN USHORT Port)
return Value; return Value;
} }
/**
* Reads the 32-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCDECL
ULONG
HlIoPortInLong(IN USHORT Port)
{
ULONG Value;
__asm__ volatile("inl %1, %0"
: "=a" (Value)
: "Nd" (Port));
return Value;
}
/** /**
* Reads the 16-bit data from the specified I/O port. * Reads the 16-bit data from the specified I/O port.
* *
@@ -63,7 +42,7 @@ HlIoPortInLong(IN USHORT Port)
*/ */
XTCDECL XTCDECL
USHORT USHORT
HlIoPortInShort(IN USHORT Port) HL::IoPort::ReadPort16(IN USHORT Port)
{ {
USHORT Value; USHORT Value;
__asm__ volatile("inw %1, %0" __asm__ volatile("inw %1, %0"
@@ -72,6 +51,27 @@ HlIoPortInShort(IN USHORT Port)
return Value; return Value;
} }
/**
* Reads the 32-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCDECL
ULONG
HL::IoPort::ReadPort32(IN USHORT Port)
{
ULONG Value;
__asm__ volatile("inl %1, %0"
: "=a" (Value)
: "Nd" (Port));
return Value;
}
/** /**
* Writes the 8-bit data to the specified I/O port. * Writes the 8-bit data to the specified I/O port.
* *
@@ -87,7 +87,7 @@ HlIoPortInShort(IN USHORT Port)
*/ */
XTCDECL XTCDECL
VOID VOID
HlIoPortOutByte(IN USHORT Port, HL::IoPort::WritePort8(IN USHORT Port,
IN UCHAR Value) IN UCHAR Value)
{ {
__asm__ volatile("outb %0, %1" __asm__ volatile("outb %0, %1"
@@ -96,30 +96,6 @@ HlIoPortOutByte(IN USHORT Port,
"Nd" (Port)); "Nd" (Port));
} }
/**
* Writes the 32-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
HlIoPortOutLong(IN USHORT Port,
IN ULONG Value)
{
__asm__ volatile("outl %0, %1"
:
: "a" (Value),
"Nd" (Port));
}
/** /**
* Writes the 16-bit data to the specified I/O port. * Writes the 16-bit data to the specified I/O port.
* *
@@ -135,7 +111,7 @@ HlIoPortOutLong(IN USHORT Port,
*/ */
XTCDECL XTCDECL
VOID VOID
HlIoPortOutShort(IN USHORT Port, HL::IoPort::WritePort16(IN USHORT Port,
IN USHORT Value) IN USHORT Value)
{ {
__asm__ volatile("outw %0, %1" __asm__ volatile("outw %0, %1"
@@ -143,3 +119,27 @@ HlIoPortOutShort(IN USHORT Port,
: "a" (Value), : "a" (Value),
"Nd" (Port)); "Nd" (Port));
} }
/**
* Writes the 32-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
HL::IoPort::WritePort32(IN USHORT Port,
IN ULONG Value)
{
__asm__ volatile("outl %0, %1"
:
: "a" (Value),
"Nd" (Port));
}

View File

@@ -1,13 +1,13 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/amd64/pic.c * FILE: xtoskrnl/hl/amd64/pic.cc
* DESCRIPTION: Programmable Interrupt Controller (PIC) for AMD64 support * DESCRIPTION: Programmable Interrupt Controller (PIC) for AMD64 support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/* Include common PIC interface */ /* Include common PIC interface */
#include ARCH_COMMON(pic.c) #include ARCH_COMMON(pic.cc)

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/amd64/runlevel.c * FILE: xtoskrnl/hl/amd64/runlevel.cc
* DESCRIPTION: Run Level management support for AMD64 architecture * DESCRIPTION: Run Level management support for AMD64 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -18,7 +18,7 @@
*/ */
XTFASTCALL XTFASTCALL
KRUNLEVEL KRUNLEVEL
HlGetRunLevel(VOID) HL::RunLevel::GetRunLevel(VOID)
{ {
return (KRUNLEVEL)ArReadControlRegister(8); return (KRUNLEVEL)ArReadControlRegister(8);
} }
@@ -35,7 +35,7 @@ HlGetRunLevel(VOID)
*/ */
XTFASTCALL XTFASTCALL
VOID VOID
HlSetRunLevel(IN KRUNLEVEL RunLevel) HL::RunLevel::SetRunLevel(IN KRUNLEVEL RunLevel)
{ {
ArWriteControlRegister(8, RunLevel); ArWriteControlRegister(8, RunLevel);
} }
@@ -52,7 +52,7 @@ HlSetRunLevel(IN KRUNLEVEL RunLevel)
*/ */
XTFASTCALL XTFASTCALL
KRUNLEVEL KRUNLEVEL
HlpTransformApicTprToRunLevel(IN UCHAR Tpr) HL::RunLevel::TransformApicTprToRunLevel(IN UCHAR Tpr)
{ {
return (KRUNLEVEL)(Tpr >> 4); return (KRUNLEVEL)(Tpr >> 4);
} }
@@ -69,7 +69,7 @@ HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
*/ */
XTFASTCALL XTFASTCALL
UCHAR UCHAR
HlpTransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel) HL::RunLevel::TransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
{ {
return (RunLevel << 4); return (RunLevel << 4);
} }

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/cport.c * FILE: xtoskrnl/hl/cport.cc
* DESCRIPTION: Serial (COM) port support * DESCRIPTION: Serial (COM) port support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -30,7 +30,7 @@
*/ */
XTCDECL XTCDECL
XTSTATUS XTSTATUS
HlComPortGetByte(IN PCPPORT Port, HL::ComPort::ReadComPort(IN PCPPORT Port,
OUT PUCHAR Byte, OUT PUCHAR Byte,
IN BOOLEAN Wait, IN BOOLEAN Wait,
IN BOOLEAN Poll) IN BOOLEAN Poll)
@@ -49,7 +49,7 @@ HlComPortGetByte(IN PCPPORT Port,
while(Retry--) while(Retry--)
{ {
/* Get LSR for data ready */ /* Get LSR for data ready */
Lsr = HlComPortReadLsr(Port, COMPORT_LSR_DR); Lsr = ReadComPortLsr(Port, COMPORT_LSR_DR);
if((Lsr & COMPORT_LSR_DR) == COMPORT_LSR_DR) if((Lsr & COMPORT_LSR_DR) == COMPORT_LSR_DR)
{ {
/* Check for errors */ /* Check for errors */
@@ -68,13 +68,13 @@ HlComPortGetByte(IN PCPPORT Port,
} }
/* Read the byte from serial port */ /* Read the byte from serial port */
*Byte = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_RBR)); *Byte = HL::IoPort::ReadPort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_RBR));
/* Check if in modem control mode */ /* Check if in modem control mode */
if(Port->Flags & COMPORT_FLAG_MC) if(Port->Flags & COMPORT_FLAG_MC)
{ {
/* Handle Carrier Detected (CD) */ /* Handle Carrier Detected (CD) */
if((HlIoPortInByte(PtrToShort(Port->Address + (ULONG)COMPORT_REG_MSR)) & COMPORT_MSR_DCD) == 0) if((HL::IoPort::ReadPort8(PtrToShort(Port->Address + (ULONG)COMPORT_REG_MSR)) & COMPORT_MSR_DCD) == 0)
{ {
/* Skip byte if no CD present */ /* Skip byte if no CD present */
continue; continue;
@@ -85,67 +85,10 @@ HlComPortGetByte(IN PCPPORT Port,
} }
/* Reset LSR and return that no data found */ /* Reset LSR and return that no data found */
HlComPortReadLsr(Port, 0); ReadComPortLsr(Port, 0);
return STATUS_NOT_FOUND; return STATUS_NOT_FOUND;
} }
/**
* This routine writes a byte to the serial port.
*
* @param Port
* Address of port object describing a port settings.
*
* @param Byte
* Data to be written.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
XTSTATUS
HlComPortPutByte(IN PCPPORT Port,
IN UCHAR Byte)
{
UCHAR Lsr, Msr;
/* Make sure the port has been initialized */
if(Port->Address == 0)
{
return STATUS_DEVICE_NOT_READY;
}
/* Check if port is in modem control */
while(Port->Flags & COMPORT_FLAG_MC)
{
/* Get the Modem Status Register (MSR) */
Msr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR)) & COMPORT_MSR_DSRCTSCD;
if(Msr != COMPORT_MSR_DSRCTSCD)
{
/* Take character, if CD is not set */
Lsr = HlComPortReadLsr(Port, 0);
if((Msr & COMPORT_MSR_DCD) == 0 && (Lsr & COMPORT_LSR_DR) == COMPORT_LSR_DR)
{
/* Eat the character */
HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_RBR));
}
}
else
{
/* CD, CTS and DSR are set, we can continue */
break;
}
}
/* Wait for busy port */
while((HlComPortReadLsr(Port, COMPORT_LSR_THRE) & COMPORT_LSR_THRE) == 0);
/* Send byte to the port */
HlIoPortOutByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_THR), Byte);
return STATUS_SUCCESS;
}
/** /**
* Reads LSR from specified serial port. * Reads LSR from specified serial port.
* *
@@ -161,19 +104,19 @@ HlComPortPutByte(IN PCPPORT Port,
*/ */
XTCDECL XTCDECL
UCHAR UCHAR
HlComPortReadLsr(IN PCPPORT Port, HL::ComPort::ReadComPortLsr(IN PCPPORT Port,
IN UCHAR Byte) IN UCHAR Byte)
{ {
UCHAR Lsr, Msr; UCHAR Lsr, Msr;
/* Read the Line Status Register (LSR) */ /* Read the Line Status Register (LSR) */
Lsr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_LSR)); Lsr = HL::IoPort::ReadPort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_LSR));
/* Check if expected byte is present */ /* Check if expected byte is present */
if((Lsr & Byte) == 0) if((Lsr & Byte) == 0)
{ {
/* Check Modem Status Register (MSR) for ring indicator */ /* Check Modem Status Register (MSR) for ring indicator */
Msr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR)); Msr = HL::IoPort::ReadPort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR));
Port->Ring |= (Msr & COMPORT_MSR_RI) ? 1 : 2; Port->Ring |= (Msr & COMPORT_MSR_RI) ? 1 : 2;
if(Port->Ring == 3) if(Port->Ring == 3)
{ {
@@ -207,7 +150,7 @@ HlComPortReadLsr(IN PCPPORT Port,
*/ */
XTCDECL XTCDECL
XTSTATUS XTSTATUS
HlInitializeComPort(IN OUT PCPPORT Port, HL::ComPort::InitializeComPort(IN OUT PCPPORT Port,
IN PUCHAR PortAddress, IN PUCHAR PortAddress,
IN ULONG BaudRate) IN ULONG BaudRate)
{ {
@@ -237,8 +180,8 @@ HlInitializeComPort(IN OUT PCPPORT Port,
do do
{ {
/* Check whether the 16450/16550 scratch register exists */ /* Check whether the 16450/16550 scratch register exists */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR), Byte); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR), Byte);
if(HlIoPortInByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR)) != Byte) if(HL::IoPort::ReadPort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR)) != Byte)
{ {
return STATUS_NOT_FOUND; return STATUS_NOT_FOUND;
} }
@@ -246,37 +189,37 @@ HlInitializeComPort(IN OUT PCPPORT Port,
while(++Byte != 0); while(++Byte != 0);
/* Disable interrupts */ /* Disable interrupts */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR), COMPORT_LSR_DIS); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR), COMPORT_LSR_DIS);
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_IER), COMPORT_LSR_DIS); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_IER), COMPORT_LSR_DIS);
/* Enable Divisor Latch Access Bit (DLAB) */ /* Enable Divisor Latch Access Bit (DLAB) */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR), COMPORT_LCR_DLAB); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR), COMPORT_LCR_DLAB);
/* Set baud rate */ /* Set baud rate */
Mode = COMPORT_CLOCK_RATE / BaudRate; Mode = COMPORT_CLOCK_RATE / BaudRate;
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_DIV_DLL), (UCHAR)(Mode & 0xFF)); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_DIV_DLL), (UCHAR)(Mode & 0xFF));
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_DIV_DLM), (UCHAR)((Mode >> 8) & 0xFF)); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_DIV_DLM), (UCHAR)((Mode >> 8) & 0xFF));
/* Set 8 data bits, 1 stop bits, no parity (8n1) */ /* Set 8 data bits, 1 stop bits, no parity (8n1) */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR), HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR),
COMPORT_LCR_8DATA | COMPORT_LCR_1STOP | COMPORT_LCR_PARN); COMPORT_LCR_8DATA | COMPORT_LCR_1STOP | COMPORT_LCR_PARN);
/* Enable DTR, RTS and OUT2 */ /* Enable DTR, RTS and OUT2 */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR), HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR),
COMPORT_MCR_DTR | COMPORT_MCR_RTS | COMPORT_MCR_OUT2); COMPORT_MCR_DTR | COMPORT_MCR_RTS | COMPORT_MCR_OUT2);
/* Enable FIFO */ /* Enable FIFO */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_FCR), HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_FCR),
COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET); COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET);
/* Mark port as fully initialized */ /* Mark port as fully initialized */
Flags |= COMPORT_FLAG_INIT; Flags |= COMPORT_FLAG_INIT;
/* Make sure port works in Normal Operation Mode (NOM) */ /* Make sure port works in Normal Operation Mode (NOM) */
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM); HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM);
/* Read junk data out of the Receive Buffer Register (RBR) */ /* Read junk data out of the Receive Buffer Register (RBR) */
HlIoPortInByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_RBR)); HL::IoPort::ReadPort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_RBR));
/* Store port details */ /* Store port details */
Port->Address = PortAddress; Port->Address = PortAddress;
@@ -287,3 +230,81 @@ HlInitializeComPort(IN OUT PCPPORT Port,
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/**
* This routine writes a byte to the serial port.
*
* @param Port
* Address of port object describing a port settings.
*
* @param Byte
* Data to be written.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
XTSTATUS
HL::ComPort::WriteComPort(IN PCPPORT Port,
IN UCHAR Byte)
{
UCHAR Lsr, Msr;
/* Make sure the port has been initialized */
if(Port->Address == 0)
{
return STATUS_DEVICE_NOT_READY;
}
/* Check if port is in modem control */
while(Port->Flags & COMPORT_FLAG_MC)
{
/* Get the Modem Status Register (MSR) */
Msr = HL::IoPort::ReadPort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR)) & COMPORT_MSR_DSRCTSCD;
if(Msr != COMPORT_MSR_DSRCTSCD)
{
/* Take character, if CD is not set */
Lsr = ReadComPortLsr(Port, 0);
if((Msr & COMPORT_MSR_DCD) == 0 && (Lsr & COMPORT_LSR_DR) == COMPORT_LSR_DR)
{
/* Eat the character */
HL::IoPort::ReadPort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_RBR));
}
}
else
{
/* CD, CTS and DSR are set, we can continue */
break;
}
}
/* Wait for busy port */
while((ReadComPortLsr(Port, COMPORT_LSR_THRE) & COMPORT_LSR_THRE) == 0);
/* Send byte to the port */
HL::IoPort::WritePort8(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_THR), Byte);
return STATUS_SUCCESS;
}
/* TEMPORARY FOR XTLDR */
XTCDECL
XTSTATUS
HlWriteComPort(IN PCPPORT Port,
IN UCHAR Byte)
{
return HL::ComPort::WriteComPort(Port, Byte);
}
/* TEMPORARY FOR XTLDR */
XTCDECL
XTSTATUS
HlInitializeComPort(IN OUT PCPPORT Port,
IN PUCHAR PortAddress,
IN ULONG BaudRate)
{
return HL::ComPort::InitializeComPort(Port, PortAddress, BaudRate);
}

34
xtoskrnl/hl/data.cc Normal file
View File

@@ -0,0 +1,34 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/data.cc
* DESCRIPTION: Hardware Layer global and static data
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtos.hh>
/* ACPI tables cache list */
LIST_ENTRY HL::Acpi::CacheList;
/* ACPI Root System Description Pointer (RSDP) */
PACPI_RSDP HL::Acpi::RsdpStructure;
/* System information */
ACPI_SYSTEM_INFO HL::Acpi::SystemInfo;
/* ACPI timer information */
ACPI_TIMER_INFO HL::Acpi::TimerInfo;
/* Active processors count */
KAFFINITY HL::Cpu::ActiveProcessors;
/* FrameBuffer information */
HL_FRAMEBUFFER_DATA HL::FrameBuffer::FrameBufferData;
/* Scroll region information */
HL_SCROLL_REGION_DATA HL::FrameBuffer::ScrollRegionData;
/* APIC mode */
APIC_MODE HL::Pic::ApicMode;

View File

@@ -9,6 +9,60 @@
#include <xtos.hh> #include <xtos.hh>
/**
* Reads the 8-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
UCHAR
HlReadPort8(IN USHORT Port)
{
return HL::IoPort::ReadPort8(Port);
}
/**
* Reads the 16-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
USHORT
HlReadPort16(IN USHORT Port)
{
return HL::IoPort::ReadPort16(Port);
}
/**
* Reads the 32-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
ULONG
HlReadPort32(IN USHORT Port)
{
return HL::IoPort::ReadPort32(Port);
}
/** /**
* Reads an 8-bit data from a specified register address. * Reads an 8-bit data from a specified register address.
* *
@@ -63,6 +117,72 @@ HlReadRegister32(IN PVOID Register)
return HL::IoRegister::ReadRegister32(Register); return HL::IoRegister::ReadRegister32(Register);
} }
/**
* Writes the 8-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
VOID
HlWritePort8(IN USHORT Port,
IN UCHAR Value)
{
HL::IoPort::WritePort8(Port, Value);
}
/**
* Writes the 16-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
VOID
HlWritePort16(IN USHORT Port,
IN USHORT Value)
{
HL::IoPort::WritePort16(Port, Value);
}
/**
* Writes the 32-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCLINK
XTCDECL
VOID
HlWritePort32(IN USHORT Port,
IN ULONG Value)
{
HL::IoPort::WritePort32(Port, Value);
}
/** /**
* Writes an 8-bit value into a specified register address. * Writes an 8-bit value into a specified register address.
* *

View File

@@ -1,13 +1,13 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/fbdev.c * FILE: xtoskrnl/hl/fbdev.cc
* DESCRIPTION: FrameBuffer support * DESCRIPTION: FrameBuffer support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
* Aiken Harris <harraiken91@gmail.com> * Aiken Harris <harraiken91@gmail.com>
*/ */
#include <xtos.h> #include <xtos.hh>
#include <xtfont.h> #include <xtfont.h>
@@ -23,7 +23,7 @@
*/ */
XTAPI XTAPI
VOID VOID
HlClearScreen(IN ULONG Color) HL::FrameBuffer::ClearScreen(IN ULONG Color)
{ {
ULONG PositionX, PositionY; ULONG PositionX, PositionY;
ULONG BackgroundColor; ULONG BackgroundColor;
@@ -31,22 +31,22 @@ HlClearScreen(IN ULONG Color)
PULONG Pixel; PULONG Pixel;
/* Make sure frame buffer is already initialized */ /* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE) if(FrameBufferData.Initialized == FALSE)
{ {
/* Unable to operate on non-initialized frame buffer */ /* Unable to operate on non-initialized frame buffer */
return; return;
} }
/* Convert background color and get pointer to frame buffer */ /* Convert background color and get pointer to frame buffer */
BackgroundColor = HlpRGBColor(Color); BackgroundColor = GetRGBColor(Color);
CurrentLine = HlpFrameBufferData.Address; CurrentLine = (PCHAR)FrameBufferData.Address;
/* Fill the screen with the specified color */ /* Fill the screen with the specified color */
for(PositionY = 0; PositionY < HlpFrameBufferData.Height; PositionY++, CurrentLine += HlpFrameBufferData.Pitch) for(PositionY = 0; PositionY < FrameBufferData.Height; PositionY++, CurrentLine += FrameBufferData.Pitch)
{ {
/* Fill the current line with the specified color */ /* Fill the current line with the specified color */
Pixel = (PULONG)CurrentLine; Pixel = (PULONG)CurrentLine;
for(PositionX = 0; PositionX < HlpFrameBufferData.Width; PositionX++) for(PositionX = 0; PositionX < FrameBufferData.Width; PositionX++)
{ {
/* Set the color of the pixel */ /* Set the color of the pixel */
Pixel[PositionX] = BackgroundColor; Pixel[PositionX] = BackgroundColor;
@@ -66,236 +66,65 @@ HlClearScreen(IN ULONG Color)
*/ */
XTCDECL XTCDECL
XTSTATUS XTSTATUS
HlDisplayCharacter(IN WCHAR Character) HL::FrameBuffer::DisplayCharacter(IN WCHAR Character)
{ {
PSSFN_FONT_HEADER FbFont; PSSFN_FONT_HEADER FbFont;
/* Make sure frame buffer is already initialized */ /* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE) if(FrameBufferData.Initialized == FALSE)
{ {
/* Unable to operate on non-initialized frame buffer */ /* Unable to operate on non-initialized frame buffer */
return STATUS_DEVICE_NOT_READY; return STATUS_DEVICE_NOT_READY;
} }
/* Get font information */ /* Get font information */
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font; FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
/* Handle special characters */ /* Handle special characters */
switch(Character) switch(Character)
{ {
case L'\n': case L'\n':
/* Move cursor to the beginning of the next line */ /* Move cursor to the beginning of the next line */
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left; ScrollRegionData.CursorX = ScrollRegionData.Left;
HlpScrollRegionData.CursorY += FbFont->Height; ScrollRegionData.CursorY += FbFont->Height;
break; break;
case L'\t': case L'\t':
/* Move cursor to the next tab stop */ /* Move cursor to the next tab stop */
HlpScrollRegionData.CursorX += (8 - (HlpScrollRegionData.CursorX - HlpScrollRegionData.Left) / FbFont->Width % 8) * FbFont->Width; ScrollRegionData.CursorX += (8 - (ScrollRegionData.CursorX - ScrollRegionData.Left) / FbFont->Width % 8) * FbFont->Width;
if (HlpScrollRegionData.CursorX >= HlpScrollRegionData.Right) if (ScrollRegionData.CursorX >= ScrollRegionData.Right)
{ {
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left; ScrollRegionData.CursorX = ScrollRegionData.Left;
HlpScrollRegionData.CursorY += FbFont->Height; ScrollRegionData.CursorY += FbFont->Height;
} }
break; break;
default: default:
/* Draw the character */ /* Draw the character */
HlpDrawCharacter(HlpScrollRegionData.CursorX, HlpScrollRegionData.CursorY, HlpScrollRegionData.TextColor, Character); DrawCharacter(ScrollRegionData.CursorX, ScrollRegionData.CursorY, ScrollRegionData.TextColor, Character);
/* Advance cursor */ /* Advance cursor */
HlpScrollRegionData.CursorX += FbFont->Width; ScrollRegionData.CursorX += FbFont->Width;
/* Check if cursor reached end of line */ /* Check if cursor reached end of line */
if(HlpScrollRegionData.CursorX >= HlpScrollRegionData.Right) if(ScrollRegionData.CursorX >= ScrollRegionData.Right)
{ {
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left; ScrollRegionData.CursorX = ScrollRegionData.Left;
HlpScrollRegionData.CursorY += FbFont->Height; ScrollRegionData.CursorY += FbFont->Height;
} }
break; break;
} }
/* Check if cursor reached end of scroll region */ /* Check if cursor reached end of scroll region */
if(HlpScrollRegionData.CursorY >= HlpScrollRegionData.Bottom) if(ScrollRegionData.CursorY >= ScrollRegionData.Bottom)
{ {
/* Scroll one line up */ /* Scroll one line up */
HlpScrollRegion(); ScrollRegion();
HlpScrollRegionData.CursorY = HlpScrollRegionData.Bottom - FbFont->Height; ScrollRegionData.CursorY = ScrollRegionData.Bottom - FbFont->Height;
} }
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/**
* Returns the current resolution of the frame buffer display.
*
* @param Width
* A pointer to memory area where the screen width will be stored.
*
* @param Height
* A pointer to memory area where the screen height will be stored.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlGetFrameBufferResolution(OUT PULONG Width, OUT PULONG Height)
{
*Width = HlpFrameBufferData.Width;
*Height = HlpFrameBufferData.Height;
}
/**
* Initializes frame buffer display.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTAPI
XTSTATUS
HlInitializeFrameBuffer(VOID)
{
PSYSTEM_RESOURCE_FRAMEBUFFER FrameBufferResource;
PSYSTEM_RESOURCE_HEADER SystemResource;
XTSTATUS Status;
/* Check if display already initialized */
if(HlpFrameBufferData.Initialized)
{
/* Nothing to do */
return STATUS_SUCCESS;
}
/* Get FrameBuffer system resource */
Status = KeGetSystemResource(SystemResourceFrameBuffer, &SystemResource);
if(Status != STATUS_SUCCESS)
{
/* Resource not found */
return STATUS_NOT_FOUND;
}
/* Cast system resource to FrameBuffer resource */
FrameBufferResource = (PSYSTEM_RESOURCE_FRAMEBUFFER)SystemResource;
/* Check if bootloader provided a framebuffer address */
if(!FrameBufferResource->Header.VirtualAddress)
{
/* Display probably not initialized */
return STATUS_DEVICE_NOT_READY;
}
/* Check if bootloader provided a custom font */
if(FrameBufferResource->Font)
{
/* Use custom font */
HlpFrameBufferData.Font = FrameBufferResource->Font;
}
else
{
/* Use default font */
HlpFrameBufferData.Font = (PVOID)&XtFbDefaultFont;
}
/* Save framebuffer information and mark display as initialized */
HlpFrameBufferData.Address = FrameBufferResource->Header.VirtualAddress;
HlpFrameBufferData.Width = FrameBufferResource->Width;
HlpFrameBufferData.Height = FrameBufferResource->Height;
HlpFrameBufferData.BytesPerPixel = FrameBufferResource->BitsPerPixel / 8;
HlpFrameBufferData.PixelsPerScanLine = FrameBufferResource->PixelsPerScanLine;
HlpFrameBufferData.Pitch = FrameBufferResource->Pitch;
HlpFrameBufferData.Pixels.BlueShift = FrameBufferResource->Pixels.BlueShift;
HlpFrameBufferData.Pixels.BlueSize = FrameBufferResource->Pixels.BlueSize;
HlpFrameBufferData.Pixels.GreenShift = FrameBufferResource->Pixels.GreenShift;
HlpFrameBufferData.Pixels.GreenSize = FrameBufferResource->Pixels.GreenSize;
HlpFrameBufferData.Pixels.RedShift = FrameBufferResource->Pixels.RedShift;
HlpFrameBufferData.Pixels.RedSize = FrameBufferResource->Pixels.RedSize;
HlpFrameBufferData.Pixels.ReservedShift = FrameBufferResource->Pixels.ReservedShift;
HlpFrameBufferData.Pixels.ReservedSize = FrameBufferResource->Pixels.ReservedSize;
HlpFrameBufferData.Initialized = TRUE;
/* Clear screen */
HlClearScreen(0x00000000);
/* Return success */
return STATUS_SUCCESS;
}
/**
* Sets the scrollable region of the screen and calculates character dimensions.
*
* @param Left
* Supplies the left pixel coordinate of the scroll region.
*
* @param Top
* Supplies the top pixel coordinate of the scroll region.
*
* @param Right
* Supplies the right pixel coordinate of the scroll region.
*
* @param Bottom
* Supplies the bottom pixel coordinate of the scroll region.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlInitializeScrollRegion(IN ULONG Left,
IN ULONG Top,
IN ULONG Right,
IN ULONG Bottom,
IN ULONG FontColor)
{
PSSFN_FONT_HEADER FbFont;
PCHAR PixelAddress;
/* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE)
{
/* Unable to operate on non-initialized frame buffer */
return;
}
/* Store pixel coordinates of the scroll region */
HlpScrollRegionData.Left = Left;
HlpScrollRegionData.Top = Top;
HlpScrollRegionData.Right = Right;
HlpScrollRegionData.Bottom = Bottom;
/* Get font information */
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font;
/* Validate font information */
if(FbFont && FbFont->Width > 0 && FbFont->Height > 0)
{
/* Calculate character dimensions */
HlpScrollRegionData.WidthInChars = (Right - Left) / FbFont->Width;
HlpScrollRegionData.HeightInChars = (Bottom - Top) / FbFont->Height;
/* Ensure the bottom of the scroll region is an exact multiple of the font height */
HlpScrollRegionData.Bottom = HlpScrollRegionData.Top + (HlpScrollRegionData.HeightInChars * FbFont->Height);
}
else
{
/* Fallback to 0 if font info is not available or invalid */
HlpScrollRegionData.WidthInChars = 0;
HlpScrollRegionData.HeightInChars = 0;
}
/* Initialize cursor position and font color */
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left;
HlpScrollRegionData.CursorY = HlpScrollRegionData.Top;
HlpScrollRegionData.TextColor = FontColor;
/* Get the background color by reading the pixel at the top-left corner of the scroll region */
PixelAddress = (PCHAR)HlpFrameBufferData.Address + (Top * HlpFrameBufferData.Pitch) +
(Left * HlpFrameBufferData.BytesPerPixel);
HlpScrollRegionData.BackgroundColor = *((PULONG)PixelAddress);
}
/** /**
* Draws a character on the framebuffer at the given position and color using the SSFN font. * Draws a character on the framebuffer at the given position and color using the SSFN font.
* *
@@ -317,7 +146,7 @@ HlInitializeScrollRegion(IN ULONG Left,
*/ */
XTAPI XTAPI
VOID VOID
HlpDrawCharacter(IN ULONG PositionX, HL::FrameBuffer::DrawCharacter(IN ULONG PositionX,
IN ULONG PositionY, IN ULONG PositionY,
IN ULONG Color, IN ULONG Color,
IN WCHAR WideCharacter) IN WCHAR WideCharacter)
@@ -329,14 +158,14 @@ HlpDrawCharacter(IN ULONG PositionX,
ULONG FontColor; ULONG FontColor;
/* Make sure frame buffer is already initialized */ /* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE) if(FrameBufferData.Initialized == FALSE)
{ {
/* Unable to operate on non-initialized frame buffer */ /* Unable to operate on non-initialized frame buffer */
return; return;
} }
/* Get pointers to font data */ /* Get pointers to font data */
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font; FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
CharacterMapping = (PUCHAR)FbFont + FbFont->CharactersOffset; CharacterMapping = (PUCHAR)FbFont + FbFont->CharactersOffset;
/* Find the character in the font's character table */ /* Find the character in the font's character table */
@@ -384,9 +213,9 @@ HlpDrawCharacter(IN ULONG PositionX,
} }
/* Find the glyph position on the frame buffer and set font color */ /* Find the glyph position on the frame buffer and set font color */
GlyphPixel = (UINT_PTR)HlpFrameBufferData.Address + PositionY * HlpFrameBufferData.Pitch + GlyphPixel = (UINT_PTR)FrameBufferData.Address + PositionY * FrameBufferData.Pitch +
PositionX * HlpFrameBufferData.BytesPerPixel; PositionX * FrameBufferData.BytesPerPixel;
FontColor = HlpRGBColor(Color); FontColor = GetRGBColor(Color);
/* Check all kerning fragments */ /* Check all kerning fragments */
Mapping = 0; Mapping = 0;
@@ -414,7 +243,7 @@ HlpDrawCharacter(IN ULONG PositionX,
} }
/* Get initial glyph line */ /* Get initial glyph line */
GlyphPixel += (CharacterMapping[1] - Mapping) * HlpFrameBufferData.Pitch; GlyphPixel += (CharacterMapping[1] - Mapping) * FrameBufferData.Pitch;
Mapping = CharacterMapping[1]; Mapping = CharacterMapping[1];
/* Extract glyph data from fragments table and advance */ /* Extract glyph data from fragments table and advance */
@@ -445,12 +274,12 @@ HlpDrawCharacter(IN ULONG PositionX,
} }
/* Advance pixel pointer */ /* Advance pixel pointer */
Pixel += HlpFrameBufferData.BytesPerPixel; Pixel += FrameBufferData.BytesPerPixel;
CurrentFragment <<= 1; CurrentFragment <<= 1;
} }
/* Advance to next line and increase mapping */ /* Advance to next line and increase mapping */
GlyphPixel += HlpFrameBufferData.Pitch; GlyphPixel += FrameBufferData.Pitch;
Mapping++; Mapping++;
} }
@@ -477,32 +306,54 @@ HlpDrawCharacter(IN ULONG PositionX,
*/ */
XTAPI XTAPI
VOID VOID
HlpDrawPixel(IN ULONG PositionX, HL::FrameBuffer::DrawPixel(IN ULONG PositionX,
IN ULONG PositionY, IN ULONG PositionY,
IN ULONG Color) IN ULONG Color)
{ {
PCHAR PixelAddress; PCHAR PixelAddress;
/* Make sure frame buffer is already initialized */ /* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE) if(FrameBufferData.Initialized == FALSE)
{ {
/* Unable to operate on non-initialized frame buffer */ /* Unable to operate on non-initialized frame buffer */
return; return;
} }
/* Make sure point is not offscreen */ /* Make sure point is not offscreen */
if(PositionX >= HlpFrameBufferData.Width || PositionY >= HlpFrameBufferData.Height || Color > 0xFFFFFFFF) if(PositionX >= FrameBufferData.Width || PositionY >= FrameBufferData.Height || Color > 0xFFFFFFFF)
{ {
/* Invalid pixel position or color given */ /* Invalid pixel position or color given */
return; return;
} }
/* Calculate the address of the pixel in the frame buffer memory */ /* Calculate the address of the pixel in the frame buffer memory */
PixelAddress = (PCHAR)HlpFrameBufferData.Address + (PositionY * HlpFrameBufferData.Pitch) + PixelAddress = (PCHAR)FrameBufferData.Address + (PositionY * FrameBufferData.Pitch) +
(PositionX * HlpFrameBufferData.BytesPerPixel); (PositionX * FrameBufferData.BytesPerPixel);
/* Set the color of the pixel by writing to the corresponding memory location */ /* Set the color of the pixel by writing to the corresponding memory location */
*((PULONG)PixelAddress) = HlpRGBColor(Color); *((PULONG)PixelAddress) = GetRGBColor(Color);
}
/**
* Returns the current resolution of the frame buffer display.
*
* @param Width
* A pointer to memory area where the screen width will be stored.
*
* @param Height
* A pointer to memory area where the screen height will be stored.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HL::FrameBuffer::GetFrameBufferResolution(OUT PULONG Width,
OUT PULONG Height)
{
*Width = FrameBufferData.Width;
*Height = FrameBufferData.Height;
} }
/** /**
@@ -517,7 +368,7 @@ HlpDrawPixel(IN ULONG PositionX,
*/ */
XTAPI XTAPI
ULONG ULONG
HlpRGBColor(IN ULONG Color) HL::FrameBuffer::GetRGBColor(IN ULONG Color)
{ {
USHORT Blue, Green, Red, Reserved; USHORT Blue, Green, Red, Reserved;
@@ -528,8 +379,158 @@ HlpRGBColor(IN ULONG Color)
Reserved = (USHORT)((Color >> 24) & 0xFF); Reserved = (USHORT)((Color >> 24) & 0xFF);
/* Return color in FrameBuffer pixel format */ /* Return color in FrameBuffer pixel format */
return (ULONG)((Blue << HlpFrameBufferData.Pixels.BlueShift) | (Green << HlpFrameBufferData.Pixels.GreenShift) | return (ULONG)((Blue << FrameBufferData.Pixels.BlueShift) | (Green << FrameBufferData.Pixels.GreenShift) |
(Red << HlpFrameBufferData.Pixels.RedShift) | (Reserved << HlpFrameBufferData.Pixels.ReservedShift)); (Red << FrameBufferData.Pixels.RedShift) | (Reserved << FrameBufferData.Pixels.ReservedShift));
}
/**
* Initializes frame buffer display.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTAPI
XTSTATUS
HL::FrameBuffer::InitializeFrameBuffer(VOID)
{
PSYSTEM_RESOURCE_FRAMEBUFFER FrameBufferResource;
PSYSTEM_RESOURCE_HEADER SystemResource;
XTSTATUS Status;
/* Check if display already initialized */
if(FrameBufferData.Initialized)
{
/* Nothing to do */
return STATUS_SUCCESS;
}
/* Get FrameBuffer system resource */
Status = KeGetSystemResource(SystemResourceFrameBuffer, &SystemResource);
if(Status != STATUS_SUCCESS)
{
/* Resource not found */
return STATUS_NOT_FOUND;
}
/* Cast system resource to FrameBuffer resource */
FrameBufferResource = (PSYSTEM_RESOURCE_FRAMEBUFFER)SystemResource;
/* Check if bootloader provided a framebuffer address */
if(!FrameBufferResource->Header.VirtualAddress)
{
/* Display probably not initialized */
return STATUS_DEVICE_NOT_READY;
}
/* Check if bootloader provided a custom font */
if(FrameBufferResource->Font)
{
/* Use custom font */
FrameBufferData.Font = FrameBufferResource->Font;
}
else
{
/* Use default font */
FrameBufferData.Font = (PVOID)&XtFbDefaultFont;
}
/* Save framebuffer information and mark display as initialized */
FrameBufferData.Address = FrameBufferResource->Header.VirtualAddress;
FrameBufferData.Width = FrameBufferResource->Width;
FrameBufferData.Height = FrameBufferResource->Height;
FrameBufferData.BytesPerPixel = FrameBufferResource->BitsPerPixel / 8;
FrameBufferData.PixelsPerScanLine = FrameBufferResource->PixelsPerScanLine;
FrameBufferData.Pitch = FrameBufferResource->Pitch;
FrameBufferData.Pixels.BlueShift = FrameBufferResource->Pixels.BlueShift;
FrameBufferData.Pixels.BlueSize = FrameBufferResource->Pixels.BlueSize;
FrameBufferData.Pixels.GreenShift = FrameBufferResource->Pixels.GreenShift;
FrameBufferData.Pixels.GreenSize = FrameBufferResource->Pixels.GreenSize;
FrameBufferData.Pixels.RedShift = FrameBufferResource->Pixels.RedShift;
FrameBufferData.Pixels.RedSize = FrameBufferResource->Pixels.RedSize;
FrameBufferData.Pixels.ReservedShift = FrameBufferResource->Pixels.ReservedShift;
FrameBufferData.Pixels.ReservedSize = FrameBufferResource->Pixels.ReservedSize;
FrameBufferData.Initialized = TRUE;
/* Clear screen */
ClearScreen(0x00000000);
/* Return success */
return STATUS_SUCCESS;
}
/**
* Sets the scrollable region of the screen and calculates character dimensions.
*
* @param Left
* Supplies the left pixel coordinate of the scroll region.
*
* @param Top
* Supplies the top pixel coordinate of the scroll region.
*
* @param Right
* Supplies the right pixel coordinate of the scroll region.
*
* @param Bottom
* Supplies the bottom pixel coordinate of the scroll region.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HL::FrameBuffer::InitializeScrollRegion(IN ULONG Left,
IN ULONG Top,
IN ULONG Right,
IN ULONG Bottom,
IN ULONG FontColor)
{
PSSFN_FONT_HEADER FbFont;
PCHAR PixelAddress;
/* Make sure frame buffer is already initialized */
if(FrameBufferData.Initialized == FALSE)
{
/* Unable to operate on non-initialized frame buffer */
return;
}
/* Store pixel coordinates of the scroll region */
ScrollRegionData.Left = Left;
ScrollRegionData.Top = Top;
ScrollRegionData.Right = Right;
ScrollRegionData.Bottom = Bottom;
/* Get font information */
FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
/* Validate font information */
if(FbFont && FbFont->Width > 0 && FbFont->Height > 0)
{
/* Calculate character dimensions */
ScrollRegionData.WidthInChars = (Right - Left) / FbFont->Width;
ScrollRegionData.HeightInChars = (Bottom - Top) / FbFont->Height;
/* Ensure the bottom of the scroll region is an exact multiple of the font height */
ScrollRegionData.Bottom = ScrollRegionData.Top + (ScrollRegionData.HeightInChars * FbFont->Height);
}
else
{
/* Fallback to 0 if font info is not available or invalid */
ScrollRegionData.WidthInChars = 0;
ScrollRegionData.HeightInChars = 0;
}
/* Initialize cursor position and font color */
ScrollRegionData.CursorX = ScrollRegionData.Left;
ScrollRegionData.CursorY = ScrollRegionData.Top;
ScrollRegionData.TextColor = FontColor;
/* Get the background color by reading the pixel at the top-left corner of the scroll region */
PixelAddress = (PCHAR)FrameBufferData.Address + (Top * FrameBufferData.Pitch) +
(Left * FrameBufferData.BytesPerPixel);
ScrollRegionData.BackgroundColor = *((PULONG)PixelAddress);
} }
/** /**
@@ -541,7 +542,7 @@ HlpRGBColor(IN ULONG Color)
*/ */
XTAPI XTAPI
VOID VOID
HlpScrollRegion(VOID) HL::FrameBuffer::ScrollRegion(VOID)
{ {
PCHAR Destination, Source; PCHAR Destination, Source;
PSSFN_FONT_HEADER FbFont; PSSFN_FONT_HEADER FbFont;
@@ -550,43 +551,85 @@ HlpScrollRegion(VOID)
PULONG Pixel; PULONG Pixel;
/* Make sure frame buffer is already initialized */ /* Make sure frame buffer is already initialized */
if(HlpFrameBufferData.Initialized == FALSE) if(FrameBufferData.Initialized == FALSE)
{ {
/* Unable to operate on non-initialized frame buffer */ /* Unable to operate on non-initialized frame buffer */
return; return;
} }
/* Get font information */ /* Get font information */
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font; FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
/* Calculate bytes per line in the scroll region */ /* Calculate bytes per line in the scroll region */
LineBytes = (HlpScrollRegionData.Right - HlpScrollRegionData.Left) * HlpFrameBufferData.BytesPerPixel; LineBytes = (ScrollRegionData.Right - ScrollRegionData.Left) * FrameBufferData.BytesPerPixel;
/* Scroll up each scan line in the scroll region */ /* Scroll up each scan line in the scroll region */
for(Line = HlpScrollRegionData.Top; Line < HlpScrollRegionData.Bottom - FbFont->Height; Line++) for(Line = ScrollRegionData.Top; Line < ScrollRegionData.Bottom - FbFont->Height; Line++)
{ {
Destination = (PCHAR)HlpFrameBufferData.Address + Line * HlpFrameBufferData.Pitch + Destination = (PCHAR)FrameBufferData.Address + Line * FrameBufferData.Pitch +
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel; ScrollRegionData.Left * FrameBufferData.BytesPerPixel;
/* The source is one full text line (FbFont->Height) below the destination */ /* The source is one full text line (FbFont->Height) below the destination */
Source = (PCHAR)HlpFrameBufferData.Address + (Line + FbFont->Height) * HlpFrameBufferData.Pitch + Source = (PCHAR)FrameBufferData.Address + (Line + FbFont->Height) * FrameBufferData.Pitch +
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel; ScrollRegionData.Left * FrameBufferData.BytesPerPixel;
/* Move each scan line in the scroll region up */ /* Move each scan line in the scroll region up */
RtlMoveMemory(Destination, Source, LineBytes); RTL::Memory::MoveMemory(Destination, Source, LineBytes);
} }
/* Clear the last text line */ /* Clear the last text line */
for(Line = HlpScrollRegionData.Bottom - FbFont->Height; Line < HlpScrollRegionData.Bottom; Line++) for(Line = ScrollRegionData.Bottom - FbFont->Height; Line < ScrollRegionData.Bottom; Line++)
{ {
/* Get pointer to the start of the scan line to clear */ /* Get pointer to the start of the scan line to clear */
Pixel = (PULONG)((PCHAR)HlpFrameBufferData.Address + Line * HlpFrameBufferData.Pitch + Pixel = (PULONG)((PCHAR)FrameBufferData.Address + Line * FrameBufferData.Pitch +
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel); ScrollRegionData.Left * FrameBufferData.BytesPerPixel);
/* Clear each pixel in the scan line with the background color */ /* Clear each pixel in the scan line with the background color */
for(PositionX = 0; PositionX < (HlpScrollRegionData.Right - HlpScrollRegionData.Left); PositionX++) for(PositionX = 0; PositionX < (ScrollRegionData.Right - ScrollRegionData.Left); PositionX++)
{ {
Pixel[PositionX] = HlpScrollRegionData.BackgroundColor; Pixel[PositionX] = ScrollRegionData.BackgroundColor;
} }
} }
} }
/* TEMPORARY FOR COMPATIBILITY WITH C CODE */
XTCLINK
XTCDECL
XTSTATUS
HlDisplayCharacter(IN WCHAR Character)
{
return HL::FrameBuffer::DisplayCharacter(Character);
}
/* TEMPORARY FOR COMPATIBILITY WITH C CODE */
XTCLINK
XTAPI
VOID
HlGetFrameBufferResolution(OUT PULONG Width,
OUT PULONG Height)
{
HL::FrameBuffer::GetFrameBufferResolution(Width, Height);
}
/* TEMPORARY FOR COMPATIBILITY WITH C CODE */
XTCLINK
XTAPI
XTSTATUS
HlInitializeFrameBuffer(VOID)
{
return HL::FrameBuffer::InitializeFrameBuffer();
}
/* TEMPORARY FOR COMPATIBILITY WITH C CODE */
XTCLINK
XTAPI
VOID
HlInitializeScrollRegion(IN ULONG Left,
IN ULONG Top,
IN ULONG Right,
IN ULONG Bottom,
IN ULONG FontColor)
{
HL::FrameBuffer::InitializeScrollRegion(Left, Top, Right, Bottom, FontColor);
}

View File

@@ -1,34 +0,0 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/globals.c
* DESCRIPTION: Architecture independent global variables related to HL subsystem
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtos.h>
/* ACPI tables cache list */
LIST_ENTRY HlpAcpiCacheList;
/* ACPI Root System Description Pointer (RSDP) */
PACPI_RSDP HlpAcpiRsdp;
/* ACPI timer information */
ACPI_TIMER_INFO HlpAcpiTimerInfo;
/* Active processors count */
KAFFINITY HlpActiveProcessors;
/* APIC mode */
APIC_MODE HlpApicMode;
/* FrameBuffer information */
HL_FRAMEBUFFER_DATA HlpFrameBufferData;
/* Scroll region information */
HL_SCROLL_REGION_DATA HlpScrollRegionData;
/* System information */
ACPI_SYSTEM_INFO HlpSystemInfo;

View File

@@ -1,13 +1,13 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/i686/cpu.c * FILE: xtoskrnl/hl/i686/cpu.cc
* DESCRIPTION: HAL i686 processor support * DESCRIPTION: HAL i686 processor support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/* Include common CPU interface */ /* Include common CPU interface */
#include ARCH_COMMON(cpu.c) #include ARCH_COMMON(cpu.cc)

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/i686/ioport.c * FILE: xtoskrnl/hl/i686/ioport.cc
* DESCRIPTION: I/O port access routines for i686 platform * DESCRIPTION: I/O port access routines for i686 platform
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -21,7 +21,7 @@
*/ */
XTCDECL XTCDECL
UCHAR UCHAR
HlIoPortInByte(IN USHORT Port) HL::IoPort::ReadPort8(IN USHORT Port)
{ {
UCHAR Value; UCHAR Value;
__asm__ volatile("inb %1, %0" __asm__ volatile("inb %1, %0"
@@ -30,27 +30,6 @@ HlIoPortInByte(IN USHORT Port)
return Value; return Value;
} }
/**
* Reads the 32-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCDECL
ULONG
HlIoPortInLong(IN USHORT Port)
{
ULONG Value;
__asm__ volatile("inl %1, %0"
: "=a" (Value)
: "Nd" (Port));
return Value;
}
/** /**
* Reads the 16-bit data from the specified I/O port. * Reads the 16-bit data from the specified I/O port.
* *
@@ -63,7 +42,7 @@ HlIoPortInLong(IN USHORT Port)
*/ */
XTCDECL XTCDECL
USHORT USHORT
HlIoPortInShort(IN USHORT Port) HL::IoPort::ReadPort16(IN USHORT Port)
{ {
USHORT Value; USHORT Value;
__asm__ volatile("inw %1, %0" __asm__ volatile("inw %1, %0"
@@ -72,6 +51,27 @@ HlIoPortInShort(IN USHORT Port)
return Value; return Value;
} }
/**
* Reads the 32-bit data from the specified I/O port.
*
* @param Port
* Specifies the address to read from, in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTCDECL
ULONG
HL::IoPort::ReadPort32(IN USHORT Port)
{
ULONG Value;
__asm__ volatile("inl %1, %0"
: "=a" (Value)
: "Nd" (Port));
return Value;
}
/** /**
* Writes the 8-bit data to the specified I/O port. * Writes the 8-bit data to the specified I/O port.
* *
@@ -87,7 +87,7 @@ HlIoPortInShort(IN USHORT Port)
*/ */
XTCDECL XTCDECL
VOID VOID
HlIoPortOutByte(IN USHORT Port, HL::IoPort::WritePort8(IN USHORT Port,
IN UCHAR Value) IN UCHAR Value)
{ {
__asm__ volatile("outb %0, %1" __asm__ volatile("outb %0, %1"
@@ -96,30 +96,6 @@ HlIoPortOutByte(IN USHORT Port,
"Nd" (Port)); "Nd" (Port));
} }
/**
* Writes the 32-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
HlIoPortOutLong(IN USHORT Port,
IN ULONG Value)
{
__asm__ volatile("outl %0, %1"
:
: "a" (Value),
"Nd" (Port));
}
/** /**
* Writes the 16-bit data to the specified I/O port. * Writes the 16-bit data to the specified I/O port.
* *
@@ -135,7 +111,7 @@ HlIoPortOutLong(IN USHORT Port,
*/ */
XTCDECL XTCDECL
VOID VOID
HlIoPortOutShort(IN USHORT Port, HL::IoPort::WritePort16(IN USHORT Port,
IN USHORT Value) IN USHORT Value)
{ {
__asm__ volatile("outw %0, %1" __asm__ volatile("outw %0, %1"
@@ -143,3 +119,27 @@ HlIoPortOutShort(IN USHORT Port,
: "a" (Value), : "a" (Value),
"Nd" (Port)); "Nd" (Port));
} }
/**
* Writes the 32-bit data to the specified I/O port.
*
* @param Port
* Specifies the address to write to, in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
HL::IoPort::WritePort32(IN USHORT Port,
IN ULONG Value)
{
__asm__ volatile("outl %0, %1"
:
: "a" (Value),
"Nd" (Port));
}

View File

@@ -1,13 +1,13 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/i686/pic.c * FILE: xtoskrnl/hl/i686/pic.cc
* DESCRIPTION: Programmable Interrupt Controller (PIC) for i686 support * DESCRIPTION: Programmable Interrupt Controller (PIC) for i686 support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/* Include common PIC interface */ /* Include common PIC interface */
#include ARCH_COMMON(pic.c) #include ARCH_COMMON(pic.cc)

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/i686/runlevel.c * FILE: xtoskrnl/hl/i686/runlevel.cc
* DESCRIPTION: Run Level management support for i686 architecture * DESCRIPTION: Run Level management support for i686 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -18,9 +18,9 @@
*/ */
XTFASTCALL XTFASTCALL
KRUNLEVEL KRUNLEVEL
HlGetRunLevel(VOID) HL::RunLevel::GetRunLevel(VOID)
{ {
return HlpTransformApicTprToRunLevel(HlReadApicRegister(APIC_TPR)); return TransformApicTprToRunLevel(HL::Pic::ReadApicRegister(APIC_TPR));
} }
/** /**
@@ -35,9 +35,9 @@ HlGetRunLevel(VOID)
*/ */
XTFASTCALL XTFASTCALL
VOID VOID
HlSetRunLevel(IN KRUNLEVEL RunLevel) HL::RunLevel::SetRunLevel(IN KRUNLEVEL RunLevel)
{ {
HlWriteApicRegister(APIC_TPR, HlpTransformRunLevelToApicTpr(RunLevel)); HL::Pic::WriteApicRegister(APIC_TPR, TransformRunLevelToApicTpr(RunLevel));
} }
/** /**
@@ -52,7 +52,7 @@ HlSetRunLevel(IN KRUNLEVEL RunLevel)
*/ */
XTFASTCALL XTFASTCALL
KRUNLEVEL KRUNLEVEL
HlpTransformApicTprToRunLevel(IN UCHAR Tpr) HL::RunLevel::TransformApicTprToRunLevel(IN UCHAR Tpr)
{ {
STATIC KRUNLEVEL TransformationTable[16] = STATIC KRUNLEVEL TransformationTable[16] =
{ {
@@ -90,7 +90,7 @@ HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
*/ */
XTFASTCALL XTFASTCALL
UCHAR UCHAR
HlpTransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel) HL::RunLevel::TransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
{ {
STATIC UCHAR TransformationTable[32] = STATIC UCHAR TransformationTable[32] =
{ {

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/init.c * FILE: xtoskrnl/hl/init.cc
* DESCRIPTION: Hardware layer initialization code * DESCRIPTION: Hardware layer initialization code
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -18,19 +18,19 @@
*/ */
XTAPI XTAPI
XTSTATUS XTSTATUS
HlInitializeSystem(VOID) HL::Init::InitializeSystem(VOID)
{ {
XTSTATUS Status; XTSTATUS Status;
/* Initialize ACPI */ /* Initialize ACPI */
Status = HlpInitializeAcpi(); Status = Acpi::InitializeAcpi();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
return Status; return Status;
} }
/* Get system information from ACPI */ /* Get system information from ACPI */
Status = HlpInitializeAcpiSystemInformation(); Status = Acpi::InitializeAcpiSystemInformation();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
return Status; return Status;

View File

@@ -1,12 +1,12 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/x86/cpu.c * FILE: xtoskrnl/hl/x86/cpu.cc
* DESCRIPTION: HAL x86 (i686/AMD64) processor support * DESCRIPTION: HAL x86 (i686/AMD64) processor support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/** /**
@@ -21,13 +21,13 @@
*/ */
XTAPI XTAPI
VOID VOID
HlInitializeProcessor(VOID) HL::Cpu::InitializeProcessor(VOID)
{ {
PKPROCESSOR_BLOCK ProcessorBlock; PKPROCESSOR_BLOCK ProcessorBlock;
KAFFINITY Affinity; KAFFINITY Affinity;
/* Get current processor block */ /* Get current processor block */
ProcessorBlock = KeGetCurrentProcessorBlock(); ProcessorBlock = KE::Processor::GetCurrentProcessorBlock();
/* Set initial stall factor, CPU number and mask interrupts */ /* Set initial stall factor, CPU number and mask interrupts */
ProcessorBlock->StallScaleFactor = INITIAL_STALL_FACTOR; ProcessorBlock->StallScaleFactor = INITIAL_STALL_FACTOR;
@@ -37,11 +37,11 @@ HlInitializeProcessor(VOID)
Affinity = (KAFFINITY) 1 << ProcessorBlock->CpuNumber; Affinity = (KAFFINITY) 1 << ProcessorBlock->CpuNumber;
/* Apply affinity to a set of processors */ /* Apply affinity to a set of processors */
HlpActiveProcessors |= Affinity; ActiveProcessors |= Affinity;
/* Initialize APIC for this processor */ /* Initialize APIC for this processor */
HlpInitializePic(); Pic::InitializePic();
/* Set the APIC running level */ /* Set the APIC running level */
HlSetRunLevel(KeGetCurrentProcessorBlock()->RunLevel); HL::RunLevel::SetRunLevel(KeGetCurrentProcessorBlock()->RunLevel);
} }

View File

@@ -1,100 +1,14 @@
/** /**
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/x86/pic.c * FILE: xtoskrnl/hl/x86/pic.cc
* DESCRIPTION: Programmable Interrupt Controller (PIC) for x86 (i686/AMD64) support * DESCRIPTION: Programmable Interrupt Controller (PIC) for x86 (i686/AMD64) support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/ */
#include <xtos.h> #include <xtos.hh>
/**
* Clears all errors on the APIC.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlClearApicErrors(VOID)
{
/* Clear APIC errors */
HlWriteApicRegister(APIC_ESR, 0);
}
/**
* Reads from the APIC register.
*
* @param Register
* Supplies the APIC register to read from.
*
* @return This routine returns the value read from the APIC register.
*
* @since XT 1.0
*/
XTFASTCALL
ULONGLONG
HlReadApicRegister(IN APIC_REGISTER Register)
{
if(HlpApicMode == APIC_MODE_X2APIC)
{
/* Read from x2APIC MSR */
return ArReadModelSpecificRegister((ULONG)(APIC_X2APIC_MSR_BASE + Register));
}
else
{
/* Read from xAPIC */
return HlReadRegister32((PULONG)(APIC_BASE + (Register << 4)));
}
}
/**
* Signals to the APIC that handling an interrupt is complete.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlSendEoi(VOID)
{
/* Send APIC EOI */
HlWriteApicRegister(APIC_EOI, 0);
}
/**
* Writes to the APIC register.
*
* @param Register
* Supplies the APIC register to write to.
*
* @param Value
* Supplies the value to write to the APIC register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTFASTCALL
VOID
HlWriteApicRegister(IN APIC_REGISTER Register,
IN ULONGLONG Value)
{
if(HlpApicMode == APIC_MODE_X2APIC)
{
/* Write to x2APIC MSR */
ArWriteModelSpecificRegister((ULONG)(APIC_X2APIC_MSR_BASE + Register), Value);
}
else
{
/* Write to xAPIC */
HlWriteRegister32((PULONG)(APIC_BASE + (Register << 4)), Value);
}
}
/** /**
* Checks whether the x2APIC extension is supported by the processor. * Checks whether the x2APIC extension is supported by the processor.
* *
@@ -107,7 +21,7 @@ HlWriteApicRegister(IN APIC_REGISTER Register,
*/ */
XTAPI XTAPI
BOOLEAN BOOLEAN
HlpCheckX2ApicSupport(VOID) HL::Pic::CheckX2ApicSupport(VOID)
{ {
CPUID_REGISTERS CpuRegisters; CPUID_REGISTERS CpuRegisters;
@@ -133,6 +47,21 @@ HlpCheckX2ApicSupport(VOID)
return TRUE; return TRUE;
} }
/**
* Clears all errors on the APIC.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HL::Pic::ClearApicErrors(VOID)
{
/* Clear APIC errors */
WriteApicRegister(APIC_ESR, 0);
}
/** /**
* Gets the local APIC ID of the current processor. * Gets the local APIC ID of the current processor.
* *
@@ -142,15 +71,15 @@ HlpCheckX2ApicSupport(VOID)
*/ */
XTAPI XTAPI
ULONG ULONG
HlpGetCpuApicId(VOID) HL::Pic::GetCpuApicId(VOID)
{ {
ULONG ApicId; ULONG ApicId;
/* Read APIC ID register */ /* Read APIC ID register */
ApicId = HlReadApicRegister(APIC_ID); ApicId = ReadApicRegister(APIC_ID);
/* Return logical CPU ID depending on current APIC mode */ /* Return logical CPU ID depending on current APIC mode */
return (HlpApicMode == APIC_MODE_COMPAT) ? ((ApicId & 0xFFFFFFFF) >> APIC_XAPIC_LDR_SHIFT) : ApicId; return (ApicMode == APIC_MODE_COMPAT) ? ((ApicId & 0xFFFFFFFF) >> APIC_XAPIC_LDR_SHIFT) : ApicId;
} }
/** /**
@@ -162,7 +91,7 @@ HlpGetCpuApicId(VOID)
*/ */
XTCDECL XTCDECL
VOID VOID
HlpHandleApicSpuriousService(VOID) HL::Pic::HandleApicSpuriousService(VOID)
{ {
} }
@@ -175,7 +104,7 @@ HlpHandleApicSpuriousService(VOID)
*/ */
XTCDECL XTCDECL
VOID VOID
HlpHandlePicSpuriousService(VOID) HL::Pic::HandlePicSpuriousService(VOID)
{ {
} }
@@ -188,7 +117,7 @@ HlpHandlePicSpuriousService(VOID)
*/ */
XTAPI XTAPI
VOID VOID
HlpInitializeApic(VOID) HL::Pic::InitializeApic(VOID)
{ {
APIC_SPURIOUS_REGISTER SpuriousRegister; APIC_SPURIOUS_REGISTER SpuriousRegister;
APIC_BASE_REGISTER BaseRegister; APIC_BASE_REGISTER BaseRegister;
@@ -196,49 +125,49 @@ HlpInitializeApic(VOID)
ULONG CpuNumber; ULONG CpuNumber;
/* Determine APIC mode (xAPIC compatibility or x2APIC) */ /* Determine APIC mode (xAPIC compatibility or x2APIC) */
if(HlpCheckX2ApicSupport()) if(CheckX2ApicSupport())
{ {
/* Enable x2APIC mode */ /* Enable x2APIC mode */
HlpApicMode = APIC_MODE_X2APIC; ApicMode = APIC_MODE_X2APIC;
} }
else else
{ {
/* Fall back to xAPIC compatibility mode */ /* Fall back to xAPIC compatibility mode */
HlpApicMode = APIC_MODE_COMPAT; ApicMode = APIC_MODE_COMPAT;
} }
/* Get current processor number */ /* Get current processor number */
CpuNumber = KeGetCurrentProcessorNumber(); CpuNumber = KE::Processor::GetCurrentProcessorNumber();
/* Enable the APIC */ /* Enable the APIC */
BaseRegister.LongLong = ArReadModelSpecificRegister(APIC_LAPIC_MSR_BASE); BaseRegister.LongLong = AR::CpuFunc::ReadModelSpecificRegister(APIC_LAPIC_MSR_BASE);
BaseRegister.Enable = 1; BaseRegister.Enable = 1;
BaseRegister.ExtendedMode = (HlpApicMode == APIC_MODE_X2APIC); BaseRegister.ExtendedMode = (ApicMode == APIC_MODE_X2APIC);
BaseRegister.BootStrapProcessor = (CpuNumber == 0) ? 1 : 0; BaseRegister.BootStrapProcessor = (CpuNumber == 0) ? 1 : 0;
ArWriteModelSpecificRegister(APIC_LAPIC_MSR_BASE, BaseRegister.LongLong); AR::CpuFunc::WriteModelSpecificRegister(APIC_LAPIC_MSR_BASE, BaseRegister.LongLong);
/* Mask all interrupts by raising Task Priority Register (TPR) */ /* Mask all interrupts by raising Task Priority Register (TPR) */
HlWriteApicRegister(APIC_TPR, 0xFF); WriteApicRegister(APIC_TPR, 0xFF);
/* Perform initialization specific to xAPIC compatibility mode */ /* Perform initialization specific to xAPIC compatibility mode */
if(HlpApicMode == APIC_MODE_COMPAT) if(ApicMode == APIC_MODE_COMPAT)
{ {
/* Use Flat Model for destination format (not supported in x2APIC) */ /* Use Flat Model for destination format (not supported in x2APIC) */
HlWriteApicRegister(APIC_DFR, APIC_DF_FLAT); WriteApicRegister(APIC_DFR, APIC_DF_FLAT);
/* Set the logical APIC ID for this processor (read-only in x2APIC) */ /* Set the logical APIC ID for this processor (read-only in x2APIC) */
HlWriteApicRegister(APIC_LDR, (1UL << CpuNumber) << 24); WriteApicRegister(APIC_LDR, (1UL << CpuNumber) << 24);
} }
/* Configure the spurious interrupt vector */ /* Configure the spurious interrupt vector */
SpuriousRegister.Long = HlReadApicRegister(APIC_SIVR); SpuriousRegister.Long = ReadApicRegister(APIC_SIVR);
SpuriousRegister.Vector = APIC_VECTOR_SPURIOUS; SpuriousRegister.Vector = APIC_VECTOR_SPURIOUS;
SpuriousRegister.SoftwareEnable = 1; SpuriousRegister.SoftwareEnable = 1;
SpuriousRegister.CoreChecking = 0; SpuriousRegister.CoreChecking = 0;
HlWriteApicRegister(APIC_SIVR, SpuriousRegister.Long); WriteApicRegister(APIC_SIVR, SpuriousRegister.Long);
/* Setup the LVT Error entry to deliver APIC errors on a dedicated vector */ /* Setup the LVT Error entry to deliver APIC errors on a dedicated vector */
HlWriteApicRegister(APIC_ERRLVTR, APIC_VECTOR_ERROR); WriteApicRegister(APIC_ERRLVTR, APIC_VECTOR_ERROR);
/* Program the APIC timer for periodic mode */ /* Program the APIC timer for periodic mode */
LvtRegister.Long = 0; LvtRegister.Long = 0;
@@ -247,7 +176,7 @@ HlpInitializeApic(VOID)
LvtRegister.TimerMode = 1; LvtRegister.TimerMode = 1;
LvtRegister.TriggerMode = APIC_TGM_EDGE; LvtRegister.TriggerMode = APIC_TGM_EDGE;
LvtRegister.Vector = APIC_VECTOR_PROFILE; LvtRegister.Vector = APIC_VECTOR_PROFILE;
HlWriteApicRegister(APIC_TMRLVTR, LvtRegister.Long); WriteApicRegister(APIC_TMRLVTR, LvtRegister.Long);
/* Configure the performance counter overflow */ /* Configure the performance counter overflow */
LvtRegister.Long = 0; LvtRegister.Long = 0;
@@ -256,7 +185,7 @@ HlpInitializeApic(VOID)
LvtRegister.TimerMode = 0; LvtRegister.TimerMode = 0;
LvtRegister.TriggerMode = APIC_TGM_EDGE; LvtRegister.TriggerMode = APIC_TGM_EDGE;
LvtRegister.Vector = APIC_VECTOR_PERF; LvtRegister.Vector = APIC_VECTOR_PERF;
HlWriteApicRegister(APIC_PCLVTR, LvtRegister.Long); WriteApicRegister(APIC_PCLVTR, LvtRegister.Long);
/* Configure the LINT0 pin */ /* Configure the LINT0 pin */
LvtRegister.Long = 0; LvtRegister.Long = 0;
@@ -265,7 +194,7 @@ HlpInitializeApic(VOID)
LvtRegister.TimerMode = 0; LvtRegister.TimerMode = 0;
LvtRegister.TriggerMode = APIC_TGM_EDGE; LvtRegister.TriggerMode = APIC_TGM_EDGE;
LvtRegister.Vector = APIC_VECTOR_SPURIOUS; LvtRegister.Vector = APIC_VECTOR_SPURIOUS;
HlWriteApicRegister(APIC_LINT0, LvtRegister.Long); WriteApicRegister(APIC_LINT0, LvtRegister.Long);
/* Configure the LINT1 pin */ /* Configure the LINT1 pin */
LvtRegister.Long = 0; LvtRegister.Long = 0;
@@ -274,17 +203,17 @@ HlpInitializeApic(VOID)
LvtRegister.TimerMode = 0; LvtRegister.TimerMode = 0;
LvtRegister.TriggerMode = APIC_TGM_EDGE; LvtRegister.TriggerMode = APIC_TGM_EDGE;
LvtRegister.Vector = APIC_VECTOR_NMI; LvtRegister.Vector = APIC_VECTOR_NMI;
HlWriteApicRegister(APIC_LINT1, LvtRegister.Long); WriteApicRegister(APIC_LINT1, LvtRegister.Long);
/* Register interrupt handlers */ /* Register interrupt handlers */
KeSetInterruptHandler(APIC_VECTOR_SPURIOUS, HlpHandleApicSpuriousService); KE::Irq::SetInterruptHandler(APIC_VECTOR_SPURIOUS, (PVOID)HandleApicSpuriousService);
KeSetInterruptHandler(PIC1_VECTOR_SPURIOUS, HlpHandlePicSpuriousService); KE::Irq::SetInterruptHandler(PIC1_VECTOR_SPURIOUS, (PVOID)HandlePicSpuriousService);
/* Clear any pre-existing errors */ /* Clear any pre-existing errors */
HlWriteApicRegister(APIC_ESR, 0); WriteApicRegister(APIC_ESR, 0);
/* Re-enable all interrupts by lowering the Task Priority Register */ /* Re-enable all interrupts by lowering the Task Priority Register */
HlWriteApicRegister(APIC_TPR, 0x00); WriteApicRegister(APIC_TPR, 0x00);
} }
/** /**
@@ -296,7 +225,7 @@ HlpInitializeApic(VOID)
*/ */
XTAPI XTAPI
VOID VOID
HlpInitializeLegacyPic(VOID) HL::Pic::InitializeLegacyPic(VOID)
{ {
PIC_I8259_ICW1 Icw1; PIC_I8259_ICW1 Icw1;
PIC_I8259_ICW2 Icw2; PIC_I8259_ICW2 Icw2;
@@ -310,16 +239,16 @@ HlpInitializeLegacyPic(VOID)
Icw1.Interval = Interval8; Icw1.Interval = Interval8;
Icw1.NeedIcw4 = TRUE; Icw1.NeedIcw4 = TRUE;
Icw1.OperatingMode = Cascade; Icw1.OperatingMode = Cascade;
HlIoPortOutByte(PIC1_CONTROL_PORT, Icw1.Bits); HL::IoPort::WritePort8(PIC1_CONTROL_PORT, Icw1.Bits);
/* Initialize ICW2 for PIC1 port */ /* Initialize ICW2 for PIC1 port */
Icw2.Bits = 0x00; Icw2.Bits = 0x00;
HlIoPortOutByte(PIC1_DATA_PORT, Icw2.Bits); HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw2.Bits);
/* Initialize ICW3 for PIC1 port */ /* Initialize ICW3 for PIC1 port */
Icw3.Bits = 0; Icw3.Bits = 0;
Icw3.SlaveIrq2 = TRUE; Icw3.SlaveIrq2 = TRUE;
HlIoPortOutByte(PIC1_DATA_PORT, Icw3.Bits); HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw3.Bits);
/* Initialize ICW4 for PIC1 port */ /* Initialize ICW4 for PIC1 port */
Icw4.BufferedMode = NonBuffered; Icw4.BufferedMode = NonBuffered;
@@ -327,10 +256,10 @@ HlpInitializeLegacyPic(VOID)
Icw4.Reserved = 0; Icw4.Reserved = 0;
Icw4.SpecialFullyNestedMode = FALSE; Icw4.SpecialFullyNestedMode = FALSE;
Icw4.SystemMode = New8086Mode; Icw4.SystemMode = New8086Mode;
HlIoPortOutByte(PIC1_DATA_PORT, Icw4.Bits); HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw4.Bits);
/* Mask all interrupts on PIC1 port */ /* Mask all interrupts on PIC1 port */
HlIoPortOutByte(PIC1_DATA_PORT, 0xFF); HL::IoPort::WritePort8(PIC1_DATA_PORT, 0xFF);
/* Initialize ICW1 for PIC2 port */ /* Initialize ICW1 for PIC2 port */
Icw1.Init = TRUE; Icw1.Init = TRUE;
@@ -339,16 +268,16 @@ HlpInitializeLegacyPic(VOID)
Icw1.Interval = Interval8; Icw1.Interval = Interval8;
Icw1.NeedIcw4 = TRUE; Icw1.NeedIcw4 = TRUE;
Icw1.OperatingMode = Cascade; Icw1.OperatingMode = Cascade;
HlIoPortOutByte(PIC2_CONTROL_PORT, Icw1.Bits); HL::IoPort::WritePort8(PIC2_CONTROL_PORT, Icw1.Bits);
/* Initialize ICW2 for PIC2 port */ /* Initialize ICW2 for PIC2 port */
Icw2.Bits = 0x08; Icw2.Bits = 0x08;
HlIoPortOutByte(PIC2_DATA_PORT, Icw2.Bits); HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw2.Bits);
/* Initialize ICW3 for PIC2 port */ /* Initialize ICW3 for PIC2 port */
Icw3.Bits = 0; Icw3.Bits = 0;
Icw3.SlaveId = 2; Icw3.SlaveId = 2;
HlIoPortOutByte(PIC2_DATA_PORT, Icw3.Bits); HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw3.Bits);
/* Initialize ICW4 for PIC2 port */ /* Initialize ICW4 for PIC2 port */
Icw4.BufferedMode = NonBuffered; Icw4.BufferedMode = NonBuffered;
@@ -356,10 +285,10 @@ HlpInitializeLegacyPic(VOID)
Icw4.Reserved = 0; Icw4.Reserved = 0;
Icw4.SpecialFullyNestedMode = FALSE; Icw4.SpecialFullyNestedMode = FALSE;
Icw4.SystemMode = New8086Mode; Icw4.SystemMode = New8086Mode;
HlIoPortOutByte(PIC2_DATA_PORT, Icw4.Bits); HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw4.Bits);
/* Mask all interrupts on PIC2 port */ /* Mask all interrupts on PIC2 port */
HlIoPortOutByte(PIC2_DATA_PORT, 0xFF); HL::IoPort::WritePort8(PIC2_DATA_PORT, 0xFF);
} }
/** /**
@@ -373,13 +302,54 @@ HlpInitializeLegacyPic(VOID)
*/ */
XTAPI XTAPI
VOID VOID
HlpInitializePic(VOID) HL::Pic::InitializePic(VOID)
{ {
/* Initialize APIC */ /* Initialize APIC */
HlpInitializeApic(); InitializeApic();
/* Initialize legacy PIC */ /* Initialize legacy PIC */
HlpInitializeLegacyPic(); InitializeLegacyPic();
}
/**
* Reads from the APIC register.
*
* @param Register
* Supplies the APIC register to read from.
*
* @return This routine returns the value read from the APIC register.
*
* @since XT 1.0
*/
XTFASTCALL
ULONGLONG
HL::Pic::ReadApicRegister(IN APIC_REGISTER Register)
{
if(ApicMode == APIC_MODE_X2APIC)
{
/* Read from x2APIC MSR */
return AR::CpuFunc::ReadModelSpecificRegister((ULONG)(APIC_X2APIC_MSR_BASE + Register));
}
else
{
/* Read from xAPIC */
return IoRegister::ReadRegister32((PULONG)(APIC_BASE + (Register << 4)));
}
}
/**
* Signals to the APIC that handling an interrupt is complete.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HL::Pic::SendEoi(VOID)
{
/* Send APIC EOI */
WriteApicRegister(APIC_EOI, 0);
} }
/** /**
@@ -397,19 +367,49 @@ HlpInitializePic(VOID)
*/ */
XTAPI XTAPI
VOID VOID
HlpSendIpi(ULONG ApicId, HL::Pic::SendIpi(ULONG ApicId,
ULONG Vector) ULONG Vector)
{ {
/* Check current APIC mode */ /* Check current APIC mode */
if(HlpApicMode == APIC_MODE_X2APIC) if(ApicMode == APIC_MODE_X2APIC)
{ {
/* Send IPI using x2APIC mode */ /* Send IPI using x2APIC mode */
HlWriteApicRegister(APIC_ICR0, ((ULONGLONG)ApicId << 32) | Vector); WriteApicRegister(APIC_ICR0, ((ULONGLONG)ApicId << 32) | Vector);
} }
else else
{ {
/* Send IPI using xAPIC compatibility mode */ /* Send IPI using xAPIC compatibility mode */
HlWriteApicRegister(APIC_ICR1, ApicId << 24); WriteApicRegister(APIC_ICR1, ApicId << 24);
HlWriteApicRegister(APIC_ICR0, Vector); WriteApicRegister(APIC_ICR0, Vector);
}
}
/**
* Writes to the APIC register.
*
* @param Register
* Supplies the APIC register to write to.
*
* @param Value
* Supplies the value to write to the APIC register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTFASTCALL
VOID
HL::Pic::WriteApicRegister(IN APIC_REGISTER Register,
IN ULONGLONG Value)
{
if(ApicMode == APIC_MODE_X2APIC)
{
/* Write to x2APIC MSR */
AR::CpuFunc::WriteModelSpecificRegister((ULONG)(APIC_X2APIC_MSR_BASE + Register), Value);
}
else
{
/* Write to xAPIC */
IoRegister::WriteRegister32((PULONG)(APIC_BASE + (Register << 4)), Value);
} }
} }

View File

@@ -11,7 +11,15 @@
#include <xtos.hh> #include <xtos.hh>
#include <hl/acpi.hh>
#include <hl/cport.hh>
#include <hl/cpu.hh>
#include <hl/fbdev.hh>
#include <hl/init.hh>
#include <hl/ioport.hh>
#include <hl/ioreg.hh> #include <hl/ioreg.hh>
#include <hl/pic.hh>
#include <hl/runlevel.hh>
#endif /* __XTOSKRNL_HL_HH */ #endif /* __XTOSKRNL_HL_HH */

View File

@@ -0,0 +1,48 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/acpi.hh
* DESCRIPTION: Advanced Configuration and Power Interface (ACPI) support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_ACPI_HH
#define __XTOSKRNL_HL_ACPI_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class Acpi
{
private:
STATIC LIST_ENTRY CacheList;
STATIC PACPI_RSDP RsdpStructure;
STATIC ACPI_SYSTEM_INFO SystemInfo;
STATIC ACPI_TIMER_INFO TimerInfo;
public:
STATIC XTAPI XTSTATUS GetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp);
STATIC XTAPI XTSTATUS GetAcpiTable(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable);
STATIC XTAPI XTSTATUS InitializeAcpi(VOID);
STATIC XTAPI XTSTATUS InitializeAcpiSystemInformation(VOID);
private:
STATIC XTAPI VOID CacheAcpiTable(IN PACPI_DESCRIPTION_HEADER AcpiTable);
STATIC XTAPI XTSTATUS InitializeAcpiCache(VOID);
STATIC XTAPI XTSTATUS InitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable);
STATIC XTAPI XTSTATUS InitializeAcpiSystemStructure(VOID);
STATIC XTAPI XTSTATUS InitializeAcpiTimer(VOID);
STATIC XTAPI XTSTATUS QueryAcpiCache(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable);
STATIC XTAPI XTSTATUS QueryAcpiTables(IN ULONG Signature,
OUT PACPI_DESCRIPTION_HEADER *AcpiTable);
STATIC XTAPI BOOLEAN ValidateAcpiTable(IN PVOID Buffer,
IN UINT_PTR Size);
};
}
#endif /* __XTOSKRNL_HL_ACPI_HH */

View File

@@ -0,0 +1,35 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/cpu.hh
* DESCRIPTION: Serial (COM) port support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_CPORT_HH
#define __XTOSKRNL_HL_CPORT_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class ComPort
{
public:
STATIC XTCDECL XTSTATUS ReadComPort(IN PCPPORT Port,
OUT PUCHAR Byte,
IN BOOLEAN Wait,
IN BOOLEAN Poll);
STATIC XTCDECL UCHAR ReadComPortLsr(IN PCPPORT Port,
IN UCHAR Byte);
STATIC XTCDECL XTSTATUS InitializeComPort(IN OUT PCPPORT Port,
IN PUCHAR PortAddress,
IN ULONG BaudRate);
STATIC XTCDECL XTSTATUS WriteComPort(IN PCPPORT Port,
IN UCHAR Byte);
};
}
#endif /* __XTOSKRNL_HL_CPORT_HH */

View File

@@ -0,0 +1,27 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/cpu.hh
* DESCRIPTION: HAL processor support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_CPU_HH
#define __XTOSKRNL_HL_CPU_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class Cpu
{
private:
STATIC KAFFINITY ActiveProcessors;
public:
STATIC XTAPI VOID InitializeProcessor(VOID);
};
}
#endif /* __XTOSKRNL_HL_CPU_HH */

View File

@@ -0,0 +1,50 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/fbdev.hh
* DESCRIPTION: FrameBuffer support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_FBDEV_HH
#define __XTOSKRNL_HL_FBDEV_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class FrameBuffer
{
private:
STATIC HL_FRAMEBUFFER_DATA FrameBufferData;
STATIC HL_SCROLL_REGION_DATA ScrollRegionData;
public:
STATIC XTAPI VOID ClearScreen(IN ULONG Color);
STATIC XTCDECL XTSTATUS DisplayCharacter(IN WCHAR Character);
STATIC XTAPI VOID GetFrameBufferResolution(OUT PULONG Width,
OUT PULONG Height);
STATIC XTAPI XTSTATUS InitializeFrameBuffer(VOID);
STATIC XTAPI VOID InitializeScrollRegion(IN ULONG Left,
IN ULONG Top,
IN ULONG Right,
IN ULONG Bottom,
IN ULONG FontColor);
private:
STATIC XTAPI VOID DrawCharacter(IN ULONG PositionX,
IN ULONG PositionY,
IN ULONG Color,
IN WCHAR WideCharacter);
STATIC XTAPI VOID DrawPixel(IN ULONG PositionX,
IN ULONG PositionY,
IN ULONG Color);
STATIC XTAPI ULONG GetRGBColor(IN ULONG Color);
STATIC XTAPI VOID ScrollRegion(VOID);
};
}
#endif /* __XTOSKRNL_HL_FBDEV_HH */

View File

@@ -0,0 +1,25 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/init.hh
* DESCRIPTION: Hardware layer initialization
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_INIT_HH
#define __XTOSKRNL_HL_INIT_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class Init
{
public:
STATIC XTAPI XTSTATUS InitializeSystem(VOID);
};
}
#endif /* __XTOSKRNL_HL_INIT_HH */

View File

@@ -0,0 +1,33 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/ioport.hh
* DESCRIPTION: I/O port access routines
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_IOPORT_HH
#define __XTOSKRNL_HL_IOPORT_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class IoPort
{
public:
STATIC XTCDECL UCHAR ReadPort8(IN USHORT Port);
STATIC XTCDECL USHORT ReadPort16(IN USHORT Port);
STATIC XTCDECL ULONG ReadPort32(IN USHORT Port);
STATIC XTCDECL VOID WritePort8(IN USHORT Port,
IN UCHAR Value);
STATIC XTCDECL VOID WritePort16(IN USHORT Port,
IN USHORT Value);
STATIC XTCDECL VOID WritePort32(IN USHORT Port,
IN ULONG Value);
};
}
#endif /* __XTOSKRNL_HL_IOPORT_HH */

View File

@@ -0,0 +1,43 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/pic.hh
* DESCRIPTION: HAL processor support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_PIC_HH
#define __XTOSKRNL_HL_PIC_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class Pic
{
private:
STATIC APIC_MODE ApicMode;
public:
STATIC XTAPI VOID ClearApicErrors(VOID);
STATIC XTAPI ULONG GetCpuApicId(VOID);
STATIC XTAPI VOID InitializePic(VOID);
STATIC XTFASTCALL ULONGLONG ReadApicRegister(IN APIC_REGISTER Register);
STATIC XTAPI VOID SendEoi(VOID);
STATIC XTAPI VOID SendIpi(ULONG ApicId,
ULONG Vector);
STATIC XTFASTCALL VOID WriteApicRegister(IN APIC_REGISTER Register,
IN ULONGLONG Value);
private:
STATIC XTAPI BOOLEAN CheckX2ApicSupport(VOID);
STATIC XTCDECL VOID HandleApicSpuriousService(VOID);
STATIC XTCDECL VOID HandlePicSpuriousService(VOID);
STATIC XTAPI VOID InitializeApic(VOID);
STATIC XTAPI VOID InitializeLegacyPic(VOID);
};
}
#endif /* __XTOSKRNL_HL_PIC_HH */

View File

@@ -0,0 +1,30 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/includes/hl/runlevel.hh
* DESCRIPTION: Run Level management support
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/
#ifndef __XTOSKRNL_HL_RUNLEVEL_HH
#define __XTOSKRNL_HL_RUNLEVEL_HH
#include <xtos.hh>
/* Hardware Layer */
namespace HL
{
class RunLevel
{
public:
STATIC XTFASTCALL KRUNLEVEL GetRunLevel(VOID);
STATIC XTFASTCALL VOID SetRunLevel(IN KRUNLEVEL RunLevel);
private:
STATIC XTFASTCALL KRUNLEVEL TransformApicTprToRunLevel(IN UCHAR Tpr);
STATIC XTFASTCALL UCHAR TransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel);
};
}
#endif /* __XTOSKRNL_HL_RUNLEVEL_HH */

View File

@@ -26,7 +26,7 @@ HlComPortGetByte(IN PCPPORT Port,
XTCDECL XTCDECL
XTSTATUS XTSTATUS
HlComPortPutByte(IN PCPPORT Port, HlWriteComPort8(IN PCPPORT Port,
IN UCHAR Byte); IN UCHAR Byte);
XTCDECL XTCDECL

View File

@@ -171,5 +171,5 @@ KdpSerialWriteCharacter(WCHAR Character)
/* Write character to the serial console */ /* Write character to the serial console */
Buffer[0] = Character; Buffer[0] = Character;
Buffer[1] = 0; Buffer[1] = 0;
return HlComPortPutByte(&KdpSerialPort, Buffer[0]); return HlWriteComPort(&KdpSerialPort, Buffer[0]);
} }

View File

@@ -23,7 +23,7 @@ KE::KernelInit::InitializeKernel(VOID)
XTSTATUS Status; XTSTATUS Status;
/* Initialize hardware layer subsystem */ /* Initialize hardware layer subsystem */
Status = HlInitializeSystem(); Status = HL::Init::InitializeSystem();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Hardware layer initialization failed, kernel panic */ /* Hardware layer initialization failed, kernel panic */
@@ -44,14 +44,14 @@ VOID
KE::KernelInit::InitializeMachine(VOID) KE::KernelInit::InitializeMachine(VOID)
{ {
/* Re-enable IDE interrupts */ /* Re-enable IDE interrupts */
HlIoPortOutByte(0x376, 0); HL::IoPort::WritePort8(0x376, 0);
HlIoPortOutByte(0x3F6, 0); HL::IoPort::WritePort8(0x3F6, 0);
/* Initialize frame buffer */ /* Initialize frame buffer */
HlInitializeFrameBuffer(); HL::FrameBuffer::InitializeFrameBuffer();
/* Initialize processor */ /* Initialize processor */
HlInitializeProcessor(); HL::Cpu::InitializeProcessor();
/* Initialize page map support */ /* Initialize page map support */
MmInitializePageMapSupport(); MmInitializePageMapSupport();

View File

@@ -2,7 +2,7 @@
* PROJECT: ExectOS * PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory * COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/ke/data.cc * FILE: xtoskrnl/ke/data.cc
* DESCRIPTION: * DESCRIPTION: Kernel Library global and static data
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com> * DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
*/ */

View File

@@ -23,7 +23,7 @@ KE::KernelInit::InitializeKernel(VOID)
XTSTATUS Status; XTSTATUS Status;
/* Initialize hardware layer subsystem */ /* Initialize hardware layer subsystem */
Status = HlInitializeSystem(); Status = HL::Init::InitializeSystem();
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Hardware layer initialization failed, kernel panic */ /* Hardware layer initialization failed, kernel panic */
@@ -44,14 +44,14 @@ VOID
KE::KernelInit::InitializeMachine(VOID) KE::KernelInit::InitializeMachine(VOID)
{ {
/* Re-enable IDE interrupts */ /* Re-enable IDE interrupts */
HlIoPortOutByte(0x376, 0); HL::IoPort::WritePort8(0x376, 0);
HlIoPortOutByte(0x3F6, 0); HL::IoPort::WritePort8(0x3F6, 0);
/* Initialize frame buffer */ /* Initialize frame buffer */
HlInitializeFrameBuffer(); HL::FrameBuffer::InitializeFrameBuffer();
/* Initialize processor */ /* Initialize processor */
HlInitializeProcessor(); HL::Cpu::InitializeProcessor();
/* Initialize page map support */ /* Initialize page map support */
MmInitializePageMapSupport(); MmInitializePageMapSupport();

View File

@@ -20,7 +20,7 @@ XTFASTCALL
KRUNLEVEL KRUNLEVEL
KE::RunLevel::GetCurrentRunLevel(VOID) KE::RunLevel::GetCurrentRunLevel(VOID)
{ {
return HlGetRunLevel(); return HL::RunLevel::GetRunLevel();
} }
/** /**
@@ -40,13 +40,13 @@ KE::RunLevel::LowerRunLevel(IN KRUNLEVEL RunLevel)
KRUNLEVEL OldRunLevel; KRUNLEVEL OldRunLevel;
/* Read current run level */ /* Read current run level */
OldRunLevel = HlGetRunLevel(); OldRunLevel = HL::RunLevel::GetRunLevel();
/* Validate run level lowerage */ /* Validate run level lowerage */
if(OldRunLevel > RunLevel) if(OldRunLevel > RunLevel)
{ {
/* Set new, lower run level */ /* Set new, lower run level */
HlSetRunLevel(RunLevel); HL::RunLevel::SetRunLevel(RunLevel);
} }
} }
@@ -67,13 +67,13 @@ KE::RunLevel::RaiseRunLevel(IN KRUNLEVEL RunLevel)
KRUNLEVEL OldRunLevel; KRUNLEVEL OldRunLevel;
/* Read current run level */ /* Read current run level */
OldRunLevel = HlGetRunLevel(); OldRunLevel = HL::RunLevel::GetRunLevel();
/* Validate run level raise */ /* Validate run level raise */
if(OldRunLevel < RunLevel) if(OldRunLevel < RunLevel)
{ {
/* Set new, higher run level */ /* Set new, higher run level */
HlSetRunLevel(RunLevel); HL::RunLevel::SetRunLevel(RunLevel);
} }
/* Return old run level */ /* Return old run level */

View File

@@ -5,15 +5,15 @@
@ fastcall ExReInitializeRundownProtection(ptr) @ fastcall ExReInitializeRundownProtection(ptr)
@ fastcall ExReleaseRundownProtection(ptr) @ fastcall ExReleaseRundownProtection(ptr)
@ fastcall ExWaitForRundownProtectionRelease(ptr) @ fastcall ExWaitForRundownProtectionRelease(ptr)
@ cdecl HlIoPortInByte(ptr) @ cdecl HlReadPort8(ptr)
@ cdecl HlIoPortInLong(ptr) @ cdecl HlReadPort16(ptr)
@ cdecl HlIoPortInShort(ptr) @ cdecl HlReadPort32(ptr)
@ cdecl HlIoPortOutByte(ptr long)
@ cdecl HlIoPortOutLong(ptr long)
@ cdecl HlIoPortOutShort(ptr long)
@ stdcall HlReadRegister8(ptr) @ stdcall HlReadRegister8(ptr)
@ stdcall HlReadRegister16(ptr) @ stdcall HlReadRegister16(ptr)
@ stdcall HlReadRegister32(ptr) @ stdcall HlReadRegister32(ptr)
@ cdecl HlWritePort8(ptr long)
@ cdecl HlWritePort16(ptr long)
@ cdecl HlWritePort32(ptr long)
@ stdcall HlWriteRegister8(ptr long) @ stdcall HlWriteRegister8(ptr long)
@ stdcall HlWriteRegister16(ptr long) @ stdcall HlWriteRegister16(ptr long)
@ stdcall HlWriteRegister32(ptr long) @ stdcall HlWriteRegister32(ptr long)