gem5  v22.1.0.0
isa.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2012-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) 2009 The Regents of The University of Michigan
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_ISA_HH__
42 #define __ARCH_ARM_ISA_HH__
43 
44 #include "arch/arm/isa_device.hh"
45 #include "arch/arm/mmu.hh"
46 #include "arch/arm/pcstate.hh"
47 #include "arch/arm/regs/int.hh"
48 #include "arch/arm/regs/misc.hh"
49 #include "arch/arm/regs/vec.hh"
50 #include "arch/arm/self_debug.hh"
51 #include "arch/arm/system.hh"
52 #include "arch/arm/types.hh"
53 #include "arch/arm/utility.hh"
54 #include "arch/generic/isa.hh"
55 #include "debug/Checkpoint.hh"
56 #include "enums/DecoderFlavor.hh"
57 #include "sim/sim_object.hh"
58 
59 namespace gem5
60 {
61 
62 struct ArmISAParams;
63 struct DummyArmISADeviceParams;
64 class Checkpoint;
65 class EventManager;
66 
67 namespace ArmISA
68 {
69  class ISA : public BaseISA
70  {
71  protected:
72  // Parent system
74 
75  // Micro Architecture
76  const enums::DecoderFlavor _decoderFlavor;
77 
80 
81  // PMU belonging to this ISA
83 
84  // Generic timer interface belonging to this ISA
85  std::unique_ptr<BaseISADevice> timer;
86 
87  // GICv3 CPU interface belonging to this ISA
88  std::unique_ptr<BaseISADevice> gicv3CpuInterface;
89 
90  // Cached copies of system-level properties
93  uint8_t physAddrRange;
94 
96  unsigned sveVL;
97 
100 
106 
108 
110  InitReg(uint32_t reg)
111  {
113  }
114 
116 
120 
122  const RegId *intRegMap;
123 
124  void
125  updateRegMap(CPSR cpsr)
126  {
127  if (cpsr.width == 0) {
129  } else {
130  switch (cpsr.mode) {
131  case MODE_USER:
132  case MODE_SYSTEM:
134  break;
135  case MODE_FIQ:
137  break;
138  case MODE_IRQ:
140  break;
141  case MODE_SVC:
143  break;
144  case MODE_MON:
146  break;
147  case MODE_ABORT:
149  break;
150  case MODE_HYP:
152  break;
153  case MODE_UNDEFINED:
155  break;
156  default:
157  panic("Unrecognized mode setting in CPSR.\n");
158  }
159  }
160  }
161 
162  public:
163  const RegId &mapIntRegId(RegIndex idx) const { return intRegMap[idx]; }
164 
165  public:
166  void clear() override;
167 
168  protected:
169  void clear32(const ArmISAParams &p, const SCTLR &sctlr_rst);
170  void clear64(const ArmISAParams &p);
171  void initID32(const ArmISAParams &p);
172  void initID64(const ArmISAParams &p);
173 
178 
179  public:
180  SelfDebug*
181  getSelfDebug() const
182  {
183  return selfDebug;
184  }
185 
186  static SelfDebug*
188  {
189  auto *arm_isa = static_cast<ArmISA::ISA *>(tc->getIsaPtr());
190  return arm_isa->getSelfDebug();
191  }
192 
193  const ArmRelease* getRelease() const { return release; }
194 
195  RegVal readMiscRegNoEffect(RegIndex idx) const override;
196  RegVal readMiscReg(RegIndex idx) override;
197  void setMiscRegNoEffect(RegIndex idx, RegVal val) override;
198  void setMiscReg(RegIndex, RegVal val) override;
199 
200  int
202  {
203  assert(reg >= 0);
204  int flat_idx = reg;
205 
206  if (reg == MISCREG_SPSR) {
207  CPSR cpsr = miscRegs[MISCREG_CPSR];
208  switch (cpsr.mode) {
209  case MODE_EL0T:
210  warn("User mode does not have SPSR\n");
211  flat_idx = MISCREG_SPSR;
212  break;
213  case MODE_EL1T:
214  case MODE_EL1H:
215  flat_idx = MISCREG_SPSR_EL1;
216  break;
217  case MODE_EL2T:
218  case MODE_EL2H:
219  flat_idx = MISCREG_SPSR_EL2;
220  break;
221  case MODE_EL3T:
222  case MODE_EL3H:
223  flat_idx = MISCREG_SPSR_EL3;
224  break;
225  case MODE_USER:
226  warn("User mode does not have SPSR\n");
227  flat_idx = MISCREG_SPSR;
228  break;
229  case MODE_FIQ:
230  flat_idx = MISCREG_SPSR_FIQ;
231  break;
232  case MODE_IRQ:
233  flat_idx = MISCREG_SPSR_IRQ;
234  break;
235  case MODE_SVC:
236  flat_idx = MISCREG_SPSR_SVC;
237  break;
238  case MODE_MON:
239  flat_idx = MISCREG_SPSR_MON;
240  break;
241  case MODE_ABORT:
242  flat_idx = MISCREG_SPSR_ABT;
243  break;
244  case MODE_HYP:
245  flat_idx = MISCREG_SPSR_HYP;
246  break;
247  case MODE_UNDEFINED:
248  flat_idx = MISCREG_SPSR_UND;
249  break;
250  default:
251  warn("Trying to access SPSR in an invalid mode: %d\n",
252  cpsr.mode);
253  flat_idx = MISCREG_SPSR;
254  break;
255  }
256  } else if (lookUpMiscReg[reg].info[MISCREG_MUTEX]) {
257  // Mutually exclusive CP15 register
258  switch (reg) {
259  case MISCREG_PRRR_MAIR0:
262  {
263  TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
264  // If the muxed reg has been flattened, work out the
265  // offset and apply it to the unmuxed reg
266  int idxOffset = reg - MISCREG_PRRR_MAIR0;
267  if (ttbcr.eae)
268  flat_idx = flattenMiscIndex(MISCREG_MAIR0 +
269  idxOffset);
270  else
271  flat_idx = flattenMiscIndex(MISCREG_PRRR +
272  idxOffset);
273  }
274  break;
275  case MISCREG_NMRR_MAIR1:
278  {
279  TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
280  // If the muxed reg has been flattened, work out the
281  // offset and apply it to the unmuxed reg
282  int idxOffset = reg - MISCREG_NMRR_MAIR1;
283  if (ttbcr.eae)
284  flat_idx = flattenMiscIndex(MISCREG_MAIR1 +
285  idxOffset);
286  else
287  flat_idx = flattenMiscIndex(MISCREG_NMRR +
288  idxOffset);
289  }
290  break;
292  {
293  PMSELR pmselr = miscRegs[MISCREG_PMSELR];
294  if (pmselr.sel == 31)
296  else
298  }
299  break;
300  default:
301  panic("Unrecognized misc. register.\n");
302  break;
303  }
304  } else {
305  if (lookUpMiscReg[reg].info[MISCREG_BANKED]) {
306  bool secure_reg = !highestELIs64 && inSecureState();
307  flat_idx += secure_reg ? 2 : 1;
308  } else {
309  flat_idx = snsBankedIndex64((MiscRegIndex)reg,
310  !inSecureState());
311  }
312  }
313  return flat_idx;
314  }
315 
320  int redirectRegVHE(int misc_reg);
321 
322  int
324  {
325  int reg_as_int = static_cast<int>(reg);
326  if (lookUpMiscReg[reg].info[MISCREG_BANKED64]) {
327  reg_as_int += (release->has(ArmExtension::SECURITY) && !ns) ?
328  2 : 1;
329  }
330  return reg_as_int;
331  }
332 
334  getMiscIndices(int misc_reg) const
335  {
336  // Note: indexes of AArch64 registers are left unchanged
337  int flat_idx = flattenMiscIndex(misc_reg);
338 
339  if (lookUpMiscReg[flat_idx].lower == 0) {
340  return std::make_pair(flat_idx, 0);
341  }
342 
343  // do additional S/NS flattenings if mapped to NS while in S
344  bool S = !highestELIs64 && inSecureState();
345 
346  int lower = lookUpMiscReg[flat_idx].lower;
347  int upper = lookUpMiscReg[flat_idx].upper;
348  // upper == 0, which is CPSR, is not MISCREG_BANKED_CHILD (no-op)
349  lower += S && lookUpMiscReg[lower].info[MISCREG_BANKED_CHILD];
350  upper += S && lookUpMiscReg[upper].info[MISCREG_BANKED_CHILD];
351  return std::make_pair(lower, upper);
352  }
353 
355  bool inSecureState() const;
356 
360  ExceptionLevel currEL() const;
361 
362  unsigned getCurSveVecLenInBits() const;
363 
364  unsigned getCurSveVecLenInBitsAtReset() const { return sveVL * 128; }
365 
366  template <typename Elem>
367  static void
368  zeroSveVecRegUpperPart(Elem *v, unsigned eCount)
369  {
370  static_assert(sizeof(Elem) <= sizeof(uint64_t),
371  "Elem type is too large.");
372  eCount *= (sizeof(uint64_t) / sizeof(Elem));
373  for (int i = 16 / sizeof(Elem); i < eCount; ++i) {
374  v[i] = 0;
375  }
376  }
377 
378  void serialize(CheckpointOut &cp) const override;
379  void unserialize(CheckpointIn &cp) override;
380 
381  void startup() override;
382 
383  void setupThreadContext();
384 
385  PCStateBase *
386  newPCState(Addr new_inst_addr=0) const override
387  {
388  return new PCState(new_inst_addr);
389  }
390 
391  void takeOverFrom(ThreadContext *new_tc,
392  ThreadContext *old_tc) override;
393 
394  enums::DecoderFlavor decoderFlavor() const { return _decoderFlavor; }
395 
396  PARAMS(ArmISA);
397 
398  ISA(const Params &p);
399 
400  uint64_t
401  getExecutingAsid() const override
402  {
404  }
405 
406  bool
407  inUserMode() const override
408  {
409  CPSR cpsr = miscRegs[MISCREG_CPSR];
410  return ArmISA::inUserMode(cpsr);
411  }
412 
413  void copyRegsFrom(ThreadContext *src) override;
414 
415  void handleLockedRead(const RequestPtr &req) override;
416  void handleLockedRead(ExecContext *xc, const RequestPtr &req) override;
417 
418  bool handleLockedWrite(const RequestPtr &req,
419  Addr cacheBlockMask) override;
420  bool handleLockedWrite(ExecContext *xc, const RequestPtr &req,
421  Addr cacheBlockMask) override;
422 
423  void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override;
425  Addr cacheBlockMask) override;
426  void handleLockedSnoopHit() override;
427  void handleLockedSnoopHit(ExecContext *xc) override;
428 
429  void globalClearExclusive() override;
430  void globalClearExclusive(ExecContext *xc) override;
431  };
432 
433 } // namespace ArmISA
434 } // namespace gem5
435 
436 #endif
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:62
Dummy device that prints a warning when it is accessed.
Definition: isa_device.hh:98
bool inSecureState() const
Return true if the PE is in Secure state.
Definition: isa.cc:2029
void clear32(const ArmISAParams &p, const SCTLR &sctlr_rst)
Definition: isa.cc:222
SelfDebug * getSelfDebug() const
Definition: isa.hh:181
unsigned getCurSveVecLenInBits() const
Definition: isa.cc:2061
std::pair< int, int > getMiscIndices(int misc_reg) const
Definition: isa.hh:334
ExceptionLevel currEL() const
Returns the current Exception Level (EL) of the ISA object.
Definition: isa.cc:2053
void takeOverFrom(ThreadContext *new_tc, ThreadContext *old_tc) override
Definition: isa.cc:534
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: isa.cc:2105
static SelfDebug * getSelfDebug(ThreadContext *tc)
Definition: isa.hh:187
void copyRegsFrom(ThreadContext *src) override
Definition: isa.cc:541
unsigned getCurSveVecLenInBitsAtReset() const
Definition: isa.hh:364
const enums::DecoderFlavor _decoderFlavor
Definition: isa.hh:76
void initID64(const ArmISAParams &p)
Definition: isa.cc:376
DummyISADevice dummyDevice
Dummy device for to handle non-existing ISA devices.
Definition: isa.hh:79
void setupThreadContext()
Definition: isa.cc:518
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
Definition: isa.cc:1052
uint8_t physAddrRange
Definition: isa.hh:93
void addressTranslation64(MMU::ArmTranslationType tran_type, BaseMMU::Mode mode, Request::Flags flags, RegVal val)
Definition: isa.cc:2121
int snsBankedIndex64(MiscRegIndex reg, bool ns) const
Definition: isa.hh:323
bool haveLargeAsid64
Definition: isa.hh:92
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
Definition: isa.cc:2270
void initID32(const ArmISAParams &p)
Definition: isa.cc:323
void clear() override
Definition: isa.cc:130
int flattenMiscIndex(int reg) const
Definition: isa.hh:201
RegVal miscRegs[NUM_MISCREGS]
Definition: isa.hh:121
void clear64(const ArmISAParams &p)
Definition: isa.cc:274
BaseISADevice * pmu
Definition: isa.hh:82
static void zeroSveVecRegUpperPart(Elem *v, unsigned eCount)
Definition: isa.hh:368
PCStateBase * newPCState(Addr new_inst_addr=0) const override
Definition: isa.hh:386
std::unique_ptr< BaseISADevice > timer
Definition: isa.hh:85
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
Definition: isa.cc:2359
SelfDebug * selfDebug
Definition: isa.hh:107
uint64_t getExecutingAsid() const override
Definition: isa.hh:401
void globalClearExclusive() override
Definition: isa.cc:2372
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: isa.cc:2112
void updateRegMap(CPSR cpsr)
Definition: isa.hh:125
void startup() override
startup() is the final initialization call before simulation.
Definition: isa.cc:503
int redirectRegVHE(int misc_reg)
Returns the enconcing equivalent when VHE is implemented and HCR_EL2.E2H is enabled and executing at ...
Definition: isa.cc:577
BaseISADevice & getGICv3CPUInterface()
Definition: isa.cc:2004
ArmSystem * system
Definition: isa.hh:73
BaseISADevice & getGenericTimer()
Definition: isa.cc:1983
RegVal readMiscRegNoEffect(RegIndex idx) const override
Definition: isa.cc:723
bool impdefAsNop
If true, accesses to IMPLEMENTATION DEFINED registers are treated as NOP hence not causing UNDEFINED ...
Definition: isa.hh:105
void setMiscReg(RegIndex, RegVal val) override
Definition: isa.cc:1074
const ArmRelease * getRelease() const
Definition: isa.hh:193
unsigned sveVL
SVE vector length in quadwords.
Definition: isa.hh:96
const MiscRegLUTEntryInitializer InitReg(uint32_t reg)
Definition: isa.hh:110
void handleLockedRead(const RequestPtr &req) override
Definition: isa.cc:2282
const RegId * intRegMap
Definition: isa.hh:122
enums::DecoderFlavor decoderFlavor() const
Definition: isa.hh:394
void addressTranslation(MMU::ArmTranslationType tran_type, BaseMMU::Mode mode, Request::Flags flags, RegVal val)
Definition: isa.cc:2172
void initializeMiscRegMetadata()
Definition: misc.cc:2070
const RegId & mapIntRegId(RegIndex idx) const
Definition: isa.hh:163
const ArmRelease * release
This could be either a FS or a SE release.
Definition: isa.hh:99
bool highestELIs64
Definition: isa.hh:91
RegVal readMiscReg(RegIndex idx) override
Definition: isa.cc:747
void handleLockedSnoopHit() override
Definition: isa.cc:2300
ISA(const Params &p)
Definition: isa.cc:81
std::unique_ptr< BaseISADevice > gicv3CpuInterface
Definition: isa.hh:88
bool inUserMode() const override
Definition: isa.hh:407
Metadata table accessible via the value of the register.
Definition: misc.hh:1201
bool has(ArmExtension ext) const
Definition: system.hh:76
ThreadContext * tc
Definition: isa.hh:65
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:72
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
SimObjectParams Params
Definition: sim_object.hh:170
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
STL pair class.
Definition: stl.hh:58
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
uint8_t flags
Definition: helpers.cc:66
#define warn(...)
Definition: logging.hh:246
const RegMap RegIrqMap
Definition: int.hh:535
const RegMap RegUsrMap
Definition: int.hh:451
const RegMap RegSvcMap
Definition: int.hh:479
const RegMap RegFiqMap
Definition: int.hh:549
const RegMap RegAbtMap
Definition: int.hh:507
const RegMap RegMonMap
Definition: int.hh:493
const RegMap Reg64Map
Definition: int.hh:437
const RegMap RegUndMap
Definition: int.hh:521
const RegMap RegHypMap
Definition: int.hh:465
Bitfield< 28 > v
Definition: misc_types.hh:54
@ MODE_SYSTEM
Definition: types.hh:296
@ MODE_ABORT
Definition: types.hh:293
@ MODE_UNDEFINED
Definition: types.hh:295
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 0 > ns
Definition: misc_types.hh:338
MiscRegIndex
Definition: misc.hh:64
@ MISCREG_PRRR_MAIR0
Definition: misc.hh:88
@ MISCREG_NMRR_MAIR1_S
Definition: misc.hh:93
@ MISCREG_SPSR_HYP
Definition: misc.hh:72
@ MISCREG_SPSR_EL2
Definition: misc.hh:630
@ NUM_MISCREGS
Definition: misc.hh:1100
@ MISCREG_TTBCR
Definition: misc.hh:265
@ MISCREG_SPSR_SVC
Definition: misc.hh:69
@ MISCREG_PMXEVTYPER
Definition: misc.hh:365
@ MISCREG_SPSR_UND
Definition: misc.hh:73
@ MISCREG_SPSR_IRQ
Definition: misc.hh:68
@ MISCREG_SPSR_ABT
Definition: misc.hh:71
@ MISCREG_PRRR
Definition: misc.hh:374
@ MISCREG_NMRR_MAIR1
Definition: misc.hh:91
@ MISCREG_CPSR
Definition: misc.hh:65
@ MISCREG_NMRR
Definition: misc.hh:380
@ MISCREG_MAIR1
Definition: misc.hh:383
@ MISCREG_PMCCFILTR
Definition: misc.hh:366
@ MISCREG_CONTEXTIDR
Definition: misc.hh:404
@ MISCREG_SPSR_EL3
Definition: misc.hh:637
@ MISCREG_SPSR_EL1
Definition: misc.hh:617
@ MISCREG_PMSELR
Definition: misc.hh:361
@ MISCREG_SPSR_MON
Definition: misc.hh:70
@ MISCREG_PRRR_MAIR0_S
Definition: misc.hh:90
@ MISCREG_NMRR_MAIR1_NS
Definition: misc.hh:92
@ MISCREG_PRRR_MAIR0_NS
Definition: misc.hh:89
@ MISCREG_SPSR
Definition: misc.hh:66
@ MISCREG_PMXEVTYPER_PMCCFILTR
Definition: misc.hh:94
@ MISCREG_SPSR_FIQ
Definition: misc.hh:67
@ MISCREG_MAIR0
Definition: misc.hh:377
static bool inUserMode(CPSR cpsr)
Definition: utility.hh:97
@ MISCREG_MUTEX
Definition: misc.hh:1111
@ MISCREG_BANKED_CHILD
Definition: misc.hh:1119
@ MISCREG_BANKED
Definition: misc.hh:1113
@ MISCREG_BANKED64
Definition: misc.hh:1116
std::vector< struct MiscRegLUTEntry > lookUpMiscReg(NUM_MISCREGS)
Definition: misc.hh:1576
GenericISA::DelaySlotPCState< 4 > PCState
Definition: pcstate.hh:40
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
uint16_t RegIndex
Definition: types.hh:176
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
uint64_t RegVal
Definition: types.hh:173

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1