Home | History | Annotate | Download | only in x86
      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_ASM_SUPPORT_X86_S_
     18 #define ART_RUNTIME_ARCH_X86_ASM_SUPPORT_X86_S_
     19 
     20 #include "asm_support_x86.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 VAR(name,index) SYMBOL($index)
     35     #define REG_VAR(name,index) %$index
     36     #define CALL_MACRO(name,index) $index
     37     #define LITERAL(value) $value
     38     #define MACRO_LITERAL(value) $$value
     39 #else
     40     // Regular gas(1) lets you name macro parameters.
     41     #define MACRO0(macro_name) .macro macro_name
     42     #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
     43     #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
     44     #define MACRO3(macro_name, macro_arg1, macro_arg2, macro_arg3) .macro macro_name macro_arg1, macro_arg2, macro_arg3
     45     #define END_MACRO .endm
     46 
     47     // Regular gas(1) uses \argument_name for macro arguments.
     48     // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
     49     // will screw us by inserting a space between the \ and the name. Even in this mode there's
     50     // no special meaning to $, so literals are still just $x. The use of altmacro means % is a
     51     // special character meaning care needs to be taken when passing registers as macro arguments.
     52     .altmacro
     53     #define SYMBOL(name) name
     54     #define VAR(name,index) name&
     55     #define REG_VAR(name,index) %name
     56     #define CALL_MACRO(name,index) name&
     57     #define LITERAL(value) $value
     58     #define MACRO_LITERAL(value) $value
     59 #endif
     60 
     61     /* Cache alignment for function entry */
     62 MACRO0(ALIGN_FUNCTION_ENTRY)
     63     .balign 16
     64 END_MACRO
     65 
     66 MACRO1(DEFINE_FUNCTION, c_name)
     67     .type VAR(c_name, 0), @function
     68     .globl VAR(c_name, 0)
     69     ALIGN_FUNCTION_ENTRY
     70 VAR(c_name, 0):
     71     .cfi_startproc
     72 END_MACRO
     73 
     74 MACRO1(END_FUNCTION, c_name)
     75     .cfi_endproc
     76     .size \c_name, .-\c_name
     77 END_MACRO
     78 
     79 MACRO1(PUSH, reg)
     80   pushl REG_VAR(reg, 0)
     81   .cfi_adjust_cfa_offset 4
     82   .cfi_rel_offset REG_VAR(reg, 0), 0
     83 END_MACRO
     84 
     85 MACRO1(POP, reg)
     86   popl REG_VAR(reg,0)
     87   .cfi_adjust_cfa_offset -4
     88   .cfi_restore REG_VAR(reg,0)
     89 END_MACRO
     90 
     91 MACRO1(UNIMPLEMENTED,name)
     92     .type VAR(name, 0), @function
     93     .globl VAR(name, 0)
     94     ALIGN_FUNCTION_ENTRY
     95 VAR(name, 0):
     96     .cfi_startproc
     97     int3
     98     int3
     99     .cfi_endproc
    100     .size \name, .-\name
    101 END_MACRO
    102 
    103 #endif  // ART_RUNTIME_ARCH_X86_ASM_SUPPORT_X86_S_
    104