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

Generated on Wed Sep 30 2020 14:02:01 for gem5 by doxygen 1.8.17