xref: /openbsd/libexec/ld.so/hppa/ldasm.S (revision d857960c)
1/*	$OpenBSD: ldasm.S,v 1.26 2023/01/09 13:52:42 kettenis 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
36	.import	$global$, data
37
38ENTRY(_dl_start,32)
39	copy	r3, r1
40	copy	sp, r3
41	stwm	r1, HPPA_FRAME_SIZE+16*4(sp)
42
43	stw	arg0, HPPA_FRAME_ARG(0)(r3)	/* ps_strings */
44
45	bl	1f, r19
46	depi	0, 31, 2, r19
471:	addil	L'$global$ - ($PIC_pcrel$0 - 8), r19
48	ldo	R'$global$ - ($PIC_pcrel$0 - 12)(r1), r19
49	bl	1f, arg2
50	depi	0, 31, 2, arg2
511:	addil	L'_DYNAMIC - ($PIC_pcrel$0 - 8), arg2
52	ldo	R'_DYNAMIC - ($PIC_pcrel$0 - 12)(r1), arg2
53	stw	arg2, HPPA_FRAME_ARG(1)(r3)
54
55	/* make sure to get a fault until it's set proper */
56	ldi	-1, dp
57
58	ldw	0(arg0), arg0
59	ldo	4(r3), arg1			/* dl_data */
60	bl	_dl_boot_bind, rp
61	ldo	-4(arg0), arg0
62
63	ldw	HPPA_FRAME_ARG(1)(r3), arg1	/* &_DYNAMIC */
64	ldw	HPPA_FRAME_ARG(0)(r3), arg3	/* ps_strings */
65	ldw	0(r19), arg2
66	sub	arg1, arg2, arg2		/* loff */
67
68	ldw	0(arg3), arg0			/* argv */
69	ldw	8(arg3), arg1			/* envp */
70
71	bl	_dl_boot, rp
72	ldo	4(r3), arg3			/* dl_data */
73
74	ldw	HPPA_FRAME_ARG(0)(r3), arg0	/* ps_strings */
75	addil	LT'_dl_dtors_plabel, r19
76	ldw	RT'_dl_dtors_plabel(r1), arg1
77	ldw	0(arg1), arg1			/* cleanup */
78
79	ldo	HPPA_FRAME_SIZE(r3), sp
80	copy	r0, rp
81	bv	r0(ret0)
82	ldwm	-HPPA_FRAME_SIZE(sp), r3
83EXIT(_dl_start)
84
85	.section .data
86	.align 4
87_dl_dtors_plabel:
88	.word P%_dl_dtors
89	.previous
90
91LEAF_ENTRY(_hppa_dl_set_dp)
92	bv	r0(rp)
93	copy	arg0, r27
94EXIT(_hppa_dl_set_dp)
95
96/*
97 * This is a magic branch instruction that is used by GCC's
98 * __canonicalize_funcptr_for_compare() function to fixup relocations
99 * in order to do function pointer comparisons.
100 */
101	b	_dl_bind
102
103ENTRY(_dl_bind_start,32)
104	copy	r3, r1
105	copy	sp, r3
106	stwm	r1, HPPA_FRAME_SIZE(sp)
107
108	stw	rp, HPPA_FRAME_CRP(r3)
109	stw	arg0, HPPA_FRAME_ARG(0)(r3)
110	stw	arg1, HPPA_FRAME_ARG(1)(r3)
111	stw	arg2, HPPA_FRAME_ARG(2)(r3)
112	stw	arg3, HPPA_FRAME_ARG(3)(r3)
113	stw	t1, 4(r3)
114	stw	ret0, 8(r3)
115	stw	ret1, 12(r3)
116
117	ldw	12(r20), arg0
118	copy	r19, arg1
119
120	bl	_dl_bind, rp
121	copy	r21, r19
122
123	copy	ret0, r21	/* &func */
124	copy	ret1, r19	/* sl */
125
126	ldw	HPPA_FRAME_ARG(0)(r3), arg0
127	ldw	HPPA_FRAME_ARG(1)(r3), arg1
128	ldw	HPPA_FRAME_ARG(2)(r3), arg2
129	ldw	HPPA_FRAME_ARG(3)(r3), arg3
130	ldw	4(r3), t1
131	ldw	8(r3), ret0
132	ldw	12(r3), ret1
133
134	ldw	HPPA_FRAME_CRP(r3), rp
135	ldo	HPPA_FRAME_SIZE(r3), sp
136	bv	r0(r21)
137	ldwm	-HPPA_FRAME_SIZE(sp), r3
138EXIT(_dl_bind_start)
139
140	.end
141