2 * Copyright (c) 2010, 2012-2013, 2017-2018 ARM Limited
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.
14 * Copyright (c) 2007-2008 The Florida State University
15 * All rights reserved.
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.
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.
40 * Authors: Stephen Hines
43 #ifndef __ARCH_ARM_TYPES_HH__
44 #define __ARCH_ARM_TYPES_HH__
46 #include "arch/generic/types.hh"
47 #include "base/bitunion.hh"
48 #include "base/logging.hh"
49 #include "base/types.hh"
50 #include "debug/Decoder.hh"
54 typedef uint32_t MachInst;
57 /* Note that the split (cond, mask) below is not as in ARM ARM.
58 * But it is more convenient for simulation. The condition
59 * is always the concatenation of the top 3 bits and the next bit,
60 * which applies when one of the bottom 4 bits is set.
61 * Refer to predecoder.cc for the use case.
65 // Bitfields for moving to/from CPSR
67 Bitfield<1, 0> bottom2;
70 BitUnion64(ExtMachInst)
72 Bitfield<63, 62> decoderFault; // See DecoderFault
73 Bitfield<61> illegalExecution;
75 // SVE vector length, encoded in the same format as the ZCR_EL<x>.LEN
77 Bitfield<59, 56> sveLen;
80 Bitfield<55, 48> itstate;
81 Bitfield<55, 52> itstateCond;
82 Bitfield<51, 48> itstateMask;
85 Bitfield<41, 40> fpscrStride;
86 Bitfield<39, 37> fpscrLen;
88 // Bitfields to select mode.
90 Bitfield<35> bigThumb;
93 // Made up bitfields that make life easier.
94 Bitfield<33> sevenAndFour;
99 // All the different types of opcode fields.
100 Bitfield<27, 25> encoding;
102 Bitfield<24, 21> opcode;
103 Bitfield<24, 20> mediaOpcode;
104 Bitfield<24> opcode24;
105 Bitfield<24, 23> opcode24_23;
106 Bitfield<23, 20> opcode23_20;
107 Bitfield<23, 21> opcode23_21;
108 Bitfield<20> opcode20;
109 Bitfield<22> opcode22;
110 Bitfield<19, 16> opcode19_16;
111 Bitfield<19> opcode19;
112 Bitfield<18> opcode18;
113 Bitfield<15, 12> opcode15_12;
114 Bitfield<15> opcode15;
115 Bitfield<7, 4> miscOpcode;
121 Bitfield<31, 28> condCode;
126 Bitfield<11, 7> shiftSize;
127 Bitfield<6, 5> shift;
132 SubBitUnion(puswl, 24, 20)
133 Bitfield<24> prepost;
135 Bitfield<22> psruser;
136 Bitfield<21> writeback;
138 EndSubBitUnion(puswl)
140 Bitfield<24, 20> pubwl;
144 Bitfield<11, 8> rotate;
146 Bitfield<11, 0> immed11_0;
147 Bitfield<7, 0> immed7_0;
149 Bitfield<11, 8> immedHi11_8;
150 Bitfield<3, 0> immedLo3_0;
152 Bitfield<15, 0> regList;
154 Bitfield<23, 0> offset;
156 Bitfield<23, 0> immed23_0;
158 Bitfield<11, 8> cpNum;
161 Bitfield<3> fpRegImm;
163 Bitfield<2, 0> fpImm;
164 Bitfield<24, 20> punwl;
166 Bitfield<15, 8> m5Func;
168 // 16 bit thumb bitfields
169 Bitfield<15, 13> topcode15_13;
170 Bitfield<13, 11> topcode13_11;
171 Bitfield<12, 11> topcode12_11;
172 Bitfield<12, 10> topcode12_10;
173 Bitfield<11, 9> topcode11_9;
174 Bitfield<11, 8> topcode11_8;
175 Bitfield<10, 9> topcode10_9;
176 Bitfield<10, 8> topcode10_8;
177 Bitfield<9, 6> topcode9_6;
178 Bitfield<7> topcode7;
179 Bitfield<7, 6> topcode7_6;
180 Bitfield<7, 5> topcode7_5;
181 Bitfield<7, 4> topcode7_4;
182 Bitfield<3, 0> topcode3_0;
184 // 32 bit thumb bitfields
185 Bitfield<28, 27> htopcode12_11;
186 Bitfield<26, 25> htopcode10_9;
187 Bitfield<25> htopcode9;
188 Bitfield<25, 24> htopcode9_8;
189 Bitfield<25, 21> htopcode9_5;
190 Bitfield<25, 20> htopcode9_4;
191 Bitfield<24> htopcode8;
192 Bitfield<24, 23> htopcode8_7;
193 Bitfield<24, 22> htopcode8_6;
194 Bitfield<24, 21> htopcode8_5;
195 Bitfield<23> htopcode7;
196 Bitfield<23, 21> htopcode7_5;
197 Bitfield<22> htopcode6;
198 Bitfield<22, 21> htopcode6_5;
199 Bitfield<21, 20> htopcode5_4;
200 Bitfield<20> htopcode4;
202 Bitfield<19, 16> htrn;
205 Bitfield<15> ltopcode15;
206 Bitfield<11, 8> ltopcode11_8;
207 Bitfield<7, 6> ltopcode7_6;
208 Bitfield<7, 4> ltopcode7_4;
209 Bitfield<4> ltopcode4;
211 Bitfield<11, 8> ltrd;
212 Bitfield<11, 8> ltcoproc;
213 EndBitUnion(ExtMachInst)
215 class PCState : public GenericISA::UPCState<MachInst>
219 typedef GenericISA::UPCState<MachInst> Base;
223 JazelleBit = (1 << 1),
224 AArch64Bit = (1 << 2)
230 uint8_t _nextItstate;
234 PCState() : flags(0), nextFlags(0), _itstate(0), _nextItstate(0),
235 _size(0), _illegalExec(false)
242 npc(val + (thumb() ? 2 : 4));
245 PCState(Addr val) : flags(0), nextFlags(0), _itstate(0),
246 _nextItstate(0), _size(0), _illegalExec(false)
256 illegalExec(bool val)
264 return flags & ThumbBit;
279 return nextFlags & ThumbBit;
286 nextFlags |= ThumbBit;
288 nextFlags &= ~ThumbBit;
291 void size(uint8_t s) { _size = s; }
292 uint8_t size() const { return _size; }
297 return ((this->pc() + this->size()) != this->npc());
304 return flags & JazelleBit;
313 flags &= ~JazelleBit;
319 return nextFlags & JazelleBit;
323 nextJazelle(bool val)
326 nextFlags |= JazelleBit;
328 nextFlags &= ~JazelleBit;
334 return flags & AArch64Bit;
343 flags &= ~AArch64Bit;
349 return nextFlags & AArch64Bit;
353 nextAArch64(bool val)
356 nextFlags |= AArch64Bit;
358 nextFlags &= ~AArch64Bit;
369 itstate(uint8_t value)
381 nextItstate(uint8_t value)
383 _nextItstate = value;
391 npc(pc() + (thumb() ? 2 : 4));
394 _itstate = _nextItstate;
396 } else if (_itstate) {
397 ITSTATE it = _itstate;
398 uint8_t cond_mask = it.mask;
399 uint8_t thumb_cond = it.cond;
400 DPRINTF(Decoder, "Advancing ITSTATE from %#x,%#x.\n",
401 thumb_cond, cond_mask);
403 uint8_t new_bit = bits(cond_mask, 4);
404 cond_mask &= mask(4);
408 replaceBits(thumb_cond, 0, new_bit);
409 DPRINTF(Decoder, "Advancing ITSTATE to %#x,%#x.\n",
410 thumb_cond, cond_mask);
412 it.cond = thumb_cond;
428 return pc() + (thumb() ? 4 : 8);
434 // @todo: review this when AArch32/64 interprocessing is
437 npc(val); // AArch64 doesn't force PC alignment, a PC
438 // Alignment Fault can be raised instead
440 npc(val &~ mask(nextThumb() ? 1 : 2));
449 // Perform an interworking branch.
453 bool thumbEE = (thumb() && jazelle());
457 if (bits(newPC, 0)) {
458 newPC = newPC & ~mask(1);
459 } // else we have a bad interworking address; do not call
460 // panic() since the instruction could be executed
463 if (bits(newPC, 0)) {
465 newPC = newPC & ~mask(1);
466 } else if (!bits(newPC, 1)) {
469 // This state is UNPREDICTABLE in the ARM architecture
470 // The easy thing to do is just mask off the bit and
471 // stay in the current mode, so we'll do that.
478 // Perform an interworking branch in ARM mode, a regular branch
483 if (!thumb() && !jazelle())
490 operator == (const PCState &opc) const
492 return Base::operator == (opc) &&
493 flags == opc.flags && nextFlags == opc.nextFlags &&
494 _itstate == opc._itstate &&
495 _nextItstate == opc._nextItstate &&
496 _illegalExec == opc._illegalExec;
500 operator != (const PCState &opc) const
502 return !(*this == opc);
506 serialize(CheckpointOut &cp) const override
509 SERIALIZE_SCALAR(flags);
510 SERIALIZE_SCALAR(_size);
511 SERIALIZE_SCALAR(nextFlags);
512 SERIALIZE_SCALAR(_itstate);
513 SERIALIZE_SCALAR(_nextItstate);
514 SERIALIZE_SCALAR(_illegalExec);
518 unserialize(CheckpointIn &cp) override
520 Base::unserialize(cp);
521 UNSERIALIZE_SCALAR(flags);
522 UNSERIALIZE_SCALAR(_size);
523 UNSERIALIZE_SCALAR(nextFlags);
524 UNSERIALIZE_SCALAR(_itstate);
525 UNSERIALIZE_SCALAR(_nextItstate);
526 UNSERIALIZE_SCALAR(_illegalExec);
530 // Shift types for ARM instructions
538 // Extension types for ARM instructions
550 typedef int RegContextParam;
551 typedef int RegContextVal;
553 //used in FP convert & round function
577 //used in FP convert & round function
585 enum ExceptionLevel {
609 MODE_MAXMODE = MODE_SYSTEM
612 enum ExceptionClass {
615 EC_TRAPPED_WFI_WFE = 0x1,
616 EC_TRAPPED_CP15_MCR_MRC = 0x3,
617 EC_TRAPPED_CP15_MCRR_MRRC = 0x4,
618 EC_TRAPPED_CP14_MCR_MRC = 0x5,
619 EC_TRAPPED_CP14_LDC_STC = 0x6,
620 EC_TRAPPED_HCPTR = 0x7,
621 EC_TRAPPED_SIMD_FP = 0x7, // AArch64 alias
622 EC_TRAPPED_CP10_MRC_VMRS = 0x8,
623 EC_TRAPPED_BXJ = 0xA,
624 EC_TRAPPED_CP14_MCRR_MRRC = 0xC,
625 EC_ILLEGAL_INST = 0xE,
626 EC_SVC_TO_HYP = 0x11,
627 EC_SVC = 0x11, // AArch64 alias
629 EC_SMC_TO_HYP = 0x13,
630 EC_SMC = 0x13, // AArch64 alias
634 EC_TRAPPED_MSR_MRS_64 = 0x18,
635 EC_TRAPPED_SVE = 0x19,
636 EC_PREFETCH_ABORT_TO_HYP = 0x20,
637 EC_PREFETCH_ABORT_LOWER_EL = 0x20, // AArch64 alias
638 EC_PREFETCH_ABORT_FROM_HYP = 0x21,
639 EC_PREFETCH_ABORT_CURR_EL = 0x21, // AArch64 alias
640 EC_PC_ALIGNMENT = 0x22,
641 EC_DATA_ABORT_TO_HYP = 0x24,
642 EC_DATA_ABORT_LOWER_EL = 0x24, // AArch64 alias
643 EC_DATA_ABORT_FROM_HYP = 0x25,
644 EC_DATA_ABORT_CURR_EL = 0x25, // AArch64 alias
645 EC_STACK_PTR_ALIGNMENT = 0x26,
646 EC_FP_EXCEPTION = 0x28,
647 EC_FP_EXCEPTION_64 = 0x2C,
649 EC_SOFTWARE_BREAKPOINT = 0x38,
650 EC_SOFTWARE_BREAKPOINT_64 = 0x3C,
654 * Instruction decoder fault codes in ExtMachInst.
656 enum DecoderFault : std::uint8_t {
657 OK = 0x0, ///< No fault
658 UNALIGNED = 0x1, ///< Unaligned instruction fault
660 PANIC = 0x3, ///< Internal gem5 error
663 BitUnion8(OperatingMode64)
667 EndBitUnion(OperatingMode64)
670 opModeIs64(OperatingMode mode)
672 return ((OperatingMode64)(uint8_t)mode).width == 0;
676 opModeIsH(OperatingMode mode)
678 return (mode == MODE_EL1H || mode == MODE_EL2H || mode == MODE_EL3H);
682 opModeIsT(OperatingMode mode)
684 return (mode == MODE_EL0T || mode == MODE_EL1T || mode == MODE_EL2T ||
688 static ExceptionLevel inline
689 opModeToEL(OperatingMode mode)
691 bool aarch32 = ((mode >> 4) & 1) ? true : false;
708 panic("Invalid operating mode: %d", mode);
713 return (ExceptionLevel) ((mode >> 2) & 3);
718 unknownMode(OperatingMode mode)
744 unknownMode32(OperatingMode mode)
762 constexpr unsigned MaxSveVecLenInBits = 2048;
763 static_assert(MaxSveVecLenInBits >= 128 &&
764 MaxSveVecLenInBits <= 2048 &&
765 MaxSveVecLenInBits % 128 == 0,
766 "Unsupported max. SVE vector length");
767 constexpr unsigned MaxSveVecLenInBytes = MaxSveVecLenInBits >> 3;
768 constexpr unsigned MaxSveVecLenInWords = MaxSveVecLenInBits >> 5;
769 constexpr unsigned MaxSveVecLenInDWords = MaxSveVecLenInBits >> 6;
771 constexpr unsigned VecRegSizeBytes = MaxSveVecLenInBytes;
772 constexpr unsigned VecPredRegSizeBits = MaxSveVecLenInBytes;
773 constexpr unsigned VecPredRegHasPackedRepr = false;
774 } // namespace ArmISA