xref: /qemu/target/sh4/gdbstub.c (revision 795bec96)
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
106faf2b6cSThomas 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 "cpu.h"
224ea5fe99SAlex Bennée #include "gdbstub/helpers.h"
23fcf5ef2aSThomas Huth 
24fcf5ef2aSThomas Huth /* Hint: Use "set architecture sh4" in GDB to see fpu registers */
25fcf5ef2aSThomas Huth /* FIXME: We should use XML for this.  */
26fcf5ef2aSThomas Huth 
superh_cpu_gdb_read_register(CPUState * cs,GByteArray * mem_buf,int n)27a010bdbeSAlex Bennée int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
28fcf5ef2aSThomas Huth {
29795bec96SPhilippe Mathieu-Daudé     CPUSH4State *env = cpu_env(cs);
30fcf5ef2aSThomas Huth 
31fcf5ef2aSThomas Huth     switch (n) {
32fcf5ef2aSThomas Huth     case 0 ... 7:
33fcf5ef2aSThomas Huth         if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
34fcf5ef2aSThomas Huth             return gdb_get_regl(mem_buf, env->gregs[n + 16]);
35fcf5ef2aSThomas Huth         } else {
36fcf5ef2aSThomas Huth             return gdb_get_regl(mem_buf, env->gregs[n]);
37fcf5ef2aSThomas Huth         }
38fcf5ef2aSThomas Huth     case 8 ... 15:
39fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n]);
40fcf5ef2aSThomas Huth     case 16:
41fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->pc);
42fcf5ef2aSThomas Huth     case 17:
43fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->pr);
44fcf5ef2aSThomas Huth     case 18:
45fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gbr);
46fcf5ef2aSThomas Huth     case 19:
47fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->vbr);
48fcf5ef2aSThomas Huth     case 20:
49fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->mach);
50fcf5ef2aSThomas Huth     case 21:
51fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->macl);
52fcf5ef2aSThomas Huth     case 22:
53fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, cpu_read_sr(env));
54fcf5ef2aSThomas Huth     case 23:
55fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->fpul);
56fcf5ef2aSThomas Huth     case 24:
57fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->fpscr);
58fcf5ef2aSThomas Huth     case 25 ... 40:
59fcf5ef2aSThomas Huth         if (env->fpscr & FPSCR_FR) {
60d20711bdSPeter Maydell             return gdb_get_reg32(mem_buf, env->fregs[n - 9]);
61fcf5ef2aSThomas Huth         }
62d20711bdSPeter Maydell         return gdb_get_reg32(mem_buf, env->fregs[n - 25]);
63fcf5ef2aSThomas Huth     case 41:
64fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->ssr);
65fcf5ef2aSThomas Huth     case 42:
66fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->spc);
67fcf5ef2aSThomas Huth     case 43 ... 50:
68fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n - 43]);
69fcf5ef2aSThomas Huth     case 51 ... 58:
70fcf5ef2aSThomas Huth         return gdb_get_regl(mem_buf, env->gregs[n - (51 - 16)]);
71fcf5ef2aSThomas Huth     }
72fcf5ef2aSThomas Huth 
73fcf5ef2aSThomas Huth     return 0;
74fcf5ef2aSThomas Huth }
75fcf5ef2aSThomas Huth 
superh_cpu_gdb_write_register(CPUState * cs,uint8_t * mem_buf,int n)76fcf5ef2aSThomas Huth int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
77fcf5ef2aSThomas Huth {
78795bec96SPhilippe Mathieu-Daudé     CPUSH4State *env = cpu_env(cs);
79fcf5ef2aSThomas Huth 
80fcf5ef2aSThomas Huth     switch (n) {
81fcf5ef2aSThomas Huth     case 0 ... 7:
82fcf5ef2aSThomas Huth         if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
83fcf5ef2aSThomas Huth             env->gregs[n + 16] = ldl_p(mem_buf);
84fcf5ef2aSThomas Huth         } else {
85fcf5ef2aSThomas Huth             env->gregs[n] = ldl_p(mem_buf);
86fcf5ef2aSThomas Huth         }
87fcf5ef2aSThomas Huth         break;
88fcf5ef2aSThomas Huth     case 8 ... 15:
89fcf5ef2aSThomas Huth         env->gregs[n] = ldl_p(mem_buf);
90fcf5ef2aSThomas Huth         break;
91fcf5ef2aSThomas Huth     case 16:
92fcf5ef2aSThomas Huth         env->pc = ldl_p(mem_buf);
93fcf5ef2aSThomas Huth         break;
94fcf5ef2aSThomas Huth     case 17:
95fcf5ef2aSThomas Huth         env->pr = ldl_p(mem_buf);
96fcf5ef2aSThomas Huth         break;
97fcf5ef2aSThomas Huth     case 18:
98fcf5ef2aSThomas Huth         env->gbr = ldl_p(mem_buf);
99fcf5ef2aSThomas Huth         break;
100fcf5ef2aSThomas Huth     case 19:
101fcf5ef2aSThomas Huth         env->vbr = ldl_p(mem_buf);
102fcf5ef2aSThomas Huth         break;
103fcf5ef2aSThomas Huth     case 20:
104fcf5ef2aSThomas Huth         env->mach = ldl_p(mem_buf);
105fcf5ef2aSThomas Huth         break;
106fcf5ef2aSThomas Huth     case 21:
107fcf5ef2aSThomas Huth         env->macl = ldl_p(mem_buf);
108fcf5ef2aSThomas Huth         break;
109fcf5ef2aSThomas Huth     case 22:
110fcf5ef2aSThomas Huth         cpu_write_sr(env, ldl_p(mem_buf));
111fcf5ef2aSThomas Huth         break;
112fcf5ef2aSThomas Huth     case 23:
113fcf5ef2aSThomas Huth         env->fpul = ldl_p(mem_buf);
114fcf5ef2aSThomas Huth         break;
115fcf5ef2aSThomas Huth     case 24:
116fcf5ef2aSThomas Huth         env->fpscr = ldl_p(mem_buf);
117fcf5ef2aSThomas Huth         break;
118fcf5ef2aSThomas Huth     case 25 ... 40:
119fcf5ef2aSThomas Huth         if (env->fpscr & FPSCR_FR) {
120d20711bdSPeter Maydell             env->fregs[n - 9] = ldl_p(mem_buf);
121fcf5ef2aSThomas Huth         } else {
122d20711bdSPeter Maydell             env->fregs[n - 25] = ldl_p(mem_buf);
123fcf5ef2aSThomas Huth         }
124fcf5ef2aSThomas Huth         break;
125fcf5ef2aSThomas Huth     case 41:
126fcf5ef2aSThomas Huth         env->ssr = ldl_p(mem_buf);
127fcf5ef2aSThomas Huth         break;
128fcf5ef2aSThomas Huth     case 42:
129fcf5ef2aSThomas Huth         env->spc = ldl_p(mem_buf);
130fcf5ef2aSThomas Huth         break;
131fcf5ef2aSThomas Huth     case 43 ... 50:
132fcf5ef2aSThomas Huth         env->gregs[n - 43] = ldl_p(mem_buf);
133fcf5ef2aSThomas Huth         break;
134fcf5ef2aSThomas Huth     case 51 ... 58:
135fcf5ef2aSThomas Huth         env->gregs[n - (51 - 16)] = ldl_p(mem_buf);
136fcf5ef2aSThomas Huth         break;
137fcf5ef2aSThomas Huth     default:
138fcf5ef2aSThomas Huth         return 0;
139fcf5ef2aSThomas Huth     }
140fcf5ef2aSThomas Huth 
141fcf5ef2aSThomas Huth     return 4;
142fcf5ef2aSThomas Huth }
143