xref: /openbsd/libexec/ld.so/sh/ldasm.S (revision 09467b48)
1/*	$OpenBSD: ldasm.S,v 1.30 2017/08/28 14:06:22 deraadt Exp $ */
2
3/*
4 * Copyright (c) 2006 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
33ENTRY(_dl_start)
34	mov	r15, r12		// save for later
35	mov	r15, r4			// sp
36	add	#-(4+4+DL_DATA_SIZE), r15
37	mov	r15, r5			// dl_data
38	bsr	1f
39	 nop
401:
41.L_offbase:
42	sts	pr, r0
43	mov.l	.L_dynamic, r6
44	add	r0, r6			// DYNAMIC
45	mov.l	.L_boot_bind, r0
46	bsrf	r0			// boot_bind(sp, dl_data, DYNAMIC)
47	 nop
48.L_call_boot_bind:
49	mov	r12, r4
50	add	#4, r4			// argv
51	mov.l	@r12, r5
52	add	#2, r5
53	shll2	r5
54	add	r12, r5			// envp
55	mov	r15, r7			// dl_data
56	mov	r7, r6
57	add	#(7*4), r6
58	mov.l	@r6, r6			// dl_data[AUX_base] == loff
59
60	mov.l	.L_boot, r0
61	bsrf	r0			// _dl_boot(argv, envp, loff, dl_data)
62	 nop
63.L_call_boot:
64	mov	r12, r15
65	mov.l	@r15, r4		// argc
66	mov	r15, r5
67	add	#4, r5			// argv
68
69	mov	r4, r6
70	add	#1, r6
71	shll2	r6
72	add	r5, r6			// envp
73
74	mov	r0, r12
75	mova	.L_GOT, r0
76	mov.l	.L_GOT, r7
77	add	r7, r0			// GOT
78	mov.l	.L_dl_dtors, r7
79	jmp	@r12
80	 mov.l	@(r0,r7), r7		// cleanup
81
82	.align 2
83.L_boot_bind:
84	.long _dl_boot_bind-.L_call_boot_bind
85.L_boot:
86	.long _dl_boot-.L_call_boot
87.L_dynamic:
88	.long _DYNAMIC-.L_offbase
89.L_GOT:
90	.long _GLOBAL_OFFSET_TABLE_
91.L_dl_dtors:
92	.long _dl_dtors@GOT
93	.size _dl_start, .-dl_start
94
95
96/*
97 * r0 - obj
98 * r1 - reloff
99 */
100
101ENTRY(_dl_bind_start)
102	mov.l	r2, @-r15
103	mov.l	r3, @-r15
104	mov.l	r4, @-r15
105	mov.l	r5, @-r15
106	mov.l	r6, @-r15
107	mov.l	r7, @-r15
108	sts.l	pr, @-r15
109	sts.l	macl, @-r15
110	sts.l	mach, @-r15
111
112	mov	r0, r4	 /* move obj to 'C' arg */
113	mov.l	.L_dl_bind, r0
114	bsrf r0
115	 mov r1, r5	 /* move reloff to 'C' arg */
116.L_call_dl_bind:
117
118	lds.l	@r15+, mach
119	lds.l	@r15+, macl
120	lds.l	@r15+, pr
121	mov.l	@r15+, r7
122	mov.l	@r15+, r6
123	mov.l	@r15+, r5
124	mov.l	@r15+, r4
125	mov.l	@r15+, r3
126	jmp	@r0		/* jump to specified address */
127	 mov.l	@r15+, r2
128
129	.align 2
130.L_dl_bind:
131	.long	_dl_bind-.L_call_dl_bind
132	.size _dl_bind_start, .-dl_bind_start
133