gem5 v24.1.0.1
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-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
56Decoder::Decoder(const ArmDecoderParams &params)
57 : InstDecoder(params, &data),
58 dvmEnabled(params.dvm_enabled),
59 data(0), fpscrLen(0), fpscrStride(0),
60 decoderFlavor(safe_cast<ISA *>(params.isa)->decoderFlavor())
61{
62 reset();
63
64 // Initialize SVE vector length
65 sveLen = (safe_cast<ISA *>(params.isa)->
66 getCurSveVecLenInBitsAtReset() >> 7) - 1;
67
68 // Initialize SME vector length
69 smeLen = (safe_cast<ISA *>(params.isa)
70 ->getCurSmeVecLenInBitsAtReset() >> 7) - 1;
71
72 if (dvmEnabled) {
74 "DVM Ops instructions are micro-architecturally "
75 "modelled as loads. This will tamper the effective "
76 "number of loads stat\n");
77 }
78}
79
80void
82{
84 bigThumb = false;
85 offset = 0;
86 emi = 0;
87 foundIt = false;
88}
89
90void
92{
93 // emi is typically ready, with some caveats below...
94 instDone = true;
95
96 if (!emi.thumb) {
97 emi.instBits = data;
98 if (!emi.aarch64) {
99 emi.sevenAndFour = bits(data, 7) && bits(data, 4);
100 emi.isMisc = (bits(data, 24, 23) == 0x2 &&
101 bits(data, 20) == 0);
102 }
103 consumeBytes(4);
104 DPRINTF(Decoder, "Arm inst: %#x.\n", (uint64_t)emi);
105 } else {
106 uint16_t word = (data >> (offset * 8));
107 if (bigThumb) {
108 // A 32 bit thumb inst is half collected.
109 emi.instBits = emi.instBits | word;
110 bigThumb = false;
111 consumeBytes(2);
112 DPRINTF(Decoder, "Second half of 32 bit Thumb: %#x.\n",
113 emi.instBits);
114 } else {
115 uint16_t highBits = word & 0xF800;
116 if (highBits == 0xE800 || highBits == 0xF000 ||
117 highBits == 0xF800) {
118 // The start of a 32 bit thumb inst.
119 emi.bigThumb = 1;
120 if (offset == 0) {
121 // We've got the whole thing.
122 emi.instBits = (data >> 16) | (data << 16);
123 DPRINTF(Decoder, "All of 32 bit Thumb: %#x.\n",
124 emi.instBits);
125 consumeBytes(4);
126 } else {
127 // We only have the first half word.
129 "First half of 32 bit Thumb.\n");
130 emi.instBits = (uint32_t)word << 16;
131 bigThumb = true;
132 consumeBytes(2);
133 // emi not ready yet.
134 instDone = false;
135 }
136 } else {
137 // A 16 bit thumb inst.
138 consumeBytes(2);
139 emi.instBits = word;
140 // Set the condition code field artificially.
141 emi.condCode = COND_UC;
142 DPRINTF(Decoder, "16 bit Thumb: %#x.\n",
143 emi.instBits);
144 if (bits(word, 15, 8) == 0xbf &&
145 bits(word, 3, 0) != 0x0) {
146 foundIt = true;
147 itBits = bits(word, 7, 0);
149 "IT detected, cond = %#x, mask = %#x\n",
150 itBits.cond, itBits.mask);
151 }
152 }
153 }
154 }
155}
156
157void
159{
160 offset += numBytes;
161 assert(offset <= sizeof(data) || emi.decoderFault);
162 if (offset == sizeof(data))
163 outOfBytes = true;
164}
165
166void
168{
169 auto &pc = _pc.as<PCState>();
170 data = letoh(data);
171 offset = (fetchPC >= pc.instAddr()) ? 0 : pc.instAddr() - fetchPC;
172 emi.thumb = pc.thumb();
173 emi.aarch64 = pc.aarch64();
174 emi.fpscrLen = fpscrLen;
175 emi.fpscrStride = fpscrStride;
176 emi.sveLen = sveLen;
177
178 const Addr alignment(pc.thumb() ? 0x1 : 0x3);
179 emi.decoderFault = static_cast<uint8_t>(
180 pc.instAddr() & alignment ? DecoderFault::UNALIGNED : DecoderFault::OK);
181
182 outOfBytes = false;
183 process();
184}
185
188{
189 if (!instDone)
190 return NULL;
191
192 auto &pc = _pc.as<PCState>();
193
194 const int inst_size((!emi.thumb || emi.bigThumb) ? 4 : 2);
195 ExtMachInst this_emi(emi);
196
197 pc.npc(pc.pc() + inst_size);
198 if (foundIt)
199 pc.nextItstate(itBits);
200 this_emi.itstate = pc.itstate();
201 this_emi.illegalExecution = pc.illegalExec() ? 1 : 0;
202 this_emi.debugStep = pc.debugStep() ? 1 : 0;
203 pc.size(inst_size);
204
205 emi = 0;
206 instDone = false;
207 foundIt = false;
208
209 return decode(this_emi, pc.instAddr());
210}
211
212} // namespace ArmISA
213} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
const char data[]
void consumeBytes(int numBytes)
Consume bytes by moving the offset into the data word and sanity check the results.
Definition decoder.cc:158
void reset() override
Reset the decoders internal state.
Definition decoder.cc:81
Decoder(const ArmDecoderParams &params)
Definition decoder.cc:56
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:91
void moreBytes(const PCStateBase &pc, Addr fetchPC) override
Feed data to the decoder.
Definition decoder.cc:167
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:398
@ OK
No fault.
Definition types.hh:397
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 Arm Limited 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 Mon Jan 13 2025 04:28:21 for gem5 by doxygen 1.9.8