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