asm_support_x86_64.S revision f4e910badbaa5aa48efbf697715f4815f0ebc7e4
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(__clang__) && (__clang_major__ < 4) && (__clang_minor__ < 5) 23 // Clang's as(1) doesn't let you name macro parameters prior to 3.5. 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 // Clang's as(1) uses $0, $1, and so on for macro arguments prior to 3.5. 31 #define VAR(name,index) SYMBOL($index) 32 #define PLT_VAR(name, index) SYMBOL($index)@PLT 33 #define REG_VAR(name,index) %$index 34 #define CALL_MACRO(name,index) $index 35 #define FUNCTION_TYPE(name,index) .type $index, @function 36 #define SIZE(name,index) .size $index, .-$index 37 38 // The use of $x for arguments mean that literals need to be represented with $$x in macros. 39 #define LITERAL(value) $value 40 #define MACRO_LITERAL(value) $$value 41#else 42 // Regular gas(1) lets you name macro parameters. 43 #define MACRO0(macro_name) .macro macro_name 44 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1 45 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2 46 #define MACRO3(macro_name, macro_arg1, macro_arg2, macro_arg3) .macro macro_name macro_arg1, macro_arg2, macro_arg3 47 #define END_MACRO .endm 48 49 // Regular gas(1) uses \argument_name for macro arguments. 50 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor 51 // will screw us by inserting a space between the \ and the name. Even in this mode there's 52 // no special meaning to $, so literals are still just $x. The use of altmacro means % is a 53 // special character meaning care needs to be taken when passing registers as macro arguments. 54 .altmacro 55 #define VAR(name,index) name& 56 #define PLT_VAR(name, index) name&@PLT 57 #define REG_VAR(name,index) %name 58 #define CALL_MACRO(name,index) name& 59 #define FUNCTION_TYPE(name,index) .type name&, @function 60 #define SIZE(name,index) .size name, .-name 61 62 #define LITERAL(value) $value 63 #define MACRO_LITERAL(value) $value 64#endif 65 66 // CFI support. 67#if !defined(__APPLE__) 68 #define CFI_STARTPROC .cfi_startproc 69 #define CFI_ENDPROC .cfi_endproc 70 #define CFI_ADJUST_CFA_OFFSET(size) .cfi_adjust_cfa_offset size 71 #define CFI_DEF_CFA(reg,size) .cfi_def_cfa reg,size 72 #define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg 73 #define CFI_RESTORE(reg) .cfi_restore reg 74 #define CFI_REL_OFFSET(reg,size) .cfi_rel_offset reg,size 75#else 76 // Mac OS' doesn't like cfi_* directives. 77 #define CFI_STARTPROC 78 #define CFI_ENDPROC 79 #define CFI_ADJUST_CFA_OFFSET(size) 80 #define CFI_DEF_CFA(reg,size) 81 #define CFI_DEF_CFA_REGISTER(reg) 82 #define CFI_RESTORE(reg) 83 #define CFI_REL_OFFSET(reg,size) 84#endif 85 86 // Symbols. 87#if !defined(__APPLE__) 88 #define SYMBOL(name) name 89 #define PLT_SYMBOL(name) name ## @PLT 90#else 91 // Mac OS' symbols have an _ prefix. 92 #define SYMBOL(name) _ ## name 93 #define PLT_SYMBOL(name) _ ## name 94#endif 95 96 /* Cache alignment for function entry */ 97MACRO0(ALIGN_FUNCTION_ENTRY) 98 .balign 16 99END_MACRO 100 101MACRO1(DEFINE_FUNCTION, c_name) 102 FUNCTION_TYPE(\c_name, 0) 103 .globl VAR(c_name, 0) 104 ALIGN_FUNCTION_ENTRY 105VAR(c_name, 0): 106 // Have a local entrypoint that's not globl 107VAR(c_name, 0)_local: 108 CFI_STARTPROC 109 // Ensure we get a sane starting CFA. 110 CFI_DEF_CFA(rsp, 8) 111END_MACRO 112 113MACRO1(END_FUNCTION, c_name) 114 CFI_ENDPROC 115 SIZE(\c_name, 0) 116END_MACRO 117 118MACRO1(PUSH, reg) 119 pushq REG_VAR(reg, 0) 120 CFI_ADJUST_CFA_OFFSET(8) 121 CFI_REL_OFFSET(REG_VAR(reg, 0), 0) 122END_MACRO 123 124MACRO1(POP, reg) 125 popq REG_VAR(reg,0) 126 CFI_ADJUST_CFA_OFFSET(-8) 127 CFI_RESTORE(REG_VAR(reg,0)) 128END_MACRO 129 130MACRO1(UNIMPLEMENTED,name) 131 FUNCTION_TYPE(\name, 0) 132 .globl VAR(name, 0) 133 ALIGN_FUNCTION_ENTRY 134VAR(name, 0): 135 CFI_STARTPROC 136 int3 137 int3 138 CFI_ENDPROC 139 SIZE(\name, 0) 140END_MACRO 141 142MACRO0(UNREACHABLE) 143 int3 144END_MACRO 145 146MACRO0(UNTESTED) 147 int3 148END_MACRO 149 150#endif // ART_RUNTIME_ARCH_X86_64_ASM_SUPPORT_X86_64_S_ 151