gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pseudo_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2003-2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __SIM_PSEUDO_INST_HH__
42 #define __SIM_PSEUDO_INST_HH__
43 
44 #include <gem5/asm/generic/m5ops.h>
45 
46 #include "base/bitfield.hh"
47 #include "base/compiler.hh"
48 #include "base/logging.hh"
49 #include "base/trace.hh"
50 #include "base/types.hh" // For Tick and Addr data types.
51 #include "cpu/thread_context.hh"
52 #include "debug/PseudoInst.hh"
53 #include "sim/guest_abi.hh"
54 
55 namespace gem5
56 {
57 
58 namespace pseudo_inst
59 {
60 
61 static inline void
62 decodeAddrOffset(Addr offset, uint8_t &func)
63 {
64  func = bits(offset, 15, 8);
65 }
66 
67 void arm(ThreadContext *tc);
68 void quiesce(ThreadContext *tc);
69 void quiesceSkip(ThreadContext *tc);
70 void quiesceNs(ThreadContext *tc, uint64_t ns);
71 void quiesceCycles(ThreadContext *tc, uint64_t cycles);
72 uint64_t quiesceTime(ThreadContext *tc);
73 uint64_t readfile(ThreadContext *tc, Addr vaddr, uint64_t len,
74  uint64_t offset);
75 uint64_t writefile(ThreadContext *tc, Addr vaddr, uint64_t len,
76  uint64_t offset, Addr filenameAddr);
77 void loadsymbol(ThreadContext *xc);
78 void addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr);
79 uint64_t initParam(ThreadContext *xc, uint64_t key_str1, uint64_t key_str2);
80 uint64_t rpns(ThreadContext *tc);
81 void wakeCPU(ThreadContext *tc, uint64_t cpuid);
82 void m5exit(ThreadContext *tc, Tick delay);
83 void m5fail(ThreadContext *tc, Tick delay, uint64_t code);
84 uint64_t m5sum(ThreadContext *tc, uint64_t a, uint64_t b, uint64_t c,
85  uint64_t d, uint64_t e, uint64_t f);
86 void resetstats(ThreadContext *tc, Tick delay, Tick period);
87 void dumpstats(ThreadContext *tc, Tick delay, Tick period);
88 void dumpresetstats(ThreadContext *tc, Tick delay, Tick period);
89 void m5checkpoint(ThreadContext *tc, Tick delay, Tick period);
90 void debugbreak(ThreadContext *tc);
91 void switchcpu(ThreadContext *tc);
92 void workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid);
93 void workend(ThreadContext *tc, uint64_t workid, uint64_t threadid);
94 void m5Syscall(ThreadContext *tc);
95 void togglesync(ThreadContext *tc);
97 
111 template <typename ABI, bool store_ret>
112 bool
113 pseudoInstWork(ThreadContext *tc, uint8_t func, uint64_t &result)
114 {
115  DPRINTF(PseudoInst, "pseudo_inst::pseudoInst(%i)\n", func);
116 
117  result = 0;
118 
119  switch (func) {
120  case M5OP_ARM:
121  invokeSimcall<ABI>(tc, arm);
122  return true;
123 
124  case M5OP_QUIESCE:
125  invokeSimcall<ABI>(tc, quiesce);
126  return true;
127 
128  case M5OP_QUIESCE_NS:
129  invokeSimcall<ABI>(tc, quiesceNs);
130  return true;
131 
132  case M5OP_QUIESCE_CYCLE:
133  invokeSimcall<ABI>(tc, quiesceCycles);
134  return true;
135 
136  case M5OP_QUIESCE_TIME:
137  result = invokeSimcall<ABI, store_ret>(tc, quiesceTime);
138  return true;
139 
140  case M5OP_RPNS:
141  result = invokeSimcall<ABI, store_ret>(tc, rpns);
142  return true;
143 
144  case M5OP_WAKE_CPU:
145  invokeSimcall<ABI>(tc, wakeCPU);
146  return true;
147 
148  case M5OP_EXIT:
149  invokeSimcall<ABI>(tc, m5exit);
150  return true;
151 
152  case M5OP_FAIL:
153  invokeSimcall<ABI>(tc, m5fail);
154  return true;
155 
156  // M5OP_SUM is for sanity checking the gem5 op interface.
157  case M5OP_SUM:
158  result = invokeSimcall<ABI, store_ret>(tc, m5sum);
159  return true;
160 
161  case M5OP_INIT_PARAM:
162  result = invokeSimcall<ABI, store_ret>(tc, initParam);
163  return true;
164 
165  case M5OP_LOAD_SYMBOL:
166  invokeSimcall<ABI>(tc, loadsymbol);
167  return true;
168 
169  case M5OP_RESET_STATS:
170  invokeSimcall<ABI>(tc, resetstats);
171  return true;
172 
173  case M5OP_DUMP_STATS:
174  invokeSimcall<ABI>(tc, dumpstats);
175  return true;
176 
177  case M5OP_DUMP_RESET_STATS:
178  invokeSimcall<ABI>(tc, dumpresetstats);
179  return true;
180 
181  case M5OP_CHECKPOINT:
182  invokeSimcall<ABI>(tc, m5checkpoint);
183  return true;
184 
185  case M5OP_WRITE_FILE:
186  result = invokeSimcall<ABI, store_ret>(tc, writefile);
187  return true;
188 
189  case M5OP_READ_FILE:
190  result = invokeSimcall<ABI, store_ret>(tc, readfile);
191  return true;
192 
193  case M5OP_DEBUG_BREAK:
194  invokeSimcall<ABI>(tc, debugbreak);
195  return true;
196 
197  case M5OP_SWITCH_CPU:
198  invokeSimcall<ABI>(tc, switchcpu);
199  return true;
200 
201  case M5OP_ADD_SYMBOL:
202  invokeSimcall<ABI>(tc, addsymbol);
203  return true;
204 
205  case M5OP_PANIC:
206  panic("M5 panic instruction called at %s\n", tc->pcState());
207 
208  case M5OP_WORK_BEGIN:
209  invokeSimcall<ABI>(tc, workbegin);
210  return true;
211 
212  case M5OP_WORK_END:
213  invokeSimcall<ABI>(tc, workend);
214  return true;
215 
216  case M5OP_RESERVED1:
217  case M5OP_RESERVED2:
218  case M5OP_RESERVED3:
219  case M5OP_RESERVED4:
220  case M5OP_RESERVED5:
221  warn("Unimplemented m5 op (%#x)\n", func);
222  return false;
223 
224  /* dist-gem5 functions */
225  case M5OP_DIST_TOGGLE_SYNC:
226  invokeSimcall<ABI>(tc, togglesync);
227  return true;
228 
229  case M5OP_WORKLOAD:
230  invokeSimcall<ABI>(tc, triggerWorkloadEvent);
231  return true;
232 
233  default:
234  warn("Unhandled m5 op: %#x\n", func);
235  return false;
236  }
237 }
238 
239 template <typename ABI, bool store_ret=false>
240 bool
241 pseudoInst(ThreadContext *tc, uint8_t func, uint64_t &result)
242 {
243  return pseudoInstWork<ABI, store_ret>(tc, func, result);
244 }
245 
246 template <typename ABI, bool store_ret=true>
247 bool
248 pseudoInst(ThreadContext *tc, uint8_t func)
249 {
250  uint64_t result;
251  return pseudoInstWork<ABI, store_ret>(tc, func, result);
252 }
253 
254 } // namespace pseudo_inst
255 } // namespace gem5
256 
257 #endif // __SIM_PSEUDO_INST_HH__
gem5::VegaISA::f
Bitfield< 56 > f
Definition: pagetable.hh:53
gem5::pseudo_inst::pseudoInst
bool pseudoInst(ThreadContext *tc, uint8_t func, uint64_t &result)
Definition: pseudo_inst.hh:241
warn
#define warn(...)
Definition: logging.hh:256
gem5::pseudo_inst::workend
void workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
Definition: pseudo_inst.cc:555
gem5::pseudo_inst::quiesceNs
void quiesceNs(ThreadContext *tc, uint64_t ns)
Definition: pseudo_inst.cc:131
gem5::MipsISA::cpuid
Bitfield< 28, 21 > cpuid
Definition: dt_constants.hh:95
gem5::pseudo_inst::quiesceTime
uint64_t quiesceTime(ThreadContext *tc)
Definition: pseudo_inst.cc:145
gem5::pseudo_inst::debugbreak
void debugbreak(ThreadContext *tc)
Definition: pseudo_inst.cc:459
gem5::pseudo_inst::switchcpu
void switchcpu(ThreadContext *tc)
Definition: pseudo_inst.cc:466
gem5::ThreadContext::pcState
virtual const PCStateBase & pcState() const =0
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
gem5::ArmISA::ns
Bitfield< 0 > ns
Definition: misc_types.hh:388
gem5::pseudo_inst::quiesce
void quiesce(ThreadContext *tc)
Definition: pseudo_inst.cc:117
gem5::pseudo_inst::rpns
uint64_t rpns(ThreadContext *tc)
Definition: pseudo_inst.cc:154
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
gem5::pseudo_inst::triggerWorkloadEvent
void triggerWorkloadEvent(ThreadContext *tc)
Definition: pseudo_inst.cc:480
gem5::pseudo_inst::m5Syscall
void m5Syscall(ThreadContext *tc)
gem5::pseudo_inst::loadsymbol
void loadsymbol(ThreadContext *tc)
Definition: pseudo_inst.cc:206
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:438
gem5::pseudo_inst::writefile
uint64_t writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, Addr filename_addr)
Definition: pseudo_inst.cc:408
gem5::pseudo_inst::wakeCPU
void wakeCPU(ThreadContext *tc, uint64_t cpuid)
Definition: pseudo_inst.cc:161
bitfield.hh
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::ArmISA::d
Bitfield< 9 > d
Definition: misc_types.hh:64
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::pseudo_inst::m5checkpoint
void m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:352
len
uint16_t len
Definition: helpers.cc:62
gem5::pseudo_inst::readfile
uint64_t readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
Definition: pseudo_inst.cc:366
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
compiler.hh
gem5::pseudo_inst::m5fail
void m5fail(ThreadContext *tc, Tick delay, uint64_t code)
Definition: pseudo_inst.cc:198
gem5::pseudo_inst::decodeAddrOffset
static void decodeAddrOffset(Addr offset, uint8_t &func)
Definition: pseudo_inst.hh:62
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::pseudo_inst::quiesceSkip
void quiesceSkip(ThreadContext *tc)
Definition: pseudo_inst.cc:124
gem5::pseudo_inst::resetstats
void resetstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:309
gem5::pseudo_inst::arm
void arm(ThreadContext *tc)
Definition: pseudo_inst.cc:107
gem5::pseudo_inst::dumpresetstats
void dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:337
gem5::pseudo_inst::workbegin
void workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
Definition: pseudo_inst.cc:492
gem5::pseudo_inst::addsymbol
void addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
Definition: pseudo_inst.cc:258
types.hh
gem5::pseudo_inst::quiesceCycles
void quiesceCycles(ThreadContext *tc, uint64_t cycles)
Definition: pseudo_inst.cc:138
gem5::pseudo_inst::m5exit
void m5exit(ThreadContext *tc, Tick delay)
Definition: pseudo_inst.cc:178
gem5::pseudo_inst::pseudoInstWork
bool pseudoInstWork(ThreadContext *tc, uint8_t func, uint64_t &result)
Execute a decoded M5 pseudo instruction.
Definition: pseudo_inst.hh:113
guest_abi.hh
logging.hh
gem5::pseudo_inst::m5sum
uint64_t m5sum(ThreadContext *tc, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f)
Definition: pseudo_inst.cc:189
trace.hh
gem5::pseudo_inst::togglesync
void togglesync(ThreadContext *tc)
Definition: pseudo_inst.cc:473
gem5::MipsISA::vaddr
vaddr
Definition: pra_constants.hh:278
gem5::pseudo_inst::initParam
uint64_t initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2)
Definition: pseudo_inst.cc:279
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::pseudo_inst::dumpstats
void dumpstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:323
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17