gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
standard.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 RISC-V Foundation
3 * Copyright (c) 2017 The University of Virginia
4 * Copyright (c) 2020 Barkhausen Institut
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
32
33#include <sstream>
34#include <string>
35
36#include "arch/riscv/faults.hh"
40#include "arch/riscv/utility.hh"
41#include "cpu/static_inst.hh"
42#include "sim/system.hh"
43
44namespace gem5
45{
46
47namespace RiscvISA
48{
49
50std::string
52{
53 std::stringstream ss;
54 ss << mnemonic << ' ' << registerName(destRegIdx(0)) << ", " <<
56 if (_numSrcRegs >= 2)
57 ss << ", " << registerName(srcRegIdx(1));
58 if (_numSrcRegs >= 3)
59 ss << ", " << registerName(srcRegIdx(2));
60 return ss.str();
61}
62
63std::string
65{
66 std::stringstream ss;
67 ss << mnemonic << ' ' << registerName(destRegIdx(0)) << ", ";
68 auto data = CSRData.find(csr);
69 if (data != CSRData.end())
70 ss << data->second.name;
71 else
72 ss << "?? (" << std::hex << "0x" << csr << std::dec << ")";
73 if (_numSrcRegs > 0)
74 ss << ", " << registerName(srcRegIdx(0));
75 else
76 ss << uimm;
77 return ss.str();
78}
79
80std::string
82{
83 if (strcmp(mnemonic, "fence_vma") == 0) {
84 std::stringstream ss;
85 ss << mnemonic << ' ' << registerName(srcRegIdx(0)) << ", " <<
87 return ss.str();
88 }
89
90 return mnemonic;
91}
92
95{
96 // If semihosting is enabled, we may need to execute a semihosting
97 // operation instead of raising a breakpoint fault.
98 ThreadContext *tc = xc->tcBase();
99 if (auto *semihosting = dynamic_cast<RiscvSemihosting *>(
101 if (semihosting->isSemihostingEBreak(xc) && semihosting->call(tc)) {
102 return NoFault;
103 }
104 }
105 // No semihosting, raise a standard breakpoint exception.
106 MISA misa = xc->readMiscReg(MISCREG_ISA);
107 bool virtualized = misa.rvh ? virtualizationEnabled(xc) : false;
108 return std::make_shared<BreakpointFault>(xc->pcState(), virtualized);
109}
110
111} // namespace RiscvISA
112} // namespace gem5
const char data[]
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
virtual ThreadContext * tcBase() const =0
Returns a pointer to the ThreadContext.
virtual RegVal readMiscReg(int misc_reg)=0
Reads a miscellaneous register, handling any architectural side effects due to reading that register.
virtual const PCStateBase & pcState() const =0
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition standard.cc:64
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition standard.cc:51
Fault executeEBreakOrSemihosting(ExecContext *xc) const
Definition standard.cc:94
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition standard.cc:81
Semihosting for RV32 and RV64.
uint8_t _numSrcRegs
See numSrcRegs().
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
const char * mnemonic
Base mnemonic (e.g., "add").
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Workload * workload
OS kernel.
Definition system.hh:331
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual System * getSystemPtr()=0
virtual SimObject * getSemihosting() const
Returns the semihosting interface if supported by the current workload.
Definition workload.hh:107
std::string registerName(RegId reg)
Definition utility.hh:130
const std::unordered_map< int, CSRMetadata > CSRData
Definition misc.hh:604
bool virtualizationEnabled(ExecContext *xc)
Definition isa.cc:1340
Bitfield< 11, 8 > ss
Bitfield< 4 > pc
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
constexpr decltype(nullptr) NoFault
Definition types.hh:253

Generated on Mon Oct 27 2025 04:12:59 for gem5 by doxygen 1.14.0