xref: /openbsd/libexec/ld.so/hppa/ldasm.S (revision 09467b48)
1/*	$OpenBSD: ldasm.S,v 1.24 2017/08/27 21:59:52 deraadt Exp $	*/
2
3/*
4 * Copyright (c) 2004 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/syscall.h>
30#include <machine/asm.h>
31#define	_LOCORE
32#include <machine/frame.h>
33#include <machine/vmparam.h>
34#undef	_LOCORE
35
36ENTRY(_dl_start,32)
37	copy	r3, r1
38	copy	sp, r3
39	stwm	r1, HPPA_FRAME_SIZE+16*4(sp)
40
41	stw	%arg0, HPPA_FRAME_ARG(0)(r3)	/* ps_strings */
42
43#define	ADDR(s,r) \
44	bl	4, t1							!\
45	depi	0, 31, 2, t1	/* kill pl bits */			!\
46	b	s		/* cold brunch -- never done */		!\
47	ldw	0(t1), t2	/* cat(w,w1,w2{10},w2{0..9}) << 2 */	!\
48	extru	t2, 28, 10, t3	/* w2{0..9} */				!\
49	extru	t2, 26, 16, r	/* w1 */				!\
50	dep	t3, 31, 11, r						!\
51	extru,=	t2, 31, 1, r0	/* w */					!\
52	depi	1, 15, 1, r						!\
53	extru,=	t2, 29, 1, r0	/* w2{10} */				!\
54	depi	1, 21, 1, r						!\
55	sh2add	r, t1, r	/* plus the base */			!\
56	addi	8, r, r		/* bl target is -8 */
57
58	ADDR(_GLOBAL_OFFSET_TABLE_, r19)
59	ADDR(_DYNAMIC, arg2)
60	stw	arg2, HPPA_FRAME_ARG(1)(r3)
61
62	/* make sure to get a fault until it's set proper */
63	ldi	-1, %dp
64
65	ldw	0(arg0), arg0
66	ldo	4(r3), arg1			/* dl_data */
67	bl	_dl_boot_bind, rp
68	ldo	-4(arg0), arg0
69
70	ldw	HPPA_FRAME_ARG(1)(r3), arg1	/* &_DYNAMIC */
71	ldw	HPPA_FRAME_ARG(0)(r3), arg3	/* ps_strings */
72	ldw	0(r19), arg2
73	sub	arg1, arg2, arg2		/* loff */
74
75	ldw	0(arg3), arg0			/* argv */
76	ldw	8(arg3), arg1			/* envp */
77
78	bl	_dl_boot, rp
79	ldo	4(r3), arg3			/* dl_data */
80
81	ldw	HPPA_FRAME_ARG(0)(r3), arg0	/* ps_strings */
82	ADDR(_hppa_dl_dtors_plabel, arg1)
83	ldw	0(arg1), arg1			/* cleanup */
84
85	ldo	HPPA_FRAME_SIZE(r3), sp
86	copy	r0, rp
87	bv	r0(ret0)
88	ldwm	-HPPA_FRAME_SIZE(sp), r3
89EXIT(_dl_start)
90
91/*
92 * void _hppa_dl_dtors(void);
93 */
94ENTRY(_hppa_dl_dtors,0)
95	ADDR(_GLOBAL_OFFSET_TABLE_, r19)
96	b	_dl_dtors
97	nop
98EXIT(_hppa_dl_dtors)
99
100	.section .data
101	.align 4
102_hppa_dl_dtors_plabel:
103	.word P%_hppa_dl_dtors
104	.previous
105
106LEAF_ENTRY(_hppa_dl_set_dp)
107	bv	r0(rp)
108	copy	arg0, r27
109EXIT(_hppa_dl_set_dp)
110
111/*
112 * This is a magic branch instruction that is used by GCC's
113 * __canonicalize_funcptr_for_compare() function to fixup relocations
114 * in order to do function pointer comparisons.
115 */
116	bl	_dl_bind, rp
117
118ENTRY(_dl_bind_start,32)
119	copy	r3, r1
120	copy	sp, r3
121	stwm	r1, HPPA_FRAME_SIZE(sp)
122
123	stw	rp, HPPA_FRAME_CRP(r3)
124	stw	arg0, HPPA_FRAME_ARG(0)(r3)
125	stw	arg1, HPPA_FRAME_ARG(1)(r3)
126	stw	arg2, HPPA_FRAME_ARG(2)(r3)
127	stw	arg3, HPPA_FRAME_ARG(3)(r3)
128	stw	t1, 4(r3)
129	stw	ret0, 8(r3)
130	stw	ret1, 12(r3)
131
132	ldw	12(r20), arg0
133	copy	r19, arg1
134
135	bl	_dl_bind, rp
136	copy	r21, r19
137
138	copy	ret0, r21	/* &func */
139	copy	ret1, r19	/* sl */
140
141	ldw	HPPA_FRAME_ARG(0)(r3), arg0
142	ldw	HPPA_FRAME_ARG(1)(r3), arg1
143	ldw	HPPA_FRAME_ARG(2)(r3), arg2
144	ldw	HPPA_FRAME_ARG(3)(r3), arg3
145	ldw	4(r3), t1
146	ldw	8(r3), ret0
147	ldw	12(r3), ret1
148
149	ldw	HPPA_FRAME_CRP(r3), rp
150	ldo	HPPA_FRAME_SIZE(r3), sp
151	bv	r0(r21)
152	ldwm	-HPPA_FRAME_SIZE(sp), r3
153EXIT(_dl_bind_start)
154
155	.end
156