1 /*
   2  * Copyright 2000-2007 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.debugger.sparc;
  26 
  27 import sun.jvm.hotspot.debugger.*;
  28 
  29 /** Currently provides just the minimal information necessary to get
  30     stack traces working. FIXME: currently hardwired for v9 -- will
  31     have to factor out v8/v9 specific code. FIXME: may want to try to
  32     share code between this class and asm/sparc. */
  33 
  34 public abstract class SPARCThreadContext implements ThreadContext {
  35   // Taken from /usr/include/sys/procfs_isa.h
  36   public static final int R_G0 = 0;
  37   public static final int R_G1 = 1;
  38   public static final int R_G2 = 2;
  39   public static final int R_G3 = 3;
  40   public static final int R_G4 = 4;
  41   public static final int R_G5 = 5;
  42   public static final int R_G6 = 6;
  43   public static final int R_G7 = 7;
  44   public static final int R_O0 = 8;
  45   public static final int R_O1 = 9;
  46   public static final int R_O2 = 10;
  47   public static final int R_O3 = 11;
  48   public static final int R_O4 = 12;
  49   public static final int R_O5 = 13;
  50   public static final int R_O6 = 14;
  51   public static final int R_O7 = 15;
  52   public static final int R_L0 = 16;
  53   public static final int R_L1 = 17;
  54   public static final int R_L2 = 18;
  55   public static final int R_L3 = 19;
  56   public static final int R_L4 = 20;
  57   public static final int R_L5 = 21;
  58   public static final int R_L6 = 22;
  59   public static final int R_L7 = 23;
  60   public static final int R_I0 = 24;
  61   public static final int R_I1 = 25;
  62   public static final int R_I2 = 26;
  63   public static final int R_I3 = 27;
  64   public static final int R_I4 = 28;
  65   public static final int R_I5 = 29;
  66   public static final int R_I6 = 30;
  67   public static final int R_I7 = 31;
  68 
  69   // sparc-v9
  70   public static final int R_CCR = 32;
  71   // sparc-v8
  72   public static final int R_PSR = 32;
  73 
  74   public static final int R_PC = 33;
  75   public static final int R_nPC = 34;
  76 
  77   public static final int R_SP = R_O6;
  78   public static final int R_FP = R_I6;
  79 
  80   public static final int R_Y  = 35;
  81 
  82   // sparc-v9
  83   public static final int R_ASI = 36;
  84   public static final int R_FPRS = 37;
  85 
  86   // sparc-v8
  87   public static final int R_WIM = 36;
  88   public static final int R_TBR = 37;
  89 
  90   public static final int NPRGREG = 38;
  91 
  92   private static final String[] regNames = {
  93     "G0",    "G1",    "G2",    "G3",
  94     "G4",    "G5",    "G6",    "G7",
  95     "O0",    "O1",    "O2",    "O3",
  96     "O4",    "O5",    "O6/SP", "O7",
  97     "L0",    "L1",    "L2",    "L3",
  98     "L4",    "L5",    "L6",    "L7",
  99     "I0",    "I1",    "I2",    "I3",
 100     "I4",    "I5",    "I6/FP", "I7",
 101     "CCR/PSR", "PC",  "nPC",   "Y",
 102     "ASI/WIM", "FPRS/TBR"
 103   };
 104 
 105   private long[] data;
 106 
 107   public SPARCThreadContext() {
 108     data = new long[NPRGREG];
 109   }
 110 
 111   public int getNumRegisters() {
 112     return NPRGREG;
 113   }
 114 
 115   public String getRegisterName(int index) {
 116     return regNames[index];
 117   }
 118 
 119   public void setRegister(int index, long value) {
 120     data[index] = value;
 121   }
 122 
 123   public long getRegister(int index) {
 124     return data[index];
 125   }
 126 
 127   /** This can't be implemented in this class since we would have to
 128       tie the implementation to, for example, the debugging system */
 129   public abstract void setRegisterAsAddress(int index, Address value);
 130 
 131   /** This can't be implemented in this class since we would have to
 132       tie the implementation to, for example, the debugging system */
 133   public abstract Address getRegisterAsAddress(int index);
 134 }