asm.h revision 1.4
1/* $NetBSD: asm.h,v 1.4 2025/01/06 10:46:43 martin 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						;\
79999:	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#ifdef _NETBSD_REVISIONID
87#define __RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
88			.asciz x;					\
89			.ascii "$"; .ascii "NetBSD: "; .ascii __FILE__;	\
90			.ascii " "; .ascii _NETBSD_REVISIONID;		\
91			.asciz " $";					\
92			.popsection
93#else
94#define __RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
95			.asciz x;					\
96			.popsection
97#endif
98#define RCSID(x)	__RCSID(x)
99
100#define	WEAK_ALIAS(alias,sym)						\
101	.weak alias;							\
102	alias = sym
103
104/*
105 * STRONG_ALIAS: create a strong alias.
106 */
107#define STRONG_ALIAS(alias,sym)						\
108	.globl alias;							\
109	alias = sym
110
111#define	WARN_REFERENCES(sym,msg)					\
112	.pushsection .gnu.warning. ## sym;				\
113	.ascii msg;							\
114	.popsection
115
116#endif /* !_OR1K_ASM_H_ */
117