1 /* 2 * Copyright (C) 2014 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_COMPILER_UTILS_X86_64_CONSTANTS_X86_64_H_ 18 #define ART_COMPILER_UTILS_X86_64_CONSTANTS_X86_64_H_ 19 20 #include <iosfwd> 21 22 #include <android-base/logging.h> 23 24 #include "arch/x86_64/registers_x86_64.h" 25 #include "base/globals.h" 26 #include "base/macros.h" 27 28 namespace art HIDDEN { 29 namespace x86_64 { 30 31 class CpuRegister { 32 public: CpuRegister(Register r)33 explicit constexpr CpuRegister(Register r) : reg_(r) {} CpuRegister(int r)34 explicit constexpr CpuRegister(int r) : reg_(Register(r)) {} AsRegister()35 constexpr Register AsRegister() const { 36 return reg_; 37 } 38 bool operator==(const CpuRegister& other) const { 39 return reg_ == other.reg_; 40 } LowBits()41 constexpr uint8_t LowBits() const { 42 return reg_ & 7; 43 } NeedsRex()44 constexpr bool NeedsRex() const { 45 return reg_ > 7; 46 } 47 private: 48 const Register reg_; 49 }; 50 std::ostream& operator<<(std::ostream& os, const CpuRegister& reg); 51 52 class XmmRegister { 53 public: XmmRegister(FloatRegister r)54 explicit constexpr XmmRegister(FloatRegister r) : reg_(r) {} XmmRegister(int r)55 explicit constexpr XmmRegister(int r) : reg_(FloatRegister(r)) {} AsFloatRegister()56 constexpr FloatRegister AsFloatRegister() const { 57 return reg_; 58 } LowBits()59 constexpr uint8_t LowBits() const { 60 return reg_ & 7; 61 } NeedsRex()62 constexpr bool NeedsRex() const { 63 return reg_ > 7; 64 } 65 bool operator==(const XmmRegister& other) const { 66 return reg_ == other.reg_; 67 } 68 private: 69 const FloatRegister reg_; 70 }; 71 std::ostream& operator<<(std::ostream& os, const XmmRegister& reg); 72 73 enum X87Register { 74 ST0 = 0, 75 ST1 = 1, 76 ST2 = 2, 77 ST3 = 3, 78 ST4 = 4, 79 ST5 = 5, 80 ST6 = 6, 81 ST7 = 7, 82 kNumberOfX87Registers = 8, 83 kNoX87Register = -1 // Signals an illegal register. 84 }; 85 std::ostream& operator<<(std::ostream& os, const X87Register& reg); 86 87 enum Condition { 88 kOverflow = 0, 89 kNoOverflow = 1, 90 kBelow = 2, 91 kAboveEqual = 3, 92 kEqual = 4, 93 kNotEqual = 5, 94 kBelowEqual = 6, 95 kAbove = 7, 96 kSign = 8, 97 kNotSign = 9, 98 kParityEven = 10, 99 kParityOdd = 11, 100 kLess = 12, 101 kGreaterEqual = 13, 102 kLessEqual = 14, 103 kGreater = 15, 104 105 kZero = kEqual, 106 kNotZero = kNotEqual, 107 kNegative = kSign, 108 kPositive = kNotSign, 109 kCarrySet = kBelow, 110 kCarryClear = kAboveEqual, 111 kUnordered = kParityEven 112 }; 113 114 115 class Instr { 116 public: 117 static const uint8_t kHltInstruction = 0xF4; 118 // We prefer not to use the int3 instruction since it conflicts with gdb. 119 static const uint8_t kBreakPointInstruction = kHltInstruction; 120 IsBreakPoint()121 bool IsBreakPoint() { 122 return (*reinterpret_cast<const uint8_t*>(this)) == kBreakPointInstruction; 123 } 124 125 // Instructions are read out of a code stream. The only way to get a 126 // reference to an instruction is to convert a pointer. There is no way 127 // to allocate or create instances of class Instr. 128 // Use the At(pc) function to create references to Instr. At(uintptr_t pc)129 static Instr* At(uintptr_t pc) { return reinterpret_cast<Instr*>(pc); } 130 131 private: 132 DISALLOW_IMPLICIT_CONSTRUCTORS(Instr); 133 }; 134 135 } // namespace x86_64 136 } // namespace art 137 138 #endif // ART_COMPILER_UTILS_X86_64_CONSTANTS_X86_64_H_ 139