remote_gdb.cc (10601:6efb37480d87) remote_gdb.cc (10707:f7d17d8a854c)
1/*
2 * Copyright 2014 Google Inc.
3 * Copyright (c) 2010, 2013 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 * William Wang
43 */
44
45/*
46 * Copyright (c) 1990, 1993 The Regents of the University of California
47 * All rights reserved
48 *
49 * This software was developed by the Computer Systems Engineering group
50 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
51 * contributed to Berkeley.
52 *
53 * All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Lawrence Berkeley Laboratories.
57 *
58 * Redistribution and use in source and binary forms, with or without
59 * modification, are permitted provided that the following conditions
60 * are met:
61 * 1. Redistributions of source code must retain the above copyright
62 * notice, this list of conditions and the following disclaimer.
63 * 2. Redistributions in binary form must reproduce the above copyright
64 * notice, this list of conditions and the following disclaimer in the
65 * documentation and/or other materials provided with the distribution.
66 * 3. All advertising materials mentioning features or use of this software
67 * must display the following acknowledgement:
68 * This product includes software developed by the University of
69 * California, Berkeley and its contributors.
70 * 4. Neither the name of the University nor the names of its contributors
71 * may be used to endorse or promote products derived from this software
72 * without specific prior written permission.
73 *
74 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
75 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
80 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84 * SUCH DAMAGE.
85 *
86 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
87 */
88
89/*-
90 * Copyright (c) 2001 The NetBSD Foundation, Inc.
91 * All rights reserved.
92 *
93 * This code is derived from software contributed to The NetBSD Foundation
94 * by Jason R. Thorpe.
95 *
96 * Redistribution and use in source and binary forms, with or without
97 * modification, are permitted provided that the following conditions
98 * are met:
99 * 1. Redistributions of source code must retain the above copyright
100 * notice, this list of conditions and the following disclaimer.
101 * 2. Redistributions in binary form must reproduce the above copyright
102 * notice, this list of conditions and the following disclaimer in the
103 * documentation and/or other materials provided with the distribution.
104 * 3. All advertising materials mentioning features or use of this software
105 * must display the following acknowledgement:
106 * This product includes software developed by the NetBSD
107 * Foundation, Inc. and its contributors.
108 * 4. Neither the name of The NetBSD Foundation nor the names of its
109 * contributors may be used to endorse or promote products derived
110 * from this software without specific prior written permission.
111 *
112 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
113 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
114 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
115 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
116 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
117 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
118 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
119 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
120 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
121 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
122 * POSSIBILITY OF SUCH DAMAGE.
123 */
124
125/*
126 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
127 *
128 * Taken from NetBSD
129 *
130 * "Stub" to allow remote cpu to debug over a serial line using gdb.
131 */
132
133#include <sys/signal.h>
134#include <unistd.h>
135
136#include <string>
137
138#include "arch/arm/decoder.hh"
139#include "arch/arm/pagetable.hh"
140#include "arch/arm/registers.hh"
141#include "arch/arm/remote_gdb.hh"
142#include "arch/arm/system.hh"
143#include "arch/arm/utility.hh"
144#include "arch/arm/vtophys.hh"
1/*
2 * Copyright 2014 Google Inc.
3 * Copyright (c) 2010, 2013 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 * William Wang
43 */
44
45/*
46 * Copyright (c) 1990, 1993 The Regents of the University of California
47 * All rights reserved
48 *
49 * This software was developed by the Computer Systems Engineering group
50 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
51 * contributed to Berkeley.
52 *
53 * All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Lawrence Berkeley Laboratories.
57 *
58 * Redistribution and use in source and binary forms, with or without
59 * modification, are permitted provided that the following conditions
60 * are met:
61 * 1. Redistributions of source code must retain the above copyright
62 * notice, this list of conditions and the following disclaimer.
63 * 2. Redistributions in binary form must reproduce the above copyright
64 * notice, this list of conditions and the following disclaimer in the
65 * documentation and/or other materials provided with the distribution.
66 * 3. All advertising materials mentioning features or use of this software
67 * must display the following acknowledgement:
68 * This product includes software developed by the University of
69 * California, Berkeley and its contributors.
70 * 4. Neither the name of the University nor the names of its contributors
71 * may be used to endorse or promote products derived from this software
72 * without specific prior written permission.
73 *
74 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
75 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
80 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84 * SUCH DAMAGE.
85 *
86 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
87 */
88
89/*-
90 * Copyright (c) 2001 The NetBSD Foundation, Inc.
91 * All rights reserved.
92 *
93 * This code is derived from software contributed to The NetBSD Foundation
94 * by Jason R. Thorpe.
95 *
96 * Redistribution and use in source and binary forms, with or without
97 * modification, are permitted provided that the following conditions
98 * are met:
99 * 1. Redistributions of source code must retain the above copyright
100 * notice, this list of conditions and the following disclaimer.
101 * 2. Redistributions in binary form must reproduce the above copyright
102 * notice, this list of conditions and the following disclaimer in the
103 * documentation and/or other materials provided with the distribution.
104 * 3. All advertising materials mentioning features or use of this software
105 * must display the following acknowledgement:
106 * This product includes software developed by the NetBSD
107 * Foundation, Inc. and its contributors.
108 * 4. Neither the name of The NetBSD Foundation nor the names of its
109 * contributors may be used to endorse or promote products derived
110 * from this software without specific prior written permission.
111 *
112 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
113 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
114 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
115 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
116 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
117 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
118 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
119 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
120 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
121 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
122 * POSSIBILITY OF SUCH DAMAGE.
123 */
124
125/*
126 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
127 *
128 * Taken from NetBSD
129 *
130 * "Stub" to allow remote cpu to debug over a serial line using gdb.
131 */
132
133#include <sys/signal.h>
134#include <unistd.h>
135
136#include <string>
137
138#include "arch/arm/decoder.hh"
139#include "arch/arm/pagetable.hh"
140#include "arch/arm/registers.hh"
141#include "arch/arm/remote_gdb.hh"
142#include "arch/arm/system.hh"
143#include "arch/arm/utility.hh"
144#include "arch/arm/vtophys.hh"
145#include "base/chunk_generator.hh"
145#include "base/intmath.hh"
146#include "base/remote_gdb.hh"
147#include "base/socket.hh"
148#include "base/trace.hh"
149#include "cpu/static_inst.hh"
150#include "cpu/thread_context.hh"
151#include "cpu/thread_state.hh"
152#include "debug/GDBAcc.hh"
153#include "debug/GDBMisc.hh"
154#include "mem/page_table.hh"
155#include "mem/physical.hh"
156#include "mem/port.hh"
157#include "sim/full_system.hh"
158#include "sim/system.hh"
159
160using namespace std;
161using namespace ArmISA;
162
163RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
164 : BaseRemoteGDB(_system, tc, GDB_REG_BYTES)
165{
166}
167
168/*
169 * Determine if the mapping at va..(va+len) is valid.
170 */
171bool
172RemoteGDB::acc(Addr va, size_t len)
173{
174 if (FullSystem) {
146#include "base/intmath.hh"
147#include "base/remote_gdb.hh"
148#include "base/socket.hh"
149#include "base/trace.hh"
150#include "cpu/static_inst.hh"
151#include "cpu/thread_context.hh"
152#include "cpu/thread_state.hh"
153#include "debug/GDBAcc.hh"
154#include "debug/GDBMisc.hh"
155#include "mem/page_table.hh"
156#include "mem/physical.hh"
157#include "mem/port.hh"
158#include "sim/full_system.hh"
159#include "sim/system.hh"
160
161using namespace std;
162using namespace ArmISA;
163
164RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
165 : BaseRemoteGDB(_system, tc, GDB_REG_BYTES)
166{
167}
168
169/*
170 * Determine if the mapping at va..(va+len) is valid.
171 */
172bool
173RemoteGDB::acc(Addr va, size_t len)
174{
175 if (FullSystem) {
175 Addr last_va;
176 va = truncPage(va);
177 last_va = roundPage(va + len);
178
179 do {
180 if (virtvalid(context, va)) {
181 return true;
176 for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) {
177 if (!virtvalid(context, gen.addr())) {
178 DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va);
179 return false;
182 }
180 }
183 va += PageBytes;
184 } while (va < last_va);
181 }
185
186 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va);
187 return true;
188 } else {
189 TlbEntry entry;
190 //Check to make sure the first byte is mapped into the processes address
191 //space.
192 if (context->getProcessPtr()->pTable->lookup(va, entry))
193 return true;
194 return false;
195 }
196}
197
198/*
199 * Translate the kernel debugger register format into the GDB register
200 * format.
201 */
202void
203RemoteGDB::getregs()
204{
205 DPRINTF(GDBAcc, "getregs in remotegdb \n");
206
207 memset(gdbregs.regs, 0, gdbregs.bytes());
208
209 if (inAArch64(context)) { // AArch64
210 // x0-x31
211 for (int i = 0; i < 32; ++i)
212 gdbregs.regs64[GDB64_X0 + i] = context->readIntReg(INTREG_X0 + i);
213 // pc
214 gdbregs.regs64[GDB64_PC] = context->pcState().pc();
215 // cpsr
216 gdbregs.regs64[GDB64_CPSR] =
217 context->readMiscRegNoEffect(MISCREG_CPSR);
218 // v0-v31
219 for (int i = 0; i < 128; i += 4) {
220 int gdboff = GDB64_V0_32 + i;
221 gdbregs.regs32[gdboff + 0] = context->readFloatRegBits(i + 2);
222 gdbregs.regs32[gdboff + 1] = context->readFloatRegBits(i + 3);
223 gdbregs.regs32[gdboff + 2] = context->readFloatRegBits(i + 0);
224 gdbregs.regs32[gdboff + 3] = context->readFloatRegBits(i + 1);
225 }
226 } else { // AArch32
227 // R0-R15 supervisor mode
228 gdbregs.regs32[GDB32_R0 + 0] = context->readIntReg(INTREG_R0);
229 gdbregs.regs32[GDB32_R0 + 1] = context->readIntReg(INTREG_R1);
230 gdbregs.regs32[GDB32_R0 + 2] = context->readIntReg(INTREG_R2);
231 gdbregs.regs32[GDB32_R0 + 3] = context->readIntReg(INTREG_R3);
232 gdbregs.regs32[GDB32_R0 + 4] = context->readIntReg(INTREG_R4);
233 gdbregs.regs32[GDB32_R0 + 5] = context->readIntReg(INTREG_R5);
234 gdbregs.regs32[GDB32_R0 + 6] = context->readIntReg(INTREG_R6);
235 gdbregs.regs32[GDB32_R0 + 7] = context->readIntReg(INTREG_R7);
236 gdbregs.regs32[GDB32_R0 + 8] = context->readIntReg(INTREG_R8);
237 gdbregs.regs32[GDB32_R0 + 9] = context->readIntReg(INTREG_R9);
238 gdbregs.regs32[GDB32_R0 + 10] = context->readIntReg(INTREG_R10);
239 gdbregs.regs32[GDB32_R0 + 11] = context->readIntReg(INTREG_R11);
240 gdbregs.regs32[GDB32_R0 + 12] = context->readIntReg(INTREG_R12);
241 gdbregs.regs32[GDB32_R0 + 13] = context->readIntReg(INTREG_SP);
242 gdbregs.regs32[GDB32_R0 + 14] = context->readIntReg(INTREG_LR);
243 gdbregs.regs32[GDB32_R0 + 15] = context->pcState().pc();
244
245 // CPSR
246 gdbregs.regs32[GDB32_CPSR] = context->readMiscRegNoEffect(MISCREG_CPSR);
247
248 // vfpv3/neon floating point registers (32 double or 64 float)
249 for (int i = 0; i < NumFloatV7ArchRegs; ++i)
250 gdbregs.regs32[GDB32_F0 + i] = context->readFloatRegBits(i);
251
252 // FPSCR
253 gdbregs.regs32[GDB32_FPSCR] =
254 context->readMiscRegNoEffect(MISCREG_FPSCR);
255 }
256}
257
258/*
259 * Translate the GDB register format into the kernel debugger register
260 * format.
261 */
262void
263RemoteGDB::setregs()
264{
265
266 DPRINTF(GDBAcc, "setregs in remotegdb \n");
267 if (inAArch64(context)) { // AArch64
268 // x0-x31
269 for (int i = 0; i < 32; ++i)
270 context->setIntReg(INTREG_X0 + i, gdbregs.regs64[GDB64_X0 + i]);
271 // pc
272 context->pcState(gdbregs.regs64[GDB64_PC]);
273 // cpsr
274 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs64[GDB64_CPSR]);
275 // v0-v31
276 for (int i = 0; i < 128; i += 4) {
277 int gdboff = GDB64_V0_32 + i;
278 context->setFloatRegBits(i + 2, gdbregs.regs32[gdboff + 0]);
279 context->setFloatRegBits(i + 3, gdbregs.regs32[gdboff + 1]);
280 context->setFloatRegBits(i + 0, gdbregs.regs32[gdboff + 2]);
281 context->setFloatRegBits(i + 1, gdbregs.regs32[gdboff + 3]);
282 }
283 } else { // AArch32
284 // R0-R15 supervisor mode
285 // arm registers are 32 bits wide, gdb registers are 64 bits wide
286 // two arm registers are packed into one gdb register (little endian)
287 context->setIntReg(INTREG_R0, gdbregs.regs32[GDB32_R0 + 0]);
288 context->setIntReg(INTREG_R1, gdbregs.regs32[GDB32_R0 + 1]);
289 context->setIntReg(INTREG_R2, gdbregs.regs32[GDB32_R0 + 2]);
290 context->setIntReg(INTREG_R3, gdbregs.regs32[GDB32_R0 + 3]);
291 context->setIntReg(INTREG_R4, gdbregs.regs32[GDB32_R0 + 4]);
292 context->setIntReg(INTREG_R5, gdbregs.regs32[GDB32_R0 + 5]);
293 context->setIntReg(INTREG_R6, gdbregs.regs32[GDB32_R0 + 6]);
294 context->setIntReg(INTREG_R7, gdbregs.regs32[GDB32_R0 + 7]);
295 context->setIntReg(INTREG_R8, gdbregs.regs32[GDB32_R0 + 8]);
296 context->setIntReg(INTREG_R9, gdbregs.regs32[GDB32_R0 + 9]);
297 context->setIntReg(INTREG_R10, gdbregs.regs32[GDB32_R0 + 10]);
298 context->setIntReg(INTREG_R11, gdbregs.regs32[GDB32_R0 + 11]);
299 context->setIntReg(INTREG_R12, gdbregs.regs32[GDB32_R0 + 12]);
300 context->setIntReg(INTREG_SP, gdbregs.regs32[GDB32_R0 + 13]);
301 context->setIntReg(INTREG_LR, gdbregs.regs32[GDB32_R0 + 14]);
302 context->pcState(gdbregs.regs32[GDB32_R0 + 7]);
303
304 //CPSR
305 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs32[GDB32_CPSR]);
306
307 //vfpv3/neon floating point registers (32 double or 64 float)
308 for (int i = 0; i < NumFloatV7ArchRegs; ++i)
309 context->setFloatRegBits(i, gdbregs.regs32[GDB32_F0 + i]);
310
311 //FPSCR
312 context->setMiscReg(MISCREG_FPSCR, gdbregs.regs32[GDB32_FPSCR]);
313 }
314}
315
316// Write bytes to kernel address space for debugger.
317bool
318RemoteGDB::write(Addr vaddr, size_t size, const char *data)
319{
320 return BaseRemoteGDB::write(vaddr, size, data);
321}
322
182
183 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va);
184 return true;
185 } else {
186 TlbEntry entry;
187 //Check to make sure the first byte is mapped into the processes address
188 //space.
189 if (context->getProcessPtr()->pTable->lookup(va, entry))
190 return true;
191 return false;
192 }
193}
194
195/*
196 * Translate the kernel debugger register format into the GDB register
197 * format.
198 */
199void
200RemoteGDB::getregs()
201{
202 DPRINTF(GDBAcc, "getregs in remotegdb \n");
203
204 memset(gdbregs.regs, 0, gdbregs.bytes());
205
206 if (inAArch64(context)) { // AArch64
207 // x0-x31
208 for (int i = 0; i < 32; ++i)
209 gdbregs.regs64[GDB64_X0 + i] = context->readIntReg(INTREG_X0 + i);
210 // pc
211 gdbregs.regs64[GDB64_PC] = context->pcState().pc();
212 // cpsr
213 gdbregs.regs64[GDB64_CPSR] =
214 context->readMiscRegNoEffect(MISCREG_CPSR);
215 // v0-v31
216 for (int i = 0; i < 128; i += 4) {
217 int gdboff = GDB64_V0_32 + i;
218 gdbregs.regs32[gdboff + 0] = context->readFloatRegBits(i + 2);
219 gdbregs.regs32[gdboff + 1] = context->readFloatRegBits(i + 3);
220 gdbregs.regs32[gdboff + 2] = context->readFloatRegBits(i + 0);
221 gdbregs.regs32[gdboff + 3] = context->readFloatRegBits(i + 1);
222 }
223 } else { // AArch32
224 // R0-R15 supervisor mode
225 gdbregs.regs32[GDB32_R0 + 0] = context->readIntReg(INTREG_R0);
226 gdbregs.regs32[GDB32_R0 + 1] = context->readIntReg(INTREG_R1);
227 gdbregs.regs32[GDB32_R0 + 2] = context->readIntReg(INTREG_R2);
228 gdbregs.regs32[GDB32_R0 + 3] = context->readIntReg(INTREG_R3);
229 gdbregs.regs32[GDB32_R0 + 4] = context->readIntReg(INTREG_R4);
230 gdbregs.regs32[GDB32_R0 + 5] = context->readIntReg(INTREG_R5);
231 gdbregs.regs32[GDB32_R0 + 6] = context->readIntReg(INTREG_R6);
232 gdbregs.regs32[GDB32_R0 + 7] = context->readIntReg(INTREG_R7);
233 gdbregs.regs32[GDB32_R0 + 8] = context->readIntReg(INTREG_R8);
234 gdbregs.regs32[GDB32_R0 + 9] = context->readIntReg(INTREG_R9);
235 gdbregs.regs32[GDB32_R0 + 10] = context->readIntReg(INTREG_R10);
236 gdbregs.regs32[GDB32_R0 + 11] = context->readIntReg(INTREG_R11);
237 gdbregs.regs32[GDB32_R0 + 12] = context->readIntReg(INTREG_R12);
238 gdbregs.regs32[GDB32_R0 + 13] = context->readIntReg(INTREG_SP);
239 gdbregs.regs32[GDB32_R0 + 14] = context->readIntReg(INTREG_LR);
240 gdbregs.regs32[GDB32_R0 + 15] = context->pcState().pc();
241
242 // CPSR
243 gdbregs.regs32[GDB32_CPSR] = context->readMiscRegNoEffect(MISCREG_CPSR);
244
245 // vfpv3/neon floating point registers (32 double or 64 float)
246 for (int i = 0; i < NumFloatV7ArchRegs; ++i)
247 gdbregs.regs32[GDB32_F0 + i] = context->readFloatRegBits(i);
248
249 // FPSCR
250 gdbregs.regs32[GDB32_FPSCR] =
251 context->readMiscRegNoEffect(MISCREG_FPSCR);
252 }
253}
254
255/*
256 * Translate the GDB register format into the kernel debugger register
257 * format.
258 */
259void
260RemoteGDB::setregs()
261{
262
263 DPRINTF(GDBAcc, "setregs in remotegdb \n");
264 if (inAArch64(context)) { // AArch64
265 // x0-x31
266 for (int i = 0; i < 32; ++i)
267 context->setIntReg(INTREG_X0 + i, gdbregs.regs64[GDB64_X0 + i]);
268 // pc
269 context->pcState(gdbregs.regs64[GDB64_PC]);
270 // cpsr
271 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs64[GDB64_CPSR]);
272 // v0-v31
273 for (int i = 0; i < 128; i += 4) {
274 int gdboff = GDB64_V0_32 + i;
275 context->setFloatRegBits(i + 2, gdbregs.regs32[gdboff + 0]);
276 context->setFloatRegBits(i + 3, gdbregs.regs32[gdboff + 1]);
277 context->setFloatRegBits(i + 0, gdbregs.regs32[gdboff + 2]);
278 context->setFloatRegBits(i + 1, gdbregs.regs32[gdboff + 3]);
279 }
280 } else { // AArch32
281 // R0-R15 supervisor mode
282 // arm registers are 32 bits wide, gdb registers are 64 bits wide
283 // two arm registers are packed into one gdb register (little endian)
284 context->setIntReg(INTREG_R0, gdbregs.regs32[GDB32_R0 + 0]);
285 context->setIntReg(INTREG_R1, gdbregs.regs32[GDB32_R0 + 1]);
286 context->setIntReg(INTREG_R2, gdbregs.regs32[GDB32_R0 + 2]);
287 context->setIntReg(INTREG_R3, gdbregs.regs32[GDB32_R0 + 3]);
288 context->setIntReg(INTREG_R4, gdbregs.regs32[GDB32_R0 + 4]);
289 context->setIntReg(INTREG_R5, gdbregs.regs32[GDB32_R0 + 5]);
290 context->setIntReg(INTREG_R6, gdbregs.regs32[GDB32_R0 + 6]);
291 context->setIntReg(INTREG_R7, gdbregs.regs32[GDB32_R0 + 7]);
292 context->setIntReg(INTREG_R8, gdbregs.regs32[GDB32_R0 + 8]);
293 context->setIntReg(INTREG_R9, gdbregs.regs32[GDB32_R0 + 9]);
294 context->setIntReg(INTREG_R10, gdbregs.regs32[GDB32_R0 + 10]);
295 context->setIntReg(INTREG_R11, gdbregs.regs32[GDB32_R0 + 11]);
296 context->setIntReg(INTREG_R12, gdbregs.regs32[GDB32_R0 + 12]);
297 context->setIntReg(INTREG_SP, gdbregs.regs32[GDB32_R0 + 13]);
298 context->setIntReg(INTREG_LR, gdbregs.regs32[GDB32_R0 + 14]);
299 context->pcState(gdbregs.regs32[GDB32_R0 + 7]);
300
301 //CPSR
302 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs32[GDB32_CPSR]);
303
304 //vfpv3/neon floating point registers (32 double or 64 float)
305 for (int i = 0; i < NumFloatV7ArchRegs; ++i)
306 context->setFloatRegBits(i, gdbregs.regs32[GDB32_F0 + i]);
307
308 //FPSCR
309 context->setMiscReg(MISCREG_FPSCR, gdbregs.regs32[GDB32_FPSCR]);
310 }
311}
312
313// Write bytes to kernel address space for debugger.
314bool
315RemoteGDB::write(Addr vaddr, size_t size, const char *data)
316{
317 return BaseRemoteGDB::write(vaddr, size, data);
318}
319