xref: /openbsd/libexec/ld.so/powerpc/ldasm.S (revision 4bdff4be)
1/*	$OpenBSD: ldasm.S,v 1.34 2019/07/01 15:57:34 kettenis Exp $ */
2
3/*
4 * Copyright (c) 1999 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 AUX_entry 9
30
31#include <machine/asm.h>
32#include <sys/syscall.h>
33
34	.section .boot.text,"ax",@progbits
35	.align	2
36	.globl	_dl_start
37	.type	_dl_start,@function
38_dl_start:
39	mr	19, 1
40	stwu	1, (-16 -((AUX_entry+3)*4))(1)	# Some space.
41
42	mflr	27		/* save off old link register */
43	stw	27, 4(19)	/* save in normal location */
44
45	# squirrel away the arguments for main
46	mr	20, 3	#argc
47	mr	21, 4	#argv
48	mr	22, 5	#envp
49	mr	23, 6	# ???
50
51	bcl	20, 31, 1f
521:	mflr	30
53	addis	30, 30, _GLOBAL_OFFSET_TABLE_-1b@ha
54	addi	30, 30, _GLOBAL_OFFSET_TABLE_-1b@l
55
56	bcl	20, 31, 1f
571:	mflr	18
58	addis	18, 18, _DYNAMIC-1b@ha
59	addi	18, 18, _DYNAMIC-1b@l
60	lwz	4, 0(30)	# load address of _DYNAMIC according to got.
61	sub	4, 18, 4	# determine load offset
62
63	mr	17, 4		# save for _dl_boot
64
65	subi	3, 21, 4	# Get stack pointer (arg0 for _dl_boot).
66	addi	4, 1, 8		# dl_data
67	mr	5, 18		# dynamicp
68
69	bl	_dl_boot_bind@local
70
71	mr	3, 21		# argv
72	mr	4, 22		# envp
73	mr	5, 17		# loff
74	addi	6, 1, 8		# dl_data
75
76	bl	_dl_boot@local
77
78	mtctr	3		# put return value into ctr to execute
79
80	# get back the squirreled away the arguments for main
81	mr	3, 20
82	mr	4, 21
83	mr	5, 22
84	mr	6, 23
85
86	lwz	7, _dl_dtors@got(30)
87
88	mtlr	27
89	lwz	1, 0(1)		# Restore stack pointer.
90	bctr			# Go execute the 'real' program.
91END(_dl_start)
92
93ENTRY(_dl_bind_start)
94	stwu	1,-72(1)
95
96	stw	0,8(1)		# save r0 - cerror ;-)
97	mflr	0
98	stw	0,68(1)		# save	lr
99
100	stw	3,12(1)		# save	r3-r10, C calling convention
101	stw	4,20(1)		# r13 - r31 are preserved by called code
102	stw	5,24(1)
103	stw	6,28(1)
104	stw	7,32(1)
105	stw	8,36(1)
106	stw	9,40(1)
107	stw	10,44(1)
108
109	mr	3,12		# obj
110	mr	4,11		# reloff
111	bl	_dl_bind@plt	#	_rtld_bind(obj,	reloff)
112	mtctr	3
113
114	lwz	3,12(1)
115	lwz	4,20(1)
116	lwz	5,24(1)
117	lwz	6,28(1)
118	lwz	7,32(1)
119	lwz	8,36(1)
120	lwz	9,40(1)
121	lwz	10,44(1)
122
123	lwz	0,68(1)		# restore lr
124	mtlr	0
125	lwz	0,8(1)
126
127	addi	1,1,72
128	bctr
129END(_dl_bind_start)
130