/* $NetBSD: asm.h,v 1.77 2025/01/06 10:46:43 martin Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)machAsmDefs.h 8.1 (Berkeley) 6/10/93
*/
/*
* machAsmDefs.h --
*
* Macros used when writing assembler programs.
*
* Copyright (C) 1989 Digital Equipment Corporation.
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appears in all copies.
* Digital Equipment Corporation makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* from: Header: /sprite/src/kernel/mach/ds3100.md/RCS/machAsmDefs.h,
* v 1.2 89/08/15 18:28:24 rab Exp SPRITE (DECWRL)
*/
#ifndef _MIPS_ASM_H
#define _MIPS_ASM_H
#include <sys/cdefs.h> /* for API selection */
#include <mips/regdef.h>
/*
* WEAK_ALIAS: create a weak alias.
*/
#define WEAK_ALIAS(alias,sym) \
.weak alias; \
alias = sym
/*
* STRONG_ALIAS: create a strong alias.
*/
#define STRONG_ALIAS(alias,sym) \
.globl alias; \
alias = sym
/*
* WARN_REFERENCES: create a warning if the specified symbol is referenced.
*/
#define WARN_REFERENCES(sym,msg) \
.pushsection __CONCAT(.gnu.warning.,sym); \
.ascii msg; \
.popsection
/*
* STATIC_LEAF_NOPROFILE
* No profilable local leaf routine.
*/
#define STATIC_LEAF_NOPROFILE(x) \
.ent _C_LABEL(x); \
_C_LABEL(x): ; \
.frame sp, 0, ra
/*
* STATIC_LEAF
* Declare a local leaf function.
*/
#define STATIC_LEAF(x) \
STATIC_LEAF_NOPROFILE(x); \
_MIPS_ASM_MCOUNT(x)
/*
* LEAF
* A leaf routine does
* - call no other function,
* - never use any register that callee-saved (S0-S8), and
* - not use any local stack storage.
*/
#define LEAF(x) \
LEAF_NOPROFILE(x); \
_MIPS_ASM_MCOUNT(x)
/*
* STATIC_XLEAF
* declare alternate entry to a static leaf routine
*/
#define STATIC_XLEAF(x) \
AENT (_C_LABEL(x)); \
_C_LABEL(x):
/*
* NESTED
* A function calls other functions and needs
* therefore stack space to save/restore registers.
*/
#define NESTED(x, fsize, retpc) \
NESTED_NOPROFILE(x, fsize, retpc); \
_MIPS_ASM_MCOUNT(x)
/*
* STATIC_NESTED
* No profilable local nested routine.
*/
#define STATIC_NESTED(x, fsize, retpc) \
STATIC_NESTED_NOPROFILE(x, fsize, retpc); \
_MIPS_ASM_MCOUNT(x)
/*
* EXPORT -- export definition of symbol
*/
#define EXPORT(x) \
.globl _C_LABEL(x); \
_C_LABEL(x):
/*
* EXPORT_OBJECT -- export definition of symbol of symbol
* type Object, visible to ksyms(4) address search.
*/
#define EXPORT_OBJECT(x) \
EXPORT(x); \
.type _C_LABEL(x), @object;
/*
* VECTOR
* exception vector entrypoint
* XXX: regmask should be used to generate .mask
*/
#define VECTOR(x, regmask) \
.ent _C_LABEL(x); \
EXPORT(x); \
/* compiler define */
#if defined(MULTIPROCESSOR) && defined(__OCTEON__)
/*
* See common/lib/libc/arch/mips/atomic/membar_ops.S for notes on
* Octeon memory ordering guarantees and barriers.
*
* cnMIPS also has a quirk where the store buffer can get clogged and
* we need to apply a plunger to it _after_ releasing a lock or else
* other CPUs may spin for hundreds of thousands of cycles before they
* see the lock is released. So we also have the quirky SYNC_PLUNGER
* barrier as syncw. See the note in the SYNCW instruction description
* on p. 2168 of Cavium OCTEON III CN78XX Hardware Reference Manual,
* CN78XX-HM-0.99E, September 2014:
*
* Core A (writer)
*
* SW R1, DATA# change shared DATA value
* LI R1, 1
* SYNCW# (or SYNCWS) Perform DATA store before performing FLAG store
* SW R2, FLAG# say that the shared DATA value is valid
* SYNCW# (or SYNCWS) Force the FLAG store soon (CN78XX-specific)
*
* ...
*
* The second SYNCW instruction executed by core A is not
* necessary for correctness, but has very important performance
* effects on the CN78XX. Without it, the store to FLAG may
* linger in core A's write buffer before it becomes visible to
* any other cores. (If core A is not performing many stores,
* this may add hundreds of thousands of cycles to the flag
* release time since the CN78XX core nominally retains stores to
* attempt to merge them before sending the store on the CMI.)
* Applications should include this second SYNCW instruction after
* flag or lock release.
*/
#define LLSCSYNC /* nothing */
#define BDSYNC sync
#define BDSYNC_ACQ nop
#define SYNC_ACQ /* nothing */
#define SYNC_REL sync 4
#define BDSYNC_PLUNGER sync 4
#define SYNC_PLUNGER sync 4
#elif defined(MULTIPROCESSOR) && (__mips >= 3 || !defined(__mips_o32))
#define LLSCSYNC /* nothing */
#define BDSYNC sync
#define BDSYNC_ACQ sync
#define SYNC_ACQ sync
#define SYNC_REL sync
#define BDSYNC_PLUNGER nop
#define SYNC_PLUNGER /* nothing */
#else
#define LLSCSYNC /* nothing */
#define BDSYNC nop
#define BDSYNC_ACQ nop
#define SYNC_ACQ /* nothing */
#define SYNC_REL /* nothing */
#define BDSYNC_PLUNGER nop
#define SYNC_PLUNGER /* nothing */
#endif
/*
* Store-before-load barrier. Do not use this unless you know what
* you're doing.
*/
#ifdef MULTIPROCESSOR
#define SYNC_DEKKER sync
#else
#define SYNC_DEKKER /* nothing */
#endif
/*
* Store-before-store and load-before-load barriers. These could be
* made weaker than release (load/store-before-store) and acquire
* (load-before-load/store) barriers, and newer MIPS does have
* instruction encodings for finer-grained barriers like this, but I
* dunno how to appropriately conditionalize their use or get the
* assembler to be happy with them, so we'll use these definitions for
* now.
*/
#define SYNC_PRODUCER SYNC_REL
#define SYNC_CONSUMER SYNC_ACQ
#if defined(__mips_n32) || defined(__mips_n64)
#define SETUP_GP /* o32 specific */
#define SETUP_GPX(r) /* o32 specific */
#define SETUP_GPX_L(r,lbl) /* o32 specific */
#define SAVE_GP(x) /* o32 specific */
#define SETUP_GP64(a,b) .cpsetup t9, a, b
#define SETUP_GPX64(a,b) \
.set push; \
move b,ra; \
.set noreorder; \
bal 7f; \
nop; \
7: .set pop; \
.cpsetup ra, a, 7b; \
move ra,b
#define SETUP_GPX64_L(a,b,c) \
.set push; \
move b,ra; \
.set noreorder; \
bal c; \
nop; \
c: .set pop; \
.cpsetup ra, a, c; \
move ra,b
#define RESTORE_GP64 .cpreturn
#define USE_ALT_CP(a) .cplocal a
#endif /* __mips_n32 || __mips_n64 */
/*
* The DYNAMIC_STATUS_MASK option adds an additional masking operation
* when updating the hardware interrupt mask in the status register.
*
* This is useful for platforms that need to at run-time mask
* interrupts based on motherboard configuration or to handle
* slowly clearing interrupts.
*
* XXX this is only currently implemented for mips3.
*/
#ifdef MIPS_DYNAMIC_STATUS_MASK
#define DYNAMIC_STATUS_MASK(sr,scratch) \
lw scratch, mips_dynamic_status_mask; \
and sr, sr, scratch