Commit | Line | Data |
---|---|---|
5af57e62 PMF |
1 | #ifndef UST_PROCESSOR_H |
2 | #define UST_PROCESSOR_H | |
d98a01c6 PMF |
3 | |
4 | #include <stddef.h> | |
636ca5d6 PMF |
5 | #include <string.h> |
6 | ||
7 | extern __thread long ust_reg_stack[500]; | |
8 | extern volatile __thread long *ust_reg_stack_ptr; | |
9 | ||
e003d6ee | 10 | #ifndef __x86_64 |
d98a01c6 PMF |
11 | |
12 | struct registers { | |
13 | long eax; | |
14 | long ebx; | |
15 | long ecx; | |
16 | long edx; | |
17 | long ebp; | |
18 | long esp; | |
19 | long esi; | |
20 | long edi; | |
21 | int xds; | |
22 | int xes; | |
23 | int xfs; | |
24 | int xgs; | |
25 | long eip; | |
26 | int xcs; | |
27 | long eflags; | |
28 | int xss; | |
29 | }; | |
30 | ||
e003d6ee | 31 | #ifdef CONFIG_UST_GDB_INTEGRATION |
defa46a7 PMF |
32 | |
33 | #error "GDB integration not supported for x86-32 yet." | |
34 | ||
35 | #define save_ip() | |
36 | #define save_registers(a) | |
37 | ||
e003d6ee | 38 | #else /* CONFIG_UST_GDB_INTEGRATION */ |
defa46a7 PMF |
39 | |
40 | #define save_ip() | |
41 | #define save_registers(a) | |
42 | ||
e003d6ee | 43 | #endif /* CONFIG_UST_GDB_INTEGRATION */ |
d98a01c6 | 44 | |
9e8f4f52 PMF |
45 | #define RELATIVE_ADDRESS(__rel_label__) __rel_label__ |
46 | ||
47 | #define _ASM_PTR ".long " | |
48 | ||
defa46a7 | 49 | #else /* below is code for x86-64 */ |
d98a01c6 PMF |
50 | |
51 | struct registers { | |
636ca5d6 PMF |
52 | int padding; /* 4 bytes */ |
53 | short ss; | |
54 | short cs; | |
636ca5d6 PMF |
55 | unsigned long r15; |
56 | unsigned long r14; | |
57 | unsigned long r13; | |
58 | unsigned long r12; | |
59 | unsigned long r11; | |
60 | unsigned long r10; | |
61 | unsigned long r9; | |
62 | unsigned long r8; | |
d98a01c6 | 63 | unsigned long rsi; |
636ca5d6 PMF |
64 | unsigned long rbp; |
65 | unsigned long rdx; | |
66 | unsigned long rcx; | |
d98a01c6 | 67 | unsigned long rdi; |
636ca5d6 PMF |
68 | unsigned long rbx; |
69 | unsigned long rax; | |
a5850bc4 | 70 | unsigned long rflags; |
636ca5d6 | 71 | unsigned long rsp; |
d98a01c6 PMF |
72 | }; |
73 | ||
e003d6ee PMF |
74 | #ifdef CONFIG_UST_GDB_INTEGRATION |
75 | #define save_ip(channel,name) \ | |
defa46a7 PMF |
76 | asm (".section __marker_addr,\"aw\",@progbits\n\t" \ |
77 | _ASM_PTR "%c[marker_struct], (1f)\n\t" \ | |
78 | ".previous\n\t" \ | |
79 | "1:\n\t" \ | |
80 | :: [marker_struct] "i" (&__mark_##channel##_##name));\ | |
81 | ||
8524c98d | 82 | #define save_registers(regsptr) \ |
636ca5d6 PMF |
83 | asm volatile ( \ |
84 | /* save original rsp */ \ | |
85 | "pushq %%rsp\n\t" \ | |
a5850bc4 PMF |
86 | /* push original rflags */ \ |
87 | "pushfq\n\t" \ | |
636ca5d6 PMF |
88 | /* rax will hold the ptr to the private stack bottom */ \ |
89 | "pushq %%rax\n\t" \ | |
90 | /* rbx will be used to temporarily hold the stack bottom addr */ \ | |
91 | "pushq %%rbx\n\t" \ | |
92 | /* rdi is the input to __tls_get_addr, and also a temp var */ \ | |
93 | "pushq %%rdi\n\t" \ | |
a5850bc4 | 94 | /* Start TLS access of private reg stack pointer */ \ |
636ca5d6 PMF |
95 | ".byte 0x66\n\t" \ |
96 | "leaq ust_reg_stack_ptr@tlsgd(%%rip), %%rdi\n\t" \ | |
97 | ".word 0x6666\n\t" \ | |
98 | "rex64\n\t" \ | |
99 | "call __tls_get_addr@plt\n\t" \ | |
100 | /* --- End TLS access */ \ | |
a5850bc4 PMF |
101 | /* check if ust_reg_stack_ptr has been initialized */ \ |
102 | "movq (%%rax),%%rbx\n\t" \ | |
103 | "testq %%rbx,%%rbx\n\t" \ | |
104 | "jne 1f\n\t" \ | |
105 | "movq %%rax,%%rbx\n\t" \ | |
106 | /* Start TLS access of private reg stack */ \ | |
107 | ".byte 0x66\n\t" \ | |
108 | "leaq ust_reg_stack@tlsgd(%%rip), %%rdi\n\t" \ | |
109 | ".word 0x6666\n\t" \ | |
110 | "rex64\n\t" \ | |
111 | "call __tls_get_addr@plt\n\t" \ | |
112 | /* --- End TLS access */ \ | |
113 | "addq $500,%%rax\n\t" \ | |
114 | "movq %%rax,(%%rbx)\n\t" \ | |
115 | "movq %%rbx,%%rax\n\t" \ | |
116 | /* now the pointer to the private stack is in rax. | |
117 | must add stack size so the ptr points to the stack bottom. */ \ | |
118 | "1:\n\t" \ | |
636ca5d6 PMF |
119 | /* Manually push rsp to private stack */ \ |
120 | "addq $-8,(%%rax)\n\t" \ | |
a5850bc4 PMF |
121 | "movq 32(%%rsp), %%rdi\n\t" \ |
122 | "movq (%%rax), %%rbx\n\t" \ | |
123 | "movq %%rdi, (%%rbx)\n\t" \ | |
124 | /* Manually push eflags to private stack */ \ | |
125 | "addq $-8,(%%rax)\n\t" \ | |
636ca5d6 PMF |
126 | "movq 24(%%rsp), %%rdi\n\t" \ |
127 | "movq (%%rax), %%rbx\n\t" \ | |
128 | "movq %%rdi, (%%rbx)\n\t" \ | |
129 | /* Manually push rax to private stack */ \ | |
130 | "addq $-8,(%%rax)\n\t" \ | |
131 | "movq 16(%%rsp), %%rdi\n\t" \ | |
132 | "movq (%%rax), %%rbx\n\t" \ | |
133 | "movq %%rdi, (%%rbx)\n\t" \ | |
134 | /* Manually push rbx to private stack */ \ | |
135 | "addq $-8,(%%rax)\n\t" \ | |
136 | "movq 8(%%rsp), %%rdi\n\t" \ | |
137 | "movq (%%rax), %%rbx\n\t" \ | |
138 | "movq %%rdi, (%%rbx)\n\t" \ | |
139 | /* Manually push rdi to private stack */ \ | |
140 | "addq $-8,(%%rax)\n\t" \ | |
141 | "movq 0(%%rsp), %%rdi\n\t" \ | |
142 | "movq (%%rax), %%rbx\n\t" \ | |
143 | "movq %%rdi, (%%rbx)\n\t" \ | |
144 | /* now push regs to tls */ \ | |
145 | /* -- rsp already pushed -- */ \ | |
146 | /* -- rax already pushed -- */ \ | |
147 | /* -- rbx already pushed -- */ \ | |
148 | /* -- rdi already pushed -- */ \ | |
149 | "addq $-8,(%%rax)\n\t" \ | |
150 | "movq (%%rax), %%rbx\n\t" \ | |
151 | "movq %%rcx,(%%rbx)\n\t" \ | |
152 | "addq $-8,(%%rax)\n\t" \ | |
153 | "movq (%%rax), %%rbx\n\t" \ | |
154 | "movq %%rdx,(%%rbx)\n\t" \ | |
155 | "addq $-8,(%%rax)\n\t" \ | |
156 | "movq (%%rax), %%rbx\n\t" \ | |
157 | "movq %%rbp,(%%rbx)\n\t" \ | |
158 | "addq $-8,(%%rax)\n\t" \ | |
159 | "movq (%%rax), %%rbx\n\t" \ | |
160 | "movq %%rsi,(%%rbx)\n\t" \ | |
161 | "addq $-8,(%%rax)\n\t" \ | |
162 | "movq (%%rax), %%rbx\n\t" \ | |
163 | "movq %%r8,(%%rbx)\n\t" \ | |
164 | "addq $-8,(%%rax)\n\t" \ | |
165 | "movq (%%rax), %%rbx\n\t" \ | |
166 | "movq %%r9,(%%rbx)\n\t" \ | |
167 | "addq $-8,(%%rax)\n\t" \ | |
168 | "movq (%%rax), %%rbx\n\t" \ | |
169 | "movq %%r10,(%%rbx)\n\t" \ | |
170 | "addq $-8,(%%rax)\n\t" \ | |
171 | "movq (%%rax), %%rbx\n\t" \ | |
172 | "movq %%r11,(%%rbx)\n\t" \ | |
173 | "addq $-8,(%%rax)\n\t" \ | |
174 | "movq (%%rax), %%rbx\n\t" \ | |
175 | "movq %%r12,(%%rbx)\n\t" \ | |
176 | "addq $-8,(%%rax)\n\t" \ | |
177 | "movq (%%rax), %%rbx\n\t" \ | |
178 | "movq %%r13,(%%rbx)\n\t" \ | |
179 | "addq $-8,(%%rax)\n\t" \ | |
180 | "movq (%%rax), %%rbx\n\t" \ | |
181 | "movq %%r14,(%%rbx)\n\t" \ | |
182 | "addq $-8,(%%rax)\n\t" \ | |
183 | "movq (%%rax), %%rbx\n\t" \ | |
184 | "movq %%r15,(%%rbx)\n\t" \ | |
636ca5d6 PMF |
185 | /* push cs */ \ |
186 | "addq $-2,(%%rax)\n\t" \ | |
187 | "movq (%%rax), %%rbx\n\t" \ | |
188 | "movw %%cs, (%%rbx)\n\t" \ | |
189 | /* push ss */ \ | |
190 | "addq $-2,(%%rax)\n\t" \ | |
191 | "movq (%%rax), %%rbx\n\t" \ | |
192 | "movw %%ss, (%%rbx)\n\t" \ | |
193 | /* add padding for struct registers */ \ | |
194 | "addq $-4,(%%rax)\n\t" \ | |
195 | /* restore original values of regs that were used internally */ \ | |
196 | "popq %%rdi\n\t" \ | |
197 | "popq %%rbx\n\t" \ | |
198 | "popq %%rax\n\t" \ | |
199 | /* cancel push of rsp */ \ | |
200 | "addq $8,%%rsp\n\t" \ | |
a5850bc4 PMF |
201 | /* cancel push of rflags */ \ |
202 | "addq $8,%%rsp\n\t" \ | |
636ca5d6 PMF |
203 | ::); \ |
204 | memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \ | |
205 | ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers)); | |
d98a01c6 | 206 | |
e003d6ee | 207 | #endif /* CONFIG_UST_GDB_INTEGRATION */ |
defa46a7 | 208 | |
9e8f4f52 PMF |
209 | /* Macro to insert the address of a relative jump in an assembly stub, |
210 | * in a relocatable way. On x86-64, this uses a special (%rip) notation. */ | |
211 | #define RELATIVE_ADDRESS(__rel_label__) __rel_label__(%%rip) | |
212 | ||
213 | #define _ASM_PTR ".quad " | |
214 | ||
d98a01c6 PMF |
215 | #endif |
216 | ||
5af57e62 | 217 | #endif /* UST_PROCESSOR_H */ |