]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/64/low_level.h
update
[l4.git] / kernel / fiasco / src / kern / ia32 / 64 / low_level.h
1 #ifndef LOW_LEVEL_H
2 #define LOW_LEVEL_H
3
4 #include "asm.h"
5 #include "regdefs.h"
6 #include "shortcut.h"
7 #include "tcboffset.h"
8
9
10 #define REGISTER_SIZE 8
11
12         .macro save_all_regs
13         push    %rax
14         push    %rcx
15         push    %rdx
16         push    %rbx
17         mov     %cr2,%rax
18         push    %rax
19         push    %rbp
20         push    %rsi
21         push    %rdi
22         push    %r8
23         push    %r9
24         push    %r10
25         push    %r11
26         push    %r12
27         push    %r13
28         push    %r14
29         push    %r15
30         .endm
31
32         .macro restore_all_regs
33         pop     %r15
34         pop     %r14
35         pop     %r13
36         pop     %r12
37         pop     %r11
38         pop     %r10
39         pop     %r9
40         pop     %r8
41         pop     %rdi
42         pop     %rsi
43         pop     %rbp
44         add     $0x08,%rsp              /* pop cr2 */
45         pop     %rbx
46         pop     %rdx
47         pop     %rcx
48         pop     %rax
49         .endm
50
51         .macro  SAVE_STATE_SYSEXIT
52         push    %rax
53         push    %rbp
54         push    %rbx
55         push    %rdi
56         push    %rsi
57         push    %rdx
58         push    $0              /* rcx contains user rip */
59         push    %r8
60         push    %r9
61         push    %r10
62         push    $0              /* r11 contains user rflags */
63         push    %r12
64         push    %r13
65         push    %r14
66         push    $0              /* r15 contains user rsp */
67         .endm
68
69         .macro  RESTORE_STATE_SYSEXIT
70         add     $8,%rsp         /* r15 contains user rsp */
71         pop     %r14
72         pop     %r13
73         pop     %r12
74         add     $8,%rsp         /* r11 contains user rflags */
75         pop     %r10
76         pop     %r9
77         pop     %r8
78         add     $8,%rsp         /* rcx contains user eip */
79         pop     %rdx
80         pop     %rsi
81         pop     %rdi
82         pop     %rbx
83         pop     %rbp
84         pop     %rax
85         .endm
86
87
88         .macro  DO_SYSEXIT
89         RESTORE_STATE_SYSEXIT
90         //      CHECK_SANITY $3         /* scratches ecx */
91         //      RESTORE_IOPL
92         mov     (%rsp), %rcx
93         mov     16(%rsp), %r11  /* load user rflags */
94         mov     24(%rsp), %rsp  /* user esp */
95         /* mmh, maybe weird things will
96            happen, if we set an hardware breakpoint before the sysretq
97            maybe we should use the IST stuff to enforce always
98            an good kernel stack
99         */
100         sysretq
101         .endm
102
103         .macro  RESET_THREAD_CANCEL_AT reg
104         andl    $~(Thread_cancel | Thread_dis_alien), OFS__THREAD__STATE (\reg)
105         .endm
106
107         .macro  RESET_THREAD_IPC_MASK_AT reg
108         andl    $~Thread_ipc_mask, OFS__THREAD__STATE (\reg)
109         .endm
110
111         .macro  ESP_TO_TCB_AT reg
112         mov     %rsp, \reg
113         andq    $~(THREAD_BLOCK_SIZE - 1), \reg
114         .endm
115
116         .macro  SAVE_STATE
117         push    %rbp
118         push    %rbx
119         push    %rdi
120         push    %rsi
121         push    %rdx
122         push    %rcx
123         push    %r8
124         push    %r9
125         push    %r10
126         push    %r11
127         push    %r12
128         push    %r13
129         push    %r14
130         push    %r15
131         .endm
132
133         .macro  RESTORE_STATE
134         pop     %r15
135         pop     %r14
136         pop     %r13
137         pop     %r12
138         pop     %r11
139         pop     %r10
140         pop     %r9
141         pop     %r8
142         pop     %rcx
143         pop     %rdx
144         pop     %rsi
145         pop     %rdi
146         pop     %rbx
147         pop     %rbp
148         .endm
149
150 #define SCRATCH_REGISTER_SIZE 72
151         .macro  SAVE_SCRATCH
152         push    %rdi
153         push    %rsi
154         push    %rax /* must be ax cx dx for pagein_tcb_request */
155         push    %rcx
156         push    %rdx
157         push    %r8
158         push    %r9
159         push    %r10
160         push    %r11
161         .endm
162
163         .macro  RESTORE_SCRATCH
164         pop     %r11
165         pop     %r10
166         pop     %r9
167         pop     %r8
168         pop     %rdx
169         pop     %rcx
170         pop     %rax
171         pop     %rsi
172         pop     %rdi
173         .endm
174
175         .macro  IRET_INSN
176         iretq
177         .endm
178
179 #define PAGE_FAULT_ADDR %cr2
180 #define PAGE_DIR_ADDR   %cr3
181
182 #endif //LOW_LEVEL_H