diff options
-rw-r--r-- | arch/i386/boot/boot.s | 4 | ||||
-rw-r--r-- | arch/i386/boot/idt.c | 6 | ||||
-rw-r--r-- | arch/i386/boot/pic.c | 2 | ||||
-rw-r--r-- | arch/i386/boot/syscall.c | 21 | ||||
-rw-r--r-- | arch/i386/boot/syscall.h | 9 | ||||
-rw-r--r-- | arch/i386/include/kernel/isr.h | 19 | ||||
-rw-r--r-- | arch/i386/make.config | 3 |
7 files changed, 61 insertions, 3 deletions
diff --git a/arch/i386/boot/boot.s b/arch/i386/boot/boot.s index 4b32ca2..91df039 100644 --- a/arch/i386/boot/boot.s +++ b/arch/i386/boot/boot.s @@ -71,6 +71,10 @@ _start: call idt_install call pic_remap + pushl $1 + pushl print_hello + call register_syscall + call kernel_main call jump_userspace diff --git a/arch/i386/boot/idt.c b/arch/i386/boot/idt.c index dbcfaa2..0789a17 100644 --- a/arch/i386/boot/idt.c +++ b/arch/i386/boot/idt.c @@ -1,4 +1,4 @@ -#include <kernel/idt.h> +#include "syscall.h" #include <kernel/isr.h> #include <kernel/io.h> #include <kernel/pic.h> @@ -157,6 +157,10 @@ void idt_install(void) { idt_set_gate(30, isr_stub_30, 0x08, IDT_EXCEPTION); idt_set_gate(31, isr_stub_31, 0x08, IDT_EXCEPTION); + idt_set_gate(128, syscall_stub, 0x08, IDT_INTERRUPT); + + register_syscall(halt_catch_fire, 0); + __asm__ volatile("lidt %0" : : "memory"(idtr)); __asm__ volatile("sti"); } diff --git a/arch/i386/boot/pic.c b/arch/i386/boot/pic.c index 607023c..69a0785 100644 --- a/arch/i386/boot/pic.c +++ b/arch/i386/boot/pic.c @@ -51,7 +51,7 @@ void irq_set_mask(uint8_t irq) { outb(port, data); } -void irq_clear_mask(unsigned char irq) { +void irq_clear_mask(uint8_t irq) { uint16_t port; uint8_t data; diff --git a/arch/i386/boot/syscall.c b/arch/i386/boot/syscall.c new file mode 100644 index 0000000..fb613b3 --- /dev/null +++ b/arch/i386/boot/syscall.c @@ -0,0 +1,21 @@ +#include "syscall.h" +#include <kernel/io.h> +#include <stddef.h> + +void *(*syscall_handlers[30])(struct isr_frame *frame); + +void syscall_dispatch(struct isr_frame *frame) { + if (syscall_handlers[frame->eax] != NULL) + syscall_handlers[frame->eax](frame); + else + kprintf("Error: Invalid system call number: %d\n", frame->eax); + __asm__ volatile("cli;hlt"); +} + +void register_syscall(void *handler(struct isr_frame*), int num) { + syscall_handlers[num] = handler; +} + +void print_hello(struct isr_frame *frame) { + kprintf("Hello syscall\n"); +} diff --git a/arch/i386/boot/syscall.h b/arch/i386/boot/syscall.h new file mode 100644 index 0000000..376fb7c --- /dev/null +++ b/arch/i386/boot/syscall.h @@ -0,0 +1,9 @@ +#ifndef I386_SYSCALL_H +#define I386_SYSCALL_H + +#include <kernel/isr.h> + +void syscall_dispatch(struct isr_frame *frame); +void register_syscall(void *handler(struct isr_frame*), int num); + +#endif diff --git a/arch/i386/include/kernel/isr.h b/arch/i386/include/kernel/isr.h index 9d88958..f177ee2 100644 --- a/arch/i386/include/kernel/isr.h +++ b/arch/i386/include/kernel/isr.h @@ -58,4 +58,23 @@ extern void isr_stub_29(void); extern void isr_stub_30(void); extern void isr_stub_31(void); +extern void irq_stub_0(void); +extern void irq_stub_1(void); +extern void irq_stub_2(void); +extern void irq_stub_3(void); +extern void irq_stub_4(void); +extern void irq_stub_5(void); +extern void irq_stub_6(void); +extern void irq_stub_7(void); +extern void irq_stub_8(void); +extern void irq_stub_9(void); +extern void irq_stub_10(void); +extern void irq_stub_11(void); +extern void irq_stub_12(void); +extern void irq_stub_13(void); +extern void irq_stub_14(void); +extern void irq_stub_15(void); + +extern void syscall_stub(void); + #endif diff --git a/arch/i386/make.config b/arch/i386/make.config index df26a3d..82e8faf 100644 --- a/arch/i386/make.config +++ b/arch/i386/make.config @@ -7,6 +7,7 @@ KERNEL_ARCH_OBJS=$(ARCHDIR)/boot/boot.o \ $(ARCHDIR)/boot/isr.o \ $(ARCHDIR)/boot/tty.o \ $(ARCHDIR)/boot/pic.o \ - $(ARCHDIR)/boot/gdt.o \ $(ARCHDIR)/boot/idt.o \ + $(ARCHDIR)/boot/syscall.o \ + $(ARCHDIR)/boot/gdt.o \ $(ARCHDIR)/kernel/serial.o \ |