-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupts.cpp
59 lines (42 loc) · 1.77 KB
/
interrupts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "interrupts.h"
void printf(char* str);
InterruptManager::GateDescriptor InterruptManager::interruptDescriptorTable[256];
void InterruptManager::SetInterruptDescriptorTableEntry(
uint8_t interruptnumber,
uint16_t codeSegmentSelectorOffset,
void (*handler)(),
uint8_t DescriptorPrivilegeLevel,
uint8_t DescriptorType)
{
const uint8_t IDT_DESC_PRESENT = 0x80;
interruptDescriptorTable[interruptnumber].handlerAddressLowBits = ((uint32_t)handler) & 0xFFFF;
interruptDescriptorTable[interruptnumber].handlerAddressHighBits = (((uint32_t)handler) >> 16) & 0xFFFF;
interruptDescriptorTable[interruptnumber].gdt_codeSegmentSelector = codeSegmentSelectorOffset;
interruptDescriptorTable[interruptnumber].access = IDT_DESC_PRESENT | DescriptorType | ((DescriptorPrivilegeLevel&3) << 5);
interruptDescriptorTable[interruptnumber].reserved = 0;
}
InterruptManager::InterruptManager(GlobalDescriptorTable* gdt)
{
uint16_t CodeSegment = gdt->CodeSegmentSelector();
const uint8_t IDT_INTERRUPT_GATE = 0xE;
for(uint16_t i=0; i<256; i++)
SetInterruptDescriptorTable[i, CodeSegment, &IgnoreInterruptRequest, 0, IDT_INTERRUPT_GATE];
SetInterruptDescriptorTable[0x20, CodeSegment, &HandleInterruptRequest0x00, 0, IDT_INTERRUPT_GATE];
SetInterruptDescriptorTable[0x21, CodeSegment, &HandleInterruptRequest0x01, 0, IDT_INTERRUPT_GATE];
InterruptDescriptorTablePointer idt;
idt.size = 256 * sizeof(GateDescriptor) - 1;
idt.base = (uint32_t)interruptDescriptorTable;
asm volatile("lidt %0" : : "m" (idt));
}
InterruptManager::~InterruptManager()
{
}
void InterruptManager::Activate()
{
asm("sti");
}
uint32_t InterruptManager::handleInterrupt(uint8_t interruptNumber, uint32_t esp)
{
printf(" INTERRUPT");
return esp;
}