blob: e48b2815991ff763f057c2b5da4b1106a8776596 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
17#ifndef ART_SRC_CONSTANTS_X86_H_
18#define ART_SRC_CONSTANTS_X86_H_
19
Ian Rogersb033c752011-07-20 12:22:35 -070020#include <iosfwd>
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021
22#include "base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080023#include "base/macros.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070024#include "globals.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070025
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070026namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070027namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070028
29enum Register {
30 EAX = 0,
31 ECX = 1,
32 EDX = 2,
33 EBX = 3,
34 ESP = 4,
35 EBP = 5,
36 ESI = 6,
37 EDI = 7,
38 kNumberOfCpuRegisters = 8,
39 kFirstByteUnsafeRegister = 4,
40 kNoRegister = -1 // Signals an illegal register.
41};
Elliott Hughes1f359b02011-07-17 14:27:17 -070042std::ostream& operator<<(std::ostream& os, const Register& rhs);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070043
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070044enum ByteRegister {
45 AL = 0,
46 CL = 1,
47 DL = 2,
48 BL = 3,
49 AH = 4,
50 CH = 5,
51 DH = 6,
52 BH = 7,
53 kNoByteRegister = -1 // Signals an illegal register.
54};
55
56
57enum XmmRegister {
58 XMM0 = 0,
59 XMM1 = 1,
60 XMM2 = 2,
61 XMM3 = 3,
62 XMM4 = 4,
63 XMM5 = 5,
64 XMM6 = 6,
65 XMM7 = 7,
66 kNumberOfXmmRegisters = 8,
67 kNoXmmRegister = -1 // Signals an illegal register.
68};
Ian Rogersb033c752011-07-20 12:22:35 -070069std::ostream& operator<<(std::ostream& os, const XmmRegister& reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070070
Ian Rogersb033c752011-07-20 12:22:35 -070071enum X87Register {
72 ST0 = 0,
73 ST1 = 1,
74 ST2 = 2,
75 ST3 = 3,
76 ST4 = 4,
77 ST5 = 5,
78 ST6 = 6,
79 ST7 = 7,
80 kNumberOfX87Registers = 8,
81 kNoX87Register = -1 // Signals an illegal register.
82};
83std::ostream& operator<<(std::ostream& os, const X87Register& reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070084
85enum ScaleFactor {
86 TIMES_1 = 0,
87 TIMES_2 = 1,
88 TIMES_4 = 2,
89 TIMES_8 = 3
90};
91
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070092enum Condition {
Elliott Hughes18c07532011-08-18 15:50:51 -070093 kOverflow = 0,
94 kNoOverflow = 1,
95 kBelow = 2,
96 kAboveEqual = 3,
97 kEqual = 4,
98 kNotEqual = 5,
99 kBelowEqual = 6,
100 kAbove = 7,
101 kSign = 8,
102 kNotSign = 9,
103 kParityEven = 10,
104 kParityOdd = 11,
105 kLess = 12,
106 kGreaterEqual = 13,
107 kLessEqual = 14,
108 kGreater = 15,
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700109
Elliott Hughes18c07532011-08-18 15:50:51 -0700110 kZero = kEqual,
111 kNotZero = kNotEqual,
112 kNegative = kSign,
113 kPositive = kNotSign
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700114};
115
116
117class Instr {
118 public:
119 static const uint8_t kHltInstruction = 0xF4;
120 // We prefer not to use the int3 instruction since it conflicts with gdb.
121 static const uint8_t kBreakPointInstruction = kHltInstruction;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700122
123 bool IsBreakPoint() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700124 return (*reinterpret_cast<const uint8_t*>(this)) == kBreakPointInstruction;
125 }
126
127 // Instructions are read out of a code stream. The only way to get a
128 // reference to an instruction is to convert a pointer. There is no way
129 // to allocate or create instances of class Instr.
130 // Use the At(pc) function to create references to Instr.
131 static Instr* At(uintptr_t pc) { return reinterpret_cast<Instr*>(pc); }
132
133 private:
134 DISALLOW_IMPLICIT_CONSTRUCTORS(Instr);
135};
136
Ian Rogers2c8f6532011-09-02 17:16:34 -0700137} // namespace x86
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700138} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700139
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700140#endif // ART_SRC_CONSTANTS_X86_H_