2 /* From: NetBSD: asm.h,v 1.18 1997/11/03 04:22:06 ross Exp */
5 * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
30 * Assembly coding style
32 * This file contains macros and register defines to
33 * aid in writing more readable assembly code.
34 * Some rules to make assembly code understandable by
35 * a debugger are also noted.
39 * "ALPHA Calling Standard", DEC 27-Apr-90
41 * defines (a superset of) the rules and conventions
42 * we use. While we make no promise of adhering to
43 * such standard and its evolution (esp where we
44 * can get faster code paths) it is certainly intended
45 * that we be interoperable with such standard.
47 * In this sense, this file is a proper part of the
48 * definition of the (software) Alpha architecture.
52 * Symbolic register names and register saving rules
55 * T Saved by caller (Temporaries)
56 * S Saved by callee (call-Safe registers)
59 #define v0 $0 /* (T) return value */
60 #define t0 $1 /* (T) temporary registers */
69 #define s0 $9 /* (S) call-safe registers */
76 #define a0 $16 /* (T) argument registers */
82 #define t8 $22 /* (T) temporary registers */
86 #define ra $26 /* (T) return address */
87 #define t12 $27 /* (T) another temporary */
88 #define at_reg $28 /* (T) assembler scratch */
89 #define gp $29 /* (T) (local) data pointer */
90 #define sp $30 /* (S) stack pointer */
91 #define zero $31 /* wired zero */
93 /* Floating point registers (XXXX VERIFY THIS) */
94 #define fv0 $f0 /* (T) return value (real) */
95 #define fv1 $f1 /* (T) return value (imaginary)*/
97 #define fs0 $f2 /* (S) call-safe registers */
105 #define ft1 $f10 /* (T) temporary registers */
111 #define fa0 $f16 /* (T) argument registers */
117 #define ft7 $f22 /* (T) more temporaries */
126 #define fzero $f31 /* wired zero */
129 /* Other DEC standard names */
130 #define ai $25 /* (T) argument information */
131 #define pv $27 /* (T) procedure value */
138 #define __CONCAT(a,b) a ## b
140 #define __CONCAT(a,b) a/**/b
142 #define ___CONCAT(a,b) __CONCAT(a,b)
145 * Macro to make a local label name.
147 #define LLABEL(name,num) ___CONCAT(___CONCAT(L,name),num)
151 * Debuggers need symbol table information to be able to properly
152 * decode a stack trace. The minimum that should be provided is:
157 * where "name" is the function's name;
158 * "numargs" how many arguments it expects. For varargs
159 * procedures this should be a negative number,
160 * indicating the minimum required number of
161 * arguments (which is at least 1);
163 * NESTED functions (functions that call other functions) should define
164 * how they handle their stack frame in a .frame directive:
166 * .frame framesize, pc_reg, i_mask, f_mask
168 * where "framesize" is the size of the frame for this function, in bytes.
170 * new_sp + framesize == old_sp
171 * Framesizes should be rounded to a cacheline size.
172 * Note that old_sp plays the role of a conventional
174 * "pc_reg" is either a register which preserves the caller's PC
175 * or 'std', if std the saved PC should be stored at
177 * "i_mask" is a bitmask that indicates which of the integer
178 * registers are saved. See the M_xx defines at the
179 * end for the encoding of this 32bit value.
180 * "f_mask" is the same, for floating point registers.
182 * Note, 10/31/97: This is interesting but it isn't the way gcc outputs
183 * frame directives and it isn't the way the macros below output them
184 * either. Frame directives look like this:
186 * .frame $15,framesize,$26,0
188 * If no fp is set up then $30 should be used instead of $15.
189 * Also, gdb expects to find a <lda sp,-framesize(sp)> at the beginning
190 * of a procedure. Don't use things like sub sp,framesize,sp for this
191 * reason. End Note 10/31/97. ross@netbsd.org
193 * Note that registers should be saved starting at "old_sp-8", where the
194 * return address should be stored. Other registers follow at -16-24-32..
195 * starting from register 0 (if saved) and up. Then float registers (ifany)
198 * If you need to alias a leaf function, or to provide multiple entry points
199 * use the LEAF() macro for the main entry point and XLEAF() for the other
200 * additional/alternate entry points.
201 * "XLEAF"s must be nested within a "LEAF" and a ".end".
202 * Similar rules for nested routines, e.g. use NESTED/XNESTED
203 * Symbols that should not be exported can be declared with the STATIC_xxx
206 * All functions must be terminated by the END macro
208 * It is conceivable, although currently at the limits of compiler
209 * technology, that while performing inter-procedural optimizations
210 * the compiler/linker be able to avoid unnecessary register spills
211 * if told about the register usage of LEAF procedures (and by transitive
212 * closure of NESTED procedures as well). Assembly code can help
213 * this process using the .reguse directive:
215 * .reguse i_mask, f_mask
217 * where the register masks are built as above or-ing M_xx defines.
220 * All symbols are internal unless EXPORTed. Symbols that are IMPORTed
221 * must be appropriately described to the debugger.
229 #if !defined(GPROF) && !defined(PROF)
230 #define MCOUNT /* nothing */
234 jsr at_reg,_mcount; \
238 * PALVECT, ESETUP, and ERSAVE
239 * Declare a palcode transfer point, and carefully construct
240 * gdb symbols with an unusual _negative_ register-save offset
241 * so that gdb can find the otherwise lost PC and then
242 * invert the vector for traceback. Also, fix up framesize,
243 * allowing for the palframe for the same reason.
246 #define PALVECT(_name_) \
250 #define ESETUP(_name_) \
256 lda sp,-(FRAME_SW_SIZE*8)(sp); \
257 .frame $30,(FRAME_SW_SIZE+6)*8,$26,0; /* give gdb the real size */\
258 .mask 0x4000000,-0x28; \
263 stq at_reg,(FRAME_AT*8)(sp); \
265 stq ra,(FRAME_RA*8)(sp); \
267 bsr ra,exception_save_regs /* jmp/CALL trashes pv/t12 */
272 * Declare a global leaf function.
273 * A leaf function does not call other functions AND does not
274 * use any register that is callee-saved AND does not modify
277 #define LEAF(_name_,_n_args_) \
284 .proc _name_,_n_args_; \
288 #define LEAF_NOPROFILE(_name_,_n_args_) \
294 .proc _name_,_n_args_; \
300 * Declare a local leaf function.
302 #define STATIC_LEAF(_name_,_n_args_) \
308 .proc _name_,_n_args_; \
313 * Global alias for a leaf function, or alternate entry point
315 #define XLEAF(_name_,_n_args_) \
320 .aproc _name_,_n_args_;
325 * Local alias for a leaf function, or alternate entry point
327 #define STATIC_XLEAF(_name_,_n_args_) \
331 .aproc _name_,_n_args_;
336 * Declare a (global) nested function
337 * A nested function calls other functions and needs
338 * therefore stack space to save/restore registers.
340 #define NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
344 .frame sp,_framesize_,_pc_reg_; \
345 .livereg _i_mask_,_f_mask_; \
348 .proc _name_,_n_args_; \
349 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
352 #define NESTED_NOPROFILE(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
356 .frame sp,_framesize_,_pc_reg_; \
357 .livereg _i_mask_,_f_mask_
359 .proc _name_,_n_args_; \
360 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
365 * Declare a local nested function.
367 #define STATIC_NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
370 .frame sp,_framesize_,_pc_reg_; \
371 .livereg _i_mask_,_f_mask_; \
374 .proc _name_,_n_args_; \
375 .frame _framesize_, _pc_reg_, _i_mask_, _f_mask_
380 * Same as XLEAF, for a nested function.
382 #define XNESTED(_name_,_n_args_) \
387 .aproc _name_,_n_args_;
393 * Same as STATIC_XLEAF, for a nested function.
395 #define STATIC_XNESTED(_name_,_n_args_) \
399 .aproc _name_,_n_args_;
407 #define END(_name_) \
413 * Function invocation
415 #define CALL(_name_) \
419 /* but this would cover longer jumps
427 * Return from function
437 #define EXPORT(_name_) \
444 * Make an external name visible, typecheck the size
446 #define IMPORT(_name_, _size_) \
447 .extern _name_,_size_
452 * Define an absolute symbol
454 #define ABS(_name_, _value_) \
461 * Allocate un-initialized space for a global symbol
463 #define BSS(_name_,_numbytes_) \
464 .comm _name_,_numbytes_
468 * Make an exception entry point look like a called function,
469 * to make it digestible to the debugger (KERNEL only)
471 #define VECTOR(_name_, _i_mask_) \
475 .mask _i_mask_|IM_EXC,0; \
476 .frame sp,MSS_SIZE,ra;
477 /* .livereg _i_mask_|IM_EXC,0 */
480 .frame MSS_SIZE,$31,_i_mask_,0; \
485 * Allocate space for a message (a read-only ascii string)
488 #define MSG(msg,reg,label) \
498 #define PRINTF(msg,label) \
504 * Fatal error (KERNEL)
506 #define PANIC(msg,label) \
511 * Register mask defines, used to define both save
512 * and use register sets.
514 * NOTE: The bit order should HAVE BEEN maintained when saving
515 * registers on the stack: sp goes at the highest
516 * address, gp lower on the stack, etc etc
517 * BUT NOONE CARES ABOUT DEBUGGERS AT MIPS
520 #define IM_EXC 0x80000000
521 #define IM_SP 0x40000000
522 #define IM_GP 0x20000000
523 #define IM_AT 0x10000000
524 #define IM_T12 0x08000000
526 #define IM_RA 0x04000000
527 #define IM_T11 0x02000000
529 #define IM_T10 0x01000000
530 #define IM_T9 0x00800000
531 #define IM_T8 0x00400000
532 #define IM_A5 0x00200000
533 #define IM_A4 0x00100000
534 #define IM_A3 0x00080000
535 #define IM_A2 0x00040000
536 #define IM_A1 0x00020000
537 #define IM_A0 0x00010000
538 #define IM_S6 0x00008000
539 #define IM_S5 0x00004000
540 #define IM_S4 0x00002000
541 #define IM_S3 0x00001000
542 #define IM_S2 0x00000800
543 #define IM_S1 0x00000400
544 #define IM_S0 0x00000200
545 #define IM_T7 0x00000100
546 #define IM_T6 0x00000080
547 #define IM_T5 0x00000040
548 #define IM_T4 0x00000020
549 #define IM_T3 0x00000010
550 #define IM_T2 0x00000008
551 #define IM_T1 0x00000004
552 #define IM_T0 0x00000002
553 #define IM_V0 0x00000001
555 #define FM_T15 0x40000000
556 #define FM_T14 0x20000000
557 #define FM_T13 0x10000000
558 #define FM_T12 0x08000000
559 #define FM_T11 0x04000000
560 #define FM_T10 0x02000000
561 #define FM_T9 0x01000000
562 #define FM_T8 0x00800000
563 #define FM_T7 0x00400000
564 #define FM_A5 0x00200000
565 #define FM_A4 0x00100000
566 #define FM_A3 0x00080000
567 #define FM_A2 0x00040000
568 #define FM_A1 0x00020000
569 #define FM_A0 0x00010000
570 #define FM_T6 0x00008000
571 #define FM_T5 0x00004000
572 #define FM_T4 0x00002000
573 #define FM_T3 0x00001000
574 #define FM_T2 0x00000800
575 #define FM_T1 0x00000400
576 #define FM_S7 0x00000200
577 #define FM_S6 0x00000100
578 #define FM_S5 0x00000080
579 #define FM_S4 0x00000040
580 #define FM_S3 0x00000020
581 #define FM_S2 0x00000010
582 #define FM_S1 0x00000008
583 #define FM_S0 0x00000004
584 #define FM_T0 0x00000002
586 #define FM_V0 0x00000001
588 /* Pull in PAL "function" codes. */
589 #include <machine/pal.h>
594 #define SYSCALLNUM(name) \
597 #define CALLSYS_NOERROR(name) \
598 ldiq v0, SYSCALLNUM(name); \
599 call_pal PAL_OSF1_callsys
602 * Load the global pointer.
608 * WEAK_ALIAS: create a weak alias (ELF only).
611 #define WEAK_ALIAS(alias,sym) \
617 * Kernel RCS ID tag and copyright macros
623 #define __KERNEL_SECTIONSTRING(_sec, _str) \
624 .section _sec ; .asciz _str ; .text
626 #define __KERNEL_SECTIONSTRING(_sec, _str) \
627 .data ; .asciz _str ; .align 3 ; .text
630 #define __KERNEL_RCSID(_n, _s) __KERNEL_SECTIONSTRING(.ident, _s)
631 #define __KERNEL_COPYRIGHT(_n, _s) __KERNEL_SECTIONSTRING(.copyright, _s)
633 #ifdef NO_KERNEL_RCSIDS
634 #undef __KERNEL_RCSID
635 #define __KERNEL_RCSID(_n, _s) /* nothing */