blob: 391d0780cacd91333ba31dfb4aecd6774daf7465 [file] [log] [blame]
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_CONSTANTS_X86_H_
4#define ART_SRC_CONSTANTS_X86_H_
5
Ian Rogersb033c752011-07-20 12:22:35 -07006#include <iosfwd>
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "globals.h"
8#include "logging.h"
9#include "macros.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070010
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070011namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070012
13enum Register {
14 EAX = 0,
15 ECX = 1,
16 EDX = 2,
17 EBX = 3,
18 ESP = 4,
19 EBP = 5,
20 ESI = 6,
21 EDI = 7,
22 kNumberOfCpuRegisters = 8,
23 kFirstByteUnsafeRegister = 4,
24 kNoRegister = -1 // Signals an illegal register.
25};
Elliott Hughes1f359b02011-07-17 14:27:17 -070026std::ostream& operator<<(std::ostream& os, const Register& rhs);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070027
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070028enum ByteRegister {
29 AL = 0,
30 CL = 1,
31 DL = 2,
32 BL = 3,
33 AH = 4,
34 CH = 5,
35 DH = 6,
36 BH = 7,
37 kNoByteRegister = -1 // Signals an illegal register.
38};
39
40
41enum XmmRegister {
42 XMM0 = 0,
43 XMM1 = 1,
44 XMM2 = 2,
45 XMM3 = 3,
46 XMM4 = 4,
47 XMM5 = 5,
48 XMM6 = 6,
49 XMM7 = 7,
50 kNumberOfXmmRegisters = 8,
51 kNoXmmRegister = -1 // Signals an illegal register.
52};
Ian Rogersb033c752011-07-20 12:22:35 -070053std::ostream& operator<<(std::ostream& os, const XmmRegister& reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070054
Ian Rogersb033c752011-07-20 12:22:35 -070055enum X87Register {
56 ST0 = 0,
57 ST1 = 1,
58 ST2 = 2,
59 ST3 = 3,
60 ST4 = 4,
61 ST5 = 5,
62 ST6 = 6,
63 ST7 = 7,
64 kNumberOfX87Registers = 8,
65 kNoX87Register = -1 // Signals an illegal register.
66};
67std::ostream& operator<<(std::ostream& os, const X87Register& reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070068
69enum ScaleFactor {
70 TIMES_1 = 0,
71 TIMES_2 = 1,
72 TIMES_4 = 2,
73 TIMES_8 = 3
74};
75
76
77enum Condition {
78 OVERFLOW = 0,
79 NO_OVERFLOW = 1,
80 BELOW = 2,
81 ABOVE_EQUAL = 3,
82 EQUAL = 4,
83 NOT_EQUAL = 5,
84 BELOW_EQUAL = 6,
85 ABOVE = 7,
86 SIGN = 8,
87 NOT_SIGN = 9,
88 PARITY_EVEN = 10,
89 PARITY_ODD = 11,
90 LESS = 12,
91 GREATER_EQUAL = 13,
92 LESS_EQUAL = 14,
93 GREATER = 15,
94
95 ZERO = EQUAL,
96 NOT_ZERO = NOT_EQUAL,
97 NEGATIVE = SIGN,
98 POSITIVE = NOT_SIGN
99};
100
101
102class Instr {
103 public:
104 static const uint8_t kHltInstruction = 0xF4;
105 // We prefer not to use the int3 instruction since it conflicts with gdb.
106 static const uint8_t kBreakPointInstruction = kHltInstruction;
107 static const int kBreakPointInstructionSize = 1;
108
109 bool IsBreakPoint() {
110 CHECK_EQ(kBreakPointInstructionSize, 1);
111 return (*reinterpret_cast<const uint8_t*>(this)) == kBreakPointInstruction;
112 }
113
114 // Instructions are read out of a code stream. The only way to get a
115 // reference to an instruction is to convert a pointer. There is no way
116 // to allocate or create instances of class Instr.
117 // Use the At(pc) function to create references to Instr.
118 static Instr* At(uintptr_t pc) { return reinterpret_cast<Instr*>(pc); }
119
120 private:
121 DISALLOW_IMPLICIT_CONSTRUCTORS(Instr);
122};
123
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700124} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700125
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700126#endif // ART_SRC_CONSTANTS_X86_H_