err: invalid syscall no

This commit is contained in:
xamidev
2024-09-16 16:43:59 +02:00
parent af716cb2ec
commit d02b3d62cb
7 changed files with 74 additions and 31 deletions

View File

@@ -25,6 +25,8 @@ extern void irq13();
extern void irq14();
extern void irq15();
extern void syscall_common_stub();
void *irq_routines[16] =
{
0, 0, 0, 0, 0, 0, 0, 0,
@@ -76,6 +78,8 @@ void irq_install()
idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E);
idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E);
printf("[kernel] installed irq 0-15\n");
idt_set_gate(0x80, (unsigned long)syscall_common_stub, 0x08, 0x8E);
}
void irq_handler(struct regs *r)

View File

@@ -210,6 +210,37 @@ irq_common_stub:
add esp, 8
iret
; we'll be placing the syscall_common_stub here.
; push everything, then call syscall_handler (be sure to define it extern)
; then pop back everything and iret
extern syscall_handler
global syscall_common_stub
syscall_common_stub:
pusha
push ds
push es
push fs
push gs
mov eax, ds
push eax ; save ds
mov ax, 0x10 ; kernel segment
mov ds, ax
mov es, ax
call syscall_handler
pop eax
mov ds, eax ; restore ds
pop gs
pop fs
pop es
pop ds
popa
iret
section .bss
align 4

View File

@@ -1,20 +0,0 @@
#include <stdarg.h>
#include "../libc/stdio.h"
#include "syscall.h"
syscall_t syscalls[] = {
(syscall_t)printf,
};
int syscall_handler(int syscall_num, ...)
{
if ((unsigned)syscall_num < sizeof(syscalls)/sizeof(syscall_t))
{
va_list args;
va_start(args, syscall_num);
syscalls[syscall_num](va_arg(args, const char*));
va_end(args);
return 0;
}
return -1;
}

View File

@@ -1,8 +0,0 @@
#ifndef SYSCALL_H
#define SYSCALL_H
#define SYSCALL_PRINTF 0
typedef void (*syscall_t)();
#endif

33
src/kernel/syscalls.c Normal file
View File

@@ -0,0 +1,33 @@
// System calls
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https://github.com/xamidev/blankos
#include "../libc/stdio.h"
void handle_syscall(int syscall_number, void* arg)
{
switch(syscall_number)
{
case 1:
puts("Here's the syscall 1\n");
break;
default:
printf("[error] Invalid syscall number '%d'!\n", syscall_number);
break;
}
}
void syscall_handler()
{
int syscall_number;
void* arg;
// mov eax, syscall_number
// mov ebx, arg
asm volatile("mov %%eax, %0" : "=r"(syscall_number));
asm volatile("mov %%ebx, %0" : "=r"(arg));
printf("[syscall] syscall_number=%d, arg=%p\n", syscall_number, arg);
handle_syscall(syscall_number, arg);
}

View File

@@ -39,5 +39,7 @@ extern volatile unsigned long global_ticks;
extern unsigned int g_multiboot_info_address;
void syscall_handler();
#endif