gem5  v20.0.0.2
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 class ThreadContext;
47 
48 #include "arch/pseudo_inst.hh"
49 #include "arch/utility.hh"
50 #include "base/types.hh" // For Tick and Addr data types.
51 #include "debug/PseudoInst.hh"
52 #include "sim/guest_abi.hh"
53 
55 {
56  using State = int;
57 };
58 
59 namespace GuestABI
60 {
61 
62 template <>
63 struct Argument<PseudoInstABI, uint64_t>
64 {
65  static uint64_t
67  {
68  uint64_t result =
69  TheISA::getArgument(tc, state, sizeof(uint64_t), false);
70  state++;
71  return result;
72  }
73 };
74 
75 } // namespace GuestABI
76 
77 namespace PseudoInst
78 {
79 
80 static inline void
81 decodeAddrOffset(Addr offset, uint8_t &func)
82 {
83  func = bits(offset, 15, 8);
84 }
85 
86 void arm(ThreadContext *tc);
87 void quiesce(ThreadContext *tc);
88 void quiesceSkip(ThreadContext *tc);
89 void quiesceNs(ThreadContext *tc, uint64_t ns);
90 void quiesceCycles(ThreadContext *tc, uint64_t cycles);
91 uint64_t quiesceTime(ThreadContext *tc);
92 uint64_t readfile(ThreadContext *tc, Addr vaddr, uint64_t len,
93  uint64_t offset);
94 uint64_t writefile(ThreadContext *tc, Addr vaddr, uint64_t len,
95  uint64_t offset, Addr filenameAddr);
96 void loadsymbol(ThreadContext *xc);
97 void addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr);
98 uint64_t initParam(ThreadContext *xc, uint64_t key_str1, uint64_t key_str2);
99 uint64_t rpns(ThreadContext *tc);
100 void wakeCPU(ThreadContext *tc, uint64_t cpuid);
101 void m5exit(ThreadContext *tc, Tick delay);
102 void m5fail(ThreadContext *tc, Tick delay, uint64_t code);
103 void resetstats(ThreadContext *tc, Tick delay, Tick period);
104 void dumpstats(ThreadContext *tc, Tick delay, Tick period);
105 void dumpresetstats(ThreadContext *tc, Tick delay, Tick period);
106 void m5checkpoint(ThreadContext *tc, Tick delay, Tick period);
107 void debugbreak(ThreadContext *tc);
108 void switchcpu(ThreadContext *tc);
109 void workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid);
110 void workend(ThreadContext *tc, uint64_t workid, uint64_t threadid);
111 void m5Syscall(ThreadContext *tc);
112 void togglesync(ThreadContext *tc);
113 
127 template <typename ABI, bool store_ret>
128 bool
129 pseudoInstWork(ThreadContext *tc, uint8_t func, uint64_t &result)
130 {
131  DPRINTF(PseudoInst, "PseudoInst::pseudoInst(%i)\n", func);
132 
133  result = 0;
134 
135  switch (func) {
136  case M5OP_ARM:
137  invokeSimcall<ABI>(tc, arm);
138  return true;
139 
140  case M5OP_QUIESCE:
141  invokeSimcall<ABI>(tc, quiesce);
142  return true;
143 
144  case M5OP_QUIESCE_NS:
145  invokeSimcall<ABI>(tc, quiesceNs);
146  return true;
147 
148  case M5OP_QUIESCE_CYCLE:
149  invokeSimcall<ABI>(tc, quiesceCycles);
150  return true;
151 
152  case M5OP_QUIESCE_TIME:
153  result = invokeSimcall<ABI, store_ret>(tc, quiesceTime);
154  return true;
155 
156  case M5OP_RPNS:
157  result = invokeSimcall<ABI, store_ret>(tc, rpns);
158  return true;
159 
160  case M5OP_WAKE_CPU:
161  invokeSimcall<ABI>(tc, wakeCPU);
162  return true;
163 
164  case M5OP_EXIT:
165  invokeSimcall<ABI>(tc, m5exit);
166  return true;
167 
168  case M5OP_FAIL:
169  invokeSimcall<ABI>(tc, m5fail);
170  return true;
171 
172  case M5OP_INIT_PARAM:
173  result = invokeSimcall<ABI, store_ret>(tc, initParam);
174  return true;
175 
176  case M5OP_LOAD_SYMBOL:
177  invokeSimcall<ABI>(tc, loadsymbol);
178  return true;
179 
180  case M5OP_RESET_STATS:
181  invokeSimcall<ABI>(tc, resetstats);
182  return true;
183 
184  case M5OP_DUMP_STATS:
185  invokeSimcall<ABI>(tc, dumpstats);
186  return true;
187 
188  case M5OP_DUMP_RESET_STATS:
189  invokeSimcall<ABI>(tc, dumpresetstats);
190  return true;
191 
192  case M5OP_CHECKPOINT:
193  invokeSimcall<ABI>(tc, m5checkpoint);
194  return true;
195 
196  case M5OP_WRITE_FILE:
197  result = invokeSimcall<ABI, store_ret>(tc, writefile);
198  return true;
199 
200  case M5OP_READ_FILE:
201  result = invokeSimcall<ABI, store_ret>(tc, readfile);
202  return true;
203 
204  case M5OP_DEBUG_BREAK:
205  invokeSimcall<ABI>(tc, debugbreak);
206  return true;
207 
208  case M5OP_SWITCH_CPU:
209  invokeSimcall<ABI>(tc, switchcpu);
210  return true;
211 
212  case M5OP_ADD_SYMBOL:
213  invokeSimcall<ABI>(tc, addsymbol);
214  return true;
215 
216  case M5OP_PANIC:
217  panic("M5 panic instruction called at %s\n", tc->pcState());
218 
219  case M5OP_WORK_BEGIN:
220  invokeSimcall<ABI>(tc, workbegin);
221  return true;
222 
223  case M5OP_WORK_END:
224  invokeSimcall<ABI>(tc, workend);
225  return true;
226 
227  case M5OP_RESERVED1:
228  case M5OP_RESERVED2:
229  case M5OP_RESERVED3:
230  case M5OP_RESERVED4:
231  case M5OP_RESERVED5:
232  warn("Unimplemented m5 op (%#x)\n", func);
233  return false;
234 
235  /* SE mode functions */
236  case M5OP_SE_SYSCALL:
237  invokeSimcall<ABI>(tc, m5Syscall);
238  return true;
239 
240  case M5OP_SE_PAGE_FAULT:
241  invokeSimcall<ABI>(tc, TheISA::m5PageFault);
242  return true;
243 
244  /* dist-gem5 functions */
245  case M5OP_DIST_TOGGLE_SYNC:
246  invokeSimcall<ABI>(tc, togglesync);
247  return true;
248 
249  default:
250  warn("Unhandled m5 op: %#x\n", func);
251  return false;
252  }
253 }
254 
255 template <typename ABI, bool store_ret=false>
256 bool
257 pseudoInst(ThreadContext *tc, uint8_t func, uint64_t &result)
258 {
259  return pseudoInstWork<ABI, store_ret>(tc, func, result);
260 }
261 
262 template <typename ABI, bool store_ret=true>
263 bool
264 pseudoInst(ThreadContext *tc, uint8_t func)
265 {
266  uint64_t result;
267  return pseudoInstWork<ABI, store_ret>(tc, func, result);
268 }
269 
270 } // namespace PseudoInst
271 
272 #endif // __SIM_PSEUDO_INST_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
void m5fail(ThreadContext *tc, Tick delay, uint64_t code)
Definition: pseudo_inst.cc:195
#define DPRINTF(x,...)
Definition: trace.hh:222
void m5PageFault(ThreadContext *tc)
Definition: pseudo_inst.cc:38
void quiesceNs(ThreadContext *tc, uint64_t ns)
Definition: pseudo_inst.cc:138
bool pseudoInstWork(ThreadContext *tc, uint8_t func, uint64_t &result)
Execute a decoded M5 pseudo instruction.
Definition: pseudo_inst.hh:129
void arm(ThreadContext *tc)
Definition: pseudo_inst.cc:113
static void decodeAddrOffset(Addr offset, uint8_t &func)
Definition: pseudo_inst.hh:81
ip6_addr_t addr
Definition: inet.hh:330
void dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:338
uint64_t quiesceTime(ThreadContext *tc)
Definition: pseudo_inst.cc:152
void quiesceSkip(ThreadContext *tc)
Definition: pseudo_inst.cc:131
void m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:352
uint64_t writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, Addr filename_addr)
Definition: pseudo_inst.cc:408
Bitfield< 23, 0 > offset
Definition: types.hh:152
Bitfield< 28, 21 > cpuid
Definition: dt_constants.hh:92
void quiesceCycles(ThreadContext *tc, uint64_t cycles)
Definition: pseudo_inst.cc:145
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void togglesync(ThreadContext *tc)
Definition: pseudo_inst.cc:479
uint64_t initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2)
Definition: pseudo_inst.cc:276
Bitfield< 0 > ns
void quiesce(ThreadContext *tc)
Definition: pseudo_inst.cc:124
uint64_t Tick
Tick count type.
Definition: types.hh:61
uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
Definition: utility.cc:56
void switchcpu(ThreadContext *tc)
Definition: pseudo_inst.cc:460
Bitfield< 18, 16 > len
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
void debugbreak(ThreadContext *tc)
Definition: pseudo_inst.cc:453
void workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
Definition: pseudo_inst.cc:491
void resetstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:310
uint64_t readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
Definition: pseudo_inst.cc:366
void wakeCPU(ThreadContext *tc, uint64_t cpuid)
Definition: pseudo_inst.cc:168
void dumpstats(ThreadContext *tc, Tick delay, Tick period)
Definition: pseudo_inst.cc:324
#define warn(...)
Definition: logging.hh:208
void m5exit(ThreadContext *tc, Tick delay)
Definition: pseudo_inst.cc:185
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:71
void addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
Definition: pseudo_inst.cc:257
void loadsymbol(ThreadContext *tc)
Definition: pseudo_inst.cc:203
void workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
Definition: pseudo_inst.cc:554
void m5Syscall(ThreadContext *tc)
Definition: pseudo_inst.cc:471
bool pseudoInst(ThreadContext *tc, uint8_t func)
Definition: pseudo_inst.hh:264
uint64_t rpns(ThreadContext *tc)
Definition: pseudo_inst.cc:161

Generated on Mon Jun 8 2020 15:34:40 for gem5 by doxygen 1.8.13