summaryrefslogtreecommitdiffstats
path: root/arch/x86/idt
diff options
context:
space:
mode:
authorAlexey Gavrilov <90127298+rebovas@users.noreply.github.com>2024-04-10 13:12:08 +0700
committerGitHub <noreply@github.com>2024-04-10 13:12:08 +0700
commit0a50b1758fd3da118408fd724825d0a50a9ecf17 (patch)
tree783ed019c87c3c9624a1a13f68c7bafc4c146dfb /arch/x86/idt
parent9ad5b9b6a1f8d641ac13f7c004afd6ea9bff50ee (diff)
parent0c56a0300b7ffbab787a4c974bc164d9a2a57ad2 (diff)
Merge pull request #8 from rebovas/msr
Msr + interrupts implement + crude implementation of IDT filling
Diffstat (limited to 'arch/x86/idt')
-rw-r--r--arch/x86/idt/Idt.cpp46
-rw-r--r--arch/x86/idt/Idt.h10
2 files changed, 53 insertions, 3 deletions
diff --git a/arch/x86/idt/Idt.cpp b/arch/x86/idt/Idt.cpp
index d489f0e..cd263fb 100644
--- a/arch/x86/idt/Idt.cpp
+++ b/arch/x86/idt/Idt.cpp
@@ -69,6 +69,15 @@ DescInterrupt32 DescInterrupt32::TaskKernel(uint16 selector)
);
};
+bool MngIdt::isIntReserved(uint8 interrupt)
+{
+ for(uint8 indx = 0; indx < reservedIntSize; indx++)
+ {
+ if(reservedInts[indx] == interrupt) return true;
+ }
+ return false;
+};
+
MngIdt::MngIdt()
{
if(!isInitialize)
@@ -88,9 +97,10 @@ bool MngIdt::canDescriptorWrite(uint8 idx)
bool MngIdt::addDescriptor(DescInterrupt32 desc)
{
- if(!canDescriptorWrite(currIdx)) return false;
+ if(!canDescriptorWrite(currIdx) or isIntReserved(currIdx)) return false;
- idt[currIdx++] = desc.getDescriptor();
+ idt[currIdx] = desc.getDescriptor();
+ while(isIntReserved(++currIdx));
return true;
};
@@ -108,7 +118,7 @@ bool MngIdt::loadIdt()
//Set descriptor
uint64 descriptor = 0;
- uint16 size = sizeof(uint64) * size - 1;
+ uint16 size = sizeof(uint64) * this->size - 1;
uint32 offset = (uint32)(&idt);
descriptor |= offset;
@@ -128,3 +138,33 @@ MngIdt &MngIdt::getInstance()
if(!isInitialize) mngIdt = MngIdt();
return mngIdt;
};
+
+void DescInterrupt32::setOffset(uint32 offset)
+{
+ uint8 gateType = attributes & 0x0f;
+
+ if(!(gateType == TSK_GATE and offset != 0))
+ {
+ offsetLow = offset & 0xffff;
+ offsetHight = (offset & 0xffff0000) >> 16;
+ }
+};
+void DescInterrupt32::setGateType(uint8 gateType)
+{
+ if(gateType < TSK_GATE
+ or (gateType > TRAP_GATE_16 and gateType < INT_GATE_32)
+ or gateType > TRAP_GATE_32
+ ) return;
+ else if(gateType == TSK_GATE)
+ {
+ offsetLow = offsetHight = 0;
+ }
+
+ attributes &= 0xfff0;
+ attributes |= (gateType & 0x0f);
+};
+
+void DescInterrupt32::setDpl(uint8 dpl)
+{
+ attributes = (dpl & 0x03) << 5;
+};
diff --git a/arch/x86/idt/Idt.h b/arch/x86/idt/Idt.h
index c90b674..7370526 100644
--- a/arch/x86/idt/Idt.h
+++ b/arch/x86/idt/Idt.h
@@ -32,6 +32,9 @@ class DescInterrupt32
DescInterrupt32() = default;
DescInterrupt32(const DescInterrupt32 &) = default;
DescInterrupt32(uint32 offset, uint16 selector, uint8 attr);
+ void setOffset(uint32 offset);
+ void setGateType(uint8 gateType);
+ void setDpl(uint8 dpl);
uint64 getDescriptor();
static DescInterrupt32 InterruptKernelLong(uint32 offset,
uint16 selector);
@@ -43,6 +46,13 @@ class DescInterrupt32
class MngIdt
{
private:
+ const static uint8 reservedIntSize = 12;
+ constexpr static uint8 reservedInts[reservedIntSize] =
+ {
+ 9, 15, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
+ };
+ // If false interrupt number isn't reserved, true - reserved
+ bool isIntReserved(uint8 interrupt);
const static uint8 size = 255;
static uint64 idt[size];
static bool isInitialize;