xref: /openbmc/qemu/target/avr/gdbstub.c (revision 12b35405)
1*12b35405SMichael Rolnik /*
2*12b35405SMichael Rolnik  * QEMU AVR gdbstub
3*12b35405SMichael Rolnik  *
4*12b35405SMichael Rolnik  * Copyright (c) 2016-2020 Michael Rolnik
5*12b35405SMichael Rolnik  *
6*12b35405SMichael Rolnik  * This library is free software; you can redistribute it and/or
7*12b35405SMichael Rolnik  * modify it under the terms of the GNU Lesser General Public
8*12b35405SMichael Rolnik  * License as published by the Free Software Foundation; either
9*12b35405SMichael Rolnik  * version 2.1 of the License, or (at your option) any later version.
10*12b35405SMichael Rolnik  *
11*12b35405SMichael Rolnik  * This library is distributed in the hope that it will be useful,
12*12b35405SMichael Rolnik  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*12b35405SMichael Rolnik  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*12b35405SMichael Rolnik  * Lesser General Public License for more details.
15*12b35405SMichael Rolnik  *
16*12b35405SMichael Rolnik  * You should have received a copy of the GNU Lesser General Public
17*12b35405SMichael Rolnik  * License along with this library; if not, see
18*12b35405SMichael Rolnik  * <http://www.gnu.org/licenses/lgpl-2.1.html>
19*12b35405SMichael Rolnik  */
20*12b35405SMichael Rolnik 
21*12b35405SMichael Rolnik #include "qemu/osdep.h"
22*12b35405SMichael Rolnik #include "exec/gdbstub.h"
23*12b35405SMichael Rolnik 
24*12b35405SMichael Rolnik int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
25*12b35405SMichael Rolnik {
26*12b35405SMichael Rolnik     AVRCPU *cpu = AVR_CPU(cs);
27*12b35405SMichael Rolnik     CPUAVRState *env = &cpu->env;
28*12b35405SMichael Rolnik 
29*12b35405SMichael Rolnik     /*  R */
30*12b35405SMichael Rolnik     if (n < 32) {
31*12b35405SMichael Rolnik         return gdb_get_reg8(mem_buf, env->r[n]);
32*12b35405SMichael Rolnik     }
33*12b35405SMichael Rolnik 
34*12b35405SMichael Rolnik     /*  SREG */
35*12b35405SMichael Rolnik     if (n == 32) {
36*12b35405SMichael Rolnik         uint8_t sreg = cpu_get_sreg(env);
37*12b35405SMichael Rolnik 
38*12b35405SMichael Rolnik         return gdb_get_reg8(mem_buf, sreg);
39*12b35405SMichael Rolnik     }
40*12b35405SMichael Rolnik 
41*12b35405SMichael Rolnik     /*  SP */
42*12b35405SMichael Rolnik     if (n == 33) {
43*12b35405SMichael Rolnik         return gdb_get_reg16(mem_buf, env->sp & 0x0000ffff);
44*12b35405SMichael Rolnik     }
45*12b35405SMichael Rolnik 
46*12b35405SMichael Rolnik     /*  PC */
47*12b35405SMichael Rolnik     if (n == 34) {
48*12b35405SMichael Rolnik         return gdb_get_reg32(mem_buf, env->pc_w * 2);
49*12b35405SMichael Rolnik     }
50*12b35405SMichael Rolnik 
51*12b35405SMichael Rolnik     return 0;
52*12b35405SMichael Rolnik }
53*12b35405SMichael Rolnik 
54*12b35405SMichael Rolnik int avr_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
55*12b35405SMichael Rolnik {
56*12b35405SMichael Rolnik     AVRCPU *cpu = AVR_CPU(cs);
57*12b35405SMichael Rolnik     CPUAVRState *env = &cpu->env;
58*12b35405SMichael Rolnik 
59*12b35405SMichael Rolnik     /*  R */
60*12b35405SMichael Rolnik     if (n < 32) {
61*12b35405SMichael Rolnik         env->r[n] = *mem_buf;
62*12b35405SMichael Rolnik         return 1;
63*12b35405SMichael Rolnik     }
64*12b35405SMichael Rolnik 
65*12b35405SMichael Rolnik     /*  SREG */
66*12b35405SMichael Rolnik     if (n == 32) {
67*12b35405SMichael Rolnik         cpu_set_sreg(env, *mem_buf);
68*12b35405SMichael Rolnik         return 1;
69*12b35405SMichael Rolnik     }
70*12b35405SMichael Rolnik 
71*12b35405SMichael Rolnik     /*  SP */
72*12b35405SMichael Rolnik     if (n == 33) {
73*12b35405SMichael Rolnik         env->sp = lduw_p(mem_buf);
74*12b35405SMichael Rolnik         return 2;
75*12b35405SMichael Rolnik     }
76*12b35405SMichael Rolnik 
77*12b35405SMichael Rolnik     /*  PC */
78*12b35405SMichael Rolnik     if (n == 34) {
79*12b35405SMichael Rolnik         env->pc_w = ldl_p(mem_buf) / 2;
80*12b35405SMichael Rolnik         return 4;
81*12b35405SMichael Rolnik     }
82*12b35405SMichael Rolnik 
83*12b35405SMichael Rolnik     return 0;
84*12b35405SMichael Rolnik }
85