2 * Copyright 2015 LabWare
3 * Copyright 2014 Google, Inc.
4 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
30 * Authors: Nathan Binkert
35 * Copyright (c) 1990, 1993 The Regents of the University of California
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.
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.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
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.
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
75 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
79 * Copyright (c) 2001 The NetBSD Foundation, Inc.
80 * All rights reserved.
82 * This code is derived from software contributed to The NetBSD Foundation
85 * Redistribution and use in source and binary forms, with or without
86 * modification, are permitted provided that the following conditions
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.
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.
115 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
119 * "Stub" to allow remote cpu to debug over a serial line using gdb.
122 #include "arch/sparc/remote_gdb.hh"
124 #include <sys/signal.h>
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"
148 using namespace SparcISA
;
150 RemoteGDB::RemoteGDB(System
*_system
, ThreadContext
*c
)
151 : BaseRemoteGDB(_system
, c
), regCache32(this), regCache64(this)
154 ///////////////////////////////////////////////////////////
157 // Determine if the mapping at va..(va+len) is valid.
160 RemoteGDB::acc(Addr va
, size_t len
)
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.
171 // Check to make sure the first byte is mapped into the processes
173 if (context
->getProcessPtr()->pTable
->lookup(va
, entry
))
180 RemoteGDB::SPARCGdbRegCache::getRegs(ThreadContext
*context
)
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));
195 RemoteGDB::SPARC64GdbRegCache::getRegs(ThreadContext
*context
)
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
);
208 context
->readMiscReg(MISCREG_CWP
) |
210 context
->readMiscReg(MISCREG_ASI
) << 24 |
211 context
->readIntReg(NumIntArchRegs
+ 2) << 32);
215 RemoteGDB::SPARCGdbRegCache::setRegs(ThreadContext
*context
) const
217 for (int i
= 0; i
< 32; i
++) context
->setIntReg(i
, r
.gpr
[i
]);
221 pc
.nnpc(pc
.npc() + sizeof(MachInst
));
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.
231 RemoteGDB::SPARC64GdbRegCache::setRegs(ThreadContext
*context
) const
233 for (int i
= 0; i
< 32; i
++) context
->setIntReg(i
, r
.gpr
[i
]);
237 pc
.nnpc(pc
.npc() + sizeof(MachInst
));
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.
247 RemoteGDB::BaseGdbRegCache
*
250 PSTATE pstate
= context
->readMiscReg(MISCREG_PSTATE
);