diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-03-27 19:50:26 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-27 19:50:26 +0700 |
| commit | a276644952ed018e77ca64181059434a6bc4ee62 (patch) | |
| tree | e6a457ec4b2758c0c3bef78df475ad52d92a7ab4 | |
| parent | 91b4d8fa6bed598e2969f16a7a953e293a1b7f89 (diff) | |
| parent | e51dea0b6e34c2959b3b0f4a5db6b11d4b619960 (diff) | |
Merge pull request #5 from rebovas/acpi_madt
Acpi madt + some updates
| -rw-r--r-- | arch/SecondaryInit.h | 4 | ||||
| -rw-r--r-- | arch/x86/PrimaryInit.h | 2 | ||||
| -rw-r--r-- | drivers/acpi/Acpi.cpp (renamed from drivers/acpi/acpi.cpp) | 42 | ||||
| -rw-r--r-- | drivers/acpi/Acpi.h (renamed from drivers/acpi/acpi.h) | 37 | ||||
| -rw-r--r-- | drivers/acpi/Ics.cpp | 7 | ||||
| -rw-r--r-- | drivers/acpi/Ics.h | 231 | ||||
| -rw-r--r-- | include/StringOperations.cpp | 6 | ||||
| -rw-r--r-- | include/StringOperations.h | 10 | ||||
| -rw-r--r-- | include/arch | 6 | ||||
| -rw-r--r-- | include/types.h | 17 | ||||
| -rw-r--r-- | kernel/kernel.c | 23 |
11 files changed, 350 insertions, 35 deletions
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 <arch> + +#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 25dad9d..6551c6a 100644 --- a/drivers/acpi/acpi.cpp +++ b/drivers/acpi/Acpi.cpp @@ -1,14 +1,15 @@ -#include "acpi.h" +#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 uintptr Rsdp::romAreaStart = 0xe0000; +const uintptr Rsdp::romAreaEnd = 0xfffff; +const uintptr Rsdp::ebdaAreaStart = 0x80000; +const uintptr Rsdp::ebdaAreaEnd = 0x803ff; const uint8 Rsdp::checksunFieldSize = 20; -// Entry **Rsdt::entries = nullptr; +const uint8 Entry::size = 4; +const uint8 sizeWithoutIcs = 44; Rsdt *Rsdp::getRsdt() const { @@ -30,12 +31,11 @@ const uint32 DescHeader::getLength() const return length; }; -const Entry *Rsdt::getEntry(uint8 index) +const Entry *Rsdt::getEntry(uint8 index) const { 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]; }; @@ -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,7 +55,29 @@ 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); + + while(icsBytesRemain > 0) + { + if(indexAmass == index) return icsPtr; + else + { + icsBytesRemain -= icsPtr->getLength(); + indexAmass++; + icsPtr = (Ics *)((uintptr)icsPtr + icsPtr->getLength()); + } + } + + return nullptr; +}; diff --git a/drivers/acpi/acpi.h b/drivers/acpi/Acpi.h index 069c954..506ab99 100644 --- a/drivers/acpi/acpi.h +++ b/drivers/acpi/Acpi.h @@ -1,5 +1,6 @@ #include <types.h> #include <StringOperations.h> +#include "Ics.h" typedef decltype(nullptr) nulltype; @@ -15,7 +16,7 @@ class Gas public: Gas(); Gas(const Gas &) = default; -}; +} __attribute__((packed)); class DescHeader { @@ -41,7 +42,7 @@ class Entry { public: // In bytes - static const uint8 size = 4; + static const uint8 size; protected: const DescHeader header; public: @@ -49,7 +50,7 @@ class Entry Entry(const Entry &) = delete; } __attribute__((packed)); -class FadtEntry : public Entry +class Fadt : public Entry { private: const uint32 firmwareCtrl; @@ -108,19 +109,33 @@ class FadtEntry : public Entry const Gas sleepStatusReg; const uint64 hypervisorVendorIdentity; public: - FadtEntry() = delete; - FadtEntry(const FadtEntry &) = delete; + 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 Entry **entries; + const uint8 entries; public: Rsdt() = delete; Rsdt(const Rsdt &) = delete; - const Entry *getEntry(uint8 index); + const Entry *getEntry(uint8 index) const; } __attribute__((packed, aligned(sizeof(uint32)))); class Xsdt @@ -139,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/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 <types.h> + + +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/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 <arch> +#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 dfb03e4..36fb0fd 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,6 +1,8 @@ #include "../arch/SecondaryInit.h" +#include "../drivers/acpi/Acpi.h" +#include <StringOperations.h> -#include "../arch/x86/cpuinfo/Cpuinfo.h" +void empty() {}; void main() { @@ -10,4 +12,23 @@ 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), + madt->getIcs(8)}; + const IoapicStruct *ioapicStruct = (IoapicStruct *)icsEntry[1]; + out::display << '\n'; + empty(); }; |
