Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / target / hexagon / gdbstub.c
blob12d6b3bbcbb16764bad145e65f0508f995faec25
1 /*
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"
20 #include "cpu.h"
21 #include "internal.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) {
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]);
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;
41 if (n < NUM_PREGS) {
42 return gdb_get_reg8(mem_buf, env->pred[n]);
45 n -= NUM_PREGS;
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;
69 if (n < NUM_PREGS) {
70 env->pred[n] = ldl_le_p(mem_buf) & 0xff;
71 return sizeof(uint8_t);
74 n -= NUM_PREGS;
76 g_assert_not_reached();
79 static int gdb_get_vreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
81 int total = 0;
82 int i;
83 for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
84 total += gdb_get_regl(mem_buf, env->VRegs[n].uw[i]);
86 return total;
89 static int gdb_get_qreg(CPUHexagonState *env, GByteArray *mem_buf, int n)
91 int total = 0;
92 int i;
93 for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
94 total += gdb_get_regl(mem_buf, env->QRegs[n].uw[i]);
96 return total;
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;
104 if (n < NUM_VREGS) {
105 return gdb_get_vreg(env, mem_buf, n);
107 n -= NUM_VREGS;
109 if (n < NUM_QREGS) {
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)
118 int i;
119 for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
120 env->VRegs[n].uw[i] = ldl_le_p(mem_buf);
121 mem_buf += 4;
123 return MAX_VEC_SIZE_BYTES;
126 static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
128 int i;
129 for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
130 env->QRegs[n].uw[i] = ldl_le_p(mem_buf);
131 mem_buf += 4;
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;
141 if (n < NUM_VREGS) {
142 return gdb_put_vreg(env, mem_buf, n);
144 n -= NUM_VREGS;
146 if (n < NUM_QREGS) {
147 return gdb_put_qreg(env, mem_buf, n);
150 g_assert_not_reached();