remote_gdb.cc revision 13611:c8b7847b4171
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright 2014 Google, Inc.
312855Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
412855Sgabeblack@google.com * All rights reserved.
512855Sgabeblack@google.com *
612855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512855Sgabeblack@google.com * this software without specific prior written permission.
1612855Sgabeblack@google.com *
1712855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812855Sgabeblack@google.com *
2912855Sgabeblack@google.com * Authors: Nathan Binkert
3012855Sgabeblack@google.com */
3112855Sgabeblack@google.com
3212855Sgabeblack@google.com/*
3312855Sgabeblack@google.com * Copyright (c) 1990, 1993 The Regents of the University of California
3412855Sgabeblack@google.com * All rights reserved.
3512855Sgabeblack@google.com *
3612855Sgabeblack@google.com * This software was developed by the Computer Systems Engineering group
3712855Sgabeblack@google.com * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
3812855Sgabeblack@google.com * contributed to Berkeley.
3912855Sgabeblack@google.com *
4012855Sgabeblack@google.com * All advertising materials mentioning features or use of this software
4112855Sgabeblack@google.com * must display the following acknowledgement:
4212855Sgabeblack@google.com *      This product includes software developed by the University of
4312855Sgabeblack@google.com *      California, Lawrence Berkeley Laboratories.
4412855Sgabeblack@google.com *
4512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
4612855Sgabeblack@google.com * modification, are permitted provided that the following conditions
4712855Sgabeblack@google.com * are met:
4812855Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright
4912855Sgabeblack@google.com *    notice, this list of conditions and the following disclaimer.
5012855Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright
5112855Sgabeblack@google.com *    notice, this list of conditions and the following disclaimer in the
5212855Sgabeblack@google.com *    documentation and/or other materials provided with the distribution.
5312855Sgabeblack@google.com * 3. All advertising materials mentioning features or use of this software
5412855Sgabeblack@google.com *    must display the following acknowledgement:
5512855Sgabeblack@google.com *      This product includes software developed by the University of
5612855Sgabeblack@google.com *      California, Berkeley and its contributors.
5712855Sgabeblack@google.com * 4. Neither the name of the University nor the names of its contributors
5812855Sgabeblack@google.com *    may be used to endorse or promote products derived from this software
5912855Sgabeblack@google.com *    without specific prior written permission.
6012855Sgabeblack@google.com *
6112855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
6212855Sgabeblack@google.com * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6312855Sgabeblack@google.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6412855Sgabeblack@google.com * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
6512855Sgabeblack@google.com * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6612855Sgabeblack@google.com * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6712855Sgabeblack@google.com * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6812855Sgabeblack@google.com * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6912855Sgabeblack@google.com * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7012855Sgabeblack@google.com * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7112855Sgabeblack@google.com * SUCH DAMAGE.
7212855Sgabeblack@google.com *
7312855Sgabeblack@google.com *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
7412855Sgabeblack@google.com */
7512855Sgabeblack@google.com
7612855Sgabeblack@google.com/*-
7712855Sgabeblack@google.com * Copyright (c) 2001 The NetBSD Foundation, Inc.
7812855Sgabeblack@google.com * All rights reserved.
7912855Sgabeblack@google.com *
8012855Sgabeblack@google.com * This code is derived from software contributed to The NetBSD Foundation
8112855Sgabeblack@google.com * by Jason R. Thorpe.
8212855Sgabeblack@google.com *
8312855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
8412855Sgabeblack@google.com * modification, are permitted provided that the following conditions
8512855Sgabeblack@google.com * are met:
8612855Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright
8712855Sgabeblack@google.com *    notice, this list of conditions and the following disclaimer.
8812855Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright
8912855Sgabeblack@google.com *    notice, this list of conditions and the following disclaimer in the
9012855Sgabeblack@google.com *    documentation and/or other materials provided with the distribution.
9112855Sgabeblack@google.com * 3. All advertising materials mentioning features or use of this software
9212855Sgabeblack@google.com *    must display the following acknowledgement:
9312855Sgabeblack@google.com *      This product includes software developed by the NetBSD
9412855Sgabeblack@google.com *      Foundation, Inc. and its contributors.
9512855Sgabeblack@google.com * 4. Neither the name of The NetBSD Foundation nor the names of its
9612855Sgabeblack@google.com *    contributors may be used to endorse or promote products derived
9712855Sgabeblack@google.com *    from this software without specific prior written permission.
9812855Sgabeblack@google.com *
9912855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
10012855Sgabeblack@google.com * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
10112855Sgabeblack@google.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
102 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
103 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
104 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
105 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
106 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
107 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
108 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
109 * POSSIBILITY OF SUCH DAMAGE.
110 */
111
112/*
113 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
114 *
115 * Taken from NetBSD
116 *
117 * "Stub" to allow remote cpu to debug over a serial line using gdb.
118 */
119
120#include "arch/alpha/remote_gdb.hh"
121
122#include <sys/signal.h>
123#include <unistd.h>
124
125#include <string>
126
127#include "arch/alpha/decoder.hh"
128#include "arch/alpha/regredir.hh"
129#include "arch/alpha/utility.hh"
130#include "arch/alpha/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/GDBMisc.hh"
139#include "mem/physical.hh"
140#include "mem/port.hh"
141#include "sim/full_system.hh"
142#include "sim/system.hh"
143
144using namespace std;
145using namespace AlphaISA;
146
147RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
148    : BaseRemoteGDB(_system, tc, _port)
149{
150    warn_once("Breakpoints do not work in Alpha PAL mode.\n"
151              "      See PCEventQueue::doService() in cpu/pc_event.cc.\n");
152}
153
154/*
155 * Determine if the mapping at va..(va+len) is valid.
156 */
157bool
158RemoteGDB::acc(Addr va, size_t len)
159{
160    if (!FullSystem)
161        panic("acc function needs to be rewritten for SE mode\n");
162
163    Addr last_va;
164
165    va = TruncPage(va);
166    last_va = RoundPage(va + len);
167
168    do  {
169        if (IsK0Seg(va)) {
170            if (va < (K0SegBase + system()->memSize())) {
171                DPRINTF(GDBAcc, "acc:   Mapping is valid  K0SEG <= "
172                        "%#x < K0SEG + size\n", va);
173                return true;
174            } else {
175                DPRINTF(GDBAcc, "acc:   Mapping invalid %#x "
176                        "> K0SEG + size\n", va);
177                return false;
178            }
179        }
180
181        /**
182         * This code says that all accesses to palcode (instruction
183         * and data) are valid since there isn't a va->pa mapping
184         * because palcode is accessed physically. At some point this
185         * should probably be cleaned up but there is no easy way to
186         * do it.
187         */
188
189        if (PcPAL(va) || va < 0x10000)
190            return true;
191
192        Addr ptbr = context()->readMiscRegNoEffect(IPR_PALtemp20);
193        PageTableEntry pte =
194            kernel_pte_lookup(context()->getPhysProxy(), ptbr, va);
195        if (!pte.valid()) {
196            DPRINTF(GDBAcc, "acc:   %#x pte is invalid\n", va);
197            return false;
198        }
199        va += PageBytes;
200    } while (va < last_va);
201
202    DPRINTF(GDBAcc, "acc:   %#x mapping is valid\n", va);
203    return true;
204}
205
206void
207RemoteGDB::AlphaGdbRegCache::getRegs(ThreadContext *context)
208{
209    DPRINTF(GDBAcc, "getRegs in remotegdb \n");
210
211    r.pc = context->pcState().pc();
212
213    if (PcPAL(r.pc)) {
214        for (int i = 0; i < 32; ++i)
215            r.gpr[i] = context->readIntReg(reg_redir[i]);
216    } else {
217        for (int i = 0; i < 32; ++i)
218            r.gpr[i] = context->readIntReg(i);
219    }
220
221    for (int i = 0; i < 32; ++i)
222#ifdef KGDB_FP_REGS
223       r.fpr[i] = context->readFloatReg(i);
224#else
225       r.fpr[i] = 0;
226#endif
227}
228
229void
230RemoteGDB::AlphaGdbRegCache::setRegs(ThreadContext *context) const
231{
232    DPRINTF(GDBAcc, "setRegs in remotegdb \n");
233
234    if (PcPAL(r.pc)) {
235        for (int i = 0; i < 32; ++i) {
236            context->setIntReg(reg_redir[i], r.gpr[i]);
237        }
238    } else {
239        for (int i = 0; i < 32; ++i) {
240            context->setIntReg(i, r.gpr[i]);
241        }
242    }
243
244#ifdef KGDB_FP_REGS
245    for (int i = 0; i < NumFloatArchRegs; ++i) {
246        context->setFloatReg(i, gdbregs.regs64[i + KGDB_REG_F0]);
247    }
248#endif
249    context->pcState(r.pc);
250}
251
252
253BaseGdbRegCache*
254RemoteGDB::gdbRegs()
255{
256    return new AlphaGdbRegCache(this);
257}
258
259