gem5  v22.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 "arch/mips/gdb-xml/gdb_xml_mips.hh"
140 #include "arch/mips/regs/float.hh"
141 #include "arch/mips/regs/int.hh"
142 #include "arch/mips/regs/misc.hh"
143 #include "cpu/thread_state.hh"
144 #include "debug/GDBAcc.hh"
145 #include "debug/GDBMisc.hh"
146 #include "mem/page_table.hh"
147 #include "sim/full_system.hh"
148 
149 namespace gem5
150 {
151 
152 using namespace MipsISA;
153 
154 RemoteGDB::RemoteGDB(System *_system, int _port)
155  : BaseRemoteGDB(_system, _port), regCache(this)
156 {
157 }
158 
159 /*
160  * Determine if the mapping at va..(va+len) is valid.
161  */
162 bool
163 RemoteGDB::acc(Addr va, size_t len)
164 {
165  // Check to make sure the first byte is mapped into the processes address
166  // space.
167  panic_if(FullSystem, "acc not implemented for MIPS FS!");
168  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
169 }
170 
171 void
172 RemoteGDB::MipsGdbRegCache::getRegs(ThreadContext *context)
173 {
174  DPRINTF(GDBAcc, "getregs in remotegdb \n");
175 
176  for (int i = 0; i < 32; i++)
177  r.gpr[i] = context->getReg(intRegClass[i]);
178  r.sr = context->readMiscRegNoEffect(misc_reg::Status);
179  r.lo = context->getReg(int_reg::Lo);
180  r.hi = context->getReg(int_reg::Hi);
181  r.badvaddr = context->readMiscRegNoEffect(misc_reg::Badvaddr);
182  r.cause = context->readMiscRegNoEffect(misc_reg::Cause);
183  r.pc = context->pcState().instAddr();
184  for (int i = 0; i < 32; i++)
185  r.fpr[i] = context->getReg(floatRegClass[i]);
186  r.fsr = context->getReg(float_reg::Fccr);
187  r.fir = context->getReg(float_reg::Fir);
188 }
189 
190 void
191 RemoteGDB::MipsGdbRegCache::setRegs(ThreadContext *context) const
192 {
193  DPRINTF(GDBAcc, "setregs in remotegdb \n");
194 
195  for (int i = 1; i < 32; i++)
196  context->setReg(intRegClass[i], r.gpr[i]);
197  context->setMiscRegNoEffect(misc_reg::Status, r.sr);
198  context->setReg(int_reg::Lo, r.lo);
199  context->setReg(int_reg::Hi, r.hi);
200  context->setMiscRegNoEffect(misc_reg::Badvaddr, r.badvaddr);
201  context->setMiscRegNoEffect(misc_reg::Cause, r.cause);
202  context->pcState(r.pc);
203  for (int i = 0; i < 32; i++)
204  context->setReg(floatRegClass[i], r.fpr[i]);
205  context->setReg(float_reg::Fccr, r.fsr);
206  context->setReg(float_reg::Fir, r.fir);
207 }
208 
210 RemoteGDB::gdbRegs()
211 {
212  return &regCache;
213 }
214 
215 bool
216 RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
217 {
218 #define GDB_XML(x, s) \
219  { x, std::string(reinterpret_cast<const char *>(Blobs::s), \
220  Blobs::s ## _len) }
221  static const std::map<std::string, std::string> annexMap {
222  GDB_XML("target.xml", gdb_xml_mips),
223  };
224 #undef GDB_XML
225  auto it = annexMap.find(annex);
226  if (it == annexMap.end())
227  return false;
228  output = it->second;
229  return true;
230 }
231 
232 } // namespace gem5
#define GDB_XML(x, s)
#define DPRINTF(x,...)
Definition: trace.hh:186
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:86
RemoteGDB(System *_system, int _port)
Addr instAddr() const
Returns the memory address of the instruction this PC points to.
Definition: pcstate.hh:107
ThreadContext is the external interface to all thread state for anything outside of the CPU.
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
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
uint16_t len
Definition: helpers.cc:62
Bitfield< 7 > i
Definition: misc_types.hh:67
constexpr RegClass intRegClass
Definition: int.hh:173
Bitfield< 8 > va
Definition: misc_types.hh:282
constexpr RegId Fccr
Definition: float.hh:133
constexpr RegId Fir
Definition: float.hh:132
constexpr auto & Lo
Definition: int.hh:205
constexpr auto & Hi
Definition: int.hh:206
Bitfield< 5 > r
Definition: pagetable.hh:60
constexpr RegClass floatRegClass
Definition: float.hh:143
std::ostream & output()
Get the ostream from the current global logger.
Definition: trace.cc:79
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
Declarations of a non-full system Page Table.

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