rtld_start.S revision 1.5 1 1.5 mycroft /* $NetBSD: rtld_start.S,v 1.5 2002/09/12 17:08:32 mycroft Exp $ */
2 1.1 mhitch
3 1.1 mhitch /*
4 1.1 mhitch * Copyright 1997 Michael L. Hitch <mhitch (at) montana.edu>
5 1.1 mhitch * All rights reserved.
6 1.1 mhitch *
7 1.1 mhitch * Redistribution and use in source and binary forms, with or without
8 1.1 mhitch * modification, are permitted provided that the following conditions
9 1.1 mhitch * are met:
10 1.1 mhitch * 1. Redistributions of source code must retain the above copyright
11 1.1 mhitch * notice, this list of conditions and the following disclaimer.
12 1.1 mhitch * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mhitch * notice, this list of conditions and the following disclaimer in the
14 1.1 mhitch * documentation and/or other materials provided with the distribution.
15 1.1 mhitch * 3. The name of the author may not be used to endorse or promote products
16 1.1 mhitch * derived from this software without specific prior written permission.
17 1.1 mhitch *
18 1.1 mhitch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mhitch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mhitch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mhitch * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mhitch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 mhitch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 mhitch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 mhitch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 mhitch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 mhitch * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 mhitch */
29 1.1 mhitch
30 1.1 mhitch #include <mips/asm.h>
31 1.1 mhitch
32 1.5 mycroft .globl _C_LABEL(_rtld_relocate_nonplt_self)
33 1.5 mycroft .globl _C_LABEL(_rtld)
34 1.5 mycroft
35 1.1 mhitch LEAF(rtld_start)
36 1.1 mhitch .set noreorder
37 1.1 mhitch
38 1.1 mhitch .cpload t9
39 1.1 mhitch addu sp, sp, -12 # adjust stack pointer
40 1.3 castor .cprestore 0 # -> 0(sp) for gp
41 1.3 castor # -> 4(sp) for atexit
42 1.3 castor # -> 8(sp) for obj_main
43 1.1 mhitch move s0,a0 # save stack pointer from a0
44 1.2 mhitch move s1,a3 # save ps_strings pointer
45 1.5 mycroft
46 1.5 mycroft la a1, 1f
47 1.5 mycroft bal 1f
48 1.5 mycroft la t9,_C_LABEL(_rtld_relocate_nonplt_self)
49 1.5 mycroft 1: subu a1, ra, a1 # relocbase
50 1.5 mycroft move s2,a1
51 1.5 mycroft la a0,_DYNAMIC
52 1.5 mycroft addu t9, a1, t9
53 1.5 mycroft jalr t9
54 1.5 mycroft addu a0, a1, a0 # &_DYNAMIC
55 1.5 mycroft
56 1.5 mycroft move a1,s2 # relocbase
57 1.5 mycroft addu a0, sp, 4 # sp
58 1.5 mycroft jal _C_LABEL(_rtld) # v0 = _rtld(sp, relocbase)
59 1.5 mycroft nop
60 1.5 mycroft
61 1.1 mhitch lw a1, 4(sp) # our atexit function
62 1.1 mhitch lw a2, 8(sp) # obj_main entry
63 1.1 mhitch addu sp, sp,12 # readjust stack
64 1.1 mhitch move a0,s0 # stack pointer
65 1.1 mhitch move t9,v0
66 1.1 mhitch jr t9 # _start(sp, cleanup, obj);
67 1.1 mhitch move a3,s1 # restore ps_strings
68 1.1 mhitch
69 1.1 mhitch END(rtld_start)
70 1.1 mhitch
71 1.1 mhitch .globl _rtld_bind_start
72 1.1 mhitch .ent _rtld_bind_start
73 1.1 mhitch _rtld_bind_start:
74 1.1 mhitch
75 1.1 mhitch move v1,gp # save old GP
76 1.1 mhitch add t9,8 # modify T9 to point at .cpload
77 1.1 mhitch .cpload t9
78 1.1 mhitch subu sp,40 # save arguments and sp value in stack
79 1.1 mhitch .cprestore 32
80 1.1 mhitch sw t7,36(sp)
81 1.1 mhitch sw a0,12(sp)
82 1.1 mhitch sw a1,16(sp)
83 1.1 mhitch sw a2,20(sp)
84 1.1 mhitch sw a3,24(sp)
85 1.1 mhitch sw s0,28(sp)
86 1.1 mhitch move s0,sp
87 1.1 mhitch move a0,t8 # symbol index
88 1.1 mhitch move a1,t7 # old RA
89 1.1 mhitch move a2,v1 # old GP
90 1.1 mhitch move a3,ra # current RA
91 1.1 mhitch jal _C_LABEL(_rtld_bind_mips)
92 1.1 mhitch nop
93 1.1 mhitch move sp,s0
94 1.1 mhitch lw ra,36(sp)
95 1.1 mhitch lw a0,12(sp)
96 1.1 mhitch lw a1,16(sp)
97 1.1 mhitch lw a2,20(sp)
98 1.1 mhitch lw a3,24(sp)
99 1.1 mhitch lw s0,28(sp)
100 1.1 mhitch addu sp,40
101 1.1 mhitch move t9,v0
102 1.1 mhitch jr t9
103 1.1 mhitch nop
104 1.1 mhitch .end _rtld_bind_start
105