blob: 502c6987f09fec5fe11ff7ffb830b12d7b27fcaa [file] [log] [blame]
Taylor Simpson9def75f2021-02-07 23:45:58 -06001/*
2 * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18#include "qemu/osdep.h"
Alex Bennée4ea5fe92023-03-02 18:57:56 -080019#include "gdbstub/helpers.h"
Taylor Simpson9def75f2021-02-07 23:45:58 -060020#include "cpu.h"
21#include "internal.h"
22
23int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
24{
Philippe Mathieu-Daudé7ab74282024-01-29 17:44:53 +010025 CPUHexagonState *env = cpu_env(cs);
Taylor Simpson9def75f2021-02-07 23:45:58 -060026
Brian Cainb0bd9d82023-05-04 12:37:34 -030027 if (n == HEX_REG_P3_0_ALIASED) {
28 uint32_t p3_0 = 0;
29 for (int i = 0; i < NUM_PREGS; i++) {
30 p3_0 = deposit32(p3_0, i * 8, 8, env->pred[i]);
31 }
32 return gdb_get_regl(mem_buf, p3_0);
33 }
34
Taylor Simpson9def75f2021-02-07 23:45:58 -060035 if (n < TOTAL_PER_THREAD_REGS) {
36 return gdb_get_regl(mem_buf, env->gpr[n]);
37 }
38
39 g_assert_not_reached();
40}
41
42int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
43{
Philippe Mathieu-Daudé7ab74282024-01-29 17:44:53 +010044 CPUHexagonState *env = cpu_env(cs);
Taylor Simpson9def75f2021-02-07 23:45:58 -060045
Brian Cainb0bd9d82023-05-04 12:37:34 -030046 if (n == HEX_REG_P3_0_ALIASED) {
47 uint32_t p3_0 = ldtul_p(mem_buf);
48 for (int i = 0; i < NUM_PREGS; i++) {
49 env->pred[i] = extract32(p3_0, i * 8, 8);
50 }
51 return sizeof(target_ulong);
52 }
53
Taylor Simpson9def75f2021-02-07 23:45:58 -060054 if (n < TOTAL_PER_THREAD_REGS) {
55 env->gpr[n] = ldtul_p(mem_buf);
56 return sizeof(target_ulong);
57 }
58
59 g_assert_not_reached();
60}
Taylor Simpsonb6476522023-05-04 12:37:35 -030061
62static int gdb_get_vreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
63{
64 int total = 0;
65 int i;
66 for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
67 total += gdb_get_regl(mem_buf, env->VRegs[n].uw[i]);
68 }
69 return total;
70}
71
72static int gdb_get_qreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
73{
74 int total = 0;
75 int i;
76 for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
77 total += gdb_get_regl(mem_buf, env->QRegs[n].uw[i]);
78 }
79 return total;
80}
81
Akihiko Odaki66260152024-02-27 14:43:16 +000082int hexagon_hvx_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
Taylor Simpsonb6476522023-05-04 12:37:35 -030083{
Akihiko Odaki66260152024-02-27 14:43:16 +000084 HexagonCPU *cpu = HEXAGON_CPU(cs);
85 CPUHexagonState *env = &cpu->env;
86
Taylor Simpsonb6476522023-05-04 12:37:35 -030087 if (n < NUM_VREGS) {
88 return gdb_get_vreg(env, mem_buf, n);
89 }
90 n -= NUM_VREGS;
91
92 if (n < NUM_QREGS) {
93 return gdb_get_qreg(env, mem_buf, n);
94 }
95
96 g_assert_not_reached();
97}
98
99static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
100{
101 int i;
102 for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
103 env->VRegs[n].uw[i] = ldtul_p(mem_buf);
104 mem_buf += 4;
105 }
106 return MAX_VEC_SIZE_BYTES;
107}
108
109static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
110{
111 int i;
112 for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
113 env->QRegs[n].uw[i] = ldtul_p(mem_buf);
114 mem_buf += 4;
115 }
116 return MAX_VEC_SIZE_BYTES / 8;
117}
118
Akihiko Odaki66260152024-02-27 14:43:16 +0000119int hexagon_hvx_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
Taylor Simpsonb6476522023-05-04 12:37:35 -0300120{
Akihiko Odaki66260152024-02-27 14:43:16 +0000121 HexagonCPU *cpu = HEXAGON_CPU(cs);
122 CPUHexagonState *env = &cpu->env;
123
Taylor Simpsonb6476522023-05-04 12:37:35 -0300124 if (n < NUM_VREGS) {
125 return gdb_put_vreg(env, mem_buf, n);
126 }
127 n -= NUM_VREGS;
128
129 if (n < NUM_QREGS) {
130 return gdb_put_qreg(env, mem_buf, n);
131 }
132
133 g_assert_not_reached();
134}