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) 2017 The University of Virginia
17 * Copyright (c) 2002-2005 The Regents of The University of Michigan
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are
22 * met: redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer;
24 * redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution;
27 * neither the name of the copyright holders nor the names of its
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * Authors: Nathan Binkert
44 *          William Wang
45 *          Deyuan Guo
46 *          Boris Shingarov
47 *          Alec Roelke
48 */
49
50/*
51 * Copyright (c) 1990, 1993 The Regents of the University of California
52 * All rights reserved
53 *
54 * This software was developed by the Computer Systems Engineering group
55 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
56 * contributed to Berkeley.
57 *
58 * All advertising materials mentioning features or use of this software
59 * must display the following acknowledgement:
60 *      This product includes software developed by the University of
61 *      California, Lawrence Berkeley Laboratories.
62 *
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
65 * are met:
66 * 1. Redistributions of source code must retain the above copyright
67 *    notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 *    notice, this list of conditions and the following disclaimer in the
70 *    documentation and/or other materials provided with the distribution.
71 * 3. All advertising materials mentioning features or use of this software
72 *    must display the following acknowledgement:
73 *      This product includes software developed by the University of
74 *      California, Berkeley and its contributors.
75 * 4. Neither the name of the University nor the names of its contributors
76 *    may be used to endorse or promote products derived from this software
77 *    without specific prior written permission.
78 *
79 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 * SUCH DAMAGE.
90 *
91 *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
92 */
93
94/*-
95 * Copyright (c) 2001 The NetBSD Foundation, Inc.
96 * All rights reserved.
97 *
98 * This code is derived from software contributed to The NetBSD Foundation
99 * by Jason R. Thorpe.
100 *
101 * Redistribution and use in source and binary forms, with or without
102 * modification, are permitted provided that the following conditions
103 * are met:
104 * 1. Redistributions of source code must retain the above copyright
105 *    notice, this list of conditions and the following disclaimer.
106 * 2. Redistributions in binary form must reproduce the above copyright
107 *    notice, this list of conditions and the following disclaimer in the
108 *    documentation and/or other materials provided with the distribution.
109 * 3. All advertising materials mentioning features or use of this software
110 *    must display the following acknowledgement:
111 *      This product includes software developed by the NetBSD
112 *      Foundation, Inc. and its contributors.
113 * 4. Neither the name of The NetBSD Foundation nor the names of its
114 *    contributors may be used to endorse or promote products derived
115 *    from this software without specific prior written permission.
116 *
117 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
118 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
119 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
120 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
121 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
122 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
123 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
124 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
125 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
126 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
127 * POSSIBILITY OF SUCH DAMAGE.
128 */
129
130/*
131 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
132 *
133 * Taken from NetBSD
134 *
135 * "Stub" to allow remote cpu to debug over a serial line using gdb.
136 */
137
138#include "arch/riscv/remote_gdb.hh"
139
140#include <string>
141
142#include "arch/riscv/registers.hh"
143#include "cpu/thread_state.hh"
144#include "debug/GDBAcc.hh"
145#include "mem/page_table.hh"
146#include "sim/full_system.hh"
147
148using namespace std;
149using namespace RiscvISA;
150
151RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
152    : BaseRemoteGDB(_system, tc, _port), regCache(this)
153{
154}
155
156bool
157RemoteGDB::acc(Addr va, size_t len)
158{
159    panic_if(FullSystem, "acc not implemented for RISCV FS!");
160    return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
161}
162
163void
164RemoteGDB::RiscvGdbRegCache::getRegs(ThreadContext *context)
165{
166    DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
167    for (int i = 0; i < NumIntArchRegs; i++)
168        r.gpr[i] = context->readIntReg(i);
169    r.pc = context->pcState().pc();
170    for (int i = 0; i < NumFloatRegs; i++)
171        r.fpr[i] = context->readFloatReg(i);
172
173    r.csr_base = context->readMiscReg(0);
174    r.fflags = context->readMiscReg(CSR_FFLAGS);
175    r.frm = context->readMiscReg(CSR_FRM);
176    r.fcsr = context->readMiscReg(CSR_FCSR);
177    for (int i = ExplicitCSRs; i < NumMiscRegs; i++)
178        r.csr[i - ExplicitCSRs] = context->readMiscReg(i);
179}
180
181void
182RemoteGDB::RiscvGdbRegCache::setRegs(ThreadContext *context) const
183{
184    DPRINTF(GDBAcc, "setregs in remotegdb \n");
185    for (int i = 0; i < NumIntArchRegs; i++)
186        context->setIntReg(i, r.gpr[i]);
187    context->pcState(r.pc);
188    for (int i = 0; i < NumFloatRegs; i++)
189        context->setFloatReg(i, r.fpr[i]);
190
191    context->setMiscReg(0, r.csr_base);
192    context->setMiscReg(CSR_FFLAGS, r.fflags);
193    context->setMiscReg(CSR_FRM, r.frm);
194    context->setMiscReg(CSR_FCSR, r.fcsr);
195    for (int i = ExplicitCSRs; i < NumMiscRegs; i++)
196        context->setMiscReg(i, r.csr[i - ExplicitCSRs]);
197}
198
199BaseGdbRegCache*
200RemoteGDB::gdbRegs()
201{
202    return &regCache;
203}
204