remote_gdb.cc revision 13611:c8b7847b4171
1/*
2 * Copyright 2015 LabWare
3 * Copyright 2014 Google, Inc.
4 * Copyright (c) 2010 ARM Limited
5 * All rights reserved
6 *
7 * The license below extends only to copyright in the software and shall
8 * not be construed as granting a license to any other intellectual
9 * property including but not limited to intellectual property relating
10 * to a hardware implementation of the functionality of the software
11 * licensed hereunder.  You may use the software subject to the license
12 * terms below provided that you ensure that this notice is replicated
13 * unmodified and in its entirety in all distributions of the software,
14 * modified or unmodified, in source code or in binary form.
15 *
16 * Copyright (c) 2002-2005 The Regents of The University of Michigan
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Authors: Nathan Binkert
43 *          William Wang
44 *          Deyuan Guo
45 *          Boris Shingarov
46 */
47
48/*
49 * Copyright (c) 1990, 1993 The Regents of the University of California
50 * All rights reserved
51 *
52 * This software was developed by the Computer Systems Engineering group
53 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
54 * contributed to Berkeley.
55 *
56 * All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 *      This product includes software developed by the University of
59 *      California, Lawrence Berkeley Laboratories.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 * 1. Redistributions of source code must retain the above copyright
65 *    notice, this list of conditions and the following disclaimer.
66 * 2. Redistributions in binary form must reproduce the above copyright
67 *    notice, this list of conditions and the following disclaimer in the
68 *    documentation and/or other materials provided with the distribution.
69 * 3. All advertising materials mentioning features or use of this software
70 *    must display the following acknowledgement:
71 *      This product includes software developed by the University of
72 *      California, Berkeley and its contributors.
73 * 4. Neither the name of the University nor the names of its contributors
74 *    may be used to endorse or promote products derived from this software
75 *    without specific prior written permission.
76 *
77 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
78 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
79 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
80 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
87 * SUCH DAMAGE.
88 *
89 *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
90 */
91
92/*-
93 * Copyright (c) 2001 The NetBSD Foundation, Inc.
94 * All rights reserved.
95 *
96 * This code is derived from software contributed to The NetBSD Foundation
97 * by Jason R. Thorpe.
98 *
99 * Redistribution and use in source and binary forms, with or without
100 * modification, are permitted provided that the following conditions
101 * are met:
102 * 1. Redistributions of source code must retain the above copyright
103 *    notice, this list of conditions and the following disclaimer.
104 * 2. Redistributions in binary form must reproduce the above copyright
105 *    notice, this list of conditions and the following disclaimer in the
106 *    documentation and/or other materials provided with the distribution.
107 * 3. All advertising materials mentioning features or use of this software
108 *    must display the following acknowledgement:
109 *      This product includes software developed by the NetBSD
110 *      Foundation, Inc. and its contributors.
111 * 4. Neither the name of The NetBSD Foundation nor the names of its
112 *    contributors may be used to endorse or promote products derived
113 *    from this software without specific prior written permission.
114 *
115 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
116 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
117 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
118 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
119 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
120 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
121 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
122 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
123 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
124 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
125 * POSSIBILITY OF SUCH DAMAGE.
126 */
127
128/*
129 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
130 *
131 * Taken from NetBSD
132 *
133 * "Stub" to allow remote cpu to debug over a serial line using gdb.
134 */
135
136#include "arch/mips/remote_gdb.hh"
137
138#include <sys/signal.h>
139#include <unistd.h>
140
141#include <string>
142
143#include "arch/mips/decoder.hh"
144#include "arch/mips/vtophys.hh"
145#include "cpu/thread_state.hh"
146#include "debug/GDBAcc.hh"
147#include "debug/GDBMisc.hh"
148#include "mem/page_table.hh"
149#include "sim/full_system.hh"
150
151using namespace std;
152using namespace MipsISA;
153
154RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
155    : BaseRemoteGDB(_system, tc, _port), regCache(this)
156{
157}
158
159/*
160 * Determine if the mapping at va..(va+len) is valid.
161 */
162bool
163RemoteGDB::acc(Addr va, size_t len)
164{
165    // Check to make sure the first byte is mapped into the processes address
166    // space.
167    panic_if(FullSystem, "acc not implemented for MIPS FS!");
168    return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
169}
170
171void
172RemoteGDB::MipsGdbRegCache::getRegs(ThreadContext *context)
173{
174    DPRINTF(GDBAcc, "getregs in remotegdb \n");
175
176    for (int i = 0; i < 32; i++) r.gpr[i] = context->readIntReg(i);
177    r.sr = context->readMiscRegNoEffect(MISCREG_STATUS);
178    r.lo = context->readIntReg(INTREG_LO);
179    r.hi = context->readIntReg(INTREG_HI);
180    r.badvaddr = context->readMiscRegNoEffect(MISCREG_BADVADDR);
181    r.cause = context->readMiscRegNoEffect(MISCREG_CAUSE);
182    r.pc = context->pcState().pc();
183    for (int i = 0; i < 32; i++) r.fpr[i] = context->readFloatReg(i);
184    r.fsr = context->readFloatReg(FLOATREG_FCCR);
185    r.fir = context->readFloatReg(FLOATREG_FIR);
186}
187
188void
189RemoteGDB::MipsGdbRegCache::setRegs(ThreadContext *context) const
190{
191    DPRINTF(GDBAcc, "setregs in remotegdb \n");
192
193    for (int i = 1; i < 32; i++) context->setIntReg(i, r.gpr[i]);
194    context->setMiscRegNoEffect(MISCREG_STATUS, r.sr);
195    context->setIntReg(INTREG_LO, r.lo);
196    context->setIntReg(INTREG_HI, r.hi);
197    context->setMiscRegNoEffect(MISCREG_BADVADDR, r.badvaddr);
198    context->setMiscRegNoEffect(MISCREG_CAUSE, r.cause);
199    context->pcState(r.pc);
200    for (int i = 0; i < 32; i++) context->setFloatReg(i, r.fpr[i]);
201    context->setFloatReg(FLOATREG_FCCR, r.fsr);
202    context->setFloatReg(FLOATREG_FIR, r.fir);
203}
204
205BaseGdbRegCache*
206RemoteGDB::gdbRegs()
207{
208    return &regCache;
209}
210