xref: /qemu/target/rx/gdbstub.c (revision a976a99a)
1 /*
2  * RX gdb server stub
3  *
4  * Copyright (c) 2019 Yoshinori Sato
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2 or later, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "qemu/osdep.h"
19 #include "cpu.h"
20 #include "exec/gdbstub.h"
21 
22 int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
23 {
24     RXCPU *cpu = RX_CPU(cs);
25     CPURXState *env = &cpu->env;
26 
27     switch (n) {
28     case 0 ... 15:
29         return gdb_get_regl(mem_buf, env->regs[n]);
30     case 16:
31         return gdb_get_regl(mem_buf, (env->psw_u) ? env->regs[0] : env->usp);
32     case 17:
33         return gdb_get_regl(mem_buf, (!env->psw_u) ? env->regs[0] : env->isp);
34     case 18:
35         return gdb_get_regl(mem_buf, rx_cpu_pack_psw(env));
36     case 19:
37         return gdb_get_regl(mem_buf, env->pc);
38     case 20:
39         return gdb_get_regl(mem_buf, env->intb);
40     case 21:
41         return gdb_get_regl(mem_buf, env->bpsw);
42     case 22:
43         return gdb_get_regl(mem_buf, env->bpc);
44     case 23:
45         return gdb_get_regl(mem_buf, env->fintv);
46     case 24:
47         return gdb_get_regl(mem_buf, env->fpsw);
48     case 25:
49         return 0;
50     }
51     return 0;
52 }
53 
54 int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
55 {
56     RXCPU *cpu = RX_CPU(cs);
57     CPURXState *env = &cpu->env;
58     uint32_t psw;
59     switch (n) {
60     case 0 ... 15:
61         env->regs[n] = ldl_p(mem_buf);
62         if (n == 0) {
63             if (env->psw_u) {
64                 env->usp = env->regs[0];
65             } else {
66                 env->isp = env->regs[0];
67             }
68         }
69         break;
70     case 16:
71         env->usp = ldl_p(mem_buf);
72         if (env->psw_u) {
73             env->regs[0] = ldl_p(mem_buf);
74         }
75         break;
76     case 17:
77         env->isp = ldl_p(mem_buf);
78         if (!env->psw_u) {
79             env->regs[0] = ldl_p(mem_buf);
80         }
81         break;
82     case 18:
83         psw = ldl_p(mem_buf);
84         rx_cpu_unpack_psw(env, psw, 1);
85         break;
86     case 19:
87         env->pc = ldl_p(mem_buf);
88         break;
89     case 20:
90         env->intb = ldl_p(mem_buf);
91         break;
92     case 21:
93         env->bpsw = ldl_p(mem_buf);
94         break;
95     case 22:
96         env->bpc = ldl_p(mem_buf);
97         break;
98     case 23:
99         env->fintv = ldl_p(mem_buf);
100         break;
101     case 24:
102         env->fpsw = ldl_p(mem_buf);
103         break;
104     case 25:
105         return 8;
106     default:
107         return 0;
108     }
109 
110     return 4;
111 }
112