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