gem5 v24.0.0.0
Loading...
Searching...
No Matches
pcstate.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2013, 2017-2018 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) 2007-2008 The Florida State University
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#ifndef __ARCH_ARM_PCSTATE_HH__
42#define __ARCH_ARM_PCSTATE_HH__
43
45#include "base/bitunion.hh"
46#include "base/types.hh"
47#include "debug/Decoder.hh"
48
49namespace gem5
50{
51
52namespace ArmISA
53{
54
55BitUnion8(ITSTATE)
56 /* Note that the split (cond, mask) below is not as in ARM ARM.
57 * But it is more convenient for simulation. The condition
58 * is always the concatenation of the top 3 bits and the next bit,
59 * which applies when one of the bottom 4 bits is set.
60 * Refer to predecoder.cc for the use case.
61 */
62 Bitfield<7, 4> cond;
63 Bitfield<3, 0> mask;
64 // Bitfields for moving to/from CPSR
65 Bitfield<7, 2> top6;
66 Bitfield<1, 0> bottom2;
67EndBitUnion(ITSTATE)
68
69class PCState : public GenericISA::UPCState<4>
70{
71 protected:
72
73 typedef GenericISA::UPCState<4> Base;
74
75 enum FlagBits
76 {
77 ThumbBit = (1 << 0),
78 AArch64Bit = (1 << 2)
79 };
80
81 uint8_t flags = 0;
82 uint8_t nextFlags = 0;
83 uint8_t _itstate = 0;
84 uint8_t _nextItstate = 0;
85 uint8_t _size = 0;
86 bool _illegalExec = false;
87
88 // Software Step flags
89 bool _debugStep = false;
90 bool _stepped = false;
91
92 public:
93 void
94 set(Addr val) override
95 {
96 Base::set(val);
97 npc(val + (thumb() ? 2 : 4));
98 }
99
100 PCState(const PCState &other) : Base(other),
101 flags(other.flags), nextFlags(other.nextFlags),
102 _itstate(other._itstate), _nextItstate(other._nextItstate),
103 _size(other._size), _illegalExec(other._illegalExec),
104 _debugStep(other._debugStep), _stepped(other._stepped)
105 {}
106 PCState &operator=(const PCState &other) = default;
107
108 PCState() {}
109 explicit PCState(Addr val) { set(val); }
110
111 PCStateBase *clone() const override { return new PCState(*this); }
112
113 void
114 update(const PCStateBase &other) override
115 {
116 Base::update(other);
117 auto &pcstate = other.as<PCState>();
118 flags = pcstate.flags;
119 nextFlags = pcstate.nextFlags;
120 _itstate = pcstate._itstate;
121 _nextItstate = pcstate._nextItstate;
122 _size = pcstate._size;
123 _illegalExec = pcstate._illegalExec;
124 _debugStep = pcstate._debugStep;
125 _stepped = pcstate._stepped;
126 }
127
128 bool
129 illegalExec() const
130 {
131 return _illegalExec;
132 }
133
134 void
135 illegalExec(bool val)
136 {
137 _illegalExec = val;
138 }
139
140 bool
141 debugStep() const
142 {
143 return _debugStep;
144 }
145
146 void
147 debugStep(bool val)
148 {
149 _debugStep = val;
150 }
151
152 bool
153 stepped() const
154 {
155 return _stepped;
156 }
157
158 void
159 stepped(bool val)
160 {
161 _stepped = val;
162 }
163
164 bool
165 thumb() const
166 {
167 return flags & ThumbBit;
168 }
169
170 void
171 thumb(bool val)
172 {
173 if (val)
174 flags |= ThumbBit;
175 else
176 flags &= ~ThumbBit;
177 }
178
179 bool
180 nextThumb() const
181 {
182 return nextFlags & ThumbBit;
183 }
184
185 void
186 nextThumb(bool val)
187 {
188 if (val)
189 nextFlags |= ThumbBit;
190 else
191 nextFlags &= ~ThumbBit;
192 }
193
194 void size(uint8_t s) { _size = s; }
195 uint8_t size() const { return _size; }
196
197 bool
198 branching() const override
199 {
200 return ((this->pc() + this->size()) != this->npc());
201 }
202
203
204 bool
205 aarch64() const
206 {
207 return flags & AArch64Bit;
208 }
209
210 void
211 aarch64(bool val)
212 {
213 if (val)
214 flags |= AArch64Bit;
215 else
216 flags &= ~AArch64Bit;
217 }
218
219 bool
220 nextAArch64() const
221 {
222 return nextFlags & AArch64Bit;
223 }
224
225 void
226 nextAArch64(bool val)
227 {
228 if (val)
229 nextFlags |= AArch64Bit;
230 else
231 nextFlags &= ~AArch64Bit;
232 }
233
234
235 uint8_t
236 itstate() const
237 {
238 return _itstate;
239 }
240
241 void
242 itstate(uint8_t value)
243 {
244 _itstate = value;
245 }
246
247 uint8_t
248 nextItstate() const
249 {
250 return _nextItstate;
251 }
252
253 void
254 nextItstate(uint8_t value)
255 {
256 _nextItstate = value;
257 }
258
259 void
260 advance() override
261 {
262 Base::advance();
263 flags = nextFlags;
264 npc(pc() + (thumb() ? 2 : 4));
265
266 if (_nextItstate) {
267 _itstate = _nextItstate;
268 _nextItstate = 0;
269 } else if (_itstate) {
270 ITSTATE it = _itstate;
271 uint8_t cond_mask = it.mask;
272 uint8_t thumb_cond = it.cond;
273 DPRINTF(Decoder, "Advancing ITSTATE from %#x,%#x.\n",
274 thumb_cond, cond_mask);
275 cond_mask <<= 1;
276 uint8_t new_bit = bits(cond_mask, 4);
277 cond_mask &= mask(4);
278 if (cond_mask == 0)
279 thumb_cond = 0;
280 else
281 replaceBits(thumb_cond, 0, new_bit);
282 DPRINTF(Decoder, "Advancing ITSTATE to %#x,%#x.\n",
283 thumb_cond, cond_mask);
284 it.mask = cond_mask;
285 it.cond = thumb_cond;
286 _itstate = it;
287 }
288 }
289
290 void
291 uEnd()
292 {
293 advance();
294 upc(0);
295 nupc(1);
296 }
297
298 Addr
299 instPC() const
300 {
301 return pc() + (thumb() ? 4 : 8);
302 }
303
304 void
305 instNPC(Addr val)
306 {
307 // @todo: review this when AArch32/64 interprocessing is
308 // supported
309 if (aarch64())
310 npc(val); // AArch64 doesn't force PC alignment, a PC
311 // Alignment Fault can be raised instead
312 else
313 npc(val &~ mask(nextThumb() ? 1 : 2));
314 }
315
316 Addr
317 instNPC() const
318 {
319 return npc();
320 }
321
322 // Perform an interworking branch.
323 void
324 instIWNPC(Addr val)
325 {
326 if (bits(val, 0)) {
327 nextThumb(true);
328 val = val & ~mask(1);
329 } else if (!bits(val, 1)) {
330 nextThumb(false);
331 } else {
332 // This state is UNPREDICTABLE in the ARM architecture
333 // The easy thing to do is just mask off the bit and
334 // stay in the current mode, so we'll do that.
335 val &= ~mask(2);
336 }
337 npc(val);
338 }
339
340 // Perform an interworking branch in ARM mode, a regular branch
341 // otherwise.
342 void
343 instAIWNPC(Addr val)
344 {
345 if (!thumb())
346 instIWNPC(val);
347 else
348 instNPC(val);
349 }
350
351 bool
352 equals(const PCStateBase &other) const override
353 {
354 auto &opc = other.as<PCState>();
355 return Base::equals(other) &&
356 flags == opc.flags && nextFlags == opc.nextFlags &&
357 _itstate == opc._itstate &&
358 _nextItstate == opc._nextItstate &&
359 _illegalExec == opc._illegalExec &&
360 _debugStep == opc._debugStep &&
361 _stepped == opc._stepped;
362 }
363
364 void
365 serialize(CheckpointOut &cp) const override
366 {
367 Base::serialize(cp);
369 SERIALIZE_SCALAR(_size);
370 SERIALIZE_SCALAR(nextFlags);
371 SERIALIZE_SCALAR(_itstate);
372 SERIALIZE_SCALAR(_nextItstate);
373 SERIALIZE_SCALAR(_illegalExec);
374 SERIALIZE_SCALAR(_debugStep);
375 SERIALIZE_SCALAR(_stepped);
376 }
377
378 void
379 unserialize(CheckpointIn &cp) override
380 {
381 Base::unserialize(cp);
383 UNSERIALIZE_SCALAR(_size);
384 UNSERIALIZE_SCALAR(nextFlags);
385 UNSERIALIZE_SCALAR(_itstate);
386 UNSERIALIZE_SCALAR(_nextItstate);
387 UNSERIALIZE_SCALAR(_illegalExec);
388 UNSERIALIZE_SCALAR(_debugStep);
389 UNSERIALIZE_SCALAR(_stepped);
390 }
391};
392
393} // namespace ArmISA
394} // namespace gem5
395
396#endif
#define DPRINTF(x,...)
Definition trace.hh:210
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
#define BitUnion8(name)
Definition bitunion.hh:497
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
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition bitfield.hh:216
#define EndBitUnion(name)
This closes off the class and union started by the above macro.
Definition bitunion.hh:428
uint8_t flags
Definition helpers.cc:87
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 4 > s
Bitfield< 7, 2 > top6
Definition pcstate.hh:65
Bitfield< 60 > debugStep
Definition types.hh:63
Bitfield< 36 > thumb
Definition types.hh:79
Bitfield< 1, 0 > bottom2
Definition pcstate.hh:66
Bitfield< 55, 48 > itstate
Definition types.hh:70
Bitfield< 34 > aarch64
Definition types.hh:81
Bitfield< 12, 11 > set
Bitfield< 4 > pc
GenericISA::DelaySlotPCState< 4 > PCState
Definition pcstate.hh:40
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

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