11.4Smartin/* $NetBSD: asm.h,v 1.4 2025/01/06 10:46:43 martin Exp $ */
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to The NetBSD Foundation
81.1Smatt * by Matt Thomas of 3am Software Foundry.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt *
191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Smatt * POSSIBILITY OF SUCH DAMAGE.
301.1Smatt */
311.1Smatt
321.1Smatt#ifndef _OR1K_ASM_H_
331.1Smatt#define _OR1K_ASM_H_
341.1Smatt
351.1Smatt#define	__BIT(n)	(1 << (n))
361.1Smatt#define __BITS(hi,lo)	((~((~0)<<((hi)+1)))&((~0)<<(lo)))
371.1Smatt
381.1Smatt#define _C_LABEL(x)	x
391.1Smatt#define	_ASM_LABEL(x)	x
401.1Smatt
411.1Smatt#define __CONCAT(x,y)	x ## y
421.1Smatt#define __STRING(x)	#x
431.1Smatt
441.1Smatt#ifndef _ALIGN_TEXT
451.1Smatt# define _ALIGN_TEXT .align 4
461.1Smatt#endif
471.1Smatt
481.1Smatt#ifndef _TEXT_SECTION
491.1Smatt#define _TEXT_SECTION	.text
501.1Smatt#endif
511.1Smatt#define _ASM_TYPE_FUNCTION	@function
521.1Smatt#define _ASM_TYPE_OBJECT	@object
531.1Smatt#define _ENTRY(x) \
541.1Smatt	_TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
551.1Smatt#define	_END(x)		.size x,.-x
561.1Smatt
571.1Smatt#ifdef GPROF
581.1Smatt# define _PROF_PROLOGUE	\
591.1Smatt	mov x9, x30; l.jal __mcount
601.1Smatt#else
611.1Smatt# define _PROF_PROLOGUE
621.1Smatt#endif
631.1Smatt
641.1Smatt#define	ENTRY(y)		_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
651.1Smatt#define	ENTRY_NP(y)		_ENTRY(_C_LABEL(y))
661.1Smatt#define	END(y)			_END(_C_LABEL(y))
671.1Smatt#define	END(y)			_END(_C_LABEL(y))
681.1Smatt#define	ASENTRY(y)		_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
691.1Smatt#define	ASENTRY_NP(y)		_ENTRY(_ASM_LABEL(y))
701.1Smatt#define	ASEND(y)		_END(_ASM_LABEL(y))
711.1Smatt
721.1Smatt#define	ASMSTR		.asciz
731.1Smatt
741.1Smatt#ifdef __PIC__
751.1Smatt#define	PLT(x)			plt(x)
761.1Smatt#define	PIC_GOTSETUP(r)					\
771.1Smatt        l.jal	999f					;\
781.1Smatt	l.nop						;\
791.1Smatt999:	l.movhi	r,gotpchi(_GLOBAL_OFFSET_TABLE_+0)	;\
801.1Smatt	l.ori	r,r,gotpclo(_GLOBAL_OFFSET_TABLE_+4)	;\
811.1Smatt	l.add	r,r,r9
821.1Smatt#else
831.1Smatt#define	PLT(x)			x
841.1Smatt#endif
851.1Smatt
861.3Smartin#ifdef _NETBSD_REVISIONID
871.3Smartin#define __RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
881.4Smartin			.asciz x;					\
891.4Smartin			.ascii "$"; .ascii "NetBSD: "; .ascii __FILE__;	\
901.4Smartin			.ascii " "; .ascii _NETBSD_REVISIONID;		\
911.4Smartin			.asciz " $";					\
921.3Smartin			.popsection
931.3Smartin#else
941.2Sjoerg#define __RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
951.2Sjoerg			.asciz x;					\
961.2Sjoerg			.popsection
971.3Smartin#endif
981.1Smatt#define RCSID(x)	__RCSID(x)
991.1Smatt
1001.1Smatt#define	WEAK_ALIAS(alias,sym)						\
1011.1Smatt	.weak alias;							\
1021.1Smatt	alias = sym
1031.1Smatt
1041.1Smatt/*
1051.1Smatt * STRONG_ALIAS: create a strong alias.
1061.1Smatt */
1071.1Smatt#define STRONG_ALIAS(alias,sym)						\
1081.1Smatt	.globl alias;							\
1091.1Smatt	alias = sym
1101.1Smatt
1111.1Smatt#define	WARN_REFERENCES(sym,msg)					\
1121.1Smatt	.pushsection .gnu.warning. ## sym;				\
1131.1Smatt	.ascii msg;							\
1141.1Smatt	.popsection
1151.1Smatt
1161.1Smatt#endif /* !_OR1K_ASM_H_ */
117