95e1164af5ad2085527ddaf8d4579c0708fb8bf7
1 #ifndef UST_PROCESSOR_H
2 #define UST_PROCESSOR_H
7 extern __thread
long ust_reg_stack
[500];
8 extern volatile __thread
long *ust_reg_stack_ptr
;
26 #ifdef CONFIG_UST_GDB_INTEGRATION
28 /* save_registers - saves most of the processor's registers so
29 * they are available to the probe. gdb uses this to give the
30 * value of local variables.
32 * Saving all registers without losing any of their values is
35 * We cannot pass to the asm stub the address of a registers structure
36 * on the stack, because it will use a register and override its value.
38 * We don't want to use a stub to push the regs on the stack and then
39 * another stub to copy them to a structure because changing %sp in asm
40 * and then returning to C (even briefly) can have unexpected results.
41 * Also, gcc might modify %sp between the stubs in reaction to the
42 * register needs of the second stub that needs to know where to copy
43 * the register values.
45 * So the chosen approach is to use another stack, declared in thread-
46 * local storage, to push the registers. They are subsequently copied
47 * to the stack, by C code.
50 #define save_registers(regsptr) \
52 /* save original esp */ \
54 /* push original eflags */ \
56 /* eax will hold the ptr to the private stack bottom */ \
58 /* ebx is used for TLS access */ \
60 /* ecx will be used to temporarily hold the stack bottom addr */\
62 /* rdi is the input to __tls_get_addr, and also a temp var */ \
64 /* For TLS access, we have to do function calls. However, \
65 * we must not lose the original value of: \
66 * esp, eflags, eax, ebx, ecx, edx, esi, edi, ebp, cs, ss \
68 * Some registers' original values have already been saved: \
69 * esp, eflags, eax, ebx, ecx, edi \
71 * In addition, the i386 ABI says the following registers belong\
72 * to the caller function: \
73 * esp, ebp, esi, edi, ebx \
75 * The following registers should not be changed by the callee: \
78 * Therefore, the following registers must be explicitly \
83 /* Get GOT address */ \
84 "call __i686.get_pc_thunk.bx\n\t" \
85 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
86 /* Start TLS access of private reg stack pointer */ \
87 "leal ust_reg_stack_ptr@tlsgd(,%%ebx,1),%%eax\n\t" \
88 "call ___tls_get_addr@plt\n\t" \
89 /* --- End TLS access */ \
90 /* check if ust_reg_stack_ptr has been initialized */ \
91 "movl (%%eax),%%ecx\n\t" \
92 "testl %%ecx,%%ecx\n\t" \
94 "movl %%eax,%%ecx\n\t" \
95 /* Save ecx because we are using it. */ \
97 /* Start TLS access of private reg stack */ \
98 "leal ust_reg_stack@tlsgd(,%%ebx,1),%%eax\n\t" \
99 "call ___tls_get_addr@plt\n\t" \
100 /* --- End TLS access */ \
102 "addl $500,%%eax\n\t" \
103 "movl %%eax,(%%ecx)\n\t" \
104 "movl %%ecx,%%eax\n\t" \
105 /* now the pointer to the private stack is in eax. \
106 must add stack size so the ptr points to the stack bottom. */ \
108 /* edx was pushed for function calls */ \
110 /* Manually push esp to private stack */ \
111 "addl $-4,(%%eax)\n\t" \
112 "movl 20(%%esp), %%edi\n\t" \
113 "movl (%%eax), %%ebx\n\t" \
114 "movl %%edi, (%%ebx)\n\t" \
115 /* Manually push eflags to private stack */ \
116 "addl $-4,(%%eax)\n\t" \
117 "movl 16(%%esp), %%edi\n\t" \
118 "movl (%%eax), %%ebx\n\t" \
119 "movl %%edi, (%%ebx)\n\t" \
120 /* Manually push eax to private stack */ \
121 "addl $-4,(%%eax)\n\t" \
122 "movl 12(%%esp), %%edi\n\t" \
123 "movl (%%eax), %%ebx\n\t" \
124 "movl %%edi, (%%ebx)\n\t" \
125 /* Manually push ebx to private stack */ \
126 "addl $-4,(%%eax)\n\t" \
127 "movl 8(%%esp), %%edi\n\t" \
128 "movl (%%eax), %%ebx\n\t" \
129 "movl %%edi, (%%ebx)\n\t" \
130 /* Manually push ecx to private stack */ \
131 "addl $-4,(%%eax)\n\t" \
132 "movl 4(%%esp), %%edi\n\t" \
133 "movl (%%eax), %%ebx\n\t" \
134 "movl %%edi, (%%ebx)\n\t" \
135 /* Manually push edi to private stack */ \
136 "addl $-4,(%%eax)\n\t" \
137 "movl 0(%%esp), %%edi\n\t" \
138 "movl (%%eax), %%ebx\n\t" \
139 "movl %%edi, (%%ebx)\n\t" \
140 /* now push regs to tls */ \
141 /* -- esp already pushed -- */ \
142 /* -- eax already pushed -- */ \
143 /* -- ebx already pushed -- */ \
144 /* -- ecx already pushed -- */ \
145 /* -- edi already pushed -- */ \
146 "addl $-4,(%%eax)\n\t" \
147 "movl (%%eax), %%ebx\n\t" \
148 "movl %%edx,(%%ebx)\n\t" \
149 "addl $-4,(%%eax)\n\t" \
150 "movl (%%eax), %%ebx\n\t" \
151 "movl %%ebp,(%%ebx)\n\t" \
152 "addl $-4,(%%eax)\n\t" \
153 "movl (%%eax), %%ebx\n\t" \
154 "movl %%esi,(%%ebx)\n\t" \
156 "addl $-2,(%%eax)\n\t" \
157 "movl (%%eax), %%ebx\n\t" \
158 "movw %%cs, (%%ebx)\n\t" \
160 "addl $-2,(%%eax)\n\t" \
161 "movl (%%eax), %%ebx\n\t" \
162 "movw %%ss, (%%ebx)\n\t" \
163 /* restore original values of regs that were used internally */ \
168 /* cancel push of rsp */ \
169 "addl $4,%%esp\n\t" \
170 /* cancel push of eflags */ \
171 "addl $4,%%esp\n\t" \
173 memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
174 ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
176 #else /* CONFIG_UST_GDB_INTEGRATION */
178 #define save_registers(a)
180 #endif /* CONFIG_UST_GDB_INTEGRATION */
182 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__
184 #define ARCH_COPY_ADDR(src, dst) "lea " src "," dst
186 #define _ASM_PTR ".long "
188 #else /* below is code for x86-64 */
191 int padding
; /* 4 bytes */
209 unsigned long rflags
;
213 #ifdef CONFIG_UST_GDB_INTEGRATION
215 #define save_registers(regsptr) \
217 /* save original rsp */ \
219 /* push original rflags */ \
221 /* rax will hold the ptr to the private stack bottom */ \
223 /* rbx will be used to temporarily hold the stack bottom addr */ \
225 /* rdi is the input to __tls_get_addr, and also a temp var */ \
227 /* For TLS access, we have to do function calls. However, \
228 * we must not lose the original value of: \
229 * rsp, rflags, rax, rbx, rcx, rdx, rsi, rdi, rbp, r8, r9 \
230 * r10, r11, r12, r13, r14, r15, cs, ss \
232 * Some registers' original values have already been saved: \
233 * rsp, rflags, rax, rbx, rdi \
235 * In addition, the x86-64 ABI says the following registers \
236 * belong to the caller function: \
237 * rbp, rbx, r12, r13, r14, r15 \
239 * The following registers should not be changed by the callee: \
242 * Therefore, the following registers must be explicitly \
244 * rcx, rdx, rsi, r8, r9, r10, r11 \
253 /* Start TLS access of private reg stack pointer */ \
255 "leaq ust_reg_stack_ptr@tlsgd(%%rip), %%rdi\n\t" \
258 "call __tls_get_addr@plt\n\t" \
259 /* --- End TLS access */ \
260 /* check if ust_reg_stack_ptr has been initialized */ \
261 "movq (%%rax),%%rbx\n\t" \
262 "testq %%rbx,%%rbx\n\t" \
264 "movq %%rax,%%rbx\n\t" \
265 /* Start TLS access of private reg stack */ \
267 "leaq ust_reg_stack@tlsgd(%%rip), %%rdi\n\t" \
270 "call __tls_get_addr@plt\n\t" \
271 /* --- End TLS access */ \
272 "addq $500,%%rax\n\t" \
273 "movq %%rax,(%%rbx)\n\t" \
274 "movq %%rbx,%%rax\n\t" \
275 /* now the pointer to the private stack is in rax.
276 must add stack size so the ptr points to the stack bottom. */ \
278 /* Pop regs that were pushed for function calls */ \
286 /* Manually push rsp to private stack */ \
287 "addq $-8,(%%rax)\n\t" \
288 "movq 32(%%rsp), %%rdi\n\t" \
289 "movq (%%rax), %%rbx\n\t" \
290 "movq %%rdi, (%%rbx)\n\t" \
291 /* Manually push eflags to private stack */ \
292 "addq $-8,(%%rax)\n\t" \
293 "movq 24(%%rsp), %%rdi\n\t" \
294 "movq (%%rax), %%rbx\n\t" \
295 "movq %%rdi, (%%rbx)\n\t" \
296 /* Manually push rax to private stack */ \
297 "addq $-8,(%%rax)\n\t" \
298 "movq 16(%%rsp), %%rdi\n\t" \
299 "movq (%%rax), %%rbx\n\t" \
300 "movq %%rdi, (%%rbx)\n\t" \
301 /* Manually push rbx to private stack */ \
302 "addq $-8,(%%rax)\n\t" \
303 "movq 8(%%rsp), %%rdi\n\t" \
304 "movq (%%rax), %%rbx\n\t" \
305 "movq %%rdi, (%%rbx)\n\t" \
306 /* Manually push rdi to private stack */ \
307 "addq $-8,(%%rax)\n\t" \
308 "movq 0(%%rsp), %%rdi\n\t" \
309 "movq (%%rax), %%rbx\n\t" \
310 "movq %%rdi, (%%rbx)\n\t" \
311 /* now push regs to tls */ \
312 /* -- rsp already pushed -- */ \
313 /* -- rax already pushed -- */ \
314 /* -- rbx already pushed -- */ \
315 /* -- rdi already pushed -- */ \
316 "addq $-8,(%%rax)\n\t" \
317 "movq (%%rax), %%rbx\n\t" \
318 "movq %%rcx,(%%rbx)\n\t" \
319 "addq $-8,(%%rax)\n\t" \
320 "movq (%%rax), %%rbx\n\t" \
321 "movq %%rdx,(%%rbx)\n\t" \
322 "addq $-8,(%%rax)\n\t" \
323 "movq (%%rax), %%rbx\n\t" \
324 "movq %%rbp,(%%rbx)\n\t" \
325 "addq $-8,(%%rax)\n\t" \
326 "movq (%%rax), %%rbx\n\t" \
327 "movq %%rsi,(%%rbx)\n\t" \
328 "addq $-8,(%%rax)\n\t" \
329 "movq (%%rax), %%rbx\n\t" \
330 "movq %%r8,(%%rbx)\n\t" \
331 "addq $-8,(%%rax)\n\t" \
332 "movq (%%rax), %%rbx\n\t" \
333 "movq %%r9,(%%rbx)\n\t" \
334 "addq $-8,(%%rax)\n\t" \
335 "movq (%%rax), %%rbx\n\t" \
336 "movq %%r10,(%%rbx)\n\t" \
337 "addq $-8,(%%rax)\n\t" \
338 "movq (%%rax), %%rbx\n\t" \
339 "movq %%r11,(%%rbx)\n\t" \
340 "addq $-8,(%%rax)\n\t" \
341 "movq (%%rax), %%rbx\n\t" \
342 "movq %%r12,(%%rbx)\n\t" \
343 "addq $-8,(%%rax)\n\t" \
344 "movq (%%rax), %%rbx\n\t" \
345 "movq %%r13,(%%rbx)\n\t" \
346 "addq $-8,(%%rax)\n\t" \
347 "movq (%%rax), %%rbx\n\t" \
348 "movq %%r14,(%%rbx)\n\t" \
349 "addq $-8,(%%rax)\n\t" \
350 "movq (%%rax), %%rbx\n\t" \
351 "movq %%r15,(%%rbx)\n\t" \
353 "addq $-2,(%%rax)\n\t" \
354 "movq (%%rax), %%rbx\n\t" \
355 "movw %%cs, (%%rbx)\n\t" \
357 "addq $-2,(%%rax)\n\t" \
358 "movq (%%rax), %%rbx\n\t" \
359 "movw %%ss, (%%rbx)\n\t" \
360 /* add padding for struct registers */ \
361 "addq $-4,(%%rax)\n\t" \
362 /* restore original values of regs that were used internally */ \
366 /* cancel push of rsp */ \
367 "addq $8,%%rsp\n\t" \
368 /* cancel push of rflags */ \
369 "addq $8,%%rsp\n\t" \
371 memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
372 ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
374 #else /* CONFIG_UST_GDB_INTEGRATION */
376 #define save_registers(a)
378 #endif /* CONFIG_UST_GDB_INTEGRATION */
380 /* Macro to insert the address of a relative jump in an assembly stub,
381 * in a relocatable way. On x86-64, this uses a special (%rip) notation. */
382 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__(%%rip)
384 #define ARCH_COPY_ADDR(src, dst) "lea " src "(%%rip)," dst
386 #define _ASM_PTR ".quad "
390 #endif /* UST_PROCESSOR_H */
This page took 0.046963 seconds and 4 git commands to generate.