summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/sys/syscall.c
blob: 4e952252331a093a82fda1863538e9268d90ee38 (plain) (blame)
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
55
56
57
58
59
60
61
62
63
#include "arch/x86_64/hal/process.h"
#include "arch/x86_64/hal/smp.h"
#include "hal/smp.h"
#include "jove.h"

int
syscall_handler_arch(uint64_t message_path_raw, uint64_t message_pathlen)
{
    uint16_t *message_path = (uint16_t*)&message_path_raw;
    if(message_pathlen > 4) {
        return EBADPATH;
    }
    processor_t *proc = processor_current();
    jove_owned_obj_t *objdir = obj_take(proc->pcb->rootdir);
    jove_owned_obj_t *message_obj = objdir_getobj(objdir, message_path, message_pathlen);
    if(message_obj == 0) {
        obj_release(objdir);
        return errno;
    }

    return 0;
}

__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 %%rbx; \
                     pushq %%rcx; \
                     pushq %%rbp; \
                     pushq %%r12; \
                     pushq %%r13; \
                     pushq %%r14; \
                     pushq %%r15; \
                     callq syscall_handler_arch; \
                     swapgs; \
                     popq %%r15; \
                     popq %%r14; \
                     popq %%r13; \
                     popq %%r12; \
                     popq %%rbp; \
                     popq %%rcx; \
                     popq %%rbx; \
                     xorq %%rdx, %%rdx; \
                     xorq %%rsi, %%rsi; \
                     xorq %%rdi, %%rdi; \
                     xorq %%r8, %%r8; \
                     xorq %%r9, %%r9; \
                     xorq %%r10, %%r10; \
                     popq %%rcx; \
                     popq %%r11; \
                     popq %%rsp; \
                     sysretq;"
                     ::
                     [pcb] "i"(offsetof(processor_t, pcb)),
                     [ksp] "i"(offsetof(pcb_t, ksp)));
}