From 8ff5b556946c9a03c2447de420c5477f5d79904e Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Wed, 15 Jul 2020 06:50:03 -0500 Subject: [PATCH] Moved interrupt handling to subdir --- .gitignore | 8 +++--- Makefile | 27 +++++-------------- src/Makefile | 18 +++++++++++++ src/entry.S | 2 +- src/interrupts/Makefile | 9 +++++++ src/interrupts/interrupts.hpp | 19 +++++++++++++ src/interrupts/x86/idt.S | 21 +++++++++++++++ src/interrupts/x86/idt.hpp | 10 +++++++ .../x86}/interruptdescriptor.cpp | 0 .../x86}/interruptdescriptor.hpp | 0 src/interrupts/x86/interrupts.cpp | 19 +++++++++++++ src/{ => interrupts/x86}/inthandlers.cpp | 1 - src/{ => interrupts/x86}/inthandlers.hpp | 0 src/quarkkernel.cpp | 10 ------- 14 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 src/Makefile create mode 100644 src/interrupts/Makefile create mode 100644 src/interrupts/interrupts.hpp create mode 100644 src/interrupts/x86/idt.S create mode 100644 src/interrupts/x86/idt.hpp rename src/{ => interrupts/x86}/interruptdescriptor.cpp (100%) rename src/{ => interrupts/x86}/interruptdescriptor.hpp (100%) create mode 100644 src/interrupts/x86/interrupts.cpp rename src/{ => interrupts/x86}/inthandlers.cpp (99%) rename src/{ => interrupts/x86}/inthandlers.hpp (100%) diff --git a/.gitignore b/.gitignore index 63e9dc8..e6d5185 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -bin/* -src/*.o quark.iso -src/*~ +src/quark-kernel +src/interrupts/libinterrupts.a +*.o *~ -rootfs +rootfs/ test/ \ No newline at end of file diff --git a/Makefile b/Makefile index ce2cb91..d7cdb0d 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,14 @@ -objs = src/addressspace.o src/tty.o src/buddyallocator.o src/math.o \ - src/cstring.o src/pagetableentry.o src/multiboot2header.o \ - src/systeminfo.o src/memorymap.o src/interruptdescriptor.o \ - src/inthandlers.o src/pio.o src/entry.o src/quarkkernel.o -link_script = src/linker.ld -quark_bin = qkernel -quark_img = quark.iso - -CXX = i686-elf-g++ -CC = i686-elf-gcc - -CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb - .PHONY: all -all: $(quark_img) +all: quark.iso -$(quark_img): bin/$(quark_bin) rootfs/boot/grub/grub.cfg - cp bin/$(quark_bin) rootfs/apps +quark.iso: src/quark-kernel + cp src/quark-kernel rootfs/apps grub-mkrescue -o $@ rootfs -bin/$(quark_bin): $(objs) $(link_script) - mkdir -p bin/ - $(CXX) -o $@ -T $(link_script) -ffreestanding -nostdlib -O0 $(objs) -lgcc +src/quark-kernel: + make -C src .PHONY: clean clean: - rm -f $(objs) bin/$(quark_bin) $(quark_img) + make -C src clean + rm -f quark.iso diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..e10855e --- /dev/null +++ b/src/Makefile @@ -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 \ No newline at end of file diff --git a/src/entry.S b/src/entry.S index 0c9b030..2778259 100755 --- a/src/entry.S +++ b/src/entry.S @@ -1,5 +1,5 @@ .section .multiboot -.include "src/multiboot2header.S" +.include "multiboot2header.S" .section .rodata diff --git a/src/interrupts/Makefile b/src/interrupts/Makefile new file mode 100644 index 0000000..c818c6f --- /dev/null +++ b/src/interrupts/Makefile @@ -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) \ No newline at end of file diff --git a/src/interrupts/interrupts.hpp b/src/interrupts/interrupts.hpp new file mode 100644 index 0000000..173a002 --- /dev/null +++ b/src/interrupts/interrupts.hpp @@ -0,0 +1,19 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +namespace kernel +{ + class Interrupts + { + public: + + Interrupts(); + + void enable(); + + void disable(); + + }; +} + +#endif \ No newline at end of file diff --git a/src/interrupts/x86/idt.S b/src/interrupts/x86/idt.S new file mode 100644 index 0000000..a76f770 --- /dev/null +++ b/src/interrupts/x86/idt.S @@ -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 \ No newline at end of file diff --git a/src/interrupts/x86/idt.hpp b/src/interrupts/x86/idt.hpp new file mode 100644 index 0000000..2c1cf0f --- /dev/null +++ b/src/interrupts/x86/idt.hpp @@ -0,0 +1,10 @@ +#ifndef IDT_H +#define IDT_H + +#include "interruptdescriptor.hpp" + +extern kernel::InterruptDescriptor idt[256]; + +extern "C" void _lidt(); + +#endif \ No newline at end of file diff --git a/src/interruptdescriptor.cpp b/src/interrupts/x86/interruptdescriptor.cpp similarity index 100% rename from src/interruptdescriptor.cpp rename to src/interrupts/x86/interruptdescriptor.cpp diff --git a/src/interruptdescriptor.hpp b/src/interrupts/x86/interruptdescriptor.hpp similarity index 100% rename from src/interruptdescriptor.hpp rename to src/interrupts/x86/interruptdescriptor.hpp diff --git a/src/interrupts/x86/interrupts.cpp b/src/interrupts/x86/interrupts.cpp new file mode 100644 index 0000000..971e6a8 --- /dev/null +++ b/src/interrupts/x86/interrupts.cpp @@ -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"); +} \ No newline at end of file diff --git a/src/inthandlers.cpp b/src/interrupts/x86/inthandlers.cpp similarity index 99% rename from src/inthandlers.cpp rename to src/interrupts/x86/inthandlers.cpp index bf780e8..59ce3ad 100644 --- a/src/inthandlers.cpp +++ b/src/interrupts/x86/inthandlers.cpp @@ -9,7 +9,6 @@ void divisionByZero(void* frame) display += 2; } - __attribute__ ((interrupt)) void gpFaultHandler(void* frame, unsigned int error) { diff --git a/src/inthandlers.hpp b/src/interrupts/x86/inthandlers.hpp similarity index 100% rename from src/inthandlers.hpp rename to src/interrupts/x86/inthandlers.hpp diff --git a/src/quarkkernel.cpp b/src/quarkkernel.cpp index 544c33a..d607169 100755 --- a/src/quarkkernel.cpp +++ b/src/quarkkernel.cpp @@ -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"; }