gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Gabe Black
29  */
30 
31 #ifndef __ARCH_GENERIC_TYPES_HH__
32 #define __ARCH_GENERIC_TYPES_HH__
33 
34 #include <iostream>
35 
36 #include "base/trace.hh"
37 #include "base/types.hh"
38 #include "sim/serialize.hh"
39 
40 namespace GenericISA
41 {
42 
43 // The guaranteed interface.
44 class PCStateBase : public Serializable
45 {
46  protected:
49 
50  PCStateBase() : _pc(0), _npc(0) {}
51  PCStateBase(Addr val) : _pc(0), _npc(0) { set(val); }
52 
53  public:
59  Addr
60  instAddr() const
61  {
62  return _pc;
63  }
64 
70  Addr
71  nextInstAddr() const
72  {
73  return _npc;
74  }
75 
81  MicroPC
82  microPC() const
83  {
84  return 0;
85  }
86 
93  void set(Addr val);
94 
95  bool
96  operator == (const PCStateBase &opc) const
97  {
98  return _pc == opc._pc && _npc == opc._npc;
99  }
100 
101  bool
102  operator != (const PCStateBase &opc) const
103  {
104  return !(*this == opc);
105  }
106 
107  void
108  serialize(CheckpointOut &cp) const override
109  {
112  }
113 
114  void
115  unserialize(CheckpointIn &cp) override
116  {
119  }
120 };
121 
122 
123 /*
124  * Different flavors of PC state. Only ISA specific code should rely on
125  * any particular type of PC state being available. All other code should
126  * use the interface above.
127  */
128 
129 // The most basic type of PC.
130 template <class MachInst>
132 {
133  protected:
134  typedef PCStateBase Base;
135 
136  public:
137 
138  Addr pc() const { return _pc; }
139  void pc(Addr val) { _pc = val; }
140 
141  Addr npc() const { return _npc; }
142  void npc(Addr val) { _npc = val; }
143 
144  void
146  {
147  pc(val);
148  npc(val + sizeof(MachInst));
149  };
150 
151  void
153  {
154  npc(val);
155  }
156 
159 
160  bool
161  branching() const
162  {
163  return this->npc() != this->pc() + sizeof(MachInst);
164  }
165 
166  // Advance the PC.
167  void
169  {
170  _pc = _npc;
171  _npc += sizeof(MachInst);
172  }
173 };
174 
175 template <class MachInst>
176 std::ostream &
177 operator<<(std::ostream & os, const SimplePCState<MachInst> &pc)
178 {
179  ccprintf(os, "(%#x=>%#x)", pc.pc(), pc.npc());
180  return os;
181 }
182 
183 // A PC and microcode PC.
184 template <class MachInst>
185 class UPCState : public SimplePCState<MachInst>
186 {
187  protected:
189 
192 
193  public:
194 
195  MicroPC upc() const { return _upc; }
196  void upc(MicroPC val) { _upc = val; }
197 
198  MicroPC nupc() const { return _nupc; }
199  void nupc(MicroPC val) { _nupc = val; }
200 
201  MicroPC
202  microPC() const
203  {
204  return _upc;
205  }
206 
207  void
209  {
210  Base::set(val);
211  upc(0);
212  nupc(1);
213  }
214 
215  UPCState() : _upc(0), _nupc(0) {}
216  UPCState(Addr val) : _upc(0), _nupc(0) { set(val); }
217 
218  bool
219  branching() const
220  {
221  return this->npc() != this->pc() + sizeof(MachInst) ||
222  this->nupc() != this->upc() + 1;
223  }
224 
225  // Advance the upc within the instruction.
226  void
228  {
229  _upc = _nupc;
230  _nupc++;
231  }
232 
233  // End the macroop by resetting the upc and advancing the regular pc.
234  void
236  {
237  this->advance();
238  _upc = 0;
239  _nupc = 1;
240  }
241 
242  bool
244  {
245  return Base::_pc == opc._pc &&
246  Base::_npc == opc._npc &&
247  _upc == opc._upc && _nupc == opc._nupc;
248  }
249 
250  bool
252  {
253  return !(*this == opc);
254  }
255 
256  void
257  serialize(CheckpointOut &cp) const override
258  {
259  Base::serialize(cp);
262  }
263 
264  void
265  unserialize(CheckpointIn &cp) override
266  {
267  Base::unserialize(cp);
270  }
271 };
272 
273 template <class MachInst>
274 std::ostream &
275 operator<<(std::ostream & os, const UPCState<MachInst> &pc)
276 {
277  ccprintf(os, "(%#x=>%#x).(%d=>%d)",
278  pc.pc(), pc.npc(), pc.upc(), pc.nupc());
279  return os;
280 }
281 
282 // A PC with a delay slot.
283 template <class MachInst>
284 class DelaySlotPCState : public SimplePCState<MachInst>
285 {
286  protected:
288 
290 
291  public:
292 
293  Addr nnpc() const { return _nnpc; }
294  void nnpc(Addr val) { _nnpc = val; }
295 
296  void
298  {
299  Base::set(val);
300  nnpc(val + 2 * sizeof(MachInst));
301  }
302 
305 
306  bool
307  branching() const
308  {
309  return !(this->nnpc() == this->npc() + sizeof(MachInst) &&
310  (this->npc() == this->pc() + sizeof(MachInst) ||
311  this->npc() == this->pc() + 2 * sizeof(MachInst)));
312  }
313 
314  // Advance the PC.
315  void
317  {
319  Base::_npc = _nnpc;
320  _nnpc += sizeof(MachInst);
321  }
322 
323  bool
325  {
326  return Base::_pc == opc._pc &&
327  Base::_npc == opc._npc &&
328  _nnpc == opc._nnpc;
329  }
330 
331  bool
333  {
334  return !(*this == opc);
335  }
336 
337  void
338  serialize(CheckpointOut &cp) const override
339  {
340  Base::serialize(cp);
342  }
343 
344  void
345  unserialize(CheckpointIn &cp) override
346  {
347  Base::unserialize(cp);
349  }
350 };
351 
352 template <class MachInst>
353 std::ostream &
354 operator<<(std::ostream & os, const DelaySlotPCState<MachInst> &pc)
355 {
356  ccprintf(os, "(%#x=>%#x=>%#x)",
357  pc.pc(), pc.npc(), pc.nnpc());
358  return os;
359 }
360 
361 // A PC with a delay slot and a microcode PC.
362 template <class MachInst>
363 class DelaySlotUPCState : public DelaySlotPCState<MachInst>
364 {
365  protected:
367 
370 
371  public:
372 
373  MicroPC upc() const { return _upc; }
374  void upc(MicroPC val) { _upc = val; }
375 
376  MicroPC nupc() const { return _nupc; }
377  void nupc(MicroPC val) { _nupc = val; }
378 
379  MicroPC
380  microPC() const
381  {
382  return _upc;
383  }
384 
385  void
387  {
388  Base::set(val);
389  upc(0);
390  nupc(1);
391  }
392 
395 
396  bool
397  branching() const
398  {
399  return Base::branching() || this->nupc() != this->upc() + 1;
400  }
401 
402  // Advance the upc within the instruction.
403  void
405  {
406  _upc = _nupc;
407  _nupc++;
408  }
409 
410  // End the macroop by resetting the upc and advancing the regular pc.
411  void
413  {
414  this->advance();
415  _upc = 0;
416  _nupc = 1;
417  }
418 
419  bool
421  {
422  return Base::_pc == opc._pc &&
423  Base::_npc == opc._npc &&
424  Base::_nnpc == opc._nnpc &&
425  _upc == opc._upc && _nupc == opc._nupc;
426  }
427 
428  bool
430  {
431  return !(*this == opc);
432  }
433 
434  void
435  serialize(CheckpointOut &cp) const override
436  {
437  Base::serialize(cp);
440  }
441 
442  void
443  unserialize(CheckpointIn &cp) override
444  {
445  Base::unserialize(cp);
448  }
449 };
450 
451 template <class MachInst>
452 std::ostream &
453 operator<<(std::ostream & os, const DelaySlotUPCState<MachInst> &pc)
454 {
455  ccprintf(os, "(%#x=>%#x=>%#x).(%d=>%d)",
456  pc.pc(), pc.npc(), pc.nnpc(), pc.upc(), pc.nupc());
457  return os;
458 }
459 
460 }
461 
462 #endif
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
bool branching() const
Definition: types.hh:397
SimplePCState< MachInst > Base
Definition: types.hh:188
bool operator!=(const DelaySlotUPCState< MachInst > &opc) const
Definition: types.hh:429
void setNPC(Addr val)
Definition: types.hh:152
bool branching() const
Definition: types.hh:219
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:115
void set(Addr val)
Definition: types.hh:208
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:345
bool operator!=(const DelaySlotPCState< MachInst > &opc) const
Definition: types.hh:332
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:435
void set(Addr val)
Definition: types.hh:145
Bitfield< 17 > os
Definition: misc.hh:804
Bitfield< 63 > val
Definition: misc.hh:770
void pc(Addr val)
Definition: types.hh:139
MicroPC microPC() const
Returns the current micropc.
Definition: types.hh:82
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:108
bool operator==(const DelaySlotPCState< MachInst > &opc) const
Definition: types.hh:324
Addr pc() const
Definition: types.hh:138
Addr instAddr() const
Returns the memory address the bytes of this instruction came from.
Definition: types.hh:60
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
void set(Addr val)
Force this PC to reflect a particular value, resetting all its other fields around it...
MicroPC upc() const
Definition: types.hh:195
DelaySlotPCState< MachInst > Base
Definition: types.hh:366
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:338
MicroPC upc() const
Definition: types.hh:373
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:265
UPCState(Addr val)
Definition: types.hh:216
PCStateBase(Addr val)
Definition: types.hh:51
uint16_t MicroPC
Definition: types.hh:144
SimplePCState(Addr val)
Definition: types.hh:158
uint64_t MachInst
Definition: types.hh:54
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:142
MicroPC nupc() const
Definition: types.hh:376
bool operator==(const DelaySlotUPCState< MachInst > &opc) const
Definition: types.hh:420
MicroPC microPC() const
Definition: types.hh:380
Basic support for object serialization.
Definition: serialize.hh:220
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
MicroPC microPC() const
Definition: types.hh:202
void nupc(MicroPC val)
Definition: types.hh:377
bool operator==(const PCStateBase &opc) const
Definition: types.hh:96
void set(Addr val)
Definition: types.hh:297
bool branching() const
Definition: types.hh:307
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:443
void npc(Addr val)
Definition: types.hh:142
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:257
Addr npc() const
Definition: types.hh:141
Addr nextInstAddr() const
Returns the memory address the bytes of the next instruction came from.
Definition: types.hh:71
std::ostream CheckpointOut
Definition: serialize.hh:67
bool operator!=(const PCStateBase &opc) const
Definition: types.hh:102
bool branching() const
Definition: types.hh:161
SimplePCState< MachInst > Base
Definition: types.hh:287
MicroPC nupc() const
Definition: types.hh:198
IntReg pc
Definition: remote_gdb.hh:91
bool operator==(const UPCState< MachInst > &opc) const
Definition: types.hh:243
void nupc(MicroPC val)
Definition: types.hh:199
void upc(MicroPC val)
Definition: types.hh:374
void nnpc(Addr val)
Definition: types.hh:294
bool operator!=(const UPCState< MachInst > &opc) const
Definition: types.hh:251
void upc(MicroPC val)
Definition: types.hh:196

Generated on Fri Jun 9 2017 13:03:37 for gem5 by doxygen 1.8.6