gem5  v22.1.0.0
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"
150 #include "base/chunk_generator.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 
166 namespace gem5
167 {
168 
169 using namespace ArmISA;
170 
171 namespace
172 {
173 
174 // https://sourceware.org/gdb/current/onlinedocs/gdb/ARM-Breakpoint-Kinds.html
175 enum class ArmBpKind
176 {
177  THUMB = 2,
178  THUMB_2 = 3,
179  ARM = 4,
180 };
181 
182 } // namespace
183 
184 
185 static 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 
204 RemoteGDB::RemoteGDB(System *_system, int _port)
205  : BaseRemoteGDB(_system, _port), regCache32(this), regCache64(this)
206 {
207 }
208 
209 /*
210  * Determine if the mapping at va..(va+len) is valid.
211  */
212 bool
214 {
215  if (FullSystem) {
216  for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) {
217  if (!tryTranslate(context(), gen.addr())) {
218  DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va);
219  return false;
220  }
221  }
222 
223  DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va);
224  return true;
225  } else {
226  // Check to make sure the first byte is mapped into the processes
227  // address space.
228  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
229  }
230 }
231 
232 void
234 {
235  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
236 
237  for (int i = 0; i < 31; ++i)
238  r.x[i] = context->getReg(int_reg::x(i));
240  r.pc = context->pcState().instAddr();
242 
243  size_t base = 0;
244  for (int i = 0; i < NumVecV8ArchRegs; i++) {
246  context->getReg(vecRegClass[i], &vc);
247  auto v = vc.as<VecElem>();
248  for (size_t j = 0; j < NumVecElemPerNeonVecReg; j++) {
249  r.v[base] = v[j];
250  base++;
251  }
252  }
255 }
256 
257 void
259 {
260  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
261 
262  for (int i = 0; i < 31; ++i)
263  context->setReg(int_reg::x(i), r.x[i]);
264  auto pc_state = context->pcState().as<PCState>();
265  pc_state.set(r.pc);
266  context->pcState(pc_state);
268  // Update the stack pointer. This should be done after
269  // updating CPSR/PSTATE since that might affect how SPX gets
270  // mapped.
271  context->setReg(int_reg::Spx, r.spx);
272 
273  size_t base = 0;
274  for (int i = 0; i < NumVecV8ArchRegs; i++) {
275  auto *vc = static_cast<ArmISA::VecRegContainer *>(
277  auto v = vc->as<VecElem>();
278  for (size_t j = 0; j < NumVecElemPerNeonVecReg; j++) {
279  v[j] = r.v[base];
280  base++;
281  }
282  }
285 }
286 
287 void
289 {
290  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
291 
292  r.gpr[0] = context->getReg(int_reg::R0);
293  r.gpr[1] = context->getReg(int_reg::R1);
294  r.gpr[2] = context->getReg(int_reg::R2);
295  r.gpr[3] = context->getReg(int_reg::R3);
296  r.gpr[4] = context->getReg(int_reg::R4);
297  r.gpr[5] = context->getReg(int_reg::R5);
298  r.gpr[6] = context->getReg(int_reg::R6);
299  r.gpr[7] = context->getReg(int_reg::R7);
300  r.gpr[8] = context->getReg(int_reg::R8);
301  r.gpr[9] = context->getReg(int_reg::R9);
302  r.gpr[10] = context->getReg(int_reg::R10);
303  r.gpr[11] = context->getReg(int_reg::R11);
304  r.gpr[12] = context->getReg(int_reg::R12);
305  r.gpr[13] = context->getReg(int_reg::Sp);
306  r.gpr[14] = context->getReg(int_reg::Lr);
307  r.gpr[15] = context->pcState().instAddr();
309 
310  // One day somebody will implement transfer of FPRs correctly.
311  for (int i = 0; i < 32; i++)
312  r.fpr[i] = 0;
313 
315 }
316 
317 void
319 {
320  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
321 
322  context->setReg(int_reg::R0, r.gpr[0]);
323  context->setReg(int_reg::R1, r.gpr[1]);
324  context->setReg(int_reg::R2, r.gpr[2]);
325  context->setReg(int_reg::R3, r.gpr[3]);
326  context->setReg(int_reg::R4, r.gpr[4]);
327  context->setReg(int_reg::R5, r.gpr[5]);
328  context->setReg(int_reg::R6, r.gpr[6]);
329  context->setReg(int_reg::R7, r.gpr[7]);
330  context->setReg(int_reg::R8, r.gpr[8]);
331  context->setReg(int_reg::R9, r.gpr[9]);
332  context->setReg(int_reg::R10, r.gpr[10]);
333  context->setReg(int_reg::R11, r.gpr[11]);
334  context->setReg(int_reg::R12, r.gpr[12]);
335  context->setReg(int_reg::Sp, r.gpr[13]);
336  context->setReg(int_reg::Lr, r.gpr[14]);
337  PCState pc_state = context->pcState().as<PCState>();
338  pc_state.set(r.gpr[15]);
339  context->pcState(pc_state);
340 
341  // One day somebody will implement transfer of FPRs correctly.
342 
345 }
346 
347 bool
348 RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
349 {
350 #define GDB_XML(x, s) \
351  { x, std::string(reinterpret_cast<const char *>(Blobs::s), \
352  Blobs::s ## _len) }
353  static const std::map<std::string, std::string> annexMap32{
354  GDB_XML("target.xml", gdb_xml_arm_target),
355  GDB_XML("arm-core.xml", gdb_xml_arm_core),
356  GDB_XML("arm-vfpv3.xml", gdb_xml_arm_vfpv3),
357  };
358  static const std::map<std::string, std::string> annexMap64{
359  GDB_XML("target.xml", gdb_xml_aarch64_target),
360  GDB_XML("aarch64-core.xml", gdb_xml_aarch64_core),
361  GDB_XML("aarch64-fpu.xml", gdb_xml_aarch64_fpu),
362  };
363 #undef GDB_XML
364  auto& annexMap = inAArch64(context()) ? annexMap64 : annexMap32;
365  auto it = annexMap.find(annex);
366  if (it == annexMap.end())
367  return false;
368  output = it->second;
369  return true;
370 }
371 
374 {
375  if (inAArch64(context()))
376  return &regCache64;
377  else
378  return &regCache32;
379 }
380 
381 bool
383 {
384  switch (ArmBpKind(kind)) {
385  case ArmBpKind::THUMB:
386  case ArmBpKind::THUMB_2:
387  case ArmBpKind::ARM:
388  return true;
389  default:
390  return false;
391  }
392 }
393 
394 } // namespace gem5
#define GDB_XML(x, s)
#define DPRINTF(x,...)
Definition: trace.hh:186
Declaration and inline definition of ChunkGenerator object.
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:318
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:288
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:258
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:233
struct gem5::ArmISA::RemoteGDB::AArch64GdbRegCache::GEM5_PACKED r
bool checkBpKind(size_t kind) override
Definition: remote_gdb.cc:382
RemoteGDB(System *_system, int _port)
Definition: remote_gdb.cc:204
bool acc(Addr addr, size_t len) override
Definition: remote_gdb.cc:213
BaseGdbRegCache * gdbRegs() override
Definition: remote_gdb.cc:373
bool getXferFeaturesRead(const std::string &annex, std::string &output) override
Get an XML target description.
Definition: remote_gdb.cc:348
AArch64GdbRegCache regCache64
Definition: remote_gdb.hh:118
AArch32GdbRegCache regCache32
Definition: remote_gdb.hh:117
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
@ Execute
Definition: mmu.hh:56
ThreadContext * context()
Definition: remote_gdb.hh:442
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:133
void set(Addr val)
Force this PC to reflect a particular value, resetting all its other fields around it.
Definition: pcstate.hh:362
Addr instAddr() const
Returns the memory address of the instruction this PC points to.
Definition: pcstate.hh:107
Target & as()
Definition: pcstate.hh:72
EmulationPageTable * pTable
Definition: process.hh:185
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void * getWritableReg(const RegId &reg)=0
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 const PCStateBase & pcState() const =0
virtual void setReg(const RegId &reg, RegVal val)
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
virtual Process * getProcessPtr()=0
virtual BaseMMU * getMMUPtr()=0
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
Definition: vec_reg.hh:124
VecElem * as()
View interposers.
Definition: vec_reg.hh:189
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< 7 > i
Definition: misc_types.hh:67
constexpr unsigned NumVecElemPerNeonVecReg
Definition: vec.hh:59
@ MISCREG_FPSR
Definition: misc.hh:627
@ MISCREG_CPSR
Definition: misc.hh:65
@ MISCREG_FPCR
Definition: misc.hh:626
@ MISCREG_FPSCR
Definition: misc.hh:76
Bitfield< 18, 16 > len
Definition: misc_types.hh:451
const Addr PageBytes
Definition: page_size.hh:53
bool inAArch64(ThreadContext *tc)
Definition: utility.cc:117
Bitfield< 24 > j
Definition: misc_types.hh:57
constexpr RegClass vecRegClass
Definition: vec.hh:101
Bitfield< 8 > va
Definition: misc_types.hh:282
uint32_t VecElem
Definition: vec.hh:63
Bitfield< 5 > r
Definition: pagetable.hh:60
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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)
Definition: remote_gdb.cc:186
Declarations of a non-full system Page Table.
VecElem v[NumVecV8ArchRegs *NumVecElemPerNeonVecReg]
Definition: remote_gdb.hh:101

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1