xref: /openbsd/lib/csu/hppa/md_init.h (revision 097a140d)
1 /* $OpenBSD: md_init.h,v 1.15 2020/10/15 16:30:23 deraadt Exp $ */
2 
3 /*
4  * Copyright (c) 2003 Dale Rahn. All rights reserved.
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 OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 /*
28  * hppa overrides these because it has different label syntax
29  */
30 #define MD_DATA_SECTION_FLAGS_SYMBOL(section, flags, type, symbol)	\
31 	extern __dso_hidden type symbol[];				\
32 	__asm("	.section "section",\""flags"\",@progbits		\n" \
33 	"	.balign 4						\n" \
34 	#symbol"							\n" \
35 	"	.previous")
36 #define MD_DATA_SECTION_SYMBOL_VALUE(section, type, symbol, value)	\
37 	extern __dso_hidden type symbol[];				\
38 	__asm("	.section "section",\"aw\",@progbits			\n" \
39 	"	.balign 4						\n" \
40 	#symbol"							\n" \
41 	"	.int "#value"						\n" \
42 	"	.previous")
43 #define MD_DATA_SECTION_FLAGS_VALUE(section, flags, value)		\
44 	__asm("	.section "section",\""flags"\",@progbits		\n" \
45 	"	.balign 4						\n" \
46 	"	.int "#value"						\n" \
47 	"	.previous")
48 
49 #define MD_SECT_CALL_FUNC(section, func)			\
50 	__asm (".section "#section",\"ax\",@progbits	\n"	\
51 	"	bl	" #func ",%r2			\n"	\
52 	"	stw	%r19,-80(%r30)			\n"	\
53 	"	ldw	-80(%r30),%r19			\n"	\
54 	"	.previous")
55 
56 #define MD_SECTION_PROLOGUE(sect, entry_pt)			\
57 	__asm (						   	\
58 	"	.section "#sect",\"ax\",@progbits	\n"	\
59 	"	.EXPORT "#entry_pt",ENTRY,PRIV_LEV=3,ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RTNVAL=NO					\n"	\
60 	"	.align 4				\n"	\
61 	#entry_pt"					\n"	\
62 	"	stw %r2, -20(%r30)			\n"	\
63 	"	ldo 64(%r30),%r30			\n"	\
64 	"	/* fall thru */				\n"	\
65 	"	.previous")
66 
67 
68 #define MD_SECTION_EPILOGUE(sect)				\
69 	__asm (							\
70 	"	.section "#sect",\"ax\",@progbits	\n"	\
71 	"	ldw -84(%r30),%r2			\n"	\
72 	"	bv %r0(%r2)				\n"	\
73 	"	ldo -64(%r30),%r30			\n"	\
74 	"	.previous")
75 
76 
77 #include <sys/exec.h>		/* for struct ps_strings */
78 
79 #define	MD_CRT0_START						\
80 	__asm(							\
81 	".import $global$, data					\n" \
82 	"	.import ___start, code				\n" \
83 	"	.text						\n" \
84 	"	.align	4					\n" \
85 	"	.export __start, entry				\n" \
86 	"	.type	__start,@function			\n" \
87 	"	.label __start					\n" \
88 	"	.proc						\n" \
89 	"	.callinfo frame=0, calls			\n" \
90 	"	.entry						\n" \
91 	"	bl L$lpc, %r27					\n" \
92 	"	depi 0, 31, 2, %r27				\n" \
93 	"L$lpc:  addil L'$global$ - ($PIC_pcrel$0 - 8), %r27	\n" \
94 	"	ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27	\n" \
95 	"	.call						\n" \
96 	"	b	___start				\n" \
97 	"	copy    %r27, %r19				\n" \
98 	"	.exit						\n" \
99 	"	.procend")
100 
101 #define	MD_RCRT0_START						\
102 	__asm(							\
103 	".import $global$, data					\n" \
104 	"	.import ___start, code				\n" \
105 	"	.text						\n" \
106 	"	.align	4					\n" \
107 	"	.export __start, entry				\n" \
108 	"	.type	__start,@function			\n" \
109 	"	.label __start					\n" \
110 	"	.proc						\n" \
111 	"	.callinfo frame=0, calls			\n" \
112 	"	.entry						\n" \
113 	"	copy	%r3, %r1				\n" \
114 	"	copy	%sp, %r3				\n" \
115 	"	stwm	%r1, 64+16*4(%sp)			\n" \
116 	"	stw	%arg0, -36(%r3)				\n" \
117 	"	bl	1f, %dp					\n" \
118 	"	depi	0, 31, 2, %dp				\n" \
119 	"1:	addil	L'$global$ - ($PIC_pcrel$0 - 8), %dp	\n" \
120 	"	ldo	R'$global$ - ($PIC_pcrel$0 - 12)(%r1), %dp \n" \
121 	"	bl	1f, %arg2				\n" \
122 	"	depi	0, 31, 2, %arg2				\n" \
123 	"1:	addil	L'_DYNAMIC - ($PIC_pcrel$0 - 8), %arg2	\n" \
124 	"	ldo	R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1), %arg2 \n" \
125 	"	stw	%arg2, -40(%r3)				\n" \
126 	"	ldw	0(%arg0), %arg0				\n" \
127 	"	ldo	4(%r3), %arg1				\n" \
128 	"	ldo	-4(%arg0), %arg0			\n" \
129 	"	bl	_dl_boot_bind, %rp			\n" \
130 	"	copy	%dp, %r19				\n" \
131 	"	ldw	-36(%r3), %arg0				\n" \
132 	"	copy	%r0, %arg1				\n" \
133 	"	ldo	64(%r3), %sp				\n" \
134 	"	ldwm	-64(%sp), %r3				\n" \
135 	"	.call						\n" \
136 	"	b	___start				\n" \
137 	"	copy	%dp, %r19				\n" \
138 	"	.exit						\n" \
139 	"	.procend					\n" \
140 	"	.export _dl_exit, entry				\n" \
141 	"	.type	_dl_exit,@function			\n" \
142 	"	.label _dl_exit					\n" \
143 	"	.proc						\n" \
144 	"	.callinfo frame=0, calls			\n" \
145 	"	.entry						\n" \
146 	"_dl_exit:						\n" \
147 	"	stw	%rp, -24(%sp)				\n" \
148 	"	ldil	L%0xc0000000, %r1			\n" \
149 	"	ble	4(%sr7, %r1)				\n" \
150 	"	ldi	" STR(SYS_exit) ", %t1			\n" \
151 	"	break 0,0					\n" \
152 	"	.exit						\n" \
153 	"	.procend")
154 
155 
156 #define	MD_START_ARGS	struct ps_strings *arginfo, void (*cleanup)(void)
157 #define	MD_START_SETUP				\
158 	char	**argv, **envp;			\
159 	int	argc;				\
160 						\
161 	argv = arginfo->ps_argvstr;		\
162 	argc = arginfo->ps_nargvstr;		\
163 	envp = arginfo->ps_envstr;
164 
165 #define	MD_EPROL_LABEL	__asm (".export _eprol, entry\n\t.label _eprol")
166