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 _ASM_PTR ".long "
186 #else /* below is code for x86-64 */
189 int padding
; /* 4 bytes */
207 unsigned long rflags
;
211 #ifdef CONFIG_UST_GDB_INTEGRATION
213 #define save_registers(regsptr) \
215 /* save original rsp */ \
217 /* push original rflags */ \
219 /* rax will hold the ptr to the private stack bottom */ \
221 /* rbx will be used to temporarily hold the stack bottom addr */ \
223 /* rdi is the input to __tls_get_addr, and also a temp var */ \
225 /* For TLS access, we have to do function calls. However, \
226 * we must not lose the original value of: \
227 * rsp, rflags, rax, rbx, rcx, rdx, rsi, rdi, rbp, r8, r9 \
228 * r10, r11, r12, r13, r14, r15, cs, ss \
230 * Some registers' original values have already been saved: \
231 * rsp, rflags, rax, rbx, rdi \
233 * In addition, the x86-64 ABI says the following registers \
234 * belong to the caller function: \
235 * rbp, rbx, r12, r13, r14, r15 \
237 * The following registers should not be changed by the callee: \
240 * Therefore, the following registers must be explicitly \
242 * rcx, rdx, rsi, r8, r9, r10, r11 \
251 /* Start TLS access of private reg stack pointer */ \
253 "leaq ust_reg_stack_ptr@tlsgd(%%rip), %%rdi\n\t" \
256 "call __tls_get_addr@plt\n\t" \
257 /* --- End TLS access */ \
258 /* check if ust_reg_stack_ptr has been initialized */ \
259 "movq (%%rax),%%rbx\n\t" \
260 "testq %%rbx,%%rbx\n\t" \
262 "movq %%rax,%%rbx\n\t" \
263 /* Start TLS access of private reg stack */ \
265 "leaq ust_reg_stack@tlsgd(%%rip), %%rdi\n\t" \
268 "call __tls_get_addr@plt\n\t" \
269 /* --- End TLS access */ \
270 "addq $500,%%rax\n\t" \
271 "movq %%rax,(%%rbx)\n\t" \
272 "movq %%rbx,%%rax\n\t" \
273 /* now the pointer to the private stack is in rax.
274 must add stack size so the ptr points to the stack bottom. */ \
276 /* Pop regs that were pushed for function calls */ \
284 /* Manually push rsp to private stack */ \
285 "addq $-8,(%%rax)\n\t" \
286 "movq 32(%%rsp), %%rdi\n\t" \
287 "movq (%%rax), %%rbx\n\t" \
288 "movq %%rdi, (%%rbx)\n\t" \
289 /* Manually push eflags to private stack */ \
290 "addq $-8,(%%rax)\n\t" \
291 "movq 24(%%rsp), %%rdi\n\t" \
292 "movq (%%rax), %%rbx\n\t" \
293 "movq %%rdi, (%%rbx)\n\t" \
294 /* Manually push rax to private stack */ \
295 "addq $-8,(%%rax)\n\t" \
296 "movq 16(%%rsp), %%rdi\n\t" \
297 "movq (%%rax), %%rbx\n\t" \
298 "movq %%rdi, (%%rbx)\n\t" \
299 /* Manually push rbx to private stack */ \
300 "addq $-8,(%%rax)\n\t" \
301 "movq 8(%%rsp), %%rdi\n\t" \
302 "movq (%%rax), %%rbx\n\t" \
303 "movq %%rdi, (%%rbx)\n\t" \
304 /* Manually push rdi to private stack */ \
305 "addq $-8,(%%rax)\n\t" \
306 "movq 0(%%rsp), %%rdi\n\t" \
307 "movq (%%rax), %%rbx\n\t" \
308 "movq %%rdi, (%%rbx)\n\t" \
309 /* now push regs to tls */ \
310 /* -- rsp already pushed -- */ \
311 /* -- rax already pushed -- */ \
312 /* -- rbx already pushed -- */ \
313 /* -- rdi already pushed -- */ \
314 "addq $-8,(%%rax)\n\t" \
315 "movq (%%rax), %%rbx\n\t" \
316 "movq %%rcx,(%%rbx)\n\t" \
317 "addq $-8,(%%rax)\n\t" \
318 "movq (%%rax), %%rbx\n\t" \
319 "movq %%rdx,(%%rbx)\n\t" \
320 "addq $-8,(%%rax)\n\t" \
321 "movq (%%rax), %%rbx\n\t" \
322 "movq %%rbp,(%%rbx)\n\t" \
323 "addq $-8,(%%rax)\n\t" \
324 "movq (%%rax), %%rbx\n\t" \
325 "movq %%rsi,(%%rbx)\n\t" \
326 "addq $-8,(%%rax)\n\t" \
327 "movq (%%rax), %%rbx\n\t" \
328 "movq %%r8,(%%rbx)\n\t" \
329 "addq $-8,(%%rax)\n\t" \
330 "movq (%%rax), %%rbx\n\t" \
331 "movq %%r9,(%%rbx)\n\t" \
332 "addq $-8,(%%rax)\n\t" \
333 "movq (%%rax), %%rbx\n\t" \
334 "movq %%r10,(%%rbx)\n\t" \
335 "addq $-8,(%%rax)\n\t" \
336 "movq (%%rax), %%rbx\n\t" \
337 "movq %%r11,(%%rbx)\n\t" \
338 "addq $-8,(%%rax)\n\t" \
339 "movq (%%rax), %%rbx\n\t" \
340 "movq %%r12,(%%rbx)\n\t" \
341 "addq $-8,(%%rax)\n\t" \
342 "movq (%%rax), %%rbx\n\t" \
343 "movq %%r13,(%%rbx)\n\t" \
344 "addq $-8,(%%rax)\n\t" \
345 "movq (%%rax), %%rbx\n\t" \
346 "movq %%r14,(%%rbx)\n\t" \
347 "addq $-8,(%%rax)\n\t" \
348 "movq (%%rax), %%rbx\n\t" \
349 "movq %%r15,(%%rbx)\n\t" \
351 "addq $-2,(%%rax)\n\t" \
352 "movq (%%rax), %%rbx\n\t" \
353 "movw %%cs, (%%rbx)\n\t" \
355 "addq $-2,(%%rax)\n\t" \
356 "movq (%%rax), %%rbx\n\t" \
357 "movw %%ss, (%%rbx)\n\t" \
358 /* add padding for struct registers */ \
359 "addq $-4,(%%rax)\n\t" \
360 /* restore original values of regs that were used internally */ \
364 /* cancel push of rsp */ \
365 "addq $8,%%rsp\n\t" \
366 /* cancel push of rflags */ \
367 "addq $8,%%rsp\n\t" \
369 memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
370 ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
372 #else /* CONFIG_UST_GDB_INTEGRATION */
374 #define save_registers(a)
376 #endif /* CONFIG_UST_GDB_INTEGRATION */
378 /* Macro to insert the address of a relative jump in an assembly stub,
379 * in a relocatable way. On x86-64, this uses a special (%rip) notation. */
380 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__(%%rip)
382 #define _ASM_PTR ".quad "
386 #endif /* UST_PROCESSOR_H */
This page took 0.04736 seconds and 4 git commands to generate.