akaros/kern/arch/x86/ros/syscall64.h
<<
>>
Prefs
   1#pragma once
   2
   3#ifndef ROS_INC_ARCH_SYSCALL_H
   4#error "Do not include include ros/arch/syscall64.h directly"
   5#endif
   6
   7#ifndef ROS_KERNEL
   8
   9#include <sys/types.h>
  10#include <stdint.h>
  11#include <ros/common.h>
  12#include <ros/arch/mmu.h>
  13#include <assert.h>
  14
  15static inline intreg_t __syscall_sysenter(uintreg_t a0, uintreg_t a1)
  16{
  17        intreg_t ret = 0;
  18        long dummy; /* force D, S clobber */
  19
  20        /* we're calling using the amd function call abi.  this asm and the
  21         * kernel will save the callee-saved state.  We'll use the clobber list
  22         * to force the compiler to save caller-saved state.  As with uthread
  23         * code, you need to make sure you have one ABI-compliant, non-inlined
  24         * function call between any floating point ops and this.
  25         *
  26         * Note that syscall doesn't save the stack pointer - using rdx for
  27         * that.  The kernel will restore it for us. */
  28        asm volatile ("movq %%rsp, %%rdx;       "
  29                      "syscall;                 "
  30                      : "=a"(ret), "=D"(dummy), "=S"(dummy)
  31                      : "D"(a0), "S"(a1)
  32                      : "cc", "memory", "rcx", "rdx", "r8", "r9", "r10", "r11");
  33        return ret;
  34}
  35
  36static inline intreg_t __syscall_trap(uintreg_t a0, uintreg_t a1)
  37{
  38        intreg_t ret;
  39
  40        /* If you change this, change pop_user_ctx() */
  41        asm volatile("int %1"
  42                     : "=a" (ret)
  43                     : "i" (T_SYSCALL),
  44                       "D" (a0),
  45                       "S" (a1)
  46                     : "cc", "memory");
  47        return ret;
  48}
  49
  50/* The kernel has a fast path for setting the fs base, used for TLS changes on
  51 * machines that can't do it from user space.  The magic value for rdi (D) is a
  52 * non-canonical address, which should never be a legitamate syscall. */
  53static inline void __fastcall_setfsbase(uintptr_t fsbase)
  54{
  55        long dummy; /* force D, S clobber */
  56
  57        asm volatile ("syscall" : "=D"(dummy), "=S"(dummy)
  58                                : "D"(FASTCALL_SETFSBASE), "S"(fsbase)
  59                                : "rax", "r11", "rcx", "rdx", "memory");
  60}
  61
  62#endif
  63