xref: /openbmc/qemu/target/rx/gdbstub.c (revision fdf1c980)
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 "gdbstub/helpers.h"
21 
22 int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
23 {
24     CPURXState *env = cpu_env(cs);
25 
26     switch (n) {
27     case 0 ... 15:
28         return gdb_get_regl(mem_buf, env->regs[n]);
29     case 16:
30         return gdb_get_regl(mem_buf, (env->psw_u) ? env->regs[0] : env->usp);
31     case 17:
32         return gdb_get_regl(mem_buf, (!env->psw_u) ? env->regs[0] : env->isp);
33     case 18:
34         return gdb_get_regl(mem_buf, rx_cpu_pack_psw(env));
35     case 19:
36         return gdb_get_regl(mem_buf, env->pc);
37     case 20:
38         return gdb_get_regl(mem_buf, env->intb);
39     case 21:
40         return gdb_get_regl(mem_buf, env->bpsw);
41     case 22:
42         return gdb_get_regl(mem_buf, env->bpc);
43     case 23:
44         return gdb_get_regl(mem_buf, env->fintv);
45     case 24:
46         return gdb_get_regl(mem_buf, env->fpsw);
47     case 25:
48         return 0;
49     }
50     return 0;
51 }
52 
53 int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
54 {
55     CPURXState *env = cpu_env(cs);
56     uint32_t psw;
57     switch (n) {
58     case 0 ... 15:
59         env->regs[n] = ldl_p(mem_buf);
60         if (n == 0) {
61             if (env->psw_u) {
62                 env->usp = env->regs[0];
63             } else {
64                 env->isp = env->regs[0];
65             }
66         }
67         break;
68     case 16:
69         env->usp = ldl_p(mem_buf);
70         if (env->psw_u) {
71             env->regs[0] = ldl_p(mem_buf);
72         }
73         break;
74     case 17:
75         env->isp = ldl_p(mem_buf);
76         if (!env->psw_u) {
77             env->regs[0] = ldl_p(mem_buf);
78         }
79         break;
80     case 18:
81         psw = ldl_p(mem_buf);
82         rx_cpu_unpack_psw(env, psw, 1);
83         break;
84     case 19:
85         env->pc = ldl_p(mem_buf);
86         break;
87     case 20:
88         env->intb = ldl_p(mem_buf);
89         break;
90     case 21:
91         env->bpsw = ldl_p(mem_buf);
92         break;
93     case 22:
94         env->bpc = ldl_p(mem_buf);
95         break;
96     case 23:
97         env->fintv = ldl_p(mem_buf);
98         break;
99     case 24:
100         env->fpsw = ldl_p(mem_buf);
101         break;
102     case 25:
103         return 8;
104     default:
105         return 0;
106     }
107 
108     return 4;
109 }
110