Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.13
      1  1.13       cgd /* $NetBSD: asm.h,v 1.13 1997/04/08 00:19:04 cgd Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.4       cgd  * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
      5   1.1       cgd  * All Rights Reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Permission to use, copy, modify and distribute this software and its
      8   1.1       cgd  * documentation is hereby granted, provided that both the copyright
      9   1.1       cgd  * notice and this permission notice appear in all copies of the
     10   1.1       cgd  * software, derivative works or modified versions, and any portions
     11   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     12   1.1       cgd  *
     13   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     14   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     15   1.1       cgd  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     16   1.1       cgd  *
     17   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     18   1.1       cgd  *
     19   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     20   1.1       cgd  *  School of Computer Science
     21   1.1       cgd  *  Carnegie Mellon University
     22   1.1       cgd  *  Pittsburgh PA 15213-3890
     23   1.1       cgd  *
     24   1.1       cgd  * any improvements or extensions that they make and grant Carnegie Mellon
     25   1.1       cgd  * the rights to redistribute these changes.
     26   1.1       cgd  */
     27   1.1       cgd 
     28   1.1       cgd /*
     29   1.1       cgd  *	Assembly coding style
     30   1.1       cgd  *
     31   1.1       cgd  *	This file contains macros and register defines to
     32   1.1       cgd  *	aid in writing more readable assembly code.
     33   1.1       cgd  *	Some rules to make assembly code understandable by
     34   1.1       cgd  *	a debugger are also noted.
     35   1.1       cgd  *
     36   1.1       cgd  *	The document
     37   1.1       cgd  *
     38   1.1       cgd  *		"ALPHA Calling Standard", DEC 27-Apr-90
     39   1.1       cgd  *
     40   1.1       cgd  *	defines (a superset of) the rules and conventions
     41   1.1       cgd  *	we use.  While we make no promise of adhering to
     42   1.1       cgd  *	such standard and its evolution (esp where we
     43   1.1       cgd  *	can get faster code paths) it is certainly intended
     44   1.1       cgd  *	that we be interoperable with such standard.
     45   1.1       cgd  *
     46   1.1       cgd  *	In this sense, this file is a proper part of the
     47   1.1       cgd  *	definition of the (software) Alpha architecture.
     48   1.1       cgd  */
     49   1.1       cgd 
     50   1.1       cgd /*
     51   1.1       cgd  *	Symbolic register names and register saving rules
     52   1.1       cgd  *
     53   1.1       cgd  *	Legend:
     54   1.1       cgd  *		T	Saved by caller (Temporaries)
     55   1.1       cgd  *		S	Saved by callee (call-Safe registers)
     56   1.1       cgd  */
     57   1.1       cgd 
     58   1.1       cgd #define	v0	$0	/* (T)		return value		*/
     59   1.1       cgd #define t0	$1	/* (T)		temporary registers	*/
     60   1.1       cgd #define t1	$2
     61   1.1       cgd #define t2	$3
     62   1.1       cgd #define t3	$4
     63   1.1       cgd #define t4	$5
     64   1.1       cgd #define t5	$6
     65   1.1       cgd #define t6	$7
     66   1.1       cgd #define t7	$8
     67   1.1       cgd 
     68   1.1       cgd #define s0	$9	/* (S)		call-safe registers	*/
     69   1.1       cgd #define s1	$10
     70   1.1       cgd #define s2	$11
     71   1.1       cgd #define s3	$12
     72   1.1       cgd #define s4	$13
     73   1.1       cgd #define s5	$14
     74   1.1       cgd #define s6	$15
     75   1.1       cgd #define a0	$16	/* (T)		argument registers	*/
     76   1.1       cgd #define a1	$17
     77   1.1       cgd #define a2	$18
     78   1.1       cgd #define a3	$19
     79   1.1       cgd #define a4	$20
     80   1.1       cgd #define a5	$21
     81   1.1       cgd #define t8	$22	/* (T)		temporary registers	*/
     82   1.1       cgd #define t9	$23
     83   1.1       cgd #define t10	$24
     84   1.1       cgd #define t11	$25
     85   1.1       cgd #define ra	$26	/* (T)		return address		*/
     86   1.1       cgd #define t12	$27	/* (T)		another temporary	*/
     87   1.1       cgd #define at_reg	$28	/* (T)		assembler scratch	*/
     88   1.1       cgd #define	gp	$29	/* (T)		(local) data pointer	*/
     89   1.1       cgd #define sp	$30	/* (S)		stack pointer		*/
     90   1.1       cgd #define zero	$31	/* 		wired zero		*/
     91   1.1       cgd 
     92   1.1       cgd /* Floating point registers  (XXXX VERIFY THIS) */
     93   1.1       cgd #define	fv0	$f0	/* (T)		return value (real)	*/
     94   1.1       cgd #define	fv1	$f1	/* (T)		return value (imaginary)*/
     95   1.1       cgd #define	ft0	fv1
     96   1.1       cgd #define	fs0	$f2	/* (S)		call-safe registers	*/
     97   1.1       cgd #define	fs1	$f3
     98   1.1       cgd #define	fs2	$f4
     99   1.1       cgd #define	fs3	$f5
    100   1.1       cgd #define	fs4	$f6
    101   1.1       cgd #define	fs5	$f7
    102   1.1       cgd #define	fs6	$f8
    103   1.1       cgd #define	fs7	$f9
    104   1.1       cgd #define	ft1	$f10	/* (T)		temporary registers	*/
    105   1.1       cgd #define	ft2	$f11
    106   1.1       cgd #define	ft3	$f12
    107   1.1       cgd #define	ft4	$f13
    108   1.1       cgd #define	ft5	$f14
    109   1.1       cgd #define	ft6	$f15
    110   1.1       cgd #define	fa0	$f16	/* (T)		argument registers	*/
    111   1.1       cgd #define	fa1	$f17
    112   1.1       cgd #define	fa2	$f18
    113   1.1       cgd #define	fa3	$f19
    114   1.1       cgd #define	fa4	$f20
    115   1.1       cgd #define	fa5	$f21
    116   1.1       cgd #define	ft7	$f22	/* (T)		more temporaries	*/
    117   1.1       cgd #define	ft8	$f23
    118   1.1       cgd #define	ft9	$f24
    119   1.1       cgd #define	ft10	$f25
    120   1.1       cgd #define	ft11	$f26
    121   1.1       cgd #define	ft12	$f27
    122   1.1       cgd #define	ft13	$f28
    123   1.1       cgd #define	ft14	$f29
    124   1.1       cgd #define	ft15	$f30
    125   1.1       cgd #define	fzero	$f31	/*		wired zero		*/
    126   1.1       cgd 
    127   1.1       cgd 
    128   1.1       cgd /* Other DEC standard names */
    129   1.1       cgd #define ai	$25	/* (T)		argument information	*/
    130   1.1       cgd #define pv	$27	/* (T)		procedure value		*/
    131   1.1       cgd 
    132   1.9       cgd 
    133   1.9       cgd /*
    134   1.9       cgd  * Useful stuff.
    135   1.9       cgd  */
    136   1.9       cgd #ifdef __STDC__
    137   1.9       cgd #define	__CONCAT(a,b)	a ## b
    138   1.9       cgd #else
    139   1.9       cgd #define	__CONCAT(a,b)	a/**/b
    140   1.9       cgd #endif
    141   1.9       cgd #define ___CONCAT(a,b)	__CONCAT(a,b)
    142   1.9       cgd 
    143   1.9       cgd /*
    144   1.9       cgd  * Macro to make a local label name.
    145   1.9       cgd  */
    146   1.9       cgd #define	LLABEL(name,num)	___CONCAT(___CONCAT(L,name),num)
    147   1.9       cgd 
    148   1.1       cgd /*
    149   1.1       cgd  *
    150   1.1       cgd  * Debuggers need symbol table information to be able to properly
    151   1.1       cgd  * decode a stack trace.  The minimum that should be provided is:
    152   1.1       cgd  *
    153   1.1       cgd  * 	name:
    154   1.1       cgd  *		.proc	name,numargs
    155   1.1       cgd  *
    156   1.1       cgd  * where "name" 	is the function's name;
    157   1.1       cgd  *	 "numargs"	how many arguments it expects. For varargs
    158   1.1       cgd  *			procedures this should be a negative number,
    159   1.1       cgd  *			indicating the minimum required number of
    160   1.1       cgd  *			arguments (which is at least 1);
    161   1.1       cgd  *
    162   1.1       cgd  * NESTED functions (functions that call other functions) should define
    163   1.1       cgd  * how they handle their stack frame in a .frame directive:
    164   1.1       cgd  *
    165   1.1       cgd  *		.frame	framesize, pc_reg, i_mask, f_mask
    166   1.1       cgd  *
    167   1.1       cgd  * where "framesize"	is the size of the frame for this function, in bytes.
    168   1.1       cgd  *			That is:
    169   1.1       cgd  *				new_sp + framesize == old_sp
    170   1.1       cgd  *			Framesizes should be rounded to a cacheline size.
    171   1.1       cgd  *			Note that old_sp plays the role of a conventional
    172   1.1       cgd  *			"frame pointer";
    173   1.1       cgd  *	 "pc_reg"	is either a register which preserves the caller's PC
    174   1.1       cgd  *			or 'std', if std the saved PC should be stored at
    175   1.1       cgd  *				old_sp-8
    176   1.1       cgd  * 	 "i_mask"	is a bitmask that indicates which of the integer
    177   1.1       cgd  *			registers are saved. See the M_xx defines at the
    178   1.1       cgd  *			end for the encoding of this 32bit value.
    179   1.1       cgd  *	 "f_mask"	is the same, for floating point registers.
    180   1.1       cgd  *
    181   1.1       cgd  * Note that registers should be saved starting at "old_sp-8", where the
    182   1.1       cgd  * return address should be stored. Other registers follow at -16-24-32..
    183   1.1       cgd  * starting from register 0 (if saved) and up. Then float registers (ifany)
    184   1.1       cgd  * are saved.
    185   1.1       cgd  *
    186   1.1       cgd  * If you need to alias a leaf function, or to provide multiple entry points
    187   1.1       cgd  * use the LEAF() macro for the main entry point and XLEAF() for the other
    188   1.1       cgd  * additional/alternate entry points.
    189   1.1       cgd  * "XLEAF"s must be nested within a "LEAF" and a ".end".
    190   1.1       cgd  * Similar rules for nested routines, e.g. use NESTED/XNESTED
    191   1.1       cgd  * Symbols that should not be exported can be declared with the STATIC_xxx
    192   1.1       cgd  * macros.
    193   1.1       cgd  *
    194   1.1       cgd  * All functions must be terminated by the END macro
    195   1.1       cgd  *
    196   1.1       cgd  * It is conceivable, although currently at the limits of compiler
    197   1.1       cgd  * technology, that while performing inter-procedural optimizations
    198   1.1       cgd  * the compiler/linker be able to avoid unnecessary register spills
    199   1.1       cgd  * if told about the register usage of LEAF procedures (and by transitive
    200   1.1       cgd  * closure of NESTED procedures as well).  Assembly code can help
    201   1.1       cgd  * this process using the .reguse directive:
    202   1.1       cgd  *
    203   1.1       cgd  *		.reguse	i_mask, f_mask
    204   1.1       cgd  *
    205   1.1       cgd  * where the register masks are built as above or-ing M_xx defines.
    206   1.1       cgd  *
    207   1.1       cgd  *
    208   1.1       cgd  * All symbols are internal unless EXPORTed.  Symbols that are IMPORTed
    209   1.1       cgd  * must be appropriately described to the debugger.
    210   1.1       cgd  *
    211   1.1       cgd  */
    212   1.1       cgd 
    213   1.1       cgd /*
    214   1.2       cgd  * MCOUNT
    215   1.2       cgd  */
    216   1.2       cgd 
    217  1.11       jtc #ifndef GPROF
    218   1.2       cgd #define MCOUNT	/* nothing */
    219   1.2       cgd #else
    220   1.2       cgd #define MCOUNT							\
    221   1.6       cgd 	.set noat;						\
    222   1.6       cgd 	jsr	at_reg,_mcount;					\
    223   1.6       cgd 	.set at
    224   1.2       cgd #endif
    225   1.2       cgd 
    226   1.2       cgd /*
    227   1.1       cgd  * LEAF
    228   1.1       cgd  *	Declare a global leaf function.
    229   1.1       cgd  *	A leaf function does not call other functions AND does not
    230   1.1       cgd  *	use any register that is callee-saved AND does not modify
    231   1.1       cgd  *	the stack pointer.
    232   1.1       cgd  */
    233   1.1       cgd #define	LEAF(_name_,_n_args_)					\
    234   1.1       cgd 	.globl	_name_;						\
    235   1.1       cgd 	.ent	_name_ 0;					\
    236   1.1       cgd _name_:;							\
    237   1.2       cgd 	.frame	sp,0,ra;					\
    238   1.2       cgd 	MCOUNT
    239   1.2       cgd /* should have been
    240   1.2       cgd 	.proc	_name_,_n_args_;				\
    241   1.2       cgd 	.frame	0,ra,0,0
    242   1.2       cgd */
    243   1.2       cgd 
    244   1.2       cgd #define	LEAF_NOPROFILE(_name_,_n_args_)					\
    245   1.2       cgd 	.globl	_name_;						\
    246   1.2       cgd 	.ent	_name_ 0;					\
    247   1.2       cgd _name_:;							\
    248   1.1       cgd 	.frame	sp,0,ra
    249   1.1       cgd /* should have been
    250   1.1       cgd 	.proc	_name_,_n_args_;				\
    251   1.1       cgd 	.frame	0,ra,0,0
    252   1.1       cgd */
    253   1.1       cgd 
    254   1.1       cgd /*
    255   1.1       cgd  * STATIC_LEAF
    256   1.1       cgd  *	Declare a local leaf function.
    257   1.1       cgd  */
    258   1.1       cgd #define STATIC_LEAF(_name_,_n_args_)				\
    259   1.1       cgd 	.ent	_name_ 0;					\
    260   1.1       cgd _name_:;							\
    261   1.2       cgd 	.frame	sp,0,ra;					\
    262   1.2       cgd 	MCOUNT
    263   1.1       cgd /* should have been
    264   1.1       cgd 	.proc	_name_,_n_args_;				\
    265   1.1       cgd 	.frame	0,ra,0,0
    266   1.1       cgd */
    267   1.1       cgd /*
    268   1.1       cgd  * XLEAF
    269   1.1       cgd  *	Global alias for a leaf function, or alternate entry point
    270   1.1       cgd  */
    271   1.1       cgd #define	XLEAF(_name_,_n_args_)					\
    272   1.1       cgd 	.globl	_name_;						\
    273   1.1       cgd 	.aent	_name_ 0;					\
    274   1.1       cgd _name_:
    275   1.1       cgd /* should have been
    276   1.1       cgd 	.aproc	_name_,_n_args_;
    277   1.1       cgd */
    278   1.1       cgd 
    279   1.1       cgd /*
    280   1.1       cgd  * STATIC_XLEAF
    281   1.1       cgd  *	Local alias for a leaf function, or alternate entry point
    282   1.1       cgd  */
    283   1.1       cgd #define	STATIC_XLEAF(_name_,_n_args_)				\
    284   1.1       cgd 	.aent	_name_ 0;					\
    285   1.1       cgd _name_:
    286   1.1       cgd /* should have been
    287   1.1       cgd 	.aproc	_name_,_n_args_;
    288   1.1       cgd */
    289   1.1       cgd 
    290   1.1       cgd /*
    291   1.1       cgd  * NESTED
    292   1.1       cgd  *	Declare a (global) nested function
    293   1.1       cgd  *	A nested function calls other functions and needs
    294   1.1       cgd  *	therefore stack space to save/restore registers.
    295   1.1       cgd  */
    296   1.1       cgd #define	NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
    297   1.1       cgd 	.globl	_name_;						\
    298   1.1       cgd 	.ent	_name_ 0;					\
    299   1.1       cgd _name_:;							\
    300   1.1       cgd 	.frame	sp,_framesize_,_pc_reg_;			\
    301   1.2       cgd 	.livereg _i_mask_,_f_mask_;				\
    302   1.2       cgd 	MCOUNT
    303   1.2       cgd /* should have been
    304   1.2       cgd 	.proc	_name_,_n_args_;				\
    305   1.2       cgd 	.frame	_framesize_, _pc_reg_, _i_mask_, _f_mask_
    306   1.2       cgd */
    307   1.2       cgd 
    308   1.2       cgd #define	NESTED_NOPROFILE(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
    309   1.2       cgd 	.globl	_name_;						\
    310   1.2       cgd 	.ent	_name_ 0;					\
    311   1.2       cgd _name_:;							\
    312   1.2       cgd 	.frame	sp,_framesize_,_pc_reg_;			\
    313   1.1       cgd 	.livereg _i_mask_,_f_mask_
    314   1.1       cgd /* should have been
    315   1.1       cgd 	.proc	_name_,_n_args_;				\
    316   1.1       cgd 	.frame	_framesize_, _pc_reg_, _i_mask_, _f_mask_
    317   1.1       cgd */
    318   1.1       cgd 
    319   1.1       cgd /*
    320   1.1       cgd  * STATIC_NESTED
    321   1.1       cgd  *	Declare a local nested function.
    322   1.1       cgd  */
    323   1.1       cgd #define	STATIC_NESTED(_name_, _n_args_, _framesize_, _pc_reg_, _i_mask_, _f_mask_ ) \
    324   1.1       cgd 	.ent	_name_ 0;					\
    325   1.1       cgd _name_:;							\
    326   1.1       cgd 	.frame	sp,_framesize_,_pc_reg_;			\
    327   1.2       cgd 	.livereg _i_mask_,_f_mask_;				\
    328   1.2       cgd 	MCOUNT
    329   1.1       cgd /* should have been
    330   1.1       cgd 	.proc	_name_,_n_args_;				\
    331   1.1       cgd 	.frame	_framesize_, _pc_reg_, _i_mask_, _f_mask_
    332   1.1       cgd */
    333   1.1       cgd 
    334   1.1       cgd /*
    335   1.1       cgd  * XNESTED
    336   1.1       cgd  *	Same as XLEAF, for a nested function.
    337   1.1       cgd  */
    338   1.1       cgd #define	XNESTED(_name_,_n_args_)				\
    339   1.1       cgd 	.globl	_name_;						\
    340   1.1       cgd 	.aent	_name_ 0;					\
    341   1.1       cgd _name_:
    342   1.1       cgd /* should have been
    343   1.1       cgd 	.aproc	_name_,_n_args_;
    344   1.1       cgd */
    345   1.1       cgd 
    346   1.1       cgd 
    347   1.1       cgd /*
    348   1.1       cgd  * STATIC_XNESTED
    349   1.1       cgd  *	Same as STATIC_XLEAF, for a nested function.
    350   1.1       cgd  */
    351   1.1       cgd #define	STATIC_XNESTED(_name_,_n_args_)				\
    352   1.1       cgd 	.aent	_name_ 0;					\
    353   1.1       cgd _name_:
    354   1.1       cgd /* should have been
    355   1.1       cgd 	.aproc	_name_,_n_args_;
    356   1.1       cgd */
    357   1.1       cgd 
    358   1.1       cgd 
    359   1.1       cgd /*
    360   1.1       cgd  * END
    361   1.1       cgd  *	Function delimiter
    362   1.1       cgd  */
    363   1.1       cgd #define	END(_name_)						\
    364   1.1       cgd 	.end	_name_
    365   1.1       cgd 
    366   1.1       cgd 
    367   1.1       cgd /*
    368   1.1       cgd  * CALL
    369   1.1       cgd  *	Function invocation
    370   1.1       cgd  */
    371   1.1       cgd #define	CALL(_name_)						\
    372   1.1       cgd 	jsr	ra,_name_;					\
    373   1.1       cgd 	ldgp	gp,0(ra)
    374   1.1       cgd /* but this would cover longer jumps
    375   1.1       cgd 	br	ra,.+4;						\
    376   1.1       cgd 	bsr	ra,_name_
    377   1.1       cgd */
    378   1.1       cgd 
    379   1.1       cgd 
    380   1.1       cgd /*
    381   1.1       cgd  * RET
    382   1.1       cgd  *	Return from function
    383   1.1       cgd  */
    384   1.1       cgd #define	RET							\
    385   1.1       cgd 	ret	zero,(ra),1
    386   1.1       cgd 
    387   1.1       cgd 
    388   1.1       cgd /*
    389   1.1       cgd  * EXPORT
    390   1.1       cgd  *	Export a symbol
    391   1.1       cgd  */
    392   1.1       cgd #define	EXPORT(_name_)						\
    393   1.1       cgd 	.globl	_name_;						\
    394   1.1       cgd _name_:
    395   1.1       cgd 
    396   1.1       cgd 
    397   1.1       cgd /*
    398   1.1       cgd  * IMPORT
    399   1.1       cgd  *	Make an external name visible, typecheck the size
    400   1.1       cgd  */
    401   1.1       cgd #define	IMPORT(_name_, _size_)					\
    402   1.1       cgd 	.extern	_name_,_size_
    403   1.1       cgd 
    404   1.1       cgd 
    405   1.1       cgd /*
    406   1.1       cgd  * ABS
    407   1.1       cgd  *	Define an absolute symbol
    408   1.1       cgd  */
    409   1.1       cgd #define	ABS(_name_, _value_)					\
    410   1.1       cgd 	.globl	_name_;						\
    411   1.1       cgd _name_	=	_value_
    412   1.1       cgd 
    413   1.1       cgd 
    414   1.1       cgd /*
    415   1.1       cgd  * BSS
    416   1.1       cgd  *	Allocate un-initialized space for a global symbol
    417   1.1       cgd  */
    418   1.1       cgd #define	BSS(_name_,_numbytes_)					\
    419   1.1       cgd 	.comm	_name_,_numbytes_
    420   1.1       cgd 
    421   1.1       cgd /*
    422   1.1       cgd  * VECTOR
    423   1.1       cgd  *	Make an exception entry point look like a called function,
    424   1.1       cgd  *	to make it digestible to the debugger (KERNEL only)
    425   1.1       cgd  */
    426   1.1       cgd #define	VECTOR(_name_, _i_mask_)				\
    427   1.1       cgd 	.globl	_name_;						\
    428   1.1       cgd 	.ent	_name_ 0;					\
    429   1.1       cgd _name_:;							\
    430   1.1       cgd 	.mask	_i_mask_|IM_EXC,0;				\
    431   1.1       cgd 	.frame	sp,MSS_SIZE,ra;
    432   1.1       cgd /*	.livereg _i_mask_|IM_EXC,0
    433   1.1       cgd /* should have been
    434   1.1       cgd 	.proc	_name_,1;					\
    435   1.1       cgd 	.frame	MSS_SIZE,$31,_i_mask_,0;			\
    436   1.1       cgd */
    437   1.1       cgd 
    438   1.1       cgd /*
    439   1.1       cgd  * MSG
    440   1.1       cgd  *	Allocate space for a message (a read-only ascii string)
    441   1.1       cgd  */
    442   1.1       cgd #define	ASCIZ	.asciz
    443   1.6       cgd #define	MSG(msg,reg,label)					\
    444   1.6       cgd 	lda reg, label;						\
    445   1.1       cgd 	.data;							\
    446   1.6       cgd label:	ASCIZ msg;						\
    447   1.1       cgd 	.text;
    448   1.1       cgd 
    449   1.1       cgd /*
    450   1.1       cgd  * PRINTF
    451   1.1       cgd  *	Print a message
    452   1.1       cgd  */
    453   1.6       cgd #define	PRINTF(msg,label)					\
    454   1.6       cgd 	MSG(msg,a0,label);					\
    455   1.8  christos 	CALL(printf)
    456   1.1       cgd 
    457   1.1       cgd /*
    458   1.1       cgd  * PANIC
    459   1.1       cgd  *	Fatal error (KERNEL)
    460   1.1       cgd  */
    461   1.6       cgd #define	PANIC(msg,label)					\
    462   1.6       cgd 	MSG(msg,a0,label);					\
    463   1.1       cgd 	CALL(panic)
    464   1.1       cgd 
    465   1.1       cgd /*
    466   1.1       cgd  * Register mask defines, used to define both save
    467   1.1       cgd  * and use register sets.
    468   1.1       cgd  *
    469   1.1       cgd  * NOTE: The bit order should HAVE BEEN maintained when saving
    470   1.1       cgd  *	 registers on the stack: sp goes at the highest
    471   1.1       cgd  *	 address, gp lower on the stack, etc etc
    472   1.1       cgd  *	 BUT NOONE CARES ABOUT DEBUGGERS AT MIPS
    473   1.1       cgd  */
    474   1.1       cgd 
    475   1.1       cgd #define	IM_EXC	0x80000000
    476   1.1       cgd #define	IM_SP	0x40000000
    477   1.1       cgd #define	IM_GP	0x20000000
    478   1.1       cgd #define	IM_AT	0x10000000
    479   1.1       cgd #define	IM_T12	0x08000000
    480   1.1       cgd #	define	IM_PV	IM_T4
    481   1.1       cgd #define	IM_RA	0x04000000
    482   1.1       cgd #define	IM_T11	0x02000000
    483   1.1       cgd #	define	IM_AI	IM_T3
    484   1.1       cgd #define	IM_T10	0x01000000
    485   1.1       cgd #define	IM_T9	0x00800000
    486   1.1       cgd #define	IM_T8	0x00400000
    487   1.1       cgd #define	IM_A5	0x00200000
    488   1.1       cgd #define	IM_A4	0x00100000
    489   1.1       cgd #define	IM_A3	0x00080000
    490   1.1       cgd #define	IM_A2	0x00040000
    491   1.1       cgd #define	IM_A1	0x00020000
    492   1.1       cgd #define	IM_A0	0x00010000
    493   1.1       cgd #define	IM_S6	0x00008000
    494   1.1       cgd #define	IM_S5	0x00004000
    495   1.1       cgd #define	IM_S4	0x00002000
    496   1.1       cgd #define	IM_S3	0x00001000
    497   1.1       cgd #define	IM_S2	0x00000800
    498   1.1       cgd #define	IM_S1	0x00000400
    499   1.1       cgd #define	IM_S0	0x00000200
    500   1.1       cgd #define	IM_T7	0x00000100
    501   1.1       cgd #define	IM_T6	0x00000080
    502   1.1       cgd #define	IM_T5	0x00000040
    503   1.1       cgd #define	IM_T4	0x00000020
    504   1.1       cgd #define	IM_T3	0x00000010
    505   1.1       cgd #define	IM_T2	0x00000008
    506   1.1       cgd #define	IM_T1	0x00000004
    507   1.1       cgd #define	IM_T0	0x00000002
    508   1.1       cgd #define	IM_V0	0x00000001
    509   1.1       cgd 
    510   1.1       cgd #define	FM_T15	0x40000000
    511   1.1       cgd #define	FM_T14	0x20000000
    512   1.1       cgd #define	FM_T13	0x10000000
    513   1.1       cgd #define	FM_T12	0x08000000
    514   1.1       cgd #define	FM_T11	0x04000000
    515   1.1       cgd #define	FM_T10	0x02000000
    516   1.1       cgd #define	FM_T9	0x01000000
    517   1.1       cgd #define	FM_T8	0x00800000
    518   1.1       cgd #define	FM_T7	0x00400000
    519   1.1       cgd #define	FM_A5	0x00200000
    520   1.1       cgd #define	FM_A4	0x00100000
    521   1.1       cgd #define	FM_A3	0x00080000
    522   1.1       cgd #define	FM_A2	0x00040000
    523   1.1       cgd #define	FM_A1	0x00020000
    524   1.1       cgd #define	FM_A0	0x00010000
    525   1.1       cgd #define	FM_T6	0x00008000
    526   1.1       cgd #define	FM_T5	0x00004000
    527   1.1       cgd #define	FM_T4	0x00002000
    528   1.1       cgd #define	FM_T3	0x00001000
    529   1.1       cgd #define	FM_T2	0x00000800
    530   1.1       cgd #define	FM_T1	0x00000400
    531   1.1       cgd #define	FM_S7	0x00000200
    532   1.1       cgd #define	FM_S6	0x00000100
    533   1.1       cgd #define	FM_S5	0x00000080
    534   1.1       cgd #define	FM_S4	0x00000040
    535   1.1       cgd #define	FM_S3	0x00000020
    536   1.1       cgd #define	FM_S2	0x00000010
    537   1.1       cgd #define	FM_S1	0x00000008
    538   1.1       cgd #define	FM_S0	0x00000004
    539   1.1       cgd #define	FM_T0	0x00000002
    540   1.1       cgd #define	FM_V1	FM_T0
    541   1.1       cgd #define	FM_V0	0x00000001
    542   1.1       cgd 
    543   1.1       cgd /*
    544   1.1       cgd  * PAL "function" codes (used as arguments to call_pal instructions).
    545   1.1       cgd  *
    546   1.1       cgd  * Those marked with "P" are privileged, and those marked with "U"
    547   1.1       cgd  * are unprivileged.
    548   1.1       cgd  */
    549   1.1       cgd 
    550   1.5       cgd /* Common PAL function codes. */
    551   1.1       cgd #define	PAL_halt		0x0000			/* P */
    552   1.1       cgd #define	PAL_draina		0x0002			/* P */
    553   1.5       cgd #define	PAL_cserve		0x0009			/* P */
    554   1.1       cgd #define	PAL_swppal		0x000a			/* P */
    555   1.1       cgd #define	PAL_bpt			0x0080			/* U */
    556   1.1       cgd #define	PAL_bugchk		0x0081			/* U */
    557   1.1       cgd #define	PAL_imb			0x0086			/* U */
    558   1.1       cgd #define	PAL_rdunique		0x009e			/* U */
    559   1.1       cgd #define	PAL_wrunique		0x009f			/* U */
    560   1.1       cgd #define	PAL_gentrap		0x00aa			/* U */
    561   1.1       cgd 
    562   1.5       cgd /* VMS PAL function codes. */
    563   1.1       cgd #define	PAL_VMS_ldqp		0x0003			/* P */
    564   1.1       cgd #define	PAL_VMS_stqp		0x0004			/* P */
    565   1.1       cgd #define	PAL_VMS_mtpr_fen	0x000c			/* P */
    566   1.1       cgd #define	PAL_VMS_mtpr_ipir	0x000d			/* P */
    567   1.1       cgd #define	PAL_VMS_mfpr_ipl	0x000e			/* P */
    568   1.1       cgd #define	PAL_VMS_mtpr_ipl	0x000f			/* P */
    569   1.1       cgd #define	PAL_VMS_mfpr_mces	0x0010			/* P */
    570   1.1       cgd #define	PAL_VMS_mtpr_mces	0x0011			/* P */
    571   1.1       cgd #define	PAL_VMS_mfpr_prbr	0x0013			/* P */
    572   1.1       cgd #define	PAL_VMS_mtpr_prbr	0x0014			/* P */
    573   1.1       cgd #define	PAL_VMS_mfpr_ptbr	0x0015			/* P */
    574   1.1       cgd #define	PAL_VMS_mtpr_scbb	0x0017			/* P */
    575   1.1       cgd #define	PAL_VMS_mtpr_sirr	0x0018			/* P */
    576   1.1       cgd #define	PAL_VMS_mtpr_tbia	0x001b			/* P */
    577   1.1       cgd #define	PAL_VMS_mtpr_tbiap	0x001c			/* P */
    578   1.1       cgd #define	PAL_VMS_mtpr_tbis	0x001d			/* P */
    579   1.1       cgd #define	PAL_VMS_mfpr_usp	0x0022			/* P */
    580   1.1       cgd #define	PAL_VMS_mtpr_usp	0x0023			/* P */
    581   1.1       cgd #define	PAL_VMS_mfpr_vptb	0x0029			/* P */
    582   1.1       cgd #define	PAL_VMS_mfpr_whami	0x003f			/* P */
    583   1.1       cgd #define	PAL_VMS_rei		0x0092			/* U */
    584   1.1       cgd 
    585   1.5       cgd /* OSF/1 PAL function codes. */
    586   1.5       cgd #define	PAL_OSF1_rdmces		0x0010			/* P */
    587   1.5       cgd #define	PAL_OSF1_wrmces		0x0011			/* P */
    588   1.1       cgd #define	PAL_OSF1_wrfen		0x002b			/* P */
    589   1.1       cgd #define	PAL_OSF1_wrvptptr	0x002d			/* P */
    590   1.1       cgd #define	PAL_OSF1_swpctx		0x0030			/* P */
    591   1.1       cgd #define	PAL_OSF1_wrval		0x0031			/* P */
    592   1.1       cgd #define	PAL_OSF1_rdval		0x0032			/* P */
    593   1.1       cgd #define	PAL_OSF1_tbi		0x0033			/* P */
    594   1.1       cgd #define	PAL_OSF1_wrent		0x0034			/* P */
    595   1.1       cgd #define	PAL_OSF1_swpipl		0x0035			/* P */
    596   1.1       cgd #define	PAL_OSF1_rdps		0x0036			/* P */
    597   1.1       cgd #define	PAL_OSF1_wrkgp		0x0037			/* P */
    598   1.1       cgd #define	PAL_OSF1_wrusp		0x0038			/* P */
    599   1.1       cgd #define	PAL_OSF1_rdusp		0x003a			/* P */
    600   1.1       cgd #define	PAL_OSF1_whami		0x003c			/* P */
    601   1.1       cgd #define	PAL_OSF1_retsys		0x003d			/* P */
    602   1.1       cgd #define	PAL_OSF1_rti		0x003f			/* P */
    603   1.1       cgd #define	PAL_OSF1_callsys	0x0083			/* U */
    604   1.1       cgd #define	PAL_OSF1_imb		0x0086			/* U */
    605   1.1       cgd 
    606   1.9       cgd 
    607   1.1       cgd /*
    608   1.9       cgd  * System call glue.
    609   1.1       cgd  */
    610   1.9       cgd #define	SYSCALLNUM(name)					\
    611   1.9       cgd 	___CONCAT(SYS_,name)
    612   1.1       cgd 
    613   1.9       cgd #define	CALLSYS_NOERROR(name)					\
    614   1.9       cgd 	ldiq	v0, SYSCALLNUM(name);				\
    615   1.9       cgd 	call_pal PAL_OSF1_callsys
    616   1.1       cgd 
    617   1.9       cgd /*
    618   1.9       cgd  * Load the global pointer.
    619   1.9       cgd  */
    620   1.9       cgd #define	LDGP(reg)						\
    621   1.9       cgd 	ldgp	gp, 0(reg)
    622  1.10       cgd 
    623  1.10       cgd /*
    624  1.10       cgd  * WEAK_ALIAS: create a weak alias (ELF only).
    625  1.10       cgd  */
    626  1.10       cgd #ifdef __ELF__
    627  1.10       cgd #define WEAK_ALIAS(alias,sym)					\
    628  1.10       cgd 	.weak alias;						\
    629  1.10       cgd 	alias = sym
    630  1.10       cgd #endif
    631  1.13       cgd 
    632  1.13       cgd /*
    633  1.13       cgd  * Kernel RCS ID tag and copyright macros
    634  1.13       cgd  */
    635  1.13       cgd 
    636  1.13       cgd #ifdef _KERNEL
    637  1.13       cgd 
    638  1.13       cgd #define	__KERNEL_SECTIONSTRING(_sec, _str)				\
    639  1.13       cgd 	.section _sec ; .asciz _str ; .text
    640  1.13       cgd 
    641  1.13       cgd #ifdef __ELF__
    642  1.13       cgd 
    643  1.13       cgd #define	__KERNEL_RCSID(_n, _s)		__KERNEL_SECTIONSTRING(.ident, _s)
    644  1.13       cgd #define	__KERNEL_COPYRIGHT(_n, _s)	__KERNEL_SECTIONSTRING(.copyright, _s)
    645  1.13       cgd 
    646  1.13       cgd #else /* __ELF__ */
    647  1.13       cgd 
    648  1.13       cgd #define	__KERNEL_RCSID(_n, _s)		__KERNEL_SECTIONSTRING(.text, _s)
    649  1.13       cgd #define	__KERNEL_COPYRIGHT(_n, _s)	__KERNEL_SECTIONSTRING(.text, _s)
    650  1.13       cgd 
    651  1.13       cgd #endif /* __ELF__ */
    652  1.13       cgd 
    653  1.13       cgd #ifdef NO_KERNEL_RCSIDS
    654  1.13       cgd #undef __KERNEL_RCSID
    655  1.13       cgd #define	__KERNEL_RCSID(_n, _s)		/* nothing */
    656  1.13       cgd #endif
    657  1.13       cgd 
    658  1.13       cgd #endif /* _KERNEL */
    659