Adds PIC initialization and hardware interrupts.

This commit is contained in:
Felix Queißner 2016-05-05 19:02:23 +02:00
parent 79b7238d84
commit b31d9164d6
5 changed files with 34 additions and 8 deletions

View file

@ -47,7 +47,7 @@ kernel-base.ker: $(OBJS)
run:
qemu-system-i386 -kernel kernel-base.ker -m 64
qemu-system-i386 -kernel kernel-base.ker -m 64 -d int
bnr: kernel-base.ker run

View file

@ -65,6 +65,7 @@ private:
IDT() = delete;
static void dispatch(CpuState *cpu);
static void setupPIC();
public:
static InterruptDescriptor & descriptor(uint32_t idx);

View file

@ -2,12 +2,12 @@
static inline void outb(uint16_t port, uint8_t data)
{
__asm__ volatile ("outb %0, %1" : : "a" (data), "Nd" (port));
asm volatile ("outb %0, %1" : : "a" (data), "Nd" (port));
}
static inline uint8_t inb(uint16_t port)
{
uint8_t data;
__asm__ volatile ("inb %1, %0" : "=a" (data) : "d" (port));
asm volatile ("inb %1, %0" : "=a" (data) : "d" (port));
return data;
}

View file

@ -8,6 +8,7 @@
#include "gdt.hpp"
#include "idt.hpp"
#include "compat.h"
#include "io.hpp"
using namespace multiboot;
using namespace console_tools;
@ -80,11 +81,14 @@ extern "C" void init(Structure const & data)
<< (freeMemory >> 10) << "KB, "
<< (freeMemory >> 0) << "B, "
<< (freeMemory >> 12) << "Pages\n";
IDT::initialize();
asm volatile("int $0x00");
// asm volatile("cli");
Console::main << "Interrupts set up.\n";
asm volatile("sti");
Console::main << "Interrupts enabled.\n";
/*
for(int i = 0; i < 10; i++) {
@ -94,7 +98,7 @@ extern "C" void init(Structure const & data)
}
*/
while(true);
}
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");

View file

@ -1,4 +1,5 @@
#include "idt.hpp"
#include "io.hpp"
#include "console.hpp"
#define ISR(num) extern "C" void isr_##num();
@ -28,7 +29,7 @@ void IDT::initialize()
#include "../interrupt-list.inc"
#undef ISR
#undef ISR_ERR
struct {
uint16_t limit;
void* pointer;
@ -37,6 +38,26 @@ void IDT::initialize()
.pointer = IDT::descriptors,
};
asm volatile("lidt %0" : : "m" (idtp));
IDT::setupPIC();
}
void IDT::setupPIC()
{
outb(0x20, 0x11);
outb(0x21, 0x20);
outb(0x21, 0x04);
outb(0x21, 0x01);
// Slave-PIC
outb(0xa0, 0x11);
outb(0xa1, 0x28);
outb(0xa1, 0x02);
outb(0xa1, 0x01);
// Demask all interrupts
outb(0x20, 0x0);
outb(0xa0, 0x0);
}
void IDT::dispatch(CpuState *cpu)