blob: 75926d4e049f2faf9be18d64b585b69d498d19cc [file] [log] [blame]
Andreas Färber2f937732013-07-07 12:42:52 +02001/*
2 * SuperH gdb server stub
3 *
4 * Copyright (c) 2003-2005 Fabrice Bellard
5 * Copyright (c) 2013 SUSE LINUX Products GmbH
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
Thomas Huth6faf2b62019-02-13 14:52:50 +010010 * version 2.1 of the License, or (at your option) any later version.
Andreas Färber2f937732013-07-07 12:42:52 +020011 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
Peter Maydell9d4c9942016-01-26 18:17:20 +000020#include "qemu/osdep.h"
Paolo Bonzini33c11872016-03-15 16:58:45 +010021#include "cpu.h"
Alex Bennée4ea5fe92023-03-02 18:57:56 -080022#include "gdbstub/helpers.h"
Andreas Färber2f937732013-07-07 12:42:52 +020023
24/* Hint: Use "set architecture sh4" in GDB to see fpu registers */
25/* FIXME: We should use XML for this. */
26
Alex Bennéea010bdb2020-03-16 17:21:41 +000027int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
Andreas Färber2f937732013-07-07 12:42:52 +020028{
Philippe Mathieu-Daudé795bec92024-01-29 17:45:07 +010029 CPUSH4State *env = cpu_env(cs);
Andreas Färber5b50e792013-06-29 04:18:45 +020030
Andreas Färber2f937732013-07-07 12:42:52 +020031 switch (n) {
32 case 0 ... 7:
Aurelien Jarno5ed9a252015-05-25 01:28:56 +020033 if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
Andreas Färber986a2992013-07-07 13:05:05 +020034 return gdb_get_regl(mem_buf, env->gregs[n + 16]);
Andreas Färber2f937732013-07-07 12:42:52 +020035 } else {
Andreas Färber986a2992013-07-07 13:05:05 +020036 return gdb_get_regl(mem_buf, env->gregs[n]);
Andreas Färber2f937732013-07-07 12:42:52 +020037 }
38 case 8 ... 15:
Andreas Färber986a2992013-07-07 13:05:05 +020039 return gdb_get_regl(mem_buf, env->gregs[n]);
Andreas Färber2f937732013-07-07 12:42:52 +020040 case 16:
Andreas Färber986a2992013-07-07 13:05:05 +020041 return gdb_get_regl(mem_buf, env->pc);
Andreas Färber2f937732013-07-07 12:42:52 +020042 case 17:
Andreas Färber986a2992013-07-07 13:05:05 +020043 return gdb_get_regl(mem_buf, env->pr);
Andreas Färber2f937732013-07-07 12:42:52 +020044 case 18:
Andreas Färber986a2992013-07-07 13:05:05 +020045 return gdb_get_regl(mem_buf, env->gbr);
Andreas Färber2f937732013-07-07 12:42:52 +020046 case 19:
Andreas Färber986a2992013-07-07 13:05:05 +020047 return gdb_get_regl(mem_buf, env->vbr);
Andreas Färber2f937732013-07-07 12:42:52 +020048 case 20:
Andreas Färber986a2992013-07-07 13:05:05 +020049 return gdb_get_regl(mem_buf, env->mach);
Andreas Färber2f937732013-07-07 12:42:52 +020050 case 21:
Andreas Färber986a2992013-07-07 13:05:05 +020051 return gdb_get_regl(mem_buf, env->macl);
Andreas Färber2f937732013-07-07 12:42:52 +020052 case 22:
Aurelien Jarno34086942015-05-25 01:28:56 +020053 return gdb_get_regl(mem_buf, cpu_read_sr(env));
Andreas Färber2f937732013-07-07 12:42:52 +020054 case 23:
Andreas Färber986a2992013-07-07 13:05:05 +020055 return gdb_get_regl(mem_buf, env->fpul);
Andreas Färber2f937732013-07-07 12:42:52 +020056 case 24:
Andreas Färber986a2992013-07-07 13:05:05 +020057 return gdb_get_regl(mem_buf, env->fpscr);
Andreas Färber2f937732013-07-07 12:42:52 +020058 case 25 ... 40:
59 if (env->fpscr & FPSCR_FR) {
Peter Maydelld20711b2021-02-11 12:27:45 +000060 return gdb_get_reg32(mem_buf, env->fregs[n - 9]);
Andreas Färber2f937732013-07-07 12:42:52 +020061 }
Peter Maydelld20711b2021-02-11 12:27:45 +000062 return gdb_get_reg32(mem_buf, env->fregs[n - 25]);
Andreas Färber2f937732013-07-07 12:42:52 +020063 case 41:
Andreas Färber986a2992013-07-07 13:05:05 +020064 return gdb_get_regl(mem_buf, env->ssr);
Andreas Färber2f937732013-07-07 12:42:52 +020065 case 42:
Andreas Färber986a2992013-07-07 13:05:05 +020066 return gdb_get_regl(mem_buf, env->spc);
Andreas Färber2f937732013-07-07 12:42:52 +020067 case 43 ... 50:
Andreas Färber986a2992013-07-07 13:05:05 +020068 return gdb_get_regl(mem_buf, env->gregs[n - 43]);
Andreas Färber2f937732013-07-07 12:42:52 +020069 case 51 ... 58:
Andreas Färber986a2992013-07-07 13:05:05 +020070 return gdb_get_regl(mem_buf, env->gregs[n - (51 - 16)]);
Andreas Färber2f937732013-07-07 12:42:52 +020071 }
72
73 return 0;
74}
75
Andreas Färber5b50e792013-06-29 04:18:45 +020076int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
Andreas Färber2f937732013-07-07 12:42:52 +020077{
Philippe Mathieu-Daudé795bec92024-01-29 17:45:07 +010078 CPUSH4State *env = cpu_env(cs);
Andreas Färber5b50e792013-06-29 04:18:45 +020079
Andreas Färber2f937732013-07-07 12:42:52 +020080 switch (n) {
81 case 0 ... 7:
Aurelien Jarno5ed9a252015-05-25 01:28:56 +020082 if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
Andreas Färber2f937732013-07-07 12:42:52 +020083 env->gregs[n + 16] = ldl_p(mem_buf);
84 } else {
85 env->gregs[n] = ldl_p(mem_buf);
86 }
87 break;
88 case 8 ... 15:
89 env->gregs[n] = ldl_p(mem_buf);
90 break;
91 case 16:
92 env->pc = ldl_p(mem_buf);
93 break;
94 case 17:
95 env->pr = ldl_p(mem_buf);
96 break;
97 case 18:
98 env->gbr = ldl_p(mem_buf);
99 break;
100 case 19:
101 env->vbr = ldl_p(mem_buf);
102 break;
103 case 20:
104 env->mach = ldl_p(mem_buf);
105 break;
106 case 21:
107 env->macl = ldl_p(mem_buf);
108 break;
109 case 22:
Aurelien Jarno34086942015-05-25 01:28:56 +0200110 cpu_write_sr(env, ldl_p(mem_buf));
Andreas Färber2f937732013-07-07 12:42:52 +0200111 break;
112 case 23:
113 env->fpul = ldl_p(mem_buf);
114 break;
115 case 24:
116 env->fpscr = ldl_p(mem_buf);
117 break;
118 case 25 ... 40:
119 if (env->fpscr & FPSCR_FR) {
Peter Maydelld20711b2021-02-11 12:27:45 +0000120 env->fregs[n - 9] = ldl_p(mem_buf);
Andreas Färber2f937732013-07-07 12:42:52 +0200121 } else {
Peter Maydelld20711b2021-02-11 12:27:45 +0000122 env->fregs[n - 25] = ldl_p(mem_buf);
Andreas Färber2f937732013-07-07 12:42:52 +0200123 }
124 break;
125 case 41:
126 env->ssr = ldl_p(mem_buf);
127 break;
128 case 42:
129 env->spc = ldl_p(mem_buf);
130 break;
131 case 43 ... 50:
132 env->gregs[n - 43] = ldl_p(mem_buf);
133 break;
134 case 51 ... 58:
135 env->gregs[n - (51 - 16)] = ldl_p(mem_buf);
136 break;
137 default:
138 return 0;
139 }
140
141 return 4;
142}