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  * Copyright (c) 2020 Barkhausen Institut
6  * All rights reserved
7  *
8  * The license below extends only to copyright in the software and shall
9  * not be construed as granting a license to any other intellectual
10  * property including but not limited to intellectual property relating
11  * to a hardware implementation of the functionality of the software
12  * licensed hereunder. You may use the software subject to the license
13  * terms below provided that you ensure that this notice is replicated
14  * unmodified and in its entirety in all distributions of the software,
15  * modified or unmodified, in source code or in binary form.
16  *
17  * Copyright (c) 2017 The University of Virginia
18  * Copyright (c) 2002-2005 The Regents of The University of Michigan
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions are
23  * met: redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer;
25  * redistributions in binary form must reproduce the above copyright
26  * notice, this list of conditions and the following disclaimer in the
27  * documentation and/or other materials provided with the distribution;
28  * neither the name of the copyright holders nor the names of its
29  * contributors may be used to endorse or promote products derived from
30  * this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  */
44 
45 /*
46  * Copyright (c) 1990, 1993 The Regents of the University of California
47  * All rights reserved
48  *
49  * This software was developed by the Computer Systems Engineering group
50  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
51  * contributed to Berkeley.
52  *
53  * All advertising materials mentioning features or use of this software
54  * must display the following acknowledgement:
55  * This product includes software developed by the University of
56  * California, Lawrence Berkeley Laboratories.
57  *
58  * Redistribution and use in source and binary forms, with or without
59  * modification, are permitted provided that the following conditions
60  * are met:
61  * 1. Redistributions of source code must retain the above copyright
62  * notice, this list of conditions and the following disclaimer.
63  * 2. Redistributions in binary form must reproduce the above copyright
64  * notice, this list of conditions and the following disclaimer in the
65  * documentation and/or other materials provided with the distribution.
66  * 3. All advertising materials mentioning features or use of this software
67  * must display the following acknowledgement:
68  * This product includes software developed by the University of
69  * California, Berkeley and its contributors.
70  * 4. Neither the name of the University nor the names of its contributors
71  * may be used to endorse or promote products derived from this software
72  * without specific prior written permission.
73  *
74  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
75  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
76  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
78  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
79  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
80  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
83  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84  * SUCH DAMAGE.
85  *
86  * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
87  */
88 
89 /*-
90  * Copyright (c) 2001 The NetBSD Foundation, Inc.
91  * All rights reserved.
92  *
93  * This code is derived from software contributed to The NetBSD Foundation
94  * by Jason R. Thorpe.
95  *
96  * Redistribution and use in source and binary forms, with or without
97  * modification, are permitted provided that the following conditions
98  * are met:
99  * 1. Redistributions of source code must retain the above copyright
100  * notice, this list of conditions and the following disclaimer.
101  * 2. Redistributions in binary form must reproduce the above copyright
102  * notice, this list of conditions and the following disclaimer in the
103  * documentation and/or other materials provided with the distribution.
104  * 3. All advertising materials mentioning features or use of this software
105  * must display the following acknowledgement:
106  * This product includes software developed by the NetBSD
107  * Foundation, Inc. and its contributors.
108  * 4. Neither the name of The NetBSD Foundation nor the names of its
109  * contributors may be used to endorse or promote products derived
110  * from this software without specific prior written permission.
111  *
112  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
113  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
114  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
115  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
116  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
117  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
118  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
119  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
120  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
121  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
122  * POSSIBILITY OF SUCH DAMAGE.
123  */
124 
125 /*
126  * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
127  *
128  * Taken from NetBSD
129  *
130  * "Stub" to allow remote cpu to debug over a serial line using gdb.
131  */
132 
133 #include "arch/riscv/remote_gdb.hh"
134 
135 #include <string>
136 
138 #include "arch/riscv/registers.hh"
139 #include "arch/riscv/tlb.hh"
140 #include "cpu/thread_state.hh"
141 #include "debug/GDBAcc.hh"
142 #include "mem/page_table.hh"
143 #include "sim/full_system.hh"
144 
145 using namespace std;
146 using namespace RiscvISA;
147 
148 RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
149  : BaseRemoteGDB(_system, tc, _port), regCache(this)
150 {
151 }
152 
153 bool
155 {
156  if (FullSystem)
157  {
158  TLB *tlb = dynamic_cast<TLB *>(context()->getDTBPtr());
159  unsigned logBytes;
160  Addr paddr = va;
161 
162  PrivilegeMode pmode = tlb->getMemPriv(context(), BaseTLB::Read);
163  SATP satp = context()->readMiscReg(MISCREG_SATP);
164  if (pmode != PrivilegeMode::PRV_M &&
165  satp.mode != AddrXlateMode::BARE) {
166  Walker *walker = tlb->getWalker();
167  Fault fault = walker->startFunctional(
168  context(), paddr, logBytes, BaseTLB::Read);
169  if (fault != NoFault)
170  return false;
171  }
172  return true;
173  }
174 
175  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
176 }
177 
178 void
180 {
181  DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
182  for (int i = 0; i < NumIntArchRegs; i++)
183  r.gpr[i] = context->readIntReg(i);
184  r.pc = context->pcState().pc();
185 }
186 
187 void
189 {
190  DPRINTF(GDBAcc, "setregs in remotegdb \n");
191  for (int i = 0; i < NumIntArchRegs; i++)
192  context->setIntReg(i, r.gpr[i]);
193  context->pcState(r.pc);
194 }
195 
198 {
199  return &regCache;
200 }
thread_state.hh
BaseTLB::Read
@ Read
Definition: tlb.hh:57
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
RiscvISA::RemoteGDB::RiscvGdbRegCache::getRegs
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:179
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
RiscvISA::RemoteGDB::RiscvGdbRegCache::setRegs
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:188
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
RiscvISA::RemoteGDB::gdbRegs
BaseGdbRegCache * gdbRegs() override
Definition: remote_gdb.cc:197
RiscvISA::TLB
Definition: tlb.hh:54
RiscvISA::RemoteGDB::RiscvGdbRegCache::size
size_t size() const
Return the size of the raw buffer, in bytes (i.e., half of the number of digits in the g/G packet).
Definition: remote_gdb.hh:66
EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:130
RiscvISA
Definition: fs_workload.cc:36
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
tlb.hh
RiscvISA::RemoteGDB::RiscvGdbRegCache::r
struct RiscvISA::RemoteGDB::RiscvGdbRegCache::@17 r
System
Definition: system.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
RiscvISA::Walker
Definition: pagetable_walker.hh:57
RiscvISA::PrivilegeMode
PrivilegeMode
Definition: isa.hh:56
RiscvISA::RemoteGDB::acc
bool acc(Addr addr, size_t len) override
Definition: remote_gdb.cc:154
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
RiscvISA::NumIntArchRegs
const int NumIntArchRegs
Definition: registers.hh:79
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
registers.hh
full_system.hh
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
remote_gdb.hh
RiscvISA::i
Bitfield< 2 > i
Definition: pra_constants.hh:276
RiscvISA::RemoteGDB::regCache
RiscvGdbRegCache regCache
Definition: remote_gdb.hh:77
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
RiscvISA::r
Bitfield< 1 > r
Definition: pagetable.hh:71
RiscvISA::MISCREG_SATP
@ MISCREG_SATP
Definition: registers.hh:244
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
page_table.hh
RiscvISA::PRV_M
@ PRV_M
Definition: isa.hh:60
RiscvISA::Walker::startFunctional
Fault startFunctional(ThreadContext *_tc, Addr &addr, unsigned &logBytes, BaseTLB::Mode mode)
Definition: pagetable_walker.cc:94
ArmISA::tlb
Bitfield< 59, 56 > tlb
Definition: miscregs_types.hh:88
ThreadContext::getDTBPtr
virtual BaseTLB * getDTBPtr()=0
ArmISA::va
Bitfield< 8 > va
Definition: miscregs_types.hh:272
pagetable_walker.hh

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