xref: /qemu/target/microblaze/gdbstub.c (revision 201dd7d37b654621c5727e49c666cbfc56e61d58)
1eabfc239SAndreas Färber /*
2eabfc239SAndreas Färber  * MicroBlaze gdb server stub
3eabfc239SAndreas Färber  *
4eabfc239SAndreas Färber  * Copyright (c) 2003-2005 Fabrice Bellard
5eabfc239SAndreas Färber  * Copyright (c) 2013 SUSE LINUX Products GmbH
6eabfc239SAndreas Färber  *
7eabfc239SAndreas Färber  * This library is free software; you can redistribute it and/or
8eabfc239SAndreas Färber  * modify it under the terms of the GNU Lesser General Public
9eabfc239SAndreas Färber  * License as published by the Free Software Foundation; either
10eabfc239SAndreas Färber  * version 2 of the License, or (at your option) any later version.
11eabfc239SAndreas Färber  *
12eabfc239SAndreas Färber  * This library is distributed in the hope that it will be useful,
13eabfc239SAndreas Färber  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14eabfc239SAndreas Färber  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15eabfc239SAndreas Färber  * Lesser General Public License for more details.
16eabfc239SAndreas Färber  *
17eabfc239SAndreas Färber  * You should have received a copy of the GNU Lesser General Public
18eabfc239SAndreas Färber  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19eabfc239SAndreas Färber  */
208fd9deceSPeter Maydell #include "qemu/osdep.h"
2133c11879SPaolo Bonzini #include "cpu.h"
225b50e790SAndreas Färber #include "exec/gdbstub.h"
23eabfc239SAndreas Färber 
24a010bdbeSAlex Bennée int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
25eabfc239SAndreas Färber {
265b50e790SAndreas Färber     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
275b50e790SAndreas Färber     CPUMBState *env = &cpu->env;
28*201dd7d3SJoe Komlodi     /*
29*201dd7d3SJoe Komlodi      * GDB expects SREGs in the following order:
30*201dd7d3SJoe Komlodi      * PC, MSR, EAR, ESR, FSR, BTR, EDR, PID, ZPR, TLBX, TLBSX, TLBLO, TLBHI.
31*201dd7d3SJoe Komlodi      * They aren't stored in this order, so make a map.
32*201dd7d3SJoe Komlodi      * PID, ZPR, TLBx, TLBsx, TLBLO, and TLBHI aren't modeled, so we don't
33*201dd7d3SJoe Komlodi      * map them to anything and return a value of 0 instead.
34*201dd7d3SJoe Komlodi      */
35*201dd7d3SJoe Komlodi     static const uint8_t sreg_map[6] = {
36*201dd7d3SJoe Komlodi         SR_PC,
37*201dd7d3SJoe Komlodi         SR_MSR,
38*201dd7d3SJoe Komlodi         SR_EAR,
39*201dd7d3SJoe Komlodi         SR_ESR,
40*201dd7d3SJoe Komlodi         SR_FSR,
41*201dd7d3SJoe Komlodi         SR_BTR
42*201dd7d3SJoe Komlodi     };
435b50e790SAndreas Färber 
44a44e82dbSJoe Komlodi     /*
45a44e82dbSJoe Komlodi      * GDB expects registers to be reported in this order:
46a44e82dbSJoe Komlodi      * R0-R31
47a44e82dbSJoe Komlodi      * PC-BTR
48a44e82dbSJoe Komlodi      * PVR0-PVR11
49a44e82dbSJoe Komlodi      * EDR-TLBHI
50a44e82dbSJoe Komlodi      * SLR-SHR
51a44e82dbSJoe Komlodi      */
52eabfc239SAndreas Färber     if (n < 32) {
53986a2998SAndreas Färber         return gdb_get_reg32(mem_buf, env->regs[n]);
54eabfc239SAndreas Färber     } else {
55a44e82dbSJoe Komlodi         n -= 32;
56a44e82dbSJoe Komlodi         switch (n) {
57a44e82dbSJoe Komlodi         case 0 ... 5:
58*201dd7d3SJoe Komlodi             return gdb_get_reg32(mem_buf, env->sregs[sreg_map[n]]);
59a44e82dbSJoe Komlodi         /* PVR12 is intentionally skipped */
60a44e82dbSJoe Komlodi         case 6 ... 17:
61a44e82dbSJoe Komlodi             n -= 6;
62a44e82dbSJoe Komlodi             return gdb_get_reg32(mem_buf, env->pvr.regs[n]);
63*201dd7d3SJoe Komlodi         case 18:
64*201dd7d3SJoe Komlodi             return gdb_get_reg32(mem_buf, env->sregs[SR_EDR]);
65*201dd7d3SJoe Komlodi         /* Other SRegs aren't modeled, so report a value of 0 */
66*201dd7d3SJoe Komlodi         case 19 ... 24:
67*201dd7d3SJoe Komlodi             return gdb_get_reg32(mem_buf, 0);
68a44e82dbSJoe Komlodi         case 25:
69a44e82dbSJoe Komlodi             return gdb_get_reg32(mem_buf, env->slr);
70a44e82dbSJoe Komlodi         case 26:
71a44e82dbSJoe Komlodi             return gdb_get_reg32(mem_buf, env->shr);
72a44e82dbSJoe Komlodi         default:
73eabfc239SAndreas Färber             return 0;
74eabfc239SAndreas Färber         }
75a44e82dbSJoe Komlodi     }
76a44e82dbSJoe Komlodi }
77eabfc239SAndreas Färber 
785b50e790SAndreas Färber int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
79eabfc239SAndreas Färber {
805b50e790SAndreas Färber     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
815b50e790SAndreas Färber     CPUClass *cc = CPU_GET_CLASS(cs);
825b50e790SAndreas Färber     CPUMBState *env = &cpu->env;
83eabfc239SAndreas Färber     uint32_t tmp;
84eabfc239SAndreas Färber 
85*201dd7d3SJoe Komlodi     /*
86*201dd7d3SJoe Komlodi      * GDB expects SREGs in the following order:
87*201dd7d3SJoe Komlodi      * PC, MSR, EAR, ESR, FSR, BTR, EDR, PID, ZPR, TLBX, TLBSX, TLBLO, TLBHI.
88*201dd7d3SJoe Komlodi      * They aren't stored in this order, so make a map.
89*201dd7d3SJoe Komlodi      * PID, ZPR, TLBx, TLBsx, TLBLO, and TLBHI aren't modeled, so we don't
90*201dd7d3SJoe Komlodi      * map them to anything.
91*201dd7d3SJoe Komlodi      */
92*201dd7d3SJoe Komlodi     static const uint8_t sreg_map[6] = {
93*201dd7d3SJoe Komlodi         SR_PC,
94*201dd7d3SJoe Komlodi         SR_MSR,
95*201dd7d3SJoe Komlodi         SR_EAR,
96*201dd7d3SJoe Komlodi         SR_ESR,
97*201dd7d3SJoe Komlodi         SR_FSR,
98*201dd7d3SJoe Komlodi         SR_BTR
99*201dd7d3SJoe Komlodi     };
100*201dd7d3SJoe Komlodi 
101eabfc239SAndreas Färber     if (n > cc->gdb_num_core_regs) {
102eabfc239SAndreas Färber         return 0;
103eabfc239SAndreas Färber     }
104eabfc239SAndreas Färber 
105eabfc239SAndreas Färber     tmp = ldl_p(mem_buf);
106eabfc239SAndreas Färber 
107*201dd7d3SJoe Komlodi     /*
108*201dd7d3SJoe Komlodi      * GDB expects registers to be reported in this order:
109*201dd7d3SJoe Komlodi      * R0-R31
110*201dd7d3SJoe Komlodi      * PC-BTR
111*201dd7d3SJoe Komlodi      * PVR0-PVR11
112*201dd7d3SJoe Komlodi      * EDR-TLBHI
113*201dd7d3SJoe Komlodi      * SLR-SHR
114*201dd7d3SJoe Komlodi      */
115eabfc239SAndreas Färber     if (n < 32) {
116eabfc239SAndreas Färber         env->regs[n] = tmp;
117eabfc239SAndreas Färber     } else {
118a44e82dbSJoe Komlodi         n -= 32;
119a44e82dbSJoe Komlodi         switch (n) {
120a44e82dbSJoe Komlodi         case 0 ... 5:
121*201dd7d3SJoe Komlodi             env->sregs[sreg_map[n]] = tmp;
122a44e82dbSJoe Komlodi             break;
123a44e82dbSJoe Komlodi         /* PVR12 is intentionally skipped */
124a44e82dbSJoe Komlodi         case 6 ... 17:
125a44e82dbSJoe Komlodi             n -= 6;
126a44e82dbSJoe Komlodi             env->pvr.regs[n] = tmp;
127a44e82dbSJoe Komlodi             break;
128*201dd7d3SJoe Komlodi         /* Only EDR is modeled in these indeces, so ignore the rest */
129*201dd7d3SJoe Komlodi         case 18:
130*201dd7d3SJoe Komlodi             env->sregs[SR_EDR] = tmp;
131a44e82dbSJoe Komlodi             break;
132a44e82dbSJoe Komlodi         case 25:
133a44e82dbSJoe Komlodi             env->slr = tmp;
134a44e82dbSJoe Komlodi             break;
135a44e82dbSJoe Komlodi         case 26:
136a44e82dbSJoe Komlodi             env->shr = tmp;
137a44e82dbSJoe Komlodi             break;
138a44e82dbSJoe Komlodi         }
139eabfc239SAndreas Färber     }
140eabfc239SAndreas Färber     return 4;
141eabfc239SAndreas Färber }
142