2 * Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "qemu/osdep.h"
19 #include "gdbstub/helpers.h"
23 int hexagon_gdb_read_register(CPUState
*cs
, GByteArray
*mem_buf
, int n
)
25 CPUHexagonState
*env
= cpu_env(cs
);
27 if (n
== HEX_REG_P3_0_ALIASED
) {
29 for (int i
= 0; i
< NUM_PREGS
; i
++) {
30 p3_0
= deposit32(p3_0
, i
* 8, 8, env
->pred
[i
]);
32 return gdb_get_regl(mem_buf
, p3_0
);
35 if (n
< TOTAL_PER_THREAD_REGS
) {
36 return gdb_get_regl(mem_buf
, env
->gpr
[n
]);
39 n
-= TOTAL_PER_THREAD_REGS
;
42 return gdb_get_reg8(mem_buf
, env
->pred
[n
]);
47 g_assert_not_reached();
50 int hexagon_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
52 CPUHexagonState
*env
= cpu_env(cs
);
54 if (n
== HEX_REG_P3_0_ALIASED
) {
55 uint32_t p3_0
= ldl_le_p(mem_buf
);
56 for (int i
= 0; i
< NUM_PREGS
; i
++) {
57 env
->pred
[i
] = extract32(p3_0
, i
* 8, 8);
59 return sizeof(target_ulong
);
62 if (n
< TOTAL_PER_THREAD_REGS
) {
63 env
->gpr
[n
] = ldl_le_p(mem_buf
);
64 return sizeof(target_ulong
);
67 n
-= TOTAL_PER_THREAD_REGS
;
70 env
->pred
[n
] = ldl_le_p(mem_buf
) & 0xff;
71 return sizeof(uint8_t);
76 g_assert_not_reached();
79 static int gdb_get_vreg(CPUHexagonState
*env
, GByteArray
*mem_buf
, int n
)
83 for (i
= 0; i
< ARRAY_SIZE(env
->VRegs
[n
].uw
); i
++) {
84 total
+= gdb_get_regl(mem_buf
, env
->VRegs
[n
].uw
[i
]);
89 static int gdb_get_qreg(CPUHexagonState
*env
, GByteArray
*mem_buf
, int n
)
93 for (i
= 0; i
< ARRAY_SIZE(env
->QRegs
[n
].uw
); i
++) {
94 total
+= gdb_get_regl(mem_buf
, env
->QRegs
[n
].uw
[i
]);
99 int hexagon_hvx_gdb_read_register(CPUState
*cs
, GByteArray
*mem_buf
, int n
)
101 HexagonCPU
*cpu
= HEXAGON_CPU(cs
);
102 CPUHexagonState
*env
= &cpu
->env
;
105 return gdb_get_vreg(env
, mem_buf
, n
);
110 return gdb_get_qreg(env
, mem_buf
, n
);
113 g_assert_not_reached();
116 static int gdb_put_vreg(CPUHexagonState
*env
, uint8_t *mem_buf
, int n
)
119 for (i
= 0; i
< ARRAY_SIZE(env
->VRegs
[n
].uw
); i
++) {
120 env
->VRegs
[n
].uw
[i
] = ldl_le_p(mem_buf
);
123 return MAX_VEC_SIZE_BYTES
;
126 static int gdb_put_qreg(CPUHexagonState
*env
, uint8_t *mem_buf
, int n
)
129 for (i
= 0; i
< ARRAY_SIZE(env
->QRegs
[n
].uw
); i
++) {
130 env
->QRegs
[n
].uw
[i
] = ldl_le_p(mem_buf
);
133 return MAX_VEC_SIZE_BYTES
/ 8;
136 int hexagon_hvx_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
138 HexagonCPU
*cpu
= HEXAGON_CPU(cs
);
139 CPUHexagonState
*env
= &cpu
->env
;
142 return gdb_put_vreg(env
, mem_buf
, n
);
147 return gdb_put_qreg(env
, mem_buf
, n
);
150 g_assert_not_reached();