unwind_registers.S revision 1.1 1 1.1 joerg //===------------------------- unwind_registers.S -------------------------===//
2 1.1 joerg //
3 1.1 joerg // The LLVM Compiler Infrastructure
4 1.1 joerg //
5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open
6 1.1 joerg // Source Licenses. See LICENSE.TXT for details.
7 1.1 joerg //
8 1.1 joerg //
9 1.1 joerg // Abstracts accessing local vs remote address spaces.
10 1.1 joerg //
11 1.1 joerg //===----------------------------------------------------------------------===//
12 1.1 joerg #include <machine/asm.h>
13 1.1 joerg
14 1.1 joerg #ifdef __i386__
15 1.1 joerg .hidden _ZN7_Unwind13Registers_x86C1Ev
16 1.1 joerg ENTRY(_ZN7_Unwind13Registers_x86C1Ev)
17 1.1 joerg pushl %eax
18 1.1 joerg movl 8(%esp), %eax /* Load this */
19 1.1 joerg /* Save all registers except EAX, EIP and ESP */
20 1.1 joerg /* Skip ECX */
21 1.1 joerg /* Skip EDX */
22 1.1 joerg movl %ebx, 12(%eax)
23 1.1 joerg movl %ebp, 20(%eax)
24 1.1 joerg movl %esi, 24(%eax)
25 1.1 joerg movl %edi, 28(%eax)
26 1.1 joerg
27 1.1 joerg leal 8(%esp), %edx /* Compute ESP from the call site */
28 1.1 joerg movl %edx, 16(%eax) /* ...and store it as ESP */
29 1.1 joerg movl 4(%esp), %edx /* Load return address */
30 1.1 joerg movl %edx, 32(%eax) /* ...and store it as EIP */
31 1.1 joerg popl %edx /* Take old EAX from stack */
32 1.1 joerg movl %edx, 0(%eax) /* ...and store it */ // XXX skip
33 1.1 joerg ret
34 1.1 joerg
35 1.1 joerg .hidden _ZNK7_Unwind13Registers_x866jumptoEv
36 1.1 joerg ENTRY(_ZNK7_Unwind13Registers_x866jumptoEv)
37 1.1 joerg movl 4(%esp), %eax /* Load this */
38 1.1 joerg movl 16(%eax), %edx /* Load new stack pointer */
39 1.1 joerg subl $4, %edx /* Reserve space on new stack for EIP */
40 1.1 joerg movl 32(%eax), %ebx /* Load new EIP */
41 1.1 joerg movl %ebx, 0(%edx) /* ...and save it on the new stack */
42 1.1 joerg pushl %edx /* Save new stack pointer on old stack */
43 1.1 joerg /* New stack is prepared, now restore all registers except ESP */
44 1.1 joerg /* EAX is the index register and must be restored last */
45 1.1 joerg movl 4(%eax), %ecx
46 1.1 joerg movl 8(%eax), %edx
47 1.1 joerg movl 12(%eax), %ebx
48 1.1 joerg movl 20(%eax), %ebp
49 1.1 joerg /* 16 is ESP */
50 1.1 joerg movl 24(%eax), %esi
51 1.1 joerg movl 28(%eax), %edi
52 1.1 joerg movl 0(%eax), %eax
53 1.1 joerg /* Now load new stack pointer pushed on the old stack earlier */
54 1.1 joerg popl %esp
55 1.1 joerg /* Return address is already on the new stack. */
56 1.1 joerg ret
57 1.1 joerg #endif
58 1.1 joerg
59 1.1 joerg #ifdef __x86_64
60 1.1 joerg .hidden _ZN7_Unwind16Registers_x86_64C1Ev
61 1.1 joerg ENTRY(_ZN7_Unwind16Registers_x86_64C1Ev)
62 1.1 joerg /* RDI == this */
63 1.1 joerg /* Skip RAX */
64 1.1 joerg /* Skip RDX */
65 1.1 joerg /* Skip RCX */
66 1.1 joerg movq %rbx, 24(%rdi)
67 1.1 joerg /* Skip RSI */
68 1.1 joerg /* Skip RDI */
69 1.1 joerg movq %rbp, 48(%rdi)
70 1.1 joerg leaq 8(%rsp), %rax
71 1.1 joerg movq %rax, 56(%rdi)
72 1.1 joerg /* Skip R8 */
73 1.1 joerg /* Skip R9 */
74 1.1 joerg /* Skip R10 */
75 1.1 joerg /* Skip R11 */
76 1.1 joerg movq %r12, 96(%rdi)
77 1.1 joerg movq %r13, 104(%rdi)
78 1.1 joerg movq %r14, 112(%rdi)
79 1.1 joerg movq %r15, 120(%rdi)
80 1.1 joerg movq (%rsp), %rax
81 1.1 joerg movq %rax, 128(%rdi)
82 1.1 joerg ret
83 1.1 joerg
84 1.1 joerg .hidden _ZNK7_Unwind16Registers_x86_646jumptoEv
85 1.1 joerg ENTRY(_ZNK7_Unwind16Registers_x86_646jumptoEv)
86 1.1 joerg /* RDI == this */
87 1.1 joerg movq 56(%rdi), %rax
88 1.1 joerg subq $8, %rax /* Reserve space on new stack for RIP */
89 1.1 joerg movq 128(%rdi), %rbx /* Load new RIP */
90 1.1 joerg movq %rbx, 0(%rax) /* ...and save it on the new stack */
91 1.1 joerg pushq %rax /* Save new stack pointer on old stack */
92 1.1 joerg /* New stack is prepared, now restore all registers */
93 1.1 joerg movq 0(%rdi), %rax
94 1.1 joerg movq 8(%rdi), %rdx
95 1.1 joerg movq 16(%rdi), %rcx
96 1.1 joerg movq 24(%rdi), %rbx
97 1.1 joerg movq 32(%rdi), %rsi
98 1.1 joerg /* RDI restored later as it is still used as index register */
99 1.1 joerg movq 48(%rdi), %rbp
100 1.1 joerg /* RSP is restored later */
101 1.1 joerg movq 64(%rdi), %r8
102 1.1 joerg movq 72(%rdi), %r9
103 1.1 joerg movq 80(%rdi), %r10
104 1.1 joerg movq 88(%rdi), %r11
105 1.1 joerg movq 96(%rdi), %r12
106 1.1 joerg movq 104(%rdi), %r13
107 1.1 joerg movq 112(%rdi), %r14
108 1.1 joerg movq 120(%rdi), %r15
109 1.1 joerg movq 40(%rdi), %rdi
110 1.1 joerg /* Now load new stack pointer pushed on the old stack earlier */
111 1.1 joerg popq %rsp
112 1.1 joerg /* Return address is already on the new stack. */
113 1.1 joerg ret
114 1.1 joerg #endif
115 1.1 joerg
116 1.1 joerg #ifdef __powerpc__
117 1.1 joerg .hidden _ZN7_Unwind15Registers_ppc32C1Ev
118 1.1 joerg ENTRY(_ZN7_Unwind15Registers_ppc32C1Ev)
119 1.1 joerg stw %r0, 0(%r3)
120 1.1 joerg stw %r1, 4(%r3)
121 1.1 joerg stw %r2, 8(%r3)
122 1.1 joerg stw %r3, 12(%r3)
123 1.1 joerg stw %r4, 16(%r3)
124 1.1 joerg stw %r5, 20(%r3)
125 1.1 joerg stw %r6, 24(%r3)
126 1.1 joerg stw %r7, 28(%r3)
127 1.1 joerg stw %r8, 32(%r3)
128 1.1 joerg stw %r9, 36(%r3)
129 1.1 joerg stw %r10, 40(%r3)
130 1.1 joerg stw %r11, 44(%r3)
131 1.1 joerg stw %r12, 48(%r3)
132 1.1 joerg stw %r13, 52(%r3)
133 1.1 joerg stw %r14, 56(%r3)
134 1.1 joerg stw %r15, 60(%r3)
135 1.1 joerg stw %r16, 64(%r3)
136 1.1 joerg stw %r17, 68(%r3)
137 1.1 joerg stw %r18, 72(%r3)
138 1.1 joerg stw %r19, 76(%r3)
139 1.1 joerg stw %r20, 80(%r3)
140 1.1 joerg stw %r21, 84(%r3)
141 1.1 joerg stw %r22, 88(%r3)
142 1.1 joerg stw %r23, 92(%r3)
143 1.1 joerg stw %r24, 96(%r3)
144 1.1 joerg stw %r25,100(%r3)
145 1.1 joerg stw %r26,104(%r3)
146 1.1 joerg stw %r27,108(%r3)
147 1.1 joerg stw %r28,112(%r3)
148 1.1 joerg stw %r29,116(%r3)
149 1.1 joerg stw %r30,120(%r3)
150 1.1 joerg stw %r31,124(%r3)
151 1.1 joerg
152 1.1 joerg mfcr %r0
153 1.1 joerg stw %r0, 128(%r3) /* CR */
154 1.1 joerg mflr %r0
155 1.1 joerg stw %r0, 132(%r3) /* LR */
156 1.1 joerg stw %r0, 144(%r3) /* LR */
157 1.1 joerg mfctr %r0
158 1.1 joerg stw %r0, 136(%r3) /* CTR */
159 1.1 joerg mfxer %r0
160 1.1 joerg stw %r0, 140(%r3) /* XER */
161 1.1 joerg
162 1.1 joerg blr
163 1.1 joerg
164 1.1 joerg .hidden _ZNK7_Unwind15Registers_ppc326jumptoEv
165 1.1 joerg ENTRY(_ZNK7_Unwind15Registers_ppc326jumptoEv)
166 1.1 joerg lwz %r2, 8(%r3)
167 1.1 joerg /* skip r3 for now */
168 1.1 joerg lwz %r4, 16(%r3)
169 1.1 joerg lwz %r5, 20(%r3)
170 1.1 joerg lwz %r6, 24(%r3)
171 1.1 joerg lwz %r7, 28(%r3)
172 1.1 joerg lwz %r8, 32(%r3)
173 1.1 joerg lwz %r9, 36(%r3)
174 1.1 joerg lwz %r10, 40(%r3)
175 1.1 joerg lwz %r11, 44(%r3)
176 1.1 joerg lwz %r12, 48(%r3)
177 1.1 joerg lwz %r13, 52(%r3)
178 1.1 joerg lwz %r14, 56(%r3)
179 1.1 joerg lwz %r15, 60(%r3)
180 1.1 joerg lwz %r16, 64(%r3)
181 1.1 joerg lwz %r17, 68(%r3)
182 1.1 joerg lwz %r18, 72(%r3)
183 1.1 joerg lwz %r19, 76(%r3)
184 1.1 joerg lwz %r20, 80(%r3)
185 1.1 joerg lwz %r21, 84(%r3)
186 1.1 joerg lwz %r22, 88(%r3)
187 1.1 joerg lwz %r23, 92(%r3)
188 1.1 joerg lwz %r24, 96(%r3)
189 1.1 joerg lwz %r25,100(%r3)
190 1.1 joerg lwz %r26,104(%r3)
191 1.1 joerg lwz %r27,108(%r3)
192 1.1 joerg lwz %r28,112(%r3)
193 1.1 joerg lwz %r29,116(%r3)
194 1.1 joerg lwz %r30,120(%r3)
195 1.1 joerg lwz %r31,124(%r3)
196 1.1 joerg
197 1.1 joerg lwz %r0, 128(%r3) /* CR */
198 1.1 joerg mtcr %r0
199 1.1 joerg lwz %r0, 132(%r3) /* LR */
200 1.1 joerg mtlr %r0
201 1.1 joerg lwz %r0, 136(%r3) /* CTR */
202 1.1 joerg mtctr %r0
203 1.1 joerg lwz %r0, 140(%r3) /* XER */
204 1.1 joerg mtxer %r0
205 1.1 joerg lwz %r0, 144(%r3) /* SRR0 ? */
206 1.1 joerg mtctr %r0
207 1.1 joerg
208 1.1 joerg lwz %r0, 0(%r3) /* do r0 now */
209 1.1 joerg lwz %r1,4(%r3) /* do sp now */
210 1.1 joerg lwz %r3,12(%r3) /* do r3 last */
211 1.1 joerg bctr
212 1.1 joerg #endif
213