diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-05-24 14:33:19 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-24 14:33:19 +0700 |
| commit | dc0b89fa63a181bd4add318bfd7a46344702f4e7 (patch) | |
| tree | 48e25b199ae3459e12c7202f7b18a37cd087bf9b /arch/x86/idt | |
| parent | 0a50b1758fd3da118408fd724825d0a50a9ecf17 (diff) | |
| parent | 5fbf41e967ed8e413ecf1e6abb72e8d285169df4 (diff) | |
Pic + Tuple + refactor PrimaryInitialization class
Diffstat (limited to 'arch/x86/idt')
| -rw-r--r-- | arch/x86/idt/Idt.cpp | 36 | ||||
| -rw-r--r-- | arch/x86/idt/Idt.h | 14 |
2 files changed, 44 insertions, 6 deletions
diff --git a/arch/x86/idt/Idt.cpp b/arch/x86/idt/Idt.cpp index cd263fb..e24cbfe 100644 --- a/arch/x86/idt/Idt.cpp +++ b/arch/x86/idt/Idt.cpp @@ -30,7 +30,7 @@ DescInterrupt32::DescInterrupt32(uint32 offset, uint16 selector, uint8 attr) } }; -uint64 DescInterrupt32::getDescriptor() +uint64 DescInterrupt32::getDescriptor() const { uint64 desc = 0; @@ -42,6 +42,11 @@ uint64 DescInterrupt32::getDescriptor() return desc; }; +uint32 DescInterrupt32::getOffset() const +{ + return offsetLow | offsetHight << 16; +}; + DescInterrupt32 DescInterrupt32::InterruptKernelLong(uint32 offset, uint16 selector) { return DescInterrupt32( @@ -86,6 +91,7 @@ MngIdt::MngIdt() currIdx = NULL; idtLoaded = false; isInitialize = true; + irqInterruptStart = firstSystemIntNumber; } }; @@ -97,10 +103,24 @@ bool MngIdt::canDescriptorWrite(uint8 idx) bool MngIdt::addDescriptor(DescInterrupt32 desc) { - if(!canDescriptorWrite(currIdx) or isIntReserved(currIdx)) return false; + uint64 descqw = desc.getDescriptor(); + + if(!canDescriptorWrite(currIdx) or isIntReserved(currIdx) + or desc.getOffset() == NULL) return false; + + idt[currIdx] = descqw; + + uint8 attributes = descqw >> 40; + + if((attributes & RING_DRIVERSH or + attributes & RING_DRIVERSL) and + (irqInterruptStart == firstSystemIntNumber)) + { + irqInterruptStart = (uint8)(descqw >> 16); + } - idt[currIdx] = desc.getDescriptor(); while(isIntReserved(++currIdx)); + return true; }; @@ -168,3 +188,13 @@ void DescInterrupt32::setDpl(uint8 dpl) { attributes = (dpl & 0x03) << 5; }; + +bool MngIdt::isInterruptSet(uint8 numberInterrupt) +{ + return idt[numberInterrupt]; +}; + +uint8 MngIdt::getIrqInterruptStart() +{ + return irqInterruptStart; +}; diff --git a/arch/x86/idt/Idt.h b/arch/x86/idt/Idt.h index 7370526..3054fd5 100644 --- a/arch/x86/idt/Idt.h +++ b/arch/x86/idt/Idt.h @@ -35,8 +35,9 @@ class DescInterrupt32 void setOffset(uint32 offset); void setGateType(uint8 gateType); void setDpl(uint8 dpl); - uint64 getDescriptor(); - static DescInterrupt32 InterruptKernelLong(uint32 offset, + uint64 getDescriptor() const; + uint32 getOffset() const; + static DescInterrupt32 InterruptKernelLong(uint32 offset, uint16 selector); static DescInterrupt32 TrapKernelLong(uint32 offset, uint16 selector); @@ -47,7 +48,7 @@ class MngIdt { private: const static uint8 reservedIntSize = 12; - constexpr static uint8 reservedInts[reservedIntSize] = + constexpr static uint8 reservedInts[reservedIntSize] = { 9, 15, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; @@ -58,7 +59,12 @@ class MngIdt static bool isInitialize; static bool idtLoaded; uint8 currIdx; + // Start number of interrupts that service IRQ + // Accpet this number as first interrupt descriptor + // with dpl = 2 or 3 (drivers) + uint8 irqInterruptStart; public: + const static uint8 firstSystemIntNumber = 0x20; MngIdt(); MngIdt(const MngIdt &) = delete; bool addDescriptor(DescInterrupt32 desc); @@ -66,6 +72,8 @@ class MngIdt bool canDescriptorWrite(uint8 idx); bool loadIdt(); static MngIdt &getInstance(); + uint8 getIrqInterruptStart(); + bool isInterruptSet(uint8 numberInterrupt); }; extern MngIdt mngIdt; |
