gem5  v22.1.0.0
static_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 RISC-V Foundation
3  * Copyright (c) 2016 The University of Virginia
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __ARCH_RISCV_STATIC_INST_HH__
31 #define __ARCH_RISCV_STATIC_INST_HH__
32 
33 #include <string>
34 
35 #include "arch/riscv/pcstate.hh"
36 #include "arch/riscv/types.hh"
37 #include "cpu/exec_context.hh"
38 #include "cpu/static_inst.hh"
39 #include "cpu/thread_context.hh"
40 #include "mem/packet.hh"
41 
42 namespace gem5
43 {
44 
45 namespace RiscvISA
46 {
47 
52 {
53  protected:
54  RiscvStaticInst(const char *_mnemonic, ExtMachInst _machInst,
55  OpClass __opClass) :
56  StaticInst(_mnemonic, __opClass), machInst(_machInst)
57  {}
58 
59  bool alignmentOk(ExecContext* xc, Addr addr, Addr size) const;
60 
61  public:
63 
64  void
65  advancePC(PCStateBase &pc) const override
66  {
67  pc.as<PCState>().advance();
68  }
69 
70  void
71  advancePC(ThreadContext *tc) const override
72  {
73  PCState pc = tc->pcState().as<PCState>();
74  pc.advance();
75  tc->pcState(pc);
76  }
77 
78  std::unique_ptr<PCStateBase>
79  buildRetPC(const PCStateBase &cur_pc,
80  const PCStateBase &call_pc) const override
81  {
82  PCStateBase *ret_pc_ptr = call_pc.clone();
83  auto &ret_pc = ret_pc_ptr->as<PCState>();
84  ret_pc.advance();
85  return std::unique_ptr<PCStateBase>{ret_pc_ptr};
86  }
87 
88  size_t
89  asBytes(void *buf, size_t size) override
90  {
91  return simpleAsBytes(buf, size, machInst);
92  }
93 };
94 
99 {
100  protected:
102 
103  RiscvMacroInst(const char *mnem, ExtMachInst _machInst,
104  OpClass __opClass) :
105  RiscvStaticInst(mnem, _machInst, __opClass)
106  {
107  flags[IsMacroop] = true;
108  }
109 
110  ~RiscvMacroInst() { microops.clear(); }
111 
113  fetchMicroop(MicroPC upc) const override
114  {
115  return microops[upc];
116  }
117 
118  Fault
119  initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
120  {
121  panic("Tried to execute a macroop directly!\n");
122  }
123 
124  Fault
126  trace::InstRecord *traceData) const override
127  {
128  panic("Tried to execute a macroop directly!\n");
129  }
130 
131  Fault
132  execute(ExecContext *xc, trace::InstRecord *traceData) const override
133  {
134  panic("Tried to execute a macroop directly!\n");
135  }
136 };
137 
142 {
143  protected:
144  RiscvMicroInst(const char *mnem, ExtMachInst _machInst,
145  OpClass __opClass) :
146  RiscvStaticInst(mnem, _machInst, __opClass)
147  {
148  flags[IsMicroop] = true;
149  }
150 
151  void advancePC(PCStateBase &pcState) const override;
152  void advancePC(ThreadContext *tc) const override;
153 };
154 
155 } // namespace RiscvISA
156 } // namespace gem5
157 
158 #endif // __ARCH_RISCV_STATIC_INST_HH__
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:72
Target & as()
Definition: pcstate.hh:72
virtual PCStateBase * clone() const =0
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Base class for all RISC-V Macroops.
Definition: static_inst.hh:99
std::vector< StaticInstPtr > microops
Definition: static_inst.hh:101
Fault initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
Definition: static_inst.hh:119
Fault completeAcc(PacketPtr pkt, ExecContext *xc, trace::InstRecord *traceData) const override
Definition: static_inst.hh:125
RiscvMacroInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Definition: static_inst.hh:103
StaticInstPtr fetchMicroop(MicroPC upc) const override
Return the microop that goes with a particular micropc.
Definition: static_inst.hh:113
Fault execute(ExecContext *xc, trace::InstRecord *traceData) const override
Definition: static_inst.hh:132
Base class for all RISC-V Microops.
Definition: static_inst.hh:142
RiscvMicroInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Definition: static_inst.hh:144
void advancePC(PCStateBase &pcState) const override
Definition: static_inst.cc:57
Base class for all RISC-V static instructions.
Definition: static_inst.hh:52
size_t asBytes(void *buf, size_t size) override
Instruction classes can override this function to return a a representation of themselves as a blob o...
Definition: static_inst.hh:89
bool alignmentOk(ExecContext *xc, Addr addr, Addr size) const
Definition: static_inst.cc:44
void advancePC(ThreadContext *tc) const override
Definition: static_inst.hh:71
void advancePC(PCStateBase &pc) const override
Definition: static_inst.hh:65
RiscvStaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
Definition: static_inst.hh:54
std::unique_ptr< PCStateBase > buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const override
Definition: static_inst.hh:79
Base, ISA-independent static instruction class.
Definition: static_inst.hh:89
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
Definition: static_inst.hh:356
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:103
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
STL vector class.
Definition: stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
uint64_t ExtMachInst
Definition: types.hh:54
Bitfield< 4 > pc
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint16_t MicroPC
Definition: types.hh:149
Declaration of the Packet class.

Generated on Wed Dec 21 2022 10:22:26 for gem5 by doxygen 1.9.1