gem5 v24.0.0.0
Loading...
Searching...
No Matches
decoder.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2014,2018, 2021 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) 2012 Google
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#include "arch/arm/decoder.hh"
42
43#include "arch/arm/isa.hh"
44#include "arch/arm/utility.hh"
45#include "base/cast.hh"
46#include "base/trace.hh"
47#include "debug/Decoder.hh"
48#include "sim/full_system.hh"
49
50namespace gem5
51{
52
53namespace ArmISA
54{
55
57
58Decoder::Decoder(const ArmDecoderParams &params)
59 : InstDecoder(params, &data),
60 dvmEnabled(params.dvm_enabled),
61 data(0), fpscrLen(0), fpscrStride(0),
62 decoderFlavor(safe_cast<ISA *>(params.isa)->decoderFlavor())
63{
64 reset();
65
66 // Initialize SVE vector length
68 getCurSveVecLenInBitsAtReset() >> 7) - 1;
69
70 // Initialize SME vector length
72 ->getCurSmeVecLenInBitsAtReset() >> 7) - 1;
73
74 if (dvmEnabled) {
76 "DVM Ops instructions are micro-architecturally "
77 "modelled as loads. This will tamper the effective "
78 "number of loads stat\n");
79 }
80}
81
82void
84{
86 bigThumb = false;
87 offset = 0;
88 emi = 0;
89 foundIt = false;
90}
91
92void
94{
95 // emi is typically ready, with some caveats below...
96 instDone = true;
97
98 if (!emi.thumb) {
99 emi.instBits = data;
100 if (!emi.aarch64) {
101 emi.sevenAndFour = bits(data, 7) && bits(data, 4);
102 emi.isMisc = (bits(data, 24, 23) == 0x2 &&
103 bits(data, 20) == 0);
104 }
105 consumeBytes(4);
106 DPRINTF(Decoder, "Arm inst: %#x.\n", (uint64_t)emi);
107 } else {
108 uint16_t word = (data >> (offset * 8));
109 if (bigThumb) {
110 // A 32 bit thumb inst is half collected.
111 emi.instBits = emi.instBits | word;
112 bigThumb = false;
113 consumeBytes(2);
114 DPRINTF(Decoder, "Second half of 32 bit Thumb: %#x.\n",
115 emi.instBits);
116 } else {
117 uint16_t highBits = word & 0xF800;
118 if (highBits == 0xE800 || highBits == 0xF000 ||
119 highBits == 0xF800) {
120 // The start of a 32 bit thumb inst.
121 emi.bigThumb = 1;
122 if (offset == 0) {
123 // We've got the whole thing.
124 emi.instBits = (data >> 16) | (data << 16);
125 DPRINTF(Decoder, "All of 32 bit Thumb: %#x.\n",
126 emi.instBits);
127 consumeBytes(4);
128 } else {
129 // We only have the first half word.
131 "First half of 32 bit Thumb.\n");
132 emi.instBits = (uint32_t)word << 16;
133 bigThumb = true;
134 consumeBytes(2);
135 // emi not ready yet.
136 instDone = false;
137 }
138 } else {
139 // A 16 bit thumb inst.
140 consumeBytes(2);
141 emi.instBits = word;
142 // Set the condition code field artificially.
143 emi.condCode = COND_UC;
144 DPRINTF(Decoder, "16 bit Thumb: %#x.\n",
145 emi.instBits);
146 if (bits(word, 15, 8) == 0xbf &&
147 bits(word, 3, 0) != 0x0) {
148 foundIt = true;
149 itBits = bits(word, 7, 0);
151 "IT detected, cond = %#x, mask = %#x\n",
152 itBits.cond, itBits.mask);
153 }
154 }
155 }
156 }
157}
158
159void
161{
162 offset += numBytes;
163 assert(offset <= sizeof(data) || emi.decoderFault);
164 if (offset == sizeof(data))
165 outOfBytes = true;
166}
167
168void
170{
171 auto &pc = _pc.as<PCState>();
172 data = letoh(data);
173 offset = (fetchPC >= pc.instAddr()) ? 0 : pc.instAddr() - fetchPC;
174 emi.thumb = pc.thumb();
175 emi.aarch64 = pc.aarch64();
176 emi.fpscrLen = fpscrLen;
177 emi.fpscrStride = fpscrStride;
178 emi.sveLen = sveLen;
179
180 const Addr alignment(pc.thumb() ? 0x1 : 0x3);
181 emi.decoderFault = static_cast<uint8_t>(
182 pc.instAddr() & alignment ? DecoderFault::UNALIGNED : DecoderFault::OK);
183
184 outOfBytes = false;
185 process();
186}
187
190{
191 if (!instDone)
192 return NULL;
193
194 auto &pc = _pc.as<PCState>();
195
196 const int inst_size((!emi.thumb || emi.bigThumb) ? 4 : 2);
197 ExtMachInst this_emi(emi);
198
199 pc.npc(pc.pc() + inst_size);
200 if (foundIt)
201 pc.nextItstate(itBits);
202 this_emi.itstate = pc.itstate();
203 this_emi.illegalExecution = pc.illegalExec() ? 1 : 0;
204 this_emi.debugStep = pc.debugStep() ? 1 : 0;
205 pc.size(inst_size);
206
207 emi = 0;
208 instDone = false;
209 foundIt = false;
210
211 return decode(this_emi, pc.instAddr());
212}
213
214} // namespace ArmISA
215} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
const char data[]
static GenericISA::BasicDecodeCache< Decoder, ExtMachInst > defaultCache
A cache of decoded instruction objects.
Definition decoder.hh:97
void consumeBytes(int numBytes)
Consume bytes by moving the offset into the data word and sanity check the results.
Definition decoder.cc:160
void reset() override
Reset the decoders internal state.
Definition decoder.cc:83
Decoder(const ArmDecoderParams &params)
Definition decoder.cc:58
int smeLen
SME vector length, encoded in the same format as the SMCR_EL<x>.LEN bitfields.
Definition decoder.hh:92
StaticInstPtr decode(ExtMachInst mach_inst, Addr addr)
Decode a pre-decoded machine instruction.
Definition decoder.hh:136
int sveLen
SVE vector length, encoded in the same format as the ZCR_EL<x>.LEN bitfields.
Definition decoder.hh:86
ExtMachInst emi
Definition decoder.hh:72
void process()
Pre-decode an instruction from the current state of the decoder.
Definition decoder.cc:93
void moreBytes(const PCStateBase &pc, Addr fetchPC) override
Feed data to the decoder.
Definition decoder.cc:169
const bool dvmEnabled
True if the decoder should emit DVM Ops (treated as Loads)
Definition decoder.hh:68
virtual void reset()
Definition decoder.hh:63
Target & as()
Definition pcstate.hh:73
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:79
const Params & params() const
#define warn_once(...)
Definition logging.hh:260
@ UNALIGNED
Unaligned instruction fault.
Definition types.hh:369
@ OK
No fault.
Definition types.hh:368
Bitfield< 41, 40 > fpscrStride
Definition types.hh:75
Bitfield< 39, 37 > fpscrLen
Definition types.hh:76
@ COND_UC
Definition cc.hh:120
Bitfield< 4 > pc
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
T letoh(T value)
Definition byteswap.hh:173
T safe_cast(U &&ref_or_ptr)
Definition cast.hh:74
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0