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