Adds improved interrupt handling.

This commit is contained in:
Felix Queißner 2016-05-05 19:38:40 +02:00
parent bae2c0a763
commit 5829e701df
4 changed files with 66 additions and 18 deletions

View file

@ -12,7 +12,7 @@ struct CpuState
uint32_t edi; uint32_t edi;
uint32_t ebp; uint32_t ebp;
uint32_t intr; uint32_t interrupt;
uint32_t error; uint32_t error;
uint32_t eip; uint32_t eip;

View file

@ -9,9 +9,20 @@ private:
public: public:
PIC(uint16_t port); PIC(uint16_t port);
/**
* Sends an initialization code to the PIC.s
*/
void initialize(uint16_t irqBase, uint16_t icw3, uint16_t icw4); void initialize(uint16_t irqBase, uint16_t icw3, uint16_t icw4);
/**
* Disables all interrupts where the corresponding bit in mask is set.
*/
void maskInterrupts(uint8_t mask); void maskInterrupts(uint8_t mask);
/**
* Sends an end-of-interrupt to the PIC.
*/
void sendEndOfInterrupt();
}; };
extern PIC masterPIC, slavePIC; extern PIC masterPIC, slavePIC;

View file

@ -56,23 +56,55 @@ void IDT::dispatch(CpuState *cpu)
{ {
using namespace console_tools; using namespace console_tools;
Console::main << "Ermahgerd, Interrupts!\n"; if(cpu->interrupt <= 0x1F) {
// Exception Handling
Console::main Console::main << FColor(Color::Red) << "Ermahgerd, Exceptions!\n";
<< "eax = " << hex(cpu->eax) << "\n" Console::main
<< "ebx = " << hex(cpu->ebx) << "\n" << "eax = " << hex(cpu->eax) << "\n"
<< "ecx = " << hex(cpu->ecx) << "\n" << "ebx = " << hex(cpu->ebx) << "\n"
<< "edx = " << hex(cpu->edx) << "\n" << "ecx = " << hex(cpu->ecx) << "\n"
<< "esi = " << hex(cpu->esi) << "\n" << "edx = " << hex(cpu->edx) << "\n"
<< "edi = " << hex(cpu->edi) << "\n" << "esi = " << hex(cpu->esi) << "\n"
<< "ebp = " << hex(cpu->ebp) << "\n" << "edi = " << hex(cpu->edi) << "\n"
<< "intr = " << cpu->intr << "\n" << "ebp = " << hex(cpu->ebp) << "\n"
<< "error = " << cpu->error << "\n" << "intr = " << cpu->interrupt << "\n"
<< "eip = " << hex(cpu->eip) << "\n" << "error = " << cpu->error << "\n"
<< "cs = " << hex(cpu->cs) << "\n" << "eip = " << hex(cpu->eip) << "\n"
<< "eflags = " << bin(cpu->eflags) << "\n" << "cs = " << hex(cpu->cs) << "\n"
<< "esp = " << hex(cpu->esp) << "\n" << "eflags = " << bin(cpu->eflags) << "\n"
<< "ss = " << hex(cpu->ss) << "\n"; << "esp = " << hex(cpu->esp) << "\n"
<< "ss = " << hex(cpu->ss) << "\n";
while(true);
} else if (cpu->interrupt >= 0x20 && cpu->interrupt <= 0x2F) {
while(true); // IRQ
Console::main << "[IRQ " << (cpu->interrupt - 0x20) << "]";
if(cpu->interrupt >= 0x28) {
slavePIC.sendEndOfInterrupt();
}
masterPIC.sendEndOfInterrupt();
} else {
// Other Interrupt
Console::main << "Ermahgerd, Interrupts!\n";
Console::main
<< "eax = " << hex(cpu->eax) << "\n"
<< "ebx = " << hex(cpu->ebx) << "\n"
<< "ecx = " << hex(cpu->ecx) << "\n"
<< "edx = " << hex(cpu->edx) << "\n"
<< "esi = " << hex(cpu->esi) << "\n"
<< "edi = " << hex(cpu->edi) << "\n"
<< "ebp = " << hex(cpu->ebp) << "\n"
<< "intr = " << cpu->interrupt << "\n"
<< "error = " << cpu->error << "\n"
<< "eip = " << hex(cpu->eip) << "\n"
<< "cs = " << hex(cpu->cs) << "\n"
<< "eflags = " << bin(cpu->eflags) << "\n"
<< "esp = " << hex(cpu->esp) << "\n"
<< "ss = " << hex(cpu->ss) << "\n";
while(true);
}
} }

View file

@ -21,4 +21,9 @@ void PIC::initialize(uint16_t irqBase, uint16_t icw3, uint16_t icw4)
void PIC::maskInterrupts(uint8_t mask) void PIC::maskInterrupts(uint8_t mask)
{ {
outb(this->port + 0x01, mask); outb(this->port + 0x01, mask);
}
void PIC::sendEndOfInterrupt()
{
outb(this->port + 0x00, 0x20);
} }