comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/x86/X86TemplateContext.java @ 3733:e233f5660da4

Added Java files from Maxine project.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 19:59:18 +0100
parents
children
comparison
equal deleted inserted replaced
3732:3e2e8b8abdaf 3733:e233f5660da4
1 /*
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.max.asm.gen.cisc.x86;
24
25 import java.util.*;
26 import java.util.Arrays;
27
28 import com.sun.max.lang.*;
29 import com.sun.max.program.*;
30
31 /**
32 * A bundle of choices one can make when creating a template (addressing modes and operand sizes).
33 */
34 public class X86TemplateContext implements Cloneable {
35
36 /**
37 * ModRM mod Field. See mod field in "A.3.1 ModRM Operand References"
38 */
39 public enum ModCase {
40 MOD_0,
41 MOD_1,
42 MOD_2,
43 MOD_3;
44
45 public static final List<ModCase> VALUES = Arrays.asList(values());
46
47 public int value() {
48 return ordinal();
49 }
50 }
51
52 /**
53 * Addressing mode variants. See r/m field in "A.3.1 ModRM Operand References"
54 */
55 public enum RMCase {
56 NORMAL(0), // all other addressing modes, e.g. registers
57 SIB(4), // Scale-Index-Base addressing mode, e.g. [SIB]; see "Table A-15. ModRM Memory References, 32-Bit and 64-Bit Addressing"
58 SWORD(6), // indirect signed 16-bit displacement, e.g. [disp16]; see "Table A-13. ModRM Memory References, 16-Bit Addressing"
59 SDWORD(5); // indirect signed 32-bit displacement, e.g. [disp32] or [rIP+disp32]; see "Table A-15. ModRM Memory References, 32-Bit and 64-Bit Addressing"
60
61 public static final List<RMCase> VALUES = Arrays.asList(values());
62
63 private final int rmFieldValue;
64
65 private RMCase(int rmFieldValue) {
66 this.rmFieldValue = rmFieldValue;
67 }
68
69 public int value() {
70 return rmFieldValue;
71 }
72 }
73
74 /**
75 * Classes of "index" fields for SIB. See "Table A-17. SIB Memory References".
76 */
77 public enum SibIndexCase {
78 GENERAL_REGISTER, // index register specified
79 NONE; // SIB index = 100b and REX.X = 0 - no index register specified
80
81 public static final List<SibIndexCase> VALUES = Arrays.asList(values());
82 }
83
84 /**
85 * Classes of "base" fields for SIB. See "Table A-16. SIB base Field References".
86 */
87 public enum SibBaseCase {
88 GENERAL_REGISTER, // general purpose register base
89 SPECIAL; // /5 - immediate displacement base / rBP / r13)
90
91 public static final List<SibBaseCase> VALUES = Arrays.asList(values());
92 }
93
94 public X86TemplateContext() {
95 }
96
97 private WordWidth addressSizeAttribute;
98
99 public WordWidth addressSizeAttribute() {
100 return addressSizeAttribute;
101 }
102
103 public void setAddressSizeAttribute(WordWidth addressSizeAttribute) {
104 this.addressSizeAttribute = addressSizeAttribute;
105 }
106
107 private WordWidth operandSizeAttribute;
108
109 public WordWidth operandSizeAttribute() {
110 return operandSizeAttribute;
111 }
112
113 public void setOperandSizeAttribute(WordWidth operandSizeAttribute) {
114 this.operandSizeAttribute = operandSizeAttribute;
115 }
116
117 private ModRMGroup.Opcode modRMGroupOpcode;
118
119 public ModRMGroup.Opcode modRMGroupOpcode() {
120 return modRMGroupOpcode;
121 }
122
123 public void setModRMGroupOpcode(ModRMGroup.Opcode modRMGroupOpcode) {
124 this.modRMGroupOpcode = modRMGroupOpcode;
125 }
126
127 private ModCase modCase;
128
129 public ModCase modCase() {
130 return modCase;
131 }
132
133 public void setModCase(ModCase modCase) {
134 this.modCase = modCase;
135 }
136
137 private RMCase rmCase;
138
139 public RMCase rmCase() {
140 return rmCase;
141 }
142
143 public void setRMCase(RMCase value) {
144 this.rmCase = value;
145 }
146
147 private SibIndexCase sibIndexCase;
148
149 public SibIndexCase sibIndexCase() {
150 return sibIndexCase;
151 }
152
153 public void setSibIndexCase(SibIndexCase sibIndexCase) {
154 this.sibIndexCase = sibIndexCase;
155 }
156
157 protected SibBaseCase sibBaseCase;
158
159 public SibBaseCase sibBaseCase() {
160 return sibBaseCase;
161 }
162
163 public void setSibBaseCase(SibBaseCase sibBaseCase) {
164 this.sibBaseCase = sibBaseCase;
165 }
166
167 @Override
168 public X86TemplateContext clone() {
169 try {
170 return (X86TemplateContext) super.clone();
171 } catch (CloneNotSupportedException cloneNotSupportedException) {
172 throw ProgramError.unexpected("clone() failed", cloneNotSupportedException);
173 }
174 }
175
176 @Override
177 public String toString() {
178 return "<Context: " + addressSizeAttribute + ", " + operandSizeAttribute + ", " + modRMGroupOpcode + ", " + modCase + ", " + rmCase + ", " + sibIndexCase + ", " + sibBaseCase + ">";
179 }
180 }