summaryrefslogtreecommitdiff
path: root/libexec/ld.so/sh/ldasm.S
blob: 09c11e6825d11b18cc4a6c76efa31f847a0bbf66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*	$OpenBSD: ldasm.S,v 1.10 2013/04/05 12:58:03 kurt Exp $ */

/*
 * Copyright (c) 2006 Dale Rahn
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#define DL_DATA_SIZE	(16 * 4)	/* XXX */
#include <machine/asm.h>
#include <sys/syscall.h>
#include <SYS.h>

ENTRY(_dl_start)
	mov	r15, r12			// save for later 
	sts	pr, r11
	mov	r15, r4			// boot_bind(sp, dl_data) (sp)
	mov.l	.L_datasize, r0
	sub	r0, r15
	mov	r15, r5
	mov	r5, r13
	// not trusting register to store the data, push it on the stack.
	// callee/caller save questions

	mov	r15, r14

	bsr	1f
	 nop
1:
.L_offbase:
	sts	pr, r0
	mov.l	.L_dynamic, r6
	add	r0, r6
	mov	 r14, r15
	mov	r15, r14
	mov.l	.L_boot_bind, r0
	bsrf	r0
	 nop
.L_call_boot_bind:
	mov	r12, r4
	add	#4, r4
	mov.l	@r12, r5		//loads argc
	add	#2, r5
	shll2	r5
	add	r12, r5			// calc argv 

	mov	r13, r7
	mov	r7, r6
	mov.l	.L_loff, r0
	add	r0, r6
	mov.l	@r6, r6

	mov.l	.L_boot, r0
	bsrf	r0
	 nop
.L_call_boot:

	mov	r12, r15
	lds	r11, pr
	mov.l	@r15, r4
	mov	r15, r5
	add	#4, r5

	mov	r4, r6
	add	#1, r6
	shll2	r6
	add	r5, r6			// calc envp
	jmp	@r0
	 mov	#0, r7

	.align 2
.L_boot_bind:
	.long _dl_boot_bind-.L_call_boot_bind
.L_boot:
	.long _dl_boot-.L_call_boot
.L_datasize:
	.long 4+4+DL_DATA_SIZE
.L_dynamic:
	.long _DYNAMIC-.L_offbase
.L_loff:
	.long 7*4
	.size _dl_start, .-dl_start


/*
 * r0 - obj
 * r1 - reloff
 */

ENTRY(_dl_bind_start)
	mov.l	r2, @-r15
	mov.l	r3, @-r15
	mov.l	r4, @-r15
	mov.l	r5, @-r15
	mov.l	r6, @-r15
	mov.l	r7, @-r15
	sts.l	pr, @-r15
	sts.l	macl, @-r15
	sts.l	mach, @-r15

	mov	r0, r4	 /* move obj to 'C' arg */
	mov.l	.L_dl_bind, r0
	bsrf r0
	 mov r1, r5	 /* move reloff to 'C' arg */
.L_call_dl_bind:

	lds.l	@r15+, mach
	lds.l	@r15+, macl
	lds.l	@r15+, pr
	mov.l	@r15+, r7
	mov.l	@r15+, r6
	mov.l	@r15+, r5
	mov.l	@r15+, r4
	mov.l	@r15+, r3
	jmp	@r0		/* jump to specified address */
	 mov.l	@r15+, r2

	.align 2
.L_dl_bind:
	.long	_dl_bind-.L_call_dl_bind
	.size _dl_bind_start, .-dl_bind_start


	/* STUB */


/* ld.so SYSCALLS */

#define DL_SYSCALL(n) DL_SYSCALL2(n,n)
#define DL_SYSCALL2(n,c)				\
	.global		__CONCAT(_dl_,n)		;\
	.type		__CONCAT(_dl_,n)%function	;\
__CONCAT(_dl_,n):					;\
	SYSTRAP(c)					;\
	bf	.L_cerr					;\
	 nop						;\
	rts						;\
	 nop

#define DL_SYSCALL2_NOERR(n,c)				\
	.global		__CONCAT(_dl_,n)		;\
	.type		__CONCAT(_dl_,n)%function	;\
__CONCAT(_dl_,n):					;\
	SYSTRAP(c)					;\
	rts						;\
	 nop


	.section	".text"
	.align		4
DL_SYSCALL(close)


	.global		_dl_exit
	.type		_dl_exit%function
_dl_exit:
	SYSTRAP(exit)
1:
	bra 1b
	 nop

DL_SYSCALL(issetugid)
DL_SYSCALL2(_syscall,__syscall)
DL_SYSCALL(munmap)
DL_SYSCALL(mprotect)
DL_SYSCALL(open)
DL_SYSCALL(read)

.L_cerr:
	mov	#-1, r0 
	rts
	 nop

DL_SYSCALL(write)
DL_SYSCALL(fstat)
DL_SYSCALL(fcntl)
DL_SYSCALL(gettimeofday)
DL_SYSCALL(readlink)
DL_SYSCALL(lstat)
DL_SYSCALL2(getcwd,__getcwd)
DL_SYSCALL2(sysctl,__sysctl)

DL_SYSCALL(getdirentries)

	.global		_dl_sigprocmask
	.type		_dl_sigprocmask%function
_dl_sigprocmask:
	mov	r5, r2			/* fetch new sigset pointer */
	tst	r2, r2			/* check new sigset pointer */
	bf	1f			/* if not null, indirect */
	 mov	#1, r4			/* SIG_BLOCK */
	bra	2f
	 nop
1:	mov.l	@r2, r2			/* fetch indirect ... */
	mov	r2, r5			/* to new mask arg */
2:	mov.l	LSYS_sigprocmask, r0
	trapa	#0x80
	bf	.L_cerr
	 mov	r6, r2			/* fetch old mask requested */
	tst	r2, r2			/* test if old mask requested */
	bt	out
	 mov.l	r0, @r2			/* store old mask */
out:
	xor	r0, r0
	rts
	 nop

	.align	2
LSYS_sigprocmask:
	.long	SYS_sigprocmask