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) 2002-2005 The Regents of The University of Michigan
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  * Copyright (c) 1990, 1993 The Regents of the University of California
33  * All rights reserved
34  *
35  * This software was developed by the Computer Systems Engineering group
36  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
37  * contributed to Berkeley.
38  *
39  * All advertising materials mentioning features or use of this software
40  * must display the following acknowledgement:
41  * This product includes software developed by the University of
42  * California, Lawrence Berkeley Laboratories.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  * notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  * notice, this list of conditions and the following disclaimer in the
51  * documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  * must display the following acknowledgement:
54  * This product includes software developed by the University of
55  * California, Berkeley and its contributors.
56  * 4. Neither the name of the University nor the names of its contributors
57  * may be used to endorse or promote products derived from this software
58  * without specific prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
73  */
74 
75 /*-
76  * Copyright (c) 2001 The NetBSD Foundation, Inc.
77  * All rights reserved.
78  *
79  * This code is derived from software contributed to The NetBSD Foundation
80  * by Jason R. Thorpe.
81  *
82  * Redistribution and use in source and binary forms, with or without
83  * modification, are permitted provided that the following conditions
84  * are met:
85  * 1. Redistributions of source code must retain the above copyright
86  * notice, this list of conditions and the following disclaimer.
87  * 2. Redistributions in binary form must reproduce the above copyright
88  * notice, this list of conditions and the following disclaimer in the
89  * documentation and/or other materials provided with the distribution.
90  * 3. All advertising materials mentioning features or use of this software
91  * must display the following acknowledgement:
92  * This product includes software developed by the NetBSD
93  * Foundation, Inc. and its contributors.
94  * 4. Neither the name of The NetBSD Foundation nor the names of its
95  * contributors may be used to endorse or promote products derived
96  * from this software without specific prior written permission.
97  *
98  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
99  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
100  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
102  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
103  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
104  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
105  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
106  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
107  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108  * POSSIBILITY OF SUCH DAMAGE.
109  */
110 
111 /*
112  * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
113  *
114  * Taken from NetBSD
115  *
116  * "Stub" to allow remote cpu to debug over a serial line using gdb.
117  */
118 
119 #include "arch/sparc/remote_gdb.hh"
120 
121 #include <sys/signal.h>
122 #include <unistd.h>
123 
124 #include <csignal>
125 #include <string>
126 
127 #include "base/intmath.hh"
128 #include "base/remote_gdb.hh"
129 #include "base/socket.hh"
130 #include "base/trace.hh"
131 #include "cpu/static_inst.hh"
132 #include "cpu/thread_context.hh"
133 #include "debug/GDBAcc.hh"
134 #include "debug/GDBRead.hh"
135 #include "mem/page_table.hh"
136 #include "mem/physical.hh"
137 #include "mem/port.hh"
138 #include "sim/byteswap.hh"
139 #include "sim/full_system.hh"
140 #include "sim/process.hh"
141 #include "sim/system.hh"
142 
143 using namespace std;
144 using namespace SparcISA;
145 
146 RemoteGDB::RemoteGDB(System *_system, ThreadContext *c, int _port)
147  : BaseRemoteGDB(_system, c, _port), regCache32(this), regCache64(this)
148 {}
149 
151 // RemoteGDB::acc
152 //
153 // Determine if the mapping at va..(va+len) is valid.
154 //
155 bool
157 {
158  //@Todo In NetBSD, this function checks if all addresses
159  // from va to va + len have valid page map entries. Not
160  // sure how this will work for other OSes or in general.
161  if (FullSystem) {
162  return va != 0;
163  } else {
164  // Check to make sure the first byte is mapped into the processes
165  // address space.
166  return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
167  }
168 }
169 
170 void
172 {
173  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
174  for (int i = 0; i < 32; i++) r.gpr[i] = htobe((uint32_t)context->readIntReg(i));
175  PCState pc = context->pcState();
176  r.pc = htobe((uint32_t)pc.pc());
177  r.npc = htobe((uint32_t)pc.npc());
178  r.y = htobe((uint32_t)context->readIntReg(INTREG_Y));
179  PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
180  r.psr = htobe((uint32_t)pstate);
181  r.fsr = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
182  r.csr = htobe((uint32_t)context->readIntReg(INTREG_CCR));
183 }
184 
185 void
187 {
188  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
189  for (int i = 0; i < 32; i++) r.gpr[i] = htobe(context->readIntReg(i));
190  for (int i = 0; i < 32; i++) r.fpr[i] = 0;
191  PCState pc = context->pcState();
192  r.pc = htobe(pc.pc());
193  r.npc = htobe(pc.npc());
197  PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
198  r.state = htobe(
200  pstate << 8 |
202  context->readIntReg(INTREG_CCR) << 32);
203 }
204 
205 void
207 {
208  for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
209  PCState pc;
210  pc.pc(r.pc);
211  pc.npc(r.npc);
212  pc.nnpc(pc.npc() + sizeof(MachInst));
213  pc.upc(0);
214  pc.nupc(1);
215  context->pcState(pc);
216  // Floating point registers are left at 0 in netbsd
217  // All registers other than the pc, npc and int regs
218  // are ignored as well.
219 }
220 
221 void
223 {
224  for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
225  PCState pc;
226  pc.pc(r.pc);
227  pc.npc(r.npc);
228  pc.nnpc(pc.npc() + sizeof(MachInst));
229  pc.upc(0);
230  pc.nupc(1);
231  context->pcState(pc);
232  // Floating point registers are left at 0 in netbsd
233  // All registers other than the pc, npc and int regs
234  // are ignored as well.
235 }
236 
237 
240 {
241  PSTATE pstate = context()->readMiscReg(MISCREG_PSTATE);
242  if (pstate.am) {
243  return &regCache32;
244  } else {
245  return &regCache64;
246  }
247 }
SparcISA::MachInst
uint32_t MachInst
Definition: types.hh:38
SparcISA::MISCREG_PSTATE
@ MISCREG_PSTATE
Definition: miscregs.hh:62
socket.hh
SparcISA::RemoteGDB::SPARCGdbRegCache::getRegs
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:171
system.hh
SparcISA::RemoteGDB::SPARCGdbRegCache::pc
uint32_t pc
Definition: remote_gdb.hh:59
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
SparcISA::RemoteGDB::SPARC64GdbRegCache::getRegs
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:186
remote_gdb.hh
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
SparcISA::INTREG_CCR
@ INTREG_CCR
Definition: registers.hh:80
GenericISA::DelaySlotUPCState
Definition: types.hh:391
SparcISA::MISCREG_FSR
@ MISCREG_FSR
Floating Point Status Register.
Definition: miscregs.hh:83
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
SparcISA::RemoteGDB::gdbRegs
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:239
SparcISA::RemoteGDB::SPARCGdbRegCache::r
struct SparcISA::RemoteGDB::SPARCGdbRegCache::@19 r
remote_gdb.hh
EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:130
SparcISA::RemoteGDB::SPARCGdbRegCache::setRegs
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:206
SparcISA::RemoteGDB::regCache64
SPARC64GdbRegCache regCache64
Definition: remote_gdb.hh:103
SparcISA
Definition: asi.cc:31
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
SparcISA::RemoteGDB::SPARC64GdbRegCache::setRegs
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:222
System
Definition: system.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
MipsISA::r
r
Definition: pra_constants.hh:95
process.hh
port.hh
SparcISA::INTREG_Y
@ INTREG_Y
Definition: registers.hh:79
static_inst.hh
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
full_system.hh
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
SparcISA::RemoteGDB::acc
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:156
SparcISA::MISCREG_ASI
@ MISCREG_ASI
Ancillary State Registers.
Definition: miscregs.hh:42
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
htobe
T htobe(T value)
Definition: byteswap.hh:142
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
physical.hh
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
trace.hh
intmath.hh
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
page_table.hh
SparcISA::RemoteGDB::regCache32
SPARCGdbRegCache regCache32
Definition: remote_gdb.hh:102
thread_context.hh
ArmISA::va
Bitfield< 8 > va
Definition: miscregs_types.hh:272
SparcISA::MISCREG_FPRS
@ MISCREG_FPRS
Definition: miscregs.hh:44
byteswap.hh
SparcISA::MISCREG_CWP
@ MISCREG_CWP
Definition: miscregs.hh:65

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