]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/arm/asm.h
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
62 #define FRAME pushl %ebp; movl %esp, %ebp
66 /* There is another definition of ALIGN for .c sources */
69 #endif /* ASSEMBLER */
77 #ifndef __NO_UNDERSCORES__
80 #define LEXT(x) _ ## x ## :
82 #define LCL(x) .L ## x
84 #define LEXT(x) x ## :
86 #define LBc(x,n) n ## :
87 #define LBb(x,n) n ## b
88 #define LBf(x,n) n ## f
90 #ifndef __NO_UNDERSCORES__
93 #define LEXT(x) _/**/x/**/:
94 #else /* __NO_UNDERSCORES__ */
95 #define LCL(x) .L/**/x
97 #define LEXT(x) x/**/:
98 #endif /* __NO_UNDERSCORES__ */
99 #define LBc(x,n) n/**/:
100 #define LBb(x,n) n/**/b
101 #define LBf(x,n) n/**/f
102 #endif /* __STDC__ */
104 #define String .asciz
106 #define Times(a,b) (a*b)
107 #define Divide(a,b) (a/b)
111 #define ELF_FUNC(x) .type x,@function
112 #define ELF_DATA(x) .type x,@object
113 #define ELF_SIZE(x,s) .size x,s
117 #define ELF_SIZE(x,s)
122 #define ELF_SIZE(x,s)
125 #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x)
126 #define ENTRY(x) Entry(x) MCOUNT
127 #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \
128 ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \
129 .align FALIGN; LEXT(x); LEXT(y) \
132 #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT
134 #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT
135 #endif /* __STDC__ */
137 #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x)
139 #define End(x) ELF_SIZE(x,.-x)
140 #define END(x) End(EXT(x))
141 #define ENDDATA(x) END(x)
142 #define Enddata(x) End(x)
148 #else /* NOT ASSEMBLER */
150 /* These defines are here for .c files that wish to reference global symbols
151 * within __asm__ statements.
153 #ifndef __NO_UNDERSCORES__
154 #define CC_SYM_PREFIX "_"
156 #define CC_SYM_PREFIX ""
157 #endif /* __NO_UNDERSCORES__ */
158 #endif /* ASSEMBLER */
162 #if defined (_ARM_ARCH_4T)
164 # define RETeq bxeq lr
165 # define RETne bxne lr
167 # define RETc(c) bx##c lr
169 # define RETc(c) bx/**/c lr
172 # define RET mov pc, lr
173 # define RETeq moveq pc, lr
174 # define RETne movne pc, lr
176 # define RETc(c) mov##c pc, lr
178 # define RETc(c) mov/**/c pc, lr
182 #if defined (__thumb__)
183 /* Provide a PI mechanism for thumb branching. */
184 # define BRANCH_EXTERN(x) ldr pc, [pc, #-4] ; \
187 # define BRANCH_EXTERN(x) b EXT(x)
191 * arg0: Register for thread pointer
194 mrc p15
, 0, $
0, c13
, c0
, 4 /* Read TPIDRPRW */
198 /* Macros for loading up addresses that are external to the .s file.
199 * LOAD_ADDR: loads the address for (label) into (reg). Not safe for
201 * LOAD_ADDR_PC: Variant for loading to the PC; load the address of (label)
203 * LOAD_ADDR_GEN_DEF: The general definition needed to support loading
206 * Usage: For any label accessed, we require one (and only one) instance
207 * of LOAD_ADDR_GEN_DEF(label).
210 * LOAD_ADDR(r0, arm_init)
211 * LOAD_ADDR(lr, arm_init_cpu)
212 * LOAD_ADDR_PC(arm_init)
215 * LOAD_ADDR_GEN_DEF(arm_init)
216 * LOAD_ADDR_GEN_DEF(arm_init_cpu)
220 /* Definitions for a position dependent kernel using non-lazy pointers.
223 /* TODO: Make this work with thumb .s files. */
226 /* We need wrapper macros in order to ensure that __LINE__ is expanded.
228 * There is some small potential for duplicate labels here, but because
229 * we do not export the generated labels, it should not be an issue.
232 #define GLUE_LABEL_GUTS(label, tag) L_##label##_##tag##_glue
233 #define GLUE_LABEL(label, tag) GLUE_LABEL_GUTS(label, tag)
235 #define LOAD_ADDR(reg, label) \
236 movw reg, :lower16:(label##$non_lazy_ptr - (GLUE_LABEL(label, __LINE__) + PC_INC)) ; \
237 movt reg, :upper16:(label##$non_lazy_ptr - (GLUE_LABEL(label, __LINE__) + PC_INC)) ; \
238 GLUE_LABEL(label, __LINE__): ; \
241 /* Designed with the understanding that directly branching to thumb code
242 * is unreliable; this should allow for dealing with __thumb__ in
243 * assembly; the non-thumb variant still needs to provide the glue label
244 * to avoid failing to build on undefined symbols.
246 * TODO: Make this actually use a scratch register; this macro is convenient
247 * for translating (ldr pc, [?]) to a slidable format without the risk of
248 * clobbering registers, but it is also wasteful.
250 #if defined(__thumb__)
251 #define LOAD_ADDR_PC(label) \
252 stmfd sp!, { r0 } ; \
253 stmfd sp!, { r0 } ; \
254 LOAD_ADDR(r0, label) ; \
256 ldmfd sp!, { r0 } ; \
259 #define LOAD_ADDR_PC(label) \
263 #define LOAD_ADDR_GEN_DEF(label) \
264 .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers ; \
266 label##$non_lazy_ptr: ; \
267 .indirect_symbol EXT(label) ; \
270 #else /* !SLIDABLE */
272 /* Definitions for a position dependent kernel */
273 #define LOAD_ADDR(reg, label) \
276 #if defined(__thumb__)
277 #define LOAD_ADDR_PC(label) \
280 #define LOAD_ADDR_PC(label) \
284 #define LOAD_ADDR_GEN_DEF(label) \
290 #endif /* SLIDABLE */
292 /* The linker can deal with branching from ARM to thumb in unconditional
293 * branches, but not in conditional branches. To support this in our
294 * assembly (which allows us to build xnu without -mno-thumb), use the
295 * following macros for branching conditionally to external symbols.
296 * These macros are used just like the corresponding conditional branch
300 #define SHIM_LABEL_GUTS(line_num) L_cond_extern_##line_num##_shim
301 #define SHIM_LABEL(line_num) SHIM_LABEL_GUTS(line_num)
303 #define COND_EXTERN_BEQ(label) \
304 bne SHIM_LABEL(__LINE__) ; \
306 SHIM_LABEL(__LINE__):
308 #define COND_EXTERN_BLNE(label) \
309 beq SHIM_LABEL(__LINE__) ; \
311 SHIM_LABEL(__LINE__):
313 #define COND_EXTERN_BLGT(label) \
314 ble SHIM_LABEL(__LINE__) ; \
316 SHIM_LABEL(__LINE__):
318 #endif /* ASSEMBLER */
320 #endif /* _ARM_ASM_H_ */