1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Add module "syscall"

This commit is contained in:
Braiden Vasco 2017-11-05 09:50:04 +00:00
parent 34326cce45
commit bb7f68d633
6 changed files with 59 additions and 3 deletions

View file

@ -19,6 +19,7 @@ OBJS += kprintf.c.o
OBJS += protected.c.o protected.asm.cpp.o
OBJS += exception.c.o exception.asm.cpp.o
OBJS += hwint.c.o hwint.asm.cpp.o
OBJS += syscall.c.o syscall.asm.cpp.o
OBJS += timer.c.o

View file

@ -38,4 +38,6 @@
#define INT_HWINT_FIRST (INT_EXCEPTION_LAST + 1)
#define INT_HWINT_LAST (INT_HWINT_FIRST + INT_HWINT_COUNT - 1)
#define INT_SYSCALL 0x80
#endif

View file

@ -5,6 +5,7 @@
#include "asm.h"
#include "exception.h"
#include "hwint.h"
#include "syscall.h"
#include <kernelmq/stdlib.h>
@ -129,6 +130,8 @@ void protected_initialize()
idt_set_gate(46, (unsigned int)hwint_14, 0x08, 0x8E);
idt_set_gate(47, (unsigned int)hwint_15, 0x08, 0x8E);
idt_set_gate(INT_SYSCALL, (unsigned int)syscall_gate, 0x08, 0x8E | 0x60);
logger_info("Load GDT.");
gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1;
@ -168,7 +171,5 @@ void idt_set_gate(unsigned char num, unsigned int base, unsigned short sel, unsi
idt_entries[num].base_hi = (base >> 16) & 0xFFFF;
idt_entries[num].sel = sel;
idt_entries[num].always0 = 0;
// We must uncomment the OR below when we get to using user-mode.
// It sets the interrupt gate's privilege level to 3.
idt_entries[num].flags = flags /* | 0x60 */;
idt_entries[num].flags = flags;
}

32
arch/syscall.asm Normal file
View file

@ -0,0 +1,32 @@
#include "config.h"
[EXTERN syscall_handler]
[GLOBAL syscall_gate]
syscall_gate:
cli
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, GDT_KERNEL_DS_SELECTOR
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call syscall_handler
pop eax ; reload the original data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa ; Pops edi,esi,ebp...
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP

14
arch/syscall.c Normal file
View file

@ -0,0 +1,14 @@
#include "kprintf.h"
struct IsrRegisters {
unsigned int ds; // Data segment selector
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
unsigned int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
};
void syscall_handler(struct IsrRegisters regs)
{
const unsigned int id = regs.eax;
kprintf("syscall %u\n", id);
}

6
arch/syscall.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef KERNELMQ_INCLUDED_SYSCALL
#define KERNELMQ_INCLUDED_SYSCALL 1
void syscall_gate();
#endif