Home | History | Annotate | Line # | Download | only in libunwind
unwind_registers.S revision 1.4
      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.3  joerg 	/* TODO: skip non-callee-safe registers */
    120  1.1  joerg 	stw		 %r0,  0(%r3)
    121  1.1  joerg 	stw		 %r1,  4(%r3)
    122  1.1  joerg 	stw		 %r2,  8(%r3)
    123  1.1  joerg 	stw		 %r3, 12(%r3)
    124  1.1  joerg 	stw		 %r4, 16(%r3)
    125  1.1  joerg 	stw		 %r5, 20(%r3)
    126  1.1  joerg 	stw		 %r6, 24(%r3)
    127  1.1  joerg 	stw		 %r7, 28(%r3)
    128  1.1  joerg 	stw		 %r8, 32(%r3)
    129  1.1  joerg 	stw		 %r9, 36(%r3)
    130  1.1  joerg 	stw		%r10, 40(%r3)
    131  1.1  joerg 	stw		%r11, 44(%r3)
    132  1.1  joerg 	stw		%r12, 48(%r3)
    133  1.1  joerg 	stw		%r13, 52(%r3)
    134  1.1  joerg 	stw		%r14, 56(%r3)
    135  1.1  joerg 	stw		%r15, 60(%r3)
    136  1.1  joerg 	stw		%r16, 64(%r3)
    137  1.1  joerg 	stw		%r17, 68(%r3)
    138  1.1  joerg 	stw		%r18, 72(%r3)
    139  1.1  joerg 	stw		%r19, 76(%r3)
    140  1.1  joerg 	stw		%r20, 80(%r3)
    141  1.1  joerg 	stw		%r21, 84(%r3)
    142  1.1  joerg 	stw		%r22, 88(%r3)
    143  1.1  joerg 	stw		%r23, 92(%r3)
    144  1.1  joerg 	stw		%r24, 96(%r3)
    145  1.1  joerg 	stw		%r25,100(%r3)
    146  1.1  joerg 	stw		%r26,104(%r3)
    147  1.1  joerg 	stw		%r27,108(%r3)
    148  1.1  joerg 	stw		%r28,112(%r3)
    149  1.1  joerg 	stw		%r29,116(%r3)
    150  1.1  joerg 	stw		%r30,120(%r3)
    151  1.1  joerg 	stw		%r31,124(%r3)
    152  1.3  joerg 	mflr		%r0
    153  1.3  joerg 	stw		%r0, 136(%r3) /* SRR0 */
    154  1.3  joerg 	mfcr		%r0
    155  1.3  joerg 	stw		%r0, 132(%r3) /* CR */
    156  1.1  joerg 
    157  1.3  joerg 	stfd		 %f0, 144(%r3)
    158  1.3  joerg 	stfd		 %f1, 152(%r3)
    159  1.3  joerg 	stfd		 %f2, 160(%r3)
    160  1.3  joerg 	stfd		 %f3, 168(%r3)
    161  1.3  joerg 	stfd		 %f4, 176(%r3)
    162  1.3  joerg 	stfd		 %f5, 184(%r3)
    163  1.3  joerg 	stfd		 %f6, 192(%r3)
    164  1.3  joerg 	stfd		 %f7, 200(%r3)
    165  1.3  joerg 	stfd		 %f8, 208(%r3)
    166  1.3  joerg 	stfd		 %f9, 216(%r3)
    167  1.3  joerg 	stfd		%f10, 224(%r3)
    168  1.3  joerg 	stfd		%f11, 232(%r3)
    169  1.3  joerg 	stfd		%f12, 240(%r3)
    170  1.3  joerg 	stfd		%f13, 248(%r3)
    171  1.3  joerg 	stfd		%f14, 256(%r3)
    172  1.3  joerg 	stfd		%f15, 264(%r3)
    173  1.3  joerg 	stfd		%f16, 272(%r3)
    174  1.3  joerg 	stfd		%f17, 280(%r3)
    175  1.3  joerg 	stfd		%f18, 288(%r3)
    176  1.3  joerg 	stfd		%f19, 296(%r3)
    177  1.3  joerg 	stfd		%f20, 304(%r3)
    178  1.3  joerg 	stfd		%f21, 312(%r3)
    179  1.3  joerg 	stfd		%f22, 320(%r3)
    180  1.3  joerg 	stfd		%f23, 328(%r3)
    181  1.3  joerg 	stfd		%f24, 336(%r3)
    182  1.3  joerg 	stfd		%f25, 344(%r3)
    183  1.3  joerg 	stfd		%f26, 352(%r3)
    184  1.3  joerg 	stfd		%f27, 360(%r3)
    185  1.3  joerg 	stfd		%f28, 368(%r3)
    186  1.3  joerg 	stfd		%f29, 376(%r3)
    187  1.3  joerg 	stfd		%f30, 384(%r3)
    188  1.3  joerg 	stfd		%f31, 392(%r3)
    189  1.1  joerg 
    190  1.3  joerg 	/* LR is undefined */
    191  1.1  joerg 	blr
    192  1.1  joerg 
    193  1.1  joerg 	.hidden _ZNK7_Unwind15Registers_ppc326jumptoEv
    194  1.1  joerg ENTRY(_ZNK7_Unwind15Registers_ppc326jumptoEv)
    195  1.3  joerg 	lfd		 %f0, 144(%r3)
    196  1.3  joerg 	lfd		 %f1, 152(%r3)
    197  1.3  joerg 	lfd		 %f2, 160(%r3)
    198  1.3  joerg 	lfd		 %f3, 168(%r3)
    199  1.3  joerg 	lfd		 %f4, 176(%r3)
    200  1.3  joerg 	lfd		 %f5, 184(%r3)
    201  1.3  joerg 	lfd		 %f6, 192(%r3)
    202  1.3  joerg 	lfd		 %f7, 200(%r3)
    203  1.3  joerg 	lfd		 %f8, 208(%r3)
    204  1.3  joerg 	lfd		 %f9, 216(%r3)
    205  1.3  joerg 	lfd		%f10, 224(%r3)
    206  1.3  joerg 	lfd		%f11, 232(%r3)
    207  1.3  joerg 	lfd		%f12, 240(%r3)
    208  1.3  joerg 	lfd		%f13, 248(%r3)
    209  1.3  joerg 	lfd		%f14, 256(%r3)
    210  1.3  joerg 	lfd		%f15, 264(%r3)
    211  1.3  joerg 	lfd		%f16, 272(%r3)
    212  1.3  joerg 	lfd		%f17, 280(%r3)
    213  1.3  joerg 	lfd		%f18, 288(%r3)
    214  1.3  joerg 	lfd		%f19, 296(%r3)
    215  1.3  joerg 	lfd		%f20, 304(%r3)
    216  1.3  joerg 	lfd		%f21, 312(%r3)
    217  1.3  joerg 	lfd		%f22, 320(%r3)
    218  1.3  joerg 	lfd		%f23, 328(%r3)
    219  1.3  joerg 	lfd		%f24, 336(%r3)
    220  1.3  joerg 	lfd		%f25, 344(%r3)
    221  1.3  joerg 	lfd		%f26, 352(%r3)
    222  1.3  joerg 	lfd		%f27, 360(%r3)
    223  1.3  joerg 	lfd		%f28, 368(%r3)
    224  1.3  joerg 	lfd		%f29, 376(%r3)
    225  1.3  joerg 	lfd		%f30, 384(%r3)
    226  1.3  joerg 	lfd		%f31, 392(%r3)
    227  1.3  joerg 
    228  1.1  joerg 	lwz		 %r2, 8(%r3)
    229  1.1  joerg 	/* skip r3 for now */
    230  1.1  joerg 	lwz		 %r4, 16(%r3)
    231  1.1  joerg 	lwz		 %r5, 20(%r3)
    232  1.1  joerg 	lwz		 %r6, 24(%r3)
    233  1.1  joerg 	lwz		 %r7, 28(%r3)
    234  1.1  joerg 	lwz		 %r8, 32(%r3)
    235  1.1  joerg 	lwz		 %r9, 36(%r3)
    236  1.1  joerg 	lwz		%r10, 40(%r3)
    237  1.1  joerg 	lwz		%r11, 44(%r3)
    238  1.1  joerg 	lwz		%r12, 48(%r3)
    239  1.1  joerg 	lwz		%r13, 52(%r3)
    240  1.1  joerg 	lwz		%r14, 56(%r3)
    241  1.1  joerg 	lwz		%r15, 60(%r3)
    242  1.1  joerg 	lwz		%r16, 64(%r3)
    243  1.1  joerg 	lwz		%r17, 68(%r3)
    244  1.1  joerg 	lwz		%r18, 72(%r3)
    245  1.1  joerg 	lwz		%r19, 76(%r3)
    246  1.1  joerg 	lwz		%r20, 80(%r3)
    247  1.1  joerg 	lwz		%r21, 84(%r3)
    248  1.1  joerg 	lwz		%r22, 88(%r3)
    249  1.1  joerg 	lwz		%r23, 92(%r3)
    250  1.1  joerg 	lwz		%r24, 96(%r3)
    251  1.1  joerg 	lwz		%r25,100(%r3)
    252  1.1  joerg 	lwz		%r26,104(%r3)
    253  1.1  joerg 	lwz		%r27,108(%r3)
    254  1.1  joerg 	lwz		%r28,112(%r3)
    255  1.1  joerg 	lwz		%r29,116(%r3)
    256  1.1  joerg 	lwz		%r30,120(%r3)
    257  1.1  joerg 	lwz		%r31,124(%r3)
    258  1.1  joerg 
    259  1.3  joerg 	lwz		%r0, 128(%r3) /* LR */
    260  1.3  joerg 	mtlr		%r0
    261  1.3  joerg 	lwz		%r0, 132(%r3) /* CR */
    262  1.1  joerg 	mtcr		%r0
    263  1.3  joerg 	lwz		%r0, 136(%r3) /* SRR0 */
    264  1.1  joerg 	mtctr		%r0
    265  1.1  joerg 
    266  1.3  joerg 	lwz		%r0,  0(%r3)   /* do r0 now */
    267  1.3  joerg 	lwz		%r1,  4(%r3)   /* do sp now */
    268  1.3  joerg 	lwz		%r3, 12(%r3)   /* do r3 last */
    269  1.1  joerg 	bctr
    270  1.1  joerg #endif
    271  1.2   matt 
    272  1.2   matt #if defined(__arm__) && !defined(__ARM_EABI__)
    273  1.2   matt 	.hidden _ZN7_Unwind15Registers_arm32C1Ev
    274  1.2   matt ENTRY(_ZN7_Unwind15Registers_arm32C1Ev)
    275  1.2   matt 	stmia	r0, {r0-r14}
    276  1.2   matt 
    277  1.2   matt 	str	lr, [r0, #60]	/* PC */
    278  1.2   matt 	mrs	r1, cpsr
    279  1.2   matt 	str	r1, [r0, #64]	/* CPSR */
    280  1.2   matt 
    281  1.2   matt 	RET
    282  1.2   matt END(_ZN7_Unwind15Registers_arm32C1Ev)
    283  1.2   matt 
    284  1.2   matt 	.hidden _ZNK7_Unwind15Registers_arm326jumptoEv
    285  1.2   matt ENTRY(_ZNK7_Unwind15Registers_arm326jumptoEv)
    286  1.2   matt 	ldr	r1, [r0, #64]
    287  1.2   matt 	msr	cpsr_sxc, r1
    288  1.2   matt 	ldmia	r0, {r0-r15}
    289  1.2   matt END(_ZNK7_Unwind15Registers_arm326jumptoEv)
    290  1.2   matt #endif
    291  1.4  joerg 
    292  1.4  joerg #if defined(__vax__)
    293  1.4  joerg 	.hidden _ZN7_Unwind13Registers_vaxC1Ev
    294  1.4  joerg ENTRY(_ZN7_Unwind13Registers_vaxC1Ev, R0)
    295  1.4  joerg 	subl2	$4, %sp
    296  1.4  joerg 	movl	4(%ap), %r0
    297  1.4  joerg 	movl	 %r1,  4(%r0)
    298  1.4  joerg 	movl	 %r2,  8(%r0)
    299  1.4  joerg 	movl	 %r3, 12(%r0)
    300  1.4  joerg 	movl	 %r4, 16(%r0)
    301  1.4  joerg 	movl	 %r5, 20(%r0)
    302  1.4  joerg 	movl	 %r6, 24(%r0)
    303  1.4  joerg 	movl	 %r7, 28(%r0)
    304  1.4  joerg 	movl	 %r8, 32(%r0)
    305  1.4  joerg 	movl	 %r9, 36(%r0)
    306  1.4  joerg 	movl	%r10, 40(%r0)
    307  1.4  joerg 	movl	%r11, 44(%r0)
    308  1.4  joerg 	movl	8(%fp), 48(%r0)
    309  1.4  joerg 	movl	12(%fp), 52(%r0)
    310  1.4  joerg 	/* XXX correct argument handling */
    311  1.4  joerg 	addl3	$36, %r14, 56(%r0)
    312  1.4  joerg 	/* Return PC */
    313  1.4  joerg 	movl	16(%fp), 60(%r0)
    314  1.4  joerg 	/* Load saved value of r0 as r1 */
    315  1.4  joerg 	movl	20(%fp), 0(%r0)
    316  1.4  joerg 	/* Saved PSW */
    317  1.4  joerg 	movl	4(%fp), 64(%r0)
    318  1.4  joerg 	ret
    319  1.4  joerg END(_ZN7_Unwind13Registers_vaxC1Ev)
    320  1.4  joerg 
    321  1.4  joerg 	.hidden _ZNK7_Unwind13Registers_vax6jumptoEv
    322  1.4  joerg ENTRY(_ZNK7_Unwind13Registers_vax6jumptoEv, 0)
    323  1.4  joerg 	subl2	$4, %sp
    324  1.4  joerg 	movl	 4(%ap),  %r0
    325  1.4  joerg 	movl	 4(%r0),  %r1
    326  1.4  joerg 	movl	 8(%r0),  %r2
    327  1.4  joerg 	movl	12(%r0),  %r3
    328  1.4  joerg 	movl	16(%r0),  %r4
    329  1.4  joerg 	movl	20(%r0),  %r5
    330  1.4  joerg 	movl	24(%r0),  %r6
    331  1.4  joerg 	movl	28(%r0),  %r7
    332  1.4  joerg 	movl	32(%r0),  %r8
    333  1.4  joerg 	movl	36(%r0),  %r9
    334  1.4  joerg 	movl	40(%r0), %r10
    335  1.4  joerg 	movl	44(%r0), %r11
    336  1.4  joerg 	movl	48(%r0), %r12
    337  1.4  joerg 	movl	52(%r0), %r13
    338  1.4  joerg 	movl	56(%r0), %r14
    339  1.4  joerg 	movl	60(%r0), -(%sp)
    340  1.4  joerg 	movl	0(%r0), %r0
    341  1.4  joerg 	/* XXX restore PSW */
    342  1.4  joerg 	rsb
    343  1.4  joerg 
    344  1.4  joerg END(_ZNK7_Unwind13Registers_vax6jumptoEv)
    345  1.4  joerg #endif
    346