gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
types.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Gabe Black
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __ARCH_GENERIC_TYPES_HH__
30 #define __ARCH_GENERIC_TYPES_HH__
31 
32 #include <iostream>
33 #include <limits>
34 
35 #include "base/trace.hh"
36 #include "base/types.hh"
37 #include "sim/serialize.hh"
38 
39 // Logical register index type.
40 typedef uint16_t RegIndex;
41 
43 using ElemIndex = uint16_t;
44 
46 #define ILLEGAL_ELEM_INDEX std::numeric_limits<ElemIndex>::max()
47 
48 namespace GenericISA
49 {
50 
51 // The guaranteed interface.
52 class PCStateBase : public Serializable
53 {
54  protected:
57 
58  PCStateBase() : _pc(0), _npc(0) {}
59  PCStateBase(Addr val) : _pc(0), _npc(0) { set(val); }
60 
61  public:
67  Addr
68  instAddr() const
69  {
70  return _pc;
71  }
72 
78  Addr
79  nextInstAddr() const
80  {
81  return _npc;
82  }
83 
89  MicroPC
90  microPC() const
91  {
92  return 0;
93  }
94 
101  void set(Addr val);
102 
103  bool
104  operator == (const PCStateBase &opc) const
105  {
106  return _pc == opc._pc && _npc == opc._npc;
107  }
108 
109  bool
110  operator != (const PCStateBase &opc) const
111  {
112  return !(*this == opc);
113  }
114 
115  void
116  serialize(CheckpointOut &cp) const override
117  {
118  SERIALIZE_SCALAR(_pc);
119  SERIALIZE_SCALAR(_npc);
120  }
121 
122  void
124  {
125  UNSERIALIZE_SCALAR(_pc);
126  UNSERIALIZE_SCALAR(_npc);
127  }
128 };
129 
130 
131 /*
132  * Different flavors of PC state. Only ISA specific code should rely on
133  * any particular type of PC state being available. All other code should
134  * use the interface above.
135  */
136 
137 // The most basic type of PC.
138 template <class MachInst>
140 {
141  protected:
142  typedef PCStateBase Base;
143 
144  public:
145 
146  Addr pc() const { return _pc; }
147  void pc(Addr val) { _pc = val; }
148 
149  Addr npc() const { return _npc; }
150  void npc(Addr val) { _npc = val; }
151 
152  void
153  set(Addr val)
154  {
155  pc(val);
156  npc(val + sizeof(MachInst));
157  };
158 
159  void
161  {
162  npc(val);
163  }
164 
167 
168  bool
169  branching() const
170  {
171  return this->npc() != this->pc() + sizeof(MachInst);
172  }
173 
174  // Advance the PC.
175  void
177  {
178  _pc = _npc;
179  _npc += sizeof(MachInst);
180  }
181 };
182 
183 template <class MachInst>
184 std::ostream &
185 operator<<(std::ostream & os, const SimplePCState<MachInst> &pc)
186 {
187  ccprintf(os, "(%#x=>%#x)", pc.pc(), pc.npc());
188  return os;
189 }
190 
191 // A PC and microcode PC.
192 template <class MachInst>
193 class UPCState : public SimplePCState<MachInst>
194 {
195  protected:
197 
200 
201  public:
202 
203  MicroPC upc() const { return _upc; }
204  void upc(MicroPC val) { _upc = val; }
205 
206  MicroPC nupc() const { return _nupc; }
207  void nupc(MicroPC val) { _nupc = val; }
208 
209  MicroPC
210  microPC() const
211  {
212  return _upc;
213  }
214 
215  void
216  set(Addr val)
217  {
218  Base::set(val);
219  upc(0);
220  nupc(1);
221  }
222 
223  UPCState() : _upc(0), _nupc(1) {}
224  UPCState(Addr val) : _upc(0), _nupc(0) { set(val); }
225 
226  bool
227  branching() const
228  {
229  return this->npc() != this->pc() + sizeof(MachInst) ||
230  this->nupc() != this->upc() + 1;
231  }
232 
233  // Advance the upc within the instruction.
234  void
236  {
237  _upc = _nupc;
238  _nupc++;
239  }
240 
241  // End the macroop by resetting the upc and advancing the regular pc.
242  void
244  {
245  this->advance();
246  _upc = 0;
247  _nupc = 1;
248  }
249 
250  bool
252  {
253  return Base::_pc == opc._pc &&
254  Base::_npc == opc._npc &&
255  _upc == opc._upc && _nupc == opc._nupc;
256  }
257 
258  bool
260  {
261  return !(*this == opc);
262  }
263 
264  void
265  serialize(CheckpointOut &cp) const override
266  {
267  Base::serialize(cp);
268  SERIALIZE_SCALAR(_upc);
269  SERIALIZE_SCALAR(_nupc);
270  }
271 
272  void
274  {
275  Base::unserialize(cp);
276  UNSERIALIZE_SCALAR(_upc);
277  UNSERIALIZE_SCALAR(_nupc);
278  }
279 };
280 
281 template <class MachInst>
282 std::ostream &
283 operator<<(std::ostream & os, const UPCState<MachInst> &pc)
284 {
285  ccprintf(os, "(%#x=>%#x).(%d=>%d)",
286  pc.pc(), pc.npc(), pc.upc(), pc.nupc());
287  return os;
288 }
289 
290 // A PC with a delay slot.
291 template <class MachInst>
292 class DelaySlotPCState : public SimplePCState<MachInst>
293 {
294  protected:
296 
298 
299  public:
300 
301  Addr nnpc() const { return _nnpc; }
302  void nnpc(Addr val) { _nnpc = val; }
303 
304  void
305  set(Addr val)
306  {
307  Base::set(val);
308  nnpc(val + 2 * sizeof(MachInst));
309  }
310 
313 
314  bool
315  branching() const
316  {
317  return !(this->nnpc() == this->npc() + sizeof(MachInst) &&
318  (this->npc() == this->pc() + sizeof(MachInst) ||
319  this->npc() == this->pc() + 2 * sizeof(MachInst)));
320  }
321 
322  // Advance the PC.
323  void
325  {
326  Base::_pc = Base::_npc;
327  Base::_npc = _nnpc;
328  _nnpc += sizeof(MachInst);
329  }
330 
331  bool
333  {
334  return Base::_pc == opc._pc &&
335  Base::_npc == opc._npc &&
336  _nnpc == opc._nnpc;
337  }
338 
339  bool
341  {
342  return !(*this == opc);
343  }
344 
345  void
346  serialize(CheckpointOut &cp) const override
347  {
348  Base::serialize(cp);
349  SERIALIZE_SCALAR(_nnpc);
350  }
351 
352  void
354  {
355  Base::unserialize(cp);
356  UNSERIALIZE_SCALAR(_nnpc);
357  }
358 };
359 
360 template <class MachInst>
361 std::ostream &
362 operator<<(std::ostream & os, const DelaySlotPCState<MachInst> &pc)
363 {
364  ccprintf(os, "(%#x=>%#x=>%#x)",
365  pc.pc(), pc.npc(), pc.nnpc());
366  return os;
367 }
368 
369 // A PC with a delay slot and a microcode PC.
370 template <class MachInst>
371 class DelaySlotUPCState : public DelaySlotPCState<MachInst>
372 {
373  protected:
375 
378 
379  public:
380 
381  MicroPC upc() const { return _upc; }
382  void upc(MicroPC val) { _upc = val; }
383 
384  MicroPC nupc() const { return _nupc; }
385  void nupc(MicroPC val) { _nupc = val; }
386 
387  MicroPC
388  microPC() const
389  {
390  return _upc;
391  }
392 
393  void
394  set(Addr val)
395  {
396  Base::set(val);
397  upc(0);
398  nupc(1);
399  }
400 
403 
404  bool
405  branching() const
406  {
407  return Base::branching() || this->nupc() != this->upc() + 1;
408  }
409 
410  // Advance the upc within the instruction.
411  void
413  {
414  _upc = _nupc;
415  _nupc++;
416  }
417 
418  // End the macroop by resetting the upc and advancing the regular pc.
419  void
421  {
422  this->advance();
423  _upc = 0;
424  _nupc = 1;
425  }
426 
427  bool
429  {
430  return Base::_pc == opc._pc &&
431  Base::_npc == opc._npc &&
432  Base::_nnpc == opc._nnpc &&
433  _upc == opc._upc && _nupc == opc._nupc;
434  }
435 
436  bool
438  {
439  return !(*this == opc);
440  }
441 
442  void
443  serialize(CheckpointOut &cp) const override
444  {
445  Base::serialize(cp);
446  SERIALIZE_SCALAR(_upc);
447  SERIALIZE_SCALAR(_nupc);
448  }
449 
450  void
452  {
453  Base::unserialize(cp);
454  UNSERIALIZE_SCALAR(_upc);
455  UNSERIALIZE_SCALAR(_nupc);
456  }
457 };
458 
459 template <class MachInst>
460 std::ostream &
461 operator<<(std::ostream & os, const DelaySlotUPCState<MachInst> &pc)
462 {
463  ccprintf(os, "(%#x=>%#x=>%#x).(%d=>%d)",
464  pc.pc(), pc.npc(), pc.nnpc(), pc.upc(), pc.nupc());
465  return os;
466 }
467 
468 }
469 
470 #endif
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
SimplePCState< MachInst > Base
Definition: types.hh:196
void setNPC(Addr val)
Definition: types.hh:160
Addr instAddr() const
Returns the memory address the bytes of this instruction came from.
Definition: types.hh:68
MicroPC microPC() const
Returns the current micropc.
Definition: types.hh:90
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:123
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:353
MicroPC microPC() const
Definition: types.hh:210
Addr nextInstAddr() const
Returns the memory address the bytes of the next instruction came from.
Definition: types.hh:79
Definition: cprintf.cc:40
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:443
MicroPC microPC() const
Definition: types.hh:388
bool branching() const
Definition: types.hh:315
Bitfield< 17 > os
Definition: misc.hh:803
bool operator==(const PCStateBase &opc) const
Definition: types.hh:104
Bitfield< 63 > val
Definition: misc.hh:769
void pc(Addr val)
Definition: types.hh:147
MicroPC upc() const
Definition: types.hh:203
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:116
MicroPC upc() const
Definition: types.hh:381
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
Bitfield< 4 > pc
bool operator!=(const PCStateBase &opc) const
Definition: types.hh:110
uint16_t RegIndex
Definition: types.hh:40
DelaySlotPCState< MachInst > Base
Definition: types.hh:374
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:346
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:273
UPCState(Addr val)
Definition: types.hh:224
bool branching() const
Definition: types.hh:227
MicroPC nupc() const
Definition: types.hh:384
PCStateBase(Addr val)
Definition: types.hh:59
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
uint16_t MicroPC
Definition: types.hh:142
SimplePCState(Addr val)
Definition: types.hh:166
uint64_t MachInst
Definition: types.hh:52
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
Basic support for object serialization.
Definition: serialize.hh:166
Addr npc() const
Definition: types.hh:149
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
void nupc(MicroPC val)
Definition: types.hh:385
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:451
void npc(Addr val)
Definition: types.hh:150
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:265
std::ostream CheckpointOut
Definition: serialize.hh:63
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:43
SimplePCState< MachInst > Base
Definition: types.hh:295
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void nupc(MicroPC val)
Definition: types.hh:207
MicroPC nupc() const
Definition: types.hh:206
void upc(MicroPC val)
Definition: types.hh:382
void nnpc(Addr val)
Definition: types.hh:302
bool branching() const
Definition: types.hh:169
void upc(MicroPC val)
Definition: types.hh:204

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