gem5  v21.1.0.2
types.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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) 2010 Gabe Black
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 __ARCH_GENERIC_TYPES_HH__
42 #define __ARCH_GENERIC_TYPES_HH__
43 
44 #include <iostream>
45 
46 #include "base/trace.hh"
47 #include "base/types.hh"
48 #include "sim/serialize.hh"
49 
50 namespace gem5
51 {
52 
53 namespace GenericISA
54 {
55 
56 // The guaranteed interface.
57 class PCStateBase : public Serializable
58 {
59  protected:
62 
63  PCStateBase() : _pc(0), _npc(0) {}
64  PCStateBase(Addr val) : _pc(0), _npc(0) { set(val); }
65 
66  public:
72  Addr
73  instAddr() const
74  {
75  return _pc;
76  }
77 
83  Addr
84  nextInstAddr() const
85  {
86  return _npc;
87  }
88 
94  MicroPC
95  microPC() const
96  {
97  return 0;
98  }
99 
106  void set(Addr val);
107 
108  bool
109  operator == (const PCStateBase &opc) const
110  {
111  return _pc == opc._pc && _npc == opc._npc;
112  }
113 
114  bool
115  operator != (const PCStateBase &opc) const
116  {
117  return !(*this == opc);
118  }
119 
120  void
121  serialize(CheckpointOut &cp) const override
122  {
125  }
126 
127  void
128  unserialize(CheckpointIn &cp) override
129  {
132  }
133 };
134 
135 
136 /*
137  * Different flavors of PC state. Only ISA specific code should rely on
138  * any particular type of PC state being available. All other code should
139  * use the interface above.
140  */
141 
142 // The most basic type of PC.
143 template <int InstWidth>
145 {
146  protected:
147  typedef PCStateBase Base;
148 
149  public:
150 
151  Addr pc() const { return _pc; }
152  void pc(Addr val) { _pc = val; }
153 
154  Addr npc() const { return _npc; }
155  void npc(Addr val) { _npc = val; }
156 
157  void
159  {
160  pc(val);
161  npc(val + InstWidth);
162  };
163 
164  void
166  {
167  npc(val);
168  }
169 
172 
173  bool
174  branching() const
175  {
176  return this->npc() != this->pc() + InstWidth;
177  }
178 
179  // Advance the PC.
180  void
182  {
183  _pc = _npc;
184  _npc += InstWidth;
185  }
186 };
187 
188 template <int InstWidth>
189 std::ostream &
190 operator<<(std::ostream & os, const SimplePCState<InstWidth> &pc)
191 {
192  ccprintf(os, "(%#x=>%#x)", pc.pc(), pc.npc());
193  return os;
194 }
195 
196 // A PC and microcode PC.
197 template <int InstWidth>
198 class UPCState : public SimplePCState<InstWidth>
199 {
200  protected:
202 
205 
206  public:
207 
208  MicroPC upc() const { return _upc; }
209  void upc(MicroPC val) { _upc = val; }
210 
211  MicroPC nupc() const { return _nupc; }
212  void nupc(MicroPC val) { _nupc = val; }
213 
214  MicroPC
215  microPC() const
216  {
217  return _upc;
218  }
219 
220  void
222  {
223  Base::set(val);
224  upc(0);
225  nupc(1);
226  }
227 
228  UPCState() : _upc(0), _nupc(1) {}
229  UPCState(Addr val) : _upc(0), _nupc(0) { set(val); }
230 
231  bool
232  branching() const
233  {
234  return this->npc() != this->pc() + InstWidth ||
235  this->nupc() != this->upc() + 1;
236  }
237 
238  // Advance the upc within the instruction.
239  void
241  {
242  _upc = _nupc;
243  _nupc++;
244  }
245 
246  // End the macroop by resetting the upc and advancing the regular pc.
247  void
249  {
250  this->advance();
251  _upc = 0;
252  _nupc = 1;
253  }
254 
255  // Reset the macroop's upc without advancing the regular pc.
256  void
258  {
259  _upc = 0;
260  _nupc = 1;
261  }
262 
263  bool
265  {
266  return Base::_pc == opc._pc &&
267  Base::_npc == opc._npc &&
268  _upc == opc._upc && _nupc == opc._nupc;
269  }
270 
271  bool
273  {
274  return !(*this == opc);
275  }
276 
277  void
278  serialize(CheckpointOut &cp) const override
279  {
280  Base::serialize(cp);
283  }
284 
285  void
286  unserialize(CheckpointIn &cp) override
287  {
288  Base::unserialize(cp);
291  }
292 };
293 
294 template <int InstWidth>
295 std::ostream &
296 operator<<(std::ostream & os, const UPCState<InstWidth> &pc)
297 {
298  ccprintf(os, "(%#x=>%#x).(%d=>%d)",
299  pc.pc(), pc.npc(), pc.upc(), pc.nupc());
300  return os;
301 }
302 
303 // A PC with a delay slot.
304 template <int InstWidth>
305 class DelaySlotPCState : public SimplePCState<InstWidth>
306 {
307  protected:
309 
311 
312  public:
313 
314  Addr nnpc() const { return _nnpc; }
315  void nnpc(Addr val) { _nnpc = val; }
316 
317  void
319  {
320  Base::set(val);
321  nnpc(val + 2 * InstWidth);
322  }
323 
326 
327  bool
328  branching() const
329  {
330  return !(this->nnpc() == this->npc() + InstWidth &&
331  (this->npc() == this->pc() + InstWidth ||
332  this->npc() == this->pc() + 2 * InstWidth));
333  }
334 
335  // Advance the PC.
336  void
338  {
340  Base::_npc = _nnpc;
341  _nnpc += InstWidth;
342  }
343 
344  bool
346  {
347  return Base::_pc == opc._pc &&
348  Base::_npc == opc._npc &&
349  _nnpc == opc._nnpc;
350  }
351 
352  bool
354  {
355  return !(*this == opc);
356  }
357 
358  void
359  serialize(CheckpointOut &cp) const override
360  {
361  Base::serialize(cp);
363  }
364 
365  void
366  unserialize(CheckpointIn &cp) override
367  {
368  Base::unserialize(cp);
370  }
371 };
372 
373 template <int InstWidth>
374 std::ostream &
376 {
377  ccprintf(os, "(%#x=>%#x=>%#x)",
378  pc.pc(), pc.npc(), pc.nnpc());
379  return os;
380 }
381 
382 // A PC with a delay slot and a microcode PC.
383 template <int InstWidth>
384 class DelaySlotUPCState : public DelaySlotPCState<InstWidth>
385 {
386  protected:
388 
391 
392  public:
393 
394  MicroPC upc() const { return _upc; }
395  void upc(MicroPC val) { _upc = val; }
396 
397  MicroPC nupc() const { return _nupc; }
398  void nupc(MicroPC val) { _nupc = val; }
399 
400  MicroPC
401  microPC() const
402  {
403  return _upc;
404  }
405 
406  void
408  {
409  Base::set(val);
410  upc(0);
411  nupc(1);
412  }
413 
416 
417  bool
418  branching() const
419  {
420  return Base::branching() || this->nupc() != this->upc() + 1;
421  }
422 
423  // Advance the upc within the instruction.
424  void
426  {
427  _upc = _nupc;
428  _nupc++;
429  }
430 
431  // End the macroop by resetting the upc and advancing the regular pc.
432  void
434  {
435  this->advance();
436  _upc = 0;
437  _nupc = 1;
438  }
439 
440  bool
442  {
443  return Base::_pc == opc._pc &&
444  Base::_npc == opc._npc &&
445  Base::_nnpc == opc._nnpc &&
446  _upc == opc._upc && _nupc == opc._nupc;
447  }
448 
449  bool
451  {
452  return !(*this == opc);
453  }
454 
455  void
456  serialize(CheckpointOut &cp) const override
457  {
458  Base::serialize(cp);
461  }
462 
463  void
464  unserialize(CheckpointIn &cp) override
465  {
466  Base::unserialize(cp);
469  }
470 };
471 
472 template <int InstWidth>
473 std::ostream &
475 {
476  ccprintf(os, "(%#x=>%#x=>%#x).(%d=>%d)",
477  pc.pc(), pc.npc(), pc.nnpc(), pc.upc(), pc.nupc());
478  return os;
479 }
480 
481 }
482 
483 } // namespace gem5
484 
485 #endif
gem5::GenericISA::DelaySlotPCState::operator==
bool operator==(const DelaySlotPCState< InstWidth > &opc) const
Definition: types.hh:345
gem5::GenericISA::UPCState::nupc
void nupc(MicroPC val)
Definition: types.hh:212
gem5::GenericISA::DelaySlotUPCState::set
void set(Addr val)
Definition: types.hh:407
gem5::GenericISA::UPCState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:286
gem5::GenericISA::PCStateBase::_pc
Addr _pc
Definition: types.hh:60
gem5::GenericISA::DelaySlotPCState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:359
gem5::GenericISA::PCStateBase::_npc
Addr _npc
Definition: types.hh:61
gem5::GenericISA::SimplePCState::npc
Addr npc() const
Definition: types.hh:154
gem5::GenericISA::DelaySlotUPCState::operator==
bool operator==(const DelaySlotUPCState< InstWidth > &opc) const
Definition: types.hh:441
gem5::GenericISA::DelaySlotPCState::_nnpc
Addr _nnpc
Definition: types.hh:310
gem5::GenericISA::UPCState::operator==
bool operator==(const UPCState< InstWidth > &opc) const
Definition: types.hh:264
gem5::GenericISA::DelaySlotUPCState::_upc
MicroPC _upc
Definition: types.hh:389
gem5::GenericISA::UPCState::UPCState
UPCState()
Definition: types.hh:228
serialize.hh
gem5::GenericISA::PCStateBase::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:128
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
gem5::GenericISA::SimplePCState::Base
PCStateBase Base
Definition: types.hh:147
gem5::GenericISA::DelaySlotUPCState::microPC
MicroPC microPC() const
Definition: types.hh:401
gem5::GenericISA::PCStateBase::microPC
MicroPC microPC() const
Returns the current micropc.
Definition: types.hh:95
gem5::GenericISA::SimplePCState::SimplePCState
SimplePCState()
Definition: types.hh:170
gem5::GenericISA::UPCState::uReset
void uReset()
Definition: types.hh:257
gem5::GenericISA::SimplePCState::setNPC
void setNPC(Addr val)
Definition: types.hh:165
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::GenericISA::UPCState::UPCState
UPCState(Addr val)
Definition: types.hh:229
gem5::GenericISA::DelaySlotPCState::DelaySlotPCState
DelaySlotPCState(Addr val)
Definition: types.hh:325
gem5::GenericISA::UPCState
Definition: types.hh:198
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
gem5::GenericISA::PCStateBase::operator!=
bool operator!=(const PCStateBase &opc) const
Definition: types.hh:115
gem5::GenericISA::DelaySlotPCState::nnpc
Addr nnpc() const
Definition: types.hh:314
gem5::GenericISA::SimplePCState::SimplePCState
SimplePCState(Addr val)
Definition: types.hh:171
gem5::GenericISA::DelaySlotPCState
Definition: types.hh:305
gem5::GenericISA::DelaySlotUPCState::operator!=
bool operator!=(const DelaySlotUPCState< InstWidth > &opc) const
Definition: types.hh:450
gem5::GenericISA::DelaySlotPCState::set
void set(Addr val)
Definition: types.hh:318
gem5::GenericISA::DelaySlotUPCState::upc
void upc(MicroPC val)
Definition: types.hh:395
gem5::GenericISA::DelaySlotUPCState::DelaySlotUPCState
DelaySlotUPCState()
Definition: types.hh:414
gem5::GenericISA::PCStateBase
Definition: types.hh:57
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
gem5::GenericISA::DelaySlotUPCState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:456
gem5::GenericISA::DelaySlotUPCState::upc
MicroPC upc() const
Definition: types.hh:394
gem5::GenericISA::DelaySlotPCState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:366
gem5::GenericISA::SimplePCState
Definition: types.hh:144
gem5::MicroPC
uint16_t MicroPC
Definition: types.hh:149
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::GenericISA::UPCState::_nupc
MicroPC _nupc
Definition: types.hh:204
gem5::GenericISA::DelaySlotPCState::operator!=
bool operator!=(const DelaySlotPCState< InstWidth > &opc) const
Definition: types.hh:353
gem5::GenericISA::DelaySlotUPCState::nupc
void nupc(MicroPC val)
Definition: types.hh:398
gem5::GenericISA::PCStateBase::PCStateBase
PCStateBase(Addr val)
Definition: types.hh:64
gem5::GenericISA::DelaySlotPCState::Base
SimplePCState< InstWidth > Base
Definition: types.hh:308
gem5::GenericISA::DelaySlotUPCState::branching
bool branching() const
Definition: types.hh:418
gem5::GenericISA::DelaySlotPCState::nnpc
void nnpc(Addr val)
Definition: types.hh:315
gem5::GenericISA::PCStateBase::operator==
bool operator==(const PCStateBase &opc) const
Definition: types.hh:109
gem5::GenericISA::UPCState::upc
void upc(MicroPC val)
Definition: types.hh:209
gem5::GenericISA::UPCState::_upc
MicroPC _upc
Definition: types.hh:203
gem5::GenericISA::DelaySlotUPCState::uAdvance
void uAdvance()
Definition: types.hh:425
gem5::GenericISA::DelaySlotUPCState::Base
DelaySlotPCState< InstWidth > Base
Definition: types.hh:387
gem5::GenericISA::PCStateBase::set
void set(Addr val)
Force this PC to reflect a particular value, resetting all its other fields around it.
gem5::GenericISA::SimplePCState::pc
void pc(Addr val)
Definition: types.hh:152
gem5::GenericISA::UPCState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:278
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
gem5::GenericISA::SimplePCState::npc
void npc(Addr val)
Definition: types.hh:155
gem5::GenericISA::DelaySlotUPCState::_nupc
MicroPC _nupc
Definition: types.hh:390
gem5::GenericISA::PCStateBase::nextInstAddr
Addr nextInstAddr() const
Returns the memory address the bytes of the next instruction came from.
Definition: types.hh:84
gem5::GenericISA::UPCState::uAdvance
void uAdvance()
Definition: types.hh:240
gem5::GenericISA::DelaySlotUPCState::DelaySlotUPCState
DelaySlotUPCState(Addr val)
Definition: types.hh:415
gem5::GenericISA::SimplePCState::advance
void advance()
Definition: types.hh:181
gem5::GenericISA::DelaySlotUPCState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:464
gem5::GenericISA::PCStateBase::PCStateBase
PCStateBase()
Definition: types.hh:63
gem5::GenericISA::SimplePCState::branching
bool branching() const
Definition: types.hh:174
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::GenericISA::operator<<
std::ostream & operator<<(std::ostream &os, const SimplePCState< InstWidth > &pc)
Definition: types.hh:190
gem5::GenericISA::UPCState::nupc
MicroPC nupc() const
Definition: types.hh:211
gem5::GenericISA::SimplePCState::set
void set(Addr val)
Definition: types.hh:158
gem5::GenericISA::UPCState::set
void set(Addr val)
Definition: types.hh:221
gem5::GenericISA::DelaySlotUPCState
Definition: types.hh:384
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::GenericISA::DelaySlotPCState::branching
bool branching() const
Definition: types.hh:328
gem5::GenericISA::UPCState::microPC
MicroPC microPC() const
Definition: types.hh:215
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::GenericISA::PCStateBase::instAddr
Addr instAddr() const
Returns the memory address the bytes of this instruction came from.
Definition: types.hh:73
gem5::GenericISA::DelaySlotPCState::advance
void advance()
Definition: types.hh:337
trace.hh
gem5::GenericISA::PCStateBase::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:121
gem5::GenericISA::UPCState::upc
MicroPC upc() const
Definition: types.hh:208
gem5::GenericISA::UPCState::operator!=
bool operator!=(const UPCState< InstWidth > &opc) const
Definition: types.hh:272
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::GenericISA::DelaySlotPCState::DelaySlotPCState
DelaySlotPCState()
Definition: types.hh:324
gem5::GenericISA::SimplePCState::pc
Addr pc() const
Definition: types.hh:151
gem5::GenericISA::DelaySlotUPCState::nupc
MicroPC nupc() const
Definition: types.hh:397
gem5::GenericISA::UPCState::Base
SimplePCState< InstWidth > Base
Definition: types.hh:201
gem5::GenericISA::UPCState::uEnd
void uEnd()
Definition: types.hh:248
gem5::GenericISA::UPCState::branching
bool branching() const
Definition: types.hh:232
gem5::GenericISA::DelaySlotUPCState::uEnd
void uEnd()
Definition: types.hh:433

Generated on Tue Sep 21 2021 12:24:46 for gem5 by doxygen 1.8.17