2 * Copyright 2014 Google Inc.
3 * Copyright (c) 2010, 2013 ARM Limited
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.
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
41 * Authors: Nathan Binkert
46 * Copyright (c) 1990, 1993 The Regents of the University of California
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.
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.
58 * Redistribution and use in source and binary forms, with or without
59 * modification, are permitted provided that the following conditions
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.
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
86 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
90 * Copyright (c) 2001 The NetBSD Foundation, Inc.
91 * All rights reserved.
93 * This code is derived from software contributed to The NetBSD Foundation
96 * Redistribution and use in source and binary forms, with or without
97 * modification, are permitted provided that the following conditions
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.
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.
126 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
130 * "Stub" to allow remote cpu to debug over a serial line using gdb.
133 #include <sys/signal.h>
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"
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"
162 using namespace ArmISA
;
164 RemoteGDB::RemoteGDB(System
*_system
, ThreadContext
*tc
)
165 : BaseRemoteGDB(_system
, tc
, GDB_REG_BYTES
)
170 * Determine if the mapping at va..(va+len) is valid.
173 RemoteGDB::acc(Addr va
, size_t len
)
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
);
183 DPRINTF(GDBAcc
, "acc: %#x mapping is valid\n", va
);
187 //Check to make sure the first byte is mapped into the processes address
189 if (context
->getProcessPtr()->pTable
->lookup(va
, entry
))
196 * Translate the kernel debugger register format into the GDB register
202 DPRINTF(GDBAcc
, "getregs in remotegdb \n");
204 memset(gdbregs
.regs
, 0, gdbregs
.bytes());
206 if (inAArch64(context
)) { // AArch64
208 for (int i
= 0; i
< 32; ++i
)
209 gdbregs
.regs64
[GDB64_X0
+ i
] = context
->readIntReg(INTREG_X0
+ i
);
211 gdbregs
.regs64
[GDB64_PC
] = context
->pcState().pc();
213 gdbregs
.regs64
[GDB64_CPSR
] =
214 context
->readMiscRegNoEffect(MISCREG_CPSR
);
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);
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();
243 gdbregs
.regs32
[GDB32_CPSR
] = context
->readMiscRegNoEffect(MISCREG_CPSR
);
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
);
250 gdbregs
.regs32
[GDB32_FPSCR
] =
251 context
->readMiscRegNoEffect(MISCREG_FPSCR
);
256 * Translate the GDB register format into the kernel debugger register
263 DPRINTF(GDBAcc
, "setregs in remotegdb \n");
264 if (inAArch64(context
)) { // AArch64
266 for (int i
= 0; i
< 32; ++i
)
267 context
->setIntReg(INTREG_X0
+ i
, gdbregs
.regs64
[GDB64_X0
+ i
]);
269 context
->pcState(gdbregs
.regs64
[GDB64_PC
]);
271 context
->setMiscRegNoEffect(MISCREG_CPSR
, gdbregs
.regs64
[GDB64_CPSR
]);
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]);
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]);
302 context
->setMiscRegNoEffect(MISCREG_CPSR
, gdbregs
.regs32
[GDB32_CPSR
]);
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
]);
309 context
->setMiscReg(MISCREG_FPSCR
, gdbregs
.regs32
[GDB32_FPSCR
]);
313 // Write bytes to kernel address space for debugger.
315 RemoteGDB::write(Addr vaddr
, size_t size
, const char *data
)
317 return BaseRemoteGDB::write(vaddr
, size
, data
);