gem5 v25.0.0.1
Loading...
Searching...
No Matches
remote_gdb.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Huawei International
3 * Copyright 2015 LabWare
4 * Copyright 2014 Google, Inc.
5 * Copyright (c) 2010 ARM Limited
6 * Copyright (c) 2020 Barkhausen Institut
7 * All rights reserved
8 *
9 * The license below extends only to copyright in the software and shall
10 * not be construed as granting a license to any other intellectual
11 * property including but not limited to intellectual property relating
12 * to a hardware implementation of the functionality of the software
13 * licensed hereunder. You may use the software subject to the license
14 * terms below provided that you ensure that this notice is replicated
15 * unmodified and in its entirety in all distributions of the software,
16 * modified or unmodified, in source code or in binary form.
17 *
18 * Copyright (c) 2017 The University of Virginia
19 * Copyright (c) 2002-2005 The Regents of The University of Michigan
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are
24 * met: redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer;
26 * redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution;
29 * neither the name of the copyright holders nor the names of its
30 * contributors may be used to endorse or promote products derived from
31 * this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45
46/*
47 * Copyright (c) 1990, 1993 The Regents of the University of California
48 * All rights reserved
49 *
50 * This software was developed by the Computer Systems Engineering group
51 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
52 * contributed to Berkeley.
53 *
54 * All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Lawrence Berkeley Laboratories.
58 *
59 * Redistribution and use in source and binary forms, with or without
60 * modification, are permitted provided that the following conditions
61 * are met:
62 * 1. Redistributions of source code must retain the above copyright
63 * notice, this list of conditions and the following disclaimer.
64 * 2. Redistributions in binary form must reproduce the above copyright
65 * notice, this list of conditions and the following disclaimer in the
66 * documentation and/or other materials provided with the distribution.
67 * 3. All advertising materials mentioning features or use of this software
68 * must display the following acknowledgement:
69 * This product includes software developed by the University of
70 * California, Berkeley and its contributors.
71 * 4. Neither the name of the University nor the names of its contributors
72 * may be used to endorse or promote products derived from this software
73 * without specific prior written permission.
74 *
75 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
76 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
78 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
79 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
80 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
81 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
82 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
83 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
84 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85 * SUCH DAMAGE.
86 *
87 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
88 */
89
90/*-
91 * Copyright (c) 2001 The NetBSD Foundation, Inc.
92 * All rights reserved.
93 *
94 * This code is derived from software contributed to The NetBSD Foundation
95 * by Jason R. Thorpe.
96 *
97 * Redistribution and use in source and binary forms, with or without
98 * modification, are permitted provided that the following conditions
99 * are met:
100 * 1. Redistributions of source code must retain the above copyright
101 * notice, this list of conditions and the following disclaimer.
102 * 2. Redistributions in binary form must reproduce the above copyright
103 * notice, this list of conditions and the following disclaimer in the
104 * documentation and/or other materials provided with the distribution.
105 * 3. All advertising materials mentioning features or use of this software
106 * must display the following acknowledgement:
107 * This product includes software developed by the NetBSD
108 * Foundation, Inc. and its contributors.
109 * 4. Neither the name of The NetBSD Foundation nor the names of its
110 * contributors may be used to endorse or promote products derived
111 * from this software without specific prior written permission.
112 *
113 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
114 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
115 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
116 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
117 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
118 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
119 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
120 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
122 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
123 * POSSIBILITY OF SUCH DAMAGE.
124 */
125
126/*
127 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
128 *
129 * Taken from NetBSD
130 *
131 * "Stub" to allow remote cpu to debug over a serial line using gdb.
132 */
133
135
136#include <string>
137
138#include "arch/riscv/gdb-xml/gdb_xml_riscv_32bit_cpu.hh"
139#include "arch/riscv/gdb-xml/gdb_xml_riscv_32bit_csr.hh"
140#include "arch/riscv/gdb-xml/gdb_xml_riscv_32bit_fpu.hh"
141#include "arch/riscv/gdb-xml/gdb_xml_riscv_32bit_target.hh"
142#include "arch/riscv/gdb-xml/gdb_xml_riscv_64bit_cpu.hh"
143#include "arch/riscv/gdb-xml/gdb_xml_riscv_64bit_csr.hh"
144#include "arch/riscv/gdb-xml/gdb_xml_riscv_64bit_fpu.hh"
145#include "arch/riscv/gdb-xml/gdb_xml_riscv_64bit_target.hh"
146#include "arch/riscv/mmu.hh"
149#include "arch/riscv/regs/int.hh"
151#include "arch/riscv/tlb.hh"
152#include "cpu/thread_state.hh"
153#include "debug/GDBAcc.hh"
154#include "mem/page_table.hh"
155#include "sim/full_system.hh"
156
157namespace gem5
158{
159
160using namespace RiscvISA;
161
162template <typename xint>
163static void
165 ThreadContext *context, RiscvType type, PrivilegeModeSet pms,
166 CSRIndex idx, xint val)
167{
168 RegVal oldVal, newVal;
169 RegVal mask = CSRMasks[type][pms].at(idx);
170 oldVal = context->readMiscRegNoEffect(CSRData.at(idx).physIndex);
171 newVal = (oldVal & ~mask) | (val & mask);
172 context->setMiscRegNoEffect(CSRData.at(idx).physIndex, newVal);
173}
174
175template <typename xint>
176static void
178 ThreadContext *context, RiscvType type, PrivilegeModeSet pms,
179 CSRIndex idx, xint val)
180{
181 RegVal oldVal, newVal;
182 RegVal mask = CSRMasks[type][pms].at(idx);
183 oldVal = context->readMiscReg(CSRData.at(idx).physIndex);
184 newVal = (oldVal & ~mask) | (val & mask);
185 context->setMiscReg(CSRData.at(idx).physIndex, newVal);
186}
187
188RemoteGDB::RemoteGDB(System *_system, ListenSocketConfig _listen_config)
189 : BaseRemoteGDB(_system, _listen_config),
190 regCache32(this), regCache64(this)
191{
192}
193
196{
197 auto isa = dynamic_cast<ISA*>(tc->getIsaPtr());
198 panic_if(!isa, "Cannot derive rv_type from non-riscv isa");
199 return isa->rvType();
200}
201
204{
205 auto isa = dynamic_cast<ISA*>(tc->getIsaPtr());
206 panic_if(!isa, "Cannot derive rv_type from non-riscv isa");
207 return isa->getPrivilegeModeSet();
208}
209
210bool
211RemoteGDB::acc(Addr va, size_t len)
212{
213 if (FullSystem)
214 {
215 MMU *mmu = static_cast<MMU *>(context()->getMMUPtr());
216 unsigned logBytes;
217 Addr paddr = va;
218
219 // TODO: does this need virt as well?
220 PrivilegeMode pmode = mmu->getMemAccessInfo(
221 context(), BaseMMU::Read).priv;
222 SATP satp = context()->readMiscReg(MISCREG_SATP);
223 MISA misa = tc->readMiscRegNoEffect(MISCREG_ISA);
224 if (misa.rvs && pmode != PrivilegeMode::PRV_M &&
225 satp.mode != AddrXlateMode::BARE) {
226 Walker *walker = mmu->getDataWalker();
227 Fault fault = walker->startFunctional(
228 context(), paddr, logBytes, BaseMMU::Read);
229 if (fault != NoFault)
230 return false;
231 }
232 return true;
233 }
234
235 return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
236}
237
238void
240{
241 Addr realAddr = getRvType(context()) == RV64 ? addr : sext(addr, 32);
242 BaseRemoteGDB::insertHardBreak(realAddr, kind);
243}
244
245void
247{
248 Addr realAddr = getRvType(context()) == RV64 ? addr : sext(addr, 32);
249 BaseRemoteGDB::removeHardBreak(realAddr, kind);
250}
251
252void
254{
255 DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
256 RemoteGDB* rv_gdb = dynamic_cast<RemoteGDB*>(gdb);
257 PrivilegeModeSet pms = enums::MSU;
258 if (rv_gdb != nullptr) {
259 pms = rv_gdb->getPrivilegeModeSet(context);
260 }
261 auto& RVxCSRMasks = CSRMasks[RV32][pms];
262
263 // General registers
264 for (int i = 0; i < int_reg::NumArchRegs; i++) {
265 r.gpr[i] = context->getReg(intRegClass[i]);
266 }
267 r.pc = context->pcState().instAddr();
268
269 // Floating point registers
270 for (int i = 0; i < float_reg::NumRegs; i++)
271 r.fpu[i] = context->getReg(floatRegClass[i]);
272 r.fflags = context->readMiscRegNoEffect(
273 CSRData.at(CSR_FFLAGS).physIndex) & RVxCSRMasks.at(CSR_FFLAGS);
274 r.frm = context->readMiscRegNoEffect(
275 CSRData.at(CSR_FRM).physIndex) & RVxCSRMasks.at(CSR_FRM);
276 r.fcsr = context->readMiscReg(
277 CSRData.at(CSR_FCSR).physIndex) & RVxCSRMasks.at(CSR_FCSR);
278
279 // CSR registers
280 r.cycle = context->readMiscRegNoEffect(
281 CSRData.at(CSR_CYCLE).physIndex);
282 r.cycleh = context->readMiscRegNoEffect(
283 CSRData.at(CSR_CYCLEH).physIndex);
284 r.time = context->readMiscRegNoEffect(
285 CSRData.at(CSR_TIME).physIndex);
286 r.timeh = context->readMiscRegNoEffect(
287 CSRData.at(CSR_TIMEH).physIndex);
288
289 // S mode CSR
290 r.sstatus = context->readMiscReg(
291 CSRData.at(CSR_SSTATUS).physIndex) & RVxCSRMasks.at(CSR_SSTATUS);
292 r.sie = context->readMiscReg(
293 CSRData.at(CSR_SIE).physIndex) & RVxCSRMasks.at(CSR_SIE);
294 r.stvec = context->readMiscRegNoEffect(
295 CSRData.at(CSR_STVEC).physIndex);
296 r.scounteren = context->readMiscRegNoEffect(
297 CSRData.at(CSR_SCOUNTEREN).physIndex);
298 r.sscratch = context->readMiscRegNoEffect(
299 CSRData.at(CSR_SSCRATCH).physIndex);
300 r.sepc = context->readMiscReg(
301 CSRData.at(CSR_SEPC).physIndex);
302 r.scause = context->readMiscRegNoEffect(
303 CSRData.at(CSR_SCAUSE).physIndex);
304 r.stval = context->readMiscRegNoEffect(
305 CSRData.at(CSR_STVAL).physIndex);
306 r.sip = context->readMiscReg(
307 CSRData.at(CSR_SIP).physIndex) & RVxCSRMasks.at(CSR_SIP);
308 r.satp = context->readMiscRegNoEffect(
309 CSRData.at(CSR_SATP).physIndex);
310 r.senvcfg = context->readMiscRegNoEffect(
311 CSRData.at(CSR_SENVCFG).physIndex);
312
313 // M mode CSR
314 r.mvendorid = context->readMiscRegNoEffect(
315 CSRData.at(CSR_MVENDORID).physIndex);
316 r.marchid = context->readMiscRegNoEffect(
317 CSRData.at(CSR_MARCHID).physIndex);
318 r.mimpid = context->readMiscRegNoEffect(
319 CSRData.at(CSR_MIMPID).physIndex);
320 r.mhartid = context->contextId();
321 r.mstatus = context->readMiscReg(
322 CSRData.at(CSR_MSTATUS).physIndex) & RVxCSRMasks.at(CSR_MSTATUS);
323 r.misa = context->readMiscRegNoEffect(
324 CSRData.at(CSR_MISA).physIndex) & RVxCSRMasks.at(CSR_MISA);
325 r.medeleg = context->readMiscRegNoEffect(
326 CSRData.at(CSR_MEDELEG).physIndex);
327 r.mideleg = context->readMiscRegNoEffect(
328 CSRData.at(CSR_MIDELEG).physIndex);
329 r.mie = context->readMiscReg(
330 CSRData.at(CSR_MIE).physIndex) & RVxCSRMasks.at(CSR_MIE);
331 r.mtvec = context->readMiscRegNoEffect(
332 CSRData.at(CSR_MTVEC).physIndex);
333 r.mcounteren = context->readMiscRegNoEffect(
334 CSRData.at(CSR_MCOUNTEREN).physIndex);
335 r.mstatush = context->readMiscReg(
336 CSRData.at(CSR_MSTATUSH).physIndex) & RVxCSRMasks.at(CSR_MSTATUSH);
337 r.mscratch = context->readMiscRegNoEffect(
338 CSRData.at(CSR_MSCRATCH).physIndex);
339 r.mepc = context->readMiscReg(
340 CSRData.at(CSR_MEPC).physIndex);
341 r.mcause = context->readMiscRegNoEffect(
342 CSRData.at(CSR_MCAUSE).physIndex);
343 r.mtval = context->readMiscRegNoEffect(
344 CSRData.at(CSR_MTVAL).physIndex);
345 r.mip = context->readMiscReg(
346 CSRData.at(CSR_MIP).physIndex) & RVxCSRMasks.at(CSR_MIP);
347
348 // H mode CSR (to be implemented)
349}
350
351void
353{
354 DPRINTF(GDBAcc, "setregs in remotegdb \n");
355 RemoteGDB* rv_gdb = dynamic_cast<RemoteGDB*>(gdb);
356 PrivilegeModeSet pms = enums::MSU;
357 if (rv_gdb != nullptr) {
358 pms = rv_gdb->getPrivilegeModeSet(context);
359 }
360 for (int i = 0; i < int_reg::NumArchRegs; i++)
361 context->setReg(intRegClass[i], r.gpr[i]);
362 context->pcState(r.pc);
363
364 // Floating point registers
365 for (int i = 0; i < float_reg::NumRegs; i++)
366 context->setReg(floatRegClass[i], r.fpu[i]);
367
370 setRegWithMask(context, RV32, pms, CSR_FCSR, r.fcsr);
371
372 // TODO: implement CSR counter registers for mcycle(h), minstret(h)
373
374 // S mode CSR
375 setRegWithMask(context, RV32, pms, CSR_SSTATUS, r.sstatus);
376 setRegWithMask(context, RV32, pms, CSR_SIE, r.sie);
377 setRegWithMask(context, RV32, pms, CSR_SIP, r.sip);
378 context->setMiscRegNoEffect(
379 CSRData.at(CSR_STVEC).physIndex, r.stvec);
380 context->setMiscRegNoEffect(
381 CSRData.at(CSR_SCOUNTEREN).physIndex, r.scounteren);
382 context->setMiscRegNoEffect(
383 CSRData.at(CSR_SSCRATCH).physIndex, r.sscratch);
384 context->setMiscRegNoEffect(
385 CSRData.at(CSR_SEPC).physIndex, r.sepc);
386 context->setMiscRegNoEffect(
387 CSRData.at(CSR_SCAUSE).physIndex, r.scause);
388 context->setMiscRegNoEffect(
389 CSRData.at(CSR_STVAL).physIndex, r.stval);
390 context->setMiscRegNoEffect(
391 CSRData.at(CSR_SATP).physIndex, r.satp);
392 context->setMiscRegNoEffect(
393 CSRData.at(CSR_SENVCFG).physIndex, r.senvcfg);
394
395 // M mode CSR
396 setRegWithMask(context, RV32, pms, CSR_MSTATUS, r.mstatus);
398 setRegWithMask(context, RV32, pms, CSR_MIE, r.mie);
399 setRegWithMask(context, RV32, pms, CSR_MIP, r.mip);
400 context->setMiscRegNoEffect(
401 CSRData.at(CSR_MEDELEG).physIndex, r.medeleg);
402 context->setMiscRegNoEffect(
403 CSRData.at(CSR_MIDELEG).physIndex, r.mideleg);
404 context->setMiscRegNoEffect(
405 CSRData.at(CSR_MTVEC).physIndex, r.mtvec);
406 context->setMiscRegNoEffect(
407 CSRData.at(CSR_MCOUNTEREN).physIndex, r.mcounteren);
408 context->setMiscRegNoEffect(
409 CSRData.at(CSR_MSCRATCH).physIndex, r.mscratch);
410 context->setMiscRegNoEffect(
411 CSRData.at(CSR_MEPC).physIndex, r.mepc);
412 context->setMiscRegNoEffect(
413 CSRData.at(CSR_MCAUSE).physIndex, r.mcause);
414 context->setMiscRegNoEffect(
415 CSRData.at(CSR_MTVAL).physIndex, r.mtval);
416
417 // H mode CSR (to be implemented)
418}
419
420void
422{
423 DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
424 RemoteGDB* rv_gdb = dynamic_cast<RemoteGDB*>(gdb);
425 PrivilegeModeSet pms = enums::MSU;
426 if (rv_gdb != nullptr) {
427 pms = rv_gdb->getPrivilegeModeSet(context);
428 }
429 auto& RVxCSRMasks = CSRMasks[RV64][pms];
430
431 // General registers
432 for (int i = 0; i < int_reg::NumArchRegs; i++) {
433 r.gpr[i] = context->getReg(intRegClass[i]);
434 }
435 r.pc = context->pcState().instAddr();
436
437 // Floating point registers
438 for (int i = 0; i < float_reg::NumRegs; i++)
439 r.fpu[i] = context->getReg(floatRegClass[i]);
440 r.fflags = context->readMiscRegNoEffect(
441 CSRData.at(CSR_FFLAGS).physIndex) & RVxCSRMasks.at(CSR_FFLAGS);
442 r.frm = context->readMiscRegNoEffect(
443 CSRData.at(CSR_FRM).physIndex) & RVxCSRMasks.at(CSR_FRM);
444 r.fcsr = context->readMiscReg(
445 CSRData.at(CSR_FCSR).physIndex) & RVxCSRMasks.at(CSR_FCSR);
446
447 // CSR registers
448 r.cycle = context->readMiscRegNoEffect(
449 CSRData.at(CSR_CYCLE).physIndex);
450 r.time = context->readMiscRegNoEffect(
451 CSRData.at(CSR_TIME).physIndex);
452
453 // S mode CSR
454 r.sstatus = context->readMiscReg(
455 CSRData.at(CSR_SSTATUS).physIndex) & RVxCSRMasks.at(CSR_SSTATUS);
456 r.sie = context->readMiscReg(
457 CSRData.at(CSR_SIE).physIndex) & RVxCSRMasks.at(CSR_SIE);
458 r.stvec = context->readMiscRegNoEffect(
459 CSRData.at(CSR_STVEC).physIndex);
460 r.scounteren = context->readMiscRegNoEffect(
461 CSRData.at(CSR_SCOUNTEREN).physIndex);
462 r.sscratch = context->readMiscRegNoEffect(
463 CSRData.at(CSR_SSCRATCH).physIndex);
464 r.sepc = context->readMiscReg(
465 CSRData.at(CSR_SEPC).physIndex);
466 r.scause = context->readMiscRegNoEffect(
467 CSRData.at(CSR_SCAUSE).physIndex);
468 r.stval = context->readMiscRegNoEffect(
469 CSRData.at(CSR_STVAL).physIndex);
470 r.sip = context->readMiscReg(
471 CSRData.at(CSR_SIP).physIndex) & RVxCSRMasks.at(CSR_SIP);
472 r.satp = context->readMiscRegNoEffect(
473 CSRData.at(CSR_SATP).physIndex);
474 r.senvcfg = context->readMiscRegNoEffect(
475 CSRData.at(CSR_SENVCFG).physIndex);
476
477 // M mode CSR
478 r.mvendorid = context->readMiscRegNoEffect(
479 CSRData.at(CSR_MVENDORID).physIndex);
480 r.marchid = context->readMiscRegNoEffect(
481 CSRData.at(CSR_MARCHID).physIndex);
482 r.mimpid = context->readMiscRegNoEffect(
483 CSRData.at(CSR_MIMPID).physIndex);
484 r.mhartid = context->contextId();
485 r.mstatus = context->readMiscReg(
486 CSRData.at(CSR_MSTATUS).physIndex) & RVxCSRMasks.at(CSR_MSTATUS);
487 r.misa = context->readMiscRegNoEffect(
488 CSRData.at(CSR_MISA).physIndex) & RVxCSRMasks.at(CSR_MISA);
489 r.medeleg = context->readMiscRegNoEffect(
490 CSRData.at(CSR_MEDELEG).physIndex);
491 r.mideleg = context->readMiscRegNoEffect(
492 CSRData.at(CSR_MIDELEG).physIndex);
493 r.mie = context->readMiscReg(
494 CSRData.at(CSR_MIE).physIndex) & RVxCSRMasks.at(CSR_MIE);
495 r.mtvec = context->readMiscRegNoEffect(
496 CSRData.at(CSR_MTVEC).physIndex);
497 r.mcounteren = context->readMiscRegNoEffect(
498 CSRData.at(CSR_MCOUNTEREN).physIndex);
499 r.mscratch = context->readMiscRegNoEffect(
500 CSRData.at(CSR_MSCRATCH).physIndex);
501 r.mepc = context->readMiscReg(
502 CSRData.at(CSR_MEPC).physIndex);
503 r.mcause = context->readMiscRegNoEffect(
504 CSRData.at(CSR_MCAUSE).physIndex);
505 r.mtval = context->readMiscRegNoEffect(
506 CSRData.at(CSR_MTVAL).physIndex);
507 r.mip = context->readMiscReg(
508 CSRData.at(CSR_MIP).physIndex) & RVxCSRMasks.at(CSR_MIP);
509
510 // H mode CSR (to be implemented)
511}
512
513void
515{
516 DPRINTF(GDBAcc, "setregs in remotegdb \n");
517 RemoteGDB* rv_gdb = dynamic_cast<RemoteGDB*>(gdb);
518 PrivilegeModeSet pms = enums::MSU;
519 if (rv_gdb != nullptr) {
520 pms = rv_gdb->getPrivilegeModeSet(context);
521 }
522 for (int i = 0; i < int_reg::NumArchRegs; i++)
523 context->setReg(intRegClass[i], r.gpr[i]);
524 context->pcState(r.pc);
525
526 // Floating point registers
527 for (int i = 0; i < float_reg::NumRegs; i++)
528 context->setReg(floatRegClass[i], r.fpu[i]);
529
532 setRegWithMask(context, RV64, pms, CSR_FCSR, r.fcsr);
533
534 // TODO: implement CSR counter registers for mcycle, minstret
535
536 // S mode CSR
537 setRegWithMask(context, RV64, pms, CSR_SSTATUS, r.sstatus);
538 setRegWithMask(context, RV64, pms, CSR_SIE, r.sie);
539 setRegWithMask(context, RV64, pms, CSR_SIP, r.sip);
540 context->setMiscRegNoEffect(
541 CSRData.at(CSR_STVEC).physIndex, r.stvec);
542 context->setMiscRegNoEffect(
543 CSRData.at(CSR_SCOUNTEREN).physIndex, r.scounteren);
544 context->setMiscRegNoEffect(
545 CSRData.at(CSR_SSCRATCH).physIndex, r.sscratch);
546 context->setMiscRegNoEffect(
547 CSRData.at(CSR_SEPC).physIndex, r.sepc);
548 context->setMiscRegNoEffect(
549 CSRData.at(CSR_SCAUSE).physIndex, r.scause);
550 context->setMiscRegNoEffect(
551 CSRData.at(CSR_STVAL).physIndex, r.stval);
552 context->setMiscRegNoEffect(
553 CSRData.at(CSR_SATP).physIndex, r.satp);
554 context->setMiscRegNoEffect(
555 CSRData.at(CSR_SENVCFG).physIndex, r.senvcfg);
556 // M mode CSR
557 setRegWithMask(context, RV64, pms, CSR_MSTATUS, r.mstatus);
559 setRegWithMask(context, RV64, pms, CSR_MIE, r.mie);
560 setRegWithMask(context, RV64, pms, CSR_MIP, r.mip);
561 context->setMiscRegNoEffect(
562 CSRData.at(CSR_MEDELEG).physIndex, r.medeleg);
563 context->setMiscRegNoEffect(
564 CSRData.at(CSR_MIDELEG).physIndex, r.mideleg);
565 context->setMiscRegNoEffect(
566 CSRData.at(CSR_MTVEC).physIndex, r.mtvec);
567 context->setMiscRegNoEffect(
568 CSRData.at(CSR_MCOUNTEREN).physIndex, r.mcounteren);
569 context->setMiscRegNoEffect(
570 CSRData.at(CSR_MSCRATCH).physIndex, r.mscratch);
571 context->setMiscRegNoEffect(
572 CSRData.at(CSR_MEPC).physIndex, r.mepc);
573 context->setMiscRegNoEffect(
574 CSRData.at(CSR_MCAUSE).physIndex, r.mcause);
575 context->setMiscRegNoEffect(
576 CSRData.at(CSR_MTVAL).physIndex, r.mtval);
577
578 // H mode CSR (to be implemented)
579}
580
581bool
582RemoteGDB::getXferFeaturesRead(const std::string &annex, std::string &output)
583{
590#define GDB_XML(x, s) \
591 { \
592 x, std::string(reinterpret_cast<const char *>(Blobs::s), \
593 Blobs::s##_len) \
594 }
595 static const std::map<std::string, std::string> annexMaps[enums::Num_RiscvType] = {
596 [RV32] = {GDB_XML("target.xml", gdb_xml_riscv_32bit_target),
597 GDB_XML("riscv-32bit-cpu.xml", gdb_xml_riscv_32bit_cpu),
598 GDB_XML("riscv-32bit-fpu.xml", gdb_xml_riscv_32bit_fpu),
599 GDB_XML("riscv-32bit-csr.xml", gdb_xml_riscv_32bit_csr)},
600 [RV64] = {GDB_XML("target.xml", gdb_xml_riscv_64bit_target),
601 GDB_XML("riscv-64bit-cpu.xml", gdb_xml_riscv_64bit_cpu),
602 GDB_XML("riscv-64bit-fpu.xml", gdb_xml_riscv_64bit_fpu),
603 GDB_XML("riscv-64bit-csr.xml", gdb_xml_riscv_64bit_csr)},
604 };
605 auto& annexMap = annexMaps[getRvType(context())];
606 auto it = annexMap.find(annex);
607 if (it == annexMap.end())
608 return false;
609 output = it->second;
610 return true;
611}
612
613BaseGdbRegCache *
614RemoteGDB::gdbRegs()
615{
616 BaseGdbRegCache* regs[enums::Num_RiscvType] = {
617 [RV32] = &regCache32,
618 [RV64] = &regCache64,
619 };
620 return regs[getRvType(context())];
621}
622
623} // namespace gem5
#define GDB_XML(x, s)
#define DPRINTF(x,...)
Definition trace.hh:209
RemoteGDB(System *_system, ListenSocketConfig _listen_config)
BaseRemoteGDB * gdb
virtual void removeHardBreak(Addr addr, size_t kind)
ThreadContext * tc
ThreadContext * context()
virtual void insertHardBreak(Addr addr, size_t kind)
Walker * getDataWalker()
Definition mmu.hh:96
MemAccessInfo getMemAccessInfo(ThreadContext *tc, BaseMMU::Mode mode)
Definition mmu.hh:89
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
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).
struct gem5::RiscvISA::RemoteGDB::Riscv32GdbRegCache::GEM5_PACKED r
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
struct gem5::RiscvISA::RemoteGDB::Riscv64GdbRegCache::GEM5_PACKED r
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).
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
void removeHardBreak(Addr addr, size_t kind) override
virtual PrivilegeModeSet getPrivilegeModeSet(ThreadContext *tc)
bool getXferFeaturesRead(const std::string &annex, std::string &output) override
Reply to qXfer:features:read:xxx.xml qeuries.
bool acc(Addr addr, size_t len) override
void insertHardBreak(Addr addr, size_t kind) override
virtual RiscvType getRvType(ThreadContext *tc)
RemoteGDB(System *_system, ListenSocketConfig _listen_config)
Fault startFunctional(ThreadContext *_tc, Addr &addr, unsigned &logBytes, BaseMMU::Mode mode)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscReg(RegIndex misc_reg)=0
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition bitfield.hh:129
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:246
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 18, 16 > len
Bitfield< 8 > va
constexpr enums::RiscvType RV32
Definition pcstate.hh:56
constexpr RegClass floatRegClass(FloatRegClass, FloatRegClassName, float_reg::NumRegs, debug::FloatRegs)
enums::PrivilegeModeSet PrivilegeModeSet
Definition pcstate.hh:59
Bitfield< 2 > i
enums::RiscvType RiscvType
Definition pcstate.hh:55
const std::unordered_map< int, CSRMetadata > CSRData
Definition misc.hh:604
const std::unordered_map< int, RegVal > CSRMasks[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
Definition misc.hh:1694
constexpr RegClass intRegClass(IntRegClass, IntRegClassName, int_reg::NumRegs, debug::IntRegs)
constexpr enums::RiscvType RV64
Definition pcstate.hh:57
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
static void setRegNoEffectWithMask(ThreadContext *context, RiscvType type, PrivilegeModeSet pms, CSRIndex idx, xint val)
uint64_t RegVal
Definition types.hh:173
static void setRegWithMask(ThreadContext *context, RiscvType type, PrivilegeModeSet pms, CSRIndex idx, xint val)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition root.cc:220
static void output(const char *filename)
Definition debug.cc:60
constexpr decltype(nullptr) NoFault
Definition types.hh:253
Declarations of a non-full system Page Table.

Generated on Sat Oct 18 2025 08:06:40 for gem5 by doxygen 1.14.0