1 /*
   2  * Copyright 2002-2003 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.asm.x86;
  26 
  27 import sun.jvm.hotspot.asm.*;
  28 
  29 public class FloatGRPDecoder extends FPInstructionDecoder {
  30 
  31    final private int number;
  32 
  33    //Please refer to IA-32 Intel Architecture Software Developer's Manual Volume 2
  34    //APPENDIX A - Escape opcodes
  35 
  36    private static final FPInstructionDecoder floatGRPMap[][] = {
  37       /* d9_2 */
  38       {
  39       new FPInstructionDecoder("fnop"),
  40       null,
  41       null,
  42       null,
  43       null,
  44       null,
  45       null,
  46       null
  47       },
  48       /*  d9_4 */
  49       {
  50       new FPInstructionDecoder("fchs"),
  51       new FPInstructionDecoder("fabs"),
  52       null,
  53       null,
  54       new FPInstructionDecoder("ftst"),
  55       new FPInstructionDecoder("fxam"),
  56       null,
  57       null
  58       },
  59       /* d9_5 */
  60       {
  61       new FPInstructionDecoder("fld1"),
  62       new FPInstructionDecoder("fldl2t"),
  63       new FPInstructionDecoder("fldl2e"),
  64       new FPInstructionDecoder("fldpi"),
  65       new FPInstructionDecoder("fldlg2"),
  66       new FPInstructionDecoder("fldln2"),
  67       new FPInstructionDecoder("fldz"),
  68       null
  69       },
  70       /* d9_6 */
  71       {
  72       new FPInstructionDecoder("f2xm1"),
  73       new FPInstructionDecoder("fyl2x"),
  74       new FPInstructionDecoder("fptan"),
  75       new FPInstructionDecoder("fpatan"),
  76       new FPInstructionDecoder("fxtract"),
  77       new FPInstructionDecoder("fprem1"),
  78       new FPInstructionDecoder("fdecstp"),
  79       new FPInstructionDecoder("fincstp")
  80       },
  81       /* d9_7 */
  82       {
  83       new FPInstructionDecoder("fprem"),
  84       new FPInstructionDecoder("fyl2xp1"),
  85       new FPInstructionDecoder("fsqrt"),
  86       new FPInstructionDecoder("fsincos"),
  87       new FPInstructionDecoder("frndint"),
  88       new FPInstructionDecoder("fscale"),
  89       new FPInstructionDecoder("fsin"),
  90       new FPInstructionDecoder("fcos")
  91       },
  92       /* da_5 */
  93       {
  94       null,
  95       new FPInstructionDecoder("fucompp"),
  96       null,
  97       null,
  98       null,
  99       null,
 100       null,
 101       null
 102       },
 103       /* db_4 */
 104       {
 105       new FPInstructionDecoder("feni(287 only)"),
 106       new FPInstructionDecoder("fdisi(287 only)"),
 107       new FPInstructionDecoder("fNclex"),
 108       new FPInstructionDecoder("fNinit"),
 109       new FPInstructionDecoder("fNsetpm(287 only)"),
 110       null,
 111       null,
 112       null
 113       },
 114       /* de_3 */
 115       {
 116       null,
 117       new FPInstructionDecoder("fcompp"),
 118       null,
 119       null,
 120       null,
 121       null,
 122       null,
 123       null
 124       },
 125       /* df_4 */
 126       {
 127       new FPInstructionDecoder("fNstsw"),
 128       null,
 129       null,
 130       null,
 131       null,
 132       null,
 133       null,
 134       null
 135       }
 136    };
 137 
 138    public FloatGRPDecoder(String name, int number) {
 139       super(name);
 140       this.number = number;
 141    }
 142 
 143    public Instruction decode(byte[] bytesArray, int index, int instrStartIndex, int segmentOverride, int prefixes, X86InstructionFactory factory) {
 144       this.byteIndex = index;
 145       this.instrStartIndex = instrStartIndex;
 146       this.prefixes = prefixes;
 147 
 148       int ModRM = readByte(bytesArray, byteIndex);
 149       int rm = ModRM & 7;
 150 
 151       FPInstructionDecoder instrDecoder = null;
 152       instrDecoder = floatGRPMap[number][rm];
 153 
 154       Instruction instr = null;
 155       if(instrDecoder != null) {
 156          instr = instrDecoder.decode(bytesArray, byteIndex, instrStartIndex, segmentOverride, prefixes, factory);
 157          byteIndex = instrDecoder.getCurrentIndex();
 158       } else {
 159          instr = factory.newIllegalInstruction();
 160       }
 161       return instr;
 162    }
 163 }