gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 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  * Authors: Nathan Binkert
43  * William Wang
44  * Boris Shingarov
45  */
46 
47 /*
48  * Copyright (c) 1990, 1993 The Regents of the University of California
49  * All rights reserved
50  *
51  * This software was developed by the Computer Systems Engineering group
52  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
53  * contributed to Berkeley.
54  *
55  * All advertising materials mentioning features or use of this software
56  * must display the following acknowledgement:
57  * This product includes software developed by the University of
58  * California, Lawrence Berkeley Laboratories.
59  *
60  * Redistribution and use in source and binary forms, with or without
61  * modification, are permitted provided that the following conditions
62  * are met:
63  * 1. Redistributions of source code must retain the above copyright
64  * notice, this list of conditions and the following disclaimer.
65  * 2. Redistributions in binary form must reproduce the above copyright
66  * notice, this list of conditions and the following disclaimer in the
67  * documentation and/or other materials provided with the distribution.
68  * 3. All advertising materials mentioning features or use of this software
69  * must display the following acknowledgement:
70  * This product includes software developed by the University of
71  * California, Berkeley and its contributors.
72  * 4. Neither the name of the University nor the names of its contributors
73  * may be used to endorse or promote products derived from this software
74  * without specific prior written permission.
75  *
76  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
77  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
80  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
86  * SUCH DAMAGE.
87  *
88  * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
89  */
90 
91 /*-
92  * Copyright (c) 2001 The NetBSD Foundation, Inc.
93  * All rights reserved.
94  *
95  * This code is derived from software contributed to The NetBSD Foundation
96  * by Jason R. Thorpe.
97  *
98  * Redistribution and use in source and binary forms, with or without
99  * modification, are permitted provided that the following conditions
100  * are met:
101  * 1. Redistributions of source code must retain the above copyright
102  * notice, this list of conditions and the following disclaimer.
103  * 2. Redistributions in binary form must reproduce the above copyright
104  * notice, this list of conditions and the following disclaimer in the
105  * documentation and/or other materials provided with the distribution.
106  * 3. All advertising materials mentioning features or use of this software
107  * must display the following acknowledgement:
108  * This product includes software developed by the NetBSD
109  * Foundation, Inc. and its contributors.
110  * 4. Neither the name of The NetBSD Foundation nor the names of its
111  * contributors may be used to endorse or promote products derived
112  * from this software without specific prior written permission.
113  *
114  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
115  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
116  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
117  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
118  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
119  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
120  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
121  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
122  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
123  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
124  * POSSIBILITY OF SUCH DAMAGE.
125  */
126 
127 /*
128  * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
129  *
130  * Taken from NetBSD
131  *
132  * "Stub" to allow remote cpu to debug over a serial line using gdb.
133  */
134 
135 #include "arch/arm/remote_gdb.hh"
136 
137 #include <sys/signal.h>
138 #include <unistd.h>
139 
140 #include <string>
141 
142 #include "arch/arm/decoder.hh"
143 #include "arch/arm/pagetable.hh"
144 #include "arch/arm/registers.hh"
145 #include "arch/arm/system.hh"
146 #include "arch/arm/utility.hh"
147 #include "arch/arm/vtophys.hh"
148 #include "base/chunk_generator.hh"
149 #include "base/intmath.hh"
150 #include "base/remote_gdb.hh"
151 #include "base/socket.hh"
152 #include "base/trace.hh"
153 #include "cpu/static_inst.hh"
154 #include "cpu/thread_context.hh"
155 #include "cpu/thread_state.hh"
156 #include "debug/GDBAcc.hh"
157 #include "debug/GDBMisc.hh"
158 #include "mem/page_table.hh"
159 #include "mem/physical.hh"
160 #include "mem/port.hh"
161 #include "sim/full_system.hh"
162 #include "sim/system.hh"
163 
164 using namespace std;
165 using namespace ArmISA;
166 
167 RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
168  : BaseRemoteGDB(_system, tc), regCache32(this), regCache64(this)
169 {
170 }
171 
172 /*
173  * Determine if the mapping at va..(va+len) is valid.
174  */
175 bool
177 {
178  if (FullSystem) {
179  for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) {
180  if (!virtvalid(context, gen.addr())) {
181  DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va);
182  return false;
183  }
184  }
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 void
200 {
201  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
202 
203  for (int i = 0; i < 31; ++i)
204  r.x[i] = context->readIntReg(INTREG_X0 + i);
205  r.spx = context->readIntReg(INTREG_SPX);
206  r.pc = context->pcState().pc();
207  r.cpsr = context->readMiscRegNoEffect(MISCREG_CPSR);
208 
209  for (int i = 0; i < 32*4; i += 4) {
210  r.v[i + 0] = context->readFloatRegBits(i + 2);
211  r.v[i + 1] = context->readFloatRegBits(i + 3);
212  r.v[i + 2] = context->readFloatRegBits(i + 0);
213  r.v[i + 3] = context->readFloatRegBits(i + 1);
214  }
215 }
216 
217 void
219 {
220  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
221 
222  for (int i = 0; i < 31; ++i)
223  context->setIntReg(INTREG_X0 + i, r.x[i]);
224  context->pcState(r.pc);
225  context->setMiscRegNoEffect(MISCREG_CPSR, r.cpsr);
226  // Update the stack pointer. This should be done after
227  // updating CPSR/PSTATE since that might affect how SPX gets
228  // mapped.
229  context->setIntReg(INTREG_SPX, r.spx);
230 
231  for (int i = 0; i < 32*4; i += 4) {
232  context->setFloatRegBits(i + 2, r.v[i + 0]);
233  context->setFloatRegBits(i + 3, r.v[i + 1]);
234  context->setFloatRegBits(i + 0, r.v[i + 2]);
235  context->setFloatRegBits(i + 1, r.v[i + 3]);
236  }
237 }
238 
239 void
241 {
242  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
243 
244  r.gpr[0] = context->readIntReg(INTREG_R0);
245  r.gpr[1] = context->readIntReg(INTREG_R1);
246  r.gpr[2] = context->readIntReg(INTREG_R2);
247  r.gpr[3] = context->readIntReg(INTREG_R3);
248  r.gpr[4] = context->readIntReg(INTREG_R4);
249  r.gpr[5] = context->readIntReg(INTREG_R5);
250  r.gpr[6] = context->readIntReg(INTREG_R6);
251  r.gpr[7] = context->readIntReg(INTREG_R7);
252  r.gpr[8] = context->readIntReg(INTREG_R8);
253  r.gpr[9] = context->readIntReg(INTREG_R9);
254  r.gpr[10] = context->readIntReg(INTREG_R10);
255  r.gpr[11] = context->readIntReg(INTREG_R11);
256  r.gpr[12] = context->readIntReg(INTREG_R12);
257  r.gpr[13] = context->readIntReg(INTREG_SP);
258  r.gpr[14] = context->readIntReg(INTREG_LR);
259  r.gpr[15] = context->pcState().pc();
260 
261  // One day somebody will implement transfer of FPRs correctly.
262  for (int i=0; i<8*3; i++) r.fpr[i] = 0;
263 
264  r.fpscr = context->readMiscRegNoEffect(MISCREG_FPSCR);
265  r.cpsr = context->readMiscRegNoEffect(MISCREG_CPSR);
266 }
267 
268 void
270 {
271  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
272 
273  context->setIntReg(INTREG_R0, r.gpr[0]);
274  context->setIntReg(INTREG_R1, r.gpr[1]);
275  context->setIntReg(INTREG_R2, r.gpr[2]);
276  context->setIntReg(INTREG_R3, r.gpr[3]);
277  context->setIntReg(INTREG_R4, r.gpr[4]);
278  context->setIntReg(INTREG_R5, r.gpr[5]);
279  context->setIntReg(INTREG_R6, r.gpr[6]);
280  context->setIntReg(INTREG_R7, r.gpr[7]);
281  context->setIntReg(INTREG_R8, r.gpr[8]);
282  context->setIntReg(INTREG_R9, r.gpr[9]);
283  context->setIntReg(INTREG_R10, r.gpr[10]);
284  context->setIntReg(INTREG_R11, r.gpr[11]);
285  context->setIntReg(INTREG_R12, r.gpr[12]);
286  context->setIntReg(INTREG_SP, r.gpr[13]);
287  context->setIntReg(INTREG_LR, r.gpr[14]);
288  context->pcState(r.gpr[15]);
289 
290  // One day somebody will implement transfer of FPRs correctly.
291 
292  context->setMiscReg(MISCREG_FPSCR, r.fpscr);
293  context->setMiscRegNoEffect(MISCREG_CPSR, r.cpsr);
294 }
295 
298 {
299  if (inAArch64(context))
300  return &regCache32;
301  else
302  return &regCache64;
303 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:218
Bitfield< 7 > i
Definition: miscregs.hh:1378
AArch32GdbRegCache regCache32
Definition: remote_gdb.hh:112
AArch64GdbRegCache regCache64
Definition: remote_gdb.hh:113
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:199
struct ArmISA::RemoteGDB::AArch64GdbRegCache::@7 r
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
virtual Process * getProcessPtr()=0
Port Object Declaration.
bool virtvalid(ThreadContext *tc, Addr vaddr)
Definition: vtophys.cc:108
Definition: system.hh:83
virtual void setIntReg(int reg_idx, uint64_t val)=0
virtual FloatRegBits readFloatRegBits(int reg_idx)=0
virtual TheISA::PCState pcState()=0
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:183
virtual void setFloatRegBits(int reg_idx, FloatRegBits val)=0
ThreadContext * context
Definition: remote_gdb.hh:173
virtual uint64_t readIntReg(int reg_idx)=0
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:297
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
void setRegs(ThreadContext *) const
Definition: remote_gdb.cc:269
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Bitfield< 8 > va
Definition: miscregs.hh:1473
PageTableBase * pTable
Definition: process.hh:178
Declarations of a non-full system Page Table.
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry)=0
Lookup function.
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:176
const Addr PageBytes
Definition: isa_traits.hh:64
bool inAArch64(ThreadContext *tc)
Definition: utility.cc:185
Declaration and inline definition of ChunkGenerator object.
virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val)=0

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6