Moved interrupt handling to subdir

This commit is contained in:
2020-07-15 06:50:03 -05:00
parent cff8965940
commit 8ff5b55694
14 changed files with 108 additions and 36 deletions

9
src/interrupts/Makefile Normal file
View File

@@ -0,0 +1,9 @@
objs = x86/inthandlers.o x86/interruptdescriptor.o x86/idt.o x86/interrupts.o
archive = libinterrupts.a
$(archive): $(objs)
i686-elf-ar rcs $@ $^
.PHONY: clean
clean:
rm -f $(archive) $(objs)

View File

@@ -0,0 +1,19 @@
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
namespace kernel
{
class Interrupts
{
public:
Interrupts();
void enable();
void disable();
};
}
#endif

21
src/interrupts/x86/idt.S Normal file
View File

@@ -0,0 +1,21 @@
.section .bss
.align 8
.global idt
idt:
.skip 8 * 256
idt_end:
.section .rodata
.idt_info:
.short idt_end - idt - 1
.long idt
.section .text
.global _lidt
.type _lidt, @function
_lidt:
ret

View File

@@ -0,0 +1,10 @@
#ifndef IDT_H
#define IDT_H
#include "interruptdescriptor.hpp"
extern kernel::InterruptDescriptor idt[256];
extern "C" void _lidt();
#endif

View File

@@ -0,0 +1,62 @@
#include "interruptdescriptor.hpp"
kernel::InterruptDescriptor::InterruptDescriptor()
{
this->m_offset1 = 0;
this->m_selector = 0;
this->m_zero = 0;
this->m_type = 0;
this->m_storage = 0;
this->m_dpl = 0;
this->m_present = 0;
this->m_offset2 = 0;
}
kernel::InterruptDescriptor::InterruptDescriptor(void* handler, Type type, unsigned int dpl)
{
uint32_t offset = (uint32_t) handler;
this->m_offset1 = (uint16_t) offset;
this->m_selector = 8;
this->m_zero = 0;
this->m_type = (uint16_t) type;
this->m_storage = 0;
this->m_dpl = dpl;
this->m_present = 1;
this->m_offset2 = offset >> 16;
}
bool kernel::InterruptDescriptor::present()
{
return m_present == 1;
}
void kernel::InterruptDescriptor::present(bool present)
{
m_present = present ? 1 : 0;
}
kernel::InterruptDescriptor::Type kernel::InterruptDescriptor::type()
{
return (Type) m_type;
}
void kernel::InterruptDescriptor::type(kernel::InterruptDescriptor::Type type)
{
m_type = (unsigned int) type;
}
unsigned int kernel::InterruptDescriptor::dpl()
{
return m_dpl;
}
void kernel::InterruptDescriptor::dpl(unsigned int dpl)
{
m_dpl = dpl;
}
void* kernel::InterruptDescriptor::operator=(void* rhs)
{
uint32_t offset = (uint32_t) rhs;
m_offset1 = (uint16_t) offset;
m_offset2 = (offset >> 16);
}

View File

@@ -0,0 +1,55 @@
#ifndef INTERRUPTDESCRIPTOR_H
#define INTERRUPTDESCRIPTOR_H
#include <stdint.h>
namespace kernel
{
class InterruptDescriptor
{
public:
enum Type
{
TASK32 = 5,
TRAP32 = 15,
INT32 = 14,
TRAP16 = 7,
INT16 = 6
};
InterruptDescriptor();
InterruptDescriptor(void* handler, Type type, unsigned int dpl);
bool present();
void present(bool present);
Type type();
void type(Type type);
unsigned int dpl();
void dpl(unsigned int dpl);
void* operator=(void* rhs);
private:
uint16_t m_offset1;
uint16_t m_selector;
uint16_t m_zero : 8;
uint16_t m_type : 4;
uint16_t m_storage : 1;
uint16_t m_dpl : 2;
uint16_t m_present : 1;
uint16_t m_offset2;
};
}
#endif

View File

@@ -0,0 +1,19 @@
#include "../interrupts.hpp"
#include "idt.hpp"
kernel::Interrupts::Interrupts()
{
// Load interrupt handlers
// Configure PIC
_lidt();
}
inline void kernel::Interrupts::enable()
{
asm("sti");
}
inline void kernel::Interrupts::disable()
{
asm("cli");
}

View File

@@ -0,0 +1,32 @@
#include "inthandlers.hpp"
char* display = (char*) 0xC00B8000;
__attribute__ ((interrupt))
void divisionByZero(void* frame)
{
*display = 'z';
display += 2;
}
__attribute__ ((interrupt))
void gpFaultHandler(void* frame, unsigned int error)
{
*display = 'a';
asm("hlt");
}
__attribute__ ((interrupt))
void pageFaultHandler(void* frame, unsigned int error)
{
*display = '0';
//asm("hlt");
}
__attribute__ ((interrupt))
void doubleFaultHandler(void* frame, unsigned int error)
{
*display = '#';
//asm("hlt");
}

View File

@@ -0,0 +1,16 @@
#ifndef INTHANDLERS_H
#define INTHANDLERS_H
__attribute__ ((interrupt))
void divisionByZero(void* frame);
__attribute__ ((interrupt))
void gpFaultHandler(void* frame, unsigned int error);
__attribute__ ((interrupt))
void pageFaultHandler(void* frame, unsigned int error);
__attribute__ ((interrupt))
void doubleFaultHandler(void* frame, unsigned int error);
#endif