remote_gdb.cc revision 11274
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/power/remote_gdb.hh"
137
138#include <sys/signal.h>
139#include <unistd.h>
140
141#include <string>
142
143#include "arch/power/vtophys.hh"
144#include "cpu/thread_state.hh"
145#include "debug/GDBAcc.hh"
146#include "debug/GDBMisc.hh"
147#include "sim/byteswap.hh"
148
149using namespace std;
150using namespace PowerISA;
151
152RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
153    : BaseRemoteGDB(_system, tc)
154{
155}
156
157/*
158 * Determine if the mapping at va..(va+len) is valid.
159 */
160bool
161RemoteGDB::acc(Addr va, size_t len)
162{
163    TlbEntry entry;
164    //Check to make sure the first byte is mapped into the processes address
165    //space.  At the time of this writing, the acc() check is used when
166    //processing the MemR/MemW packets before actually asking the translating
167    //port proxy to read/writeBlob.  I (bgs) am not convinced the first byte
168    //check is enough.
169    if (FullSystem)
170        panic("acc not implemented for POWER FS!");
171    else
172        return context->getProcessPtr()->pTable->lookup(va, entry);
173}
174
175void
176RemoteGDB::PowerGdbRegCache::getRegs(ThreadContext *context)
177{
178    DPRINTF(GDBAcc, "getRegs in remotegdb \n");
179
180    // Default order on 32-bit PowerPC:
181    // R0-R31 (32-bit each), F0-F31 (64-bit IEEE754 double),
182    // PC, MSR, CR, LR, CTR, XER (32-bit each)
183
184    for (int i = 0; i < NumIntArchRegs; i++)
185        r.gpr[i] = htobe((uint32_t)context->readIntReg(i));
186
187    for (int i = 0; i < NumFloatArchRegs; i++)
188        r.fpr[i] = context->readFloatRegBits(i);
189
190    r.pc = htobe((uint32_t)context->pcState().pc());
191    r.msr = 0; // Is MSR modeled?
192    r.cr = htobe((uint32_t)context->readIntReg(INTREG_CR));
193    r.lr = htobe((uint32_t)context->readIntReg(INTREG_LR));
194    r.ctr = htobe((uint32_t)context->readIntReg(INTREG_CTR));
195    r.xer = htobe((uint32_t)context->readIntReg(INTREG_XER));
196}
197
198void
199RemoteGDB::PowerGdbRegCache::setRegs(ThreadContext *context) const
200{
201    DPRINTF(GDBAcc, "setRegs in remotegdb \n");
202
203    for (int i = 0; i < NumIntArchRegs; i++)
204        context->setIntReg(i, betoh(r.gpr[i]));
205
206    for (int i = 0; i < NumFloatArchRegs; i++)
207        context->setFloatRegBits(i, r.fpr[i]);
208
209    context->pcState(betoh(r.pc));
210    // Is MSR modeled?
211    context->setIntReg(INTREG_CR, betoh(r.cr));
212    context->setIntReg(INTREG_LR, betoh(r.lr));
213    context->setIntReg(INTREG_CTR, betoh(r.ctr));
214    context->setIntReg(INTREG_XER, betoh(r.xer));
215}
216
217RemoteGDB::BaseGdbRegCache*
218RemoteGDB::gdbRegs() {
219    return new PowerGdbRegCache(this);
220}
221
222