Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_CONSTANTS_X86_H_ |
| 4 | #define ART_SRC_CONSTANTS_X86_H_ |
| 5 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 6 | #include <iosfwd> |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 7 | #include "globals.h" |
| 8 | #include "logging.h" |
| 9 | #include "macros.h" |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 10 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 11 | namespace art { |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 12 | namespace x86 { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 13 | |
| 14 | enum Register { |
| 15 | EAX = 0, |
| 16 | ECX = 1, |
| 17 | EDX = 2, |
| 18 | EBX = 3, |
| 19 | ESP = 4, |
| 20 | EBP = 5, |
| 21 | ESI = 6, |
| 22 | EDI = 7, |
| 23 | kNumberOfCpuRegisters = 8, |
| 24 | kFirstByteUnsafeRegister = 4, |
| 25 | kNoRegister = -1 // Signals an illegal register. |
| 26 | }; |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 27 | std::ostream& operator<<(std::ostream& os, const Register& rhs); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 28 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 29 | enum ByteRegister { |
| 30 | AL = 0, |
| 31 | CL = 1, |
| 32 | DL = 2, |
| 33 | BL = 3, |
| 34 | AH = 4, |
| 35 | CH = 5, |
| 36 | DH = 6, |
| 37 | BH = 7, |
| 38 | kNoByteRegister = -1 // Signals an illegal register. |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | enum XmmRegister { |
| 43 | XMM0 = 0, |
| 44 | XMM1 = 1, |
| 45 | XMM2 = 2, |
| 46 | XMM3 = 3, |
| 47 | XMM4 = 4, |
| 48 | XMM5 = 5, |
| 49 | XMM6 = 6, |
| 50 | XMM7 = 7, |
| 51 | kNumberOfXmmRegisters = 8, |
| 52 | kNoXmmRegister = -1 // Signals an illegal register. |
| 53 | }; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 54 | std::ostream& operator<<(std::ostream& os, const XmmRegister& reg); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 55 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 56 | enum X87Register { |
| 57 | ST0 = 0, |
| 58 | ST1 = 1, |
| 59 | ST2 = 2, |
| 60 | ST3 = 3, |
| 61 | ST4 = 4, |
| 62 | ST5 = 5, |
| 63 | ST6 = 6, |
| 64 | ST7 = 7, |
| 65 | kNumberOfX87Registers = 8, |
| 66 | kNoX87Register = -1 // Signals an illegal register. |
| 67 | }; |
| 68 | std::ostream& operator<<(std::ostream& os, const X87Register& reg); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 69 | |
| 70 | enum ScaleFactor { |
| 71 | TIMES_1 = 0, |
| 72 | TIMES_2 = 1, |
| 73 | TIMES_4 = 2, |
| 74 | TIMES_8 = 3 |
| 75 | }; |
| 76 | |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 77 | enum Condition { |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 78 | kOverflow = 0, |
| 79 | kNoOverflow = 1, |
| 80 | kBelow = 2, |
| 81 | kAboveEqual = 3, |
| 82 | kEqual = 4, |
| 83 | kNotEqual = 5, |
| 84 | kBelowEqual = 6, |
| 85 | kAbove = 7, |
| 86 | kSign = 8, |
| 87 | kNotSign = 9, |
| 88 | kParityEven = 10, |
| 89 | kParityOdd = 11, |
| 90 | kLess = 12, |
| 91 | kGreaterEqual = 13, |
| 92 | kLessEqual = 14, |
| 93 | kGreater = 15, |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 94 | |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 95 | kZero = kEqual, |
| 96 | kNotZero = kNotEqual, |
| 97 | kNegative = kSign, |
| 98 | kPositive = kNotSign |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
| 102 | class 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 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 124 | } // namespace x86 |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 125 | } // namespace art |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 126 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 127 | #endif // ART_SRC_CONSTANTS_X86_H_ |