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: 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 bnr: kernel-base.ker run

View file

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

View file

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

View file

@ -8,6 +8,7 @@
#include "gdt.hpp" #include "gdt.hpp"
#include "idt.hpp" #include "idt.hpp"
#include "compat.h" #include "compat.h"
#include "io.hpp"
using namespace multiboot; using namespace multiboot;
using namespace console_tools; using namespace console_tools;
@ -83,8 +84,11 @@ extern "C" void init(Structure const & data)
IDT::initialize(); IDT::initialize();
asm volatile("int $0x00"); Console::main << "Interrupts set up.\n";
// asm volatile("cli");
asm volatile("sti");
Console::main << "Interrupts enabled.\n";
/* /*
for(int i = 0; i < 10; i++) { 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."); static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");

View file

@ -1,4 +1,5 @@
#include "idt.hpp" #include "idt.hpp"
#include "io.hpp"
#include "console.hpp" #include "console.hpp"
#define ISR(num) extern "C" void isr_##num(); #define ISR(num) extern "C" void isr_##num();
@ -37,6 +38,26 @@ void IDT::initialize()
.pointer = IDT::descriptors, .pointer = IDT::descriptors,
}; };
asm volatile("lidt %0" : : "m" (idtp)); 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) void IDT::dispatch(CpuState *cpu)