Skip to content

Commit

Permalink
+ | syscall triggers GPF
Browse files Browse the repository at this point in the history
  • Loading branch information
BolvicBolvicovic committed Sep 8, 2024
1 parent 685d747 commit d8b6105
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ VGA_OBJ = vga/vga.o
PIT_SRC = pit/pit.c
PIT_OBJ = pit/pit.o

SYS_SRC = syscall/syscall.c
SYS_OBJ = syscall/syscall.o

DES_SRC = descriptor/idt.c descriptor/irq.c descriptor/isr.c descriptor/interrupt_handlers.s descriptor/gdt.c
DES_OBJ = descriptor/idt.o descriptor/irq.o descriptor/isr.o descriptor/interrupt_handlers.o descriptor/gdt.o

Expand All @@ -21,12 +24,15 @@ FLAGS = -ffreestanding \

all: $(DRIVERS)

$(DRIVERS): $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ)
$(AR) $@ $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ)
$(DRIVERS): $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) $(SYS_OBJ)
$(AR) $@ $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) $(SYS_OBJ)

$(VGA_OBJ): $(VGA_SRC)
$(CC) $(FLAGS) -c $^ -o $@

$(SYS_OBJ): $(SYS_SRC)
$(CC) $(FLAGS) -c $^ -o $@

$(PIT_OBJ): $(PIT_SRC)
$(CC) $(FLAGS) -c $^ -o $@

Expand All @@ -41,6 +47,7 @@ keyboard/%.o: keyboard/%.c

clean:
rm -rf $(VGA_OBJ)
rm -rf $(SYS_OBJ)
rm -rf $(DES_OBJ)
rm -rf $(KEY_OBJ)
rm -rf $(PIT_OBJ)
Expand Down
38 changes: 38 additions & 0 deletions drivers/syscall/syscall.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "syscall.h"

void sys_read(registers_t* r) {
printf("Syscall read : eax == %d\n", r->eax);
}

void sys_write(registers_t* r) {
printf("Syscall write: eax == %d\n", r->eax);
}

void sys_open(registers_t* r) {
printf("Syscall open : eax == %d\n", r->eax);
}

void sys_close(registers_t* r) {
printf("Syscall close: eax == %d\n", r->eax);
}

void sys_stat(registers_t* r) {
printf("Syscall stat : eax == %d\n", r->eax);
}

isr_t syscall_tab[] = {
sys_read,
sys_write,
sys_open,
sys_close,
sys_stat
// Write all handlers here based on Linux system call table
};

void syscall_callback(registers_t* r) {
syscall_tab[r->eax](r);
}

void init_syscall() {
register_interrupt_handler(SYSCALL_INTERRUPT_NUMBER, &syscall_callback);
}
9 changes: 9 additions & 0 deletions drivers/syscall/syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SYSCALL_H
# define SYSCALL_H

#include "../descriptor/descriptor.h"

# define SYSCALL_INTERRUPT_NUMBER 0x80
void init_syscall();

#endif
5 changes: 5 additions & 0 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void kernel_main(uint32_t magic, uint32_t addr) {
isr_install();
init_keyboard();
init_timer(50);
init_syscall();
asm volatile(
"mov $1, %eax\n"
"int $80"
);
pmm_init(mem_size, bitmap);

for (size_t i = 0; i < 15; i++) {
Expand Down
1 change: 1 addition & 0 deletions kernel/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../drivers/descriptor/descriptor.h"
#include "../drivers/keyboard/keyboard.h"
#include "../drivers/pit/pit.h"
#include "../drivers/syscall/syscall.h"
#include "../multiboot/multiboot.h"
#include "../memory/pmm/pmm.h"
#include "../memory/vmm/vmm.h"
Expand Down

0 comments on commit d8b6105

Please sign in to comment.