aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/context_switching/syscall/main.cpp
blob: a226e23457c19e0a0867ee0c298f0bb73a43a6da (plain)
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
#include "arch/context_switching/syscall/main.hpp"

namespace teachos::arch::context_switching::syscall
{
  auto syscall(type syscall_number, arguments args) -> error
  {
    asm volatile("mov %[input], %%rax"
                 : /* no output from call */
                 : [input] "m"(syscall_number)
                 : "memory");

    asm volatile("mov %[input], %%rdi " : /* no output from call */ : [input] "m"(args.arg_0) : "memory");
    asm volatile("mov %[input], %%rsi" : /* no output from call */ : [input] "m"(args.arg_1) : "memory");
    asm volatile("mov %[input], %%rdx" : /* no output from call */ : [input] "m"(args.arg_2) : "memory");
    asm volatile("mov %[input], %%r10" : /* no output from call */ : [input] "m"(args.arg_3) : "memory");
    asm volatile("mov %[input], %%r8" : /* no output from call */ : [input] "m"(args.arg_4) : "memory");
    asm volatile("mov %[input], %%r9" : /* no output from call */ : [input] "m"(args.arg_5) : "memory");

    asm volatile("syscall");

    error error{};
    asm volatile("mov %%rax, %[output]" : [output] "=m"(error));
    return error;
  }

}  // namespace teachos::arch::context_switching::syscall