2 * Copyright (c) 2010-2014 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 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include "arch/arm/isa.hh"
42 #include "arch/arm/pmu.hh"
43 #include "arch/arm/system.hh"
44 #include "cpu/checker/cpu.hh"
45 #include "cpu/base.hh"
46 #include "debug/Arm.hh"
47 #include "debug/MiscRegs.hh"
48 #include "params/ArmISA.hh"
49 #include "sim/faults.hh"
50 #include "sim/stat_control.hh"
51 #include "sim/system.hh"
58 * Some registers aliase with others, and therefore need to be translated.
60 * The first value is the misc register that is to be looked up
61 * the second value is the lower part of the translation
62 * the third the upper part
64 const struct ISA::MiscRegInitializerEntry
65 ISA::MiscRegSwitch
[miscRegTranslateMax
] = {
66 {MISCREG_CSSELR_EL1
, {MISCREG_CSSELR
, 0}},
67 {MISCREG_SCTLR_EL1
, {MISCREG_SCTLR
, 0}},
68 {MISCREG_SCTLR_EL2
, {MISCREG_HSCTLR
, 0}},
69 {MISCREG_ACTLR_EL1
, {MISCREG_ACTLR
, 0}},
70 {MISCREG_ACTLR_EL2
, {MISCREG_HACTLR
, 0}},
71 {MISCREG_CPACR_EL1
, {MISCREG_CPACR
, 0}},
72 {MISCREG_CPTR_EL2
, {MISCREG_HCPTR
, 0}},
73 {MISCREG_HCR_EL2
, {MISCREG_HCR
, 0}},
74 {MISCREG_MDCR_EL2
, {MISCREG_HDCR
, 0}},
75 {MISCREG_HSTR_EL2
, {MISCREG_HSTR
, 0}},
76 {MISCREG_HACR_EL2
, {MISCREG_HACR
, 0}},
77 {MISCREG_TTBR0_EL1
, {MISCREG_TTBR0
, 0}},
78 {MISCREG_TTBR1_EL1
, {MISCREG_TTBR1
, 0}},
79 {MISCREG_TTBR0_EL2
, {MISCREG_HTTBR
, 0}},
80 {MISCREG_VTTBR_EL2
, {MISCREG_VTTBR
, 0}},
81 {MISCREG_TCR_EL1
, {MISCREG_TTBCR
, 0}},
82 {MISCREG_TCR_EL2
, {MISCREG_HTCR
, 0}},
83 {MISCREG_VTCR_EL2
, {MISCREG_VTCR
, 0}},
84 {MISCREG_AFSR0_EL1
, {MISCREG_ADFSR
, 0}},
85 {MISCREG_AFSR1_EL1
, {MISCREG_AIFSR
, 0}},
86 {MISCREG_AFSR0_EL2
, {MISCREG_HADFSR
, 0}},
87 {MISCREG_AFSR1_EL2
, {MISCREG_HAIFSR
, 0}},
88 {MISCREG_ESR_EL2
, {MISCREG_HSR
, 0}},
89 {MISCREG_FAR_EL1
, {MISCREG_DFAR
, MISCREG_IFAR
}},
90 {MISCREG_FAR_EL2
, {MISCREG_HDFAR
, MISCREG_HIFAR
}},
91 {MISCREG_HPFAR_EL2
, {MISCREG_HPFAR
, 0}},
92 {MISCREG_PAR_EL1
, {MISCREG_PAR
, 0}},
93 {MISCREG_MAIR_EL1
, {MISCREG_PRRR
, MISCREG_NMRR
}},
94 {MISCREG_MAIR_EL2
, {MISCREG_HMAIR0
, MISCREG_HMAIR1
}},
95 {MISCREG_AMAIR_EL1
, {MISCREG_AMAIR0
, MISCREG_AMAIR1
}},
96 {MISCREG_VBAR_EL1
, {MISCREG_VBAR
, 0}},
97 {MISCREG_VBAR_EL2
, {MISCREG_HVBAR
, 0}},
98 {MISCREG_CONTEXTIDR_EL1
, {MISCREG_CONTEXTIDR
, 0}},
99 {MISCREG_TPIDR_EL0
, {MISCREG_TPIDRURW
, 0}},
100 {MISCREG_TPIDRRO_EL0
, {MISCREG_TPIDRURO
, 0}},
101 {MISCREG_TPIDR_EL1
, {MISCREG_TPIDRPRW
, 0}},
102 {MISCREG_TPIDR_EL2
, {MISCREG_HTPIDR
, 0}},
103 {MISCREG_TEECR32_EL1
, {MISCREG_TEECR
, 0}},
104 {MISCREG_CNTFRQ_EL0
, {MISCREG_CNTFRQ
, 0}},
105 {MISCREG_CNTPCT_EL0
, {MISCREG_CNTPCT
, 0}},
106 {MISCREG_CNTVCT_EL0
, {MISCREG_CNTVCT
, 0}},
107 {MISCREG_CNTVOFF_EL2
, {MISCREG_CNTVOFF
, 0}},
108 {MISCREG_CNTKCTL_EL1
, {MISCREG_CNTKCTL
, 0}},
109 {MISCREG_CNTHCTL_EL2
, {MISCREG_CNTHCTL
, 0}},
110 {MISCREG_CNTP_TVAL_EL0
, {MISCREG_CNTP_TVAL
, 0}},
111 {MISCREG_CNTP_CTL_EL0
, {MISCREG_CNTP_CTL
, 0}},
112 {MISCREG_CNTP_CVAL_EL0
, {MISCREG_CNTP_CVAL
, 0}},
113 {MISCREG_CNTV_TVAL_EL0
, {MISCREG_CNTV_TVAL
, 0}},
114 {MISCREG_CNTV_CTL_EL0
, {MISCREG_CNTV_CTL
, 0}},
115 {MISCREG_CNTV_CVAL_EL0
, {MISCREG_CNTV_CVAL
, 0}},
116 {MISCREG_CNTHP_TVAL_EL2
, {MISCREG_CNTHP_TVAL
, 0}},
117 {MISCREG_CNTHP_CTL_EL2
, {MISCREG_CNTHP_CTL
, 0}},
118 {MISCREG_CNTHP_CVAL_EL2
, {MISCREG_CNTHP_CVAL
, 0}},
119 {MISCREG_DACR32_EL2
, {MISCREG_DACR
, 0}},
120 {MISCREG_IFSR32_EL2
, {MISCREG_IFSR
, 0}},
121 {MISCREG_TEEHBR32_EL1
, {MISCREG_TEEHBR
, 0}},
122 {MISCREG_SDER32_EL3
, {MISCREG_SDER
, 0}}
130 lookUpMiscReg(NUM_MISCREGS
, {0,0})
134 miscRegs
[MISCREG_SCTLR_RST
] = sctlr
;
136 // Hook up a dummy device if we haven't been configured with a
137 // real PMU. By using a dummy device, we don't need to check that
138 // the PMU exist every time we try to access a PMU register.
142 system
= dynamic_cast<ArmSystem
*>(p
->system
);
143 DPRINTFN("ISA system set to: %p %p\n", system
, p
->system
);
145 // Cache system-level properties
146 if (FullSystem
&& system
) {
147 haveSecurity
= system
->haveSecurity();
148 haveLPAE
= system
->haveLPAE();
149 haveVirtualization
= system
->haveVirtualization();
150 haveLargeAsid64
= system
->haveLargeAsid64();
151 physAddrRange64
= system
->physAddrRange64();
153 haveSecurity
= haveLPAE
= haveVirtualization
= false;
154 haveLargeAsid64
= false;
155 physAddrRange64
= 32; // dummy value
158 /** Fill in the miscReg translation table */
159 for (uint32_t i
= 0; i
< miscRegTranslateMax
; i
++) {
160 struct MiscRegLUTEntry new_entry
;
162 uint32_t select
= MiscRegSwitch
[i
].index
;
163 new_entry
= MiscRegSwitch
[i
].entry
;
165 lookUpMiscReg
[select
] = new_entry
;
168 preUnflattenMiscReg();
176 return dynamic_cast<const Params
*>(_params
);
182 const Params
*p(params());
184 SCTLR sctlr_rst
= miscRegs
[MISCREG_SCTLR_RST
];
185 memset(miscRegs
, 0, sizeof(miscRegs
));
187 // Initialize configurable default values
188 miscRegs
[MISCREG_MIDR
] = p
->midr
;
189 miscRegs
[MISCREG_MIDR_EL1
] = p
->midr
;
190 miscRegs
[MISCREG_VPIDR
] = p
->midr
;
192 if (FullSystem
&& system
->highestELIs64()) {
193 // Initialize AArch64 state
198 // Initialize AArch32 state...
201 cpsr
.mode
= MODE_USER
;
202 miscRegs
[MISCREG_CPSR
] = cpsr
;
206 sctlr
.te
= (bool) sctlr_rst
.te
;
207 sctlr
.nmfi
= (bool) sctlr_rst
.nmfi
;
208 sctlr
.v
= (bool) sctlr_rst
.v
;
213 sctlr
.rao4
= 0xf; // SCTLR[6:3]
216 miscRegs
[MISCREG_SCTLR_NS
] = sctlr
;
217 miscRegs
[MISCREG_SCTLR_RST
] = sctlr_rst
;
218 miscRegs
[MISCREG_HCPTR
] = 0;
220 // Start with an event in the mailbox
221 miscRegs
[MISCREG_SEV_MAILBOX
] = 1;
223 // Separate Instruction and Data TLBs
224 miscRegs
[MISCREG_TLBTR
] = 1;
227 mvfr0
.advSimdRegisters
= 2;
228 mvfr0
.singlePrecision
= 2;
229 mvfr0
.doublePrecision
= 2;
230 mvfr0
.vfpExceptionTrapping
= 0;
232 mvfr0
.squareRoot
= 1;
233 mvfr0
.shortVectors
= 1;
234 mvfr0
.roundingModes
= 1;
235 miscRegs
[MISCREG_MVFR0
] = mvfr0
;
238 mvfr1
.flushToZero
= 1;
239 mvfr1
.defaultNaN
= 1;
240 mvfr1
.advSimdLoadStore
= 1;
241 mvfr1
.advSimdInteger
= 1;
242 mvfr1
.advSimdSinglePrecision
= 1;
243 mvfr1
.advSimdHalfPrecision
= 1;
244 mvfr1
.vfpHalfPrecision
= 1;
245 miscRegs
[MISCREG_MVFR1
] = mvfr1
;
247 // Reset values of PRRR and NMRR are implementation dependent
249 // @todo: PRRR and NMRR in secure state?
250 miscRegs
[MISCREG_PRRR_NS
] =
263 miscRegs
[MISCREG_NMRR_NS
] =
280 miscRegs
[MISCREG_CPACR
] = 0;
283 miscRegs
[MISCREG_ID_PFR0
] = p
->id_pfr0
;
284 miscRegs
[MISCREG_ID_PFR1
] = p
->id_pfr1
;
286 miscRegs
[MISCREG_ID_MMFR0
] = p
->id_mmfr0
;
287 miscRegs
[MISCREG_ID_MMFR1
] = p
->id_mmfr1
;
288 miscRegs
[MISCREG_ID_MMFR2
] = p
->id_mmfr2
;
289 miscRegs
[MISCREG_ID_MMFR3
] = p
->id_mmfr3
;
291 miscRegs
[MISCREG_ID_ISAR0
] = p
->id_isar0
;
292 miscRegs
[MISCREG_ID_ISAR1
] = p
->id_isar1
;
293 miscRegs
[MISCREG_ID_ISAR2
] = p
->id_isar2
;
294 miscRegs
[MISCREG_ID_ISAR3
] = p
->id_isar3
;
295 miscRegs
[MISCREG_ID_ISAR4
] = p
->id_isar4
;
296 miscRegs
[MISCREG_ID_ISAR5
] = p
->id_isar5
;
298 miscRegs
[MISCREG_FPSID
] = p
->fpsid
;
301 TTBCR ttbcr
= miscRegs
[MISCREG_TTBCR_NS
];
303 miscRegs
[MISCREG_TTBCR_NS
] = ttbcr
;
304 // Enforce consistency with system-level settings
305 miscRegs
[MISCREG_ID_MMFR0
] = (miscRegs
[MISCREG_ID_MMFR0
] & ~0xf) | 0x5;
309 miscRegs
[MISCREG_SCTLR_S
] = sctlr
;
310 miscRegs
[MISCREG_SCR
] = 0;
311 miscRegs
[MISCREG_VBAR_S
] = 0;
313 // we're always non-secure
314 miscRegs
[MISCREG_SCR
] = 1;
317 //XXX We need to initialize the rest of the state.
321 ISA::clear64(const ArmISAParams
*p
)
324 Addr rvbar
= system
->resetAddr64();
325 switch (system
->highestEL()) {
326 // Set initial EL to highest implemented EL using associated stack
327 // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
330 cpsr
.mode
= MODE_EL3H
;
331 miscRegs
[MISCREG_RVBAR_EL3
] = rvbar
;
334 cpsr
.mode
= MODE_EL2H
;
335 miscRegs
[MISCREG_RVBAR_EL2
] = rvbar
;
338 cpsr
.mode
= MODE_EL1H
;
339 miscRegs
[MISCREG_RVBAR_EL1
] = rvbar
;
342 panic("Invalid highest implemented exception level");
346 // Initialize rest of CPSR
347 cpsr
.daif
= 0xf; // Mask all interrupts
350 miscRegs
[MISCREG_CPSR
] = cpsr
;
353 // Initialize other control registers
354 miscRegs
[MISCREG_MPIDR_EL1
] = 0x80000000;
356 miscRegs
[MISCREG_SCTLR_EL3
] = 0x30c50870;
357 miscRegs
[MISCREG_SCR_EL3
] = 0x00000030; // RES1 fields
358 // @todo: uncomment this to enable Virtualization
359 // } else if (haveVirtualization) {
360 // miscRegs[MISCREG_SCTLR_EL2] = 0x30c50870;
362 miscRegs
[MISCREG_SCTLR_EL1
] = 0x30c50870;
364 miscRegs
[MISCREG_SCR_EL3
] = 1;
367 // Initialize configurable id registers
368 miscRegs
[MISCREG_ID_AA64AFR0_EL1
] = p
->id_aa64afr0_el1
;
369 miscRegs
[MISCREG_ID_AA64AFR1_EL1
] = p
->id_aa64afr1_el1
;
370 miscRegs
[MISCREG_ID_AA64DFR0_EL1
] =
371 (p
->id_aa64dfr0_el1
& 0xfffffffffffff0ffULL
) |
372 (p
->pmu
? 0x0000000000000100ULL
: 0); // Enable PMUv3
374 miscRegs
[MISCREG_ID_AA64DFR1_EL1
] = p
->id_aa64dfr1_el1
;
375 miscRegs
[MISCREG_ID_AA64ISAR0_EL1
] = p
->id_aa64isar0_el1
;
376 miscRegs
[MISCREG_ID_AA64ISAR1_EL1
] = p
->id_aa64isar1_el1
;
377 miscRegs
[MISCREG_ID_AA64MMFR0_EL1
] = p
->id_aa64mmfr0_el1
;
378 miscRegs
[MISCREG_ID_AA64MMFR1_EL1
] = p
->id_aa64mmfr1_el1
;
379 miscRegs
[MISCREG_ID_AA64PFR0_EL1
] = p
->id_aa64pfr0_el1
;
380 miscRegs
[MISCREG_ID_AA64PFR1_EL1
] = p
->id_aa64pfr1_el1
;
382 miscRegs
[MISCREG_ID_DFR0_EL1
] =
383 (p
->pmu
? 0x03000000ULL
: 0); // Enable PMUv3
385 miscRegs
[MISCREG_ID_DFR0
] = miscRegs
[MISCREG_ID_DFR0_EL1
];
387 // Enforce consistency with system-level settings...
390 // (no AArch32/64 interprocessing support for now)
391 miscRegs
[MISCREG_ID_AA64PFR0_EL1
] = insertBits(
392 miscRegs
[MISCREG_ID_AA64PFR0_EL1
], 15, 12,
393 haveSecurity
? 0x1 : 0x0);
395 // (no AArch32/64 interprocessing support for now)
396 miscRegs
[MISCREG_ID_AA64PFR0_EL1
] = insertBits(
397 miscRegs
[MISCREG_ID_AA64PFR0_EL1
], 11, 8,
398 haveVirtualization
? 0x1 : 0x0);
399 // Large ASID support
400 miscRegs
[MISCREG_ID_AA64MMFR0_EL1
] = insertBits(
401 miscRegs
[MISCREG_ID_AA64MMFR0_EL1
], 7, 4,
402 haveLargeAsid64
? 0x2 : 0x0);
403 // Physical address size
404 miscRegs
[MISCREG_ID_AA64MMFR0_EL1
] = insertBits(
405 miscRegs
[MISCREG_ID_AA64MMFR0_EL1
], 3, 0,
406 encodePhysAddrRange64(physAddrRange64
));
410 ISA::readMiscRegNoEffect(int misc_reg
) const
412 assert(misc_reg
< NumMiscRegs
);
414 int flat_idx
= flattenMiscIndex(misc_reg
); // Note: indexes of AArch64
415 // registers are left unchanged
418 if (lookUpMiscReg
[flat_idx
].lower
== 0 || flat_idx
== MISCREG_SPSR
419 || flat_idx
== MISCREG_SCTLR_EL1
) {
420 if (flat_idx
== MISCREG_SPSR
)
421 flat_idx
= flattenMiscIndex(MISCREG_SPSR
);
422 if (flat_idx
== MISCREG_SCTLR_EL1
)
423 flat_idx
= flattenMiscIndex(MISCREG_SCTLR
);
424 val
= miscRegs
[flat_idx
];
426 if (lookUpMiscReg
[flat_idx
].upper
> 0)
427 val
= ((miscRegs
[lookUpMiscReg
[flat_idx
].lower
] & mask(32))
428 | (miscRegs
[lookUpMiscReg
[flat_idx
].upper
] << 32));
430 val
= miscRegs
[lookUpMiscReg
[flat_idx
].lower
];
437 ISA::readMiscReg(int misc_reg
, ThreadContext
*tc
)
443 if (misc_reg
== MISCREG_CPSR
) {
444 cpsr
= miscRegs
[misc_reg
];
446 cpsr
.j
= pc
.jazelle() ? 1 : 0;
447 cpsr
.t
= pc
.thumb() ? 1 : 0;
452 if (!miscRegInfo
[misc_reg
][MISCREG_IMPLEMENTED
]) {
453 if (miscRegInfo
[misc_reg
][MISCREG_WARN_NOT_FAIL
])
454 warn("Unimplemented system register %s read.\n",
455 miscRegName
[misc_reg
]);
457 panic("Unimplemented system register %s read.\n",
458 miscRegName
[misc_reg
]);
462 switch (unflattenMiscReg(misc_reg
)) {
465 if (!haveVirtualization
)
468 return readMiscRegNoEffect(MISCREG_HCR
);
472 const uint32_t ones
= (uint32_t)(-1);
474 // Only cp10, cp11, and ase are implemented, nothing else should
475 // be readable? (straight copy from the write code)
476 cpacrMask
.cp10
= ones
;
477 cpacrMask
.cp11
= ones
;
478 cpacrMask
.asedis
= ones
;
480 // Security Extensions may limit the readability of CPACR
482 scr
= readMiscRegNoEffect(MISCREG_SCR
);
483 cpsr
= readMiscRegNoEffect(MISCREG_CPSR
);
484 if (scr
.ns
&& (cpsr
.mode
!= MODE_MON
)) {
485 NSACR nsacr
= readMiscRegNoEffect(MISCREG_NSACR
);
486 // NB: Skipping the full loop, here
487 if (!nsacr
.cp10
) cpacrMask
.cp10
= 0;
488 if (!nsacr
.cp11
) cpacrMask
.cp11
= 0;
491 MiscReg val
= readMiscRegNoEffect(MISCREG_CPACR
);
493 DPRINTF(MiscRegs
, "Reading misc reg %s: %#x\n",
494 miscRegName
[misc_reg
], val
);
498 cpsr
= readMiscRegNoEffect(MISCREG_CPSR
);
499 scr
= readMiscRegNoEffect(MISCREG_SCR
);
500 if ((cpsr
.mode
== MODE_HYP
) || inSecureState(scr
, cpsr
)) {
501 return getMPIDR(system
, tc
);
503 return readMiscReg(MISCREG_VMPIDR
, tc
);
506 case MISCREG_MPIDR_EL1
:
507 // @todo in the absence of v8 virtualization support just return MPIDR_EL1
508 return getMPIDR(system
, tc
) & 0xffffffff;
510 // top bit defined as RES1
511 return readMiscRegNoEffect(misc_reg
) | 0x80000000;
512 case MISCREG_ID_AFR0
: // not implemented, so alias MIDR
513 case MISCREG_REVIDR
: // not implemented, so alias MIDR
515 cpsr
= readMiscRegNoEffect(MISCREG_CPSR
);
516 scr
= readMiscRegNoEffect(MISCREG_SCR
);
517 if ((cpsr
.mode
== MODE_HYP
) || inSecureState(scr
, cpsr
)) {
518 return readMiscRegNoEffect(misc_reg
);
520 return readMiscRegNoEffect(MISCREG_VPIDR
);
523 case MISCREG_JOSCR
: // Jazelle trivial implementation, RAZ/WI
524 case MISCREG_JMCR
: // Jazelle trivial implementation, RAZ/WI
525 case MISCREG_JIDR
: // Jazelle trivial implementation, RAZ/WI
526 case MISCREG_AIDR
: // AUX ID set to 0
527 case MISCREG_TCMTR
: // No TCM's
531 warn_once("The clidr register always reports 0 caches.\n");
532 warn_once("clidr LoUIS field of 0b001 to match current "
533 "ARM implementations.\n");
536 warn_once("The ccsidr register isn't implemented and "
537 "always reads as 0.\n");
541 //all caches have the same line size in gem5
542 //4 byte words in ARM
543 unsigned lineSizeWords
=
544 tc
->getSystemPtr()->cacheLineSize() / 4;
545 unsigned log2LineSizeWords
= 0;
547 while (lineSizeWords
>>= 1) {
552 //log2 of minimun i-cache line size (words)
553 ctr
.iCacheLineSize
= log2LineSizeWords
;
554 //b11 - gem5 uses pipt
555 ctr
.l1IndexPolicy
= 0x3;
556 //log2 of minimum d-cache line size (words)
557 ctr
.dCacheLineSize
= log2LineSizeWords
;
558 //log2 of max reservation size (words)
559 ctr
.erg
= log2LineSizeWords
;
560 //log2 of max writeback size (words)
561 ctr
.cwg
= log2LineSizeWords
;
562 //b100 - gem5 format is ARMv7
568 warn("Not doing anything for miscreg ACTLR\n");
571 case MISCREG_PMXEVTYPER_PMCCFILTR
:
572 case MISCREG_PMINTENSET_EL1
... MISCREG_PMOVSSET_EL0
:
573 case MISCREG_PMEVCNTR0_EL0
... MISCREG_PMEVTYPER5_EL0
:
574 case MISCREG_PMCR
... MISCREG_PMOVSSET
:
575 return pmu
->readMiscReg(misc_reg
);
578 panic("shouldn't be reading this register seperately\n");
579 case MISCREG_FPSCR_QC
:
580 return readMiscRegNoEffect(MISCREG_FPSCR
) & ~FpscrQcMask
;
581 case MISCREG_FPSCR_EXC
:
582 return readMiscRegNoEffect(MISCREG_FPSCR
) & ~FpscrExcMask
;
585 const uint32_t ones
= (uint32_t)(-1);
587 fpscrMask
.ioc
= ones
;
588 fpscrMask
.dzc
= ones
;
589 fpscrMask
.ofc
= ones
;
590 fpscrMask
.ufc
= ones
;
591 fpscrMask
.ixc
= ones
;
592 fpscrMask
.idc
= ones
;
598 return readMiscRegNoEffect(MISCREG_FPSCR
) & (uint32_t)fpscrMask
;
602 const uint32_t ones
= (uint32_t)(-1);
604 fpscrMask
.ioe
= ones
;
605 fpscrMask
.dze
= ones
;
606 fpscrMask
.ofe
= ones
;
607 fpscrMask
.ufe
= ones
;
608 fpscrMask
.ixe
= ones
;
609 fpscrMask
.ide
= ones
;
610 fpscrMask
.len
= ones
;
611 fpscrMask
.stride
= ones
;
612 fpscrMask
.rMode
= ones
;
615 fpscrMask
.ahp
= ones
;
616 return readMiscRegNoEffect(MISCREG_FPSCR
) & (uint32_t)fpscrMask
;
621 cpsr
.nz
= tc
->readCCReg(CCREG_NZ
);
622 cpsr
.c
= tc
->readCCReg(CCREG_C
);
623 cpsr
.v
= tc
->readCCReg(CCREG_V
);
629 cpsr
.daif
= (uint8_t) ((CPSR
) miscRegs
[MISCREG_CPSR
]).daif
;
634 return tc
->readIntReg(INTREG_SP0
);
638 return tc
->readIntReg(INTREG_SP1
);
642 return tc
->readIntReg(INTREG_SP2
);
646 return miscRegs
[MISCREG_CPSR
] & 0x1;
648 case MISCREG_CURRENTEL
:
650 return miscRegs
[MISCREG_CPSR
] & 0xc;
654 // mostly unimplemented, just set NumCPUs field from sim and return
656 // b00:1CPU to b11:4CPUs
657 l2ctlr
.numCPUs
= tc
->getSystemPtr()->numContexts() - 1;
660 case MISCREG_DBGDIDR
:
661 /* For now just implement the version number.
662 * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
665 case MISCREG_DBGDSCRint
:
668 return tc
->getCpuPtr()->getInterruptController()->getISR(
669 readMiscRegNoEffect(MISCREG_HCR
),
670 readMiscRegNoEffect(MISCREG_CPSR
),
671 readMiscRegNoEffect(MISCREG_SCR
));
672 case MISCREG_ISR_EL1
:
673 return tc
->getCpuPtr()->getInterruptController()->getISR(
674 readMiscRegNoEffect(MISCREG_HCR_EL2
),
675 readMiscRegNoEffect(MISCREG_CPSR
),
676 readMiscRegNoEffect(MISCREG_SCR_EL3
));
677 case MISCREG_DCZID_EL0
:
678 return 0x04; // DC ZVA clear 64-byte chunks
681 MiscReg val
= readMiscRegNoEffect(misc_reg
);
682 // The trap bit associated with CP14 is defined as RAZ
684 // If a CP bit in NSACR is 0 then the corresponding bit in
686 bool secure_lookup
= haveSecurity
&&
687 inSecureState(readMiscRegNoEffect(MISCREG_SCR
),
688 readMiscRegNoEffect(MISCREG_CPSR
));
689 if (!secure_lookup
) {
690 MiscReg mask
= readMiscRegNoEffect(MISCREG_NSACR
);
691 val
|= (mask
^ 0x7FFF) & 0xBFFF;
693 // Set the bits for unimplemented coprocessors to RAO/WI
697 case MISCREG_HDFAR
: // alias for secure DFAR
698 return readMiscRegNoEffect(MISCREG_DFAR_S
);
699 case MISCREG_HIFAR
: // alias for secure IFAR
700 return readMiscRegNoEffect(MISCREG_IFAR_S
);
701 case MISCREG_HVBAR
: // bottom bits reserved
702 return readMiscRegNoEffect(MISCREG_HVBAR
) & 0xFFFFFFE0;
703 case MISCREG_SCTLR
: // Some bits hardwired
704 // The FI field (bit 21) is common between S/NS versions of the register
705 return (readMiscRegNoEffect(MISCREG_SCTLR_S
) & (1 << 21)) |
706 (readMiscRegNoEffect(misc_reg
) & 0x72DD39FF) | 0x00C00818; // V8 SCTLR
707 case MISCREG_SCTLR_EL1
:
708 // The FI field (bit 21) is common between S/NS versions of the register
709 return (readMiscRegNoEffect(MISCREG_SCTLR_S
) & (1 << 21)) |
710 (readMiscRegNoEffect(misc_reg
) & 0x37DDDBFF) | 0x30D00800; // V8 SCTLR_EL1
711 case MISCREG_SCTLR_EL3
:
712 // The FI field (bit 21) is common between S/NS versions of the register
713 return (readMiscRegNoEffect(MISCREG_SCTLR_S
) & (1 << 21)) |
714 (readMiscRegNoEffect(misc_reg
) & 0x32CD183F) | 0x30C50830; // V8 SCTLR_EL3
715 case MISCREG_HSCTLR
: // FI comes from SCTLR
717 uint32_t mask
= 1 << 27;
718 return (readMiscRegNoEffect(MISCREG_HSCTLR
) & ~mask
) |
719 (readMiscRegNoEffect(MISCREG_SCTLR
) & mask
);
723 CPSR cpsr
= readMiscRegNoEffect(MISCREG_CPSR
);
725 return readMiscRegNoEffect(MISCREG_SCR
);
727 return readMiscRegNoEffect(MISCREG_SCR_EL3
);
730 // Generic Timer registers
732 case MISCREG_CNTFRQ_EL0
:
733 inform_once("Read CNTFREQ_EL0 frequency\n");
734 return getSystemCounter(tc
)->freq();
736 case MISCREG_CNTPCT_EL0
:
737 return getSystemCounter(tc
)->value();
739 return getSystemCounter(tc
)->value();
740 case MISCREG_CNTVCT_EL0
:
741 return getSystemCounter(tc
)->value();
742 case MISCREG_CNTP_CVAL
:
743 case MISCREG_CNTP_CVAL_EL0
:
744 return getArchTimer(tc
, tc
->cpuId())->compareValue();
745 case MISCREG_CNTP_TVAL
:
746 case MISCREG_CNTP_TVAL_EL0
:
747 return getArchTimer(tc
, tc
->cpuId())->timerValue();
748 case MISCREG_CNTP_CTL
:
749 case MISCREG_CNTP_CTL_EL0
:
750 return getArchTimer(tc
, tc
->cpuId())->control();
751 // PL1 phys. timer, secure
753 // case MISCREG_CNTPS_CVAL_EL1:
754 // case MISCREG_CNTPS_TVAL_EL1:
755 // case MISCREG_CNTPS_CTL_EL1:
756 // PL2 phys. timer, non-secure
758 // case MISCREG_CNTHCTL:
759 // case MISCREG_CNTHP_CVAL:
760 // case MISCREG_CNTHP_TVAL:
761 // case MISCREG_CNTHP_CTL:
763 // case MISCREG_CNTHCTL_EL2:
764 // case MISCREG_CNTHP_CVAL_EL2:
765 // case MISCREG_CNTHP_TVAL_EL2:
766 // case MISCREG_CNTHP_CTL_EL2:
769 // case MISCREG_CNTV_CVAL:
770 // case MISCREG_CNTV_TVAL:
771 // case MISCREG_CNTV_CTL:
773 // case MISCREG_CNTV_CVAL_EL2:
774 // case MISCREG_CNTV_TVAL_EL2:
775 // case MISCREG_CNTV_CTL_EL2:
780 return readMiscRegNoEffect(misc_reg
);
784 ISA::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
)
786 assert(misc_reg
< NumMiscRegs
);
788 int flat_idx
= flattenMiscIndex(misc_reg
); // Note: indexes of AArch64
789 // registers are left unchanged
791 int flat_idx2
= lookUpMiscReg
[flat_idx
].upper
;
794 miscRegs
[lookUpMiscReg
[flat_idx
].lower
] = bits(val
, 31, 0);
795 miscRegs
[flat_idx2
] = bits(val
, 63, 32);
796 DPRINTF(MiscRegs
, "Writing to misc reg %d (%d:%d) : %#x\n",
797 misc_reg
, flat_idx
, flat_idx2
, val
);
799 if (flat_idx
== MISCREG_SPSR
)
800 flat_idx
= flattenMiscIndex(MISCREG_SPSR
);
801 else if (flat_idx
== MISCREG_SCTLR_EL1
)
802 flat_idx
= flattenMiscIndex(MISCREG_SCTLR
);
804 flat_idx
= (lookUpMiscReg
[flat_idx
].lower
> 0) ?
805 lookUpMiscReg
[flat_idx
].lower
: flat_idx
;
806 miscRegs
[flat_idx
] = val
;
807 DPRINTF(MiscRegs
, "Writing to misc reg %d (%d) : %#x\n",
808 misc_reg
, flat_idx
, val
);
813 ISA::setMiscReg(int misc_reg
, const MiscReg
&val
, ThreadContext
*tc
)
816 MiscReg newVal
= val
;
826 if (misc_reg
== MISCREG_CPSR
) {
830 CPSR old_cpsr
= miscRegs
[MISCREG_CPSR
];
831 int old_mode
= old_cpsr
.mode
;
833 if (old_mode
!= cpsr
.mode
) {
834 tc
->getITBPtr()->invalidateMiscReg();
835 tc
->getDTBPtr()->invalidateMiscReg();
838 DPRINTF(Arm
, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
839 miscRegs
[misc_reg
], cpsr
, cpsr
.f
, cpsr
.i
, cpsr
.a
, cpsr
.mode
);
840 PCState pc
= tc
->pcState();
841 pc
.nextThumb(cpsr
.t
);
842 pc
.nextJazelle(cpsr
.j
);
844 // Follow slightly different semantics if a CheckerCPU object
846 CheckerCPU
*checker
= tc
->getCheckerCpuPtr();
848 tc
->pcStateNoRecord(pc
);
854 if (!miscRegInfo
[misc_reg
][MISCREG_IMPLEMENTED
]) {
855 if (miscRegInfo
[misc_reg
][MISCREG_WARN_NOT_FAIL
])
856 warn("Unimplemented system register %s write with %#x.\n",
857 miscRegName
[misc_reg
], val
);
859 panic("Unimplemented system register %s write with %#x.\n",
860 miscRegName
[misc_reg
], val
);
863 switch (unflattenMiscReg(misc_reg
)) {
867 const uint32_t ones
= (uint32_t)(-1);
869 // Only cp10, cp11, and ase are implemented, nothing else should
871 cpacrMask
.cp10
= ones
;
872 cpacrMask
.cp11
= ones
;
873 cpacrMask
.asedis
= ones
;
875 // Security Extensions may limit the writability of CPACR
877 scr
= readMiscRegNoEffect(MISCREG_SCR
);
878 CPSR cpsr
= readMiscRegNoEffect(MISCREG_CPSR
);
879 if (scr
.ns
&& (cpsr
.mode
!= MODE_MON
)) {
880 NSACR nsacr
= readMiscRegNoEffect(MISCREG_NSACR
);
881 // NB: Skipping the full loop, here
882 if (!nsacr
.cp10
) cpacrMask
.cp10
= 0;
883 if (!nsacr
.cp11
) cpacrMask
.cp11
= 0;
887 MiscReg old_val
= readMiscRegNoEffect(MISCREG_CPACR
);
889 newVal
|= old_val
& ~cpacrMask
;
890 DPRINTF(MiscRegs
, "Writing misc reg %s: %#x\n",
891 miscRegName
[misc_reg
], newVal
);
894 case MISCREG_CPACR_EL1
:
896 const uint32_t ones
= (uint32_t)(-1);
898 cpacrMask
.tta
= ones
;
899 cpacrMask
.fpen
= ones
;
901 DPRINTF(MiscRegs
, "Writing misc reg %s: %#x\n",
902 miscRegName
[misc_reg
], newVal
);
905 case MISCREG_CPTR_EL2
:
907 const uint32_t ones
= (uint32_t)(-1);
909 cptrMask
.tcpac
= ones
;
914 cptrMask
.res1_13_12_el2
= ones
;
915 cptrMask
.res1_9_0_el2
= ones
;
917 DPRINTF(MiscRegs
, "Writing misc reg %s: %#x\n",
918 miscRegName
[misc_reg
], newVal
);
921 case MISCREG_CPTR_EL3
:
923 const uint32_t ones
= (uint32_t)(-1);
925 cptrMask
.tcpac
= ones
;
929 DPRINTF(MiscRegs
, "Writing misc reg %s: %#x\n",
930 miscRegName
[misc_reg
], newVal
);
934 warn_once("The csselr register isn't implemented.\n");
937 case MISCREG_DC_ZVA_Xt
:
938 warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
943 const uint32_t ones
= (uint32_t)(-1);
945 fpscrMask
.ioc
= ones
;
946 fpscrMask
.dzc
= ones
;
947 fpscrMask
.ofc
= ones
;
948 fpscrMask
.ufc
= ones
;
949 fpscrMask
.ixc
= ones
;
950 fpscrMask
.idc
= ones
;
951 fpscrMask
.ioe
= ones
;
952 fpscrMask
.dze
= ones
;
953 fpscrMask
.ofe
= ones
;
954 fpscrMask
.ufe
= ones
;
955 fpscrMask
.ixe
= ones
;
956 fpscrMask
.ide
= ones
;
957 fpscrMask
.len
= ones
;
958 fpscrMask
.stride
= ones
;
959 fpscrMask
.rMode
= ones
;
962 fpscrMask
.ahp
= ones
;
968 newVal
= (newVal
& (uint32_t)fpscrMask
) |
969 (readMiscRegNoEffect(MISCREG_FPSCR
) &
970 ~(uint32_t)fpscrMask
);
971 tc
->getDecoderPtr()->setContext(newVal
);
976 const uint32_t ones
= (uint32_t)(-1);
978 fpscrMask
.ioc
= ones
;
979 fpscrMask
.dzc
= ones
;
980 fpscrMask
.ofc
= ones
;
981 fpscrMask
.ufc
= ones
;
982 fpscrMask
.ixc
= ones
;
983 fpscrMask
.idc
= ones
;
989 newVal
= (newVal
& (uint32_t)fpscrMask
) |
990 (readMiscRegNoEffect(MISCREG_FPSCR
) &
991 ~(uint32_t)fpscrMask
);
992 misc_reg
= MISCREG_FPSCR
;
997 const uint32_t ones
= (uint32_t)(-1);
999 fpscrMask
.ioe
= ones
;
1000 fpscrMask
.dze
= ones
;
1001 fpscrMask
.ofe
= ones
;
1002 fpscrMask
.ufe
= ones
;
1003 fpscrMask
.ixe
= ones
;
1004 fpscrMask
.ide
= ones
;
1005 fpscrMask
.len
= ones
;
1006 fpscrMask
.stride
= ones
;
1007 fpscrMask
.rMode
= ones
;
1008 fpscrMask
.fz
= ones
;
1009 fpscrMask
.dn
= ones
;
1010 fpscrMask
.ahp
= ones
;
1011 newVal
= (newVal
& (uint32_t)fpscrMask
) |
1012 (readMiscRegNoEffect(MISCREG_FPSCR
) &
1013 ~(uint32_t)fpscrMask
);
1014 misc_reg
= MISCREG_FPSCR
;
1017 case MISCREG_CPSR_Q
:
1019 assert(!(newVal
& ~CpsrMaskQ
));
1020 newVal
= readMiscRegNoEffect(MISCREG_CPSR
) | newVal
;
1021 misc_reg
= MISCREG_CPSR
;
1024 case MISCREG_FPSCR_QC
:
1026 newVal
= readMiscRegNoEffect(MISCREG_FPSCR
) |
1027 (newVal
& FpscrQcMask
);
1028 misc_reg
= MISCREG_FPSCR
;
1031 case MISCREG_FPSCR_EXC
:
1033 newVal
= readMiscRegNoEffect(MISCREG_FPSCR
) |
1034 (newVal
& FpscrExcMask
);
1035 misc_reg
= MISCREG_FPSCR
;
1040 // vfpv3 architecture, section B.6.1 of DDI04068
1041 // bit 29 - valid only if fpexc[31] is 0
1042 const uint32_t fpexcMask
= 0x60000000;
1043 newVal
= (newVal
& fpexcMask
) |
1044 (readMiscRegNoEffect(MISCREG_FPEXC
) & ~fpexcMask
);
1049 if (!haveVirtualization
)
1055 // ARM ARM (ARM DDI 0406C.b) B4.1.96
1056 const uint32_t ifsrMask
=
1057 mask(31, 13) | mask(11, 11) | mask(8, 6);
1058 newVal
= newVal
& ~ifsrMask
;
1063 // ARM ARM (ARM DDI 0406C.b) B4.1.52
1064 const uint32_t dfsrMask
= mask(31, 14) | mask(8, 8);
1065 newVal
= newVal
& ~dfsrMask
;
1068 case MISCREG_AMAIR0
:
1069 case MISCREG_AMAIR1
:
1071 // ARM ARM (ARM DDI 0406C.b) B4.1.5
1072 // Valid only with LPAE
1075 DPRINTF(MiscRegs
, "Writing AMAIR: %#x\n", newVal
);
1079 tc
->getITBPtr()->invalidateMiscReg();
1080 tc
->getDTBPtr()->invalidateMiscReg();
1084 DPRINTF(MiscRegs
, "Writing SCTLR: %#x\n", newVal
);
1085 MiscRegIndex sctlr_idx
;
1086 scr
= readMiscRegNoEffect(MISCREG_SCR
);
1087 if (haveSecurity
&& !scr
.ns
) {
1088 sctlr_idx
= MISCREG_SCTLR_S
;
1090 sctlr_idx
= MISCREG_SCTLR_NS
;
1091 // The FI field (bit 21) is common between S/NS versions
1092 // of the register, we store this in the secure copy of
1094 miscRegs
[MISCREG_SCTLR_S
] &= ~(1 << 21);
1095 miscRegs
[MISCREG_SCTLR_S
] |= newVal
& (1 << 21);
1097 SCTLR sctlr
= miscRegs
[sctlr_idx
];
1098 SCTLR new_sctlr
= newVal
;
1099 new_sctlr
.nmfi
= ((bool)sctlr
.nmfi
) && !haveVirtualization
;
1100 miscRegs
[sctlr_idx
] = (MiscReg
)new_sctlr
;
1101 tc
->getITBPtr()->invalidateMiscReg();
1102 tc
->getDTBPtr()->invalidateMiscReg();
1105 updateBootUncacheable(sctlr_idx
, tc
);
1109 case MISCREG_ID_PFR0
:
1110 case MISCREG_ID_PFR1
:
1111 case MISCREG_ID_DFR0
:
1112 case MISCREG_ID_MMFR0
:
1113 case MISCREG_ID_MMFR1
:
1114 case MISCREG_ID_MMFR2
:
1115 case MISCREG_ID_MMFR3
:
1116 case MISCREG_ID_ISAR0
:
1117 case MISCREG_ID_ISAR1
:
1118 case MISCREG_ID_ISAR2
:
1119 case MISCREG_ID_ISAR3
:
1120 case MISCREG_ID_ISAR4
:
1121 case MISCREG_ID_ISAR5
:
1129 case MISCREG_ID_AA64AFR0_EL1
:
1130 case MISCREG_ID_AA64AFR1_EL1
:
1131 case MISCREG_ID_AA64DFR0_EL1
:
1132 case MISCREG_ID_AA64DFR1_EL1
:
1133 case MISCREG_ID_AA64ISAR0_EL1
:
1134 case MISCREG_ID_AA64ISAR1_EL1
:
1135 case MISCREG_ID_AA64MMFR0_EL1
:
1136 case MISCREG_ID_AA64MMFR1_EL1
:
1137 case MISCREG_ID_AA64PFR0_EL1
:
1138 case MISCREG_ID_AA64PFR1_EL1
:
1139 // ID registers are constants.
1142 // TLBI all entries, EL0&1 inner sharable (ignored)
1143 case MISCREG_TLBIALLIS
:
1144 case MISCREG_TLBIALL
: // TLBI all entries, EL0&1,
1146 target_el
= 1; // el 0 and 1 are handled together
1147 scr
= readMiscReg(MISCREG_SCR
, tc
);
1148 secure_lookup
= haveSecurity
&& !scr
.ns
;
1149 sys
= tc
->getSystemPtr();
1150 for (x
= 0; x
< sys
->numContexts(); x
++) {
1151 oc
= sys
->getThreadContext(x
);
1152 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1153 oc
->getITBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1154 oc
->getDTBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1156 // If CheckerCPU is connected, need to notify it of a flush
1157 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1159 checker
->getITBPtr()->flushAllSecurity(secure_lookup
,
1161 checker
->getDTBPtr()->flushAllSecurity(secure_lookup
,
1166 // TLBI all entries, EL0&1, instruction side
1167 case MISCREG_ITLBIALL
:
1169 target_el
= 1; // el 0 and 1 are handled together
1170 scr
= readMiscReg(MISCREG_SCR
, tc
);
1171 secure_lookup
= haveSecurity
&& !scr
.ns
;
1172 tc
->getITBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1174 // TLBI all entries, EL0&1, data side
1175 case MISCREG_DTLBIALL
:
1177 target_el
= 1; // el 0 and 1 are handled together
1178 scr
= readMiscReg(MISCREG_SCR
, tc
);
1179 secure_lookup
= haveSecurity
&& !scr
.ns
;
1180 tc
->getDTBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1182 // TLBI based on VA, EL0&1 inner sharable (ignored)
1183 case MISCREG_TLBIMVAIS
:
1184 case MISCREG_TLBIMVA
:
1186 target_el
= 1; // el 0 and 1 are handled together
1187 scr
= readMiscReg(MISCREG_SCR
, tc
);
1188 secure_lookup
= haveSecurity
&& !scr
.ns
;
1189 sys
= tc
->getSystemPtr();
1190 for (x
= 0; x
< sys
->numContexts(); x
++) {
1191 oc
= sys
->getThreadContext(x
);
1192 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1193 oc
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1195 secure_lookup
, target_el
);
1196 oc
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1198 secure_lookup
, target_el
);
1200 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1202 checker
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1203 bits(newVal
, 7,0), secure_lookup
, target_el
);
1204 checker
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1205 bits(newVal
, 7,0), secure_lookup
, target_el
);
1209 // TLBI by ASID, EL0&1, inner sharable
1210 case MISCREG_TLBIASIDIS
:
1211 case MISCREG_TLBIASID
:
1213 target_el
= 1; // el 0 and 1 are handled together
1214 scr
= readMiscReg(MISCREG_SCR
, tc
);
1215 secure_lookup
= haveSecurity
&& !scr
.ns
;
1216 sys
= tc
->getSystemPtr();
1217 for (x
= 0; x
< sys
->numContexts(); x
++) {
1218 oc
= sys
->getThreadContext(x
);
1219 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1220 oc
->getITBPtr()->flushAsid(bits(newVal
, 7,0),
1221 secure_lookup
, target_el
);
1222 oc
->getDTBPtr()->flushAsid(bits(newVal
, 7,0),
1223 secure_lookup
, target_el
);
1224 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1226 checker
->getITBPtr()->flushAsid(bits(newVal
, 7,0),
1227 secure_lookup
, target_el
);
1228 checker
->getDTBPtr()->flushAsid(bits(newVal
, 7,0),
1229 secure_lookup
, target_el
);
1233 // TLBI by address, EL0&1, inner sharable (ignored)
1234 case MISCREG_TLBIMVAAIS
:
1235 case MISCREG_TLBIMVAA
:
1237 target_el
= 1; // el 0 and 1 are handled together
1238 scr
= readMiscReg(MISCREG_SCR
, tc
);
1239 secure_lookup
= haveSecurity
&& !scr
.ns
;
1241 tlbiMVA(tc
, newVal
, secure_lookup
, hyp
, target_el
);
1243 // TLBI by address, EL2, hypervisor mode
1244 case MISCREG_TLBIMVAH
:
1245 case MISCREG_TLBIMVAHIS
:
1247 target_el
= 1; // aarch32, use hyp bit
1248 scr
= readMiscReg(MISCREG_SCR
, tc
);
1249 secure_lookup
= haveSecurity
&& !scr
.ns
;
1251 tlbiMVA(tc
, newVal
, secure_lookup
, hyp
, target_el
);
1253 // TLBI by address and asid, EL0&1, instruction side only
1254 case MISCREG_ITLBIMVA
:
1256 target_el
= 1; // el 0 and 1 are handled together
1257 scr
= readMiscReg(MISCREG_SCR
, tc
);
1258 secure_lookup
= haveSecurity
&& !scr
.ns
;
1259 tc
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1260 bits(newVal
, 7,0), secure_lookup
, target_el
);
1262 // TLBI by address and asid, EL0&1, data side only
1263 case MISCREG_DTLBIMVA
:
1265 target_el
= 1; // el 0 and 1 are handled together
1266 scr
= readMiscReg(MISCREG_SCR
, tc
);
1267 secure_lookup
= haveSecurity
&& !scr
.ns
;
1268 tc
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
1269 bits(newVal
, 7,0), secure_lookup
, target_el
);
1271 // TLBI by ASID, EL0&1, instrution side only
1272 case MISCREG_ITLBIASID
:
1274 target_el
= 1; // el 0 and 1 are handled together
1275 scr
= readMiscReg(MISCREG_SCR
, tc
);
1276 secure_lookup
= haveSecurity
&& !scr
.ns
;
1277 tc
->getITBPtr()->flushAsid(bits(newVal
, 7,0), secure_lookup
,
1280 // TLBI by ASID EL0&1 data size only
1281 case MISCREG_DTLBIASID
:
1283 target_el
= 1; // el 0 and 1 are handled together
1284 scr
= readMiscReg(MISCREG_SCR
, tc
);
1285 secure_lookup
= haveSecurity
&& !scr
.ns
;
1286 tc
->getDTBPtr()->flushAsid(bits(newVal
, 7,0), secure_lookup
,
1289 // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB
1290 case MISCREG_TLBIALLNSNH
:
1291 case MISCREG_TLBIALLNSNHIS
:
1293 target_el
= 1; // el 0 and 1 are handled together
1295 tlbiALLN(tc
, hyp
, target_el
);
1297 // TLBI all entries, EL2, hyp,
1298 case MISCREG_TLBIALLH
:
1299 case MISCREG_TLBIALLHIS
:
1301 target_el
= 1; // aarch32, use hyp bit
1303 tlbiALLN(tc
, hyp
, target_el
);
1305 // AArch64 TLBI: invalidate all entries EL3
1306 case MISCREG_TLBI_ALLE3IS
:
1307 case MISCREG_TLBI_ALLE3
:
1310 secure_lookup
= true;
1311 tlbiALL(tc
, secure_lookup
, target_el
);
1313 // @todo: uncomment this to enable Virtualization
1314 // case MISCREG_TLBI_ALLE2IS:
1315 // case MISCREG_TLBI_ALLE2:
1316 // TLBI all entries, EL0&1
1317 case MISCREG_TLBI_ALLE1IS
:
1318 case MISCREG_TLBI_ALLE1
:
1319 // AArch64 TLBI: invalidate all entries, stage 1, current VMID
1320 case MISCREG_TLBI_VMALLE1IS
:
1321 case MISCREG_TLBI_VMALLE1
:
1322 // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID
1323 case MISCREG_TLBI_VMALLS12E1IS
:
1324 case MISCREG_TLBI_VMALLS12E1
:
1325 // @todo: handle VMID and stage 2 to enable Virtualization
1327 target_el
= 1; // el 0 and 1 are handled together
1328 scr
= readMiscReg(MISCREG_SCR
, tc
);
1329 secure_lookup
= haveSecurity
&& !scr
.ns
;
1330 tlbiALL(tc
, secure_lookup
, target_el
);
1332 // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID
1333 // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries
1334 // from the last level of translation table walks
1335 // @todo: handle VMID to enable Virtualization
1336 // TLBI all entries, EL0&1
1337 case MISCREG_TLBI_VAE3IS_Xt
:
1338 case MISCREG_TLBI_VAE3_Xt
:
1339 // TLBI by VA, EL3 regime stage 1, last level walk
1340 case MISCREG_TLBI_VALE3IS_Xt
:
1341 case MISCREG_TLBI_VALE3_Xt
:
1344 asid
= 0xbeef; // does not matter, tlbi is global
1345 secure_lookup
= true;
1346 tlbiVA(tc
, newVal
, asid
, secure_lookup
, target_el
);
1349 case MISCREG_TLBI_VAE2IS_Xt
:
1350 case MISCREG_TLBI_VAE2_Xt
:
1351 // TLBI by VA, EL2, stage1 last level walk
1352 case MISCREG_TLBI_VALE2IS_Xt
:
1353 case MISCREG_TLBI_VALE2_Xt
:
1356 asid
= 0xbeef; // does not matter, tlbi is global
1357 scr
= readMiscReg(MISCREG_SCR
, tc
);
1358 secure_lookup
= haveSecurity
&& !scr
.ns
;
1359 tlbiVA(tc
, newVal
, asid
, secure_lookup
, target_el
);
1361 // TLBI by VA EL1 & 0, stage1, ASID, current VMID
1362 case MISCREG_TLBI_VAE1IS_Xt
:
1363 case MISCREG_TLBI_VAE1_Xt
:
1364 case MISCREG_TLBI_VALE1IS_Xt
:
1365 case MISCREG_TLBI_VALE1_Xt
:
1367 asid
= bits(newVal
, 63, 48);
1368 target_el
= 1; // el 0 and 1 are handled together
1369 scr
= readMiscReg(MISCREG_SCR
, tc
);
1370 secure_lookup
= haveSecurity
&& !scr
.ns
;
1371 tlbiVA(tc
, newVal
, asid
, secure_lookup
, target_el
);
1373 // AArch64 TLBI: invalidate by ASID, stage 1, current VMID
1374 // @todo: handle VMID to enable Virtualization
1375 case MISCREG_TLBI_ASIDE1IS_Xt
:
1376 case MISCREG_TLBI_ASIDE1_Xt
:
1378 target_el
= 1; // el 0 and 1 are handled together
1379 scr
= readMiscReg(MISCREG_SCR
, tc
);
1380 secure_lookup
= haveSecurity
&& !scr
.ns
;
1381 sys
= tc
->getSystemPtr();
1382 for (x
= 0; x
< sys
->numContexts(); x
++) {
1383 oc
= sys
->getThreadContext(x
);
1384 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1385 asid
= bits(newVal
, 63, 48);
1386 if (haveLargeAsid64
)
1388 oc
->getITBPtr()->flushAsid(asid
, secure_lookup
, target_el
);
1389 oc
->getDTBPtr()->flushAsid(asid
, secure_lookup
, target_el
);
1390 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1392 checker
->getITBPtr()->flushAsid(asid
,
1393 secure_lookup
, target_el
);
1394 checker
->getDTBPtr()->flushAsid(asid
,
1395 secure_lookup
, target_el
);
1399 // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID
1400 // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
1401 // entries from the last level of translation table walks
1402 // @todo: handle VMID to enable Virtualization
1403 case MISCREG_TLBI_VAAE1IS_Xt
:
1404 case MISCREG_TLBI_VAAE1_Xt
:
1405 case MISCREG_TLBI_VAALE1IS_Xt
:
1406 case MISCREG_TLBI_VAALE1_Xt
:
1408 target_el
= 1; // el 0 and 1 are handled together
1409 scr
= readMiscReg(MISCREG_SCR
, tc
);
1410 secure_lookup
= haveSecurity
&& !scr
.ns
;
1411 sys
= tc
->getSystemPtr();
1412 for (x
= 0; x
< sys
->numContexts(); x
++) {
1413 // @todo: extra controls on TLBI broadcast?
1414 oc
= sys
->getThreadContext(x
);
1415 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1416 Addr va
= ((Addr
) bits(newVal
, 43, 0)) << 12;
1417 oc
->getITBPtr()->flushMva(va
,
1418 secure_lookup
, false, target_el
);
1419 oc
->getDTBPtr()->flushMva(va
,
1420 secure_lookup
, false, target_el
);
1422 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1424 checker
->getITBPtr()->flushMva(va
,
1425 secure_lookup
, false, target_el
);
1426 checker
->getDTBPtr()->flushMva(va
,
1427 secure_lookup
, false, target_el
);
1431 // AArch64 TLBI: invalidate by IPA, stage 2, current VMID
1432 case MISCREG_TLBI_IPAS2LE1IS_Xt
:
1433 case MISCREG_TLBI_IPAS2LE1_Xt
:
1434 case MISCREG_TLBI_IPAS2E1IS_Xt
:
1435 case MISCREG_TLBI_IPAS2E1_Xt
:
1437 // @todo: implement these as part of Virtualization
1438 warn("Not doing anything for write of miscreg ITLB_IPAS2\n");
1441 warn("Not doing anything for write of miscreg ACTLR\n");
1444 case MISCREG_PMXEVTYPER_PMCCFILTR
:
1445 case MISCREG_PMINTENSET_EL1
... MISCREG_PMOVSSET_EL0
:
1446 case MISCREG_PMEVCNTR0_EL0
... MISCREG_PMEVTYPER5_EL0
:
1447 case MISCREG_PMCR
... MISCREG_PMOVSSET
:
1448 pmu
->setMiscReg(misc_reg
, newVal
);
1452 case MISCREG_HSTR
: // TJDBX, now redifined to be RES0
1456 newVal
&= ~((uint32_t) hstrMask
);
1461 // If a CP bit in NSACR is 0 then the corresponding bit in
1462 // HCPTR is RAO/WI. Same applies to NSASEDIS
1463 secure_lookup
= haveSecurity
&&
1464 inSecureState(readMiscRegNoEffect(MISCREG_SCR
),
1465 readMiscRegNoEffect(MISCREG_CPSR
));
1466 if (!secure_lookup
) {
1467 MiscReg oldValue
= readMiscRegNoEffect(MISCREG_HCPTR
);
1468 MiscReg mask
= (readMiscRegNoEffect(MISCREG_NSACR
) ^ 0x7FFF) & 0xBFFF;
1469 newVal
= (newVal
& ~mask
) | (oldValue
& mask
);
1473 case MISCREG_HDFAR
: // alias for secure DFAR
1474 misc_reg
= MISCREG_DFAR_S
;
1476 case MISCREG_HIFAR
: // alias for secure IFAR
1477 misc_reg
= MISCREG_IFAR_S
;
1479 case MISCREG_ATS1CPR
:
1480 case MISCREG_ATS1CPW
:
1481 case MISCREG_ATS1CUR
:
1482 case MISCREG_ATS1CUW
:
1483 case MISCREG_ATS12NSOPR
:
1484 case MISCREG_ATS12NSOPW
:
1485 case MISCREG_ATS12NSOUR
:
1486 case MISCREG_ATS12NSOUW
:
1487 case MISCREG_ATS1HR
:
1488 case MISCREG_ATS1HW
:
1490 RequestPtr req
= new Request
;
1492 BaseTLB::Mode mode
= BaseTLB::Read
;
1493 TLB::ArmTranslationType tranType
= TLB::NormalTran
;
1496 case MISCREG_ATS1CPR
:
1497 flags
= TLB::MustBeOne
;
1498 tranType
= TLB::S1CTran
;
1499 mode
= BaseTLB::Read
;
1501 case MISCREG_ATS1CPW
:
1502 flags
= TLB::MustBeOne
;
1503 tranType
= TLB::S1CTran
;
1504 mode
= BaseTLB::Write
;
1506 case MISCREG_ATS1CUR
:
1507 flags
= TLB::MustBeOne
| TLB::UserMode
;
1508 tranType
= TLB::S1CTran
;
1509 mode
= BaseTLB::Read
;
1511 case MISCREG_ATS1CUW
:
1512 flags
= TLB::MustBeOne
| TLB::UserMode
;
1513 tranType
= TLB::S1CTran
;
1514 mode
= BaseTLB::Write
;
1516 case MISCREG_ATS12NSOPR
:
1518 panic("Security Extensions required for ATS12NSOPR");
1519 flags
= TLB::MustBeOne
;
1520 tranType
= TLB::S1S2NsTran
;
1521 mode
= BaseTLB::Read
;
1523 case MISCREG_ATS12NSOPW
:
1525 panic("Security Extensions required for ATS12NSOPW");
1526 flags
= TLB::MustBeOne
;
1527 tranType
= TLB::S1S2NsTran
;
1528 mode
= BaseTLB::Write
;
1530 case MISCREG_ATS12NSOUR
:
1532 panic("Security Extensions required for ATS12NSOUR");
1533 flags
= TLB::MustBeOne
| TLB::UserMode
;
1534 tranType
= TLB::S1S2NsTran
;
1535 mode
= BaseTLB::Read
;
1537 case MISCREG_ATS12NSOUW
:
1539 panic("Security Extensions required for ATS12NSOUW");
1540 flags
= TLB::MustBeOne
| TLB::UserMode
;
1541 tranType
= TLB::S1S2NsTran
;
1542 mode
= BaseTLB::Write
;
1544 case MISCREG_ATS1HR
: // only really useful from secure mode.
1545 flags
= TLB::MustBeOne
;
1546 tranType
= TLB::HypMode
;
1547 mode
= BaseTLB::Read
;
1549 case MISCREG_ATS1HW
:
1550 flags
= TLB::MustBeOne
;
1551 tranType
= TLB::HypMode
;
1552 mode
= BaseTLB::Write
;
1555 // If we're in timing mode then doing the translation in
1556 // functional mode then we're slightly distorting performance
1557 // results obtained from simulations. The translation should be
1558 // done in the same mode the core is running in. NOTE: This
1559 // can't be an atomic translation because that causes problems
1560 // with unexpected atomic snoop requests.
1561 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg
);
1562 req
->setVirt(0, val
, 1, flags
, Request::funcMasterId
,
1563 tc
->pcState().pc());
1564 req
->setThreadContext(tc
->contextId(), tc
->threadId());
1565 fault
= tc
->getDTBPtr()->translateFunctional(req
, tc
, mode
, tranType
);
1566 TTBCR ttbcr
= readMiscRegNoEffect(MISCREG_TTBCR
);
1567 HCR hcr
= readMiscRegNoEffect(MISCREG_HCR
);
1570 if (fault
== NoFault
) {
1571 Addr paddr
= req
->getPaddr();
1572 if (haveLPAE
&& (ttbcr
.eae
|| tranType
& TLB::HypMode
||
1573 ((tranType
& TLB::S1S2NsTran
) && hcr
.vm
) )) {
1574 newVal
= (paddr
& mask(39, 12)) |
1575 (tc
->getDTBPtr()->getAttr());
1577 newVal
= (paddr
& 0xfffff000) |
1578 (tc
->getDTBPtr()->getAttr());
1581 "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
1584 ArmFault
*armFault
= reinterpret_cast<ArmFault
*>(fault
.get());
1585 // Set fault bit and FSR
1586 FSR fsr
= armFault
->getFsr(tc
);
1588 newVal
= ((fsr
>> 9) & 1) << 11;
1590 // LPAE - rearange fault status
1591 newVal
|= ((fsr
>> 0) & 0x3f) << 1;
1593 // VMSA - rearange fault status
1594 newVal
|= ((fsr
>> 0) & 0xf) << 1;
1595 newVal
|= ((fsr
>> 10) & 0x1) << 5;
1596 newVal
|= ((fsr
>> 12) & 0x1) << 6;
1598 newVal
|= 0x1; // F bit
1599 newVal
|= ((armFault
->iss() >> 7) & 0x1) << 8;
1600 newVal
|= armFault
->isStage2() ? 0x200 : 0;
1602 "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
1606 setMiscRegNoEffect(MISCREG_PAR
, newVal
);
1611 TTBCR ttbcr
= readMiscRegNoEffect(MISCREG_TTBCR
);
1612 const uint32_t ones
= (uint32_t)(-1);
1613 TTBCR ttbcrMask
= 0;
1614 TTBCR ttbcrNew
= newVal
;
1616 // ARM DDI 0406C.b, ARMv7-32
1617 ttbcrMask
.n
= ones
; // T0SZ
1619 ttbcrMask
.pd0
= ones
;
1620 ttbcrMask
.pd1
= ones
;
1622 ttbcrMask
.epd0
= ones
;
1623 ttbcrMask
.irgn0
= ones
;
1624 ttbcrMask
.orgn0
= ones
;
1625 ttbcrMask
.sh0
= ones
;
1626 ttbcrMask
.ps
= ones
; // T1SZ
1627 ttbcrMask
.a1
= ones
;
1628 ttbcrMask
.epd1
= ones
;
1629 ttbcrMask
.irgn1
= ones
;
1630 ttbcrMask
.orgn1
= ones
;
1631 ttbcrMask
.sh1
= ones
;
1633 ttbcrMask
.eae
= ones
;
1635 if (haveLPAE
&& ttbcrNew
.eae
) {
1636 newVal
= newVal
& ttbcrMask
;
1638 newVal
= (newVal
& ttbcrMask
) | (ttbcr
& (~ttbcrMask
));
1644 TTBCR ttbcr
= readMiscRegNoEffect(MISCREG_TTBCR
);
1647 // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
1648 // ARMv8 AArch32 bit 63-56 only
1649 uint64_t ttbrMask
= mask(63,56) | mask(47,40);
1650 newVal
= (newVal
& (~ttbrMask
));
1654 case MISCREG_SCTLR_EL1
:
1656 tc
->getITBPtr()->invalidateMiscReg();
1657 tc
->getDTBPtr()->invalidateMiscReg();
1658 SCTLR new_sctlr
= newVal
;
1659 setMiscRegNoEffect(misc_reg
, newVal
);
1661 updateBootUncacheable(misc_reg
, tc
);
1664 case MISCREG_CONTEXTIDR
:
1671 case MISCREG_SCR_EL3
:
1672 case MISCREG_TCR_EL1
:
1673 case MISCREG_TCR_EL2
:
1674 case MISCREG_TCR_EL3
:
1675 case MISCREG_SCTLR_EL2
:
1676 case MISCREG_SCTLR_EL3
:
1677 case MISCREG_TTBR0_EL1
:
1678 case MISCREG_TTBR1_EL1
:
1679 case MISCREG_TTBR0_EL2
:
1680 case MISCREG_TTBR0_EL3
:
1681 tc
->getITBPtr()->invalidateMiscReg();
1682 tc
->getDTBPtr()->invalidateMiscReg();
1688 tc
->setCCReg(CCREG_NZ
, cpsr
.nz
);
1689 tc
->setCCReg(CCREG_C
, cpsr
.c
);
1690 tc
->setCCReg(CCREG_V
, cpsr
.v
);
1695 CPSR cpsr
= miscRegs
[MISCREG_CPSR
];
1696 cpsr
.daif
= (uint8_t) ((CPSR
) newVal
).daif
;
1698 misc_reg
= MISCREG_CPSR
;
1701 case MISCREG_SP_EL0
:
1702 tc
->setIntReg(INTREG_SP0
, newVal
);
1704 case MISCREG_SP_EL1
:
1705 tc
->setIntReg(INTREG_SP1
, newVal
);
1707 case MISCREG_SP_EL2
:
1708 tc
->setIntReg(INTREG_SP2
, newVal
);
1712 CPSR cpsr
= miscRegs
[MISCREG_CPSR
];
1713 cpsr
.sp
= (uint8_t) ((CPSR
) newVal
).sp
;
1715 misc_reg
= MISCREG_CPSR
;
1718 case MISCREG_CURRENTEL
:
1720 CPSR cpsr
= miscRegs
[MISCREG_CPSR
];
1721 cpsr
.el
= (uint8_t) ((CPSR
) newVal
).el
;
1723 misc_reg
= MISCREG_CPSR
;
1726 case MISCREG_AT_S1E1R_Xt
:
1727 case MISCREG_AT_S1E1W_Xt
:
1728 case MISCREG_AT_S1E0R_Xt
:
1729 case MISCREG_AT_S1E0W_Xt
:
1730 case MISCREG_AT_S1E2R_Xt
:
1731 case MISCREG_AT_S1E2W_Xt
:
1732 case MISCREG_AT_S12E1R_Xt
:
1733 case MISCREG_AT_S12E1W_Xt
:
1734 case MISCREG_AT_S12E0R_Xt
:
1735 case MISCREG_AT_S12E0W_Xt
:
1736 case MISCREG_AT_S1E3R_Xt
:
1737 case MISCREG_AT_S1E3W_Xt
:
1739 RequestPtr req
= new Request
;
1741 BaseTLB::Mode mode
= BaseTLB::Read
;
1742 TLB::ArmTranslationType tranType
= TLB::NormalTran
;
1745 case MISCREG_AT_S1E1R_Xt
:
1746 flags
= TLB::MustBeOne
;
1747 tranType
= TLB::S1CTran
;
1748 mode
= BaseTLB::Read
;
1750 case MISCREG_AT_S1E1W_Xt
:
1751 flags
= TLB::MustBeOne
;
1752 tranType
= TLB::S1CTran
;
1753 mode
= BaseTLB::Write
;
1755 case MISCREG_AT_S1E0R_Xt
:
1756 flags
= TLB::MustBeOne
| TLB::UserMode
;
1757 tranType
= TLB::S1CTran
;
1758 mode
= BaseTLB::Read
;
1760 case MISCREG_AT_S1E0W_Xt
:
1761 flags
= TLB::MustBeOne
| TLB::UserMode
;
1762 tranType
= TLB::S1CTran
;
1763 mode
= BaseTLB::Write
;
1765 case MISCREG_AT_S1E2R_Xt
:
1766 flags
= TLB::MustBeOne
;
1767 tranType
= TLB::HypMode
;
1768 mode
= BaseTLB::Read
;
1770 case MISCREG_AT_S1E2W_Xt
:
1771 flags
= TLB::MustBeOne
;
1772 tranType
= TLB::HypMode
;
1773 mode
= BaseTLB::Write
;
1775 case MISCREG_AT_S12E0R_Xt
:
1776 flags
= TLB::MustBeOne
| TLB::UserMode
;
1777 tranType
= TLB::S1S2NsTran
;
1778 mode
= BaseTLB::Read
;
1780 case MISCREG_AT_S12E0W_Xt
:
1781 flags
= TLB::MustBeOne
| TLB::UserMode
;
1782 tranType
= TLB::S1S2NsTran
;
1783 mode
= BaseTLB::Write
;
1785 case MISCREG_AT_S12E1R_Xt
:
1786 flags
= TLB::MustBeOne
;
1787 tranType
= TLB::S1S2NsTran
;
1788 mode
= BaseTLB::Read
;
1790 case MISCREG_AT_S12E1W_Xt
:
1791 flags
= TLB::MustBeOne
;
1792 tranType
= TLB::S1S2NsTran
;
1793 mode
= BaseTLB::Write
;
1795 case MISCREG_AT_S1E3R_Xt
:
1796 flags
= TLB::MustBeOne
;
1797 tranType
= TLB::HypMode
; // There is no TZ mode defined.
1798 mode
= BaseTLB::Read
;
1800 case MISCREG_AT_S1E3W_Xt
:
1801 flags
= TLB::MustBeOne
;
1802 tranType
= TLB::HypMode
; // There is no TZ mode defined.
1803 mode
= BaseTLB::Write
;
1806 // If we're in timing mode then doing the translation in
1807 // functional mode then we're slightly distorting performance
1808 // results obtained from simulations. The translation should be
1809 // done in the same mode the core is running in. NOTE: This
1810 // can't be an atomic translation because that causes problems
1811 // with unexpected atomic snoop requests.
1812 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg
);
1813 req
->setVirt(0, val
, 1, flags
, Request::funcMasterId
,
1814 tc
->pcState().pc());
1815 req
->setThreadContext(tc
->contextId(), tc
->threadId());
1816 fault
= tc
->getDTBPtr()->translateFunctional(req
, tc
, mode
,
1820 if (fault
== NoFault
) {
1821 Addr paddr
= req
->getPaddr();
1822 uint64_t attr
= tc
->getDTBPtr()->getAttr();
1823 uint64_t attr1
= attr
>> 56;
1824 if (!attr1
|| attr1
==0x44) {
1826 attr
&= ~ uint64_t(0x80);
1828 newVal
= (paddr
& mask(47, 12)) | attr
;
1830 "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
1833 ArmFault
*armFault
= reinterpret_cast<ArmFault
*>(fault
.get());
1834 // Set fault bit and FSR
1835 FSR fsr
= armFault
->getFsr(tc
);
1837 newVal
= ((fsr
>> 9) & 1) << 11;
1838 // rearange fault status
1839 newVal
|= ((fsr
>> 0) & 0x3f) << 1;
1840 newVal
|= 0x1; // F bit
1841 newVal
|= ((armFault
->iss() >> 7) & 0x1) << 8;
1842 newVal
|= armFault
->isStage2() ? 0x200 : 0;
1844 "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
1848 setMiscRegNoEffect(MISCREG_PAR_EL1
, newVal
);
1851 case MISCREG_SPSR_EL3
:
1852 case MISCREG_SPSR_EL2
:
1853 case MISCREG_SPSR_EL1
:
1854 // Force bits 23:21 to 0
1855 newVal
= val
& ~(0x7 << 21);
1857 case MISCREG_L2CTLR
:
1858 warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
1859 miscRegName
[misc_reg
], uint32_t(val
));
1862 // Generic Timer registers
1863 case MISCREG_CNTFRQ
:
1864 case MISCREG_CNTFRQ_EL0
:
1865 getSystemCounter(tc
)->setFreq(val
);
1867 case MISCREG_CNTP_CVAL
:
1868 case MISCREG_CNTP_CVAL_EL0
:
1869 getArchTimer(tc
, tc
->cpuId())->setCompareValue(val
);
1871 case MISCREG_CNTP_TVAL
:
1872 case MISCREG_CNTP_TVAL_EL0
:
1873 getArchTimer(tc
, tc
->cpuId())->setTimerValue(val
);
1875 case MISCREG_CNTP_CTL
:
1876 case MISCREG_CNTP_CTL_EL0
:
1877 getArchTimer(tc
, tc
->cpuId())->setControl(val
);
1879 // PL1 phys. timer, secure
1881 case MISCREG_CNTPS_CVAL_EL1
:
1882 case MISCREG_CNTPS_TVAL_EL1
:
1883 case MISCREG_CNTPS_CTL_EL1
:
1884 // PL2 phys. timer, non-secure
1886 case MISCREG_CNTHCTL
:
1887 case MISCREG_CNTHP_CVAL
:
1888 case MISCREG_CNTHP_TVAL
:
1889 case MISCREG_CNTHP_CTL
:
1891 case MISCREG_CNTHCTL_EL2
:
1892 case MISCREG_CNTHP_CVAL_EL2
:
1893 case MISCREG_CNTHP_TVAL_EL2
:
1894 case MISCREG_CNTHP_CTL_EL2
:
1897 case MISCREG_CNTV_CVAL
:
1898 case MISCREG_CNTV_TVAL
:
1899 case MISCREG_CNTV_CTL
:
1901 // case MISCREG_CNTV_CVAL_EL2:
1902 // case MISCREG_CNTV_TVAL_EL2:
1903 // case MISCREG_CNTV_CTL_EL2:
1907 setMiscRegNoEffect(misc_reg
, newVal
);
1911 ISA::updateBootUncacheable(int sctlr_idx
, ThreadContext
*tc
)
1916 // Check if all CPUs are booted with caches enabled
1917 // so we can stop enforcing coherency of some kernel
1918 // structures manually.
1919 sys
= tc
->getSystemPtr();
1920 for (int x
= 0; x
< sys
->numContexts(); x
++) {
1921 oc
= sys
->getThreadContext(x
);
1922 // @todo: double check this for security
1923 SCTLR other_sctlr
= oc
->readMiscRegNoEffect(sctlr_idx
);
1924 if (!other_sctlr
.c
&& oc
->status() != ThreadContext::Halted
)
1928 for (int x
= 0; x
< sys
->numContexts(); x
++) {
1929 oc
= sys
->getThreadContext(x
);
1930 oc
->getDTBPtr()->allCpusCaching();
1931 oc
->getITBPtr()->allCpusCaching();
1933 // If CheckerCPU is connected, need to notify it.
1934 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1936 checker
->getDTBPtr()->allCpusCaching();
1937 checker
->getITBPtr()->allCpusCaching();
1943 ISA::tlbiVA(ThreadContext
*tc
, MiscReg newVal
, uint8_t asid
, bool secure_lookup
,
1946 if (haveLargeAsid64
)
1948 Addr va
= ((Addr
) bits(newVal
, 43, 0)) << 12;
1949 System
*sys
= tc
->getSystemPtr();
1950 for (int x
= 0; x
< sys
->numContexts(); x
++) {
1951 ThreadContext
*oc
= sys
->getThreadContext(x
);
1952 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1953 oc
->getITBPtr()->flushMvaAsid(va
, asid
,
1954 secure_lookup
, target_el
);
1955 oc
->getDTBPtr()->flushMvaAsid(va
, asid
,
1956 secure_lookup
, target_el
);
1958 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1960 checker
->getITBPtr()->flushMvaAsid(
1961 va
, asid
, secure_lookup
, target_el
);
1962 checker
->getDTBPtr()->flushMvaAsid(
1963 va
, asid
, secure_lookup
, target_el
);
1969 ISA::tlbiALL(ThreadContext
*tc
, bool secure_lookup
, uint8_t target_el
)
1971 System
*sys
= tc
->getSystemPtr();
1972 for (int x
= 0; x
< sys
->numContexts(); x
++) {
1973 ThreadContext
*oc
= sys
->getThreadContext(x
);
1974 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1975 oc
->getITBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1976 oc
->getDTBPtr()->flushAllSecurity(secure_lookup
, target_el
);
1978 // If CheckerCPU is connected, need to notify it of a flush
1979 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
1981 checker
->getITBPtr()->flushAllSecurity(secure_lookup
,
1983 checker
->getDTBPtr()->flushAllSecurity(secure_lookup
,
1990 ISA::tlbiALLN(ThreadContext
*tc
, bool hyp
, uint8_t target_el
)
1992 System
*sys
= tc
->getSystemPtr();
1993 for (int x
= 0; x
< sys
->numContexts(); x
++) {
1994 ThreadContext
*oc
= sys
->getThreadContext(x
);
1995 assert(oc
->getITBPtr() && oc
->getDTBPtr());
1996 oc
->getITBPtr()->flushAllNs(hyp
, target_el
);
1997 oc
->getDTBPtr()->flushAllNs(hyp
, target_el
);
1999 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
2001 checker
->getITBPtr()->flushAllNs(hyp
, target_el
);
2002 checker
->getDTBPtr()->flushAllNs(hyp
, target_el
);
2008 ISA::tlbiMVA(ThreadContext
*tc
, MiscReg newVal
, bool secure_lookup
, bool hyp
,
2011 System
*sys
= tc
->getSystemPtr();
2012 for (int x
= 0; x
< sys
->numContexts(); x
++) {
2013 ThreadContext
*oc
= sys
->getThreadContext(x
);
2014 assert(oc
->getITBPtr() && oc
->getDTBPtr());
2015 oc
->getITBPtr()->flushMva(mbits(newVal
, 31,12),
2016 secure_lookup
, hyp
, target_el
);
2017 oc
->getDTBPtr()->flushMva(mbits(newVal
, 31,12),
2018 secure_lookup
, hyp
, target_el
);
2020 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
2022 checker
->getITBPtr()->flushMva(mbits(newVal
, 31,12),
2023 secure_lookup
, hyp
, target_el
);
2024 checker
->getDTBPtr()->flushMva(mbits(newVal
, 31,12),
2025 secure_lookup
, hyp
, target_el
);
2030 ::GenericTimer::SystemCounter
*
2031 ISA::getSystemCounter(ThreadContext
*tc
)
2033 ::GenericTimer::SystemCounter
*cnt
= ((ArmSystem
*) tc
->getSystemPtr())->
2036 panic("System counter not available\n");
2041 ::GenericTimer::ArchTimer
*
2042 ISA::getArchTimer(ThreadContext
*tc
, int cpu_id
)
2044 ::GenericTimer::ArchTimer
*timer
= ((ArmSystem
*) tc
->getSystemPtr())->
2045 getArchTimer(cpu_id
);
2046 if (timer
== NULL
) {
2047 panic("Architected timer not available\n");
2055 ArmISAParams::create()
2057 return new ArmISA::ISA(this);