2 * Copyright (c) 2001 Jake Burkholder.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #ifndef _MACHINE_ASMACROS_H_
30 #define _MACHINE_ASMACROS_H_
35 * Normal and alternate %g6 point to the pcb of the current process. Normal,
36 * alternate and interrupt %g7 point to per-cpu data.
42 * Alternate %g5 points to a per-cpu panic stack, which is used as a last
43 * resort, and for temporarily saving alternate globals.
50 * Atomically decrement an integer in memory.
52 #define ATOMIC_DEC_INT(r1, r2, r3) \
55 casa [r1] ASI_N, r2, r3 ; \
61 * Atomically increment an integer in memory.
63 #define ATOMIC_INC_INT(r1, r2, r3) \
66 casa [r1] ASI_N, r2, r3 ; \
72 * Atomically increment a long in memory.
74 #define ATOMIC_INC_LONG(r1, r2, r3) \
77 casxa [r1] ASI_N, r2, r3 ; \
83 * Atomically clear a number of bits of an integer in memory.
85 #define ATOMIC_CLEAR_INT(r1, r2, r3, bits) \
87 9: andn r2, bits, r3 ; \
88 casa [r1] ASI_N, r2, r3 ; \
94 * Atomically clear a number of bits of a long in memory.
96 #define ATOMIC_CLEAR_LONG(r1, r2, r3, bits) \
98 9: andn r2, bits, r3 ; \
99 casxa [r1] ASI_N, r2, r3 ; \
104 #define PCPU(member) PCPU_REG + PC_ ## member
105 #define PCPU_ADDR(member, reg) \
106 add PCPU_REG, PC_ ## member, reg
111 #define PANIC(msg, r1) \
120 #define KASSERT(r1, msg) \
126 #define KASSERT(r1, msg)
129 #define PUTS(msg, r1) \
137 #define _ALIGN_DATA .align 8
143 .type name, @object ; \
149 * Generate atomic compare and swap, load and store instructions for the
150 * corresponding width and ASI (or not). Note that we want to evaluate the
151 * macro args before concatenating, so that EMPTY really turns into nothing.
153 #define _LD(w, a) ld ## w ## a
154 #define _ST(w, a) st ## w ## a
155 #define _CAS(w, a) cas ## w ## a
157 #define LD(w, a) _LD(w, a)
158 #define ST(w, a) _ST(w, a)
159 #define CAS(w, a) _CAS(w, a)
165 #endif /* !_MACHINE_ASMACROS_H_ */