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

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13