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