gem5  v20.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 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 
132 #include "arch/power/remote_gdb.hh"
133 
134 #include <sys/signal.h>
135 #include <unistd.h>
136 
137 #include <string>
138 
139 #include "blobs/gdb_xml_power.hh"
140 #include "cpu/thread_state.hh"
141 #include "debug/GDBAcc.hh"
142 #include "debug/GDBMisc.hh"
143 #include "mem/page_table.hh"
144 #include "sim/byteswap.hh"
145 
146 using namespace std;
147 using namespace PowerISA;
148 
149 RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
150  : BaseRemoteGDB(_system, tc, _port), regCache(this)
151 {
152 }
153 
154 /*
155  * Determine if the mapping at va..(va+len) is valid.
156  */
157 bool
159 {
160  // Check to make sure the first byte is mapped into the processes address
161  // space. At the time of this writing, the acc() check is used when
162  // processing the MemR/MemW packets before actually asking the translating
163  // port proxy to read/writeBlob. I (bgs) am not convinced the first byte
164  // check is enough.
165  panic_if(FullSystem, "acc not implemented for POWER FS!");
166  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
167 }
168 
169 void
171 {
172  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
173 
174  // Default order on 32-bit PowerPC:
175  // R0-R31 (32-bit each), F0-F31 (64-bit IEEE754 double),
176  // PC, MSR, CR, LR, CTR, XER (32-bit each)
177 
178  for (int i = 0; i < NumIntArchRegs; i++)
179  r.gpr[i] = htobe((uint32_t)context->readIntReg(i));
180 
181  for (int i = 0; i < NumFloatArchRegs; i++)
182  r.fpr[i] = context->readFloatReg(i);
183 
184  r.pc = htobe((uint32_t)context->pcState().pc());
185  r.msr = 0; // Is MSR modeled?
186  r.cr = htobe((uint32_t)context->readIntReg(INTREG_CR));
187  r.lr = htobe((uint32_t)context->readIntReg(INTREG_LR));
188  r.ctr = htobe((uint32_t)context->readIntReg(INTREG_CTR));
189  r.xer = htobe((uint32_t)context->readIntReg(INTREG_XER));
190 }
191 
192 void
194 {
195  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
196 
197  for (int i = 0; i < NumIntArchRegs; i++)
198  context->setIntReg(i, betoh(r.gpr[i]));
199 
200  for (int i = 0; i < NumFloatArchRegs; i++)
201  context->setFloatReg(i, r.fpr[i]);
202 
203  context->pcState(betoh(r.pc));
204  // Is MSR modeled?
209 }
210 
213 {
214  return &regCache;
215 }
216 
217 bool
218 RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
219 {
220 #define GDB_XML(x, s) \
221  { x, std::string(reinterpret_cast<const char *>(Blobs::s), \
222  Blobs::s ## _len) }
223  static const std::map<std::string, std::string> annexMap {
224  GDB_XML("target.xml", gdb_xml_power),
225  };
226 #undef GDB_XML
227  auto it = annexMap.find(annex);
228  if (it == annexMap.end())
229  return false;
230  output = it->second;
231  return true;
232 }
remote_gdb.hh
output
static void output(const char *filename)
Definition: debug.cc:60
thread_state.hh
PowerISA::RemoteGDB::PowerGdbRegCache::getRegs
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:170
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
PowerISA::RemoteGDB::gdbRegs
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:212
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
GDB_XML
#define GDB_XML(x, s)
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
PowerISA::RemoteGDB::regCache
PowerGdbRegCache regCache
Definition: remote_gdb.hh:74
EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:130
PowerISA::RemoteGDB::PowerGdbRegCache::setRegs
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:193
ThreadContext::readFloatReg
virtual RegVal readFloatReg(RegIndex reg_idx) const =0
PowerISA::INTREG_CR
@ INTREG_CR
Definition: registers.hh:99
BaseRemoteGDB::context
ThreadContext * context()
Definition: remote_gdb.hh:304
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
PowerISA
Definition: decoder.cc:31
System
Definition: system.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
PowerISA::NumFloatArchRegs
const int NumFloatArchRegs
Definition: registers.hh:68
MipsISA::r
r
Definition: pra_constants.hh:95
PowerISA::INTREG_CTR
@ INTREG_CTR
Definition: registers.hh:102
BaseRemoteGDB
Definition: remote_gdb.hh:43
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
betoh
T betoh(T value)
Definition: byteswap.hh:143
BaseGdbRegCache
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:70
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
ThreadContext::setFloatReg
virtual void setFloatReg(RegIndex reg_idx, RegVal val)=0
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
htobe
T htobe(T value)
Definition: byteswap.hh:142
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
PowerISA::RemoteGDB::acc
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:158
PowerISA::RemoteGDB::getXferFeaturesRead
bool getXferFeaturesRead(const std::string &annex, std::string &output)
Get an XML target description.
Definition: remote_gdb.cc:218
PowerISA::INTREG_LR
@ INTREG_LR
Definition: registers.hh:101
PowerISA::RemoteGDB::PowerGdbRegCache::r
struct PowerISA::RemoteGDB::PowerGdbRegCache::@16 r
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
page_table.hh
PowerISA::NumIntArchRegs
const int NumIntArchRegs
Definition: registers.hh:63
ArmISA::va
Bitfield< 8 > va
Definition: miscregs_types.hh:272
PowerISA::INTREG_XER
@ INTREG_XER
Definition: registers.hh:100
byteswap.hh

Generated on Wed Sep 30 2020 14:02:01 for gem5 by doxygen 1.8.17