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