gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
remote_gdb.cc
Go to the documentation of this file.
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 
148 using namespace std;
149 using namespace RiscvISA;
150 
151 RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
152  : BaseRemoteGDB(_system, tc), regCache(this)
153 {
154 }
155 
156 bool
158 {
159  TlbEntry entry;
160  if (FullSystem)
161  panic("acc not implemented for RISCV FS!");
162  else
163  return context->getProcessPtr()->pTable->lookup(va, entry);
164 }
165 
166 void
168 {
169  DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
170  for (int i = 0; i < NumIntArchRegs; i++)
171  r.gpr[i] = context->readIntReg(i);
172  r.pc = context->pcState().pc();
173  for (int i = 0; i < NumFloatRegs; i++)
174  r.fpr[i] = context->readFloatRegBits(i);
175 
176  r.csr_base = context->readMiscReg(0);
177  r.fflags = context->readMiscReg(MISCREG_FFLAGS);
178  r.frm = context->readMiscReg(MISCREG_FRM);
179  r.fcsr = context->readMiscReg(MISCREG_FCSR);
180  for (int i = ExplicitCSRs; i < NumMiscRegs; i++)
181  r.csr[i - ExplicitCSRs] = context->readMiscReg(i);
182 }
183 
184 void
186 {
187  DPRINTF(GDBAcc, "setregs in remotegdb \n");
188  for (int i = 0; i < NumIntArchRegs; i++)
189  context->setIntReg(i, r.gpr[i]);
190  context->pcState(r.pc);
191  for (int i = 0; i < NumFloatRegs; i++)
192  context->setFloatRegBits(i, r.fpr[i]);
193 
194  context->setMiscReg(0, r.csr_base);
195  context->setMiscReg(MISCREG_FFLAGS, r.fflags);
196  context->setMiscReg(MISCREG_FRM, r.frm);
197  context->setMiscReg(MISCREG_FCSR, r.fcsr);
198  for (int i = ExplicitCSRs; i < NumMiscRegs; i++)
199  context->setMiscReg(i, r.csr[i - ExplicitCSRs]);
200 }
201 
204  return &regCache;
205 }
#define DPRINTF(x,...)
Definition: trace.hh:212
const int NumFloatRegs
Definition: registers.hh:73
const int NumIntArchRegs
Definition: registers.hh:70
#define panic(...)
Definition: misc.hh:153
size_t size() const
Return the size of the raw buffer, in bytes (i.e., half of the number of digits in the g/G packet)...
Definition: remote_gdb.hh:74
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
virtual Process * getProcessPtr()=0
Definition: system.hh:83
virtual void setIntReg(int reg_idx, uint64_t val)=0
virtual FloatRegBits readFloatRegBits(int reg_idx)=0
virtual TheISA::PCState pcState()=0
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:167
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:183
virtual void setFloatRegBits(int reg_idx, FloatRegBits val)=0
const int NumMiscRegs
Definition: registers.hh:75
ThreadContext * context
Definition: remote_gdb.hh:173
virtual uint64_t readIntReg(int reg_idx)=0
Bitfield< 2 > i
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Bitfield< 8 > va
Definition: miscregs.hh:1473
static const int ExplicitCSRs
Definition: remote_gdb.hh:53
PageTableBase * pTable
Definition: process.hh:178
virtual MiscReg readMiscReg(int misc_reg)=0
Declarations of a non-full system Page Table.
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:185
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry)=0
Lookup function.
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:203
RiscvGdbRegCache regCache
Definition: remote_gdb.hh:85
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:157

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6