1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_ASSM_CONST_H_
16 : #define SYZYGY_ASSM_CONST_H_
17 :
18 : namespace assm {
19 :
20 : enum Mod {
21 : kReg1Ind = 0, // Register indirect mode.
22 : kReg1ByteDisp = 1, // Register + byte displacement.
23 : kReg1WordDisp = 2, // Register + word displacement.
24 : kReg1 = 3, // Register itself.
25 : };
26 :
27 : // The code that AL/AX/EAX/RAX registers all map to. There are special encodings
28 : // for arithmetic instructions with this register as the destination.
29 E : static const RegisterCode kAccumulatorCode = Register::Code(kRegisterEax);
30 :
31 : const uint8 kTwoByteOpCodePrefix = 0x0F;
32 : // Prefix group 2 (segment selection).
33 : const uint8 kFsSegmentPrefix = 0x64;
34 : // Prefix group 3 (operand size override).
35 : const uint8 kOperandSizePrefix = 0x66;
36 :
37 : // Some opcodes that are used repeatedly.
38 : const uint8 kNopOpCode = 0x1F;
39 :
40 : const size_t kShortBranchOpcodeSize = 1;
41 : const size_t kShortBranchSize = kShortBranchOpcodeSize + 1;
42 :
43 : const size_t kLongBranchOpcodeSize = 2;
44 : const size_t kLongBranchSize = kLongBranchOpcodeSize + 4;
45 :
46 : const size_t kShortJumpOpcodeSize = 1;
47 : const size_t kShortJumpSize = kShortJumpOpcodeSize + 1;
48 :
49 : const size_t kLongJumpOpcodeSize = 1;
50 : const size_t kLongJumpSize = kLongJumpOpcodeSize + 4;
51 :
52 : // The maximum length a single instruction will assemble to.
53 : // No instruction on x86 can exceed 15 bytes, per specs.
54 : static const size_t kMaxInstructionLength = 15;
55 :
56 : } // namespace assm
57 :
58 : #endif // SYZYGY_ASSM_CONST_H_
|