asmacros.h revision 89032
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 89032 2002-01-08 04:34:20Z 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 %xcc, 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 %xcc, 9b ; \ 74 mov r3, r2 75 76#define PCPU(member) %g7 + PC_ ## member 77#define PCPU_ADDR(member, reg) add %g7, PC_ ## member, reg 78 79#define DEBUGGER() ta %xcc, 1 80 81#define PANIC(msg, r1) \ 82 .sect .rodata ; \ 839: .asciz msg ; \ 84 .previous ; \ 85 SET(9b, r1, %o0) ; \ 86 call panic ; \ 87 nop 88 89#ifdef INVARIANTS 90#define KASSERT(r1, msg) \ 91 brnz r1, 8f ; \ 92 nop ; \ 93 PANIC(msg, r1) ; \ 948: 95#else 96#define KASSERT(r1, msg) 97#endif 98 99#define PUTS(msg, r1) \ 100 .sect .rodata ; \ 1019: .asciz msg ; \ 102 .previous ; \ 103 SET(9b, r1, %o0) ; \ 104 call printf ; \ 105 nop 106 107/* 108 * If the kernel can be located above 4G, setx needs to be used to load 109 * symbol values, otherwise set is sufficient. 110 */ 111#ifdef HIGH_KERNEL 112#define SET(sym, tmp, dst) \ 113 setx sym, tmp, dst 114#else 115#define SET(sym, tmp, dst) \ 116 set sym, dst 117#endif 118 119#endif /* LOCORE */ 120 121#endif /* _KERNEL */ 122 123#define DATA(name) \ 124 .data ; \ 125 .globl name ; \ 126 .type name, @object ; \ 127name ## : 128 129#define EMPTY 130 131#define ENTRY(name) \ 132 .text ; \ 133 .align 16 ; \ 134 .globl name ; \ 135 .type name, @function ; \ 136name ## : 137 138#define END(name) \ 139 .size name, . - name 140 141#endif /* !_MACHINE_ASMACROS_H_ */ 142