Fixed x86 lidt function, added addSyscall() method

This commit is contained in:
2020-08-02 15:07:23 -05:00
parent f220514e72
commit b924e632cf
2 changed files with 20 additions and 1 deletions

View File

@@ -7,12 +7,20 @@ namespace kernel
{ {
public: public:
static const unsigned int MAX_SYSCALL_ID = 31;
Interrupts(); Interrupts();
void enable(); void enable();
void disable(); void disable();
void addSyscall(unsigned int id, void* function);
private:
void* syscalls[MAX_SYSCALL_ID + 1];
}; };
} }

View File

@@ -1,6 +1,7 @@
#include "../interrupts.hpp" #include "../interrupts.hpp"
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
class InterruptDescriptor class InterruptDescriptor
{ {
@@ -59,7 +60,9 @@ void lidt()
IDTInfo idtInfo; IDTInfo idtInfo;
idtInfo.size = sizeof(idt) - 1; idtInfo.size = sizeof(idt) - 1;
idtInfo.location = (void*) &idt; idtInfo.location = (void*) &idt;
asm("lidt idt"); asm("lidt (%0)"
:
: "r" (&idtInfo));
} }
__attribute__ ((interrupt)) __attribute__ ((interrupt))
@@ -156,6 +159,8 @@ void* InterruptDescriptor::operator=(void* rhs)
kernel::Interrupts::Interrupts() 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[0] = InterruptDescriptor((void*) &divisionByZero, InterruptDescriptor::INT32, 0);
idt[8] = InterruptDescriptor((void*) &doubleFaultHandler, InterruptDescriptor::INT32, 0); idt[8] = InterruptDescriptor((void*) &doubleFaultHandler, InterruptDescriptor::INT32, 0);
idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0); idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0);
@@ -173,3 +178,9 @@ void kernel::Interrupts::disable()
{ {
asm("cli"); asm("cli");
} }
void kernel::Interrupts::addSyscall(unsigned int id, void* function)
{
if(id <= MAX_SYSCALL_ID)
syscalls[id] = function;
}