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