refactor: striped more arch-related code from the kernel code base
[lunaix-os.git] / lunaix-os / arch / i386 / includes / sys / abi.h
1 #ifndef __LUNAIX_I386ABI_H
2 #define __LUNAIX_I386ABI_H
3
4 #include <sys/x86_isa.h>
5
6 #define stack_alignment 0xfffffff0
7
8 #ifndef __ASM__
9 #define store_retval(retval) __current->intr_ctx->registers.eax = (retval)
10
11 #define store_retval_to(proc, retval) (proc)->intr_ctx->registers.eax = (retval)
12
13 #define eret_target(proc) (proc)->intr_ctx->execp->eip
14 #define eret_stack(proc) (proc)->intr_ctx->execp->esp
15 #define intr_ivec(proc) (proc)->intr_ctx->execp->vector
16 #define intr_ierr(proc) (proc)->intr_ctx->execp->err_code
17
18 #define j_usr(sp, pc)                                                          \
19     asm volatile("movw %0, %%ax\n"                                             \
20                  "movw %%ax, %%es\n"                                           \
21                  "movw %%ax, %%ds\n"                                           \
22                  "movw %%ax, %%fs\n"                                           \
23                  "movw %%ax, %%gs\n"                                           \
24                  "pushl %0\n"                                                  \
25                  "pushl %1\n"                                                  \
26                  "pushl %2\n"                                                  \
27                  "pushl %3\n"                                                  \
28                  "retf" ::"i"(UDATA_SEG),                                      \
29                  "r"(sp),                                                      \
30                  "i"(UCODE_SEG),                                               \
31                  "r"(pc)                                                       \
32                  : "eax", "memory");
33
34 #define push_arg1(stack_ptr, arg) *((typeof((arg))*)(stack_ptr)--) = arg
35 #define push_arg2(stack_ptr, arg1, arg2)                                       \
36     {                                                                          \
37         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
38         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
39     }
40 #define push_arg3(stack_ptr, arg1, arg2, arg3)                                 \
41     {                                                                          \
42         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
43         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
44         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
45     }
46 #define push_arg4(stack_ptr, arg1, arg2, arg3, arg4)                           \
47     {                                                                          \
48         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
49         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
50         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
51         *((typeof((arg4))*)(stack_ptr)--) = arg4;                              \
52     }
53 #endif
54 #endif /* __LUNAIX_ABI_H */