1*3dc08fb5Smartin /* $NetBSD: asm.h,v 1.11 2025/01/06 10:46:44 martin Exp $ */ 2ba7cbe76Scherry 3ba7cbe76Scherry /* - 4ba7cbe76Scherry * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University 5ba7cbe76Scherry * All Rights Reserved. 6ba7cbe76Scherry * 7ba7cbe76Scherry * Permission to use, copy, modify and distribute this software and its 8ba7cbe76Scherry * documentation is hereby granted, provided that both the copyright 9ba7cbe76Scherry * notice and this permission notice appear in all copies of the 10ba7cbe76Scherry * software, derivative works or modified versions, and any portions 11ba7cbe76Scherry * thereof, and that both notices appear in supporting documentation. 12ba7cbe76Scherry * 13ba7cbe76Scherry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14ba7cbe76Scherry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 15ba7cbe76Scherry * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 16ba7cbe76Scherry * 17ba7cbe76Scherry * Carnegie Mellon requests users of this software to return to 18ba7cbe76Scherry * 19ba7cbe76Scherry * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 20ba7cbe76Scherry * School of Computer Science 21ba7cbe76Scherry * Carnegie Mellon University 22ba7cbe76Scherry * Pittsburgh PA 15213-3890 23ba7cbe76Scherry * 24ba7cbe76Scherry * any improvements or extensions that they make and grant Carnegie Mellon 25ba7cbe76Scherry * the rights to redistribute these changes. 26ba7cbe76Scherry */ 27ba7cbe76Scherry 28ba7cbe76Scherry /* 29ba7cbe76Scherry * Assembly coding style 30ba7cbe76Scherry * 31ba7cbe76Scherry * This file contains macros and register defines to 32ba7cbe76Scherry * aid in writing more readable assembly code. 33ba7cbe76Scherry * Some rules to make assembly code understandable by 34ba7cbe76Scherry * a debugger are also noted. 35ba7cbe76Scherry */ 36ba7cbe76Scherry 37890122a3Skiyohara #define _C_LABEL(x) x 38890122a3Skiyohara 39ba7cbe76Scherry /* 40ba7cbe76Scherry * Macro to make a local label name. 41ba7cbe76Scherry */ 42ba7cbe76Scherry #define LLABEL(name,num) L ## name ## num 43ba7cbe76Scherry 44ba7cbe76Scherry /* 45ba7cbe76Scherry * MCOUNT 46ba7cbe76Scherry */ 47ba7cbe76Scherry #if defined(GPROF) 48ba7cbe76Scherry #define MCOUNT \ 49ba7cbe76Scherry alloc out0 = ar.pfs, 8, 0, 4, 0; \ 50ba7cbe76Scherry mov out1 = r1; \ 51ba7cbe76Scherry mov out2 = b0;; \ 52ba7cbe76Scherry mov out3 = r0; \ 53ba7cbe76Scherry br.call.sptk b0 = _mcount;; 54ba7cbe76Scherry #else 55ba7cbe76Scherry #define MCOUNT /* nothing */ 56ba7cbe76Scherry #endif 57ba7cbe76Scherry 58ba7cbe76Scherry /* 59ba7cbe76Scherry * ENTRY 60ba7cbe76Scherry * Declare a global leaf function. 61ba7cbe76Scherry * A leaf function does not call other functions. 62ba7cbe76Scherry */ 63ba7cbe76Scherry #define ENTRY(_name_, _n_args_) \ 64ba7cbe76Scherry .global _name_; \ 65ba7cbe76Scherry .align 16; \ 66ba7cbe76Scherry .proc _name_; \ 67ba7cbe76Scherry _name_:; \ 68ba7cbe76Scherry .regstk _n_args_, 0, 0, 0; \ 69ba7cbe76Scherry MCOUNT 70ba7cbe76Scherry 71ba7cbe76Scherry #define ENTRY_NOPROFILE(_name_, _n_args_) \ 72ba7cbe76Scherry .global _name_; \ 73ba7cbe76Scherry .align 16; \ 74ba7cbe76Scherry .proc _name_; \ 75ba7cbe76Scherry _name_:; \ 76ba7cbe76Scherry .regstk _n_args_, 0, 0, 0 77ba7cbe76Scherry 78ba7cbe76Scherry /* 79ba7cbe76Scherry * STATIC_ENTRY 80ba7cbe76Scherry * Declare a local leaf function. 81ba7cbe76Scherry */ 82ba7cbe76Scherry #define STATIC_ENTRY(_name_, _n_args_) \ 83ba7cbe76Scherry .align 16; \ 84ba7cbe76Scherry .proc _name_; \ 85ba7cbe76Scherry _name_:; \ 86ba7cbe76Scherry .regstk _n_args_, 0, 0, 0 \ 87ba7cbe76Scherry MCOUNT 88ba7cbe76Scherry /* 89ba7cbe76Scherry * XENTRY 90ba7cbe76Scherry * Global alias for a leaf function, or alternate entry point 91ba7cbe76Scherry */ 92ba7cbe76Scherry #define XENTRY(_name_) \ 93ba7cbe76Scherry .globl _name_; \ 94ba7cbe76Scherry _name_: 95ba7cbe76Scherry 96ba7cbe76Scherry /* 97ba7cbe76Scherry * STATIC_XENTRY 98ba7cbe76Scherry * Local alias for a leaf function, or alternate entry point 99ba7cbe76Scherry */ 100ba7cbe76Scherry #define STATIC_XENTRY(_name_) \ 101ba7cbe76Scherry _name_: 102ba7cbe76Scherry 103ba7cbe76Scherry 104ba7cbe76Scherry /* 105ba7cbe76Scherry * END 106ba7cbe76Scherry * Function delimiter 107ba7cbe76Scherry */ 108ba7cbe76Scherry #define END(_name_) \ 109ba7cbe76Scherry .endp _name_ 110ba7cbe76Scherry 111ba7cbe76Scherry 112ba7cbe76Scherry /* 113ba7cbe76Scherry * EXPORT 114ba7cbe76Scherry * Export a symbol 115ba7cbe76Scherry */ 116ba7cbe76Scherry #define EXPORT(_name_) \ 117ba7cbe76Scherry .global _name_; \ 118ba7cbe76Scherry _name_: 119ba7cbe76Scherry 120ba7cbe76Scherry 121ba7cbe76Scherry /* 122ba7cbe76Scherry * IMPORT 123ba7cbe76Scherry * Make an external name visible, typecheck the size 124ba7cbe76Scherry */ 125ba7cbe76Scherry #define IMPORT(_name_, _size_) \ 126ba7cbe76Scherry /* .extern _name_,_size_ */ 127ba7cbe76Scherry 128ba7cbe76Scherry 129ba7cbe76Scherry /* 130ba7cbe76Scherry * ABS 131ba7cbe76Scherry * Define an absolute symbol 132ba7cbe76Scherry */ 133ba7cbe76Scherry #define ABS(_name_, _value_) \ 134ba7cbe76Scherry .globl _name_; \ 135ba7cbe76Scherry _name_ = _value_ 136ba7cbe76Scherry 137ba7cbe76Scherry 138ba7cbe76Scherry /* 139ba7cbe76Scherry * BSS 140ba7cbe76Scherry * Allocate un-initialized space for a global symbol 141ba7cbe76Scherry */ 142ba7cbe76Scherry #define BSS(_name_,_numbytes_) \ 143ba7cbe76Scherry .comm _name_,_numbytes_ 144ba7cbe76Scherry 145ba7cbe76Scherry 146ba7cbe76Scherry /* 147ba7cbe76Scherry * MSG 148ba7cbe76Scherry * Allocate space for a message (a read-only ascii string) 149ba7cbe76Scherry */ 150ba7cbe76Scherry #define ASCIZ .asciz 151ba7cbe76Scherry #define MSG(msg,reg,label) \ 152ba7cbe76Scherry addl reg,@ltoff(label),gp;; \ 153ba7cbe76Scherry ld8 reg=[reg];; \ 154ba7cbe76Scherry .data; \ 155ba7cbe76Scherry label: ASCIZ msg; \ 156ba7cbe76Scherry .text; 157ba7cbe76Scherry 158ba7cbe76Scherry 159ba7cbe76Scherry /* 160ba7cbe76Scherry * System call glue. 161ba7cbe76Scherry */ 1628e4670daScherry #define SYSCALLNUM(name) ___CONCAT(SYS_,name) 163ba7cbe76Scherry 164ba7cbe76Scherry #define CALLSYS_NOERROR(name) \ 165ba7cbe76Scherry { .mmi ; \ 166ba7cbe76Scherry alloc r9 = ar.pfs, 0, 0, 8, 0 ; \ 167ba7cbe76Scherry mov r31 = ar.k5 ; \ 168ba7cbe76Scherry mov r10 = b0 ;; } \ 169ba7cbe76Scherry { .mib ; \ 170ba7cbe76Scherry mov r8 = SYSCALLNUM(name) ; \ 171ba7cbe76Scherry mov b7 = r31 ; \ 172ba7cbe76Scherry br.call.sptk b0 = b7 ;; } 173ba7cbe76Scherry 174ba7cbe76Scherry 175ba7cbe76Scherry /* 176ba7cbe76Scherry * WEAK_ALIAS: create a weak alias (ELF only). 177ba7cbe76Scherry */ 178ba7cbe76Scherry #define WEAK_ALIAS(alias,sym) \ 179ba7cbe76Scherry .weak alias; \ 180ba7cbe76Scherry alias = sym 181ba7cbe76Scherry 1828e4670daScherry /* 1838e4670daScherry * STRONG_ALIAS: create a strong alias. 1848e4670daScherry */ 1858e4670daScherry #define STRONG_ALIAS(alias,sym) \ 1868e4670daScherry .globl alias; \ 1878e4670daScherry alias = sym 188738b90f6Smartin 189738b90f6Smartin /* 190738b90f6Smartin * WARN_REFERENCES: create a warning if the specified symbol is referenced. 191738b90f6Smartin */ 192738b90f6Smartin #ifdef __STDC__ 193738b90f6Smartin #define WARN_REFERENCES(sym,msg) \ 194738b90f6Smartin .pushsection .gnu.warning. ## sym; \ 195738b90f6Smartin .ascii msg; \ 196738b90f6Smartin .popsection 197738b90f6Smartin #else 198738b90f6Smartin #define WARN_REFERENCES(sym,msg) \ 199738b90f6Smartin .pushsection .gnu.warning./**/sym; \ 200738b90f6Smartin .ascii msg; \ 201738b90f6Smartin .popsection 202738b90f6Smartin #endif /* __STDC__ */ 203738b90f6Smartin 204738b90f6Smartin 2050131c6b6Scherry #ifdef __ELF__ 2064f6e58e2Smartin #ifdef _NETBSD_REVISIONID 2074f6e58e2Smartin #define RCSID(x) .pushsection ".ident","MS",@progbits,1; \ 208*3dc08fb5Smartin .asciz x; \ 209*3dc08fb5Smartin .ascii "$"; .ascii "NetBSD: "; .ascii __FILE__; \ 210*3dc08fb5Smartin .ascii " "; .ascii _NETBSD_REVISIONID; \ 211*3dc08fb5Smartin .asciz " $"; \ 2124f6e58e2Smartin .popsection 2134f6e58e2Smartin #else 214628289e3Sjoerg #define RCSID(x) .pushsection ".ident","MS",@progbits,1; \ 215628289e3Sjoerg .asciz x; \ 216628289e3Sjoerg .popsection 2174f6e58e2Smartin #endif 2180131c6b6Scherry #else 2190131c6b6Scherry #define RCSID(name) .asciz name 2200131c6b6Scherry #endif 2210131c6b6Scherry 222738b90f6Smartin /* 223738b90f6Smartin * Kernel RCS ID tag and copyright macros 224738b90f6Smartin */ 225738b90f6Smartin 226738b90f6Smartin #ifdef _KERNEL 227738b90f6Smartin 228738b90f6Smartin #define __KERNEL_SECTIONSTRING(_sec, _str) \ 229738b90f6Smartin .pushsection _sec ; .asciz _str ; .popsection 230738b90f6Smartin 2314f6e58e2Smartin #ifdef _NETBSD_REVISIONID 2324f6e58e2Smartin #define __KERNEL_RCSID(_n, _s) __KERNEL_SECTIONSTRING(.ident, \ 2334f6e58e2Smartin "$" "NetBSD: " __FILE__ " " \ 2344f6e58e2Smartin _NETBSD_REVISIONID " $") 2354f6e58e2Smartin #else 236738b90f6Smartin #define __KERNEL_RCSID(_n, _s) __KERNEL_SECTIONSTRING(.ident, _s) 2374f6e58e2Smartin #endif 238738b90f6Smartin #define __KERNEL_COPYRIGHT(_n, _s) __KERNEL_SECTIONSTRING(.copyright, _s) 239738b90f6Smartin 240738b90f6Smartin #ifdef NO_KERNEL_RCSIDS 241738b90f6Smartin #undef __KERNEL_RCSID 242738b90f6Smartin #define __KERNEL_RCSID(_n, _s) /* nothing */ 243738b90f6Smartin #endif 244738b90f6Smartin 245738b90f6Smartin #endif /* _KERNEL */ 246