2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
32 * Copyright (c) 1990, 1993
33 * The Regents of the University of California. All rights reserved.
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.
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.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
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.
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
72 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
76 * Copyright (c) 2001 The NetBSD Foundation, Inc.
77 * All rights reserved.
79 * This code is derived from software contributed to The NetBSD Foundation
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
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.
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.
112 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
116 * "Stub" to allow remote cpu to debug over a serial line using gdb.
119 #include <sys/signal.h>
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"
138 using namespace TheISA
;
140 RemoteGDB::RemoteGDB(System
*_system
, ThreadContext
*c
)
141 : BaseRemoteGDB(_system
, c
, NumGDBRegs
)
144 ///////////////////////////////////////////////////////////
147 // Determine if the mapping at va..(va+len) is valid.
150 RemoteGDB::acc(Addr va
, size_t len
)
155 va
= TheISA::TruncPage(va
);
156 last_va
= TheISA::RoundPage(va
+ len
);
159 if (TheISA::IsK0Seg(va
)) {
160 if (va
< (TheISA::K0SegBase
+ pmem
->size())) {
161 DPRINTF(GDBAcc
, "acc: Mapping is valid K0SEG <= "
162 "%#x < K0SEG + size\n", va
);
165 DPRINTF(GDBAcc
, "acc: Mapping invalid %#x > K0SEG + size\n",
172 * This code says that all accesses to palcode (instruction and data)
173 * are valid since there isn't a va->pa mapping because palcode is
174 * accessed physically. At some point this should probably be cleaned up
175 * but there is no easy way to do it.
178 if (AlphaISA::PcPAL(va
) || va
< 0x10000)
181 Addr ptbr
= context
->readMiscReg(AlphaISA::IPR_PALtemp20
);
182 TheISA::PageTableEntry pte
= TheISA::kernel_pte_lookup(context
->getPhysPort(), ptbr
, va
);
184 DPRINTF(GDBAcc
, "acc: %#x pte is invalid\n", va
);
187 va
+= TheISA::PageBytes
;
188 } while (va
< last_va
);
190 DPRINTF(GDBAcc
, "acc: %#x mapping is valid\n", va
);
195 ///////////////////////////////////////////////////////////
196 // RemoteGDB::getregs
198 // Translate the kernel debugger register format into
199 // the GDB register format.
203 memset(gdbregs
.regs
, 0, gdbregs
.size
);
205 gdbregs
.regs
[RegPc
] = context
->readPC();
206 gdbregs
.regs
[RegNpc
] = context
->readNextPC();
207 for(int x
= RegG0
; x
<= RegI7
; x
++)
208 gdbregs
.regs
[x
] = context
->readIntReg(x
- RegG0
);
209 for(int x
= RegF0
; x
<= RegF31
; x
++)
210 gdbregs
.regs
[x
] = context
->readFloatRegBits(x
- RegF0
);
211 gdbregs
.regs
[RegY
] = context
->readMiscReg(MISCREG_Y
);
212 //XXX need to also load up Psr, Wim, Tbr, Fpsr, and Cpsr
215 ///////////////////////////////////////////////////////////
216 // RemoteGDB::setregs
218 // Translate the GDB register format into the kernel
219 // debugger register format.
224 context
->setPC(gdbregs
.regs
[RegPc
]);
225 context
->setNextPC(gdbregs
.regs
[RegNpc
]);
226 for(int x
= RegG0
; x
<= RegI7
; x
++)
227 context
->setIntReg(x
- RegG0
, gdbregs
.regs
[x
]);
228 for(int x
= RegF0
; x
<= RegF31
; x
++)
229 context
->setFloatRegBits(x
- RegF0
, gdbregs
.regs
[x
]);
230 context
->setMiscRegWithEffect(MISCREG_Y
, gdbregs
.regs
[RegY
]);
231 //XXX need to also set Psr, Wim, Tbr, Fpsr, and Cpsr
235 RemoteGDB::clearSingleStep()
238 DPRINTF(GDBMisc
, "clearSingleStep bt_addr=%#x nt_addr=%#x\n",
239 takenBkpt
.address
, notTakenBkpt
.address
);
241 if (takenBkpt
.address
!= 0)
242 clearTempBreakpoint(takenBkpt
);
244 if (notTakenBkpt
.address
!= 0)
245 clearTempBreakpoint(notTakenBkpt
);
250 RemoteGDB::setSingleStep()
253 Addr pc
= context
->readPC();
257 npc
= pc
+ sizeof(MachInst
);
259 // User was stopped at pc, e.g. the instruction at pc was not
261 MachInst inst
= read
<MachInst
>(pc
);
262 StaticInstPtr
si(inst
);
263 if (si
->hasBranchTarget(pc
, context
, bpc
)) {
264 // Don't bother setting a breakpoint on the taken branch if it
265 // is the same as the next pc
270 DPRINTF(GDBMisc
, "setSingleStep bt_addr=%#x nt_addr=%#x\n",
271 takenBkpt
.address
, notTakenBkpt
.address
);
273 setTempBreakpoint(notTakenBkpt
, npc
);
276 setTempBreakpoint(takenBkpt
, bpc
);