gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
decoder.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Google
3  * Copyright (c) The University of Virginia
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Gabe Black
30  * Alec Roelke
31  */
32 
33 #include "arch/riscv/decoder.hh"
34 #include "arch/riscv/types.hh"
35 #include "debug/Decode.hh"
36 
37 namespace RiscvISA
38 {
39 
40 static const MachInst LowerBitMask = (1 << sizeof(MachInst) * 4) - 1;
41 static const MachInst UpperBitMask = LowerBitMask << sizeof(MachInst) * 4;
42 
44 {
45  aligned = true;
46  mid = false;
47  more = true;
48  emi = 0;
49  instDone = false;
50 }
51 
52 void
53 Decoder::moreBytes(const PCState &pc, Addr fetchPC, MachInst inst)
54 {
55  inst = letoh(inst);
56  DPRINTF(Decode, "Requesting bytes 0x%08x from address %#x\n", inst,
57  fetchPC);
58 
59  bool aligned = pc.pc() % sizeof(MachInst) == 0;
60  if (aligned) {
61  emi = inst;
62  if (compressed(emi))
63  emi &= LowerBitMask;
64  more = !compressed(emi);
65  instDone = true;
66  } else {
67  if (mid) {
68  assert((emi & UpperBitMask) == 0);
69  emi |= (inst & LowerBitMask) << sizeof(MachInst)*4;
70  mid = false;
71  more = false;
72  instDone = true;
73  } else {
74  emi = (inst & UpperBitMask) >> sizeof(MachInst)*4;
75  mid = !compressed(emi);
76  more = true;
78  }
79  }
80 }
81 
84 {
85  DPRINTF(Decode, "Decoding instruction 0x%08x at address %#x\n",
86  mach_inst, addr);
87  if (instMap.find(mach_inst) != instMap.end())
88  return instMap[mach_inst];
89  else {
90  StaticInstPtr si = decodeInst(mach_inst);
91  instMap[mach_inst] = si;
92  return si;
93  }
94 }
95 
98 {
99  if (!instDone)
100  return nullptr;
101  instDone = false;
102 
103  if (compressed(emi)) {
104  nextPC.npc(nextPC.instAddr() + sizeof(MachInst) / 2);
105  } else {
106  nextPC.npc(nextPC.instAddr() + sizeof(MachInst));
107  }
108 
109  return decode(emi, nextPC.instAddr());
110 }
111 
112 }
#define DPRINTF(x,...)
Definition: trace.hh:229
Addr instAddr() const
Returns the memory address the bytes of this instruction came from.
Definition: types.hh:70
uint32_t MachInst
Definition: types.hh:54
ip6_addr_t addr
Definition: inet.hh:335
static const MachInst UpperBitMask
Definition: decoder.cc:41
uint64_t ExtMachInst
Definition: types.hh:55
T letoh(T value)
Definition: byteswap.hh:145
Bitfield< 15, 0 > si
Definition: types.hh:55
Bitfield< 4 > pc
StaticInstPtr decodeInst(ExtMachInst mach_inst)
static const MachInst LowerBitMask
Definition: decoder.cc:40
void moreBytes(const PCState &pc, Addr fetchPC, MachInst inst)
Definition: decoder.cc:53
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool compressed(ExtMachInst inst)
Definition: decoder.hh:67
Addr npc() const
Definition: types.hh:151
DecodeCache::InstMap< ExtMachInst > instMap
Definition: decoder.hh:51
StaticInstPtr decode(ExtMachInst mach_inst, Addr addr)
Decode a machine instruction.
Definition: decoder.cc:83
ExtMachInst emi
Definition: decoder.hh:58

Generated on Fri Feb 28 2020 16:26:55 for gem5 by doxygen 1.8.13