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.cpp | 81 ++++++++++++++++++ drivers/acpi/Acpi.h | 178 ++++++++++++++++++++++++++++++++++++++ drivers/acpi/Ics.cpp | 7 ++ drivers/acpi/Ics.h | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/acpi.cpp | 61 ------------- drivers/acpi/acpi.h | 163 ----------------------------------- kernel/kernel.c | 21 ++++- 7 files changed, 517 insertions(+), 225 deletions(-) create mode 100644 drivers/acpi/Acpi.cpp create mode 100644 drivers/acpi/Acpi.h create mode 100644 drivers/acpi/Ics.cpp create mode 100644 drivers/acpi/Ics.h delete mode 100644 drivers/acpi/acpi.cpp delete mode 100644 drivers/acpi/acpi.h diff --git a/drivers/acpi/Acpi.cpp b/drivers/acpi/Acpi.cpp new file mode 100644 index 0000000..207c9bb --- /dev/null +++ b/drivers/acpi/Acpi.cpp @@ -0,0 +1,81 @@ +#include "Acpi.h" + + +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 uint8 Rsdp::checksunFieldSize = 20; +const uint8 Entry::size = 4; +const uint8 sizeWithoutIcs = 44; + +Rsdt *Rsdp::getRsdt() const +{ + Rsdt *rsdtPtr = (Rsdt *)(rsdtAddress); + if(rsdtPtr == nullptr or checksumCheck()) return nullptr; + else return rsdtPtr; +}; + +Xsdt *Rsdp::getXsdt() const +{ + Xsdt *xsdtPtr = (Xsdt *)(xsdtAddress); + if(xsdtPtr == nullptr or checksumCheck()) return nullptr; + else return xsdtPtr; +}; + + +const uint32 DescHeader::getLength() const +{ + return length; +}; + +const Entry *Rsdt::getEntry(uint8 index) const +{ + uint32 entriesAmount = (header.getLength() - sizeof(DescHeader)) / Entry::size; + + if(index >= entriesAmount + or header.checksumCheck()) return nullptr; + else return ((const Entry **)&entries)[index]; +}; + +uint8 Rsdp::checksumCheck() const +{ + uint8 check = 0; + for(uint32 offset = 0; offset < checksunFieldSize; offset++) + { + check += *(uint8 *)((memAddr)this + offset); + } + return check; +}; + +uint8 DescHeader::checksumCheck() const +{ + uint8 check = 0; + for(uint32 offset = 0; offset < length; offset++) + { + check += *(uint8 *)((memAddr)this + offset); + } + return check; +}; + +const Ics *Madt::getIcs(uint8 index) const +{ + uint32 icsBytesRemain = header.getLength() - ::sizeWithoutIcs; + uint16 indexAmass = 0; + const Ics *icsPtr = (Ics *)(&icsBegin); + + while(icsBytesRemain > 0) + { + if(indexAmass == index) return icsPtr; + else + { + icsBytesRemain -= icsPtr->getLength(); + indexAmass++; + icsPtr = (Ics *)((memAddr)icsPtr + icsPtr->getLength()); + } + } + + return nullptr; +}; 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; +}; diff --git a/drivers/acpi/Ics.cpp b/drivers/acpi/Ics.cpp new file mode 100644 index 0000000..754b9f0 --- /dev/null +++ b/drivers/acpi/Ics.cpp @@ -0,0 +1,7 @@ +#include "Ics.h" + + +uint8 Ics::getLength() const +{ + return length; +}; diff --git a/drivers/acpi/Ics.h b/drivers/acpi/Ics.h new file mode 100644 index 0000000..8289c90 --- /dev/null +++ b/drivers/acpi/Ics.h @@ -0,0 +1,231 @@ +#include + + +class Ics +{ + protected: + const uint8 type; + const uint8 length; + public: + Ics() = delete; + Ics(const Ics &) = delete; + uint8 getLength() const; +}; + +class LapicStruct : public Ics +{ + private: + const uint8 acpiProcUid; + const uint8 apicId; + const uint32 flags; + public: + LapicStruct() = delete; + LapicStruct(const LapicStruct &) = delete; +}; + +class IoapicStruct : public Ics +{ + private: + const uint8 ioapicId; + const uint8 reserved; + const uint32 ioapicAddr; + const uint32 globalSysIntBase; + public: + IoapicStruct() = delete; + IoapicStruct(const IoapicStruct &) = delete; +}; + +class IsoStruct : public Ics +{ + private: + const uint8 bus; + const uint8 source; + const uint32 globalSysInt; + const uint16 flags; + public: + IsoStruct() = delete; + IsoStruct(const IsoStruct &) = delete; +}; + +class NmiSourceStruct: public Ics +{ + private: + const uint16 flags; + const uint32 globalSysInt; + public: + NmiSourceStruct() = delete; + NmiSourceStruct(const NmiSourceStruct &) = delete; +}; + +class LapicNmiStruct : public Ics +{ + private: + const uint8 acpiProcUid; + const uint16 flags; + const uint8 localApicLint; + public: + LapicNmiStruct() = delete; + LapicNmiStruct(const LapicNmiStruct &) = delete; +}; + +class LapicAddrOverrrideStruct : public Ics +{ + private: + const uint16 reserved; + const uint64 lapicAddr; + public: + LapicAddrOverrrideStruct() = delete; + LapicAddrOverrrideStruct(const LapicAddrOverrrideStruct &) = delete; +}; + +class IosapicStruct : public Ics +{ + private: + const uint8 ioapicId; + const uint8 reserved; + const uint32 globSysIntBase; + const uint64 iosapicAddr; + public: + IosapicStruct() = delete; + IosapicStruct(const IosapicStruct &) = delete; +}; + +class LsapicStruct : public Ics +{ + private: + const uint8 acpiProcId; + const uint8 lsapicId; + const uint8 lsapicUid; + const uint8 reserved[3]; + const uint32 flags; + const uint32 acpiProcUidValue; + const uint8 acpiProcUidStringBegin; + public: + LsapicStruct() = delete; + LsapicStruct(const LsapicStruct &) = delete; +}; + +class PlatformIntSourceStruct : public Ics +{ + private: + const uint16 flags; + const uint8 intType; + const uint8 procId; + const uint8 procEid; + const uint8 iosapicVector; + const uint32 globSysInt; + const uint32 platformIntSourceFlags; + public: + PlatformIntSourceStruct() = delete; + PlatformIntSourceStruct(const PlatformIntSourceStruct &) = delete; +}; + +class ProcLxapicStruct : public Ics +{ + private: + const uint16 reserved; + const uint32 xapicId; + const uint32 flags; + const uint32 acpiProcUid; + public: + ProcLxapicStruct() = delete; + ProcLxapicStruct(const ProcLxapicStruct &) = delete; +}; + +class LocalXapicNmiStruct : public Ics +{ + private: + const uint16 flags; + const uint32 acpiProcUid; + const uint8 localXapicLint; + const uint8 reserved[3]; + public: + LocalXapicNmiStruct() = delete; + LocalXapicNmiStruct(const LocalXapicNmiStruct &) = delete; +}; + +class GiccStruct : public Ics +{ + private: + const uint16 reservedBegin; + const uint32 cpuInterfaceNumber; + const uint32 acpiProcUid; + const uint32 flags; + const uint32 parkingProtocolVersion; + const uint32 performanceIntGsiv; + const uint64 parkedAddr; + const uint64 physBaseAddr; + const uint64 gicv; + const uint64 gich; + const uint32 vgicMaintenanceInt; + const uint64 gicrBaseAddr; + const uint64 mpidr; + const uint8 ProcPowerEfficiencyClass; + const uint8 reservedEnd; + const uint16 speOverflowInterrupt; + public: + GiccStruct() = delete; + GiccStruct(const GiccStruct &) = delete; +}; + +class GicdStruct : public Ics +{ + private: + const uint16 reservedBegin; + const uint32 gicId; + const uint64 physBaseAddr; + const uint32 sysVectorBase; + const uint8 gicVersion; + const uint8 reservedEnd[3]; + public: + GicdStruct() = delete; + GicdStruct(const GicdStruct &) = delete; +}; + +class GisMsiFrameStruct : public Ics +{ + private: + const uint16 reserved; + const uint32 gicMsiFrameId; + const uint64 physBaseAddr; + const uint32 flags; + const uint16 spiCount; + const uint16 spiBase; + public: + GisMsiFrameStruct() = delete; + GisMsiFrameStruct(const GisMsiFrameStruct &) = delete; +}; + +class GicrStruct : public Ics +{ + private: + const uint16 reserved; + const uint64 discoveryRangeBaseAddr; + const uint32 discoveryRangeLength; + public: + GicrStruct() = delete; + GicrStruct(const GicrStruct &) = delete; +}; + +class ItsStruct : public Ics +{ + private: + const uint16 reserved; + const uint32 GicItsId; + const uint64 physBaseAddr; + const uint32 reservedEnd; + public: + ItsStruct() = delete; + ItsStruct(const ItsStruct &) = delete; +}; + +class MprocWakeupStruct : Ics +{ + private: + const uint16 mailBoxVersion; + const uint32 reserved; + const uint64 mailBoxAddr; + public: + MprocWakeupStruct() = delete; + MprocWakeupStruct(const MprocWakeupStruct &) = delete; +}; diff --git a/drivers/acpi/acpi.cpp b/drivers/acpi/acpi.cpp deleted file mode 100644 index 25dad9d..0000000 --- a/drivers/acpi/acpi.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "acpi.h" - - -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 uint8 Rsdp::checksunFieldSize = 20; -// Entry **Rsdt::entries = nullptr; - -Rsdt *Rsdp::getRsdt() const -{ - Rsdt *rsdtPtr = (Rsdt *)(rsdtAddress); - if(rsdtPtr == nullptr or checksumCheck()) return nullptr; - else return rsdtPtr; -}; - -Xsdt *Rsdp::getXsdt() const -{ - Xsdt *xsdtPtr = (Xsdt *)(xsdtAddress); - if(xsdtPtr == nullptr or checksumCheck()) return nullptr; - else return xsdtPtr; -}; - - -const uint32 DescHeader::getLength() const -{ - return length; -}; - -const Entry *Rsdt::getEntry(uint8 index) -{ - uint32 entriesAmount = (header.getLength() - sizeof(DescHeader)) / Entry::size; - - if(index >= entriesAmount - or entries == nullptr - or header.checksumCheck()) return nullptr; - else return ((const Entry **)&entries)[index]; -}; - -uint8 Rsdp::checksumCheck() const -{ - uint8 check = 0; - for(uint32 offset = 0; offset < checksunFieldSize; offset++) - { - check += *(uint8 *)((memAddr)this + offset); - } - return check; -}; - -uint8 DescHeader::checksumCheck() const -{ - uint8 check = 0; - for(uint32 offset = 0; offset < length; offset++) - { - check += *(uint8 *)((memAddr)this + offset); - } - return check; -}; diff --git a/drivers/acpi/acpi.h b/drivers/acpi/acpi.h deleted file mode 100644 index 069c954..0000000 --- a/drivers/acpi/acpi.h +++ /dev/null @@ -1,163 +0,0 @@ -#include -#include - - -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; -}; - -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 = 4; - protected: - const DescHeader header; - public: - Entry() = delete; - Entry(const Entry &) = delete; -} __attribute__((packed)); - -class FadtEntry : 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: - FadtEntry() = delete; - FadtEntry(const FadtEntry &) = delete; -} __attribute__((packed)); - -class Rsdt -{ - private: - const DescHeader header; - const Entry **entries; - public: - Rsdt() = delete; - Rsdt(const Rsdt &) = delete; - const Entry *getEntry(uint8 index); -} __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; -}; diff --git a/kernel/kernel.c b/kernel/kernel.c index dfb03e4..1fb167f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,6 +1,9 @@ #include "../arch/SecondaryInit.h" +#include "../drivers/acpi/Acpi.h" +#include -#include "../arch/x86/cpuinfo/Cpuinfo.h" + +void empty() {}; void main() { @@ -10,4 +13,20 @@ void main() init.devicesInitialize(); out::display << "Hello, World!\n"; + Rsdp *rsdp = (Rsdp *)StringOperations::findInMemory(Rsdp::signatureString, + MemArea( + Rsdp::romAreaStart, + Rsdp::romAreaEnd)); + const Rsdt *rsdt = rsdp->getRsdt(); + const Entry *entry = rsdt->getEntry(1); + const Madt *madt = (Madt *)entry; + const Ics *icsEntry[10] = {madt->getIcs(0), + madt->getIcs(1), + madt->getIcs(2), + madt->getIcs(3), + madt->getIcs(4), + madt->getIcs(5), + madt->getIcs(6), + madt->getIcs(7)}; + empty(); }; -- 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 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