AARCH64ThreadContext.java revision 9883:903a2e023ffb
1/*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, Red Hat Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26package sun.jvm.hotspot.debugger.aarch64;
27
28import java.lang.annotation.Native;
29
30import sun.jvm.hotspot.debugger.*;
31import sun.jvm.hotspot.debugger.cdbg.*;
32
33/** Specifies the thread context on aarch64 platforms; only a sub-portion
34 * of the context is guaranteed to be present on all operating
35 * systems. */
36
37public abstract class AARCH64ThreadContext implements ThreadContext {
38    // Taken from /usr/include/asm/sigcontext.h on Linux/AARCH64.
39
40    //  /*
41    //   * Signal context structure - contains all info to do with the state
42    //   * before the signal handler was invoked.
43    //   */
44    // struct sigcontext {
45    //         __u64 fault_address;
46    //         /* AArch64 registers */
47    //          __u64 regs[31];
48    //          __u64 sp;
49    //          __u64 pc;
50    //          __u64 pstate;
51    //          /* 4K reserved for FP/SIMD state and future expansion */
52    //          __u8 __reserved[4096] __attribute__((__aligned__(16)));
53    //  };
54
55    // NOTE: the indices for the various registers must be maintained as
56    // listed across various operating systems. However, only a small
57    // subset of the registers' values are guaranteed to be present (and
58    // must be present for the SA's stack walking to work)
59
60    // One instance of the Native annotation is enough to trigger header generation
61    // for this file.
62    @Native
63    public static final int R0 = 0;
64    public static final int R1 = 1;
65    public static final int R2 = 2;
66    public static final int R3 = 3;
67    public static final int R4 = 4;
68    public static final int R5 = 5;
69    public static final int R6 = 6;
70    public static final int R7 = 7;
71    public static final int R8 = 8;
72    public static final int R9 = 9;
73    public static final int R10 = 10;
74    public static final int R11 = 11;
75    public static final int R12 = 12;
76    public static final int R13 = 13;
77    public static final int R14 = 14;
78    public static final int R15 = 15;
79    public static final int R16 = 16;
80    public static final int R17 = 17;
81    public static final int R18 = 18;
82    public static final int R19 = 19;
83    public static final int R20 = 20;
84    public static final int R21 = 21;
85    public static final int R22 = 22;
86    public static final int R23 = 23;
87    public static final int R24 = 24;
88    public static final int R25 = 25;
89    public static final int R26 = 26;
90    public static final int R27 = 27;
91    public static final int R28 = 28;
92    public static final int FP = 29;
93    public static final int LR = 30;
94    public static final int SP = 31;
95    public static final int PC = 32;
96    public static final int PSTATE = 33;
97
98    public static final int NPRGREG = 34;
99
100    private long[] data;
101
102    public AARCH64ThreadContext() {
103        data = new long[NPRGREG];
104    }
105
106    public int getNumRegisters() {
107        return NPRGREG;
108    }
109
110    public String getRegisterName(int index) {
111        switch (index) {
112        case LR: return "lr";
113        case SP: return "sp";
114        case PC: return "pc";
115        default:
116            return "r" + index;
117        }
118    }
119
120    public void setRegister(int index, long value) {
121        data[index] = value;
122    }
123
124    public long getRegister(int index) {
125        return data[index];
126    }
127
128    public CFrame getTopFrame(Debugger dbg) {
129        return null;
130    }
131
132    /** This can't be implemented in this class since we would have to
133     * tie the implementation to, for example, the debugging system */
134    public abstract void setRegisterAsAddress(int index, Address value);
135
136    /** This can't be implemented in this class since we would have to
137     * tie the implementation to, for example, the debugging system */
138    public abstract Address getRegisterAsAddress(int index);
139}
140