asmacros.h revision 92198
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 92198 2002-03-13 03:28:47Z 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) %g7 + PC_ ## member 88#define PCPU_ADDR(member, reg) add %g7, PC_ ## member, reg 89 90#define DEBUGGER() ta %xcc, 1 91 92#define PANIC(msg, r1) \ 93 .sect .rodata ; \ 949: .asciz msg ; \ 95 .previous ; \ 96 SET(9b, r1, %o0) ; \ 97 call panic ; \ 98 nop 99 100#ifdef INVARIANTS 101#define KASSERT(r1, msg) \ 102 brnz r1, 8f ; \ 103 nop ; \ 104 PANIC(msg, r1) ; \ 1058: 106#else 107#define KASSERT(r1, msg) 108#endif 109 110#define PUTS(msg, r1) \ 111 .sect .rodata ; \ 1129: .asciz msg ; \ 113 .previous ; \ 114 SET(9b, r1, %o0) ; \ 115 call printf ; \ 116 nop 117 118/* 119 * If the kernel can be located above 4G, setx needs to be used to load 120 * symbol values, otherwise set is sufficient. 121 */ 122#ifdef HIGH_KERNEL 123#define SET(sym, tmp, dst) \ 124 setx sym, tmp, dst 125#else 126#define SET(sym, tmp, dst) \ 127 set sym, dst 128#endif 129 130#endif /* LOCORE */ 131 132#endif /* _KERNEL */ 133 134#define DATA(name) \ 135 .data ; \ 136 .globl name ; \ 137 .type name, @object ; \ 138name ## : 139 140#define EMPTY 141 142#define ENTRY(name) \ 143 .text ; \ 144 .align 16 ; \ 145 .globl name ; \ 146 .type name, @function ; \ 147name ## : 148 149#define END(name) \ 150 .size name, . - name 151 152#endif /* !_MACHINE_ASMACROS_H_ */ 153