1/*	$NetBSD: rtld_start.S,v 1.4 1999/03/28 11:56:51 simonb Exp $	*/
2
3/*
4 * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
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 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <mips/asm.h>
31
32LEAF(rtld_start)
33	.set	noreorder
34
35	.cpload t9
36	addu	sp, sp, -12		# adjust stack pointer
37	.cprestore 0			# -> 0(sp) for gp
38					# -> 4(sp) for atexit
39					# -> 8(sp) for obj_main
40	move	s0,a0			# save stack pointer from a0
41	addu	a0, sp, 4		# _rtld argument
42	move	s1,a3			# save ps_strings pointer
43	jal	_C_LABEL(_rtld)		# v0 = _rtld(sp)
44	nop				# [BD if jal not expanded]
45	lw	a1, 4(sp)		# our atexit function
46	lw	a2, 8(sp)		# obj_main entry
47	addu	sp, sp,12		# readjust stack
48	move	a0,s0			# stack pointer
49	move	t9,v0
50	jr	t9			# _start(sp, cleanup, obj);
51	move	a3,s1			# restore ps_strings
52
53END(rtld_start)
54
55	.globl	_rtld_bind_start
56	.ent	_rtld_bind_start
57_rtld_bind_start:
58
59	move	v1,gp			# save old GP
60	add	t9,8			# modify T9 to point at .cpload
61	.cpload	t9
62	subu	sp,40			# save arguments and sp value in stack
63	.cprestore 32
64	sw	t7,36(sp)
65	sw	a0,12(sp)
66	sw	a1,16(sp)
67	sw	a2,20(sp)
68	sw	a3,24(sp)
69	sw	s0,28(sp)
70	move	s0,sp
71	move	a0,t8			# symbol index
72	move	a1,t7			# old RA
73	move	a2,v1			# old GP
74	move	a3,ra			# current RA
75	jal	_C_LABEL(_rtld_bind_mips)
76	nop
77	move	sp,s0
78	lw	ra,36(sp)
79	lw	a0,12(sp)
80	lw	a1,16(sp)
81	lw	a2,20(sp)
82	lw	a3,24(sp)
83	lw	s0,28(sp)
84	addu	sp,40
85	move	t9,v0
86	jr	t9
87	nop
88	.end	_rtld_bind_start
89