From e0bac2387b373316337b177fe8aa9851b0d5e870 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Tue, 26 Mar 2024 13:51:05 +0700 Subject: Implement MADT table --- drivers/acpi/Acpi.h | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 drivers/acpi/Acpi.h (limited to 'drivers/acpi/Acpi.h') diff --git a/drivers/acpi/Acpi.h b/drivers/acpi/Acpi.h new file mode 100644 index 0000000..6a5c806 --- /dev/null +++ b/drivers/acpi/Acpi.h @@ -0,0 +1,178 @@ +#include +#include +#include "Ics.h" + + +typedef decltype(nullptr) nulltype; + +class Gas +{ + private: + const uint8 addressSpaceId; + const uint8 registerBitWidth; + const uint8 registerBitOffset; + const uint8 accessSize; + const uint64 address; + public: + Gas(); + Gas(const Gas &) = default; +} __attribute__((packed)); + +class DescHeader +{ + private: + const char signature[4]; + const uint32 length; + const uint8 revision; + const uint8 checksum; + const char oemId[6]; + const uint64 oemTableId; + const uint32 oemRevision; + const uint32 creatorId; + const uint32 creatorRevision; + public: + DescHeader() = delete; + DescHeader(const DescHeader &) = delete; + const uint32 getLength() const; + uint8 checksumCheck() const; +} __attribute__((packed)); + + +class Entry +{ + public: + // In bytes + static const uint8 size; + protected: + const DescHeader header; + public: + Entry() = delete; + Entry(const Entry &) = delete; +} __attribute__((packed)); + +class Fadt : public Entry +{ + private: + const uint32 firmwareCtrl; + const uint32 dsdt; + const uint8 reserved; + const uint8 preferredPmProfile; + const uint16 sciInt; + const uint32 smiCmd; + const uint8 acpiEnable; + const uint8 acpiDisable; + const uint8 s4biosReq; + const uint8 pstateCnt; + const uint32 pm1AEvtBlk; + const uint32 pm1BEvtBlk; + const uint32 pm1ACntBlk; + const uint32 pm1BCntBlk; + const uint32 pm2CntBlk; + const uint32 pmTmrBlk; + const uint32 gpe0Blk; + const uint32 gpe1Blk; + const uint8 pm1EvtLen; + const uint8 pm1CntLen; + const uint8 pm2CntLen; + const uint8 pmTmrLen; + const uint8 gpe0BlkLen; + const uint8 gpe1BlkLen; + const uint8 gpe1Base; + const uint8 cstCnt; + const uint16 pLvl2Lat; + const uint16 pLvl3Lat; + const uint16 flushSize; + const uint16 flushStride; + const uint8 dutyOffset; + const uint8 dutyWidth; + const uint8 dayAlrm; + const uint8 monAlrm; + const uint8 century; + const uint16 iapcBootArch; + const uint8 reservedTwo; + const uint32 flags; + const Gas resetReg; + const uint8 resetValue; + const uint16 armBootArch; + const uint8 minorRevision; + const uint64 xFirmwareCtrl; + const uint64 xDsdt; + const Gas xPm1AEvtBlk; + const Gas xPm1BEvtBlk; + const Gas xPm1ACntBlk; + const Gas xPm1BCntBlk; + const Gas xPm2CntBlk; + const Gas xPmTmrBlk; + const Gas xGpe0Blk; + const Gas xGpe1Blk; + const Gas sleepControlReg; + const Gas sleepStatusReg; + const uint64 hypervisorVendorIdentity; + public: + Fadt() = delete; + Fadt(const Fadt &) = delete; +} __attribute__((packed)); + +class Madt : Entry +{ + public: + const static uint8 sizeWithoutIcs; + private: + const uint32 localIntControlerAddr; + const uint32 flags; + const uint8 icsBegin; + public: + Madt() = delete; + Madt(const Madt &) = delete; + const Ics *getIcs(uint8 index) const; +} __attribute__((packed)); + +class Rsdt +{ + private: + const DescHeader header; + const uint8 entries; + public: + Rsdt() = delete; + Rsdt(const Rsdt &) = delete; + const Entry *getEntry(uint8 index) const; +} __attribute__((packed, aligned(sizeof(uint32)))); + +class Xsdt +{ + private: + const DescHeader header; + const uint64 firstEntryAddr; + public: + Xsdt() = delete; + Xsdt(const Xsdt &) = delete; +} __attribute__((packed)); + +class Rsdp +{ + public: + const static uint8 validFieldRevision; + // RSDP memory address areas in IA-PC systems + const static char *signatureString; + const static memAddr romAreaStart; + const static memAddr romAreaEnd; + const static memAddr ebdaAreaStart; + const static memAddr ebdaAreaEnd; + private: + const static uint8 checksunFieldSize; + const char signature[8]; + const uint8 checksum; + const char oemId[6]; + const uint8 revision; + const uint32 rsdtAddress; + const uint32 length; + const uint32 xsdtAddress; + const uint8 extendedChecksum; + const char reserved[3]; + public: + Rsdp() = delete; + Rsdp(const Rsdp &) = delete; + Rsdt *getRsdt() const; + Xsdt *getXsdt() const; + uint8 checksumCheck() const; +}; -- cgit v1.2.3 From e51dea0b6e34c2959b3b0f4a5db6b11d4b619960 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Wed, 27 Mar 2024 19:49:10 +0700 Subject: Some updates: rename memAddr, define architecture --- arch/SecondaryInit.h | 4 ++++ arch/x86/PrimaryInit.h | 2 -- drivers/acpi/Acpi.cpp | 16 +++++++++------- drivers/acpi/Acpi.h | 8 ++++---- include/StringOperations.cpp | 6 +++--- include/StringOperations.h | 10 +++++----- include/arch | 6 ++++++ include/types.h | 17 ++++++++++++++--- kernel/kernel.c | 6 ++++-- 9 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 include/arch (limited to 'drivers/acpi/Acpi.h') diff --git a/arch/SecondaryInit.h b/arch/SecondaryInit.h index f9aa5be..f11c7be 100644 --- a/arch/SecondaryInit.h +++ b/arch/SecondaryInit.h @@ -1,4 +1,8 @@ +#include + +#if defined(__IAPC) #include "x86/PrimaryInit.h" +#endif class SecondaryInitialization : protected PrimaryInitialization { diff --git a/arch/x86/PrimaryInit.h b/arch/x86/PrimaryInit.h index 8d16549..243c731 100644 --- a/arch/x86/PrimaryInit.h +++ b/arch/x86/PrimaryInit.h @@ -2,8 +2,6 @@ #include "io/VGADisplay.h" -#define x86_ARCH - class PrimaryInitialization { protected: diff --git a/drivers/acpi/Acpi.cpp b/drivers/acpi/Acpi.cpp index 207c9bb..6551c6a 100644 --- a/drivers/acpi/Acpi.cpp +++ b/drivers/acpi/Acpi.cpp @@ -3,10 +3,10 @@ const char *Rsdp::signatureString = "RSD PTR "; const uint8 Rsdp::validFieldRevision = 2; -const memAddr Rsdp::romAreaStart = 0xe0000; -const memAddr Rsdp::romAreaEnd = 0xfffff; -const memAddr Rsdp::ebdaAreaStart = 0x80000; -const memAddr Rsdp::ebdaAreaEnd = 0x803ff; +const uintptr Rsdp::romAreaStart = 0xe0000; +const uintptr Rsdp::romAreaEnd = 0xfffff; +const uintptr Rsdp::ebdaAreaStart = 0x80000; +const uintptr Rsdp::ebdaAreaEnd = 0x803ff; const uint8 Rsdp::checksunFieldSize = 20; const uint8 Entry::size = 4; const uint8 sizeWithoutIcs = 44; @@ -45,7 +45,7 @@ uint8 Rsdp::checksumCheck() const uint8 check = 0; for(uint32 offset = 0; offset < checksunFieldSize; offset++) { - check += *(uint8 *)((memAddr)this + offset); + check += *(uint8 *)((uintptr)this + offset); } return check; }; @@ -55,13 +55,15 @@ uint8 DescHeader::checksumCheck() const uint8 check = 0; for(uint32 offset = 0; offset < length; offset++) { - check += *(uint8 *)((memAddr)this + offset); + check += *(uint8 *)((uintptr)this + offset); } return check; }; const Ics *Madt::getIcs(uint8 index) const { + if(header.checksumCheck()) return nullptr; + uint32 icsBytesRemain = header.getLength() - ::sizeWithoutIcs; uint16 indexAmass = 0; const Ics *icsPtr = (Ics *)(&icsBegin); @@ -73,7 +75,7 @@ const Ics *Madt::getIcs(uint8 index) const { icsBytesRemain -= icsPtr->getLength(); indexAmass++; - icsPtr = (Ics *)((memAddr)icsPtr + icsPtr->getLength()); + icsPtr = (Ics *)((uintptr)icsPtr + icsPtr->getLength()); } } diff --git a/drivers/acpi/Acpi.h b/drivers/acpi/Acpi.h index 6a5c806..506ab99 100644 --- a/drivers/acpi/Acpi.h +++ b/drivers/acpi/Acpi.h @@ -154,10 +154,10 @@ class Rsdp const static uint8 validFieldRevision; // RSDP memory address areas in IA-PC systems const static char *signatureString; - const static memAddr romAreaStart; - const static memAddr romAreaEnd; - const static memAddr ebdaAreaStart; - const static memAddr ebdaAreaEnd; + const static uintptr romAreaStart; + const static uintptr romAreaEnd; + const static uintptr ebdaAreaStart; + const static uintptr ebdaAreaEnd; private: const static uint8 checksunFieldSize; const char signature[8]; diff --git a/include/StringOperations.cpp b/include/StringOperations.cpp index 01e7a76..055892e 100644 --- a/include/StringOperations.cpp +++ b/include/StringOperations.cpp @@ -6,7 +6,7 @@ MemArea::MemArea() start = final = NULL; }; -MemArea::MemArea(const memAddr start, const memAddr final) +MemArea::MemArea(const uintptr start, const uintptr final) { this->start = start; this->final = final; @@ -17,12 +17,12 @@ MemArea::MemArea(const memAddr start, const memAddr final) } }; -memAddr MemArea::begin() +uintptr MemArea::begin() { return start; } -memAddr MemArea::end() +uintptr MemArea::end() { if(start == final) return start; else return final + 1; diff --git a/include/StringOperations.h b/include/StringOperations.h index 81d7144..5d2826c 100644 --- a/include/StringOperations.h +++ b/include/StringOperations.h @@ -7,15 +7,15 @@ class MemArea { private: - memAddr start, final; + uintptr start, final; public: MemArea(); - MemArea(const memAddr start, const memAddr final); - memAddr begin(); - memAddr end(); + MemArea(const uintptr start, const uintptr final); + uintptr begin(); + uintptr end(); bool valid(); - typedef memAddr iterator; + typedef uintptr iterator; }; class StringOperations diff --git a/include/arch b/include/arch new file mode 100644 index 0000000..f5fc8f7 --- /dev/null +++ b/include/arch @@ -0,0 +1,6 @@ +#ifndef ARCH_H +#define ARCH_H + +#define __IAPC + +#endif diff --git a/include/types.h b/include/types.h index e578adb..f7c0eb6 100644 --- a/include/types.h +++ b/include/types.h @@ -1,13 +1,24 @@ -#define NULL 0 +#ifndef TYPES_H +#define TYPES_H + +#include +#define NULL 0 + +#if defined(__IAPC) typedef unsigned char uint8; typedef unsigned short int uint16; typedef unsigned long uint32; typedef unsigned long long uint64; #if defined(__x86_64) - typedef uint64 memAddr; + typedef uint64 uintptr; #else - typedef uint32 memAddr; + typedef uint32 uintptr; +#endif +#else + #error IA-PC only support +#endif + #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 1fb167f..36fb0fd 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -2,7 +2,6 @@ #include "../drivers/acpi/Acpi.h" #include - void empty() {}; void main() @@ -27,6 +26,9 @@ void main() madt->getIcs(4), madt->getIcs(5), madt->getIcs(6), - madt->getIcs(7)}; + madt->getIcs(7), + madt->getIcs(8)}; + const IoapicStruct *ioapicStruct = (IoapicStruct *)icsEntry[1]; + out::display << '\n'; empty(); }; -- cgit v1.2.3