cpustate.h revision 1.1.1.5 1 1.1 christos /* cpustate.h -- Prototypes for AArch64 cpu state functions.
2 1.1 christos
3 1.1.1.5 christos Copyright (C) 2015-2023 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos Contributed by Red Hat.
6 1.1 christos
7 1.1 christos This file is part of GDB.
8 1.1 christos
9 1.1 christos This program is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3 of the License, or
12 1.1 christos (at your option) any later version.
13 1.1 christos
14 1.1 christos This program is distributed in the hope that it will be useful,
15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 1.1 christos GNU General Public License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 1.1 christos
22 1.1 christos #ifndef _CPU_STATE_H
23 1.1 christos #define _CPU_STATE_H
24 1.1 christos
25 1.1 christos #include <sys/types.h>
26 1.1 christos #include <stdint.h>
27 1.1 christos #include <inttypes.h>
28 1.1 christos
29 1.1.1.5 christos #include "sim/sim.h"
30 1.1 christos
31 1.1 christos /* Symbolic names used to identify general registers which also match
32 1.1 christos the registers indices in machine code.
33 1.1 christos
34 1.1 christos We have 32 general registers which can be read/written as 32 bit or
35 1.1 christos 64 bit sources/sinks and are appropriately referred to as Wn or Xn
36 1.1 christos in the assembly code. Some instructions mix these access modes
37 1.1 christos (e.g. ADD X0, X1, W2) so the implementation of the instruction
38 1.1 christos needs to *know* which type of read or write access is required. */
39 1.1 christos typedef enum GReg
40 1.1 christos {
41 1.1 christos R0,
42 1.1 christos R1,
43 1.1 christos R2,
44 1.1 christos R3,
45 1.1 christos R4,
46 1.1 christos R5,
47 1.1 christos R6,
48 1.1 christos R7,
49 1.1 christos R8,
50 1.1 christos R9,
51 1.1 christos R10,
52 1.1 christos R11,
53 1.1 christos R12,
54 1.1 christos R13,
55 1.1 christos R14,
56 1.1 christos R15,
57 1.1 christos R16,
58 1.1 christos R17,
59 1.1 christos R18,
60 1.1 christos R19,
61 1.1 christos R20,
62 1.1 christos R21,
63 1.1 christos R22,
64 1.1 christos R23,
65 1.1 christos R24,
66 1.1 christos R25,
67 1.1 christos R26,
68 1.1 christos R27,
69 1.1 christos R28,
70 1.1 christos R29,
71 1.1 christos R30,
72 1.1 christos R31,
73 1.1 christos FP = R29,
74 1.1 christos LR = R30,
75 1.1 christos SP = R31,
76 1.1 christos ZR = R31
77 1.1 christos } GReg;
78 1.1 christos
79 1.1 christos /* Symbolic names used to refer to floating point registers which also
80 1.1 christos match the registers indices in machine code.
81 1.1 christos
82 1.1 christos We have 32 FP registers which can be read/written as 8, 16, 32, 64
83 1.1 christos and 128 bit sources/sinks and are appropriately referred to as Bn,
84 1.1 christos Hn, Sn, Dn and Qn in the assembly code. Some instructions mix these
85 1.1 christos access modes (e.g. FCVT S0, D0) so the implementation of the
86 1.1 christos instruction needs to *know* which type of read or write access is
87 1.1 christos required. */
88 1.1 christos
89 1.1 christos typedef enum VReg
90 1.1 christos {
91 1.1 christos V0,
92 1.1 christos V1,
93 1.1 christos V2,
94 1.1 christos V3,
95 1.1 christos V4,
96 1.1 christos V5,
97 1.1 christos V6,
98 1.1 christos V7,
99 1.1 christos V8,
100 1.1 christos V9,
101 1.1 christos V10,
102 1.1 christos V11,
103 1.1 christos V12,
104 1.1 christos V13,
105 1.1 christos V14,
106 1.1 christos V15,
107 1.1 christos V16,
108 1.1 christos V17,
109 1.1 christos V18,
110 1.1 christos V19,
111 1.1 christos V20,
112 1.1 christos V21,
113 1.1 christos V22,
114 1.1 christos V23,
115 1.1 christos V24,
116 1.1 christos V25,
117 1.1 christos V26,
118 1.1 christos V27,
119 1.1 christos V28,
120 1.1 christos V29,
121 1.1 christos V30,
122 1.1 christos V31,
123 1.1 christos } VReg;
124 1.1 christos
125 1.1 christos /* All the different integer bit patterns for the components of a
126 1.1 christos general register are overlaid here using a union so as to allow
127 1.1 christos all reading and writing of the desired bits. Note that we have
128 1.1 christos to take care when emulating a big-endian AArch64 as we are
129 1.1 christos running on a little endian host. */
130 1.1 christos
131 1.1 christos typedef union GRegisterValue
132 1.1 christos {
133 1.1 christos #if !WORDS_BIGENDIAN
134 1.1 christos int8_t s8;
135 1.1 christos int16_t s16;
136 1.1 christos int32_t s32;
137 1.1 christos int64_t s64;
138 1.1 christos uint8_t u8;
139 1.1 christos uint16_t u16;
140 1.1 christos uint32_t u32;
141 1.1 christos uint64_t u64;
142 1.1 christos #else
143 1.1 christos struct { int64_t :56; int8_t s8; };
144 1.1 christos struct { int64_t :48; int16_t s16; };
145 1.1 christos struct { int64_t :32; int32_t s32; };
146 1.1 christos int64_t s64;
147 1.1 christos struct { uint64_t :56; uint8_t u8; };
148 1.1 christos struct { uint64_t :48; uint16_t u16; };
149 1.1 christos struct { uint64_t :32; uint32_t u32; };
150 1.1 christos uint64_t u64;
151 1.1 christos #endif
152 1.1 christos } GRegister;
153 1.1 christos
154 1.1 christos /* Float registers provide for storage of a single, double or quad
155 1.1 christos word format float in the same register. Single floats are not
156 1.1 christos paired within each double register as per 32 bit arm. Instead each
157 1.1 christos 128 bit register Vn embeds the bits for Sn, and Dn in the lower
158 1.1 christos quarter and half, respectively, of the bits for Qn.
159 1.1 christos
160 1.1 christos The upper bits can also be accessed as single or double floats by
161 1.1 christos the float vector operations using indexing e.g. V1.D[1], V1.S[3]
162 1.1 christos etc and, for SIMD operations using a horrible index range notation.
163 1.1 christos
164 1.1 christos The spec also talks about accessing float registers as half words
165 1.1 christos and bytes with Hn and Bn providing access to the low 16 and 8 bits
166 1.1 christos of Vn but it is not really clear what these bits represent. We can
167 1.1 christos probably ignore this for Java anyway. However, we do need to access
168 1.1 christos the raw bits at 32 and 64 bit resolution to load to/from integer
169 1.1 christos registers.
170 1.1 christos
171 1.1 christos Note - we do not use the long double type. Aliasing issues between
172 1.1 christos integer and float values mean that it is unreliable to use them. */
173 1.1 christos
174 1.1 christos typedef union FRegisterValue
175 1.1 christos {
176 1.1 christos float s;
177 1.1 christos double d;
178 1.1 christos
179 1.1 christos uint64_t v[2];
180 1.1 christos uint32_t w[4];
181 1.1 christos uint16_t h[8];
182 1.1 christos uint8_t b[16];
183 1.1 christos
184 1.1 christos int64_t V[2];
185 1.1 christos int32_t W[4];
186 1.1 christos int16_t H[8];
187 1.1 christos int8_t B[16];
188 1.1 christos
189 1.1 christos float S[4];
190 1.1 christos double D[2];
191 1.1 christos
192 1.1 christos } FRegister;
193 1.1 christos
194 1.1 christos /* Condition register bit select values.
195 1.1 christos
196 1.1 christos The order of bits here is important because some of
197 1.1 christos the flag setting conditional instructions employ a
198 1.1 christos bit field to populate the flags when a false condition
199 1.1 christos bypasses execution of the operation and we want to
200 1.1 christos be able to assign the flags register using the
201 1.1 christos supplied value. */
202 1.1 christos
203 1.1 christos typedef enum FlagIdx
204 1.1 christos {
205 1.1 christos V_IDX = 0,
206 1.1 christos C_IDX = 1,
207 1.1 christos Z_IDX = 2,
208 1.1 christos N_IDX = 3
209 1.1 christos } FlagIdx;
210 1.1 christos
211 1.1 christos typedef enum FlagMask
212 1.1 christos {
213 1.1 christos V = 1 << V_IDX,
214 1.1 christos C = 1 << C_IDX,
215 1.1 christos Z = 1 << Z_IDX,
216 1.1 christos N = 1 << N_IDX
217 1.1 christos } FlagMask;
218 1.1 christos
219 1.1 christos #define CPSR_ALL_FLAGS (V | C | Z | N)
220 1.1 christos
221 1.1 christos typedef uint32_t FlagsRegister;
222 1.1 christos
223 1.1 christos /* FPSR register -- floating point status register
224 1.1 christos
225 1.1 christos This register includes IDC, IXC, UFC, OFC, DZC, IOC and QC bits,
226 1.1 christos and the floating point N, Z, C, V bits but the latter are unused in
227 1.1 christos aarch64 mode. The sim ignores QC for now.
228 1.1 christos
229 1.1 christos Bit positions are as per the ARMv7 FPSCR register
230 1.1 christos
231 1.1 christos IDC : 7 ==> Input Denormal (cumulative exception bit)
232 1.1 christos IXC : 4 ==> Inexact
233 1.1 christos UFC : 3 ==> Underflow
234 1.1 christos OFC : 2 ==> Overflow
235 1.1 christos DZC : 1 ==> Division by Zero
236 1.1 christos IOC : 0 ==> Invalid Operation
237 1.1 christos
238 1.1 christos The rounding mode is held in bits [23,22] defined as follows:
239 1.1 christos
240 1.1 christos 0b00 Round to Nearest (RN) mode
241 1.1 christos 0b01 Round towards Plus Infinity (RP) mode
242 1.1 christos 0b10 Round towards Minus Infinity (RM) mode
243 1.1 christos 0b11 Round towards Zero (RZ) mode. */
244 1.1 christos
245 1.1 christos /* Indices for bits in the FPSR register value. */
246 1.1 christos typedef enum FPSRIdx
247 1.1 christos {
248 1.1 christos IO_IDX = 0,
249 1.1 christos DZ_IDX = 1,
250 1.1 christos OF_IDX = 2,
251 1.1 christos UF_IDX = 3,
252 1.1 christos IX_IDX = 4,
253 1.1 christos ID_IDX = 7
254 1.1 christos } FPSRIdx;
255 1.1 christos
256 1.1 christos /* Corresponding bits as numeric values. */
257 1.1 christos typedef enum FPSRMask
258 1.1 christos {
259 1.1 christos IO = (1 << IO_IDX),
260 1.1 christos DZ = (1 << DZ_IDX),
261 1.1 christos OF = (1 << OF_IDX),
262 1.1 christos UF = (1 << UF_IDX),
263 1.1 christos IX = (1 << IX_IDX),
264 1.1 christos ID = (1 << ID_IDX)
265 1.1 christos } FPSRMask;
266 1.1 christos
267 1.1 christos #define FPSR_ALL_FPSRS (IO | DZ | OF | UF | IX | ID)
268 1.1 christos
269 1.1 christos /* General Register access functions. */
270 1.1 christos extern uint64_t aarch64_get_reg_u64 (sim_cpu *, GReg, int);
271 1.1 christos extern int64_t aarch64_get_reg_s64 (sim_cpu *, GReg, int);
272 1.1 christos extern uint32_t aarch64_get_reg_u32 (sim_cpu *, GReg, int);
273 1.1 christos extern int32_t aarch64_get_reg_s32 (sim_cpu *, GReg, int);
274 1.1 christos extern uint32_t aarch64_get_reg_u16 (sim_cpu *, GReg, int);
275 1.1 christos extern int32_t aarch64_get_reg_s16 (sim_cpu *, GReg, int);
276 1.1 christos extern uint32_t aarch64_get_reg_u8 (sim_cpu *, GReg, int);
277 1.1 christos extern int32_t aarch64_get_reg_s8 (sim_cpu *, GReg, int);
278 1.1 christos
279 1.1 christos extern void aarch64_set_reg_u64 (sim_cpu *, GReg, int, uint64_t);
280 1.1 christos extern void aarch64_set_reg_u32 (sim_cpu *, GReg, int, uint32_t);
281 1.1 christos extern void aarch64_set_reg_s64 (sim_cpu *, GReg, int, int64_t);
282 1.1 christos extern void aarch64_set_reg_s32 (sim_cpu *, GReg, int, int32_t);
283 1.1 christos
284 1.1 christos /* FP Register access functions. */
285 1.1 christos extern float aarch64_get_FP_half (sim_cpu *, VReg);
286 1.1 christos extern float aarch64_get_FP_float (sim_cpu *, VReg);
287 1.1 christos extern double aarch64_get_FP_double (sim_cpu *, VReg);
288 1.1 christos extern void aarch64_get_FP_long_double (sim_cpu *, VReg, FRegister *);
289 1.1 christos
290 1.1 christos extern void aarch64_set_FP_half (sim_cpu *, VReg, float);
291 1.1 christos extern void aarch64_set_FP_float (sim_cpu *, VReg, float);
292 1.1 christos extern void aarch64_set_FP_double (sim_cpu *, VReg, double);
293 1.1 christos extern void aarch64_set_FP_long_double (sim_cpu *, VReg, FRegister);
294 1.1 christos
295 1.1 christos /* PC register accessors. */
296 1.1 christos extern uint64_t aarch64_get_PC (sim_cpu *);
297 1.1 christos extern uint64_t aarch64_get_next_PC (sim_cpu *);
298 1.1 christos extern void aarch64_set_next_PC (sim_cpu *, uint64_t);
299 1.1 christos extern void aarch64_set_next_PC_by_offset (sim_cpu *, int64_t);
300 1.1 christos extern void aarch64_update_PC (sim_cpu *);
301 1.1 christos extern void aarch64_save_LR (sim_cpu *);
302 1.1 christos
303 1.1 christos /* Instruction accessor - implemented as a
304 1.1 christos macro as we do not need to annotate it. */
305 1.1 christos #define aarch64_get_instr(cpu) ((cpu)->instr)
306 1.1 christos
307 1.1 christos /* Flag register accessors. */
308 1.1 christos extern uint32_t aarch64_get_CPSR (sim_cpu *);
309 1.1 christos extern void aarch64_set_CPSR (sim_cpu *, uint32_t);
310 1.1.1.5 christos extern uint32_t aarch64_get_CPSR_bits (sim_cpu *, FlagMask);
311 1.1 christos extern void aarch64_set_CPSR_bits (sim_cpu *, uint32_t, uint32_t);
312 1.1 christos extern uint32_t aarch64_test_CPSR_bit (sim_cpu *, FlagMask);
313 1.1 christos extern void aarch64_set_CPSR_bit (sim_cpu *, FlagMask);
314 1.1 christos extern void aarch64_clear_CPSR_bit (sim_cpu *, FlagMask);
315 1.1 christos
316 1.1 christos extern void aarch64_set_FPSR (sim_cpu *, uint32_t);
317 1.1 christos extern uint32_t aarch64_get_FPSR (sim_cpu *);
318 1.1 christos extern void aarch64_set_FPSR_bits (sim_cpu *, uint32_t, uint32_t);
319 1.1 christos extern uint32_t aarch64_get_FPSR_bits (sim_cpu *, uint32_t);
320 1.1 christos extern int aarch64_test_FPSR_bit (sim_cpu *, FPSRMask);
321 1.1 christos
322 1.1 christos /* Vector register accessors. */
323 1.1 christos extern uint64_t aarch64_get_vec_u64 (sim_cpu *, VReg, unsigned);
324 1.1 christos extern uint32_t aarch64_get_vec_u32 (sim_cpu *, VReg, unsigned);
325 1.1 christos extern uint16_t aarch64_get_vec_u16 (sim_cpu *, VReg, unsigned);
326 1.1 christos extern uint8_t aarch64_get_vec_u8 (sim_cpu *, VReg, unsigned);
327 1.1 christos extern void aarch64_set_vec_u64 (sim_cpu *, VReg, unsigned, uint64_t);
328 1.1 christos extern void aarch64_set_vec_u32 (sim_cpu *, VReg, unsigned, uint32_t);
329 1.1 christos extern void aarch64_set_vec_u16 (sim_cpu *, VReg, unsigned, uint16_t);
330 1.1 christos extern void aarch64_set_vec_u8 (sim_cpu *, VReg, unsigned, uint8_t);
331 1.1 christos
332 1.1 christos extern int64_t aarch64_get_vec_s64 (sim_cpu *, VReg, unsigned);
333 1.1 christos extern int32_t aarch64_get_vec_s32 (sim_cpu *, VReg, unsigned);
334 1.1 christos extern int16_t aarch64_get_vec_s16 (sim_cpu *, VReg, unsigned);
335 1.1 christos extern int8_t aarch64_get_vec_s8 (sim_cpu *, VReg, unsigned);
336 1.1 christos extern void aarch64_set_vec_s64 (sim_cpu *, VReg, unsigned, int64_t);
337 1.1 christos extern void aarch64_set_vec_s32 (sim_cpu *, VReg, unsigned, int32_t);
338 1.1 christos extern void aarch64_set_vec_s16 (sim_cpu *, VReg, unsigned, int16_t);
339 1.1 christos extern void aarch64_set_vec_s8 (sim_cpu *, VReg, unsigned, int8_t);
340 1.1 christos
341 1.1 christos extern float aarch64_get_vec_float (sim_cpu *, VReg, unsigned);
342 1.1 christos extern double aarch64_get_vec_double (sim_cpu *, VReg, unsigned);
343 1.1 christos extern void aarch64_set_vec_float (sim_cpu *, VReg, unsigned, float);
344 1.1 christos extern void aarch64_set_vec_double (sim_cpu *, VReg, unsigned, double);
345 1.1 christos
346 1.1 christos /* System register accessors. */
347 1.1 christos extern uint64_t aarch64_get_thread_id (sim_cpu *);
348 1.1 christos extern uint32_t aarch64_get_FPCR (sim_cpu *);
349 1.1 christos extern void aarch64_set_FPCR (sim_cpu *, uint32_t);
350 1.1 christos
351 1.1 christos #endif /* _CPU_STATE_H */
352