Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/ia32/IA32Template.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 | bc8527f3071c |
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.ia32; | |
24 | |
25 import com.sun.max.asm.gen.*; | |
26 import com.sun.max.asm.gen.cisc.*; | |
27 import com.sun.max.asm.gen.cisc.x86.*; | |
28 import com.sun.max.asm.ia32.*; | |
29 import com.sun.max.asm.x86.*; | |
30 import com.sun.max.lang.*; | |
31 import com.sun.max.program.*; | |
32 | |
33 /** | |
34 */ | |
35 public class IA32Template extends X86Template { | |
36 | |
37 public IA32Template(X86InstructionDescription instructionDescription, int serial, InstructionAssessment instructionFamily, X86TemplateContext context) { | |
38 super(instructionDescription, serial, instructionFamily, context); | |
39 } | |
40 | |
41 private void addSib(X86Operand.Designation designation) throws TemplateNotNeededException { | |
42 assert context().addressSizeAttribute() != WordWidth.BITS_16; | |
43 haveSibByte(); | |
44 switch (context().sibBaseCase()) { | |
45 case GENERAL_REGISTER: { | |
46 switch (context().modCase()) { | |
47 case MOD_0: { | |
48 addEnumerableParameter(designation, ParameterPlace.SIB_BASE, IA32BaseRegister32.ENUMERATOR); | |
49 break; | |
50 } | |
51 case MOD_1: | |
52 case MOD_2: { | |
53 addEnumerableParameter(designation, ParameterPlace.SIB_BASE, IA32BaseRegister32.ENUMERATOR); | |
54 break; | |
55 } | |
56 case MOD_3: { | |
57 throw ProgramError.unexpected("no SIB for mod == 3"); | |
58 } | |
59 } | |
60 break; | |
61 } | |
62 case SPECIAL: { | |
63 switch (context().modCase()) { | |
64 case MOD_0: { | |
65 setLabelParameterIndex(); | |
66 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
67 break; | |
68 } | |
69 default: { | |
70 throw ProgramError.unexpected("no special SIB base for mod != 0"); | |
71 } | |
72 } | |
73 break; | |
74 } | |
75 } | |
76 switch (context().sibIndexCase()) { | |
77 case GENERAL_REGISTER: | |
78 addEnumerableParameter(designation, ParameterPlace.SIB_INDEX, IA32IndexRegister32.ENUMERATOR); | |
79 break; | |
80 case NONE: | |
81 // Our external assembler (gas) cannot generate these case and they seem redundant anyway, | |
82 // so for now we do not produce them: | |
83 TemplateNotNeededException.raise(); | |
84 } | |
85 addParameter(new X86EnumerableParameter<Scale>(designation, ParameterPlace.SIB_SCALE, Scale.ENUMERATOR)); | |
86 } | |
87 | |
88 @Override | |
89 protected void organize_M(X86Operand.Designation designation) throws TemplateNotNeededException { | |
90 switch (context().modCase()) { | |
91 case MOD_0: { | |
92 switch (context().rmCase()) { | |
93 case NORMAL: | |
94 switch (context().addressSizeAttribute()) { | |
95 case BITS_16: | |
96 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister16.ENUMERATOR); | |
97 break; | |
98 case BITS_32: | |
99 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister32.ENUMERATOR); | |
100 break; | |
101 default: | |
102 throw ProgramError.unexpected(); | |
103 } | |
104 break; | |
105 case SWORD: | |
106 switch (context().addressSizeAttribute()) { | |
107 case BITS_16: | |
108 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
109 addParameter(new X86AddressParameter(designation, WordWidth.BITS_16)); | |
110 break; | |
111 default: | |
112 TemplateNotNeededException.raise(); | |
113 } | |
114 break; | |
115 case SDWORD: | |
116 switch (context().addressSizeAttribute()) { | |
117 case BITS_32: | |
118 setLabelParameterIndex(); | |
119 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
120 break; | |
121 default: | |
122 TemplateNotNeededException.raise(); | |
123 } | |
124 break; | |
125 case SIB: | |
126 switch (context().addressSizeAttribute()) { | |
127 case BITS_32: | |
128 addSib(designation); | |
129 break; | |
130 default: | |
131 TemplateNotNeededException.raise(); | |
132 } | |
133 break; | |
134 } | |
135 break; | |
136 } | |
137 case MOD_1: { | |
138 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_8)); | |
139 switch (context().rmCase()) { | |
140 case NORMAL: | |
141 switch (context().addressSizeAttribute()) { | |
142 case BITS_16: | |
143 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister16.ENUMERATOR); | |
144 break; | |
145 case BITS_32: | |
146 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister32.ENUMERATOR); | |
147 break; | |
148 default: | |
149 throw ProgramError.unexpected(); | |
150 } | |
151 break; | |
152 case SIB: | |
153 switch (context().addressSizeAttribute()) { | |
154 case BITS_32: | |
155 addSib(designation); | |
156 break; | |
157 default: | |
158 TemplateNotNeededException.raise(); | |
159 } | |
160 break; | |
161 default: | |
162 TemplateNotNeededException.raise(); | |
163 } | |
164 break; | |
165 } | |
166 case MOD_2: { | |
167 switch (context().addressSizeAttribute()) { | |
168 case BITS_16: | |
169 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_16)); | |
170 break; | |
171 case BITS_32: | |
172 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_32)); | |
173 break; | |
174 default: | |
175 throw ProgramError.unexpected(); | |
176 } | |
177 switch (context().rmCase()) { | |
178 case NORMAL: | |
179 switch (context().addressSizeAttribute()) { | |
180 case BITS_16: | |
181 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister16.ENUMERATOR); | |
182 break; | |
183 case BITS_32: | |
184 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32IndirectRegister32.ENUMERATOR); | |
185 break; | |
186 default: | |
187 throw ProgramError.unexpected(); | |
188 } | |
189 break; | |
190 case SIB: | |
191 switch (context().addressSizeAttribute()) { | |
192 case BITS_16: | |
193 throw TemplateNotNeededException.raise(); | |
194 case BITS_32: | |
195 addSib(designation); | |
196 break; | |
197 default: | |
198 throw ProgramError.unexpected(); | |
199 } | |
200 break; | |
201 default: | |
202 TemplateNotNeededException.raise(); | |
203 } | |
204 break; | |
205 } | |
206 case MOD_3: { | |
207 TemplateNotNeededException.raise(); | |
208 } | |
209 } | |
210 } | |
211 | |
212 public void visitOperandCode(OperandCode operandCode, X86Operand.Designation designation, ArgumentRange argumentRange, TestArgumentExclusion testArgumentExclusion) | |
213 throws TemplateNotNeededException { | |
214 switch (operandCode) { | |
215 case Ap: | |
216 instructionDescription().beNotExternallyTestable(); // gas does not support cross-segment instructions | |
217 switch (context().addressSizeAttribute()) { | |
218 case BITS_16: | |
219 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
220 addParameter(new X86AddressParameter(designation, WordWidth.BITS_16)); | |
221 break; | |
222 case BITS_32: | |
223 setLabelParameterIndex(); | |
224 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
225 break; | |
226 default: | |
227 throw ProgramError.unexpected(); | |
228 } | |
229 break; | |
230 case Cd: { | |
231 addParameter(new X86EnumerableParameter<ControlRegister>(designation, ParameterPlace.MOD_REG, ControlRegister.ENUMERATOR)); | |
232 break; | |
233 } | |
234 case Dd: { | |
235 addParameter(new X86EnumerableParameter<DebugRegister>(designation, ParameterPlace.MOD_REG, DebugRegister.ENUMERATOR)); | |
236 break; | |
237 } | |
238 case Eb: { | |
239 organize_E(designation, ParameterPlace.MOD_RM, IA32GeneralRegister8.ENUMERATOR, testArgumentExclusion); | |
240 break; | |
241 } | |
242 case Ed: { | |
243 organize_E(designation, ParameterPlace.MOD_RM, IA32GeneralRegister32.ENUMERATOR, testArgumentExclusion); | |
244 break; | |
245 } | |
246 case Ev: { | |
247 switch (context().operandSizeAttribute()) { | |
248 case BITS_16: | |
249 organize_E(designation, ParameterPlace.MOD_RM, IA32GeneralRegister16.ENUMERATOR, testArgumentExclusion); | |
250 break; | |
251 case BITS_32: | |
252 organize_E(designation, ParameterPlace.MOD_RM, IA32GeneralRegister32.ENUMERATOR, testArgumentExclusion); | |
253 break; | |
254 default: | |
255 throw ProgramError.unexpected(); | |
256 } | |
257 break; | |
258 } | |
259 case Ew: { | |
260 organize_E(designation, ParameterPlace.MOD_RM, IA32GeneralRegister16.ENUMERATOR, testArgumentExclusion); | |
261 break; | |
262 } | |
263 case Fv: { | |
264 break; | |
265 } | |
266 case Gb: { | |
267 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32GeneralRegister8.ENUMERATOR).excludeTestArguments( | |
268 testArgumentExclusion); | |
269 break; | |
270 } | |
271 case Gd: { | |
272 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
273 break; | |
274 } | |
275 case Gv: { | |
276 switch (context().operandSizeAttribute()) { | |
277 case BITS_16: | |
278 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32GeneralRegister16.ENUMERATOR).excludeTestArguments( | |
279 testArgumentExclusion); | |
280 break; | |
281 case BITS_32: | |
282 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments( | |
283 testArgumentExclusion); | |
284 break; | |
285 default: | |
286 throw ProgramError.unexpected(); | |
287 } | |
288 break; | |
289 } | |
290 case Gw: { | |
291 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32GeneralRegister16.ENUMERATOR).excludeTestArguments( | |
292 testArgumentExclusion); | |
293 break; | |
294 } | |
295 case Ib: { | |
296 final X86ImmediateParameter parameter = new X86ImmediateParameter(designation, WordWidth.BITS_8); | |
297 addParameter(parameter); | |
298 parameter.setArgumentRange(argumentRange); | |
299 parameter.excludeTestArguments(testArgumentExclusion); | |
300 break; | |
301 } | |
302 case ICb: { | |
303 addEnumerableParameter(designation, ParameterPlace.APPEND, IA32XMMComparison.ENUMERATOR); | |
304 break; | |
305 } | |
306 case Iv: { | |
307 setExternalOperandTypeSuffix(operandCode.operandTypeCode()); | |
308 final X86ImmediateParameter parameter = new X86ImmediateParameter(designation, context().operandSizeAttribute()); | |
309 addParameter(parameter); | |
310 parameter.setArgumentRange(argumentRange); | |
311 parameter.excludeTestArguments(testArgumentExclusion); | |
312 break; | |
313 } | |
314 case Iw: { | |
315 setExternalCodeSizeAttribute(context().operandSizeAttribute()); | |
316 final X86ImmediateParameter parameter = new X86ImmediateParameter(designation, WordWidth.BITS_16); | |
317 addParameter(parameter); | |
318 parameter.setArgumentRange(argumentRange); | |
319 parameter.excludeTestArguments(testArgumentExclusion); | |
320 break; | |
321 } | |
322 case Jb: { | |
323 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
324 setLabelParameterIndex(); | |
325 final X86OffsetParameter parameter = new X86OffsetParameter(designation, WordWidth.BITS_8); | |
326 addParameter(parameter); | |
327 parameter.setArgumentRange(argumentRange); | |
328 parameter.excludeTestArguments(testArgumentExclusion); | |
329 break; | |
330 } | |
331 case Jv: { | |
332 switch (context().operandSizeAttribute()) { | |
333 case BITS_16: | |
334 setExternalCodeSizeAttribute(context().operandSizeAttribute()); | |
335 setLabelParameterIndex(); | |
336 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_16)); | |
337 break; | |
338 case BITS_32: | |
339 setLabelParameterIndex(); | |
340 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_32)); | |
341 break; | |
342 default: | |
343 throw ProgramError.unexpected(); | |
344 } | |
345 break; | |
346 } | |
347 case Md_q: { | |
348 if (operandSizeAttribute() == WordWidth.BITS_16) { | |
349 TemplateNotNeededException.raise(); | |
350 } | |
351 organize_M(designation); | |
352 break; | |
353 } | |
354 case Mdq: | |
355 case Ma: | |
356 case Mp: | |
357 case Mq: | |
358 case Ms: | |
359 case Mv: | |
360 case Mw: { | |
361 organize_M(designation); | |
362 break; | |
363 } | |
364 case Nb: { | |
365 addEnumerableParameter(designation, ParameterPlace.OPCODE1, IA32GeneralRegister8.ENUMERATOR).excludeTestArguments( | |
366 testArgumentExclusion); | |
367 break; | |
368 } | |
369 case Nd: | |
370 addEnumerableParameter(designation, ParameterPlace.OPCODE2, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments( | |
371 testArgumentExclusion); | |
372 break; | |
373 case Nv: | |
374 final ParameterPlace place = (opcode2() != null) ? ParameterPlace.OPCODE2 : ParameterPlace.OPCODE1; | |
375 switch (context().operandSizeAttribute()) { | |
376 case BITS_16: | |
377 addEnumerableParameter(designation, place, IA32GeneralRegister16.ENUMERATOR).excludeTestArguments( | |
378 testArgumentExclusion); | |
379 break; | |
380 case BITS_32: | |
381 addEnumerableParameter(designation, place, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments( | |
382 testArgumentExclusion); | |
383 break; | |
384 default: | |
385 throw ProgramError.unexpected(); | |
386 } | |
387 break; | |
388 case Ob: | |
389 case Ov: { | |
390 switch (context().addressSizeAttribute()) { | |
391 case BITS_16: | |
392 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
393 addParameter(new X86AddressParameter(designation, WordWidth.BITS_16)); | |
394 break; | |
395 case BITS_32: | |
396 setLabelParameterIndex(); | |
397 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
398 break; | |
399 default: | |
400 throw ProgramError.unexpected(); | |
401 } | |
402 break; | |
403 } | |
404 case Pd: | |
405 case Pq: { | |
406 addEnumerableParameter(designation, ParameterPlace.MOD_REG, MMXRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
407 break; | |
408 } | |
409 case PRq: { | |
410 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
411 TemplateNotNeededException.raise(); | |
412 } | |
413 addEnumerableParameter(designation, ParameterPlace.MOD_RM, MMXRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
414 break; | |
415 } | |
416 case Qd: | |
417 case Qq: { | |
418 organize_E(designation, ParameterPlace.MOD_RM, MMXRegister.ENUMERATOR, testArgumentExclusion); | |
419 break; | |
420 } | |
421 case Rd: { | |
422 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
423 TemplateNotNeededException.raise(); | |
424 } | |
425 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments( | |
426 testArgumentExclusion); | |
427 break; | |
428 } | |
429 case Rv: | |
430 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
431 TemplateNotNeededException.raise(); | |
432 } | |
433 switch (context().operandSizeAttribute()) { | |
434 case BITS_16: | |
435 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32GeneralRegister16.ENUMERATOR).excludeTestArguments( | |
436 testArgumentExclusion); | |
437 break; | |
438 case BITS_32: | |
439 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32GeneralRegister32.ENUMERATOR).excludeTestArguments( | |
440 testArgumentExclusion); | |
441 break; | |
442 default: | |
443 throw ProgramError.unexpected(); | |
444 } | |
445 break; | |
446 case Sw: { | |
447 addEnumerableParameter(designation, ParameterPlace.MOD_REG, SegmentRegister.ENUMERATOR).excludeTestArguments( | |
448 testArgumentExclusion); | |
449 break; | |
450 } | |
451 case Vpd: | |
452 case Vps: | |
453 case Vq: | |
454 case Vdq: | |
455 case Vsd: | |
456 case Vss: { | |
457 addEnumerableParameter(designation, ParameterPlace.MOD_REG, IA32XMMRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
458 break; | |
459 } | |
460 case VRq: | |
461 case VRdq: | |
462 case VRpd: | |
463 case VRps: { | |
464 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
465 TemplateNotNeededException.raise(); | |
466 } | |
467 addEnumerableParameter(designation, ParameterPlace.MOD_RM, IA32XMMRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
468 break; | |
469 } | |
470 case Wdq: | |
471 case Wpd: | |
472 case Wps: | |
473 case Wq: | |
474 case Wsd: | |
475 case Wss: { | |
476 switch (context().operandSizeAttribute()) { | |
477 case BITS_32: | |
478 case BITS_64: | |
479 organize_E(designation, ParameterPlace.MOD_RM, IA32XMMRegister.ENUMERATOR, testArgumentExclusion); | |
480 break; | |
481 default: | |
482 TemplateNotNeededException.raise(); | |
483 } | |
484 break; | |
485 } | |
486 case Xb: | |
487 case Xv: | |
488 case Yb: | |
489 case Yv: { | |
490 visitOperandTypeCode(operandCode.operandTypeCode()); | |
491 break; | |
492 } | |
493 default: | |
494 throw ProgramError.unexpected("undefined operand code: " + operandCode); | |
495 } | |
496 } | |
497 | |
498 public void visitRegisterOperandCode(RegisterOperandCode registerOperandCode, X86Operand.Designation designation, ImplicitOperand.ExternalPresence externalPresence) { | |
499 switch (operandSizeAttribute()) { | |
500 case BITS_16: | |
501 addImplicitOperand(new X86ImplicitOperand(designation, externalPresence, IA32GeneralRegister16.ENUMERATOR.get(registerOperandCode.id()))); | |
502 break; | |
503 case BITS_32: | |
504 addImplicitOperand(new X86ImplicitOperand(designation, externalPresence, IA32GeneralRegister32.ENUMERATOR.get(registerOperandCode.id()))); | |
505 break; | |
506 default: | |
507 throw ProgramError.unexpected(); | |
508 } | |
509 } | |
510 } |