xref: /openbmc/qemu/target/sh4/gdbstub.c (revision 6faf2b6c4d70e5c3df523ee0f95c1bed95284ced)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * SuperH gdb server stub
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  * Copyright (c) 2003-2005 Fabrice Bellard
5fcf5ef2aSThomas Huth  * Copyright (c) 2013 SUSE LINUX Products GmbH
6fcf5ef2aSThomas Huth  *
7fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
10*6faf2b6cSThomas Huth  * version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth  *
12fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
16fcf5ef2aSThomas Huth  *
17fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth #include "qemu/osdep.h"
21fcf5ef2aSThomas Huth #include "qemu-common.h"
22fcf5ef2aSThomas Huth #include "cpu.h"
23fcf5ef2aSThomas Huth #include "exec/gdbstub.h"
24fcf5ef2aSThomas Huth 
25fcf5ef2aSThomas Huth /* Hint: Use "set architecture sh4" in GDB to see fpu registers */
26fcf5ef2aSThomas Huth /* FIXME: We should use XML for this.  */
27fcf5ef2aSThomas Huth 
28fcf5ef2aSThomas Huth int superh_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
29fcf5ef2aSThomas Huth {
30fcf5ef2aSThomas Huth     SuperHCPU *cpu = SUPERH_CPU(cs);
31fcf5ef2aSThomas Huth     CPUSH4State *env = &cpu->env;
32fcf5ef2aSThomas Huth 
33fcf5ef2aSThomas Huth     switch (n) {
34fcf5ef2aSThomas Huth     case 0 ... 7:
35fcf5ef2aSThomas Huth         if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
36fcf5ef2aSThomas Huth             return gdb_get_regl(mem_buf, env->gregs[n + 16]);
37fcf5ef2aSThomas Huth         } else {
38fcf5ef2aSThomas Huth             return gdb_get_regl(mem_buf, env->gregs[n]);
39fcf5ef2aSThomas Huth         }
40fcf5ef2aSThomas Huth     case 8 ... 15:
41fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n]);
42fcf5ef2aSThomas Huth     case 16:
43fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->pc);
44fcf5ef2aSThomas Huth     case 17:
45fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->pr);
46fcf5ef2aSThomas Huth     case 18:
47fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gbr);
48fcf5ef2aSThomas Huth     case 19:
49fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->vbr);
50fcf5ef2aSThomas Huth     case 20:
51fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->mach);
52fcf5ef2aSThomas Huth     case 21:
53fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->macl);
54fcf5ef2aSThomas Huth     case 22:
55fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, cpu_read_sr(env));
56fcf5ef2aSThomas Huth     case 23:
57fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->fpul);
58fcf5ef2aSThomas Huth     case 24:
59fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->fpscr);
60fcf5ef2aSThomas Huth     case 25 ... 40:
61fcf5ef2aSThomas Huth         if (env->fpscr & FPSCR_FR) {
62fcf5ef2aSThomas Huth             stfl_p(mem_buf, env->fregs[n - 9]);
63fcf5ef2aSThomas Huth         } else {
64fcf5ef2aSThomas Huth             stfl_p(mem_buf, env->fregs[n - 25]);
65fcf5ef2aSThomas Huth         }
66fcf5ef2aSThomas Huth         return 4;
67fcf5ef2aSThomas Huth     case 41:
68fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->ssr);
69fcf5ef2aSThomas Huth     case 42:
70fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->spc);
71fcf5ef2aSThomas Huth     case 43 ... 50:
72fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n - 43]);
73fcf5ef2aSThomas Huth     case 51 ... 58:
74fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n - (51 - 16)]);
75fcf5ef2aSThomas Huth     }
76fcf5ef2aSThomas Huth 
77fcf5ef2aSThomas Huth     return 0;
78fcf5ef2aSThomas Huth }
79fcf5ef2aSThomas Huth 
80fcf5ef2aSThomas Huth int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
81fcf5ef2aSThomas Huth {
82fcf5ef2aSThomas Huth     SuperHCPU *cpu = SUPERH_CPU(cs);
83fcf5ef2aSThomas Huth     CPUSH4State *env = &cpu->env;
84fcf5ef2aSThomas Huth 
85fcf5ef2aSThomas Huth     switch (n) {
86fcf5ef2aSThomas Huth     case 0 ... 7:
87fcf5ef2aSThomas Huth         if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
88fcf5ef2aSThomas Huth             env->gregs[n + 16] = ldl_p(mem_buf);
89fcf5ef2aSThomas Huth         } else {
90fcf5ef2aSThomas Huth             env->gregs[n] = ldl_p(mem_buf);
91fcf5ef2aSThomas Huth         }
92fcf5ef2aSThomas Huth         break;
93fcf5ef2aSThomas Huth     case 8 ... 15:
94fcf5ef2aSThomas Huth         env->gregs[n] = ldl_p(mem_buf);
95fcf5ef2aSThomas Huth         break;
96fcf5ef2aSThomas Huth     case 16:
97fcf5ef2aSThomas Huth         env->pc = ldl_p(mem_buf);
98fcf5ef2aSThomas Huth         break;
99fcf5ef2aSThomas Huth     case 17:
100fcf5ef2aSThomas Huth         env->pr = ldl_p(mem_buf);
101fcf5ef2aSThomas Huth         break;
102fcf5ef2aSThomas Huth     case 18:
103fcf5ef2aSThomas Huth         env->gbr = ldl_p(mem_buf);
104fcf5ef2aSThomas Huth         break;
105fcf5ef2aSThomas Huth     case 19:
106fcf5ef2aSThomas Huth         env->vbr = ldl_p(mem_buf);
107fcf5ef2aSThomas Huth         break;
108fcf5ef2aSThomas Huth     case 20:
109fcf5ef2aSThomas Huth         env->mach = ldl_p(mem_buf);
110fcf5ef2aSThomas Huth         break;
111fcf5ef2aSThomas Huth     case 21:
112fcf5ef2aSThomas Huth         env->macl = ldl_p(mem_buf);
113fcf5ef2aSThomas Huth         break;
114fcf5ef2aSThomas Huth     case 22:
115fcf5ef2aSThomas Huth         cpu_write_sr(env, ldl_p(mem_buf));
116fcf5ef2aSThomas Huth         break;
117fcf5ef2aSThomas Huth     case 23:
118fcf5ef2aSThomas Huth         env->fpul = ldl_p(mem_buf);
119fcf5ef2aSThomas Huth         break;
120fcf5ef2aSThomas Huth     case 24:
121fcf5ef2aSThomas Huth         env->fpscr = ldl_p(mem_buf);
122fcf5ef2aSThomas Huth         break;
123fcf5ef2aSThomas Huth     case 25 ... 40:
124fcf5ef2aSThomas Huth         if (env->fpscr & FPSCR_FR) {
125fcf5ef2aSThomas Huth             env->fregs[n - 9] = ldfl_p(mem_buf);
126fcf5ef2aSThomas Huth         } else {
127fcf5ef2aSThomas Huth             env->fregs[n - 25] = ldfl_p(mem_buf);
128fcf5ef2aSThomas Huth         }
129fcf5ef2aSThomas Huth         break;
130fcf5ef2aSThomas Huth     case 41:
131fcf5ef2aSThomas Huth         env->ssr = ldl_p(mem_buf);
132fcf5ef2aSThomas Huth         break;
133fcf5ef2aSThomas Huth     case 42:
134fcf5ef2aSThomas Huth         env->spc = ldl_p(mem_buf);
135fcf5ef2aSThomas Huth         break;
136fcf5ef2aSThomas Huth     case 43 ... 50:
137fcf5ef2aSThomas Huth         env->gregs[n - 43] = ldl_p(mem_buf);
138fcf5ef2aSThomas Huth         break;
139fcf5ef2aSThomas Huth     case 51 ... 58:
140fcf5ef2aSThomas Huth         env->gregs[n - (51 - 16)] = ldl_p(mem_buf);
141fcf5ef2aSThomas Huth         break;
142fcf5ef2aSThomas Huth     default:
143fcf5ef2aSThomas Huth         return 0;
144fcf5ef2aSThomas Huth     }
145fcf5ef2aSThomas Huth 
146fcf5ef2aSThomas Huth     return 4;
147fcf5ef2aSThomas Huth }
148