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 2014 Google, Inc.
3  * Copyright (c) 2002-2005 The Regents of The University of Michigan
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Nathan Binkert
30  */
31 
32 /*
33  * Copyright (c) 1990, 1993 The Regents of the University of California
34  * All rights reserved.
35  *
36  * This software was developed by the Computer Systems Engineering group
37  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
38  * contributed to Berkeley.
39  *
40  * All advertising materials mentioning features or use of this software
41  * must display the following acknowledgement:
42  * This product includes software developed by the University of
43  * California, Lawrence Berkeley Laboratories.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  * 1. Redistributions of source code must retain the above copyright
49  * notice, this list of conditions and the following disclaimer.
50  * 2. Redistributions in binary form must reproduce the above copyright
51  * notice, this list of conditions and the following disclaimer in the
52  * documentation and/or other materials provided with the distribution.
53  * 3. 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, Berkeley and its contributors.
57  * 4. Neither the name of the University nor the names of its contributors
58  * may be used to endorse or promote products derived from this software
59  * without specific prior written permission.
60  *
61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71  * SUCH DAMAGE.
72  *
73  * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
74  */
75 
76 /*-
77  * Copyright (c) 2001 The NetBSD Foundation, Inc.
78  * All rights reserved.
79  *
80  * This code is derived from software contributed to The NetBSD Foundation
81  * by Jason R. Thorpe.
82  *
83  * Redistribution and use in source and binary forms, with or without
84  * modification, are permitted provided that the following conditions
85  * are met:
86  * 1. Redistributions of source code must retain the above copyright
87  * notice, this list of conditions and the following disclaimer.
88  * 2. Redistributions in binary form must reproduce the above copyright
89  * notice, this list of conditions and the following disclaimer in the
90  * documentation and/or other materials provided with the distribution.
91  * 3. All advertising materials mentioning features or use of this software
92  * must display the following acknowledgement:
93  * This product includes software developed by the NetBSD
94  * Foundation, Inc. and its contributors.
95  * 4. Neither the name of The NetBSD Foundation nor the names of its
96  * contributors may be used to endorse or promote products derived
97  * from this software without specific prior written permission.
98  *
99  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
100  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
101  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
102  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
103  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
104  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
105  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
106  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
107  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
108  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
109  * POSSIBILITY OF SUCH DAMAGE.
110  */
111 
112 /*
113  * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
114  *
115  * Taken from NetBSD
116  *
117  * "Stub" to allow remote cpu to debug over a serial line using gdb.
118  */
119 
120 #include "arch/alpha/remote_gdb.hh"
121 
122 #include <sys/signal.h>
123 #include <unistd.h>
124 
125 #include <string>
126 
127 #include "arch/alpha/decoder.hh"
128 #include "arch/alpha/regredir.hh"
129 #include "arch/alpha/utility.hh"
130 #include "arch/alpha/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/GDBMisc.hh"
139 #include "mem/physical.hh"
140 #include "mem/port.hh"
141 #include "sim/full_system.hh"
142 #include "sim/system.hh"
143 
144 using namespace std;
145 using namespace AlphaISA;
146 
147 RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
148  : BaseRemoteGDB(_system, tc)
149 {
150 }
151 
152 /*
153  * Determine if the mapping at va..(va+len) is valid.
154  */
155 bool
157 {
158  if (!FullSystem)
159  panic("acc function needs to be rewritten for SE mode\n");
160 
161  Addr last_va;
162 
163  va = TruncPage(va);
164  last_va = RoundPage(va + len);
165 
166  do {
167  if (IsK0Seg(va)) {
168  if (va < (K0SegBase + system->memSize())) {
169  DPRINTF(GDBAcc, "acc: Mapping is valid K0SEG <= "
170  "%#x < K0SEG + size\n", va);
171  return true;
172  } else {
173  DPRINTF(GDBAcc, "acc: Mapping invalid %#x "
174  "> K0SEG + size\n", va);
175  return false;
176  }
177  }
178 
187  if (PcPAL(va) || va < 0x10000)
188  return true;
189 
191  PageTableEntry pte =
193  if (!pte.valid()) {
194  DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va);
195  return false;
196  }
197  va += PageBytes;
198  } while (va < last_va);
199 
200  DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va);
201  return true;
202 }
203 
204 void
206 {
207  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
208 
209  r.pc = context->pcState().pc();
210 
211  if (PcPAL(r.pc)) {
212  for (int i = 0; i < 32; ++i)
213  r.gpr[i] = context->readIntReg(reg_redir[i]);
214  } else {
215  for (int i = 0; i < 32; ++i)
216  r.gpr[i] = context->readIntReg(i);
217  }
218 
219  for (int i = 0; i < 32; ++i)
220 #ifdef KGDB_FP_REGS
221  r.fpr[i] = context->readFloatRegBits(i);
222 #else
223  r.fpr[i] = 0;
224 #endif
225 }
226 
227 void
229 {
230  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
231 
232  if (PcPAL(r.pc)) {
233  for (int i = 0; i < 32; ++i) {
234  context->setIntReg(reg_redir[i], r.gpr[i]);
235  }
236  } else {
237  for (int i = 0; i < 32; ++i) {
238  context->setIntReg(i, r.gpr[i]);
239  }
240  }
241 
242 #ifdef KGDB_FP_REGS
243  for (int i = 0; i < NumFloatArchRegs; ++i) {
244  context->setFloatRegBits(i, gdbregs.regs64[i + KGDB_REG_F0]);
245  }
246 #endif
247  context->pcState(r.pc);
248 }
249 
250 // Write bytes to kernel address space for debugger.
251 bool
252 RemoteGDB::write(Addr vaddr, size_t size, const char *data)
253 {
254  if (BaseRemoteGDB::write(vaddr, size, data)) {
255 #ifdef IMB
256  alpha_pal_imb();
257 #endif
258  return true;
259  } else {
260  return false;
261  }
262 }
263 
264 
265 void
267 {
268  warn_once("Breakpoints do not work in Alpha PAL mode.\n"
269  " See PCEventQueue::doService() in cpu/pc_event.cc.\n");
271 }
272 
275  return new AlphaGdbRegCache(this);
276 }
277 
#define DPRINTF(x,...)
Definition: trace.hh:212
bool PcPAL(Addr addr)
Definition: utility.hh:69
void setRegs(ThreadContext *) const
Definition: remote_gdb.cc:228
Bitfield< 7 > i
Definition: miscregs.hh:1378
bool write(Addr addr, size_t size, const char *data)
Definition: remote_gdb.cc:252
#define panic(...)
Definition: misc.hh:153
const int reg_redir[NumIntRegs]
Definition: regredir.cc:37
ip6_addr_t addr
Definition: inet.hh:335
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
Port Object Declaration.
#define warn_once(...)
Definition: misc.hh:226
Definition: system.hh:83
virtual void setIntReg(int reg_idx, uint64_t val)=0
virtual FloatRegBits readFloatRegBits(int reg_idx)=0
virtual TheISA::PCState pcState()=0
System * system
Definition: remote_gdb.hh:172
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
const int NumFloatArchRegs
Definition: registers.hh:93
virtual void setFloatRegBits(int reg_idx, FloatRegBits val)=0
const char data[]
Definition: circlebuf.cc:43
ThreadContext * context
Definition: remote_gdb.hh:173
virtual PortProxy & getPhysProxy()=0
virtual uint64_t readIntReg(int reg_idx)=0
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:274
PageTableEntry kernel_pte_lookup(PortProxy &mem, Addr ptbr, VAddr vaddr)
Definition: vtophys.cc:49
Addr TruncPage(Addr addr)
Definition: utility.hh:91
bool valid() const
Definition: pagetable.hh:87
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual bool write(Addr addr, size_t size, const char *data)
Definition: remote_gdb.cc:490
Bitfield< 8 > va
Definition: miscregs.hh:1473
const Addr PageBytes
Definition: isa_traits.hh:52
Addr memSize() const
Amount of physical memory that exists.
Definition: system.cc:359
int size()
Definition: pagetable.hh:146
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:156
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
bool IsK0Seg(Addr a)
Definition: utility.hh:84
struct AlphaISA::RemoteGDB::AlphaGdbRegCache::@1 r
void insertHardBreak(Addr addr, size_t len) override
Definition: remote_gdb.cc:266
virtual void insertHardBreak(Addr addr, size_t len)
Definition: remote_gdb.cc:602
Addr RoundPage(Addr addr)
Definition: utility.hh:95
const Addr K0SegBase
Definition: isa_traits.hh:71

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