gem5 v24.0.0.0
Loading...
Searching...
No Matches
remote_gdb.cc
Go to the documentation of this file.
1/*
2 * Copyright 2015 LabWare
3 * Copyright 2014 Google Inc.
4 * Copyright (c) 2010, 2013, 2016, 2018-2019 ARM Limited
5 * All rights reserved
6 *
7 * The license below extends only to copyright in the software and shall
8 * not be construed as granting a license to any other intellectual
9 * property including but not limited to intellectual property relating
10 * to a hardware implementation of the functionality of the software
11 * licensed hereunder. You may use the software subject to the license
12 * terms below provided that you ensure that this notice is replicated
13 * unmodified and in its entirety in all distributions of the software,
14 * modified or unmodified, in source code or in binary form.
15 *
16 * Copyright (c) 2002-2005 The Regents of The University of Michigan
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42
43/*
44 * Copyright (c) 1990, 1993 The Regents of the University of California
45 * All rights reserved
46 *
47 * This software was developed by the Computer Systems Engineering group
48 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
49 * contributed to Berkeley.
50 *
51 * All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Lawrence Berkeley Laboratories.
55 *
56 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
58 * are met:
59 * 1. Redistributions of source code must retain the above copyright
60 * notice, this list of conditions and the following disclaimer.
61 * 2. Redistributions in binary form must reproduce the above copyright
62 * notice, this list of conditions and the following disclaimer in the
63 * documentation and/or other materials provided with the distribution.
64 * 3. All advertising materials mentioning features or use of this software
65 * must display the following acknowledgement:
66 * This product includes software developed by the University of
67 * California, Berkeley and its contributors.
68 * 4. Neither the name of the University nor the names of its contributors
69 * may be used to endorse or promote products derived from this software
70 * without specific prior written permission.
71 *
72 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
73 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
76 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
77 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
78 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
80 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
81 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
82 * SUCH DAMAGE.
83 *
84 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
85 */
86
87/*-
88 * Copyright (c) 2001 The NetBSD Foundation, Inc.
89 * All rights reserved.
90 *
91 * This code is derived from software contributed to The NetBSD Foundation
92 * by Jason R. Thorpe.
93 *
94 * Redistribution and use in source and binary forms, with or without
95 * modification, are permitted provided that the following conditions
96 * are met:
97 * 1. Redistributions of source code must retain the above copyright
98 * notice, this list of conditions and the following disclaimer.
99 * 2. Redistributions in binary form must reproduce the above copyright
100 * notice, this list of conditions and the following disclaimer in the
101 * documentation and/or other materials provided with the distribution.
102 * 3. All advertising materials mentioning features or use of this software
103 * must display the following acknowledgement:
104 * This product includes software developed by the NetBSD
105 * Foundation, Inc. and its contributors.
106 * 4. Neither the name of The NetBSD Foundation nor the names of its
107 * contributors may be used to endorse or promote products derived
108 * from this software without specific prior written permission.
109 *
110 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
111 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
112 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
113 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
114 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
115 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
116 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
117 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
118 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
119 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
120 * POSSIBILITY OF SUCH DAMAGE.
121 */
122
123/*
124 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
125 *
126 * Taken from NetBSD
127 *
128 * "Stub" to allow remote cpu to debug over a serial line using gdb.
129 */
130
131#include "arch/arm/remote_gdb.hh"
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/gdb-xml/gdb_xml_aarch64_core.hh"
140#include "arch/arm/gdb-xml/gdb_xml_aarch64_fpu.hh"
141#include "arch/arm/gdb-xml/gdb_xml_aarch64_target.hh"
142#include "arch/arm/gdb-xml/gdb_xml_arm_core.hh"
143#include "arch/arm/gdb-xml/gdb_xml_arm_target.hh"
144#include "arch/arm/gdb-xml/gdb_xml_arm_vfpv3.hh"
145#include "arch/arm/pagetable.hh"
146#include "arch/arm/regs/vec.hh"
147#include "arch/arm/system.hh"
148#include "arch/arm/utility.hh"
149#include "arch/generic/mmu.hh"
151#include "base/intmath.hh"
152#include "base/remote_gdb.hh"
153#include "base/socket.hh"
154#include "base/trace.hh"
155#include "cpu/static_inst.hh"
156#include "cpu/thread_context.hh"
157#include "cpu/thread_state.hh"
158#include "debug/GDBAcc.hh"
159#include "debug/GDBMisc.hh"
160#include "mem/page_table.hh"
161#include "mem/physical.hh"
162#include "mem/port.hh"
163#include "sim/full_system.hh"
164#include "sim/system.hh"
165
166namespace gem5
167{
168
169using namespace ArmISA;
170
171namespace
172{
173
174// https://sourceware.org/gdb/current/onlinedocs/gdb/ARM-Breakpoint-Kinds.html
175enum class ArmBpKind
176{
177 THUMB = 2,
178 THUMB_2 = 3,
179 ARM = 4,
180};
181
182} // namespace
183
184
185static bool
187{
188 // Set up a functional memory Request to pass to the TLB
189 // to get it to translate the vaddr to a paddr
190 auto req = std::make_shared<Request>(addr, 64, 0x40, -1, 0, 0);
191
192 // Check the TLBs for a translation
193 // It's possible that there is a valid translation in the tlb
194 // that is no loger valid in the page table in memory
195 // so we need to check here first
196 //
197 // Calling translateFunctional invokes a table-walk if required
198 // so we should always succeed
199 auto *mmu = tc->getMMUPtr();
200 return mmu->translateFunctional(req, tc, BaseMMU::Read) == NoFault ||
201 mmu->translateFunctional(req, tc, BaseMMU::Execute) == NoFault;
202}
203
205 : BaseRemoteGDB(_system, _listen_config),
206 regCache32(this), regCache64(this)
207{
208}
209
210/*
211 * Determine if the mapping at va..(va+len) is valid.
212 */
213bool
215{
216 if (FullSystem) {
217 for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) {
218 if (!tryTranslate(context(), gen.addr())) {
219 DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va);
220 return false;
221 }
222 }
223
224 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va);
225 return true;
226 } else {
227 // Check to make sure the first byte is mapped into the processes
228 // address space.
229 return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
230 }
231}
232
233void
235{
236 DPRINTF(GDBAcc, "getRegs in remotegdb \n");
237
238 for (int i = 0; i < 31; ++i)
239 r.x[i] = context->getReg(int_reg::x(i));
241 r.pc = context->pcState().instAddr();
243
244 size_t base = 0;
245 for (int i = 0; i < NumVecV8ArchRegs; i++) {
247 context->getReg(vecRegClass[i], &vc);
248 auto v = vc.as<VecElem>();
249 for (size_t j = 0; j < NumVecElemPerNeonVecReg; j++) {
250 r.v[base] = v[j];
251 base++;
252 }
253 }
256}
257
258void
260{
261 DPRINTF(GDBAcc, "setRegs in remotegdb \n");
262
263 for (int i = 0; i < 31; ++i)
264 context->setReg(int_reg::x(i), r.x[i]);
265 auto pc_state = context->pcState().as<PCState>();
266 pc_state.set(r.pc);
267 context->pcState(pc_state);
269 // Update the stack pointer. This should be done after
270 // updating CPSR/PSTATE since that might affect how SPX gets
271 // mapped.
273
274 size_t base = 0;
275 for (int i = 0; i < NumVecV8ArchRegs; i++) {
276 auto *vc = static_cast<ArmISA::VecRegContainer *>(
278 auto v = vc->as<VecElem>();
279 for (size_t j = 0; j < NumVecElemPerNeonVecReg; j++) {
280 v[j] = r.v[base];
281 base++;
282 }
283 }
286}
287
288void
290{
291 DPRINTF(GDBAcc, "getRegs in remotegdb \n");
292
293 r.gpr[0] = context->getReg(int_reg::R0);
294 r.gpr[1] = context->getReg(int_reg::R1);
295 r.gpr[2] = context->getReg(int_reg::R2);
296 r.gpr[3] = context->getReg(int_reg::R3);
297 r.gpr[4] = context->getReg(int_reg::R4);
298 r.gpr[5] = context->getReg(int_reg::R5);
299 r.gpr[6] = context->getReg(int_reg::R6);
300 r.gpr[7] = context->getReg(int_reg::R7);
301 r.gpr[8] = context->getReg(int_reg::R8);
302 r.gpr[9] = context->getReg(int_reg::R9);
303 r.gpr[10] = context->getReg(int_reg::R10);
304 r.gpr[11] = context->getReg(int_reg::R11);
305 r.gpr[12] = context->getReg(int_reg::R12);
306 r.gpr[13] = context->getReg(int_reg::Sp);
307 r.gpr[14] = context->getReg(int_reg::Lr);
308 r.gpr[15] = context->pcState().instAddr();
310
311 // One day somebody will implement transfer of FPRs correctly.
312 for (int i = 0; i < 32; i++)
313 r.fpr[i] = 0;
314
316}
317
318void
320{
321 DPRINTF(GDBAcc, "setRegs in remotegdb \n");
322
323 context->setReg(int_reg::R0, r.gpr[0]);
324 context->setReg(int_reg::R1, r.gpr[1]);
325 context->setReg(int_reg::R2, r.gpr[2]);
326 context->setReg(int_reg::R3, r.gpr[3]);
327 context->setReg(int_reg::R4, r.gpr[4]);
328 context->setReg(int_reg::R5, r.gpr[5]);
329 context->setReg(int_reg::R6, r.gpr[6]);
330 context->setReg(int_reg::R7, r.gpr[7]);
331 context->setReg(int_reg::R8, r.gpr[8]);
332 context->setReg(int_reg::R9, r.gpr[9]);
333 context->setReg(int_reg::R10, r.gpr[10]);
334 context->setReg(int_reg::R11, r.gpr[11]);
335 context->setReg(int_reg::R12, r.gpr[12]);
336 context->setReg(int_reg::Sp, r.gpr[13]);
337 context->setReg(int_reg::Lr, r.gpr[14]);
338 PCState pc_state = context->pcState().as<PCState>();
339 pc_state.set(r.gpr[15]);
340 context->pcState(pc_state);
341
342 // One day somebody will implement transfer of FPRs correctly.
343
346}
347
348bool
349RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
350{
351#define GDB_XML(x, s) \
352 { x, std::string(reinterpret_cast<const char *>(Blobs::s), \
353 Blobs::s ## _len) }
354 static const std::map<std::string, std::string> annexMap32{
355 GDB_XML("target.xml", gdb_xml_arm_target),
356 GDB_XML("arm-core.xml", gdb_xml_arm_core),
357 GDB_XML("arm-vfpv3.xml", gdb_xml_arm_vfpv3),
358 };
359 static const std::map<std::string, std::string> annexMap64{
360 GDB_XML("target.xml", gdb_xml_aarch64_target),
361 GDB_XML("aarch64-core.xml", gdb_xml_aarch64_core),
362 GDB_XML("aarch64-fpu.xml", gdb_xml_aarch64_fpu),
363 };
364#undef GDB_XML
365 auto& annexMap = inAArch64(context()) ? annexMap64 : annexMap32;
366 auto it = annexMap.find(annex);
367 if (it == annexMap.end())
368 return false;
369 output = it->second;
370 return true;
371}
372
375{
376 if (inAArch64(context()))
377 return &regCache64;
378 else
379 return &regCache32;
380}
381
382bool
384{
385 switch (ArmBpKind(kind)) {
386 case ArmBpKind::THUMB:
387 case ArmBpKind::THUMB_2:
388 case ArmBpKind::ARM:
389 return true;
390 default:
391 return false;
392 }
393}
394
395} // namespace gem5
#define GDB_XML(x, s)
#define DPRINTF(x,...)
Definition trace.hh:210
Declaration and inline definition of ChunkGenerator object.
void setRegs(ThreadContext *) const override
Set the ThreadContext's registers from the values in the raw buffer.
void getRegs(ThreadContext *) override
Fill the raw buffer from the registers in the ThreadContext.
void setRegs(ThreadContext *) const override
Set the ThreadContext's registers from the values in the raw buffer.
struct gem5::ArmISA::RemoteGDB::AArch64GdbRegCache::GEM5_PACKED r
void getRegs(ThreadContext *) override
Fill the raw buffer from the registers in the ThreadContext.
bool checkBpKind(size_t kind) override
bool acc(Addr addr, size_t len) override
BaseGdbRegCache * gdbRegs() override
bool getXferFeaturesRead(const std::string &annex, std::string &output) override
Get an XML target description.
AArch64GdbRegCache regCache64
AArch32GdbRegCache regCache32
RemoteGDB(System *_system, ListenSocketConfig _listen_config)
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition remote_gdb.hh:86
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:118
ThreadContext * context()
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
const Entry * lookup(Addr vaddr)
Lookup function.
void set(Addr val) override
Force this PC to reflect a particular value, resetting all its other fields around it.
Definition pcstate.hh:378
Target & as()
Definition pcstate.hh:73
Addr instAddr() const
Returns the memory address of the instruction this PC points to.
Definition pcstate.hh:108
EmulationPageTable * pTable
Definition process.hh:184
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
virtual RegVal getReg(const RegId &reg) const
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual void setReg(const RegId &reg, RegVal val)
virtual void * getWritableReg(const RegId &reg)=0
virtual const PCStateBase & pcState() const =0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
virtual BaseMMU * getMMUPtr()=0
virtual Process * getProcessPtr()=0
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
Definition vec_reg.hh:126
VecElem * as()
View interposers.
Definition vec_reg.hh:191
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
Port Object Declaration.
constexpr RegId R4
Definition int.hh:190
constexpr RegId R9
Definition int.hh:195
constexpr RegId R6
Definition int.hh:192
constexpr auto & Sp
Definition int.hh:274
constexpr RegId R12
Definition int.hh:198
constexpr RegId R7
Definition int.hh:193
static RegId x(unsigned index)
Definition int.hh:445
constexpr RegId R3
Definition int.hh:189
constexpr RegId R8
Definition int.hh:194
constexpr RegId Spx
Definition int.hh:238
constexpr RegId R11
Definition int.hh:197
constexpr RegId R5
Definition int.hh:191
constexpr auto & Lr
Definition int.hh:275
constexpr RegId R10
Definition int.hh:196
constexpr RegId R2
Definition int.hh:188
constexpr RegId R1
Definition int.hh:187
constexpr RegId R0
Definition int.hh:186
Bitfield< 28 > v
Definition misc_types.hh:54
const int NumVecV8ArchRegs
Definition vec.hh:80
Bitfield< 18, 16 > len
Bitfield< 7 > i
Definition misc_types.hh:67
constexpr unsigned NumVecElemPerNeonVecReg
Definition vec.hh:59
@ MISCREG_FPSR
Definition misc.hh:636
@ MISCREG_CPSR
Definition misc.hh:67
@ MISCREG_FPCR
Definition misc.hh:635
@ MISCREG_FPSCR
Definition misc.hh:78
const Addr PageBytes
Definition page_size.hh:53
uint32_t VecElem
Definition vec.hh:63
bool inAArch64(ThreadContext *tc)
Definition utility.cc:126
constexpr RegClass vecRegClass
Definition vec.hh:101
Bitfield< 8 > va
Bitfield< 51, 12 > base
Definition pagetable.hh:141
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition root.cc:220
static void output(const char *filename)
Definition debug.cc:60
constexpr decltype(nullptr) NoFault
Definition types.hh:253
static bool tryTranslate(ThreadContext *tc, Addr addr)
Declarations of a non-full system Page Table.
VecElem v[NumVecV8ArchRegs *NumVecElemPerNeonVecReg]

Generated on Tue Jun 18 2024 16:23:59 for gem5 by doxygen 1.11.0