summaryrefslogtreecommitdiff
path: root/lib/csu/m88k/md_init.h
blob: 217a1a806db059521352b1c4010e4823f7299c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*	$OpenBSD: md_init.h,v 1.7 2018/10/06 23:30:25 aoyama Exp $	*/

/*
 * Copyright (c) 2012 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define	MD_SECT_CALL_FUNC(section, func) __asm (			\
	"\t.section\t" #section ",\"ax\",@progbits\n"			\
	"\tbsr\t" #func "\n"					\
	"\t.previous")

#define	MD_SECTION_PROLOGUE(section, entry) __asm (			\
	"\t.section\t" #section ",\"ax\",@progbits\n"			\
	"\t.globl\t" #entry "\n"					\
	"\t.type\t" #entry ",@function\n"				\
	"\t.align\t2\n"							\
	#entry ":\n"							\
	"\tsubu\t%r31, %r31, 16\n"					\
	"\tst\t%r1, %r31, 0\n"						\
	"\t.previous")

#define	MD_SECTION_EPILOGUE(section) __asm(				\
	"\t.section\t" #section ",\"ax\",@progbits\n"			\
	"\tld\t%r1, %r31, 0\n"						\
	"\tjmp.n\t%r1\n"						\
	"\taddu\t%r31, %r31, 16\n"					\
	"\t.previous")

/*
 * When a program begins, r31 points to a structure passed by the kernel.
 *
 * This structure contains argc, the argv[] NULL-terminated array, and
 * the envp[] NULL-terminated array.
 *
 * Our start code starts with two nops because execution may skip up to
 * two instructions; see setregs() in the kernel for details.
 *
 * The definitions of environ and __progname prevent the creation
 * of COPY relocations for WEAK symbols.
 */
#define	MD_CRT0_START					\
	char **environ, *__progname;			\
	__asm(						\
	"	.text					\n" \
	"	.align 3				\n" \
	"	.globl __start				\n" \
	"	.globl _start				\n" \
	"__start:					\n" \
	"_start:					\n" \
	"	or	%r0, %r0, %r0			\n" \
	"	or	%r0, %r0, %r0			\n" \
	"	ld	%r2, %r31, 0	/* argc */	\n" \
	"	addu	%r3, %r31, 4	/* argv */	\n" \
	"	lda	%r4, %r3[%r2]			\n" \
	"	br.n	___start			\n" \
	"	 addu	%r4, %r4, 4			\n" \
	"	 /* envp = argv + argc + 1 */		\n" \
	"	.previous");

#define	MD_RCRT0_START					\
	__asm(						\
	"	.text					\n" \
	"	.align 3				\n" \
	"	.globl __start				\n" \
	"	.globl _start				\n" \
	"__start:					\n" \
	"_start:					\n" \
	"	or	%r0, %r0, %r0			\n" \
	"	or	%r0, %r0, %r0			\n" \
	\
	"	or	%r2, %r31, 0			\n" \
	"	subu	%r31, %r31, 4*16		\n" \
	"	or	%r3, %r31, 0			\n" \
	"	bsr	1f				\n" \
	"	bsr	_DYNAMIC#plt			\n" \
	"1:	ld	%r6, %r1, 0			\n" \
	"	mak	%r5, %r6, 26<2>			\n" \
	"	addu	%r4, %r5, %r1			\n" \
	"	bsr	_dl_boot_bind#plt		\n" \
	"	addu	%r31, %r31, 4*16		\n" \
	\
	"	ld	%r2, %r31, 0	/* argc */	\n" \
	"	addu	%r3, %r31, 4	/* argv */	\n" \
	"	lda	%r4, %r3[%r2]			\n" \
	"	or	%r5, %r0, %r0	/* cleanup */	\n" \
	"	br.n	___start			\n" \
	"	 addu	%r4, %r4, 4			\n" \
	"	 /* envp = argv + argc + 1 */		\n" \
	\
	"_dl_exit:					\n" \
	"	or	%r13, %r0, 1			\n" \
	"	tb0	0, %r0, 450			\n" \
	"	or	%r0, %r0, %r0			\n" \
	"	.previous");