C to C++ migration and refactoring #17
@@ -15,38 +15,38 @@
|
||||
#include <amd64/xtstruct.h>
|
||||
|
||||
|
||||
/* HAL library routines forward references */
|
||||
/* Hardware layer routines forward references */
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
UCHAR
|
||||
HlIoPortInByte(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
ULONG
|
||||
HlIoPortInLong(IN USHORT Port);
|
||||
HlReadPort8(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
USHORT
|
||||
HlIoPortInShort(IN USHORT Port);
|
||||
HlReadPort16(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
ULONG
|
||||
HlReadPort32(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutByte(IN USHORT Port,
|
||||
IN UCHAR Data);
|
||||
HlWritePort8(IN USHORT Port,
|
||||
IN UCHAR Data);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutLong(IN USHORT Port,
|
||||
IN ULONG Value);
|
||||
HlWritePort16(IN USHORT Port,
|
||||
IN USHORT Value);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutShort(IN USHORT Port,
|
||||
IN USHORT Value);
|
||||
HlWritePort32(IN USHORT Port,
|
||||
IN ULONG Value);
|
||||
|
||||
#endif /* __XTDK_AMD64_HLFUNCS_H */
|
||||
|
@@ -18,8 +18,8 @@
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
HlComPortPutByte(IN PCPPORT Port,
|
||||
IN UCHAR Byte);
|
||||
HlWriteComPort(IN PCPPORT Port,
|
||||
IN UCHAR Byte);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
@@ -28,6 +28,7 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
||||
IN PUCHAR PortAddress,
|
||||
IN ULONG BaudRate);
|
||||
|
||||
/* Hardware layer routines forward references */
|
||||
XTCLINK
|
||||
XTAPI
|
||||
UCHAR
|
||||
|
@@ -15,38 +15,38 @@
|
||||
#include <i686/xtstruct.h>
|
||||
|
||||
|
||||
/* HAL library routines forward references */
|
||||
/* Hardware layer routines forward references */
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
UCHAR
|
||||
HlIoPortInByte(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
ULONG
|
||||
HlIoPortInLong(IN USHORT Port);
|
||||
HlReadPort8(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
USHORT
|
||||
HlIoPortInShort(IN USHORT Port);
|
||||
HlReadPort16(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
ULONG
|
||||
HlReadPort32(IN USHORT Port);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutByte(IN USHORT Port,
|
||||
IN UCHAR Data);
|
||||
HlWritePort8(IN USHORT Port,
|
||||
IN UCHAR Data);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutLong(IN USHORT Port,
|
||||
IN ULONG Value);
|
||||
HlWritePort16(IN USHORT Port,
|
||||
IN USHORT Value);
|
||||
|
||||
XTCLINK
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutShort(IN USHORT Port,
|
||||
IN USHORT Value);
|
||||
HlWritePort32(IN USHORT Port,
|
||||
IN ULONG Value);
|
||||
|
||||
#endif /* __XTDK_I686_HLFUNCS_H */
|
||||
|
@@ -78,7 +78,7 @@ BlpDebugPutChar(IN WCHAR Character)
|
||||
/* Write character to the serial console */
|
||||
Buffer[0] = Character;
|
||||
Buffer[1] = 0;
|
||||
return HlComPortPutByte(&BlpStatus.SerialPort, Buffer[0]);
|
||||
return HlWriteComPort(&BlpStatus.SerialPort, Buffer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -29,8 +29,8 @@ BpDisableToneBeep()
|
||||
UCHAR Status;
|
||||
|
||||
/* Stop the PC speaker */
|
||||
Status = HlIoPortInByte(0x61);
|
||||
HlIoPortOutByte(0x61, Status & 0xFC);
|
||||
Status = HlReadPort8(0x61);
|
||||
HlWritePort8(0x61, Status & 0xFC);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,14 +62,14 @@ BpEnableToneBeep(IN UINT Pitch)
|
||||
|
||||
/* Set the desired frequency of the PIT clock */
|
||||
Counter = 0x1234DD / Pitch;
|
||||
HlIoPortOutByte(0x43, 0xB6);
|
||||
HlIoPortOutByte(0x43, 0xB6);
|
||||
HlIoPortOutByte(0x42, (UCHAR) Counter & 0xFF);
|
||||
HlIoPortOutByte(0x42, (UCHAR) (Counter >> 8) & 0xFF);
|
||||
HlWritePort8(0x43, 0xB6);
|
||||
HlWritePort8(0x43, 0xB6);
|
||||
HlWritePort8(0x42, (UCHAR) Counter & 0xFF);
|
||||
HlWritePort8(0x42, (UCHAR) (Counter >> 8) & 0xFF);
|
||||
|
||||
/* Start the PC speaker */
|
||||
Status = HlIoPortInByte(0x61);
|
||||
HlIoPortOutByte(0x61, Status | 0x03);
|
||||
Status = HlReadPort8(0x61);
|
||||
HlWritePort8(0x61, Status | 0x03);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -17,17 +17,17 @@ list(APPEND XTOSKRNL_SOURCE
|
||||
${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/traps.cc
|
||||
${XTOSKRNL_SOURCE_DIR}/ex/exports.cc
|
||||
${XTOSKRNL_SOURCE_DIR}/ex/rundown.cc
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/acpi.c
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/cport.c
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/cpu.cc
|
||||
${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/fbdev.c
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/globals.c
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/init.c
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/fbdev.cc
|
||||
${XTOSKRNL_SOURCE_DIR}/hl/init.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/dbgio.c
|
||||
${XTOSKRNL_SOURCE_DIR}/kd/globals.c
|
||||
|
@@ -159,7 +159,7 @@ AR::ProcSup::InitializeProcessor(IN PVOID ProcessorStructures)
|
||||
CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS);
|
||||
|
||||
/* Enter passive IRQ level */
|
||||
HlSetRunLevel(PASSIVE_LEVEL);
|
||||
HL::RunLevel::SetRunLevel(PASSIVE_LEVEL);
|
||||
|
||||
/* Initialize segment registers */
|
||||
InitializeSegments();
|
||||
|
@@ -159,7 +159,7 @@ AR::ProcSup::InitializeProcessor(IN PVOID ProcessorStructures)
|
||||
CpuFunc::LoadTaskRegister((UINT)KGDT_SYS_TSS);
|
||||
|
||||
/* Enter passive IRQ level */
|
||||
HlSetRunLevel(PASSIVE_LEVEL);
|
||||
HL::RunLevel::SetRunLevel(PASSIVE_LEVEL);
|
||||
|
||||
/* Initialize segment registers */
|
||||
InitializeSegments();
|
||||
|
@@ -1,14 +1,35 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* 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).
|
||||
*
|
||||
@@ -21,10 +42,10 @@
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlGetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp)
|
||||
HL::Acpi::GetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp)
|
||||
{
|
||||
/* Get RSDP and return success */
|
||||
*Rsdp = HlpAcpiRsdp;
|
||||
*Rsdp = RsdpStructure;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -43,21 +64,21 @@ HlGetAcpiSystemDescriptionPointer(OUT PACPI_RSDP *Rsdp)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlGetAcpiTable(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
HL::Acpi::GetAcpiTable(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
{
|
||||
PACPI_DESCRIPTION_HEADER Table;
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Assume ACPI table not found */
|
||||
*AcpiTable = NULL;
|
||||
*AcpiTable = nullptr;
|
||||
|
||||
/* Attempt to get ACPI table from the cache */
|
||||
Status = HlpQueryAcpiCache(Signature, &Table);
|
||||
Status = QueryAcpiCache(Signature, &Table);
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Table not found in the cache, query ACPI tables */
|
||||
Status = HlpQueryAcpiTables(Signature, &Table);
|
||||
Status = QueryAcpiTables(Signature, &Table);
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* ACPI table not found, return error */
|
||||
@@ -70,27 +91,6 @@ HlGetAcpiTable(IN ULONG Signature,
|
||||
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.
|
||||
*
|
||||
@@ -100,13 +100,13 @@ HlpCacheAcpiTable(IN PACPI_DESCRIPTION_HEADER AcpiTable)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpi(VOID)
|
||||
HL::Acpi::InitializeAcpi(VOID)
|
||||
{
|
||||
PACPI_FADT Fadt;
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Initialize ACPI cache */
|
||||
Status = HlpInitializeAcpiCache();
|
||||
Status = InitializeAcpiCache();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* ACPI cache initialization failed, return error */
|
||||
@@ -114,7 +114,7 @@ HlpInitializeAcpi(VOID)
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to get FADT, return error */
|
||||
@@ -122,7 +122,7 @@ HlpInitializeAcpi(VOID)
|
||||
}
|
||||
|
||||
/* Initialize ACPI timer */
|
||||
HlpInitializeAcpiTimer();
|
||||
InitializeAcpiTimer();
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
@@ -137,16 +137,16 @@ HlpInitializeAcpi(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpiCache(VOID)
|
||||
HL::Acpi::InitializeAcpiCache(VOID)
|
||||
{
|
||||
PACPI_DESCRIPTION_HEADER Rsdt;
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Initialize ACPI cache list */
|
||||
RtlInitializeListHead(&HlpAcpiCacheList);
|
||||
RTL::LinkedList::InitializeListHead(&CacheList);
|
||||
|
||||
/* Get XSDT/RSDT */
|
||||
Status = HlpInitializeAcpiSystemDescriptionTable(&Rsdt);
|
||||
Status = InitializeAcpiSystemDescriptionTable(&Rsdt);
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Failed to get XSDT/RSDT, return error */
|
||||
@@ -154,7 +154,7 @@ HlpInitializeAcpiCache(VOID)
|
||||
}
|
||||
|
||||
/* Cache XSDT/RSDT table */
|
||||
HlpCacheAcpiTable(Rsdt);
|
||||
CacheAcpiTable(Rsdt);
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
@@ -172,7 +172,7 @@ HlpInitializeAcpiCache(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
HL::Acpi::InitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
{
|
||||
PHYSICAL_ADDRESS RsdpAddress, RsdtAddress;
|
||||
PSYSTEM_RESOURCE_HEADER ResourceHeader;
|
||||
@@ -182,7 +182,7 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Assume ACPI table not found */
|
||||
*AcpiTable = NULL;
|
||||
*AcpiTable = nullptr;
|
||||
|
||||
/* Get ACPI system resource */
|
||||
Status = KeGetSystemResource(SystemResourceAcpi, &ResourceHeader);
|
||||
@@ -197,26 +197,26 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
RsdpAddress.QuadPart = (LONGLONG)AcpiResource->Header.PhysicalAddress;
|
||||
|
||||
/* Map RSDP and mark it as CD/WT to avoid delays in write-back cache */
|
||||
Status = MmMapHardwareMemory(RsdpAddress, 1, TRUE, (PVOID *)&HlpAcpiRsdp);
|
||||
MmMarkHardwareMemoryWriteThrough(HlpAcpiRsdp, 1);
|
||||
Status = MmMapHardwareMemory(RsdpAddress, 1, TRUE, (PVOID *)&RsdpStructure);
|
||||
MmMarkHardwareMemoryWriteThrough(RsdpStructure, 1);
|
||||
|
||||
/* 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 */
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Check RSDP revision to determine RSDT/XSDT address */
|
||||
if(HlpAcpiRsdp->Revision >= 2)
|
||||
if(RsdpStructure->Revision >= 2)
|
||||
{
|
||||
/* Get XSDT address */
|
||||
RsdtAddress.QuadPart = (LONGLONG)HlpAcpiRsdp->XsdtAddress;
|
||||
RsdtAddress.QuadPart = (LONGLONG)RsdpStructure->XsdtAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get RSDT address */
|
||||
RsdtAddress.QuadPart = (LONGLONG)HlpAcpiRsdp->RsdtAddress;
|
||||
RsdtAddress.QuadPart = (LONGLONG)RsdpStructure->RsdtAddress;
|
||||
}
|
||||
|
||||
/* Map RSDT/XSDT as CD/WT */
|
||||
@@ -263,7 +263,7 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpiSystemInformation(VOID)
|
||||
HL::Acpi::InitializeAcpiSystemInformation(VOID)
|
||||
{
|
||||
PACPI_MADT_LOCAL_X2APIC LocalX2Apic;
|
||||
PACPI_MADT_LOCAL_APIC LocalApic;
|
||||
@@ -273,7 +273,7 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
USHORT CpuCount;
|
||||
|
||||
/* Allocate memory for ACPI system information structure */
|
||||
Status = HlpInitializeAcpiSystemStructure();
|
||||
Status = InitializeAcpiSystemStructure();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Failed to allocate memory, return error */
|
||||
@@ -281,7 +281,7 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to get MADT, return error */
|
||||
@@ -306,9 +306,9 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
if(LocalApic->Flags & ACPI_MADT_PLAOC_ENABLED)
|
||||
{
|
||||
/* Store CPU number, APIC ID and CPU ID */
|
||||
HlpSystemInfo.CpuInfo[CpuCount].AcpiId = LocalApic->AcpiId;
|
||||
HlpSystemInfo.CpuInfo[CpuCount].ApicId = LocalApic->ApicId;
|
||||
HlpSystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
|
||||
SystemInfo.CpuInfo[CpuCount].AcpiId = LocalApic->AcpiId;
|
||||
SystemInfo.CpuInfo[CpuCount].ApicId = LocalApic->ApicId;
|
||||
SystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
|
||||
|
||||
/* Increment number of CPUs */
|
||||
CpuCount++;
|
||||
@@ -327,9 +327,9 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
if(LocalX2Apic->Flags & ACPI_MADT_PLAOC_ENABLED)
|
||||
{
|
||||
/* Store CPU number, APIC ID and CPU ID */
|
||||
HlpSystemInfo.CpuInfo[CpuCount].AcpiId = LocalX2Apic->AcpiId;
|
||||
HlpSystemInfo.CpuInfo[CpuCount].ApicId = LocalX2Apic->ApicId;
|
||||
HlpSystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
|
||||
SystemInfo.CpuInfo[CpuCount].AcpiId = LocalX2Apic->AcpiId;
|
||||
SystemInfo.CpuInfo[CpuCount].ApicId = LocalX2Apic->ApicId;
|
||||
SystemInfo.CpuInfo[CpuCount].CpuNumber = CpuCount;
|
||||
|
||||
/* Increment number of CPUs */
|
||||
CpuCount++;
|
||||
@@ -346,7 +346,7 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
}
|
||||
|
||||
/* Store number of CPUs */
|
||||
HlpSystemInfo.CpuCount = CpuCount;
|
||||
SystemInfo.CpuCount = CpuCount;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
@@ -361,7 +361,7 @@ HlpInitializeAcpiSystemInformation(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpiSystemStructure(VOID)
|
||||
HL::Acpi::InitializeAcpiSystemStructure(VOID)
|
||||
{
|
||||
PHYSICAL_ADDRESS PhysicalAddress;
|
||||
PFN_NUMBER PageCount;
|
||||
@@ -371,7 +371,7 @@ HlpInitializeAcpiSystemStructure(VOID)
|
||||
ULONG CpuCount;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to get MADT, return error */
|
||||
@@ -420,7 +420,7 @@ HlpInitializeAcpiSystemStructure(VOID)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY));
|
||||
@@ -434,7 +434,7 @@ HlpInitializeAcpiSystemStructure(VOID)
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to map memory, return error */
|
||||
@@ -442,7 +442,7 @@ HlpInitializeAcpiSystemStructure(VOID)
|
||||
}
|
||||
|
||||
/* Zero the CPU information structure */
|
||||
RtlZeroMemory(HlpSystemInfo.CpuInfo, PAGES_TO_SIZE(PageCount));
|
||||
RTL::Memory::ZeroMemory(SystemInfo.CpuInfo, PAGES_TO_SIZE(PageCount));
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
@@ -457,13 +457,13 @@ HlpInitializeAcpiSystemStructure(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpInitializeAcpiTimer(VOID)
|
||||
HL::Acpi::InitializeAcpiTimer(VOID)
|
||||
{
|
||||
PACPI_FADT Fadt;
|
||||
XTSTATUS Status;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to get FADT, return error */
|
||||
@@ -471,18 +471,18 @@ HlpInitializeAcpiTimer(VOID)
|
||||
}
|
||||
|
||||
/* Set ACPI timer port address */
|
||||
HlpAcpiTimerInfo.TimerPort = Fadt->PmTmrBlkIoPort;
|
||||
TimerInfo.TimerPort = Fadt->PmTmrBlkIoPort;
|
||||
|
||||
/* Determine whether 32-bit or 24-bit timer is used */
|
||||
if(Fadt->Flags & ACPI_FADT_32BIT_TIMER)
|
||||
{
|
||||
/* 32-bit timer */
|
||||
HlpAcpiTimerInfo.MsbMask = ACPI_FADT_TIMER_32BIT;
|
||||
TimerInfo.MsbMask = ACPI_FADT_TIMER_32BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 24-bit timer */
|
||||
HlpAcpiTimerInfo.MsbMask = ACPI_FADT_TIMER_24BIT;
|
||||
TimerInfo.MsbMask = ACPI_FADT_TIMER_24BIT;
|
||||
}
|
||||
|
||||
/* Return success */
|
||||
@@ -504,19 +504,19 @@ HlpInitializeAcpiTimer(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpQueryAcpiCache(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
HL::Acpi::QueryAcpiCache(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
{
|
||||
PACPI_DESCRIPTION_HEADER TableHeader;
|
||||
PACPI_CACHE_LIST AcpiCache;
|
||||
PLIST_ENTRY ListEntry;
|
||||
|
||||
/* Initialize variables */
|
||||
TableHeader = NULL;
|
||||
TableHeader = nullptr;
|
||||
|
||||
/* Iterate through ACPI tables cache list */
|
||||
ListEntry = HlpAcpiCacheList.Flink;
|
||||
while(ListEntry != &HlpAcpiCacheList)
|
||||
ListEntry = CacheList.Flink;
|
||||
while(ListEntry != &CacheList)
|
||||
{
|
||||
/* Get cached ACPI table header */
|
||||
AcpiCache = CONTAIN_RECORD(ListEntry, ACPI_CACHE_LIST, ListEntry);
|
||||
@@ -561,8 +561,8 @@ HlpQueryAcpiCache(IN ULONG Signature,
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlpQueryAcpiTables(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
HL::Acpi::QueryAcpiTables(IN ULONG Signature,
|
||||
OUT PACPI_DESCRIPTION_HEADER *AcpiTable)
|
||||
{
|
||||
ULONG TableCount, TableIndex, TablePages;
|
||||
PACPI_DESCRIPTION_HEADER TableHeader;
|
||||
@@ -580,13 +580,13 @@ HlpQueryAcpiTables(IN ULONG Signature,
|
||||
}
|
||||
|
||||
/* Ensure that table header is not set before attempting to find ACPI table */
|
||||
TableHeader = NULL;
|
||||
TableHeader = nullptr;
|
||||
|
||||
/* Check if DSDT or FACS table requested */
|
||||
if(Signature == ACPI_DSDT_SIGNATURE || Signature == ACPI_FACS_SIGNATURE)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
/* Failed to get FADT, return error */
|
||||
@@ -619,11 +619,11 @@ HlpQueryAcpiTables(IN ULONG Signature,
|
||||
else
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
/* 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 */
|
||||
@@ -703,7 +703,7 @@ HlpQueryAcpiTables(IN ULONG Signature,
|
||||
if(TableHeader->Signature != ACPI_FADT_SIGNATURE || TableHeader->Revision > 2)
|
||||
{
|
||||
/* Validate table checksum */
|
||||
if(!HlpValidateAcpiTable(TableHeader, TableHeader->Length))
|
||||
if(!ValidateAcpiTable(TableHeader, TableHeader->Length))
|
||||
{
|
||||
/* Checksum mismatch, unmap table and return error */
|
||||
MmUnmapHardwareMemory(TableHeader, 2, TRUE);
|
||||
@@ -729,7 +729,7 @@ HlpQueryAcpiTables(IN ULONG Signature,
|
||||
|
||||
/* Mark table as write through and store it in local cache */
|
||||
MmMarkHardwareMemoryWriteThrough(TableHeader, TablePages);
|
||||
HlpCacheAcpiTable(TableHeader);
|
||||
CacheAcpiTable(TableHeader);
|
||||
|
||||
/* Store ACPI table and return success */
|
||||
*AcpiTable = TableHeader;
|
||||
@@ -751,15 +751,15 @@ HlpQueryAcpiTables(IN ULONG Signature,
|
||||
*/
|
||||
XTAPI
|
||||
BOOLEAN
|
||||
HlpValidateAcpiTable(IN PVOID Buffer,
|
||||
IN UINT_PTR Size)
|
||||
HL::Acpi::ValidateAcpiTable(IN PVOID Buffer,
|
||||
IN UINT_PTR Size)
|
||||
{
|
||||
PUCHAR Pointer;
|
||||
UCHAR Sum;
|
||||
|
||||
/* Initialize variables */
|
||||
Sum = 0;
|
||||
Pointer = Buffer;
|
||||
Pointer = (PUCHAR)Buffer;
|
||||
|
||||
/* Calculate checksum of given table */
|
||||
while(Size != 0)
|
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/* Include common CPU interface */
|
||||
#include ARCH_COMMON(cpu.c)
|
||||
#include ARCH_COMMON(cpu.cc)
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
XTCDECL
|
||||
UCHAR
|
||||
HlIoPortInByte(IN USHORT Port)
|
||||
HL::IoPort::ReadPort8(IN USHORT Port)
|
||||
{
|
||||
UCHAR Value;
|
||||
__asm__ volatile("inb %1, %0"
|
||||
@@ -30,27 +30,6 @@ HlIoPortInByte(IN USHORT Port)
|
||||
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.
|
||||
*
|
||||
@@ -63,7 +42,7 @@ HlIoPortInLong(IN USHORT Port)
|
||||
*/
|
||||
XTCDECL
|
||||
USHORT
|
||||
HlIoPortInShort(IN USHORT Port)
|
||||
HL::IoPort::ReadPort16(IN USHORT Port)
|
||||
{
|
||||
USHORT Value;
|
||||
__asm__ volatile("inw %1, %0"
|
||||
@@ -72,6 +51,27 @@ HlIoPortInShort(IN USHORT Port)
|
||||
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.
|
||||
*
|
||||
@@ -87,8 +87,8 @@ HlIoPortInShort(IN USHORT Port)
|
||||
*/
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutByte(IN USHORT Port,
|
||||
IN UCHAR Value)
|
||||
HL::IoPort::WritePort8(IN USHORT Port,
|
||||
IN UCHAR Value)
|
||||
{
|
||||
__asm__ volatile("outb %0, %1"
|
||||
:
|
||||
@@ -96,30 +96,6 @@ HlIoPortOutByte(IN USHORT 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.
|
||||
*
|
||||
@@ -135,11 +111,35 @@ HlIoPortOutLong(IN USHORT Port,
|
||||
*/
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutShort(IN USHORT Port,
|
||||
IN USHORT Value)
|
||||
HL::IoPort::WritePort16(IN USHORT Port,
|
||||
IN USHORT Value)
|
||||
{
|
||||
__asm__ volatile("outw %0, %1"
|
||||
:
|
||||
: "a" (Value),
|
||||
"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));
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/* Include common PIC interface */
|
||||
#include ARCH_COMMON(pic.c)
|
||||
#include ARCH_COMMON(pic.cc)
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
XTFASTCALL
|
||||
KRUNLEVEL
|
||||
HlGetRunLevel(VOID)
|
||||
HL::RunLevel::GetRunLevel(VOID)
|
||||
{
|
||||
return (KRUNLEVEL)ArReadControlRegister(8);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ HlGetRunLevel(VOID)
|
||||
*/
|
||||
XTFASTCALL
|
||||
VOID
|
||||
HlSetRunLevel(IN KRUNLEVEL RunLevel)
|
||||
HL::RunLevel::SetRunLevel(IN KRUNLEVEL RunLevel)
|
||||
{
|
||||
ArWriteControlRegister(8, RunLevel);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ HlSetRunLevel(IN KRUNLEVEL RunLevel)
|
||||
*/
|
||||
XTFASTCALL
|
||||
KRUNLEVEL
|
||||
HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
HL::RunLevel::TransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
{
|
||||
return (KRUNLEVEL)(Tpr >> 4);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
*/
|
||||
XTFASTCALL
|
||||
UCHAR
|
||||
HlpTransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
|
||||
HL::RunLevel::TransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
|
||||
{
|
||||
return (RunLevel << 4);
|
||||
}
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/hl/cport.c
|
||||
* FILE: xtoskrnl/hl/cport.cc
|
||||
* DESCRIPTION: Serial (COM) port support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,10 +30,10 @@
|
||||
*/
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
HlComPortGetByte(IN PCPPORT Port,
|
||||
OUT PUCHAR Byte,
|
||||
IN BOOLEAN Wait,
|
||||
IN BOOLEAN Poll)
|
||||
HL::ComPort::ReadComPort(IN PCPPORT Port,
|
||||
OUT PUCHAR Byte,
|
||||
IN BOOLEAN Wait,
|
||||
IN BOOLEAN Poll)
|
||||
{
|
||||
UCHAR Lsr;
|
||||
ULONG Retry;
|
||||
@@ -49,7 +49,7 @@ HlComPortGetByte(IN PCPPORT Port,
|
||||
while(Retry--)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
/* Check for errors */
|
||||
@@ -68,13 +68,13 @@ HlComPortGetByte(IN PCPPORT 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 */
|
||||
if(Port->Flags & COMPORT_FLAG_MC)
|
||||
{
|
||||
/* 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 */
|
||||
continue;
|
||||
@@ -85,67 +85,10 @@ HlComPortGetByte(IN PCPPORT Port,
|
||||
}
|
||||
|
||||
/* Reset LSR and return that no data found */
|
||||
HlComPortReadLsr(Port, 0);
|
||||
ReadComPortLsr(Port, 0);
|
||||
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.
|
||||
*
|
||||
@@ -161,19 +104,19 @@ HlComPortPutByte(IN PCPPORT Port,
|
||||
*/
|
||||
XTCDECL
|
||||
UCHAR
|
||||
HlComPortReadLsr(IN PCPPORT Port,
|
||||
IN UCHAR Byte)
|
||||
HL::ComPort::ReadComPortLsr(IN PCPPORT Port,
|
||||
IN UCHAR Byte)
|
||||
{
|
||||
UCHAR Lsr, Msr;
|
||||
|
||||
/* 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 */
|
||||
if((Lsr & Byte) == 0)
|
||||
{
|
||||
/* 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;
|
||||
if(Port->Ring == 3)
|
||||
{
|
||||
@@ -207,9 +150,9 @@ HlComPortReadLsr(IN PCPPORT Port,
|
||||
*/
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
HlInitializeComPort(IN OUT PCPPORT Port,
|
||||
IN PUCHAR PortAddress,
|
||||
IN ULONG BaudRate)
|
||||
HL::ComPort::InitializeComPort(IN OUT PCPPORT Port,
|
||||
IN PUCHAR PortAddress,
|
||||
IN ULONG BaudRate)
|
||||
{
|
||||
USHORT Flags;
|
||||
UCHAR Byte;
|
||||
@@ -237,8 +180,8 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
||||
do
|
||||
{
|
||||
/* Check whether the 16450/16550 scratch register exists */
|
||||
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR), Byte);
|
||||
if(HlIoPortInByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR)) != Byte)
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR), Byte);
|
||||
if(HL::IoPort::ReadPort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_SR)) != Byte)
|
||||
{
|
||||
return STATUS_NOT_FOUND;
|
||||
}
|
||||
@@ -246,37 +189,37 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
||||
while(++Byte != 0);
|
||||
|
||||
/* Disable interrupts */
|
||||
HlIoPortOutByte(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_LCR), COMPORT_LSR_DIS);
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_IER), COMPORT_LSR_DIS);
|
||||
|
||||
/* 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 */
|
||||
Mode = COMPORT_CLOCK_RATE / BaudRate;
|
||||
HlIoPortOutByte(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_DLL), (UCHAR)(Mode & 0xFF));
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_DIV_DLM), (UCHAR)((Mode >> 8) & 0xFF));
|
||||
|
||||
/* Set 8 data bits, 1 stop bits, no parity (8n1) */
|
||||
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR),
|
||||
COMPORT_LCR_8DATA | COMPORT_LCR_1STOP | COMPORT_LCR_PARN);
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_LCR),
|
||||
COMPORT_LCR_8DATA | COMPORT_LCR_1STOP | COMPORT_LCR_PARN);
|
||||
|
||||
/* Enable DTR, RTS and OUT2 */
|
||||
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR),
|
||||
COMPORT_MCR_DTR | COMPORT_MCR_RTS | COMPORT_MCR_OUT2);
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_MCR),
|
||||
COMPORT_MCR_DTR | COMPORT_MCR_RTS | COMPORT_MCR_OUT2);
|
||||
|
||||
/* Enable FIFO */
|
||||
HlIoPortOutByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_FCR),
|
||||
COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET);
|
||||
HL::IoPort::WritePort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_FCR),
|
||||
COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET);
|
||||
|
||||
/* Mark port as fully initialized */
|
||||
Flags |= COMPORT_FLAG_INIT;
|
||||
|
||||
/* 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) */
|
||||
HlIoPortInByte(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_RBR));
|
||||
HL::IoPort::ReadPort8(PtrToUshort(PortAddress + (ULONG)COMPORT_REG_RBR));
|
||||
|
||||
/* Store port details */
|
||||
Port->Address = PortAddress;
|
||||
@@ -287,3 +230,81 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
||||
/* Return 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
34
xtoskrnl/hl/data.cc
Normal 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;
|
@@ -9,6 +9,60 @@
|
||||
#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.
|
||||
*
|
||||
@@ -63,6 +117,72 @@ HlReadRegister32(IN PVOID 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.
|
||||
*
|
||||
|
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/hl/fbdev.c
|
||||
* FILE: xtoskrnl/hl/fbdev.cc
|
||||
* DESCRIPTION: FrameBuffer support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
* Aiken Harris <harraiken91@gmail.com>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
#include <xtfont.h>
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
HlClearScreen(IN ULONG Color)
|
||||
HL::FrameBuffer::ClearScreen(IN ULONG Color)
|
||||
{
|
||||
ULONG PositionX, PositionY;
|
||||
ULONG BackgroundColor;
|
||||
@@ -31,22 +31,22 @@ HlClearScreen(IN ULONG Color)
|
||||
PULONG Pixel;
|
||||
|
||||
/* Make sure frame buffer is already initialized */
|
||||
if(HlpFrameBufferData.Initialized == FALSE)
|
||||
if(FrameBufferData.Initialized == FALSE)
|
||||
{
|
||||
/* Unable to operate on non-initialized frame buffer */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Convert background color and get pointer to frame buffer */
|
||||
BackgroundColor = HlpRGBColor(Color);
|
||||
CurrentLine = HlpFrameBufferData.Address;
|
||||
BackgroundColor = GetRGBColor(Color);
|
||||
CurrentLine = (PCHAR)FrameBufferData.Address;
|
||||
|
||||
/* 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 */
|
||||
Pixel = (PULONG)CurrentLine;
|
||||
for(PositionX = 0; PositionX < HlpFrameBufferData.Width; PositionX++)
|
||||
for(PositionX = 0; PositionX < FrameBufferData.Width; PositionX++)
|
||||
{
|
||||
/* Set the color of the pixel */
|
||||
Pixel[PositionX] = BackgroundColor;
|
||||
@@ -66,236 +66,65 @@ HlClearScreen(IN ULONG Color)
|
||||
*/
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
HlDisplayCharacter(IN WCHAR Character)
|
||||
HL::FrameBuffer::DisplayCharacter(IN WCHAR Character)
|
||||
{
|
||||
PSSFN_FONT_HEADER FbFont;
|
||||
|
||||
/* Make sure frame buffer is already initialized */
|
||||
if(HlpFrameBufferData.Initialized == FALSE)
|
||||
if(FrameBufferData.Initialized == FALSE)
|
||||
{
|
||||
/* Unable to operate on non-initialized frame buffer */
|
||||
return STATUS_DEVICE_NOT_READY;
|
||||
}
|
||||
|
||||
/* Get font information */
|
||||
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font;
|
||||
FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
|
||||
|
||||
/* Handle special characters */
|
||||
switch(Character)
|
||||
{
|
||||
case L'\n':
|
||||
/* Move cursor to the beginning of the next line */
|
||||
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left;
|
||||
HlpScrollRegionData.CursorY += FbFont->Height;
|
||||
ScrollRegionData.CursorX = ScrollRegionData.Left;
|
||||
ScrollRegionData.CursorY += FbFont->Height;
|
||||
break;
|
||||
case L'\t':
|
||||
/* Move cursor to the next tab stop */
|
||||
HlpScrollRegionData.CursorX += (8 - (HlpScrollRegionData.CursorX - HlpScrollRegionData.Left) / FbFont->Width % 8) * FbFont->Width;
|
||||
if (HlpScrollRegionData.CursorX >= HlpScrollRegionData.Right)
|
||||
ScrollRegionData.CursorX += (8 - (ScrollRegionData.CursorX - ScrollRegionData.Left) / FbFont->Width % 8) * FbFont->Width;
|
||||
if (ScrollRegionData.CursorX >= ScrollRegionData.Right)
|
||||
{
|
||||
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left;
|
||||
HlpScrollRegionData.CursorY += FbFont->Height;
|
||||
ScrollRegionData.CursorX = ScrollRegionData.Left;
|
||||
ScrollRegionData.CursorY += FbFont->Height;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Draw the character */
|
||||
HlpDrawCharacter(HlpScrollRegionData.CursorX, HlpScrollRegionData.CursorY, HlpScrollRegionData.TextColor, Character);
|
||||
DrawCharacter(ScrollRegionData.CursorX, ScrollRegionData.CursorY, ScrollRegionData.TextColor, Character);
|
||||
|
||||
/* Advance cursor */
|
||||
HlpScrollRegionData.CursorX += FbFont->Width;
|
||||
ScrollRegionData.CursorX += FbFont->Width;
|
||||
|
||||
/* Check if cursor reached end of line */
|
||||
if(HlpScrollRegionData.CursorX >= HlpScrollRegionData.Right)
|
||||
if(ScrollRegionData.CursorX >= ScrollRegionData.Right)
|
||||
{
|
||||
HlpScrollRegionData.CursorX = HlpScrollRegionData.Left;
|
||||
HlpScrollRegionData.CursorY += FbFont->Height;
|
||||
ScrollRegionData.CursorX = ScrollRegionData.Left;
|
||||
ScrollRegionData.CursorY += FbFont->Height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if cursor reached end of scroll region */
|
||||
if(HlpScrollRegionData.CursorY >= HlpScrollRegionData.Bottom)
|
||||
if(ScrollRegionData.CursorY >= ScrollRegionData.Bottom)
|
||||
{
|
||||
/* Scroll one line up */
|
||||
HlpScrollRegion();
|
||||
HlpScrollRegionData.CursorY = HlpScrollRegionData.Bottom - FbFont->Height;
|
||||
ScrollRegion();
|
||||
ScrollRegionData.CursorY = ScrollRegionData.Bottom - FbFont->Height;
|
||||
}
|
||||
|
||||
/* Return 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.
|
||||
*
|
||||
@@ -317,10 +146,10 @@ HlInitializeScrollRegion(IN ULONG Left,
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
HlpDrawCharacter(IN ULONG PositionX,
|
||||
IN ULONG PositionY,
|
||||
IN ULONG Color,
|
||||
IN WCHAR WideCharacter)
|
||||
HL::FrameBuffer::DrawCharacter(IN ULONG PositionX,
|
||||
IN ULONG PositionY,
|
||||
IN ULONG Color,
|
||||
IN WCHAR WideCharacter)
|
||||
{
|
||||
UINT CurrentFragment, Glyph, GlyphLimit, Index, Line, Mapping;
|
||||
PUCHAR Character, CharacterMapping, Fragment;
|
||||
@@ -329,14 +158,14 @@ HlpDrawCharacter(IN ULONG PositionX,
|
||||
ULONG FontColor;
|
||||
|
||||
/* Make sure frame buffer is already initialized */
|
||||
if(HlpFrameBufferData.Initialized == FALSE)
|
||||
if(FrameBufferData.Initialized == FALSE)
|
||||
{
|
||||
/* Unable to operate on non-initialized frame buffer */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get pointers to font data */
|
||||
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font;
|
||||
FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
|
||||
CharacterMapping = (PUCHAR)FbFont + FbFont->CharactersOffset;
|
||||
|
||||
/* 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 */
|
||||
GlyphPixel = (UINT_PTR)HlpFrameBufferData.Address + PositionY * HlpFrameBufferData.Pitch +
|
||||
PositionX * HlpFrameBufferData.BytesPerPixel;
|
||||
FontColor = HlpRGBColor(Color);
|
||||
GlyphPixel = (UINT_PTR)FrameBufferData.Address + PositionY * FrameBufferData.Pitch +
|
||||
PositionX * FrameBufferData.BytesPerPixel;
|
||||
FontColor = GetRGBColor(Color);
|
||||
|
||||
/* Check all kerning fragments */
|
||||
Mapping = 0;
|
||||
@@ -414,7 +243,7 @@ HlpDrawCharacter(IN ULONG PositionX,
|
||||
}
|
||||
|
||||
/* Get initial glyph line */
|
||||
GlyphPixel += (CharacterMapping[1] - Mapping) * HlpFrameBufferData.Pitch;
|
||||
GlyphPixel += (CharacterMapping[1] - Mapping) * FrameBufferData.Pitch;
|
||||
Mapping = CharacterMapping[1];
|
||||
|
||||
/* Extract glyph data from fragments table and advance */
|
||||
@@ -445,12 +274,12 @@ HlpDrawCharacter(IN ULONG PositionX,
|
||||
}
|
||||
|
||||
/* Advance pixel pointer */
|
||||
Pixel += HlpFrameBufferData.BytesPerPixel;
|
||||
Pixel += FrameBufferData.BytesPerPixel;
|
||||
CurrentFragment <<= 1;
|
||||
}
|
||||
|
||||
/* Advance to next line and increase mapping */
|
||||
GlyphPixel += HlpFrameBufferData.Pitch;
|
||||
GlyphPixel += FrameBufferData.Pitch;
|
||||
Mapping++;
|
||||
}
|
||||
|
||||
@@ -477,32 +306,54 @@ HlpDrawCharacter(IN ULONG PositionX,
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
HlpDrawPixel(IN ULONG PositionX,
|
||||
IN ULONG PositionY,
|
||||
IN ULONG Color)
|
||||
HL::FrameBuffer::DrawPixel(IN ULONG PositionX,
|
||||
IN ULONG PositionY,
|
||||
IN ULONG Color)
|
||||
{
|
||||
PCHAR PixelAddress;
|
||||
|
||||
/* Make sure frame buffer is already initialized */
|
||||
if(HlpFrameBufferData.Initialized == FALSE)
|
||||
if(FrameBufferData.Initialized == FALSE)
|
||||
{
|
||||
/* Unable to operate on non-initialized frame buffer */
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Calculate the address of the pixel in the frame buffer memory */
|
||||
PixelAddress = (PCHAR)HlpFrameBufferData.Address + (PositionY * HlpFrameBufferData.Pitch) +
|
||||
(PositionX * HlpFrameBufferData.BytesPerPixel);
|
||||
PixelAddress = (PCHAR)FrameBufferData.Address + (PositionY * FrameBufferData.Pitch) +
|
||||
(PositionX * FrameBufferData.BytesPerPixel);
|
||||
|
||||
/* 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
|
||||
ULONG
|
||||
HlpRGBColor(IN ULONG Color)
|
||||
HL::FrameBuffer::GetRGBColor(IN ULONG Color)
|
||||
{
|
||||
USHORT Blue, Green, Red, Reserved;
|
||||
|
||||
@@ -528,8 +379,158 @@ HlpRGBColor(IN ULONG Color)
|
||||
Reserved = (USHORT)((Color >> 24) & 0xFF);
|
||||
|
||||
/* Return color in FrameBuffer pixel format */
|
||||
return (ULONG)((Blue << HlpFrameBufferData.Pixels.BlueShift) | (Green << HlpFrameBufferData.Pixels.GreenShift) |
|
||||
(Red << HlpFrameBufferData.Pixels.RedShift) | (Reserved << HlpFrameBufferData.Pixels.ReservedShift));
|
||||
return (ULONG)((Blue << FrameBufferData.Pixels.BlueShift) | (Green << FrameBufferData.Pixels.GreenShift) |
|
||||
(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
|
||||
VOID
|
||||
HlpScrollRegion(VOID)
|
||||
HL::FrameBuffer::ScrollRegion(VOID)
|
||||
{
|
||||
PCHAR Destination, Source;
|
||||
PSSFN_FONT_HEADER FbFont;
|
||||
@@ -550,43 +551,85 @@ HlpScrollRegion(VOID)
|
||||
PULONG Pixel;
|
||||
|
||||
/* Make sure frame buffer is already initialized */
|
||||
if(HlpFrameBufferData.Initialized == FALSE)
|
||||
if(FrameBufferData.Initialized == FALSE)
|
||||
{
|
||||
/* Unable to operate on non-initialized frame buffer */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get font information */
|
||||
FbFont = (PSSFN_FONT_HEADER)HlpFrameBufferData.Font;
|
||||
FbFont = (PSSFN_FONT_HEADER)FrameBufferData.Font;
|
||||
|
||||
/* 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 */
|
||||
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 +
|
||||
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel;
|
||||
Destination = (PCHAR)FrameBufferData.Address + Line * FrameBufferData.Pitch +
|
||||
ScrollRegionData.Left * FrameBufferData.BytesPerPixel;
|
||||
|
||||
/* The source is one full text line (FbFont->Height) below the destination */
|
||||
Source = (PCHAR)HlpFrameBufferData.Address + (Line + FbFont->Height) * HlpFrameBufferData.Pitch +
|
||||
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel;
|
||||
Source = (PCHAR)FrameBufferData.Address + (Line + FbFont->Height) * FrameBufferData.Pitch +
|
||||
ScrollRegionData.Left * FrameBufferData.BytesPerPixel;
|
||||
|
||||
/* Move each scan line in the scroll region up */
|
||||
RtlMoveMemory(Destination, Source, LineBytes);
|
||||
RTL::Memory::MoveMemory(Destination, Source, LineBytes);
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
Pixel = (PULONG)((PCHAR)HlpFrameBufferData.Address + Line * HlpFrameBufferData.Pitch +
|
||||
HlpScrollRegionData.Left * HlpFrameBufferData.BytesPerPixel);
|
||||
Pixel = (PULONG)((PCHAR)FrameBufferData.Address + Line * FrameBufferData.Pitch +
|
||||
ScrollRegionData.Left * FrameBufferData.BytesPerPixel);
|
||||
|
||||
/* 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);
|
||||
}
|
@@ -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;
|
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/* Include common CPU interface */
|
||||
#include ARCH_COMMON(cpu.c)
|
||||
#include ARCH_COMMON(cpu.cc)
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
XTCDECL
|
||||
UCHAR
|
||||
HlIoPortInByte(IN USHORT Port)
|
||||
HL::IoPort::ReadPort8(IN USHORT Port)
|
||||
{
|
||||
UCHAR Value;
|
||||
__asm__ volatile("inb %1, %0"
|
||||
@@ -30,27 +30,6 @@ HlIoPortInByte(IN USHORT Port)
|
||||
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.
|
||||
*
|
||||
@@ -63,7 +42,7 @@ HlIoPortInLong(IN USHORT Port)
|
||||
*/
|
||||
XTCDECL
|
||||
USHORT
|
||||
HlIoPortInShort(IN USHORT Port)
|
||||
HL::IoPort::ReadPort16(IN USHORT Port)
|
||||
{
|
||||
USHORT Value;
|
||||
__asm__ volatile("inw %1, %0"
|
||||
@@ -72,6 +51,27 @@ HlIoPortInShort(IN USHORT Port)
|
||||
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.
|
||||
*
|
||||
@@ -87,8 +87,8 @@ HlIoPortInShort(IN USHORT Port)
|
||||
*/
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutByte(IN USHORT Port,
|
||||
IN UCHAR Value)
|
||||
HL::IoPort::WritePort8(IN USHORT Port,
|
||||
IN UCHAR Value)
|
||||
{
|
||||
__asm__ volatile("outb %0, %1"
|
||||
:
|
||||
@@ -96,30 +96,6 @@ HlIoPortOutByte(IN USHORT 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.
|
||||
*
|
||||
@@ -135,11 +111,35 @@ HlIoPortOutLong(IN USHORT Port,
|
||||
*/
|
||||
XTCDECL
|
||||
VOID
|
||||
HlIoPortOutShort(IN USHORT Port,
|
||||
IN USHORT Value)
|
||||
HL::IoPort::WritePort16(IN USHORT Port,
|
||||
IN USHORT Value)
|
||||
{
|
||||
__asm__ volatile("outw %0, %1"
|
||||
:
|
||||
: "a" (Value),
|
||||
"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));
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/* Include common PIC interface */
|
||||
#include ARCH_COMMON(pic.c)
|
||||
#include ARCH_COMMON(pic.cc)
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
XTFASTCALL
|
||||
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
|
||||
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
|
||||
KRUNLEVEL
|
||||
HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
HL::RunLevel::TransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
{
|
||||
STATIC KRUNLEVEL TransformationTable[16] =
|
||||
{
|
||||
@@ -90,7 +90,7 @@ HlpTransformApicTprToRunLevel(IN UCHAR Tpr)
|
||||
*/
|
||||
XTFASTCALL
|
||||
UCHAR
|
||||
HlpTransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
|
||||
HL::RunLevel::TransformRunLevelToApicTpr(IN KRUNLEVEL RunLevel)
|
||||
{
|
||||
STATIC UCHAR TransformationTable[32] =
|
||||
{
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/hl/init.c
|
||||
* FILE: xtoskrnl/hl/init.cc
|
||||
* DESCRIPTION: Hardware layer initialization code
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,19 +18,19 @@
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
HlInitializeSystem(VOID)
|
||||
HL::Init::InitializeSystem(VOID)
|
||||
{
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Initialize ACPI */
|
||||
Status = HlpInitializeAcpi();
|
||||
Status = Acpi::InitializeAcpi();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Get system information from ACPI */
|
||||
Status = HlpInitializeAcpiSystemInformation();
|
||||
Status = Acpi::InitializeAcpiSystemInformation();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
return Status;
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,13 +21,13 @@
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
HlInitializeProcessor(VOID)
|
||||
HL::Cpu::InitializeProcessor(VOID)
|
||||
{
|
||||
PKPROCESSOR_BLOCK ProcessorBlock;
|
||||
KAFFINITY Affinity;
|
||||
|
||||
/* Get current processor block */
|
||||
ProcessorBlock = KeGetCurrentProcessorBlock();
|
||||
ProcessorBlock = KE::Processor::GetCurrentProcessorBlock();
|
||||
|
||||
/* Set initial stall factor, CPU number and mask interrupts */
|
||||
ProcessorBlock->StallScaleFactor = INITIAL_STALL_FACTOR;
|
||||
@@ -37,11 +37,11 @@ HlInitializeProcessor(VOID)
|
||||
Affinity = (KAFFINITY) 1 << ProcessorBlock->CpuNumber;
|
||||
|
||||
/* Apply affinity to a set of processors */
|
||||
HlpActiveProcessors |= Affinity;
|
||||
ActiveProcessors |= Affinity;
|
||||
|
||||
/* Initialize APIC for this processor */
|
||||
HlpInitializePic();
|
||||
Pic::InitializePic();
|
||||
|
||||
/* Set the APIC running level */
|
||||
HlSetRunLevel(KeGetCurrentProcessorBlock()->RunLevel);
|
||||
HL::RunLevel::SetRunLevel(KeGetCurrentProcessorBlock()->RunLevel);
|
||||
}
|
@@ -1,100 +1,14 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
@@ -107,7 +21,7 @@ HlWriteApicRegister(IN APIC_REGISTER Register,
|
||||
*/
|
||||
XTAPI
|
||||
BOOLEAN
|
||||
HlpCheckX2ApicSupport(VOID)
|
||||
HL::Pic::CheckX2ApicSupport(VOID)
|
||||
{
|
||||
CPUID_REGISTERS CpuRegisters;
|
||||
|
||||
@@ -133,6 +47,21 @@ HlpCheckX2ApicSupport(VOID)
|
||||
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.
|
||||
*
|
||||
@@ -142,15 +71,15 @@ HlpCheckX2ApicSupport(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
HlpGetCpuApicId(VOID)
|
||||
HL::Pic::GetCpuApicId(VOID)
|
||||
{
|
||||
ULONG ApicId;
|
||||
|
||||
/* Read APIC ID register */
|
||||
ApicId = HlReadApicRegister(APIC_ID);
|
||||
ApicId = ReadApicRegister(APIC_ID);
|
||||
|
||||
/* 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
|
||||
VOID
|
||||
HlpHandleApicSpuriousService(VOID)
|
||||
HL::Pic::HandleApicSpuriousService(VOID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -175,7 +104,7 @@ HlpHandleApicSpuriousService(VOID)
|
||||
*/
|
||||
XTCDECL
|
||||
VOID
|
||||
HlpHandlePicSpuriousService(VOID)
|
||||
HL::Pic::HandlePicSpuriousService(VOID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -188,7 +117,7 @@ HlpHandlePicSpuriousService(VOID)
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
HlpInitializeApic(VOID)
|
||||
HL::Pic::InitializeApic(VOID)
|
||||
{
|
||||
APIC_SPURIOUS_REGISTER SpuriousRegister;
|
||||
APIC_BASE_REGISTER BaseRegister;
|
||||
@@ -196,49 +125,49 @@ HlpInitializeApic(VOID)
|
||||
ULONG CpuNumber;
|
||||
|
||||
/* Determine APIC mode (xAPIC compatibility or x2APIC) */
|
||||
if(HlpCheckX2ApicSupport())
|
||||
if(CheckX2ApicSupport())
|
||||
{
|
||||
/* Enable x2APIC mode */
|
||||
HlpApicMode = APIC_MODE_X2APIC;
|
||||
ApicMode = APIC_MODE_X2APIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Fall back to xAPIC compatibility mode */
|
||||
HlpApicMode = APIC_MODE_COMPAT;
|
||||
ApicMode = APIC_MODE_COMPAT;
|
||||
}
|
||||
|
||||
/* Get current processor number */
|
||||
CpuNumber = KeGetCurrentProcessorNumber();
|
||||
CpuNumber = KE::Processor::GetCurrentProcessorNumber();
|
||||
|
||||
/* Enable the APIC */
|
||||
BaseRegister.LongLong = ArReadModelSpecificRegister(APIC_LAPIC_MSR_BASE);
|
||||
BaseRegister.LongLong = AR::CpuFunc::ReadModelSpecificRegister(APIC_LAPIC_MSR_BASE);
|
||||
BaseRegister.Enable = 1;
|
||||
BaseRegister.ExtendedMode = (HlpApicMode == APIC_MODE_X2APIC);
|
||||
BaseRegister.ExtendedMode = (ApicMode == APIC_MODE_X2APIC);
|
||||
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) */
|
||||
HlWriteApicRegister(APIC_TPR, 0xFF);
|
||||
WriteApicRegister(APIC_TPR, 0xFF);
|
||||
|
||||
/* 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) */
|
||||
HlWriteApicRegister(APIC_DFR, APIC_DF_FLAT);
|
||||
WriteApicRegister(APIC_DFR, APIC_DF_FLAT);
|
||||
|
||||
/* 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 */
|
||||
SpuriousRegister.Long = HlReadApicRegister(APIC_SIVR);
|
||||
SpuriousRegister.Long = ReadApicRegister(APIC_SIVR);
|
||||
SpuriousRegister.Vector = APIC_VECTOR_SPURIOUS;
|
||||
SpuriousRegister.SoftwareEnable = 1;
|
||||
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 */
|
||||
HlWriteApicRegister(APIC_ERRLVTR, APIC_VECTOR_ERROR);
|
||||
WriteApicRegister(APIC_ERRLVTR, APIC_VECTOR_ERROR);
|
||||
|
||||
/* Program the APIC timer for periodic mode */
|
||||
LvtRegister.Long = 0;
|
||||
@@ -247,7 +176,7 @@ HlpInitializeApic(VOID)
|
||||
LvtRegister.TimerMode = 1;
|
||||
LvtRegister.TriggerMode = APIC_TGM_EDGE;
|
||||
LvtRegister.Vector = APIC_VECTOR_PROFILE;
|
||||
HlWriteApicRegister(APIC_TMRLVTR, LvtRegister.Long);
|
||||
WriteApicRegister(APIC_TMRLVTR, LvtRegister.Long);
|
||||
|
||||
/* Configure the performance counter overflow */
|
||||
LvtRegister.Long = 0;
|
||||
@@ -256,7 +185,7 @@ HlpInitializeApic(VOID)
|
||||
LvtRegister.TimerMode = 0;
|
||||
LvtRegister.TriggerMode = APIC_TGM_EDGE;
|
||||
LvtRegister.Vector = APIC_VECTOR_PERF;
|
||||
HlWriteApicRegister(APIC_PCLVTR, LvtRegister.Long);
|
||||
WriteApicRegister(APIC_PCLVTR, LvtRegister.Long);
|
||||
|
||||
/* Configure the LINT0 pin */
|
||||
LvtRegister.Long = 0;
|
||||
@@ -265,7 +194,7 @@ HlpInitializeApic(VOID)
|
||||
LvtRegister.TimerMode = 0;
|
||||
LvtRegister.TriggerMode = APIC_TGM_EDGE;
|
||||
LvtRegister.Vector = APIC_VECTOR_SPURIOUS;
|
||||
HlWriteApicRegister(APIC_LINT0, LvtRegister.Long);
|
||||
WriteApicRegister(APIC_LINT0, LvtRegister.Long);
|
||||
|
||||
/* Configure the LINT1 pin */
|
||||
LvtRegister.Long = 0;
|
||||
@@ -274,17 +203,17 @@ HlpInitializeApic(VOID)
|
||||
LvtRegister.TimerMode = 0;
|
||||
LvtRegister.TriggerMode = APIC_TGM_EDGE;
|
||||
LvtRegister.Vector = APIC_VECTOR_NMI;
|
||||
HlWriteApicRegister(APIC_LINT1, LvtRegister.Long);
|
||||
WriteApicRegister(APIC_LINT1, LvtRegister.Long);
|
||||
|
||||
/* Register interrupt handlers */
|
||||
KeSetInterruptHandler(APIC_VECTOR_SPURIOUS, HlpHandleApicSpuriousService);
|
||||
KeSetInterruptHandler(PIC1_VECTOR_SPURIOUS, HlpHandlePicSpuriousService);
|
||||
KE::Irq::SetInterruptHandler(APIC_VECTOR_SPURIOUS, (PVOID)HandleApicSpuriousService);
|
||||
KE::Irq::SetInterruptHandler(PIC1_VECTOR_SPURIOUS, (PVOID)HandlePicSpuriousService);
|
||||
|
||||
/* Clear any pre-existing errors */
|
||||
HlWriteApicRegister(APIC_ESR, 0);
|
||||
WriteApicRegister(APIC_ESR, 0);
|
||||
|
||||
/* 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
|
||||
VOID
|
||||
HlpInitializeLegacyPic(VOID)
|
||||
HL::Pic::InitializeLegacyPic(VOID)
|
||||
{
|
||||
PIC_I8259_ICW1 Icw1;
|
||||
PIC_I8259_ICW2 Icw2;
|
||||
@@ -310,16 +239,16 @@ HlpInitializeLegacyPic(VOID)
|
||||
Icw1.Interval = Interval8;
|
||||
Icw1.NeedIcw4 = TRUE;
|
||||
Icw1.OperatingMode = Cascade;
|
||||
HlIoPortOutByte(PIC1_CONTROL_PORT, Icw1.Bits);
|
||||
HL::IoPort::WritePort8(PIC1_CONTROL_PORT, Icw1.Bits);
|
||||
|
||||
/* Initialize ICW2 for PIC1 port */
|
||||
Icw2.Bits = 0x00;
|
||||
HlIoPortOutByte(PIC1_DATA_PORT, Icw2.Bits);
|
||||
HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw2.Bits);
|
||||
|
||||
/* Initialize ICW3 for PIC1 port */
|
||||
Icw3.Bits = 0;
|
||||
Icw3.SlaveIrq2 = TRUE;
|
||||
HlIoPortOutByte(PIC1_DATA_PORT, Icw3.Bits);
|
||||
HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw3.Bits);
|
||||
|
||||
/* Initialize ICW4 for PIC1 port */
|
||||
Icw4.BufferedMode = NonBuffered;
|
||||
@@ -327,10 +256,10 @@ HlpInitializeLegacyPic(VOID)
|
||||
Icw4.Reserved = 0;
|
||||
Icw4.SpecialFullyNestedMode = FALSE;
|
||||
Icw4.SystemMode = New8086Mode;
|
||||
HlIoPortOutByte(PIC1_DATA_PORT, Icw4.Bits);
|
||||
HL::IoPort::WritePort8(PIC1_DATA_PORT, Icw4.Bits);
|
||||
|
||||
/* Mask all interrupts on PIC1 port */
|
||||
HlIoPortOutByte(PIC1_DATA_PORT, 0xFF);
|
||||
HL::IoPort::WritePort8(PIC1_DATA_PORT, 0xFF);
|
||||
|
||||
/* Initialize ICW1 for PIC2 port */
|
||||
Icw1.Init = TRUE;
|
||||
@@ -339,16 +268,16 @@ HlpInitializeLegacyPic(VOID)
|
||||
Icw1.Interval = Interval8;
|
||||
Icw1.NeedIcw4 = TRUE;
|
||||
Icw1.OperatingMode = Cascade;
|
||||
HlIoPortOutByte(PIC2_CONTROL_PORT, Icw1.Bits);
|
||||
HL::IoPort::WritePort8(PIC2_CONTROL_PORT, Icw1.Bits);
|
||||
|
||||
/* Initialize ICW2 for PIC2 port */
|
||||
Icw2.Bits = 0x08;
|
||||
HlIoPortOutByte(PIC2_DATA_PORT, Icw2.Bits);
|
||||
HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw2.Bits);
|
||||
|
||||
/* Initialize ICW3 for PIC2 port */
|
||||
Icw3.Bits = 0;
|
||||
Icw3.SlaveId = 2;
|
||||
HlIoPortOutByte(PIC2_DATA_PORT, Icw3.Bits);
|
||||
HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw3.Bits);
|
||||
|
||||
/* Initialize ICW4 for PIC2 port */
|
||||
Icw4.BufferedMode = NonBuffered;
|
||||
@@ -356,10 +285,10 @@ HlpInitializeLegacyPic(VOID)
|
||||
Icw4.Reserved = 0;
|
||||
Icw4.SpecialFullyNestedMode = FALSE;
|
||||
Icw4.SystemMode = New8086Mode;
|
||||
HlIoPortOutByte(PIC2_DATA_PORT, Icw4.Bits);
|
||||
HL::IoPort::WritePort8(PIC2_DATA_PORT, Icw4.Bits);
|
||||
|
||||
/* 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
|
||||
VOID
|
||||
HlpInitializePic(VOID)
|
||||
HL::Pic::InitializePic(VOID)
|
||||
{
|
||||
/* Initialize APIC */
|
||||
HlpInitializeApic();
|
||||
InitializeApic();
|
||||
|
||||
/* 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
|
||||
VOID
|
||||
HlpSendIpi(ULONG ApicId,
|
||||
ULONG Vector)
|
||||
HL::Pic::SendIpi(ULONG ApicId,
|
||||
ULONG Vector)
|
||||
{
|
||||
/* Check current APIC mode */
|
||||
if(HlpApicMode == APIC_MODE_X2APIC)
|
||||
if(ApicMode == APIC_MODE_X2APIC)
|
||||
{
|
||||
/* Send IPI using x2APIC mode */
|
||||
HlWriteApicRegister(APIC_ICR0, ((ULONGLONG)ApicId << 32) | Vector);
|
||||
WriteApicRegister(APIC_ICR0, ((ULONGLONG)ApicId << 32) | Vector);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Send IPI using xAPIC compatibility mode */
|
||||
HlWriteApicRegister(APIC_ICR1, ApicId << 24);
|
||||
HlWriteApicRegister(APIC_ICR0, Vector);
|
||||
WriteApicRegister(APIC_ICR1, ApicId << 24);
|
||||
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);
|
||||
}
|
||||
}
|
@@ -11,7 +11,15 @@
|
||||
|
||||
#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/pic.hh>
|
||||
#include <hl/runlevel.hh>
|
||||
|
||||
|
||||
#endif /* __XTOSKRNL_HL_HH */
|
||||
|
48
xtoskrnl/includes/hl/acpi.hh
Normal file
48
xtoskrnl/includes/hl/acpi.hh
Normal 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 */
|
35
xtoskrnl/includes/hl/cport.hh
Normal file
35
xtoskrnl/includes/hl/cport.hh
Normal 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 */
|
27
xtoskrnl/includes/hl/cpu.hh
Normal file
27
xtoskrnl/includes/hl/cpu.hh
Normal 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 */
|
50
xtoskrnl/includes/hl/fbdev.hh
Normal file
50
xtoskrnl/includes/hl/fbdev.hh
Normal 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 */
|
25
xtoskrnl/includes/hl/init.hh
Normal file
25
xtoskrnl/includes/hl/init.hh
Normal 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 */
|
33
xtoskrnl/includes/hl/ioport.hh
Normal file
33
xtoskrnl/includes/hl/ioport.hh
Normal 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 */
|
43
xtoskrnl/includes/hl/pic.hh
Normal file
43
xtoskrnl/includes/hl/pic.hh
Normal 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 */
|
30
xtoskrnl/includes/hl/runlevel.hh
Normal file
30
xtoskrnl/includes/hl/runlevel.hh
Normal 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 */
|
@@ -26,8 +26,8 @@ HlComPortGetByte(IN PCPPORT Port,
|
||||
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
HlComPortPutByte(IN PCPPORT Port,
|
||||
IN UCHAR Byte);
|
||||
HlWriteComPort8(IN PCPPORT Port,
|
||||
IN UCHAR Byte);
|
||||
|
||||
XTCDECL
|
||||
UCHAR
|
||||
|
@@ -171,5 +171,5 @@ KdpSerialWriteCharacter(WCHAR Character)
|
||||
/* Write character to the serial console */
|
||||
Buffer[0] = Character;
|
||||
Buffer[1] = 0;
|
||||
return HlComPortPutByte(&KdpSerialPort, Buffer[0]);
|
||||
return HlWriteComPort(&KdpSerialPort, Buffer[0]);
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ KE::KernelInit::InitializeKernel(VOID)
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Initialize hardware layer subsystem */
|
||||
Status = HlInitializeSystem();
|
||||
Status = HL::Init::InitializeSystem();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Hardware layer initialization failed, kernel panic */
|
||||
@@ -44,14 +44,14 @@ VOID
|
||||
KE::KernelInit::InitializeMachine(VOID)
|
||||
{
|
||||
/* Re-enable IDE interrupts */
|
||||
HlIoPortOutByte(0x376, 0);
|
||||
HlIoPortOutByte(0x3F6, 0);
|
||||
HL::IoPort::WritePort8(0x376, 0);
|
||||
HL::IoPort::WritePort8(0x3F6, 0);
|
||||
|
||||
/* Initialize frame buffer */
|
||||
HlInitializeFrameBuffer();
|
||||
HL::FrameBuffer::InitializeFrameBuffer();
|
||||
|
||||
/* Initialize processor */
|
||||
HlInitializeProcessor();
|
||||
HL::Cpu::InitializeProcessor();
|
||||
|
||||
/* Initialize page map support */
|
||||
MmInitializePageMapSupport();
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/ke/data.cc
|
||||
* DESCRIPTION:
|
||||
* DESCRIPTION: Kernel Library global and static data
|
||||
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||
*/
|
||||
|
||||
|
@@ -23,7 +23,7 @@ KE::KernelInit::InitializeKernel(VOID)
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Initialize hardware layer subsystem */
|
||||
Status = HlInitializeSystem();
|
||||
Status = HL::Init::InitializeSystem();
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Hardware layer initialization failed, kernel panic */
|
||||
@@ -44,14 +44,14 @@ VOID
|
||||
KE::KernelInit::InitializeMachine(VOID)
|
||||
{
|
||||
/* Re-enable IDE interrupts */
|
||||
HlIoPortOutByte(0x376, 0);
|
||||
HlIoPortOutByte(0x3F6, 0);
|
||||
HL::IoPort::WritePort8(0x376, 0);
|
||||
HL::IoPort::WritePort8(0x3F6, 0);
|
||||
|
||||
/* Initialize frame buffer */
|
||||
HlInitializeFrameBuffer();
|
||||
HL::FrameBuffer::InitializeFrameBuffer();
|
||||
|
||||
/* Initialize processor */
|
||||
HlInitializeProcessor();
|
||||
HL::Cpu::InitializeProcessor();
|
||||
|
||||
/* Initialize page map support */
|
||||
MmInitializePageMapSupport();
|
||||
|
@@ -20,7 +20,7 @@ XTFASTCALL
|
||||
KRUNLEVEL
|
||||
KE::RunLevel::GetCurrentRunLevel(VOID)
|
||||
{
|
||||
return HlGetRunLevel();
|
||||
return HL::RunLevel::GetRunLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,13 +40,13 @@ KE::RunLevel::LowerRunLevel(IN KRUNLEVEL RunLevel)
|
||||
KRUNLEVEL OldRunLevel;
|
||||
|
||||
/* Read current run level */
|
||||
OldRunLevel = HlGetRunLevel();
|
||||
OldRunLevel = HL::RunLevel::GetRunLevel();
|
||||
|
||||
/* Validate run level lowerage */
|
||||
if(OldRunLevel > RunLevel)
|
||||
{
|
||||
/* Set new, lower run level */
|
||||
HlSetRunLevel(RunLevel);
|
||||
HL::RunLevel::SetRunLevel(RunLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ KE::RunLevel::RaiseRunLevel(IN KRUNLEVEL RunLevel)
|
||||
KRUNLEVEL OldRunLevel;
|
||||
|
||||
/* Read current run level */
|
||||
OldRunLevel = HlGetRunLevel();
|
||||
OldRunLevel = HL::RunLevel::GetRunLevel();
|
||||
|
||||
/* Validate run level raise */
|
||||
if(OldRunLevel < RunLevel)
|
||||
{
|
||||
/* Set new, higher run level */
|
||||
HlSetRunLevel(RunLevel);
|
||||
HL::RunLevel::SetRunLevel(RunLevel);
|
||||
}
|
||||
|
||||
/* Return old run level */
|
||||
|
@@ -5,15 +5,15 @@
|
||||
@ fastcall ExReInitializeRundownProtection(ptr)
|
||||
@ fastcall ExReleaseRundownProtection(ptr)
|
||||
@ fastcall ExWaitForRundownProtectionRelease(ptr)
|
||||
@ cdecl HlIoPortInByte(ptr)
|
||||
@ cdecl HlIoPortInLong(ptr)
|
||||
@ cdecl HlIoPortInShort(ptr)
|
||||
@ cdecl HlIoPortOutByte(ptr long)
|
||||
@ cdecl HlIoPortOutLong(ptr long)
|
||||
@ cdecl HlIoPortOutShort(ptr long)
|
||||
@ cdecl HlReadPort8(ptr)
|
||||
@ cdecl HlReadPort16(ptr)
|
||||
@ cdecl HlReadPort32(ptr)
|
||||
@ stdcall HlReadRegister8(ptr)
|
||||
@ stdcall HlReadRegister16(ptr)
|
||||
@ stdcall HlReadRegister32(ptr)
|
||||
@ cdecl HlWritePort8(ptr long)
|
||||
@ cdecl HlWritePort16(ptr long)
|
||||
@ cdecl HlWritePort32(ptr long)
|
||||
@ stdcall HlWriteRegister8(ptr long)
|
||||
@ stdcall HlWriteRegister16(ptr long)
|
||||
@ stdcall HlWriteRegister32(ptr long)
|
||||
|
Reference in New Issue
Block a user