1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "arch/x86_64/hal/obj.h"
#include "arch/x86_64/hal/process.h"
#include "arch/x86_64/hal/smp.h"
#include "lib/printf.h"
#include "syscall.h"
syscall_handle_t s_arch_handles[128] = {
[JOVE_OBJ_SERIAL_COM-0x80] = _syscall_handle_serial
};
int
_syscall_handle_arch(syscall_context_t *ctx)
{
uint8_t target_type = obj_gettype(ctx->target.obj) - 0x80;
syscall_handle_t call_handle = s_arch_handles[target_type];
if(call_handle == NULL) {
kprintf("syscall: Process %i tried to call syscall on object %P which doesn't support syscalls!\n",
pcb_pid(obj_deref(ctx->pcb)), ctx->header->path, ctx->header->pathlen);
return -EBADOBJ;
}
return call_handle(ctx);
}
__attribute__((naked))
void _syscall_entry(void)
{
asm volatile(" \
swapgs; \
movq %%gs:%c[pcb], %%rax; \
movq %%rsp, %%rdx; \
movq %c[ksp](%%rax), %%rsp; \
pushq %%rdx; \
pushq %%r11; \
pushq %%rcx; \
pushq %%rbp; \
callq syscall_handler; \
swapgs; \
xorq %%r10, %%r10; \
xorq %%r9, %%r9; \
xorq %%r8, %%r8; \
xorq %%rsi, %%rsi; \
xorq %%rdi, %%rdi; \
xorq %%rdx, %%rdx; \
popq %%rbp; \
popq %%rcx; \
popq %%r11; \
popq %%rsp; \
sysretq"
::
[pcb] "i"(offsetof(processor_t, pcb)),
[ksp] "i"(offsetof(pcb_t, ksp)));
}
|