asm.h revision 1.1.10.2 1 1.1.10.2 tron /* $NetBSD: asm.h,v 1.1.10.2 2006/05/24 15:47:59 tron Exp $ */
2 1.1.10.2 tron
3 1.1.10.2 tron /* -
4 1.1.10.2 tron * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
5 1.1.10.2 tron * All Rights Reserved.
6 1.1.10.2 tron *
7 1.1.10.2 tron * Permission to use, copy, modify and distribute this software and its
8 1.1.10.2 tron * documentation is hereby granted, provided that both the copyright
9 1.1.10.2 tron * notice and this permission notice appear in all copies of the
10 1.1.10.2 tron * software, derivative works or modified versions, and any portions
11 1.1.10.2 tron * thereof, and that both notices appear in supporting documentation.
12 1.1.10.2 tron *
13 1.1.10.2 tron * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 1.1.10.2 tron * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 1.1.10.2 tron * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 1.1.10.2 tron *
17 1.1.10.2 tron * Carnegie Mellon requests users of this software to return to
18 1.1.10.2 tron *
19 1.1.10.2 tron * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
20 1.1.10.2 tron * School of Computer Science
21 1.1.10.2 tron * Carnegie Mellon University
22 1.1.10.2 tron * Pittsburgh PA 15213-3890
23 1.1.10.2 tron *
24 1.1.10.2 tron * any improvements or extensions that they make and grant Carnegie Mellon
25 1.1.10.2 tron * the rights to redistribute these changes.
26 1.1.10.2 tron */
27 1.1.10.2 tron
28 1.1.10.2 tron /*
29 1.1.10.2 tron * Assembly coding style
30 1.1.10.2 tron *
31 1.1.10.2 tron * This file contains macros and register defines to
32 1.1.10.2 tron * aid in writing more readable assembly code.
33 1.1.10.2 tron * Some rules to make assembly code understandable by
34 1.1.10.2 tron * a debugger are also noted.
35 1.1.10.2 tron */
36 1.1.10.2 tron
37 1.1.10.2 tron /*
38 1.1.10.2 tron * Macro to make a local label name.
39 1.1.10.2 tron */
40 1.1.10.2 tron #define LLABEL(name,num) L ## name ## num
41 1.1.10.2 tron
42 1.1.10.2 tron /*
43 1.1.10.2 tron * MCOUNT
44 1.1.10.2 tron */
45 1.1.10.2 tron #if defined(GPROF)
46 1.1.10.2 tron #define MCOUNT \
47 1.1.10.2 tron alloc out0 = ar.pfs, 8, 0, 4, 0; \
48 1.1.10.2 tron mov out1 = r1; \
49 1.1.10.2 tron mov out2 = b0;; \
50 1.1.10.2 tron mov out3 = r0; \
51 1.1.10.2 tron br.call.sptk b0 = _mcount;;
52 1.1.10.2 tron #else
53 1.1.10.2 tron #define MCOUNT /* nothing */
54 1.1.10.2 tron #endif
55 1.1.10.2 tron
56 1.1.10.2 tron /*
57 1.1.10.2 tron * ENTRY
58 1.1.10.2 tron * Declare a global leaf function.
59 1.1.10.2 tron * A leaf function does not call other functions.
60 1.1.10.2 tron */
61 1.1.10.2 tron #define ENTRY(_name_, _n_args_) \
62 1.1.10.2 tron .global _name_; \
63 1.1.10.2 tron .align 16; \
64 1.1.10.2 tron .proc _name_; \
65 1.1.10.2 tron _name_:; \
66 1.1.10.2 tron .regstk _n_args_, 0, 0, 0; \
67 1.1.10.2 tron MCOUNT
68 1.1.10.2 tron
69 1.1.10.2 tron #define ENTRY_NOPROFILE(_name_, _n_args_) \
70 1.1.10.2 tron .global _name_; \
71 1.1.10.2 tron .align 16; \
72 1.1.10.2 tron .proc _name_; \
73 1.1.10.2 tron _name_:; \
74 1.1.10.2 tron .regstk _n_args_, 0, 0, 0
75 1.1.10.2 tron
76 1.1.10.2 tron /*
77 1.1.10.2 tron * STATIC_ENTRY
78 1.1.10.2 tron * Declare a local leaf function.
79 1.1.10.2 tron */
80 1.1.10.2 tron #define STATIC_ENTRY(_name_, _n_args_) \
81 1.1.10.2 tron .align 16; \
82 1.1.10.2 tron .proc _name_; \
83 1.1.10.2 tron _name_:; \
84 1.1.10.2 tron .regstk _n_args_, 0, 0, 0 \
85 1.1.10.2 tron MCOUNT
86 1.1.10.2 tron /*
87 1.1.10.2 tron * XENTRY
88 1.1.10.2 tron * Global alias for a leaf function, or alternate entry point
89 1.1.10.2 tron */
90 1.1.10.2 tron #define XENTRY(_name_) \
91 1.1.10.2 tron .globl _name_; \
92 1.1.10.2 tron _name_:
93 1.1.10.2 tron
94 1.1.10.2 tron /*
95 1.1.10.2 tron * STATIC_XENTRY
96 1.1.10.2 tron * Local alias for a leaf function, or alternate entry point
97 1.1.10.2 tron */
98 1.1.10.2 tron #define STATIC_XENTRY(_name_) \
99 1.1.10.2 tron _name_:
100 1.1.10.2 tron
101 1.1.10.2 tron
102 1.1.10.2 tron /*
103 1.1.10.2 tron * END
104 1.1.10.2 tron * Function delimiter
105 1.1.10.2 tron */
106 1.1.10.2 tron #define END(_name_) \
107 1.1.10.2 tron .endp _name_
108 1.1.10.2 tron
109 1.1.10.2 tron
110 1.1.10.2 tron /*
111 1.1.10.2 tron * EXPORT
112 1.1.10.2 tron * Export a symbol
113 1.1.10.2 tron */
114 1.1.10.2 tron #define EXPORT(_name_) \
115 1.1.10.2 tron .global _name_; \
116 1.1.10.2 tron _name_:
117 1.1.10.2 tron
118 1.1.10.2 tron
119 1.1.10.2 tron /*
120 1.1.10.2 tron * IMPORT
121 1.1.10.2 tron * Make an external name visible, typecheck the size
122 1.1.10.2 tron */
123 1.1.10.2 tron #define IMPORT(_name_, _size_) \
124 1.1.10.2 tron /* .extern _name_,_size_ */
125 1.1.10.2 tron
126 1.1.10.2 tron
127 1.1.10.2 tron /*
128 1.1.10.2 tron * ABS
129 1.1.10.2 tron * Define an absolute symbol
130 1.1.10.2 tron */
131 1.1.10.2 tron #define ABS(_name_, _value_) \
132 1.1.10.2 tron .globl _name_; \
133 1.1.10.2 tron _name_ = _value_
134 1.1.10.2 tron
135 1.1.10.2 tron
136 1.1.10.2 tron /*
137 1.1.10.2 tron * BSS
138 1.1.10.2 tron * Allocate un-initialized space for a global symbol
139 1.1.10.2 tron */
140 1.1.10.2 tron #define BSS(_name_,_numbytes_) \
141 1.1.10.2 tron .comm _name_,_numbytes_
142 1.1.10.2 tron
143 1.1.10.2 tron
144 1.1.10.2 tron /*
145 1.1.10.2 tron * MSG
146 1.1.10.2 tron * Allocate space for a message (a read-only ascii string)
147 1.1.10.2 tron */
148 1.1.10.2 tron #define ASCIZ .asciz
149 1.1.10.2 tron #define MSG(msg,reg,label) \
150 1.1.10.2 tron addl reg,@ltoff(label),gp;; \
151 1.1.10.2 tron ld8 reg=[reg];; \
152 1.1.10.2 tron .data; \
153 1.1.10.2 tron label: ASCIZ msg; \
154 1.1.10.2 tron .text;
155 1.1.10.2 tron
156 1.1.10.2 tron
157 1.1.10.2 tron /*
158 1.1.10.2 tron * System call glue.
159 1.1.10.2 tron */
160 1.1.10.2 tron #define SYSCALLNUM(name) SYS_ ## name
161 1.1.10.2 tron
162 1.1.10.2 tron #define CALLSYS_NOERROR(name) \
163 1.1.10.2 tron { .mmi ; \
164 1.1.10.2 tron alloc r9 = ar.pfs, 0, 0, 8, 0 ; \
165 1.1.10.2 tron mov r31 = ar.k5 ; \
166 1.1.10.2 tron mov r10 = b0 ;; } \
167 1.1.10.2 tron { .mib ; \
168 1.1.10.2 tron mov r8 = SYSCALLNUM(name) ; \
169 1.1.10.2 tron mov b7 = r31 ; \
170 1.1.10.2 tron br.call.sptk b0 = b7 ;; }
171 1.1.10.2 tron
172 1.1.10.2 tron
173 1.1.10.2 tron /*
174 1.1.10.2 tron * WEAK_ALIAS: create a weak alias (ELF only).
175 1.1.10.2 tron */
176 1.1.10.2 tron #define WEAK_ALIAS(alias,sym) \
177 1.1.10.2 tron .weak alias; \
178 1.1.10.2 tron alias = sym
179 1.1.10.2 tron
180