1 /* $NetBSD: asm.h,v 1.29 2006/01/20 22:02:40 christos Exp $ */
4 * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
29 * Assembly coding style
31 * This file contains macros and register defines to
32 * aid in writing more readable assembly code.
33 * Some rules to make assembly code understandable by
34 * a debugger are also noted.
38 * "ALPHA Calling Standard", DEC 27-Apr-90
40 * defines (a superset of) the rules and conventions
41 * we use. While we make no promise of adhering to
42 * such standard and its evolution (esp where we
43 * can get faster code paths) it is certainly intended
44 * that we be interoperable with such standard.
46 * In this sense, this file is a proper part of the
47 * definition of the (software) Alpha architecture.
51 * Symbolic register names and register saving rules
54 * T Saved by caller (Temporaries)
55 * S Saved by callee (call-Safe registers)
58 #define v0 $0 /* (T) return value */
59 #define t0 $1 /* (T) temporary registers */
68 #define s0 $9 /* (S) call-safe registers */
75 #define a0 $16 /* (T) argument registers */
81 #define t8 $22 /* (T) temporary registers */
85 #define ra $26 /* (S) return address */
86 #define t12 $27 /* (T) another temporary */
87 #define at_reg $28 /* (T) assembler scratch */
88 #define gp $29 /* (T) (local) data pointer */
89 #define sp $30 /* (S) stack pointer */
90 #define zero $31 /* wired zero */
92 /* Floating point registers (XXXX VERIFY THIS) */
93 #define fv0 $f0 /* (T) return value (real) */
94 #define fv1 $f1 /* (T) return value (imaginary)*/
96 #define fs0 $f2 /* (S) call-safe registers */
104 #define ft1 $f10 /* (T) temporary registers */
110 #define fa0 $f16 /* (T) argument registers */
116 #define ft7 $f22 /* (T) more temporaries */
125 #define fzero $f31 /* wired zero */
128 /* Other DEC standard names */
129 #define ai $25 /* (T) argument information */
130 #define pv $27 /* (T) procedure value */
137 #define __CONCAT(a,b) a ## b
139 #define __CONCAT(a,b) a/**/b
141 #define ___CONCAT(a,b) __CONCAT(a,b)
144 * Macro to make a local label name.
146 #define LLABEL(name,num) ___CONCAT(___CONCAT(L,name),num)
150 * Debuggers need symbol table information to be able to properly
151 * decode a stack trace. The minimum that should be provided is:
156 * where "name" is the function's name;
157 * "numargs" how many arguments it expects. For varargs
158 * procedures this should be a negative number,
159 * indicating the minimum required number of
160 * arguments (which is at least 1);
162 * NESTED functions (functions that call other functions) should define
163 * how they handle their stack frame in a .frame directive:
165 * .frame framesize, pc_reg, i_mask, f_mask
167 * where "framesize" is the size of the frame for this function, in bytes.
169 * new_sp + framesize == old_sp
170 * Framesizes should be rounded to a cacheline size.
171 * Note that old_sp plays the role of a conventional
173 * "pc_reg" is either a register which preserves the caller's PC
174 * or 'std', if std the saved PC should be stored at
176 * "i_mask" is a bitmask that indicates which of the integer
177 * registers are saved. See the M_xx defines at the
178 * end for the encoding of this 32bit value.
179 * "f_mask" is the same, for floating point registers.
181 * Note, 10/31/97: This is interesting but it isn't the way gcc outputs
182 * frame directives and it isn't the way the macros below output them
183 * either. Frame directives look like this:
185 * .frame $15,framesize,$26,0
187 * If no fp is set up then $30 should be used instead of $15.
188 * Also, gdb expects to find a <lda sp,-framesize(sp)> at the beginning
189 * of a procedure. Don't use things like sub sp,framesize,sp for this
190 * reason. End Note 10/31/97. ross@NetBSD.org
192 * Note that registers should be saved starting at "old_sp-8", where the
193 * return address should be stored. Other registers follow at -16-24-32..
194 * starting from register 0 (if saved) and up. Then float registers (ifany)
197 * If you need to alias a leaf function, or to provide multiple entry points
198 * use the LEAF() macro for the main entry point and XLEAF() for the other
199 * additional/alternate entry points.
200 * "XLEAF"s must be nested within a "LEAF" and a ".end".
201 * Similar rules for nested routines, e.g. use NESTED/XNESTED
202 * Symbols that should not be exported can be declared with the STATIC_xxx
205 * All functions must be terminated by the END macro
207 * It is conceivable, although currently at the limits of compiler
208 * technology, that while performing inter-procedural optimizations
209 * the compiler/linker be able to avoid unnecessary register spills
210 * if told about the register usage of LEAF procedures (and by transitive
211 * closure of NESTED procedures as well). Assembly code can help
212 * this process using the .reguse directive:
214 * .reguse i_mask, f_mask
216 * where the register masks are built as above or-ing M_xx defines.
219 * All symbols are internal unless EXPORTed. Symbols that are IMPORTed
220 * must be appropriately described to the debugger.
229 #define MCOUNT /* nothing */
233 jsr at_reg,_mcount; \
237 * PALVECT, ESETUP, and ERSAVE
238 * Declare a palcode transfer point, and carefully construct
239 * gdb symbols with an unusual _negative_ register-save offset
240 * so that gdb can find the otherwise lost PC and then
241 * invert the vector for traceback. Also, fix up framesize,
242 * allowing for the palframe for the same reason.
245 #define PALVECT(_name_) \
249 #define ESETUP(_name_) \
250 /* .loc 1 __LINE__; */ \
255 lda sp,-(FRAME_SW_SIZE*8)(sp); \
256 .frame $30,(FRAME_SW_SIZE+6)*8,$26,0; /* give gdb the real size */\
257 .mask 0x4000000,-0x28; \
262 stq at_reg,(FRAME_AT*8)(sp); \
264 stq ra,(FRAME_RA*8)(sp); \
265 /* .loc 1 __LINE__; */ \
266 bsr ra,exception_save_regs /* jmp/CALL trashes pv/t12 */
271 * Declare a global leaf function.
272 * A leaf function does not call other functions AND does not
273 * use any register that is callee-saved AND does not modify
276 #define LEAF(_name_,_n_args_) \
283 .proc _name_,_n_args_; \
287 #define LEAF_NOPROFILE(_name_,_n_args_) \
293 .proc _name_,_n_args_; \
299 * Declare a local leaf function.
301 #define STATIC_LEAF(_name_,_n_args_) \
307 .proc _name_,_n_args_; \
312 * Global alias for a leaf function, or alternate entry point
314 #define XLEAF(_name_,_n_args_) \
319 .aproc _name_,_n_args_;
324 * Local alias for a leaf function, or alternate entry point
326 #define STATIC_XLEAF(_name_,_n_args_) \
330 .aproc _name_,_n_args_;
335 * Declare a (global) nested function
336 * A nested function calls other functions and needs
337 * therefore stack space to save/restore registers.
339 #define NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
343 .frame sp,_framesize_,_pc_reg_; \
344 .livereg _i_mask_,_f_mask_; \
347 .proc _name_,_n_args_; \
348 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
351 #define NESTED_NOPROFILE(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
355 .frame sp,_framesize_,_pc_reg_; \
356 .livereg _i_mask_,_f_mask_
358 .proc _name_,_n_args_; \
359 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
364 * Declare a local nested function.
366 #define STATIC_NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
369 .frame sp,_framesize_,_pc_reg_; \
370 .livereg _i_mask_,_f_mask_; \
373 .proc _name_,_n_args_; \
374 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
379 * Same as XLEAF, for a nested function.
381 #define XNESTED(_name_,_n_args_) \
386 .aproc _name_,_n_args_;
392 * Same as STATIC_XLEAF, for a nested function.
394 #define STATIC_XNESTED(_name_,_n_args_) \
398 .aproc _name_,_n_args_;
406 #define END(_name_) \
412 * Function invocation
414 #define CALL(_name_) \
415 /* .loc 1 __LINE__; */ \
418 /* but this would cover longer jumps
426 * Return from function
436 #define EXPORT(_name_) \
443 * Make an external name visible, typecheck the size
445 #define IMPORT(_name_, _size_) \
446 .extern _name_,_size_
451 * Define an absolute symbol
453 #define ABS(_name_, _value_) \
460 * Allocate un-initialized space for a global symbol
462 #define BSS(_name_,_numbytes_) \
463 .comm _name_,_numbytes_
467 * Make an exception entry point look like a called function,
468 * to make it digestible to the debugger (KERNEL only)
470 #define VECTOR(_name_, _i_mask_) \
474 .mask _i_mask_|IM_EXC,0; \
475 .frame sp,MSS_SIZE,ra;
476 /* .livereg _i_mask_|IM_EXC,0 */
479 .frame MSS_SIZE,$31,_i_mask_,0; \
484 * Allocate space for a message (a read-only ascii string)
487 #define MSG(msg,reg,label) \
497 #define PRINTF(msg,label) \
503 * Fatal error (KERNEL)
505 #define PANIC(msg,label) \
510 * Register mask defines, used to define both save
511 * and use register sets.
513 * NOTE: The bit order should HAVE BEEN maintained when saving
514 * registers on the stack: sp goes at the highest
515 * address, gp lower on the stack, etc etc
516 * BUT NOONE CARES ABOUT DEBUGGERS AT MIPS
519 #define IM_EXC 0x80000000
520 #define IM_SP 0x40000000
521 #define IM_GP 0x20000000
522 #define IM_AT 0x10000000
523 #define IM_T12 0x08000000
525 #define IM_RA 0x04000000
526 #define IM_T11 0x02000000
528 #define IM_T10 0x01000000
529 #define IM_T9 0x00800000
530 #define IM_T8 0x00400000
531 #define IM_A5 0x00200000
532 #define IM_A4 0x00100000
533 #define IM_A3 0x00080000
534 #define IM_A2 0x00040000
535 #define IM_A1 0x00020000
536 #define IM_A0 0x00010000
537 #define IM_S6 0x00008000
538 #define IM_S5 0x00004000
539 #define IM_S4 0x00002000
540 #define IM_S3 0x00001000
541 #define IM_S2 0x00000800
542 #define IM_S1 0x00000400
543 #define IM_S0 0x00000200
544 #define IM_T7 0x00000100
545 #define IM_T6 0x00000080
546 #define IM_T5 0x00000040
547 #define IM_T4 0x00000020
548 #define IM_T3 0x00000010
549 #define IM_T2 0x00000008
550 #define IM_T1 0x00000004
551 #define IM_T0 0x00000002
552 #define IM_V0 0x00000001
554 #define FM_T15 0x40000000
555 #define FM_T14 0x20000000
556 #define FM_T13 0x10000000
557 #define FM_T12 0x08000000
558 #define FM_T11 0x04000000
559 #define FM_T10 0x02000000
560 #define FM_T9 0x01000000
561 #define FM_T8 0x00800000
562 #define FM_T7 0x00400000
563 #define FM_A5 0x00200000
564 #define FM_A4 0x00100000
565 #define FM_A3 0x00080000
566 #define FM_A2 0x00040000
567 #define FM_A1 0x00020000
568 #define FM_A0 0x00010000
569 #define FM_T6 0x00008000
570 #define FM_T5 0x00004000
571 #define FM_T4 0x00002000
572 #define FM_T3 0x00001000
573 #define FM_T2 0x00000800
574 #define FM_T1 0x00000400
575 #define FM_S7 0x00000200
576 #define FM_S6 0x00000100
577 #define FM_S5 0x00000080
578 #define FM_S4 0x00000040
579 #define FM_S3 0x00000020
580 #define FM_S2 0x00000010
581 #define FM_S1 0x00000008
582 #define FM_S0 0x00000004
583 #define FM_T0 0x00000002
585 #define FM_V0 0x00000001
587 /* Pull in PAL "function" codes. */
588 #include <machine/pal.h>
593 #define SYSCALLNUM(name) \
596 #define CALLSYS_NOERROR(name) \
597 ldiq v0, SYSCALLNUM(name); \
598 call_pal PAL_OSF1_callsys
600 #define LINUX_SYSCALLNUM(name) \
601 ___CONCAT(LINUX_SYS_,name)
603 #define LINUX_CALLSYS_NOERROR(name) \
604 ldiq v0, LINUX_SYSCALLNUM(name); \
605 call_pal PAL_OSF1_callsys
608 * Load the global pointer.
614 * WEAK_ALIAS: create a weak alias.
616 #define WEAK_ALIAS(alias,sym) \
621 * STRONG_ALIAS: create a strong alias.
623 #define STRONG_ALIAS(alias,sym) \
628 * WARN_REFERENCES: create a warning if the specified symbol is referenced.
631 #define WARN_REFERENCES(_sym,_msg) \
632 .section .gnu.warning. ## _sym ; .ascii _msg ; .text
634 #define WARN_REFERENCES(_sym,_msg) \
635 .section .gnu.warning./**/_sym ; .ascii _msg ; .text
636 #endif /* __STDC__ */
639 * Kernel RCS ID tag and copyright macros
644 #define __KERNEL_SECTIONSTRING(_sec, _str) \
645 .section _sec ; .asciz _str ; .text
647 #define __KERNEL_RCSID(_n, _s) __KERNEL_SECTIONSTRING(.ident, _s)
648 #define __KERNEL_COPYRIGHT(_n, _s) __KERNEL_SECTIONSTRING(.copyright, _s)
650 #ifdef NO_KERNEL_RCSIDS
651 #undef __KERNEL_RCSID
652 #define __KERNEL_RCSID(_n, _s) /* nothing */
655 #if defined(MULTIPROCESSOR)
658 * Get various per-cpu values. A pointer to our cpu_info structure
659 * is stored in SysValue. These macros clobber v0, t0, t8..t11.
661 * All return values are in v0.
663 #define GET_CPUINFO call_pal PAL_OSF1_rdval
666 call_pal PAL_OSF1_rdval ; \
667 addq v0, CPU_INFO_CURLWP, v0
669 #define GET_FPCURLWP \
670 call_pal PAL_OSF1_rdval ; \
671 addq v0, CPU_INFO_FPCURLWP, v0
674 call_pal PAL_OSF1_rdval ; \
675 addq v0, CPU_INFO_CURPCB, v0
677 #define GET_IDLE_PCB(reg) \
678 call_pal PAL_OSF1_rdval ; \
679 ldq reg, CPU_INFO_IDLE_PCB_PADDR(v0)
681 #else /* if not MULTIPROCESSOR... */
683 IMPORT(cpu_info_primary
, CPU_INFO_SIZEOF
)
685 #define GET_CPUINFO lda v0, cpu_info_primary
687 #define GET_CURLWP lda v0, cpu_info_primary + CPU_INFO_CURLWP
689 #define GET_FPCURLWP lda v0, cpu_info_primary + CPU_INFO_FPCURLWP
691 #define GET_CURPCB lda v0, cpu_info_primary + CPU_INFO_CURPCB
693 #define GET_IDLE_PCB(reg) \
694 lda reg, cpu_info_primary ; \
695 ldq reg, CPU_INFO_IDLE_PCB_PADDR(reg)