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

18
src/Makefile Normal file
View File

@@ -0,0 +1,18 @@
objs = addressspace.o tty.o buddyallocator.o math.o cstring.o pagetableentry.o multiboot2header.o systeminfo.o memorymap.o pio.o entry.o quarkkernel.o
CXX = i686-elf-g++
CC = i686-elf-gcc
CXXFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb
LDFLAGS = -T linker.ld -lgcc -nostdlib
quark-kernel: $(objs) linker.ld interrupts/libinterrupts.a
$(CXX) -o $@ $(LDFLAGS) interrupts/libinterrupts.a $(objs)
interrupts/libinterrupts.a:
make -C interrupts CXX="$(CXX)" CC="$(CC)" CXXFLAGS="$(CXXFLAGS)"
.PHONY: clean
clean:
make -C interrupts clean
rm -f $(objs) quark-kernel

View File

@@ -1,5 +1,5 @@
.section .multiboot
.include "src/multiboot2header.S"
.include "multiboot2header.S"
.section .rodata

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,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

@@ -9,7 +9,6 @@ void divisionByZero(void* frame)
display += 2;
}
__attribute__ ((interrupt))
void gpFaultHandler(void* frame, unsigned int error)
{

View File

@@ -6,8 +6,6 @@
#include "memorymap.hpp"
#include "buddyallocator.hpp"
#include "addressspace.hpp"
#include "interruptdescriptor.hpp"
#include "inthandlers.hpp"
#include "pio.hpp"
#include "tty.h"
@@ -15,7 +13,6 @@ using namespace kernel;
extern SystemInfo system_info;
extern MemoryMap::Region memory_map;
extern InterruptDescriptor idt;
extern "C" void __cxa_pure_virtual()
{
@@ -39,14 +36,7 @@ void main(char* cmdline)
BuddyAllocator alloc(memmap, (char*) 0xC0000000, system_info.getHighMemory() / 4 + 256, 6);
AddressSpace vmem(alloc);
vmem.mmap((void*) 0x80000000, 0x10000);
InterruptDescriptor* interruptTable = &idt;
interruptTable[0] = InterruptDescriptor((void*) &divisionByZero, InterruptDescriptor::INT32, 0);
interruptTable[8] = InterruptDescriptor((void*) &doubleFaultHandler, InterruptDescriptor::INT32, 0);
interruptTable[14] = InterruptDescriptor((void*) &pageFaultHandler, InterruptDescriptor::INT32, 0);
//for(int i = 1; i < 32; i++)
// interruptTable[i] = InterruptDescriptor((void*) &pageFaultHandler, InterruptDescriptor::INT32, 0);
outb(0xa1, 0xff);
outb(0x21, 0xff);
asm("sti");
tty << "Nothing left to do. Hanging.\n";
}