asmacros.h revision 100840
1/*-
2 * Copyright (c) 2001 Jake Burkholder.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/sparc64/include/asmacros.h 100840 2002-07-29 00:38:07Z jake $
27 */
28
29#ifndef	_MACHINE_ASMACROS_H_
30#define	_MACHINE_ASMACROS_H_
31
32#ifdef _KERNEL
33
34/*
35 * Normal and alternate %g6 point to the pcb of the current process.  Normal,
36 & alternate and interrupt %g7 point to per-cpu data.
37 */
38#define	PCB_REG		%g6
39#define	PCPU_REG	%g7
40
41/*
42 * Alternate %g5 points to a per-cpu panic stack, which is used as a last
43 * resort, and for temporarily saving alternate globals.
44 */
45#define	ASP_REG		%g5
46
47/*
48 * MMU %g7 points to the user tsb.
49 */
50#define	TSB_REG		%g7
51
52#ifdef LOCORE
53
54/*
55 * Atomically decrement an integer in memory.
56 */
57#define	ATOMIC_DEC_INT(r1, r2, r3) \
58	lduw	[r1], r2 ; \
599:	sub	r2, 1, r3 ; \
60	casa	[r1] ASI_N, r2, r3 ; \
61	cmp	r2, r3 ; \
62	bne,pn	%icc, 9b ; \
63	 mov	r3, r2
64
65/*
66 * Atomically increment an integer in memory.
67 */
68#define	ATOMIC_INC_INT(r1, r2, r3) \
69	lduw	[r1], r2 ; \
709:	add	r2, 1, r3 ; \
71	casa	[r1] ASI_N, r2, r3 ; \
72	cmp	r2, r3 ; \
73	bne,pn	%icc, 9b ; \
74	 mov	r3, r2
75
76/*
77 * Atomically clear a number of bits of an integer in memory.
78 */
79#define	ATOMIC_CLEAR_INT(r1, r2, r3, bits) \
80	lduw	[r1], r2 ; \
819:	andn	r2, bits, r3 ; \
82	casa	[r1] ASI_N, r2, r3 ; \
83	cmp	r2, r3 ; \
84	bne,pn	%icc, 9b ; \
85	 mov	r3, r2
86
87#define	PCPU(member)	PCPU_REG + PC_ ## member
88#define	PCPU_ADDR(member, reg) \
89	add	PCPU_REG, PC_ ## member, reg
90
91#define	DEBUGGER() \
92	ta	%xcc, 1
93
94#define	PANIC(msg, r1) \
95	.sect	.rodata ; \
969:	.asciz	msg ; \
97	.previous ; \
98	SET(9b, r1, %o0) ; \
99	call	panic ; \
100	 nop
101
102#ifdef INVARIANTS
103#define	KASSERT(r1, msg) \
104	brnz	r1, 8f ; \
105	 nop ; \
106	PANIC(msg, r1) ; \
1078:
108#else
109#define	KASSERT(r1, msg)
110#endif
111
112#define	PUTS(msg, r1) \
113	.sect	.rodata ; \
1149:	.asciz	msg ; \
115	.previous ; \
116	SET(9b, r1, %o0) ; \
117	call	printf ; \
118	 nop
119
120/*
121 * If the kernel can be located above 4G, setx needs to be used to load
122 * symbol values, otherwise set is sufficient.
123 */
124#ifdef HIGH_KERNEL
125#define	SET(sym, tmp, dst) \
126	setx	sym, tmp, dst
127#else
128#define	SET(sym, tmp, dst) \
129	set	sym, dst
130#endif
131
132#define	_ALIGN_DATA	.align 8
133#ifdef GPROF
134#define	_ALIGN_TEXT	.align 32
135#else
136#define	_ALIGN_TEXT	.align 16
137#endif
138
139#define	DATA(name) \
140	.data ; \
141	_ALIGN_DATA ; \
142	.globl	name ; \
143	.type	name, @object ; \
144name ## :
145
146#define	EMPTY
147
148#define	ENTRY(name) \
149	.text ; \
150	_ALIGN_TEXT ; \
151	.globl	name ; \
152	.type	name, @function ; \
153name ## :
154
155#define	END(name) \
156	.size	name, . - name
157
158#endif /* LOCORE */
159
160#endif /* _KERNEL */
161
162#endif /* !_MACHINE_ASMACROS_H_ */
163