refactor: add a async read/write variant to device ops, with allow async io to be...
[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 switch_context(process) asm volatile("jmp switch_to\n" ::"a"(process));
35
36 #define push_arg1(stack_ptr, arg) *((typeof((arg))*)(stack_ptr)--) = arg
37 #define push_arg2(stack_ptr, arg1, arg2)                                       \
38     {                                                                          \
39         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
40         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
41     }
42 #define push_arg3(stack_ptr, arg1, arg2, arg3)                                 \
43     {                                                                          \
44         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
45         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
46         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
47     }
48 #define push_arg4(stack_ptr, arg1, arg2, arg3, arg4)                           \
49     {                                                                          \
50         *((typeof((arg1))*)(stack_ptr)--) = arg1;                              \
51         *((typeof((arg2))*)(stack_ptr)--) = arg2;                              \
52         *((typeof((arg3))*)(stack_ptr)--) = arg3;                              \
53         *((typeof((arg4))*)(stack_ptr)--) = arg4;                              \
54     }
55 #endif
56 #endif /* __LUNAIX_ABI_H */