gem5  v22.1.0.0
decoder.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __ARCH_GENERIC_DECODER_HH__
29 #define __ARCH_GENERIC_DECODER_HH__
30 
31 #include "arch/generic/pcstate.hh"
32 #include "base/bitfield.hh"
33 #include "base/intmath.hh"
34 #include "base/types.hh"
35 #include "cpu/static_inst_fwd.hh"
36 #include "params/InstDecoder.hh"
37 #include "sim/sim_object.hh"
38 
39 namespace gem5
40 {
41 
42 class InstDecoder : public SimObject
43 {
44  protected:
48 
49  bool instDone = false;
50  bool outOfBytes = true;
51 
52  public:
53  template <typename MoreBytesType>
54  InstDecoder(const InstDecoderParams &params, MoreBytesType *mb_buf) :
55  SimObject(params), _moreBytesPtr(mb_buf),
56  _moreBytesSize(sizeof(MoreBytesType)),
58  {}
59 
61  MicroPC micropc, StaticInstPtr curMacroop);
62  virtual void
64  {
65  instDone = false;
66  outOfBytes = true;
67  }
68 
69  template <class Type>
70  Type &
71  as()
72  {
73  return *static_cast<Type *>(this);
74  }
75 
76  template <class Type>
77  const Type &
78  as() const
79  {
80  return *static_cast<const Type *>(this);
81  }
82 
88  virtual void
90  {
91  instDone = old->instDone;
92  outOfBytes = old->outOfBytes;
93  }
94 
95  void *moreBytesPtr() const { return _moreBytesPtr; }
96  size_t moreBytesSize() const { return _moreBytesSize; }
97  Addr pcMask() const { return _pcMask; }
98 
107  bool instReady() const { return instDone; }
108 
116  bool needMoreBytes() const { return outOfBytes; }
117 
143  virtual void moreBytes(const PCStateBase &pc, Addr fetchPC) = 0;
144 
157 };
158 
159 } // namespace gem5
160 
161 #endif // __ARCH_DECODER_GENERIC_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
virtual StaticInstPtr decode(PCStateBase &pc)=0
Decode an instruction or fetch it from the code cache.
Type & as()
Definition: decoder.hh:71
virtual StaticInstPtr fetchRomMicroop(MicroPC micropc, StaticInstPtr curMacroop)
Definition: decoder.cc:36
void * moreBytesPtr() const
Definition: decoder.hh:95
virtual void takeOverFrom(InstDecoder *old)
Take over the state from an old decoder when switching CPUs.
Definition: decoder.hh:89
InstDecoder(const InstDecoderParams &params, MoreBytesType *mb_buf)
Definition: decoder.hh:54
size_t moreBytesSize() const
Definition: decoder.hh:96
bool needMoreBytes() const
Can the decoder accept more data?
Definition: decoder.hh:116
bool instReady() const
Is an instruction ready to be decoded?
Definition: decoder.hh:107
virtual void reset()
Definition: decoder.hh:63
virtual void moreBytes(const PCStateBase &pc, Addr fetchPC)=0
Feed data to the decoder.
void * _moreBytesPtr
Definition: decoder.hh:45
const Type & as() const
Definition: decoder.hh:78
size_t _moreBytesSize
Definition: decoder.hh:46
Addr pcMask() const
Definition: decoder.hh:97
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
const Params & params() const
Definition: sim_object.hh:176
Bitfield< 4 > pc
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint16_t MicroPC
Definition: types.hh:149

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1