xref: /netbsd-src/sys/arch/or1k/include/asm.h (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1 /* $NetBSD: asm.h,v 1.2 2020/04/17 14:19:44 joerg Exp $ */
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of 3am Software Foundry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _OR1K_ASM_H_
33 #define _OR1K_ASM_H_
34 
35 #define	__BIT(n)	(1 << (n))
36 #define __BITS(hi,lo)	((~((~0)<<((hi)+1)))&((~0)<<(lo)))
37 
38 #define _C_LABEL(x)	x
39 #define	_ASM_LABEL(x)	x
40 
41 #define __CONCAT(x,y)	x ## y
42 #define __STRING(x)	#x
43 
44 #ifndef _ALIGN_TEXT
45 # define _ALIGN_TEXT .align 4
46 #endif
47 
48 #ifndef _TEXT_SECTION
49 #define _TEXT_SECTION	.text
50 #endif
51 #define _ASM_TYPE_FUNCTION	@function
52 #define _ASM_TYPE_OBJECT	@object
53 #define _ENTRY(x) \
54 	_TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
55 #define	_END(x)		.size x,.-x
56 
57 #ifdef GPROF
58 # define _PROF_PROLOGUE	\
59 	mov x9, x30; l.jal __mcount
60 #else
61 # define _PROF_PROLOGUE
62 #endif
63 
64 #define	ENTRY(y)		_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
65 #define	ENTRY_NP(y)		_ENTRY(_C_LABEL(y))
66 #define	END(y)			_END(_C_LABEL(y))
67 #define	END(y)			_END(_C_LABEL(y))
68 #define	ASENTRY(y)		_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
69 #define	ASENTRY_NP(y)		_ENTRY(_ASM_LABEL(y))
70 #define	ASEND(y)		_END(_ASM_LABEL(y))
71 
72 #define	ASMSTR		.asciz
73 
74 #ifdef __PIC__
75 #define	PLT(x)			plt(x)
76 #define	PIC_GOTSETUP(r)					\
77         l.jal	999f					;\
78 	l.nop						;\
79 999:	l.movhi	r,gotpchi(_GLOBAL_OFFSET_TABLE_+0)	;\
80 	l.ori	r,r,gotpclo(_GLOBAL_OFFSET_TABLE_+4)	;\
81 	l.add	r,r,r9
82 #else
83 #define	PLT(x)			x
84 #endif
85 
86 #define __RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
87 			.asciz x;					\
88 			.popsection
89 #define RCSID(x)	__RCSID(x)
90 
91 #define	WEAK_ALIAS(alias,sym)						\
92 	.weak alias;							\
93 	alias = sym
94 
95 /*
96  * STRONG_ALIAS: create a strong alias.
97  */
98 #define STRONG_ALIAS(alias,sym)						\
99 	.globl alias;							\
100 	alias = sym
101 
102 #define	WARN_REFERENCES(sym,msg)					\
103 	.pushsection .gnu.warning. ## sym;				\
104 	.ascii msg;							\
105 	.popsection
106 
107 #endif /* !_OR1K_ASM_H_ */
108