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