remote_gdb.cc (4070:74449a198a44) remote_gdb.cc (4172:141705d83494)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31/*
32 * Copyright (c) 1990, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * This software was developed by the Computer Systems Engineering group
36 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
37 * contributed to Berkeley.
38 *
39 * All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Lawrence Berkeley Laboratories.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by the University of
55 * California, Berkeley and its contributors.
56 * 4. Neither the name of the University nor the names of its contributors
57 * may be used to endorse or promote products derived from this software
58 * without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
73 */
74
75/*-
76 * Copyright (c) 2001 The NetBSD Foundation, Inc.
77 * All rights reserved.
78 *
79 * This code is derived from software contributed to The NetBSD Foundation
80 * by Jason R. Thorpe.
81 *
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
84 * are met:
85 * 1. Redistributions of source code must retain the above copyright
86 * notice, this list of conditions and the following disclaimer.
87 * 2. Redistributions in binary form must reproduce the above copyright
88 * notice, this list of conditions and the following disclaimer in the
89 * documentation and/or other materials provided with the distribution.
90 * 3. All advertising materials mentioning features or use of this software
91 * must display the following acknowledgement:
92 * This product includes software developed by the NetBSD
93 * Foundation, Inc. and its contributors.
94 * 4. Neither the name of The NetBSD Foundation nor the names of its
95 * contributors may be used to endorse or promote products derived
96 * from this software without specific prior written permission.
97 *
98 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
99 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
100 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
102 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
103 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
104 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
105 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
106 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
107 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108 * POSSIBILITY OF SUCH DAMAGE.
109 */
110
111/*
112 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
113 *
114 * Taken from NetBSD
115 *
116 * "Stub" to allow remote cpu to debug over a serial line using gdb.
117 */
118
119#include <sys/signal.h>
120
121#include <string>
122#include <unistd.h>
123
124#include "arch/vtophys.hh"
125#include "arch/sparc/remote_gdb.hh"
126#include "base/intmath.hh"
127#include "base/remote_gdb.hh"
128#include "base/socket.hh"
129#include "base/trace.hh"
130#include "config/full_system.hh"
131#include "cpu/thread_context.hh"
132#include "cpu/static_inst.hh"
133#include "mem/physical.hh"
134#include "mem/port.hh"
135#include "sim/system.hh"
136
137using namespace std;
138using namespace TheISA;
139
140RemoteGDB::RemoteGDB(System *_system, ThreadContext *c)
141 : BaseRemoteGDB(_system, c, NumGDBRegs), nextBkpt(0)
142{}
143
144///////////////////////////////////////////////////////////
145// RemoteGDB::acc
146//
147// Determine if the mapping at va..(va+len) is valid.
148//
149bool
150RemoteGDB::acc(Addr va, size_t len)
151{
152 //@Todo In NetBSD, this function checks if all addresses
153 //from va to va + len have valid page mape entries. Not
154 //sure how this will work for other OSes or in general.
155 if (va)
156 return true;
157 return false;
158}
159
160///////////////////////////////////////////////////////////
161// RemoteGDB::getregs
162//
163// Translate the kernel debugger register format into
164// the GDB register format.
165void
166RemoteGDB::getregs()
167{
168 memset(gdbregs.regs, 0, gdbregs.size);
169
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31/*
32 * Copyright (c) 1990, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * This software was developed by the Computer Systems Engineering group
36 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
37 * contributed to Berkeley.
38 *
39 * All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Lawrence Berkeley Laboratories.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by the University of
55 * California, Berkeley and its contributors.
56 * 4. Neither the name of the University nor the names of its contributors
57 * may be used to endorse or promote products derived from this software
58 * without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
73 */
74
75/*-
76 * Copyright (c) 2001 The NetBSD Foundation, Inc.
77 * All rights reserved.
78 *
79 * This code is derived from software contributed to The NetBSD Foundation
80 * by Jason R. Thorpe.
81 *
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
84 * are met:
85 * 1. Redistributions of source code must retain the above copyright
86 * notice, this list of conditions and the following disclaimer.
87 * 2. Redistributions in binary form must reproduce the above copyright
88 * notice, this list of conditions and the following disclaimer in the
89 * documentation and/or other materials provided with the distribution.
90 * 3. All advertising materials mentioning features or use of this software
91 * must display the following acknowledgement:
92 * This product includes software developed by the NetBSD
93 * Foundation, Inc. and its contributors.
94 * 4. Neither the name of The NetBSD Foundation nor the names of its
95 * contributors may be used to endorse or promote products derived
96 * from this software without specific prior written permission.
97 *
98 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
99 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
100 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
102 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
103 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
104 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
105 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
106 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
107 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108 * POSSIBILITY OF SUCH DAMAGE.
109 */
110
111/*
112 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
113 *
114 * Taken from NetBSD
115 *
116 * "Stub" to allow remote cpu to debug over a serial line using gdb.
117 */
118
119#include <sys/signal.h>
120
121#include <string>
122#include <unistd.h>
123
124#include "arch/vtophys.hh"
125#include "arch/sparc/remote_gdb.hh"
126#include "base/intmath.hh"
127#include "base/remote_gdb.hh"
128#include "base/socket.hh"
129#include "base/trace.hh"
130#include "config/full_system.hh"
131#include "cpu/thread_context.hh"
132#include "cpu/static_inst.hh"
133#include "mem/physical.hh"
134#include "mem/port.hh"
135#include "sim/system.hh"
136
137using namespace std;
138using namespace TheISA;
139
140RemoteGDB::RemoteGDB(System *_system, ThreadContext *c)
141 : BaseRemoteGDB(_system, c, NumGDBRegs), nextBkpt(0)
142{}
143
144///////////////////////////////////////////////////////////
145// RemoteGDB::acc
146//
147// Determine if the mapping at va..(va+len) is valid.
148//
149bool
150RemoteGDB::acc(Addr va, size_t len)
151{
152 //@Todo In NetBSD, this function checks if all addresses
153 //from va to va + len have valid page mape entries. Not
154 //sure how this will work for other OSes or in general.
155 if (va)
156 return true;
157 return false;
158}
159
160///////////////////////////////////////////////////////////
161// RemoteGDB::getregs
162//
163// Translate the kernel debugger register format into
164// the GDB register format.
165void
166RemoteGDB::getregs()
167{
168 memset(gdbregs.regs, 0, gdbregs.size);
169
170 if (context->readMiscRegWithEffect(MISCREG_PSTATE) &
170 if (context->readMiscReg(MISCREG_PSTATE) &
171 PSTATE::am) {
172 uint32_t *regs;
173 regs = (uint32_t*)gdbregs.regs;
174 regs[Reg32Pc] = htobe((uint32_t)context->readPC());
175 regs[Reg32Npc] = htobe((uint32_t)context->readNextPC());
176 for(int x = RegG0; x <= RegI0 + 7; x++)
177 regs[x] = htobe((uint32_t)context->readIntReg(x - RegG0));
178
179 regs[Reg32Y] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
171 PSTATE::am) {
172 uint32_t *regs;
173 regs = (uint32_t*)gdbregs.regs;
174 regs[Reg32Pc] = htobe((uint32_t)context->readPC());
175 regs[Reg32Npc] = htobe((uint32_t)context->readNextPC());
176 for(int x = RegG0; x <= RegI0 + 7; x++)
177 regs[x] = htobe((uint32_t)context->readIntReg(x - RegG0));
178
179 regs[Reg32Y] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
180 regs[Reg32Psr] = htobe((uint32_t)context->readMiscRegWithEffect(MISCREG_PSTATE));
181 regs[Reg32Fsr] = htobe((uint32_t)context->readMiscRegWithEffect(MISCREG_FSR));
180 regs[Reg32Psr] = htobe((uint32_t)context->readMiscReg(MISCREG_PSTATE));
181 regs[Reg32Fsr] = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
182 regs[Reg32Csr] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
183 } else {
184 gdbregs.regs[RegPc] = htobe(context->readPC());
185 gdbregs.regs[RegNpc] = htobe(context->readNextPC());
186 for(int x = RegG0; x <= RegI0 + 7; x++)
187 gdbregs.regs[x] = htobe(context->readIntReg(x - RegG0));
188
182 regs[Reg32Csr] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
183 } else {
184 gdbregs.regs[RegPc] = htobe(context->readPC());
185 gdbregs.regs[RegNpc] = htobe(context->readNextPC());
186 for(int x = RegG0; x <= RegI0 + 7; x++)
187 gdbregs.regs[x] = htobe(context->readIntReg(x - RegG0));
188
189 gdbregs.regs[RegFsr] = htobe(context->readMiscRegWithEffect(MISCREG_FSR));
190 gdbregs.regs[RegFprs] = htobe(context->readMiscRegWithEffect(MISCREG_FPRS));
189 gdbregs.regs[RegFsr] = htobe(context->readMiscReg(MISCREG_FSR));
190 gdbregs.regs[RegFprs] = htobe(context->readMiscReg(MISCREG_FPRS));
191 gdbregs.regs[RegY] = htobe(context->readIntReg(NumIntArchRegs + 1));
192 gdbregs.regs[RegState] = htobe(
191 gdbregs.regs[RegY] = htobe(context->readIntReg(NumIntArchRegs + 1));
192 gdbregs.regs[RegState] = htobe(
193 context->readMiscRegWithEffect(MISCREG_CWP) |
194 context->readMiscRegWithEffect(MISCREG_PSTATE) << 8 |
195 context->readMiscRegWithEffect(MISCREG_ASI) << 24 |
193 context->readMiscReg(MISCREG_CWP) |
194 context->readMiscReg(MISCREG_PSTATE) << 8 |
195 context->readMiscReg(MISCREG_ASI) << 24 |
196 context->readIntReg(NumIntArchRegs + 2) << 32);
197 }
198
199 DPRINTF(GDBRead, "PC=%#x\n", gdbregs.regs[RegPc]);
200
201 //Floating point registers are left at 0 in netbsd
202 //All registers other than the pc, npc and int regs
203 //are ignored as well.
204}
205
206///////////////////////////////////////////////////////////
207// RemoteGDB::setregs
208//
209// Translate the GDB register format into the kernel
210// debugger register format.
211//
212void
213RemoteGDB::setregs()
214{
215 context->setPC(gdbregs.regs[RegPc]);
216 context->setNextPC(gdbregs.regs[RegNpc]);
217 for(int x = RegG0; x <= RegI0 + 7; x++)
218 context->setIntReg(x - RegG0, gdbregs.regs[x]);
219 //Only the integer registers, pc and npc are set in netbsd
220}
221
222void
223RemoteGDB::clearSingleStep()
224{
225 if (nextBkpt)
226 clearTempBreakpoint(nextBkpt);
227}
228
229void
230RemoteGDB::setSingleStep()
231{
232 nextBkpt = context->readNextPC();
233 setTempBreakpoint(nextBkpt);
234}
196 context->readIntReg(NumIntArchRegs + 2) << 32);
197 }
198
199 DPRINTF(GDBRead, "PC=%#x\n", gdbregs.regs[RegPc]);
200
201 //Floating point registers are left at 0 in netbsd
202 //All registers other than the pc, npc and int regs
203 //are ignored as well.
204}
205
206///////////////////////////////////////////////////////////
207// RemoteGDB::setregs
208//
209// Translate the GDB register format into the kernel
210// debugger register format.
211//
212void
213RemoteGDB::setregs()
214{
215 context->setPC(gdbregs.regs[RegPc]);
216 context->setNextPC(gdbregs.regs[RegNpc]);
217 for(int x = RegG0; x <= RegI0 + 7; x++)
218 context->setIntReg(x - RegG0, gdbregs.regs[x]);
219 //Only the integer registers, pc and npc are set in netbsd
220}
221
222void
223RemoteGDB::clearSingleStep()
224{
225 if (nextBkpt)
226 clearTempBreakpoint(nextBkpt);
227}
228
229void
230RemoteGDB::setSingleStep()
231{
232 nextBkpt = context->readNextPC();
233 setTempBreakpoint(nextBkpt);
234}