asm_support_x86_64.S revision ef7d42fca18c16fbaf103822ad16f23246e2905d
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ART_RUNTIME_ARCH_X86_64_ASM_SUPPORT_X86_64_S_ 18#define ART_RUNTIME_ARCH_X86_64_ASM_SUPPORT_X86_64_S_ 19 20#include "asm_support_x86_64.h" 21 22#if defined(__APPLE__) 23 // Mac OS' as(1) doesn't let you name macro parameters. 24 #define MACRO0(macro_name) .macro macro_name 25 #define MACRO1(macro_name, macro_arg1) .macro macro_name 26 #define MACRO2(macro_name, macro_arg1, macro_args2) .macro macro_name 27 #define MACRO3(macro_name, macro_arg1, macro_args2, macro_args3) .macro macro_name 28 #define END_MACRO .endmacro 29 30 // Mac OS' as(1) uses $0, $1, and so on for macro arguments, and function names 31 // are mangled with an extra underscore prefix. The use of $x for arguments 32 // mean that literals need to be represented with $$x in macros. 33 #define SYMBOL(name) _ ## name 34 #define PLT_SYMBOL(name) _ ## name 35 #define VAR(name,index) SYMBOL($index) 36 #define PLT_VAR(name, index) SYMBOL($index) 37 #define REG_VAR(name,index) %$index 38 #define CALL_MACRO(name,index) $index 39 #define LITERAL(value) $value 40 #define MACRO_LITERAL(value) $$value 41 42 // Mac OS' doesn't like cfi_* directives 43 #define CFI_STARTPROC 44 #define CFI_ENDPROC 45 #define CFI_ADJUST_CFA_OFFSET(size) 46 #define CFI_DEF_CFA(reg,size) 47 #define CFI_DEF_CFA_REGISTER(reg) 48 #define CFI_RESTORE(reg) 49 #define CFI_REL_OFFSET(reg,size) 50 51 // Mac OS' doesn't support certain directives 52 #define FUNCTION_TYPE(name) 53 #define SIZE(name) 54#else 55 // Regular gas(1) lets you name macro parameters. 56 #define MACRO0(macro_name) .macro macro_name 57 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1 58 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2 59 #define MACRO3(macro_name, macro_arg1, macro_arg2, macro_arg3) .macro macro_name macro_arg1, macro_arg2, macro_arg3 60 #define END_MACRO .endm 61 62 // Regular gas(1) uses \argument_name for macro arguments. 63 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor 64 // will screw us by inserting a space between the \ and the name. Even in this mode there's 65 // no special meaning to $, so literals are still just $x. The use of altmacro means % is a 66 // special character meaning care needs to be taken when passing registers as macro arguments. 67 .altmacro 68 #define SYMBOL(name) name 69 #define PLT_SYMBOL(name) name@PLT 70 #define VAR(name,index) name& 71 #define PLT_VAR(name, index) name&@PLT 72 #define REG_VAR(name,index) %name 73 #define CALL_MACRO(name,index) name& 74 #define LITERAL(value) $value 75 #define MACRO_LITERAL(value) $value 76 77 // CFI support 78 #define CFI_STARTPROC .cfi_startproc 79 #define CFI_ENDPROC .cfi_endproc 80 #define CFI_ADJUST_CFA_OFFSET(size) .cfi_adjust_cfa_offset size 81 #define CFI_DEF_CFA(reg,size) .cfi_def_cfa reg,size 82 #define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg 83 #define CFI_RESTORE(reg) .cfi_restore reg 84 #define CFI_REL_OFFSET(reg,size) .cfi_rel_offset reg,size 85 86 #define FUNCTION_TYPE(name) .type name&, @function 87 #define SIZE(name) .size name, .-name 88#endif 89 90 /* Cache alignment for function entry */ 91MACRO0(ALIGN_FUNCTION_ENTRY) 92 .balign 16 93END_MACRO 94 95MACRO1(DEFINE_FUNCTION, c_name) 96 FUNCTION_TYPE(\c_name) 97 .globl VAR(c_name, 0) 98 ALIGN_FUNCTION_ENTRY 99VAR(c_name, 0): 100 CFI_STARTPROC 101END_MACRO 102 103MACRO1(END_FUNCTION, c_name) 104 CFI_ENDPROC 105 SIZE(\c_name) 106END_MACRO 107 108MACRO1(PUSH, reg) 109 pushq REG_VAR(reg, 0) 110 CFI_ADJUST_CFA_OFFSET(8) 111 CFI_REL_OFFSET(REG_VAR(reg, 0), 0) 112END_MACRO 113 114MACRO1(POP, reg) 115 popq REG_VAR(reg,0) 116 CFI_ADJUST_CFA_OFFSET(-8) 117 CFI_RESTORE(REG_VAR(reg,0)) 118END_MACRO 119 120MACRO1(UNIMPLEMENTED,name) 121 FUNCTION_TYPE(\name) 122 .globl VAR(name, 0) 123 ALIGN_FUNCTION_ENTRY 124VAR(name, 0): 125 CFI_STARTPROC 126 int3 127 int3 128 CFI_ENDPROC 129 SIZE(\name) 130END_MACRO 131 132MACRO0(SETUP_GOT_NOSAVE) 133 call __x86.get_pc_thunk.bx 134 addl $_GLOBAL_OFFSET_TABLE_, %ebx 135END_MACRO 136 137MACRO0(SETUP_GOT) 138 PUSH ebx 139 SETUP_GOT_NOSAVE 140END_MACRO 141 142MACRO0(UNDO_SETUP_GOT) 143 POP ebx 144END_MACRO 145 146#endif // ART_RUNTIME_ARCH_X86_64_ASM_SUPPORT_X86_64_S_ 147