asm.h revision 1.16.2.2 1 1.16.2.2 nathanw /* $NetBSD: asm.h,v 1.16.2.2 2002/02/28 04:12:12 nathanw Exp $ */
2 1.16.2.2 nathanw
3 1.16.2.2 nathanw /*
4 1.16.2.2 nathanw * Copyright (c) 1994 Allen Briggs
5 1.16.2.2 nathanw * All rights reserved.
6 1.16.2.2 nathanw *
7 1.16.2.2 nathanw * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
8 1.16.2.2 nathanw * locore.s:
9 1.16.2.2 nathanw * Copyright (c) 1988 University of Utah.
10 1.16.2.2 nathanw * Copyright (c) 1982, 1990 The Regents of the University of California.
11 1.16.2.2 nathanw * sun3/include/asm.h:
12 1.16.2.2 nathanw * Copyright (c) 1993 Adam Glass
13 1.16.2.2 nathanw * Copyright (c) 1990 The Regents of the University of California.
14 1.16.2.2 nathanw *
15 1.16.2.2 nathanw * Redistribution and use in source and binary forms, with or without
16 1.16.2.2 nathanw * modification, are permitted provided that the following conditions
17 1.16.2.2 nathanw * are met:
18 1.16.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
19 1.16.2.2 nathanw * notice, this list of conditions and the following disclaimer.
20 1.16.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
21 1.16.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
22 1.16.2.2 nathanw * documentation and/or other materials provided with the distribution.
23 1.16.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
24 1.16.2.2 nathanw * must display the following acknowledgement:
25 1.16.2.2 nathanw * This product includes software developed by the University of
26 1.16.2.2 nathanw * California, Berkeley and its contributors.
27 1.16.2.2 nathanw * 4. Neither the name of the University nor the names of its contributors
28 1.16.2.2 nathanw * may be used to endorse or promote products derived from this software
29 1.16.2.2 nathanw * without specific prior written permission.
30 1.16.2.2 nathanw *
31 1.16.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 1.16.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 1.16.2.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 1.16.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 1.16.2.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.16.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.16.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.16.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 1.16.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 1.16.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 1.16.2.2 nathanw * SUCH DAMAGE.
42 1.16.2.2 nathanw */
43 1.16.2.2 nathanw
44 1.16.2.2 nathanw #ifndef _ASM_H_
45 1.16.2.2 nathanw #define _ASM_H_
46 1.16.2.2 nathanw
47 1.16.2.2 nathanw #ifndef _LOCORE
48 1.16.2.2 nathanw #define _LOCORE
49 1.16.2.2 nathanw #endif
50 1.16.2.2 nathanw #include <machine/frame.h>
51 1.16.2.2 nathanw
52 1.16.2.2 nathanw #ifdef __arch64__
53 1.16.2.2 nathanw #ifndef __ELF__
54 1.16.2.2 nathanw #define __ELF__
55 1.16.2.2 nathanw #endif
56 1.16.2.2 nathanw #endif
57 1.16.2.2 nathanw
58 1.16.2.2 nathanw /* Pull in CCFSZ, CC64FSZ, and BIAS from frame.h */
59 1.16.2.2 nathanw #ifndef _LOCORE
60 1.16.2.2 nathanw #define _LOCORE
61 1.16.2.2 nathanw #endif
62 1.16.2.2 nathanw #include <machine/frame.h>
63 1.16.2.2 nathanw
64 1.16.2.2 nathanw #ifdef __ELF__
65 1.16.2.2 nathanw #define _C_LABEL(name) name
66 1.16.2.2 nathanw #else
67 1.16.2.2 nathanw #ifdef __STDC__
68 1.16.2.2 nathanw #define _C_LABEL(name) _ ## name
69 1.16.2.2 nathanw #else
70 1.16.2.2 nathanw #define _C_LABEL(name) _/**/name
71 1.16.2.2 nathanw #endif
72 1.16.2.2 nathanw #endif
73 1.16.2.2 nathanw #define _ASM_LABEL(name) name
74 1.16.2.2 nathanw
75 1.16.2.2 nathanw #ifdef PIC
76 1.16.2.2 nathanw /*
77 1.16.2.2 nathanw * PIC_PROLOGUE() is akin to the compiler generated function prologue for
78 1.16.2.2 nathanw * PIC code. It leaves the address of the Global Offset Table in DEST,
79 1.16.2.2 nathanw * clobbering register TMP in the process.
80 1.16.2.2 nathanw *
81 1.16.2.2 nathanw * We can use two code sequences. We can read the %pc or use the call
82 1.16.2.2 nathanw * instruction that saves the pc in %o7. Call requires the branch unit and
83 1.16.2.2 nathanw * IEU1, and clobbers %o7 which needs to be restored. This instruction
84 1.16.2.2 nathanw * sequence takes about 4 cycles due to instruction interdependence. Reading
85 1.16.2.2 nathanw * the pc takes 4 cycles to dispatch and is always dispatched alone. That
86 1.16.2.2 nathanw * sequence takes 7 cycles.
87 1.16.2.2 nathanw */
88 1.16.2.2 nathanw #define PIC_PROLOGUE(dest,tmp) \
89 1.16.2.2 nathanw mov %o7, tmp; \
90 1.16.2.2 nathanw sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \
91 1.16.2.2 nathanw call 0f; \
92 1.16.2.2 nathanw or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \
93 1.16.2.2 nathanw 0: \
94 1.16.2.2 nathanw add dest,%o7,dest; \
95 1.16.2.2 nathanw mov tmp, %o7
96 1.16.2.2 nathanw
97 1.16.2.2 nathanw /*
98 1.16.2.2 nathanw * PICCY_SET() does the equivalent of a `set var, %dest' instruction in
99 1.16.2.2 nathanw * a PIC-like way, but without involving the Global Offset Table. This
100 1.16.2.2 nathanw * only works for VARs defined in the same file *and* in the text segment.
101 1.16.2.2 nathanw */
102 1.16.2.2 nathanw #define PICCY_SET(var,dest,tmp) \
103 1.16.2.2 nathanw 3: rd %pc, tmp; add tmp,(var-3b),dest
104 1.16.2.2 nathanw #else
105 1.16.2.2 nathanw #define PIC_PROLOGUE(dest,tmp)
106 1.16.2.2 nathanw #define PICCY_OFFSET(var,dest,tmp)
107 1.16.2.2 nathanw #endif
108 1.16.2.2 nathanw
109 1.16.2.2 nathanw #define FTYPE(x) .type x,@function
110 1.16.2.2 nathanw #define OTYPE(x) .type x,@object
111 1.16.2.2 nathanw
112 1.16.2.2 nathanw #define _ENTRY(name) \
113 1.16.2.2 nathanw .align 4; .globl name; .proc 1; FTYPE(name); name:
114 1.16.2.2 nathanw
115 1.16.2.2 nathanw #ifdef GPROF
116 1.16.2.2 nathanw /* see _MCOUNT_ENTRY in profile.h */
117 1.16.2.2 nathanw #ifdef __ELF__
118 1.16.2.2 nathanw #define _PROF_PROLOGUE \
119 1.16.2.2 nathanw .data; .align 8; 1: .uaword 0; .uaword 0; \
120 1.16.2.2 nathanw .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \
121 1.16.2.2 nathanw or %o0,%lo(1b),%o0; restore
122 1.16.2.2 nathanw #else
123 1.16.2.2 nathanw #define _PROF_PROLOGUE \
124 1.16.2.2 nathanw .data; .align 8; 1: .uaword 0; .uaword 0; \
125 1.16.2.2 nathanw .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call mcount; \
126 1.16.2.2 nathanw or %o0,%lo(1b),%o0; restore
127 1.16.2.2 nathanw #endif
128 1.16.2.2 nathanw #else
129 1.16.2.2 nathanw #define _PROF_PROLOGUE
130 1.16.2.2 nathanw #endif
131 1.16.2.2 nathanw
132 1.16.2.2 nathanw #define ENTRY(name) _ENTRY(_C_LABEL(name)); _PROF_PROLOGUE
133 1.16.2.2 nathanw #define ASENTRY(name) _ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE
134 1.16.2.2 nathanw #define FUNC(name) ASENTRY(name)
135 1.16.2.2 nathanw #define RODATA(name) .align 4; .text; .globl _C_LABEL(name); \
136 1.16.2.2 nathanw OTYPE(_C_LABEL(name)); _C_LABEL(name):
137 1.16.2.2 nathanw
138 1.16.2.2 nathanw
139 1.16.2.2 nathanw #define ASMSTR .asciz
140 1.16.2.2 nathanw
141 1.16.2.2 nathanw #define RCSID(name) .asciz name
142 1.16.2.2 nathanw
143 1.16.2.2 nathanw #ifdef __ELF__
144 1.16.2.2 nathanw #define WEAK_ALIAS(alias,sym) \
145 1.16.2.2 nathanw .weak alias; \
146 1.16.2.2 nathanw alias = sym
147 1.16.2.2 nathanw #endif
148 1.16.2.2 nathanw
149 1.16.2.2 nathanw /*
150 1.16.2.2 nathanw * WARN_REFERENCES: create a warning if the specified symbol is referenced.
151 1.16.2.2 nathanw */
152 1.16.2.2 nathanw #ifdef __ELF__
153 1.16.2.2 nathanw #ifdef __STDC__
154 1.16.2.2 nathanw #define WARN_REFERENCES(_sym,_msg) \
155 1.16.2.2 nathanw .section .gnu.warning. ## _sym ; .ascii _msg ; .text
156 1.16.2.2 nathanw #else
157 1.16.2.2 nathanw #define WARN_REFERENCES(_sym,_msg) \
158 1.16.2.2 nathanw .section .gnu.warning./**/_sym ; .ascii _msg ; .text
159 1.16.2.2 nathanw #endif /* __STDC__ */
160 1.16.2.2 nathanw #else
161 1.16.2.2 nathanw #ifdef __STDC__
162 1.16.2.2 nathanw #define __STRING(x) #x
163 1.16.2.2 nathanw #define WARN_REFERENCES(sym,msg) \
164 1.16.2.2 nathanw .stabs msg ## ,30,0,0,0 ; \
165 1.16.2.2 nathanw .stabs __STRING(_ ## sym) ## ,1,0,0,0
166 1.16.2.2 nathanw #else
167 1.16.2.2 nathanw #define __STRING(x) "x"
168 1.16.2.2 nathanw #define WARN_REFERENCES(sym,msg) \
169 1.16.2.2 nathanw .stabs msg,30,0,0,0 ; \
170 1.16.2.2 nathanw .stabs __STRING(_/**/sym),1,0,0,0
171 1.16.2.2 nathanw #endif /* __STDC__ */
172 1.16.2.2 nathanw #endif /* __ELF__ */
173 1.16.2.2 nathanw
174 1.16.2.2 nathanw #endif /* _ASM_H_ */
175