xref: /openbsd/libexec/ld.so/mips64/ldasm.S (revision 73471bf0)
1/*	$OpenBSD: ldasm.S,v 1.24 2019/09/02 12:43:54 mortimer Exp $ */
2
3/*
4 * Copyright (c) 1998-2002 Opsycon AB, Sweden.
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#include <machine/asm.h>
30#include <sys/syscall.h>
31
32/* Stack at this stage is:
33 * struct stack {
34 *	int	kargc;
35 *	char	*kargv[1];	size depends on kargc
36 *	char	kargstr[1];	size varies
37 *	char	kenvstr[1];	size varies
38 * };
39 */
40
41FRAMESZ= MKFSIZ(4,16)
42GPOFF= FRAMESZ-2*REGSZ
43RAOFF= FRAMESZ-1*REGSZ
44A0OFF= FRAMESZ-3*REGSZ
45A1OFF= FRAMESZ-4*REGSZ
46A2OFF= FRAMESZ-5*REGSZ
47A3OFF= FRAMESZ-6*REGSZ
48A4OFF= FRAMESZ-7*REGSZ
49A5OFF= FRAMESZ-8*REGSZ
50A6OFF= FRAMESZ-9*REGSZ
51A7OFF= FRAMESZ-10*REGSZ
52S0OFF= FRAMESZ-11*REGSZ
53
54LEAF(_dl_start, FRAMESZ)		/* Not really LEAF, but we simplify */
55	PTR_SUBU sp, FRAMESZ		# Some space.
56	SETUP_GP64(GPOFF, _dl_start)
57
58	LA	s1, 1f
59	bgezal	zero, 1f
601:
61	PTR_SUBU s0, ra, s1		# This is the load offset
62
63	PTR_ADDU a0, sp, FRAMESZ	# Where stack info is.
64	PTR_ADDU a1, sp, 0		# Where fast AUX info will be.
65	LA	a2, _DYNAMIC
66	PTR_ADDU a2, s0			# Where _DYNAMIC is
67	LA	t9, _dl_boot_bind
68	PTR_ADDU t9, s0
69	jalr	t9			# Relocate ourself.
70
71	REG_L	a3, FRAMESZ(sp)		# argc
72	PTR_ADDU a0, sp, FRAMESZ+REGSZ	# argv
73	PTR_ADDU a1, a0, REGSZ
74	PTR_SLL  a3, a3, LOGREGSZ
75	PTR_ADDU a1, a3
76	PTR_ADDU a3, sp, 0		# Where fast AUX info will be.
77	move	a2, s0			# Load offset
78	jal	_dl_boot		# Go do the linking.
79
80	move	t9, v0			# Entry address from _dl_boot.
81	LA	v0, _dl_dtors		# cleanup
82
83	RESTORE_GP64
84	PTR_ADDU sp, FRAMESZ		# Restore stack pointer.
85	move	ra, zero		# Mark last stack frame.
86	j	t9			# Go execute the 'real' program.
87END(_dl_start)
88
89	.globl	_dl_bind_start
90	.ent	_dl_bind_start, 0
91_dl_bind_start:
92	ld	v1, -32744(gp)
93	PTR_SUBU sp, FRAMESZ
94	SETUP_GP64(GPOFF, _dl_bind_start)
95	REG_S	a0, A0OFF(sp)
96	REG_S	a1, A1OFF(sp)
97	REG_S	a2, A2OFF(sp)
98	REG_S	a3, A3OFF(sp)
99	REG_S	a4, A4OFF(sp)
100	REG_S	a5, A5OFF(sp)
101	REG_S	a6, A6OFF(sp)
102	REG_S	a7, A7OFF(sp)
103	REG_S	$15, RAOFF(sp)
104	REG_S	s0, S0OFF(sp)
105	move	s0, sp
106	move	a0, v1
107	move	a1, t8
108	jal	_dl_bind
109
110	move	sp, s0
111	REG_L	ra, RAOFF(sp)
112	REG_L	s0, S0OFF(sp)
113	REG_L	a0, A0OFF(sp)
114	REG_L	a1, A1OFF(sp)
115	REG_L	a2, A2OFF(sp)
116	REG_L	a3, A3OFF(sp)
117	REG_L	a4, A4OFF(sp)
118	REG_L	a5, A5OFF(sp)
119	REG_L	a6, A6OFF(sp)
120	REG_L	a7, A7OFF(sp)
121	RESTORE_GP64
122	PTR_ADDU sp, FRAMESZ
123	move	t9, v0
124	jr	t9
125	.end	_dl_bind_start
126