1*2c2f96dcSApple OSS Distributions /* 2*2c2f96dcSApple OSS Distributions * Copyright (c) 2007 Apple Inc. All rights reserved. 3*2c2f96dcSApple OSS Distributions * 4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*2c2f96dcSApple OSS Distributions * 6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*2c2f96dcSApple OSS Distributions * 15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at 16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*2c2f96dcSApple OSS Distributions * 18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are 19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and 24*2c2f96dcSApple OSS Distributions * limitations under the License. 25*2c2f96dcSApple OSS Distributions * 26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*2c2f96dcSApple OSS Distributions */ 28*2c2f96dcSApple OSS Distributions /* 29*2c2f96dcSApple OSS Distributions * @OSF_COPYRIGHT@ 30*2c2f96dcSApple OSS Distributions */ 31*2c2f96dcSApple OSS Distributions /* 32*2c2f96dcSApple OSS Distributions * Mach Operating System 33*2c2f96dcSApple OSS Distributions * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34*2c2f96dcSApple OSS Distributions * All Rights Reserved. 35*2c2f96dcSApple OSS Distributions * 36*2c2f96dcSApple OSS Distributions * Permission to use, copy, modify and distribute this software and its 37*2c2f96dcSApple OSS Distributions * documentation is hereby granted, provided that both the copyright 38*2c2f96dcSApple OSS Distributions * notice and this permission notice appear in all copies of the 39*2c2f96dcSApple OSS Distributions * software, derivative works or modified versions, and any portions 40*2c2f96dcSApple OSS Distributions * thereof, and that both notices appear in supporting documentation. 41*2c2f96dcSApple OSS Distributions * 42*2c2f96dcSApple OSS Distributions * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43*2c2f96dcSApple OSS Distributions * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44*2c2f96dcSApple OSS Distributions * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45*2c2f96dcSApple OSS Distributions * 46*2c2f96dcSApple OSS Distributions * Carnegie Mellon requests users of this software to return to 47*2c2f96dcSApple OSS Distributions * 48*2c2f96dcSApple OSS Distributions * Software Distribution Coordinator or [email protected] 49*2c2f96dcSApple OSS Distributions * School of Computer Science 50*2c2f96dcSApple OSS Distributions * Carnegie Mellon University 51*2c2f96dcSApple OSS Distributions * Pittsburgh PA 15213-3890 52*2c2f96dcSApple OSS Distributions * 53*2c2f96dcSApple OSS Distributions * any improvements or extensions that they make and grant Carnegie Mellon 54*2c2f96dcSApple OSS Distributions * the rights to redistribute these changes. 55*2c2f96dcSApple OSS Distributions */ 56*2c2f96dcSApple OSS Distributions 57*2c2f96dcSApple OSS Distributions #ifndef _ARM_ASM_H_ 58*2c2f96dcSApple OSS Distributions #define _ARM_ASM_H_ 59*2c2f96dcSApple OSS Distributions 60*2c2f96dcSApple OSS Distributions #if defined (__arm__) || defined (__arm64__) 61*2c2f96dcSApple OSS Distributions 62*2c2f96dcSApple OSS Distributions #include <arm/arch.h> 63*2c2f96dcSApple OSS Distributions 64*2c2f96dcSApple OSS Distributions #define FRAME pushl %ebp; movl %esp, %ebp 65*2c2f96dcSApple OSS Distributions #define EMARF leave 66*2c2f96dcSApple OSS Distributions 67*2c2f96dcSApple OSS Distributions 68*2c2f96dcSApple OSS Distributions /* There is another definition of ALIGN for .c sources */ 69*2c2f96dcSApple OSS Distributions #ifdef ASSEMBLER 70*2c2f96dcSApple OSS Distributions #define ALIGN 2 71*2c2f96dcSApple OSS Distributions #endif /* ASSEMBLER */ 72*2c2f96dcSApple OSS Distributions 73*2c2f96dcSApple OSS Distributions #ifndef FALIGN 74*2c2f96dcSApple OSS Distributions #define FALIGN ALIGN 75*2c2f96dcSApple OSS Distributions #endif 76*2c2f96dcSApple OSS Distributions 77*2c2f96dcSApple OSS Distributions #define LB(x,n) n 78*2c2f96dcSApple OSS Distributions #if __STDC__ 79*2c2f96dcSApple OSS Distributions #ifndef __NO_UNDERSCORES__ 80*2c2f96dcSApple OSS Distributions #define LCL(x) L ## x 81*2c2f96dcSApple OSS Distributions #define EXT(x) _ ## x 82*2c2f96dcSApple OSS Distributions #define LEXT(x) _ ## x ## : 83*2c2f96dcSApple OSS Distributions #else 84*2c2f96dcSApple OSS Distributions #define LCL(x) .L ## x 85*2c2f96dcSApple OSS Distributions #define EXT(x) x 86*2c2f96dcSApple OSS Distributions #define LEXT(x) x ## : 87*2c2f96dcSApple OSS Distributions #endif 88*2c2f96dcSApple OSS Distributions #define LBc(x,n) n ## : 89*2c2f96dcSApple OSS Distributions #define LBb(x,n) n ## b 90*2c2f96dcSApple OSS Distributions #define LBf(x,n) n ## f 91*2c2f96dcSApple OSS Distributions #else /* __STDC__ */ 92*2c2f96dcSApple OSS Distributions #ifndef __NO_UNDERSCORES__ 93*2c2f96dcSApple OSS Distributions #define LCL(x) L/**/x 94*2c2f96dcSApple OSS Distributions #define EXT(x) _/**/x 95*2c2f96dcSApple OSS Distributions #define LEXT(x) _/**/x/**/: 96*2c2f96dcSApple OSS Distributions #else /* __NO_UNDERSCORES__ */ 97*2c2f96dcSApple OSS Distributions #define LCL(x) .L/**/x 98*2c2f96dcSApple OSS Distributions #define EXT(x) x 99*2c2f96dcSApple OSS Distributions #define LEXT(x) x/**/: 100*2c2f96dcSApple OSS Distributions #endif /* __NO_UNDERSCORES__ */ 101*2c2f96dcSApple OSS Distributions #define LBc(x,n) n/**/: 102*2c2f96dcSApple OSS Distributions #define LBb(x,n) n/**/b 103*2c2f96dcSApple OSS Distributions #define LBf(x,n) n/**/f 104*2c2f96dcSApple OSS Distributions #endif /* __STDC__ */ 105*2c2f96dcSApple OSS Distributions 106*2c2f96dcSApple OSS Distributions #define String .asciz 107*2c2f96dcSApple OSS Distributions #define Value .word 108*2c2f96dcSApple OSS Distributions #define Times(a,b) (a*b) 109*2c2f96dcSApple OSS Distributions #define Divide(a,b) (a/b) 110*2c2f96dcSApple OSS Distributions 111*2c2f96dcSApple OSS Distributions #if 0 /* TOTOJK */ 112*2c2f96dcSApple OSS Distributions #ifdef __ELF__ 113*2c2f96dcSApple OSS Distributions #define ELF_FUNC(x) .type x,@function 114*2c2f96dcSApple OSS Distributions #define ELF_DATA(x) .type x,@object 115*2c2f96dcSApple OSS Distributions #define ELF_SIZE(x,s) .size x,s 116*2c2f96dcSApple OSS Distributions #else 117*2c2f96dcSApple OSS Distributions #define ELF_FUNC(x) 118*2c2f96dcSApple OSS Distributions #define ELF_DATA(x) 119*2c2f96dcSApple OSS Distributions #define ELF_SIZE(x,s) 120*2c2f96dcSApple OSS Distributions #endif 121*2c2f96dcSApple OSS Distributions #else 122*2c2f96dcSApple OSS Distributions #define ELF_FUNC(x) 123*2c2f96dcSApple OSS Distributions #define ELF_DATA(x) 124*2c2f96dcSApple OSS Distributions #define ELF_SIZE(x,s) 125*2c2f96dcSApple OSS Distributions #endif /* TODOJK */ 126*2c2f96dcSApple OSS Distributions 127*2c2f96dcSApple OSS Distributions #define Entry(x) .globl EXT(x); ELF_FUNC(EXT(x)); .align FALIGN; LEXT(x) 128*2c2f96dcSApple OSS Distributions #define ENTRY(x) Entry(x) MCOUNT 129*2c2f96dcSApple OSS Distributions #define ENTRY2(x,y) .globl EXT(x); .globl EXT(y); \ 130*2c2f96dcSApple OSS Distributions ELF_FUNC(EXT(x)); ELF_FUNC(EXT(y)); \ 131*2c2f96dcSApple OSS Distributions .align FALIGN; LEXT(x); LEXT(y) \ 132*2c2f96dcSApple OSS Distributions MCOUNT 133*2c2f96dcSApple OSS Distributions #if __STDC__ 134*2c2f96dcSApple OSS Distributions #define ASENTRY(x) .globl x; .align FALIGN; x ## : ELF_FUNC(x) MCOUNT 135*2c2f96dcSApple OSS Distributions #else 136*2c2f96dcSApple OSS Distributions #define ASENTRY(x) .globl x; .align FALIGN; x: ELF_FUNC(x) MCOUNT 137*2c2f96dcSApple OSS Distributions #endif /* __STDC__ */ 138*2c2f96dcSApple OSS Distributions 139*2c2f96dcSApple OSS Distributions #define DATA(x) .globl EXT(x); ELF_DATA(EXT(x)); .align ALIGN; LEXT(x) 140*2c2f96dcSApple OSS Distributions 141*2c2f96dcSApple OSS Distributions #define End(x) ELF_SIZE(x,.-x) 142*2c2f96dcSApple OSS Distributions #define END(x) End(EXT(x)) 143*2c2f96dcSApple OSS Distributions #define ENDDATA(x) END(x) 144*2c2f96dcSApple OSS Distributions #define Enddata(x) End(x) 145*2c2f96dcSApple OSS Distributions 146*2c2f96dcSApple OSS Distributions #ifdef ASSEMBLER 147*2c2f96dcSApple OSS Distributions 148*2c2f96dcSApple OSS Distributions #define MCOUNT 149*2c2f96dcSApple OSS Distributions 150*2c2f96dcSApple OSS Distributions #else /* NOT ASSEMBLER */ 151*2c2f96dcSApple OSS Distributions 152*2c2f96dcSApple OSS Distributions /* These defines are here for .c files that wish to reference global symbols 153*2c2f96dcSApple OSS Distributions * within __asm__ statements. 154*2c2f96dcSApple OSS Distributions */ 155*2c2f96dcSApple OSS Distributions #ifndef __NO_UNDERSCORES__ 156*2c2f96dcSApple OSS Distributions #define CC_SYM_PREFIX "_" 157*2c2f96dcSApple OSS Distributions #else 158*2c2f96dcSApple OSS Distributions #define CC_SYM_PREFIX "" 159*2c2f96dcSApple OSS Distributions #endif /* __NO_UNDERSCORES__ */ 160*2c2f96dcSApple OSS Distributions #endif /* ASSEMBLER */ 161*2c2f96dcSApple OSS Distributions 162*2c2f96dcSApple OSS Distributions #ifdef ASSEMBLER 163*2c2f96dcSApple OSS Distributions 164*2c2f96dcSApple OSS Distributions #if defined (_ARM_ARCH_4T) 165*2c2f96dcSApple OSS Distributions # define RET bx lr 166*2c2f96dcSApple OSS Distributions # define RETeq bxeq lr 167*2c2f96dcSApple OSS Distributions # define RETne bxne lr 168*2c2f96dcSApple OSS Distributions # ifdef __STDC__ 169*2c2f96dcSApple OSS Distributions # define RETc(c) bx##c lr 170*2c2f96dcSApple OSS Distributions # else 171*2c2f96dcSApple OSS Distributions # define RETc(c) bx/**/c lr 172*2c2f96dcSApple OSS Distributions # endif 173*2c2f96dcSApple OSS Distributions #else 174*2c2f96dcSApple OSS Distributions # define RET mov pc, lr 175*2c2f96dcSApple OSS Distributions # define RETeq moveq pc, lr 176*2c2f96dcSApple OSS Distributions # define RETne movne pc, lr 177*2c2f96dcSApple OSS Distributions # ifdef __STDC__ 178*2c2f96dcSApple OSS Distributions # define RETc(c) mov##c pc, lr 179*2c2f96dcSApple OSS Distributions # else 180*2c2f96dcSApple OSS Distributions # define RETc(c) mov/**/c pc, lr 181*2c2f96dcSApple OSS Distributions # endif 182*2c2f96dcSApple OSS Distributions #endif 183*2c2f96dcSApple OSS Distributions 184*2c2f96dcSApple OSS Distributions #if defined (__thumb__) 185*2c2f96dcSApple OSS Distributions /* Provide a PI mechanism for thumb branching. */ 186*2c2f96dcSApple OSS Distributions # define BRANCH_EXTERN(x) ldr pc, [pc, #-4] ; \ 187*2c2f96dcSApple OSS Distributions .long EXT(x) 188*2c2f96dcSApple OSS Distributions #else 189*2c2f96dcSApple OSS Distributions # define BRANCH_EXTERN(x) b EXT(x) 190*2c2f96dcSApple OSS Distributions #endif 191*2c2f96dcSApple OSS Distributions 192*2c2f96dcSApple OSS Distributions /* 193*2c2f96dcSApple OSS Distributions * arg0: Register for thread pointer 194*2c2f96dcSApple OSS Distributions */ 195*2c2f96dcSApple OSS Distributions .macro READ_THREAD 196*2c2f96dcSApple OSS Distributions mrc p15, 0, $0, c13, c0, 4 /* Read TPIDRPRW */ 197*2c2f96dcSApple OSS Distributions .endmacro 198*2c2f96dcSApple OSS Distributions 199*2c2f96dcSApple OSS Distributions 200*2c2f96dcSApple OSS Distributions /* Macros for loading up addresses that are external to the .s file. 201*2c2f96dcSApple OSS Distributions * LOAD_ADDR: loads the address for (label) into (reg). Not safe for 202*2c2f96dcSApple OSS Distributions * loading to the PC. 203*2c2f96dcSApple OSS Distributions * LOAD_ADDR_PC: Variant for loading to the PC; load the address of (label) 204*2c2f96dcSApple OSS Distributions * into the pc. 205*2c2f96dcSApple OSS Distributions * LOAD_ADDR_GEN_DEF: The general definition needed to support loading 206*2c2f96dcSApple OSS Distributions * a label address. 207*2c2f96dcSApple OSS Distributions * 208*2c2f96dcSApple OSS Distributions * Usage: For any label accessed, we require one (and only one) instance 209*2c2f96dcSApple OSS Distributions * of LOAD_ADDR_GEN_DEF(label). 210*2c2f96dcSApple OSS Distributions * 211*2c2f96dcSApple OSS Distributions * Example: 212*2c2f96dcSApple OSS Distributions * LOAD_ADDR(r0, arm_init) 213*2c2f96dcSApple OSS Distributions * LOAD_ADDR(lr, arm_init_cpu) 214*2c2f96dcSApple OSS Distributions * LOAD_ADDR_PC(arm_init) 215*2c2f96dcSApple OSS Distributions * ... 216*2c2f96dcSApple OSS Distributions * 217*2c2f96dcSApple OSS Distributions * LOAD_ADDR_GEN_DEF(arm_init) 218*2c2f96dcSApple OSS Distributions * LOAD_ADDR_GEN_DEF(arm_init_cpu) 219*2c2f96dcSApple OSS Distributions */ 220*2c2f96dcSApple OSS Distributions 221*2c2f96dcSApple OSS Distributions /* Definitions for a position dependent kernel using non-lazy pointers. 222*2c2f96dcSApple OSS Distributions */ 223*2c2f96dcSApple OSS Distributions 224*2c2f96dcSApple OSS Distributions /* TODO: Make this work with thumb .s files. */ 225*2c2f96dcSApple OSS Distributions #define PC_INC 0x8 226*2c2f96dcSApple OSS Distributions 227*2c2f96dcSApple OSS Distributions /* We need wrapper macros in order to ensure that __LINE__ is expanded. 228*2c2f96dcSApple OSS Distributions * 229*2c2f96dcSApple OSS Distributions * There is some small potential for duplicate labels here, but because 230*2c2f96dcSApple OSS Distributions * we do not export the generated labels, it should not be an issue. 231*2c2f96dcSApple OSS Distributions */ 232*2c2f96dcSApple OSS Distributions 233*2c2f96dcSApple OSS Distributions #define GLUE_LABEL_GUTS(label, tag) L_##label##_##tag##_glue 234*2c2f96dcSApple OSS Distributions #define GLUE_LABEL(label, tag) GLUE_LABEL_GUTS(label, tag) 235*2c2f96dcSApple OSS Distributions 236*2c2f96dcSApple OSS Distributions #define LOAD_ADDR(reg, label) \ 237*2c2f96dcSApple OSS Distributions movw reg, :lower16:(label##$non_lazy_ptr - (GLUE_LABEL(label, __LINE__) + PC_INC)) ; \ 238*2c2f96dcSApple OSS Distributions movt reg, :upper16:(label##$non_lazy_ptr - (GLUE_LABEL(label, __LINE__) + PC_INC)) ; \ 239*2c2f96dcSApple OSS Distributions GLUE_LABEL(label, __LINE__): ; \ 240*2c2f96dcSApple OSS Distributions ldr reg, [pc, reg] 241*2c2f96dcSApple OSS Distributions 242*2c2f96dcSApple OSS Distributions /* Designed with the understanding that directly branching to thumb code 243*2c2f96dcSApple OSS Distributions * is unreliable; this should allow for dealing with __thumb__ in 244*2c2f96dcSApple OSS Distributions * assembly; the non-thumb variant still needs to provide the glue label 245*2c2f96dcSApple OSS Distributions * to avoid failing to build on undefined symbols. 246*2c2f96dcSApple OSS Distributions * 247*2c2f96dcSApple OSS Distributions * TODO: Make this actually use a scratch register; this macro is convenient 248*2c2f96dcSApple OSS Distributions * for translating (ldr pc, [?]) to a slidable format without the risk of 249*2c2f96dcSApple OSS Distributions * clobbering registers, but it is also wasteful. 250*2c2f96dcSApple OSS Distributions */ 251*2c2f96dcSApple OSS Distributions #if defined(__thumb__) 252*2c2f96dcSApple OSS Distributions #define LOAD_ADDR_PC(label) \ 253*2c2f96dcSApple OSS Distributions stmfd sp!, { r0 } ; \ 254*2c2f96dcSApple OSS Distributions stmfd sp!, { r0 } ; \ 255*2c2f96dcSApple OSS Distributions LOAD_ADDR(r0, label) ; \ 256*2c2f96dcSApple OSS Distributions str r0, [sp, #4] ; \ 257*2c2f96dcSApple OSS Distributions ldmfd sp!, { r0 } ; \ 258*2c2f96dcSApple OSS Distributions ldmfd sp!, { pc } 259*2c2f96dcSApple OSS Distributions #else 260*2c2f96dcSApple OSS Distributions #define LOAD_ADDR_PC(label) \ 261*2c2f96dcSApple OSS Distributions b EXT(label) 262*2c2f96dcSApple OSS Distributions #endif 263*2c2f96dcSApple OSS Distributions 264*2c2f96dcSApple OSS Distributions #define LOAD_ADDR_GEN_DEF(label) \ 265*2c2f96dcSApple OSS Distributions .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers ; \ 266*2c2f96dcSApple OSS Distributions .align 2 ; \ 267*2c2f96dcSApple OSS Distributions label##$non_lazy_ptr: ; \ 268*2c2f96dcSApple OSS Distributions .indirect_symbol EXT(label) ; \ 269*2c2f96dcSApple OSS Distributions .long 0 270*2c2f96dcSApple OSS Distributions 271*2c2f96dcSApple OSS Distributions /* The linker can deal with branching from ARM to thumb in unconditional 272*2c2f96dcSApple OSS Distributions * branches, but not in conditional branches. To support this in our 273*2c2f96dcSApple OSS Distributions * assembly (which allows us to build xnu without -mno-thumb), use the 274*2c2f96dcSApple OSS Distributions * following macros for branching conditionally to external symbols. 275*2c2f96dcSApple OSS Distributions * These macros are used just like the corresponding conditional branch 276*2c2f96dcSApple OSS Distributions * instructions. 277*2c2f96dcSApple OSS Distributions */ 278*2c2f96dcSApple OSS Distributions 279*2c2f96dcSApple OSS Distributions #define SHIM_LABEL_GUTS(line_num) L_cond_extern_##line_num##_shim 280*2c2f96dcSApple OSS Distributions #define SHIM_LABEL(line_num) SHIM_LABEL_GUTS(line_num) 281*2c2f96dcSApple OSS Distributions 282*2c2f96dcSApple OSS Distributions #define COND_EXTERN_BEQ(label) \ 283*2c2f96dcSApple OSS Distributions bne SHIM_LABEL(__LINE__) ; \ 284*2c2f96dcSApple OSS Distributions b EXT(label) ; \ 285*2c2f96dcSApple OSS Distributions SHIM_LABEL(__LINE__): 286*2c2f96dcSApple OSS Distributions 287*2c2f96dcSApple OSS Distributions #define COND_EXTERN_BLNE(label) \ 288*2c2f96dcSApple OSS Distributions beq SHIM_LABEL(__LINE__) ; \ 289*2c2f96dcSApple OSS Distributions bl EXT(label) ; \ 290*2c2f96dcSApple OSS Distributions SHIM_LABEL(__LINE__): 291*2c2f96dcSApple OSS Distributions 292*2c2f96dcSApple OSS Distributions #define COND_EXTERN_BLGT(label) \ 293*2c2f96dcSApple OSS Distributions ble SHIM_LABEL(__LINE__) ; \ 294*2c2f96dcSApple OSS Distributions bl EXT(label) ; \ 295*2c2f96dcSApple OSS Distributions SHIM_LABEL(__LINE__): 296*2c2f96dcSApple OSS Distributions 297*2c2f96dcSApple OSS Distributions #endif /* ASSEMBLER */ 298*2c2f96dcSApple OSS Distributions 299*2c2f96dcSApple OSS Distributions #endif /* defined (__arm__) || defined (__arm64__) */ 300*2c2f96dcSApple OSS Distributions 301*2c2f96dcSApple OSS Distributions #endif /* _ARM_ASM_H_ */ 302