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
;
32 static inline save_registers(struct registers
*regs
)
36 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__
38 #define _ASM_PTR ".long "
43 int padding
; /* 4 bytes */
65 #define save_registers(regsptr) \
66 if(ust_reg_stack_ptr == NULL) { \
67 ust_reg_stack_ptr = (long*)((long)ust_reg_stack)+500; \
70 /* save original rsp */ \
72 /* rax will hold the ptr to the private stack bottom */ \
74 /* rbx will be used to temporarily hold the stack bottom addr */ \
76 /* rdi is the input to __tls_get_addr, and also a temp var */ \
78 /* Start TLS access of private reg stack */ \
80 "leaq ust_reg_stack_ptr@tlsgd(%%rip), %%rdi\n\t" \
83 "call __tls_get_addr@plt\n\t" \
84 /* --- End TLS access */ \
85 /* Manually push rsp to private stack */ \
86 "addq $-8,(%%rax)\n\t" \
87 "movq 24(%%rsp), %%rdi\n\t" \
88 "movq (%%rax), %%rbx\n\t" \
89 "movq %%rdi, (%%rbx)\n\t" \
90 /* Manually push rax to private stack */ \
91 "addq $-8,(%%rax)\n\t" \
92 "movq 16(%%rsp), %%rdi\n\t" \
93 "movq (%%rax), %%rbx\n\t" \
94 "movq %%rdi, (%%rbx)\n\t" \
95 /* Manually push rbx to private stack */ \
96 "addq $-8,(%%rax)\n\t" \
97 "movq 8(%%rsp), %%rdi\n\t" \
98 "movq (%%rax), %%rbx\n\t" \
99 "movq %%rdi, (%%rbx)\n\t" \
100 /* Manually push rdi to private stack */ \
101 "addq $-8,(%%rax)\n\t" \
102 "movq 0(%%rsp), %%rdi\n\t" \
103 "movq (%%rax), %%rbx\n\t" \
104 "movq %%rdi, (%%rbx)\n\t" \
105 /* now push regs to tls */ \
106 /* -- rsp already pushed -- */ \
107 /* -- rax already pushed -- */ \
108 /* -- rbx already pushed -- */ \
109 /* -- rdi already pushed -- */ \
110 "addq $-8,(%%rax)\n\t" \
111 "movq (%%rax), %%rbx\n\t" \
112 "movq %%rcx,(%%rbx)\n\t" \
113 "addq $-8,(%%rax)\n\t" \
114 "movq (%%rax), %%rbx\n\t" \
115 "movq %%rdx,(%%rbx)\n\t" \
116 "addq $-8,(%%rax)\n\t" \
117 "movq (%%rax), %%rbx\n\t" \
118 "movq %%rbp,(%%rbx)\n\t" \
119 "addq $-8,(%%rax)\n\t" \
120 "movq (%%rax), %%rbx\n\t" \
121 "movq %%rsi,(%%rbx)\n\t" \
122 "addq $-8,(%%rax)\n\t" \
123 "movq (%%rax), %%rbx\n\t" \
124 "movq %%r8,(%%rbx)\n\t" \
125 "addq $-8,(%%rax)\n\t" \
126 "movq (%%rax), %%rbx\n\t" \
127 "movq %%r9,(%%rbx)\n\t" \
128 "addq $-8,(%%rax)\n\t" \
129 "movq (%%rax), %%rbx\n\t" \
130 "movq %%r10,(%%rbx)\n\t" \
131 "addq $-8,(%%rax)\n\t" \
132 "movq (%%rax), %%rbx\n\t" \
133 "movq %%r11,(%%rbx)\n\t" \
134 "addq $-8,(%%rax)\n\t" \
135 "movq (%%rax), %%rbx\n\t" \
136 "movq %%r12,(%%rbx)\n\t" \
137 "addq $-8,(%%rax)\n\t" \
138 "movq (%%rax), %%rbx\n\t" \
139 "movq %%r13,(%%rbx)\n\t" \
140 "addq $-8,(%%rax)\n\t" \
141 "movq (%%rax), %%rbx\n\t" \
142 "movq %%r14,(%%rbx)\n\t" \
143 "addq $-8,(%%rax)\n\t" \
144 "movq (%%rax), %%rbx\n\t" \
145 "movq %%r15,(%%rbx)\n\t" \
146 /* deal with rflags */ \
147 "pushfq\n\t" /* push rflags on stack */ \
148 "addq $-8,(%%rax)\n\t" \
149 "movq (%%rax), %%rbx\n\t" \
152 "addq $-2,(%%rax)\n\t" \
153 "movq (%%rax), %%rbx\n\t" \
154 "movw %%cs, (%%rbx)\n\t" \
156 "addq $-2,(%%rax)\n\t" \
157 "movq (%%rax), %%rbx\n\t" \
158 "movw %%ss, (%%rbx)\n\t" \
159 /* add padding for struct registers */ \
160 "addq $-4,(%%rax)\n\t" \
161 /* restore original values of regs that were used internally */ \
165 /* cancel push of rsp */ \
166 "addq $8,%%rsp\n\t" \
168 memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
169 ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
171 /* Macro to insert the address of a relative jump in an assembly stub,
172 * in a relocatable way. On x86-64, this uses a special (%rip) notation. */
173 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__(%%rip)
175 #define _ASM_PTR ".quad "
179 #endif /* UST_PROCESSOR_H */
This page took 0.035512 seconds and 6 git commands to generate.