From b924e632cf80bb23fcaccf36c6371bb997ef1fb2 Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Sun, 2 Aug 2020 15:07:23 -0500 Subject: [PATCH] Fixed x86 lidt function, added addSyscall() method --- src/interrupts.hpp | 8 ++++++++ src/x86/interrupts.cpp | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/interrupts.hpp b/src/interrupts.hpp index 173a002..d51d864 100644 --- a/src/interrupts.hpp +++ b/src/interrupts.hpp @@ -7,12 +7,20 @@ namespace kernel { public: + static const unsigned int MAX_SYSCALL_ID = 31; + Interrupts(); void enable(); void disable(); + void addSyscall(unsigned int id, void* function); + + private: + + void* syscalls[MAX_SYSCALL_ID + 1]; + }; } diff --git a/src/x86/interrupts.cpp b/src/x86/interrupts.cpp index 2b22417..c825113 100644 --- a/src/x86/interrupts.cpp +++ b/src/x86/interrupts.cpp @@ -1,6 +1,7 @@ #include "../interrupts.hpp" #include +#include class InterruptDescriptor { @@ -59,7 +60,9 @@ void lidt() IDTInfo idtInfo; idtInfo.size = sizeof(idt) - 1; idtInfo.location = (void*) &idt; - asm("lidt idt"); + asm("lidt (%0)" + : + : "r" (&idtInfo)); } __attribute__ ((interrupt)) @@ -156,6 +159,8 @@ void* InterruptDescriptor::operator=(void* rhs) kernel::Interrupts::Interrupts() { + for(unsigned int i = 0; i <= MAX_SYSCALL_ID; i++) + syscalls[i] = (void*) NULL; idt[0] = InterruptDescriptor((void*) &divisionByZero, InterruptDescriptor::INT32, 0); idt[8] = InterruptDescriptor((void*) &doubleFaultHandler, InterruptDescriptor::INT32, 0); idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0); @@ -172,4 +177,10 @@ void kernel::Interrupts::enable() void kernel::Interrupts::disable() { asm("cli"); +} + +void kernel::Interrupts::addSyscall(unsigned int id, void* function) +{ + if(id <= MAX_SYSCALL_ID) + syscalls[id] = function; } \ No newline at end of file