asmacros.h revision 225887
180709Sjake/*- 280709Sjake * Copyright (c) 2001 Jake Burkholder. 380709Sjake * All rights reserved. 480709Sjake * 580709Sjake * Redistribution and use in source and binary forms, with or without 680709Sjake * modification, are permitted provided that the following conditions 780709Sjake * are met: 880709Sjake * 1. Redistributions of source code must retain the above copyright 980709Sjake * notice, this list of conditions and the following disclaimer. 1080709Sjake * 2. Redistributions in binary form must reproduce the above copyright 1180709Sjake * notice, this list of conditions and the following disclaimer in the 1280709Sjake * documentation and/or other materials provided with the distribution. 1380709Sjake * 1481334Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1580709Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1680709Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1781334Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1880709Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1980709Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2080709Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2180709Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2280709Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2380709Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2480709Sjake * SUCH DAMAGE. 2580709Sjake * 2680709Sjake * $FreeBSD: head/sys/sparc64/include/asmacros.h 225887 2011-09-30 20:13:51Z marius $ 2780709Sjake */ 2880709Sjake 2980709Sjake#ifndef _MACHINE_ASMACROS_H_ 3080709Sjake#define _MACHINE_ASMACROS_H_ 3180709Sjake 3280709Sjake#ifdef _KERNEL 3380709Sjake 3488616Sjake/* 3589032Sjake * Normal and alternate %g6 point to the pcb of the current process. Normal, 36216802Smarius * alternate and interrupt %g7 point to per-cpu data. 3788616Sjake */ 3889032Sjake#define PCB_REG %g6 3988616Sjake#define PCPU_REG %g7 4081893Sjake 4188616Sjake/* 4289032Sjake * Alternate %g5 points to a per-cpu panic stack, which is used as a last 4389032Sjake * resort, and for temporarily saving alternate globals. 4488616Sjake */ 4588616Sjake#define ASP_REG %g5 4688616Sjake 4789032Sjake#ifdef LOCORE 4889032Sjake 4988616Sjake/* 5089032Sjake * Atomically decrement an integer in memory. 5188616Sjake */ 52225886Smarius#define ATOMIC_DEC_INT(r1, r2, r3) \ 53225886Smarius lduw [r1], r2 ; \ 54225886Smarius9: sub r2, 1, r3 ; \ 55225886Smarius casa [r1] ASI_N, r2, r3 ; \ 56225886Smarius cmp r2, r3 ; \ 57225886Smarius bne,pn %icc, 9b ; \ 5889032Sjake mov r3, r2 5988616Sjake 6089032Sjake/* 6189032Sjake * Atomically increment an integer in memory. 6289032Sjake */ 63225886Smarius#define ATOMIC_INC_INT(r1, r2, r3) \ 64225886Smarius lduw [r1], r2 ; \ 65225886Smarius9: add r2, 1, r3 ; \ 66225886Smarius casa [r1] ASI_N, r2, r3 ; \ 67225886Smarius cmp r2, r3 ; \ 68225886Smarius bne,pn %icc, 9b ; \ 6989032Sjake mov r3, r2 7089032Sjake 7192198Sjake/* 72225886Smarius * Atomically increment a long in memory. 73117658Sjmg */ 74225886Smarius#define ATOMIC_INC_LONG(r1, r2, r3) \ 75225886Smarius ldx [r1], r2 ; \ 76225886Smarius9: add r2, 1, r3 ; \ 77225886Smarius casxa [r1] ASI_N, r2, r3 ; \ 78225886Smarius cmp r2, r3 ; \ 79225887Smarius bne,pn %xcc, 9b ; \ 80117658Sjmg mov r3, r2 81117658Sjmg 82117658Sjmg/* 8392198Sjake * Atomically clear a number of bits of an integer in memory. 8492198Sjake */ 85225886Smarius#define ATOMIC_CLEAR_INT(r1, r2, r3, bits) \ 86225886Smarius lduw [r1], r2 ; \ 87225886Smarius9: andn r2, bits, r3 ; \ 88225886Smarius casa [r1] ASI_N, r2, r3 ; \ 89225886Smarius cmp r2, r3 ; \ 90225886Smarius bne,pn %icc, 9b ; \ 9192198Sjake mov r3, r2 9292198Sjake 93221750Smarius/* 94225886Smarius * Atomically clear a number of bits of a long in memory. 95221750Smarius */ 96225886Smarius#define ATOMIC_CLEAR_LONG(r1, r2, r3, bits) \ 97225886Smarius ldx [r1], r2 ; \ 98225886Smarius9: andn r2, bits, r3 ; \ 99225886Smarius casxa [r1] ASI_N, r2, r3 ; \ 100225886Smarius cmp r2, r3 ; \ 101225886Smarius bne,pn %icc, 9b ; \ 102221750Smarius mov r3, r2 103221750Smarius 10497262Sjake#define PCPU(member) PCPU_REG + PC_ ## member 105225886Smarius#define PCPU_ADDR(member, reg) \ 10697262Sjake add PCPU_REG, PC_ ## member, reg 10784176Sjake 108225886Smarius#define DEBUGGER() \ 10997262Sjake ta %xcc, 1 11084176Sjake 111225886Smarius#define PANIC(msg, r1) \ 112225886Smarius .sect .rodata ; \ 113225886Smarius9: .asciz msg ; \ 114225886Smarius .previous ; \ 115225886Smarius SET(9b, r1, %o0) ; \ 116225886Smarius call panic ; \ 11780709Sjake nop 11880709Sjake 11989032Sjake#ifdef INVARIANTS 120225886Smarius#define KASSERT(r1, msg) \ 121225886Smarius brnz,pt r1, 8f ; \ 122225886Smarius nop ; \ 123225886Smarius PANIC(msg, r1) ; \ 12489032Sjake8: 12589032Sjake#else 12689032Sjake#define KASSERT(r1, msg) 12789032Sjake#endif 12889032Sjake 129225886Smarius#define PUTS(msg, r1) \ 130225886Smarius .sect .rodata ; \ 131225886Smarius9: .asciz msg ; \ 132225886Smarius .previous ; \ 133225886Smarius SET(9b, r1, %o0) ; \ 134225886Smarius call printf ; \ 13588616Sjake nop 13688616Sjake 137100840Sjake#define _ALIGN_DATA .align 8 138100840Sjake 139225886Smarius#define DATA(name) \ 140225886Smarius .data ; \ 141225886Smarius _ALIGN_DATA ; \ 142225886Smarius .globl name ; \ 143225886Smarius .type name, @object ; \ 144114071Sobrienname: 14580709Sjake 14680709Sjake#define EMPTY 14780709Sjake 148216802Smarius/* 149216802Smarius * Generate atomic compare and swap, load and store instructions for the 150216802Smarius * corresponding width and ASI (or not). Note that we want to evaluate the 151216802Smarius * macro args before concatenating, so that EMPTY really turns into nothing. 152216802Smarius */ 153216802Smarius#define _LD(w, a) ld ## w ## a 154216802Smarius#define _ST(w, a) st ## w ## a 155216802Smarius#define _CAS(w, a) cas ## w ## a 156216802Smarius 157216802Smarius#define LD(w, a) _LD(w, a) 158216802Smarius#define ST(w, a) _ST(w, a) 159216802Smarius#define CAS(w, a) _CAS(w, a) 160216802Smarius 16192213Sjake#endif /* LOCORE */ 16292213Sjake 16392213Sjake#endif /* _KERNEL */ 16492213Sjake 16580709Sjake#endif /* !_MACHINE_ASMACROS_H_ */ 166