asmacros.h revision 114071
11541Srgrimes/*-
21541Srgrimes * Copyright (c) 2001 Jake Burkholder.
31541Srgrimes * All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes *
141541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241541Srgrimes * SUCH DAMAGE.
251541Srgrimes *
261541Srgrimes * $FreeBSD: head/sys/sparc64/include/asmacros.h 114071 2003-04-26 17:00:10Z obrien $
271541Srgrimes */
281541Srgrimes
291541Srgrimes#ifndef	_MACHINE_ASMACROS_H_
301541Srgrimes#define	_MACHINE_ASMACROS_H_
311541Srgrimes
321541Srgrimes#ifdef _KERNEL
331541Srgrimes
341541Srgrimes/*
351541Srgrimes * Normal and alternate %g6 point to the pcb of the current process.  Normal,
361541Srgrimes & alternate and interrupt %g7 point to per-cpu data.
371541Srgrimes */
381541Srgrimes#define	PCB_REG		%g6
391541Srgrimes#define	PCPU_REG	%g7
401541Srgrimes
411541Srgrimes/*
421541Srgrimes * Alternate %g5 points to a per-cpu panic stack, which is used as a last
431541Srgrimes * resort, and for temporarily saving alternate globals.
4445739Speter */
451541Srgrimes#define	ASP_REG		%g5
461541Srgrimes
471541Srgrimes#ifdef LOCORE
4829680Sgibbs
4929680Sgibbs/*
501541Srgrimes * Atomically decrement an integer in memory.
5131260Sbde */
521541Srgrimes#define	ATOMIC_DEC_INT(r1, r2, r3) \
5331260Sbde	lduw	[r1], r2 ; \
541541Srgrimes9:	sub	r2, 1, r3 ; \
551541Srgrimes	casa	[r1] ASI_N, r2, r3 ; \
561541Srgrimes	cmp	r2, r3 ; \
571541Srgrimes	bne,pn	%icc, 9b ; \
581541Srgrimes	 mov	r3, r2
5929680Sgibbs
601541Srgrimes/*
611541Srgrimes * Atomically increment an integer in memory.
621541Srgrimes */
631541Srgrimes#define	ATOMIC_INC_INT(r1, r2, r3) \
641541Srgrimes	lduw	[r1], r2 ; \
651541Srgrimes9:	add	r2, 1, r3 ; \
661541Srgrimes	casa	[r1] ASI_N, r2, r3 ; \
671541Srgrimes	cmp	r2, r3 ; \
681541Srgrimes	bne,pn	%icc, 9b ; \
691541Srgrimes	 mov	r3, r2
701541Srgrimes
711541Srgrimes/*
721541Srgrimes * Atomically clear a number of bits of an integer in memory.
731541Srgrimes */
741541Srgrimes#define	ATOMIC_CLEAR_INT(r1, r2, r3, bits) \
751541Srgrimes	lduw	[r1], r2 ; \
761541Srgrimes9:	andn	r2, bits, r3 ; \
771541Srgrimes	casa	[r1] ASI_N, r2, r3 ; \
781541Srgrimes	cmp	r2, r3 ; \
791541Srgrimes	bne,pn	%icc, 9b ; \
801541Srgrimes	 mov	r3, r2
811541Srgrimes
821541Srgrimes#define	PCPU(member)	PCPU_REG + PC_ ## member
831541Srgrimes#define	PCPU_ADDR(member, reg) \
841541Srgrimes	add	PCPU_REG, PC_ ## member, reg
851541Srgrimes
861541Srgrimes#define	DEBUGGER() \
871541Srgrimes	ta	%xcc, 1
881541Srgrimes
891541Srgrimes#define	PANIC(msg, r1) \
901541Srgrimes	.sect	.rodata ; \
911541Srgrimes9:	.asciz	msg ; \
921541Srgrimes	.previous ; \
931541Srgrimes	SET(9b, r1, %o0) ; \
941541Srgrimes	call	panic ; \
951541Srgrimes	 nop
961541Srgrimes
971541Srgrimes#ifdef INVARIANTS
981541Srgrimes#define	KASSERT(r1, msg) \
991541Srgrimes	brnz	r1, 8f ; \
1001541Srgrimes	 nop ; \
1011541Srgrimes	PANIC(msg, r1) ; \
1021541Srgrimes8:
1031541Srgrimes#else
1041541Srgrimes#define	KASSERT(r1, msg)
1051541Srgrimes#endif
1061541Srgrimes
1071541Srgrimes#define	PUTS(msg, r1) \
1081541Srgrimes	.sect	.rodata ; \
1091541Srgrimes9:	.asciz	msg ; \
1101541Srgrimes	.previous ; \
1111541Srgrimes	SET(9b, r1, %o0) ; \
1121541Srgrimes	call	printf ; \
1131541Srgrimes	 nop
1141541Srgrimes
1151541Srgrimes/*
1161541Srgrimes * If the kernel can be located above 4G, setx needs to be used to load
1171541Srgrimes * symbol values, otherwise set is sufficient.
1181541Srgrimes */
1191541Srgrimes#ifdef HIGH_KERNEL
1201541Srgrimes#define	SET(sym, tmp, dst) \
1211541Srgrimes	setx	sym, tmp, dst
1221541Srgrimes#else
1231541Srgrimes#define	SET(sym, tmp, dst) \
1241541Srgrimes	set	sym, dst
1251541Srgrimes#endif
1261541Srgrimes
1271541Srgrimes#define	_ALIGN_DATA	.align 8
1281541Srgrimes#ifdef GPROF
1291541Srgrimes#define	_ALIGN_TEXT	.align 32
1301541Srgrimes#else
1311541Srgrimes#define	_ALIGN_TEXT	.align 16
1321541Srgrimes#endif
1331541Srgrimes
1341541Srgrimes#define	DATA(name) \
1351541Srgrimes	.data ; \
1361541Srgrimes	_ALIGN_DATA ; \
1371541Srgrimes	.globl	name ; \
1381541Srgrimes	.type	name, @object ; \
1391541Srgrimesname:
1401541Srgrimes
1411541Srgrimes#define	EMPTY
1421541Srgrimes
1431541Srgrimes#define	ENTRY(name) \
1441541Srgrimes	.text ; \
1451541Srgrimes	_ALIGN_TEXT ; \
1461541Srgrimes	.globl	name ; \
1471541Srgrimes	.type	name, @function ; \
1481541Srgrimesname:
1491541Srgrimes
1501541Srgrimes#define	END(name) \
1511541Srgrimes	.size	name, . - name
1521541Srgrimes
1531541Srgrimes#endif /* LOCORE */
1541541Srgrimes
1551541Srgrimes#endif /* _KERNEL */
1561541Srgrimes
1571541Srgrimes#endif /* !_MACHINE_ASMACROS_H_ */
1581541Srgrimes