refactor: Optimize the context switch overhead
[lunaix-os.git] / lunaix-os / includes / arch / x86 / 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 j_usr(sp, pc)                                                          \
9     asm volatile("movw %0, %%ax\n"                                             \
10                  "movw %%ax, %%es\n"                                           \
11                  "movw %%ax, %%ds\n"                                           \
12                  "movw %%ax, %%fs\n"                                           \
13                  "movw %%ax, %%gs\n"                                           \
14                  "pushl %0\n"                                                  \
15                  "pushl %1\n"                                                  \
16                  "pushl %2\n"                                                  \
17                  "pushl %3\n"                                                  \
18                  "retf" ::"i"(UDATA_SEG),                                      \
19                  "r"(sp),                                                      \
20                  "i"(UCODE_SEG),                                               \
21                  "r"(pc)                                                       \
22                  : "eax", "memory");
23
24 #define push_arg1(stack_ptr, arg) *((typeof((arg))*)(stack_ptr)--) = arg
25 #define push_arg2(stack_ptr, arg1, arg2)                                       \
26     {                                                                          \
27         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
28         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
29     }
30 #define push_arg3(stack_ptr, arg1, arg2, arg3)                                 \
31     {                                                                          \
32         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
33         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
34         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
35     }
36 #define push_arg4(stack_ptr, arg1, arg2, arg3, arg4)                           \
37     {                                                                          \
38         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
39         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
40         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
41         *((typeof((arg4))*)(stack_ptr)--) = arg4;                              \
42     }
43
44 #endif /* __LUNAIX_ABI_H */