diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/init/main.c | 6 | ||||
-rw-r--r-- | src/init/syscall.s | 4 | ||||
-rw-r--r-- | src/kernel/arch/generic.h | 2 | ||||
-rw-r--r-- | src/kernel/arch/i386/sysenter.s | 9 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 11 |
5 files changed, 27 insertions, 5 deletions
diff --git a/src/init/main.c b/src/init/main.c index cb3fa1d..6c4ccc3 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -1,15 +1,15 @@ #include <stdint.h> -void _syscall(); +int _syscall(int, int, int, int); int main() { - _syscall(); + uint8_t color = _syscall(1, 2, 3, 4); // change the colors of VGA text // doesn't require a lot of code, but still shows that it's working uint8_t *vga = (void*) 0xB8000; for (int i = 0; i < 80 * 25; i++) - vga[(i << 1) + 1] = 0x4e; + vga[(i << 1) + 1] = color; // try to mess with kernel memory uint8_t *kernel = (void*) 0x100000; diff --git a/src/init/syscall.s b/src/init/syscall.s index ebd9d0e..86d3523 100644 --- a/src/init/syscall.s +++ b/src/init/syscall.s @@ -2,8 +2,12 @@ .global _syscall .type _syscall, @function _syscall: + mov 4(%esp), %eax + mov 8(%esp), %ebx mov %esp, %ecx mov $_syscall_ret, %edx + mov 12(%esp), %esi + mov 16(%esp), %edi sysenter _syscall_ret: ret diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h index 08f26a7..0b005a2 100644 --- a/src/kernel/arch/generic.h +++ b/src/kernel/arch/generic.h @@ -17,7 +17,7 @@ void halt_cpu(); // src/arch/i386/sysenter.s void sysexit(void (*fun)(), void *stack_top); void sysenter_setup(); -void syscall_handler(); +int syscall_handler(int, int, int, int); // all of those can allocate memory struct pagedir *pagedir_new(); diff --git a/src/kernel/arch/i386/sysenter.s b/src/kernel/arch/i386/sysenter.s index 3fcd4c3..7375e06 100644 --- a/src/kernel/arch/i386/sysenter.s +++ b/src/kernel/arch/i386/sysenter.s @@ -49,6 +49,10 @@ sysenter_setup: sysenter_handler: pushal + push %edi + push %esi + push %ebx + push %eax mov %cr0, %eax and $0x7FFFFFFF, %eax // disable paging @@ -56,9 +60,14 @@ sysenter_handler: call syscall_handler + // save the return value + mov %eax, 44(%esp) // 16 [top of eflags] + 7*4 [skip until EAX] + mov %edx, 32(%esp) // 16 + 4*4 [skip until EBX] + mov %cr0, %eax or $0x80000000, %eax // enable paging mov %eax, %cr0 + add $16, %esp popal sysexit diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 25b8eb5..a42dc44 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -1,6 +1,15 @@ #include <kernel/arch/generic.h> #include <kernel/panic.h> -void syscall_handler() { +int syscall_handler(int a, int b, int c, int d) { + // verify that the parameters get passed correctly + if (a != 1) panic(); + if (b != 2) panic(); + if (c != 3) panic(); + if (d != 4) panic(); + log_const("in a syscall!"); + + // used to check if the return value gets passed correctly + return 0x4e; } |