xref: /openbsd/libexec/ld.so/arm/ldasm.S (revision 3cab2bb3)
1/*	$OpenBSD: ldasm.S,v 1.28 2019/05/10 13:29:21 guenther Exp $ */
2
3/*
4 * Copyright (c) 2004 Dale Rahn
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#define DL_DATA_SIZE	(16 * 4)	/* XXX */
30#include <machine/asm.h>
31#include <sys/syscall.h>
32
33	.section .boot.text,"ax",%progbits
34	_ALIGN_TEXT
35	.globl	_dl_start
36	.type	_dl_start,#function
37_dl_start:
38	mov	fp, sp
39	mov	r5, sp
40	mov	lr, r6				@ save lr
41	sub	sp, sp, #4+4+DL_DATA_SIZE
42	add	r7, sp, #4			@ dl_data
43
44	mov	r0, fp				@ original stack
45	mov	r1, r7				@ dl_data
46
47	ldr	r8, .L_GOT			@ calculate address of GOT...
481:	add	r8, pc, r8			@ into r8
49
50	ldr	r2, .L__DYNAMIC			@ &_DYNAMIC
51	add	r2, r2, r8
52
53	bl	_dl_boot_bind
54
55	add	r0, r5, #4			@ argv
56	ldr	r1, [r5, #0x0]			@ envp
57	add	r1, r1, #2
58	add	r1, fp, r1, lsl #2
59	ldr	r2, [r7, #7*4]			@ loff from dl_data
60	mov	r3, r7				@ dl_data
61	bl	_dl_boot
62
63	mov	sp, fp
64	mov	fp, #0
65	mov	lr, r6
66
67	mov	r1, r0
68	ldr	r0, .L_dl_dtors
69	add	r0, r0, r8
70	mov	pc, r1
71.L_GOT:
72	.long	_GLOBAL_OFFSET_TABLE_-(1b+8)
73.L__DYNAMIC:
74	.long	_DYNAMIC(GOTOFF)
75.L_dl_dtors:
76	.long	_dl_dtors(GOTOFF)
77END(_dl_start)
78
79
80ENTRY(_dl_bind_start)
81	/*
82	 * ip is pointer to got entry for this relocation
83	 * lr is pointer to pltgot[2], which is entry -1 of got plt reloc.
84	 * return address is on stack
85	 */
86	stmdb	sp!, {r0-r4,sl,fp}
87
88	sub	r1, ip, lr		/* r1 = 4 * (n + 1) */
89	sub	r1, r1, #4		/* r1 = 4 * n */
90	mov	r1, r1, lsr #2		/* r1 = n */
91
92	ldr	r0, [lr, #-4]
93	bl	_dl_bind
94	mov	ip, r0
95	ldmia	sp!, {r0-r4,sl,fp,lr}
96	mov	pc, ip
97END(_dl_bind_start)
98