x86: cleans up syscalls, fixes pop_ros_tf() (XCC)
[akaros.git] / kern / arch / i686 / ros / bits / syscall.h
1 #ifndef _ROS_ARCH_BITS_SYSCALL_H
2 #define _ROS_ARCH_BITS_SYSCALL_H
3
4 #define T_SYSCALL       0x80
5
6 #ifndef ROS_KERNEL
7
8 #include <sys/types.h>
9 #include <stdint.h>
10 #include <ros/common.h>
11 #include <assert.h>
12
13 static inline intreg_t __syscall_sysenter(uintreg_t a0, uintreg_t a1)
14 {
15         /* The kernel clobbers ecx, so we save it manually. */
16         intreg_t ret = 0;
17         asm volatile ("  pushl %%ecx;        "
18                       "  pushl %%edx;        "
19                       "  pushl %%ebp;        "
20                       "  movl %%esp, %%ebp;  "
21                       "  leal 1f, %%edx;     "
22                       "  sysenter;           "
23                       "1:                    "
24                       "  popl %%ebp;         "
25                       "  popl %%edx;         "
26                       "  popl %%ecx;         "
27                       : "=a" (ret)
28                       : "a" (a0),
29                         "S" (a1)
30                       : "cc", "memory");
31         return ret;
32 }
33
34 static inline intreg_t __syscall_trap(uintreg_t a0, uintreg_t a1)
35 {
36         intreg_t ret;
37
38         /* If you change this, change pop_ros_tf() */
39         asm volatile("int %1"
40                      : "=a" (ret)
41                      : "i" (T_SYSCALL),
42                        "a" (a0),
43                        "d" (a1)
44                      : "cc", "memory");
45         return ret;
46 }
47
48 #endif
49
50 #endif
51