Deleted Added
sdiff udiff text old ( 11274:d9a0136ab8cc ) new ( 11793:ef606668d247 )
full compact
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 <signal.h>
123#include <sys/signal.h>
124#include <unistd.h>
125
126#include <string>
127
128#include "arch/sparc/remote_gdb.hh"
129#include "arch/vtophys.hh"
130#include "base/intmath.hh"
131#include "base/remote_gdb.hh"
132#include "base/socket.hh"
133#include "base/trace.hh"
134#include "cpu/static_inst.hh"
135#include "cpu/thread_context.hh"
136#include "debug/GDBAcc.hh"
137#include "debug/GDBRead.hh"
138#include "mem/page_table.hh"
139#include "mem/physical.hh"
140#include "mem/port.hh"
141#include "sim/byteswap.hh"
142#include "sim/full_system.hh"
143#include "sim/process.hh"
144#include "sim/system.hh"
145
146using namespace std;
147using namespace SparcISA;
148
149RemoteGDB::RemoteGDB(System *_system, ThreadContext *c)
150 : BaseRemoteGDB(_system, c)
151{}
152
153///////////////////////////////////////////////////////////
154// RemoteGDB::acc
155//
156// Determine if the mapping at va..(va+len) is valid.
157//
158bool
159RemoteGDB::acc(Addr va, size_t len)
160{
161 //@Todo In NetBSD, this function checks if all addresses
162 // from va to va + len have valid page map entries. Not
163 // sure how this will work for other OSes or in general.
164 if (FullSystem) {
165 if (va)
166 return true;
167 return false;
168 } else {
169 TlbEntry entry;
170 // Check to make sure the first byte is mapped into the processes
171 // address space.
172 if (context->getProcessPtr()->pTable->lookup(va, entry))
173 return true;
174 return false;
175 }
176}
177
178void
179RemoteGDB::SPARCGdbRegCache::getRegs(ThreadContext *context)
180{
181 DPRINTF(GDBAcc, "getRegs in remotegdb \n");
182 for (int i = 0; i < 32; i++) r.gpr[i] = htobe((uint32_t)context->readIntReg(i));
183 PCState pc = context->pcState();
184 r.pc = htobe((uint32_t)pc.pc());
185 r.npc = htobe((uint32_t)pc.npc());
186 r.y = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
187 PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
188 r.psr = htobe((uint32_t)pstate);
189 r.fsr = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
190 r.csr = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
191}
192
193void
194RemoteGDB::SPARC64GdbRegCache::getRegs(ThreadContext *context)
195{
196 DPRINTF(GDBAcc, "getRegs in remotegdb \n");
197 for (int i = 0; i < 32; i++) r.gpr[i] = htobe(context->readIntReg(i));
198 for (int i = 0; i < 32; i++) r.fpr[i] = 0;
199 PCState pc = context->pcState();
200 r.pc = htobe(pc.pc());
201 r.npc = htobe(pc.npc());
202 r.fsr = htobe(context->readMiscReg(MISCREG_FSR));
203 r.fprs = htobe(context->readMiscReg(MISCREG_FPRS));
204 r.y = htobe(context->readIntReg(NumIntArchRegs + 1));
205 PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
206 r.state = htobe(
207 context->readMiscReg(MISCREG_CWP) |
208 pstate << 8 |
209 context->readMiscReg(MISCREG_ASI) << 24 |
210 context->readIntReg(NumIntArchRegs + 2) << 32);
211}
212
213void
214RemoteGDB::SPARCGdbRegCache::setRegs(ThreadContext *context) const
215{
216 for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
217 PCState pc;
218 pc.pc(r.pc);
219 pc.npc(r.npc);
220 pc.nnpc(pc.npc() + sizeof(MachInst));
221 pc.upc(0);
222 pc.nupc(1);
223 context->pcState(pc);
224 // Floating point registers are left at 0 in netbsd
225 // All registers other than the pc, npc and int regs
226 // are ignored as well.
227}
228
229void
230RemoteGDB::SPARC64GdbRegCache::setRegs(ThreadContext *context) const
231{
232 for (int i = 0; i < 32; i++) context->setIntReg(i, r.gpr[i]);
233 PCState pc;
234 pc.pc(r.pc);
235 pc.npc(r.npc);
236 pc.nnpc(pc.npc() + sizeof(MachInst));
237 pc.upc(0);
238 pc.nupc(1);
239 context->pcState(pc);
240 // Floating point registers are left at 0 in netbsd
241 // All registers other than the pc, npc and int regs
242 // are ignored as well.
243}
244
245
246RemoteGDB::BaseGdbRegCache*
247RemoteGDB::gdbRegs()
248{
249 PSTATE pstate = context->readMiscReg(MISCREG_PSTATE);
250 if (pstate.am)
251 {DPRINTF(GDBRead, "Creating 32-bit GDB\n");
252 return new SPARCGdbRegCache(this);}
253 else
254 {DPRINTF(GDBRead, "Creating 64-bit GDB\n");
255 return new SPARC64GdbRegCache(this);}
256}