xref: /openbsd/lib/csu/mips64/md_init.h (revision 17df1aa7)
1 /* $OpenBSD: md_init.h,v 1.2 2004/09/09 17:45:26 pefo Exp $ */
2 
3 /*-
4  * Copyright (c) 2001 Ross Harvey
5  * Copyright (c) 2001 Simon Burge
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the NetBSD
19  *      Foundation, Inc. and its contributors.
20  * 4. Neither the name of The NetBSD Foundation nor the names of its
21  *    contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #define ra      "$31"
38 
39 /*
40  * Allocate 32 bytes for the stack frame.  Store GP at SP+16 (since
41  * this is where code generated by the compiler for fallthru processing
42  * expects it to be), and the RA at SP+24.
43  */
44 
45 /* this is gross... */
46 
47 #ifdef __ABICALLS__
48 #define MD_FUNCTION_PROLOGUE(entry_pt)			\
49 	"	.frame $sp,32,$31		\n"	\
50 	"	.set	reorder			\n"	\
51 	"	dsubu    $sp,$sp,32		\n"	\
52 	"	.cpsetup $25, 16, "#entry_pt"	\n"	\
53 	"	sd      "ra",24($sp)		\n"
54 #else
55 #define MD_FUNCTION_PROLOGUE(entry_pt)			\
56 	"       dsubu	$sp,$sp,32		\n"	\
57 	"       sd	"ra",24($sp)		\n"
58 #endif
59 
60 
61 #define MD_SECTION_PROLOGUE(sect, entry_pt)		\
62 	__asm (						\
63 	".section "#sect",\"ax\",@progbits	\n"	\
64 	".align 2				\n"	\
65 	".globl "#entry_pt"			\n"	\
66 	".type "#entry_pt"@function		\n"	\
67 	".ent "#entry_pt"			\n"	\
68 	#entry_pt":				\n"	\
69 	MD_FUNCTION_PROLOGUE(entry_pt)			\
70 	"       /* fall thru */			\n"	\
71 	".previous")
72 
73 #define MD_SECTION_EPILOGUE(sect)                       \
74 	__asm (						\
75 	".section "#sect",\"ax\",@progbits      \n"	\
76 	"	ld	"ra",24($sp)		\n"	\
77 	" # next should have been a .cpreturn 	\n"	\
78 	"	ld	$gp,16($sp)		\n"	\
79 	"	.set	noreorder		\n"	\
80 	"	j	"ra"			\n"	\
81 	"	daddu	$sp,$sp,32		\n"	\
82 	"	.set	reorder			\n"	\
83 	".previous")
84 
85 #define MD_SECT_CALL_FUNC(section, func)		\
86 	__asm (".section "#section", \"ax\"	\n"	\
87 	"	jal	" #func "		\n"	\
88 	".previous")
89 
90