gem5  v20.1.0.0
remote_gdb.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2020 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 #include "arch/mips/remote_gdb.hh"
132 
133 #include <sys/signal.h>
134 #include <unistd.h>
135 
136 #include <string>
137 
138 #include "arch/mips/decoder.hh"
139 #include "blobs/gdb_xml_mips.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/full_system.hh"
145 
146 using namespace std;
147 using namespace MipsISA;
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.
162  panic_if(FullSystem, "acc not implemented for MIPS FS!");
163  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
164 }
165 
166 void
168 {
169  DPRINTF(GDBAcc, "getregs in remotegdb \n");
170 
171  for (int i = 0; i < 32; i++) r.gpr[i] = context->readIntReg(i);
173  r.lo = context->readIntReg(INTREG_LO);
174  r.hi = context->readIntReg(INTREG_HI);
177  r.pc = context->pcState().pc();
178  for (int i = 0; i < 32; i++) r.fpr[i] = context->readFloatReg(i);
181 }
182 
183 void
185 {
186  DPRINTF(GDBAcc, "setregs in remotegdb \n");
187 
188  for (int i = 1; i < 32; i++) context->setIntReg(i, r.gpr[i]);
194  context->pcState(r.pc);
195  for (int i = 0; i < 32; i++) context->setFloatReg(i, r.fpr[i]);
198 }
199 
202 {
203  return &regCache;
204 }
205 
206 bool
207 RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
208 {
209 #define GDB_XML(x, s) \
210  { x, std::string(reinterpret_cast<const char *>(Blobs::s), \
211  Blobs::s ## _len) }
212  static const std::map<std::string, std::string> annexMap {
213  GDB_XML("target.xml", gdb_xml_mips),
214  };
215 #undef GDB_XML
216  auto it = annexMap.find(annex);
217  if (it == annexMap.end())
218  return false;
219  output = it->second;
220  return true;
221 }
ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
output
static void output(const char *filename)
Definition: debug.cc:60
MipsISA::RemoteGDB::MipsGdbRegCache::r
struct MipsISA::RemoteGDB::MipsGdbRegCache::@15 r
thread_state.hh
MipsISA::RemoteGDB::getXferFeaturesRead
bool getXferFeaturesRead(const std::string &annex, std::string &output)
Get an XML target description.
Definition: remote_gdb.cc:207
MipsISA::FLOATREG_FIR
@ FLOATREG_FIR
Definition: registers.hh:67
MipsISA::RemoteGDB::regCache
MipsGdbRegCache regCache
Definition: remote_gdb.hh:77
MipsISA::RemoteGDB::acc
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:158
MipsISA::INTREG_LO
@ INTREG_LO
Definition: registers.hh:90
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
MipsISA::RemoteGDB::gdbRegs
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:201
MipsISA::RemoteGDB::MipsGdbRegCache::getRegs
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:167
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
MipsISA::MISCREG_CAUSE
@ MISCREG_CAUSE
Definition: registers.hh:184
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
MipsISA
Definition: decoder.cc:31
EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:130
decoder.hh
ThreadContext::readFloatReg
virtual RegVal readFloatReg(RegIndex reg_idx) const =0
BaseRemoteGDB::context
ThreadContext * context()
Definition: remote_gdb.hh:304
MipsISA::MISCREG_STATUS
@ MISCREG_STATUS
Definition: registers.hh:179
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
System
Definition: system.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::RemoteGDB::MipsGdbRegCache::setRegs
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:184
MipsISA::r
r
Definition: pra_constants.hh:95
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
BaseGdbRegCache
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:70
remote_gdb.hh
full_system.hh
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
MipsISA::i
Bitfield< 2 > i
Definition: pra_constants.hh:276
ThreadContext::setFloatReg
virtual void setFloatReg(RegIndex reg_idx, RegVal val)=0
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
GDB_XML
#define GDB_XML(x, s)
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
MipsISA::FLOATREG_FCCR
@ FLOATREG_FCCR
Definition: registers.hh:68
ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
MipsISA::INTREG_HI
@ INTREG_HI
Definition: registers.hh:92
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
page_table.hh
MipsISA::MISCREG_BADVADDR
@ MISCREG_BADVADDR
Definition: registers.hh:171
ArmISA::va
Bitfield< 8 > va
Definition: miscregs_types.hh:272

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