gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
151  : BaseRemoteGDB(_system, c), 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  if (va)
167  return true;
168  return false;
169  } else {
170  TlbEntry entry;
171  // Check to make sure the first byte is mapped into the processes
172  // address space.
173  if (context->getProcessPtr()->pTable->lookup(va, entry))
174  return true;
175  return false;
176  }
177 }
178 
179 void
181 {
182  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
183  for (int i = 0; i < 32; i++) r.gpr[i] = htobe((uint32_t)context->readIntReg(i));
184  PCState pc = context->pcState();
185  r.pc = htobe((uint32_t)pc.pc());
186  r.npc = htobe((uint32_t)pc.npc());
187  r.y = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
188  PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
189  r.psr = htobe((uint32_t)pstate);
190  r.fsr = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
191  r.csr = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
192 }
193 
194 void
196 {
197  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
198  for (int i = 0; i < 32; i++) r.gpr[i] = htobe(context->readIntReg(i));
199  for (int i = 0; i < 32; i++) r.fpr[i] = 0;
200  PCState pc = context->pcState();
201  r.pc = htobe(pc.pc());
202  r.npc = htobe(pc.npc());
203  r.fsr = htobe(context->readMiscReg(MISCREG_FSR));
204  r.fprs = htobe(context->readMiscReg(MISCREG_FPRS));
205  r.y = htobe(context->readIntReg(NumIntArchRegs + 1));
206  PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
207  r.state = htobe(
208  context->readMiscReg(MISCREG_CWP) |
209  pstate << 8 |
210  context->readMiscReg(MISCREG_ASI) << 24 |
211  context->readIntReg(NumIntArchRegs + 2) << 32);
212 }
213 
214 void
216 {
217  for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
218  PCState pc;
219  pc.pc(r.pc);
220  pc.npc(r.npc);
221  pc.nnpc(pc.npc() + sizeof(MachInst));
222  pc.upc(0);
223  pc.nupc(1);
224  context->pcState(pc);
225  // Floating point registers are left at 0 in netbsd
226  // All registers other than the pc, npc and int regs
227  // are ignored as well.
228 }
229 
230 void
232 {
233  for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
234  PCState pc;
235  pc.pc(r.pc);
236  pc.npc(r.npc);
237  pc.nnpc(pc.npc() + sizeof(MachInst));
238  pc.upc(0);
239  pc.nupc(1);
240  context->pcState(pc);
241  // Floating point registers are left at 0 in netbsd
242  // All registers other than the pc, npc and int regs
243  // are ignored as well.
244 }
245 
246 
249 {
250  PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
251  if (pstate.am) {
252  return &regCache32;
253  } else {
254  return &regCache64;
255  }
256 }
#define DPRINTF(x,...)
Definition: trace.hh:212
Bitfield< 7 > i
Definition: miscregs.hh:1378
uint32_t MachInst
Definition: types.hh:41
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:195
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:231
virtual Process * getProcessPtr()=0
Port Object Declaration.
Definition: system.hh:83
virtual void setIntReg(int reg_idx, uint64_t val)=0
virtual TheISA::PCState pcState()=0
struct SparcISA::RemoteGDB::SPARCGdbRegCache::@21 r
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:183
SPARCGdbRegCache regCache32
Definition: remote_gdb.hh:97
Addr pc() const
Definition: types.hh:138
ThreadContext * context
Definition: remote_gdb.hh:173
const int NumIntArchRegs
Definition: registers.hh:75
virtual uint64_t readIntReg(int reg_idx)=0
void setRegs(ThreadContext *) const
Definition: remote_gdb.cc:215
MicroPC upc() const
Definition: types.hh:373
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:248
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
MicroPC nupc() const
Definition: types.hh:376
Bitfield< 8 > va
Definition: miscregs.hh:1473
PageTableBase * pTable
Definition: process.hh:178
Ancillary State Registers.
Definition: miscregs.hh:45
virtual MiscReg readMiscReg(int misc_reg)=0
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:160
Bitfield< 29 > c
Definition: miscregs.hh:1365
Declarations of a non-full system Page Table.
Addr npc() const
Definition: types.hh:141
T htobe(T value)
Definition: byteswap.hh:153
SPARC64GdbRegCache regCache64
Definition: remote_gdb.hh:98
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry)=0
Lookup function.
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
IntReg pc
Definition: remote_gdb.hh:91
Floating Point Status Register.
Definition: miscregs.hh:86

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6