xref: /openbsd-src/lib/csu/hppa/md_init.h (revision 1e43641e997f17b3e752e4bc940b17070ff580a3)
1*1e43641eSderaadt /* $OpenBSD: md_init.h,v 1.16 2023/11/18 16:26:16 deraadt Exp $ */
28d0ba7c9Sdrahn 
38d0ba7c9Sdrahn /*
48d0ba7c9Sdrahn  * Copyright (c) 2003 Dale Rahn. All rights reserved.
58d0ba7c9Sdrahn  *
68d0ba7c9Sdrahn  * Redistribution and use in source and binary forms, with or without
78d0ba7c9Sdrahn  * modification, are permitted provided that the following conditions
88d0ba7c9Sdrahn  * are met:
98d0ba7c9Sdrahn  * 1. Redistributions of source code must retain the above copyright
108d0ba7c9Sdrahn  *    notice, this list of conditions and the following disclaimer.
118d0ba7c9Sdrahn  * 2. Redistributions in binary form must reproduce the above copyright
128d0ba7c9Sdrahn  *    notice, this list of conditions and the following disclaimer in the
138d0ba7c9Sdrahn  *    documentation and/or other materials provided with the distribution.
148d0ba7c9Sdrahn  *
158d0ba7c9Sdrahn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
168d0ba7c9Sdrahn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
178d0ba7c9Sdrahn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
188d0ba7c9Sdrahn  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
198d0ba7c9Sdrahn  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
208d0ba7c9Sdrahn  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
218d0ba7c9Sdrahn  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
228d0ba7c9Sdrahn  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
238d0ba7c9Sdrahn  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
248d0ba7c9Sdrahn  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
258d0ba7c9Sdrahn  */
268d0ba7c9Sdrahn 
27b3fe29f4Sguenther /*
28b3fe29f4Sguenther  * hppa overrides these because it has different label syntax
29b3fe29f4Sguenther  */
30b3fe29f4Sguenther #define MD_DATA_SECTION_FLAGS_SYMBOL(section, flags, type, symbol)	\
31b3fe29f4Sguenther 	extern __dso_hidden type symbol[];				\
32b3fe29f4Sguenther 	__asm("	.section "section",\""flags"\",@progbits		\n" \
33b3fe29f4Sguenther 	"	.balign 4						\n" \
34b3fe29f4Sguenther 	#symbol"							\n" \
35b3fe29f4Sguenther 	"	.previous")
36b3fe29f4Sguenther #define MD_DATA_SECTION_SYMBOL_VALUE(section, type, symbol, value)	\
37b3fe29f4Sguenther 	extern __dso_hidden type symbol[];				\
38b3fe29f4Sguenther 	__asm("	.section "section",\"aw\",@progbits			\n" \
39b3fe29f4Sguenther 	"	.balign 4						\n" \
40b3fe29f4Sguenther 	#symbol"							\n" \
41b3fe29f4Sguenther 	"	.int "#value"						\n" \
42b3fe29f4Sguenther 	"	.previous")
43b3fe29f4Sguenther #define MD_DATA_SECTION_FLAGS_VALUE(section, flags, value)		\
44b3fe29f4Sguenther 	__asm("	.section "section",\""flags"\",@progbits		\n" \
45b3fe29f4Sguenther 	"	.balign 4						\n" \
46b3fe29f4Sguenther 	"	.int "#value"						\n" \
47b3fe29f4Sguenther 	"	.previous")
488d0ba7c9Sdrahn 
498d0ba7c9Sdrahn #define MD_SECT_CALL_FUNC(section, func)			\
508d0ba7c9Sdrahn 	__asm (".section "#section",\"ax\",@progbits	\n"	\
518d0ba7c9Sdrahn 	"	bl	" #func ",%r2			\n"	\
52a98ea81aSmickey 	"	stw	%r19,-80(%r30)			\n"	\
53a98ea81aSmickey 	"	ldw	-80(%r30),%r19			\n"	\
548d0ba7c9Sdrahn 	"	.previous")
558d0ba7c9Sdrahn 
568d0ba7c9Sdrahn #define MD_SECTION_PROLOGUE(sect, entry_pt)			\
578d0ba7c9Sdrahn 	__asm (						   	\
588d0ba7c9Sdrahn 	"	.section "#sect",\"ax\",@progbits	\n"	\
598d0ba7c9Sdrahn 	"	.EXPORT "#entry_pt",ENTRY,PRIV_LEV=3,ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RTNVAL=NO					\n"	\
608d0ba7c9Sdrahn 	"	.align 4				\n"	\
618d0ba7c9Sdrahn 	#entry_pt"					\n"	\
628d0ba7c9Sdrahn 	"	stw %r2, -20(%r30)			\n"	\
638d0ba7c9Sdrahn 	"	ldo 64(%r30),%r30			\n"	\
648d0ba7c9Sdrahn 	"	/* fall thru */				\n"	\
658d0ba7c9Sdrahn 	"	.previous")
668d0ba7c9Sdrahn 
678d0ba7c9Sdrahn 
688d0ba7c9Sdrahn #define MD_SECTION_EPILOGUE(sect)				\
698d0ba7c9Sdrahn 	__asm (							\
708d0ba7c9Sdrahn 	"	.section "#sect",\"ax\",@progbits	\n"	\
718d0ba7c9Sdrahn 	"	ldw -84(%r30),%r2			\n"	\
728d0ba7c9Sdrahn 	"	bv %r0(%r2)				\n"	\
738d0ba7c9Sdrahn 	"	ldo -64(%r30),%r30			\n"	\
748d0ba7c9Sdrahn 	"	.previous")
75453b49cdSguenther 
76453b49cdSguenther 
7787e2f33bSguenther #include <sys/exec.h>		/* for struct ps_strings */
78453b49cdSguenther 
79453b49cdSguenther #define	MD_CRT0_START						\
80453b49cdSguenther 	__asm(							\
81453b49cdSguenther 	".import $global$, data					\n" \
82453b49cdSguenther 	"	.import ___start, code				\n" \
83453b49cdSguenther 	"	.text						\n" \
84453b49cdSguenther 	"	.align	4					\n" \
85453b49cdSguenther 	"	.export __start, entry				\n" \
86453b49cdSguenther 	"	.type	__start,@function			\n" \
87453b49cdSguenther 	"	.label __start					\n" \
88453b49cdSguenther 	"	.proc						\n" \
89453b49cdSguenther 	"	.callinfo frame=0, calls			\n" \
90453b49cdSguenther 	"	.entry						\n" \
91453b49cdSguenther 	"	bl L$lpc, %r27					\n" \
92453b49cdSguenther 	"	depi 0, 31, 2, %r27				\n" \
93453b49cdSguenther 	"L$lpc:  addil L'$global$ - ($PIC_pcrel$0 - 8), %r27	\n" \
94453b49cdSguenther 	"	ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27	\n" \
95453b49cdSguenther 	"	.call						\n" \
96453b49cdSguenther 	"	b	___start				\n" \
97453b49cdSguenther 	"	copy    %r27, %r19				\n" \
98453b49cdSguenther 	"	.exit						\n" \
99453b49cdSguenther 	"	.procend")
100453b49cdSguenther 
10176346582Skettenis #define	MD_RCRT0_START						\
10276346582Skettenis 	__asm(							\
10376346582Skettenis 	".import $global$, data					\n" \
10476346582Skettenis 	"	.import ___start, code				\n" \
10576346582Skettenis 	"	.text						\n" \
10676346582Skettenis 	"	.align	4					\n" \
10776346582Skettenis 	"	.export __start, entry				\n" \
10876346582Skettenis 	"	.type	__start,@function			\n" \
10976346582Skettenis 	"	.label __start					\n" \
11076346582Skettenis 	"	.proc						\n" \
11176346582Skettenis 	"	.callinfo frame=0, calls			\n" \
11276346582Skettenis 	"	.entry						\n" \
11376346582Skettenis 	"	copy	%r3, %r1				\n" \
11476346582Skettenis 	"	copy	%sp, %r3				\n" \
11576346582Skettenis 	"	stwm	%r1, 64+16*4(%sp)			\n" \
11676346582Skettenis 	"	stw	%arg0, -36(%r3)				\n" \
117ed3c11e0Skettenis 	"	bl	1f, %dp					\n" \
118ed3c11e0Skettenis 	"	depi	0, 31, 2, %dp				\n" \
119ed3c11e0Skettenis 	"1:	addil	L'$global$ - ($PIC_pcrel$0 - 8), %dp	\n" \
120ed3c11e0Skettenis 	"	ldo	R'$global$ - ($PIC_pcrel$0 - 12)(%r1), %dp \n" \
12176346582Skettenis 	"	bl	1f, %arg2				\n" \
12276346582Skettenis 	"	depi	0, 31, 2, %arg2				\n" \
12376346582Skettenis 	"1:	addil	L'_DYNAMIC - ($PIC_pcrel$0 - 8), %arg2	\n" \
12476346582Skettenis 	"	ldo	R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1), %arg2 \n" \
12576346582Skettenis 	"	stw	%arg2, -40(%r3)				\n" \
12676346582Skettenis 	"	ldw	0(%arg0), %arg0				\n" \
12776346582Skettenis 	"	ldo	4(%r3), %arg1				\n" \
12876346582Skettenis 	"	ldo	-4(%arg0), %arg0			\n" \
129ed3c11e0Skettenis 	"	bl	_dl_boot_bind, %rp			\n" \
130ed3c11e0Skettenis 	"	copy	%dp, %r19				\n" \
13176346582Skettenis 	"	ldw	-36(%r3), %arg0				\n" \
13276346582Skettenis 	"	copy	%r0, %arg1				\n" \
13376346582Skettenis 	"	ldo	64(%r3), %sp				\n" \
13476346582Skettenis 	"	ldwm	-64(%sp), %r3				\n" \
13576346582Skettenis 	"	.call						\n" \
13676346582Skettenis 	"	b	___start				\n" \
137ed3c11e0Skettenis 	"	copy	%dp, %r19				\n" \
13876346582Skettenis 	"	.exit						\n" \
13976346582Skettenis 	"	.procend					\n" \
140*1e43641eSderaadt 	"	.export _csu_abort, entry			\n" \
141*1e43641eSderaadt 	"	.type	_csu_abort,@function			\n" \
142*1e43641eSderaadt 	"	.label _csu_abort				\n" \
14376346582Skettenis 	"	.proc						\n" \
14476346582Skettenis 	"	.callinfo frame=0, calls			\n" \
14576346582Skettenis 	"	.entry						\n" \
146*1e43641eSderaadt 	"_csu_abort:						\n" \
1472bc3a8c0Sderaadt 	"	break 0,0					\n" \
14876346582Skettenis 	"	.exit						\n" \
14976346582Skettenis 	"	.procend")
15076346582Skettenis 
15176346582Skettenis 
152453b49cdSguenther #define	MD_START_ARGS	struct ps_strings *arginfo, void (*cleanup)(void)
153453b49cdSguenther #define	MD_START_SETUP				\
154453b49cdSguenther 	char	**argv, **envp;			\
155453b49cdSguenther 	int	argc;				\
156453b49cdSguenther 						\
157453b49cdSguenther 	argv = arginfo->ps_argvstr;		\
158453b49cdSguenther 	argc = arginfo->ps_nargvstr;		\
159d5d4315eSguenther 	envp = arginfo->ps_envstr;
160453b49cdSguenther 
161453b49cdSguenther #define	MD_EPROL_LABEL	__asm (".export _eprol, entry\n\t.label _eprol")
162