1 /*
   2  * Copyright (c) 2001, 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,
  20  * CA 94065 USA or visit www.oracle.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.utilities.*;
  28 
  29 public class X86Registers {
  30   public static final int NUM_REGISTERS = 8;
  31 
  32    public static final X86Register EAX;
  33    public static final X86Register ECX;
  34    public static final X86Register EDX;
  35    public static final X86Register EBX;
  36    public static final X86Register ESP;
  37    public static final X86Register EBP;
  38    public static final X86Register ESI;
  39    public static final X86Register EDI;
  40 
  41    public static final X86Register AX;
  42    public static final X86Register CX;
  43    public static final X86Register DX;
  44    public static final X86Register BX;
  45    public static final X86Register SP;
  46    public static final X86Register BP;
  47    public static final X86Register SI;
  48    public static final X86Register DI;
  49 
  50    public static final X86Register AL;
  51    public static final X86Register CL;
  52    public static final X86Register DL;
  53    public static final X86Register BL;
  54    public static final X86Register AH;
  55    public static final X86Register CH;
  56    public static final X86Register DH;
  57    public static final X86Register BH;
  58 
  59    private static X86Register registers8[];
  60    private static X86Register registers16[];
  61    private static X86Register registers32[];
  62 
  63    static {
  64       EAX = new X86RegisterPart(0, "%eax", 0, 32);
  65       ECX = new X86RegisterPart(1, "%ecx", 0, 32);
  66       EDX = new X86RegisterPart(2, "%edx", 0, 32);
  67       EBX = new X86RegisterPart(3, "%ebx", 0, 32);
  68       ESP = new X86RegisterPart(4, "%esp", 0, 32);
  69       EBP = new X86RegisterPart(5, "%ebp", 0, 32);
  70       ESI = new X86RegisterPart(6, "%esi", 0, 32);
  71       EDI = new X86RegisterPart(7, "%edi", 0, 32);
  72 
  73       AX = new X86RegisterPart(0, "%ax", 0, 16);
  74       CX = new X86RegisterPart(1, "%cx", 0, 16);
  75       DX = new X86RegisterPart(2, "%dx", 0, 16);
  76       BX = new X86RegisterPart(3, "%bx", 0, 16);
  77       SP = new X86RegisterPart(4, "%sp", 0, 16);
  78       BP = new X86RegisterPart(5, "%bp", 0, 16);
  79       SI = new X86RegisterPart(6, "%si", 0, 16);
  80       DI = new X86RegisterPart(7, "%di", 0, 16);
  81 
  82       AL = new X86RegisterPart(0, "%al", 0, 8);
  83       CL = new X86RegisterPart(1, "%cl", 0, 8);
  84       DL = new X86RegisterPart(2, "%dl", 0, 8);
  85       BL = new X86RegisterPart(3, "%bl", 0, 8);
  86       AH = new X86RegisterPart(0, "%ah", 8, 8);
  87       CH = new X86RegisterPart(1, "%ch", 8, 8);
  88       DH = new X86RegisterPart(2, "%dh", 8, 8);
  89       BH = new X86RegisterPart(3, "%bh", 8, 8);
  90 
  91       registers32 = (new X86Register[] {
  92             EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
  93       });
  94       registers16 = (new X86Register[] {
  95             AX, CX, DX, BX, SP, BP, SI, DI
  96       });
  97       registers8 = (new X86Register[] {
  98             AL, CL, DL, BL, AH, CH, DH, BH
  99       });
 100    }
 101 
 102    public static int getNumberOfRegisters() {
 103       return NUM_REGISTERS;
 104    }
 105 
 106    public static X86Register getRegister8(int regNum) {
 107       if (Assert.ASSERTS_ENABLED) {
 108          Assert.that(regNum > -1 && regNum < NUM_REGISTERS, "invalid integer register number!");
 109       }
 110       return registers8[regNum];
 111    }
 112 
 113    public static X86Register getRegister16(int regNum) {
 114       if (Assert.ASSERTS_ENABLED) {
 115          Assert.that(regNum > -1 && regNum < NUM_REGISTERS, "invalid integer register number!");
 116       }
 117       return registers16[regNum];
 118    }
 119 
 120    public static X86Register getRegister32(int regNum) {
 121       if (Assert.ASSERTS_ENABLED) {
 122          Assert.that(regNum > -1 && regNum < NUM_REGISTERS, "invalid integer register number!");
 123       }
 124       return registers32[regNum];
 125    }
 126 
 127    //Return the 32bit register name
 128    public static String getRegisterName(int regNum) {
 129       if (Assert.ASSERTS_ENABLED) {
 130          Assert.that(regNum > -1 && regNum < NUM_REGISTERS, "invalid integer register number!");
 131       }
 132       return registers32[regNum].toString();
 133    }
 134 }