2 * Copyright (c) 2010-2012 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/system.hh"
43 #include "cpu/checker/cpu.hh"
44 #include "debug/Arm.hh"
45 #include "debug/MiscRegs.hh"
46 #include "sim/faults.hh"
47 #include "sim/stat_control.hh"
48 #include "sim/system.hh"
56 SCTLR sctlr_rst
= miscRegs
[MISCREG_SCTLR_RST
];
57 uint32_t midr
= miscRegs
[MISCREG_MIDR
];
58 memset(miscRegs
, 0, sizeof(miscRegs
));
60 cpsr
.mode
= MODE_USER
;
61 miscRegs
[MISCREG_CPSR
] = cpsr
;
65 sctlr
.te
= (bool)sctlr_rst
.te
;
66 sctlr
.nmfi
= (bool)sctlr_rst
.nmfi
;
67 sctlr
.v
= (bool)sctlr_rst
.v
;
73 miscRegs
[MISCREG_SCTLR
] = sctlr
;
74 miscRegs
[MISCREG_SCTLR_RST
] = sctlr_rst
;
76 // Preserve MIDR across reset
77 miscRegs
[MISCREG_MIDR
] = midr
;
79 /* Start with an event in the mailbox */
80 miscRegs
[MISCREG_SEV_MAILBOX
] = 1;
82 // Separate Instruction and Data TLBs.
83 miscRegs
[MISCREG_TLBTR
] = 1;
86 mvfr0
.advSimdRegisters
= 2;
87 mvfr0
.singlePrecision
= 2;
88 mvfr0
.doublePrecision
= 2;
89 mvfr0
.vfpExceptionTrapping
= 0;
92 mvfr0
.shortVectors
= 1;
93 mvfr0
.roundingModes
= 1;
94 miscRegs
[MISCREG_MVFR0
] = mvfr0
;
97 mvfr1
.flushToZero
= 1;
99 mvfr1
.advSimdLoadStore
= 1;
100 mvfr1
.advSimdInteger
= 1;
101 mvfr1
.advSimdSinglePrecision
= 1;
102 mvfr1
.advSimdHalfPrecision
= 1;
103 mvfr1
.vfpHalfPrecision
= 1;
104 miscRegs
[MISCREG_MVFR1
] = mvfr1
;
106 // Reset values of PRRR and NMRR are implementation dependent
108 miscRegs
[MISCREG_PRRR
] =
121 miscRegs
[MISCREG_NMRR
] =
138 miscRegs
[MISCREG_CPACR
] = 0;
139 miscRegs
[MISCREG_FPSID
] = 0x410430A0;
141 // See section B4.1.84 of ARM ARM
142 // All values are latest for ARMv7-A profile
143 miscRegs
[MISCREG_ID_ISAR0
] = 0x02101111;
144 miscRegs
[MISCREG_ID_ISAR1
] = 0x02112111;
145 miscRegs
[MISCREG_ID_ISAR2
] = 0x21232141;
146 miscRegs
[MISCREG_ID_ISAR3
] = 0x01112131;
147 miscRegs
[MISCREG_ID_ISAR4
] = 0x10010142;
148 miscRegs
[MISCREG_ID_ISAR5
] = 0x00000000;
150 //XXX We need to initialize the rest of the state.
154 ISA::readMiscRegNoEffect(int misc_reg
)
156 assert(misc_reg
< NumMiscRegs
);
159 if (misc_reg
== MISCREG_SPSR
)
160 flat_idx
= flattenMiscIndex(misc_reg
);
163 MiscReg val
= miscRegs
[flat_idx
];
165 DPRINTF(MiscRegs
, "Reading From misc reg %d (%d) : %#x\n",
166 misc_reg
, flat_idx
, val
);
172 ISA::readMiscReg(int misc_reg
, ThreadContext
*tc
)
176 if (misc_reg
== MISCREG_CPSR
) {
177 CPSR cpsr
= miscRegs
[misc_reg
];
178 PCState pc
= tc
->pcState();
179 cpsr
.j
= pc
.jazelle() ? 1 : 0;
180 cpsr
.t
= pc
.thumb() ? 1 : 0;
183 if (misc_reg
>= MISCREG_CP15_UNIMP_START
)
184 panic("Unimplemented CP15 register %s read.\n",
185 miscRegName
[misc_reg
]);
189 arm_sys
= dynamic_cast<ArmSystem
*>(tc
->getSystemPtr());
192 if (arm_sys
->multiProc
) {
193 return 0x80000000 | // multiprocessor extensions available
196 return 0x80000000 | // multiprocessor extensions available
197 0x40000000 | // in up system
201 case MISCREG_ID_MMFR0
:
202 return 0x03; // VMSAv7 support
203 case MISCREG_ID_MMFR2
:
204 return 0x01230000; // no HW access | WFI stalling | ISB and DSB
205 // | all TLB maintenance | no Harvard
206 case MISCREG_ID_MMFR3
:
207 return 0xF0102211; // SuperSec | Coherent TLB | Bcast Maint |
208 // BP Maint | Cache Maint Set/way | Cache Maint MVA
210 warn_once("The clidr register always reports 0 caches.\n");
211 warn_once("clidr LoUIS field of 0b001 to match current "
212 "ARM implementations.\n");
215 warn_once("The ccsidr register isn't implemented and "
216 "always reads as 0.\n");
218 case MISCREG_ID_PFR0
:
219 warn("Returning thumbEE disabled for now since we don't support CP14"
220 "config registers and jumping to ThumbEE vectors\n");
221 return 0x0031; // !ThumbEE | !Jazelle | Thumb | ARM
222 case MISCREG_ID_PFR1
:
223 return 0x00001; // !Timer | !Virti | !M Profile | !TrustZone | ARMv4
225 return 0x86468006; // V7, 64 byte cache line, load/exclusive is exact
227 warn("Not doing anything for miscreg ACTLR\n");
230 case MISCREG_PMCCNTR
:
232 warn("Not doing anything for read to miscreg %s\n",
233 miscRegName
[misc_reg
]);
236 panic("shouldn't be reading this register seperately\n");
237 case MISCREG_FPSCR_QC
:
238 return readMiscRegNoEffect(MISCREG_FPSCR
) & ~FpscrQcMask
;
239 case MISCREG_FPSCR_EXC
:
240 return readMiscRegNoEffect(MISCREG_FPSCR
) & ~FpscrExcMask
;
243 // mostly unimplemented, just set NumCPUs field from sim and return
245 // b00:1CPU to b11:4CPUs
246 l2ctlr
.numCPUs
= tc
->getSystemPtr()->numContexts() - 1;
249 case MISCREG_DBGDIDR
:
250 /* For now just implement the version number.
251 * Return 0 as we don't support debug architecture yet.
254 case MISCREG_DBGDSCR_INT
:
257 return readMiscRegNoEffect(misc_reg
);
261 ISA::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
)
263 assert(misc_reg
< NumMiscRegs
);
266 if (misc_reg
== MISCREG_SPSR
)
267 flat_idx
= flattenMiscIndex(misc_reg
);
270 miscRegs
[flat_idx
] = val
;
272 DPRINTF(MiscRegs
, "Writing to misc reg %d (%d) : %#x\n", misc_reg
,
277 ISA::setMiscReg(int misc_reg
, const MiscReg
&val
, ThreadContext
*tc
)
280 MiscReg newVal
= val
;
285 if (misc_reg
== MISCREG_CPSR
) {
289 CPSR old_cpsr
= miscRegs
[MISCREG_CPSR
];
290 int old_mode
= old_cpsr
.mode
;
292 if (old_mode
!= cpsr
.mode
) {
293 tc
->getITBPtr()->invalidateMiscReg();
294 tc
->getDTBPtr()->invalidateMiscReg();
297 DPRINTF(Arm
, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
298 miscRegs
[misc_reg
], cpsr
, cpsr
.f
, cpsr
.i
, cpsr
.a
, cpsr
.mode
);
299 PCState pc
= tc
->pcState();
300 pc
.nextThumb(cpsr
.t
);
301 pc
.nextJazelle(cpsr
.j
);
303 // Follow slightly different semantics if a CheckerCPU object
305 CheckerCPU
*checker
= tc
->getCheckerCpuPtr();
307 tc
->pcStateNoRecord(pc
);
311 } else if (misc_reg
>= MISCREG_CP15_UNIMP_START
&&
312 misc_reg
< MISCREG_CP15_END
) {
313 panic("Unimplemented CP15 register %s wrote with %#x.\n",
314 miscRegName
[misc_reg
], val
);
320 const uint32_t ones
= (uint32_t)(-1);
322 // Only cp10, cp11, and ase are implemented, nothing else should
324 cpacrMask
.cp10
= ones
;
325 cpacrMask
.cp11
= ones
;
326 cpacrMask
.asedis
= ones
;
328 DPRINTF(MiscRegs
, "Writing misc reg %s: %#x\n",
329 miscRegName
[misc_reg
], newVal
);
333 warn_once("The csselr register isn't implemented.\n");
337 const uint32_t ones
= (uint32_t)(-1);
339 fpscrMask
.ioc
= ones
;
340 fpscrMask
.dzc
= ones
;
341 fpscrMask
.ofc
= ones
;
342 fpscrMask
.ufc
= ones
;
343 fpscrMask
.ixc
= ones
;
344 fpscrMask
.idc
= ones
;
345 fpscrMask
.len
= ones
;
346 fpscrMask
.stride
= ones
;
347 fpscrMask
.rMode
= ones
;
350 fpscrMask
.ahp
= ones
;
356 newVal
= (newVal
& (uint32_t)fpscrMask
) |
357 (miscRegs
[MISCREG_FPSCR
] & ~(uint32_t)fpscrMask
);
362 assert(!(newVal
& ~CpsrMaskQ
));
363 newVal
= miscRegs
[MISCREG_CPSR
] | newVal
;
364 misc_reg
= MISCREG_CPSR
;
367 case MISCREG_FPSCR_QC
:
369 newVal
= miscRegs
[MISCREG_FPSCR
] | (newVal
& FpscrQcMask
);
370 misc_reg
= MISCREG_FPSCR
;
373 case MISCREG_FPSCR_EXC
:
375 newVal
= miscRegs
[MISCREG_FPSCR
] | (newVal
& FpscrExcMask
);
376 misc_reg
= MISCREG_FPSCR
;
381 // vfpv3 architecture, section B.6.1 of DDI04068
382 // bit 29 - valid only if fpexc[31] is 0
383 const uint32_t fpexcMask
= 0x60000000;
384 newVal
= (newVal
& fpexcMask
) |
385 (miscRegs
[MISCREG_FPEXC
] & ~fpexcMask
);
390 DPRINTF(MiscRegs
, "Writing SCTLR: %#x\n", newVal
);
391 SCTLR sctlr
= miscRegs
[MISCREG_SCTLR
];
392 SCTLR new_sctlr
= newVal
;
393 new_sctlr
.nmfi
= (bool)sctlr
.nmfi
;
394 miscRegs
[MISCREG_SCTLR
] = (MiscReg
)new_sctlr
;
395 tc
->getITBPtr()->invalidateMiscReg();
396 tc
->getDTBPtr()->invalidateMiscReg();
398 // Check if all CPUs are booted with caches enabled
399 // so we can stop enforcing coherency of some kernel
400 // structures manually.
401 sys
= tc
->getSystemPtr();
402 for (x
= 0; x
< sys
->numContexts(); x
++) {
403 oc
= sys
->getThreadContext(x
);
404 SCTLR other_sctlr
= oc
->readMiscRegNoEffect(MISCREG_SCTLR
);
405 if (!other_sctlr
.c
&& oc
->status() != ThreadContext::Halted
)
409 for (x
= 0; x
< sys
->numContexts(); x
++) {
410 oc
= sys
->getThreadContext(x
);
411 oc
->getDTBPtr()->allCpusCaching();
412 oc
->getITBPtr()->allCpusCaching();
414 // If CheckerCPU is connected, need to notify it.
415 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
417 checker
->getDTBPtr()->allCpusCaching();
418 checker
->getITBPtr()->allCpusCaching();
429 case MISCREG_TLBIALLIS
:
430 case MISCREG_TLBIALL
:
431 sys
= tc
->getSystemPtr();
432 for (x
= 0; x
< sys
->numContexts(); x
++) {
433 oc
= sys
->getThreadContext(x
);
434 assert(oc
->getITBPtr() && oc
->getDTBPtr());
435 oc
->getITBPtr()->flushAll();
436 oc
->getDTBPtr()->flushAll();
438 // If CheckerCPU is connected, need to notify it of a flush
439 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
441 checker
->getITBPtr()->flushAll();
442 checker
->getDTBPtr()->flushAll();
446 case MISCREG_ITLBIALL
:
447 tc
->getITBPtr()->flushAll();
449 case MISCREG_DTLBIALL
:
450 tc
->getDTBPtr()->flushAll();
452 case MISCREG_TLBIMVAIS
:
453 case MISCREG_TLBIMVA
:
454 sys
= tc
->getSystemPtr();
455 for (x
= 0; x
< sys
->numContexts(); x
++) {
456 oc
= sys
->getThreadContext(x
);
457 assert(oc
->getITBPtr() && oc
->getDTBPtr());
458 oc
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
460 oc
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
463 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
465 checker
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
467 checker
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
472 case MISCREG_TLBIASIDIS
:
473 case MISCREG_TLBIASID
:
474 sys
= tc
->getSystemPtr();
475 for (x
= 0; x
< sys
->numContexts(); x
++) {
476 oc
= sys
->getThreadContext(x
);
477 assert(oc
->getITBPtr() && oc
->getDTBPtr());
478 oc
->getITBPtr()->flushAsid(bits(newVal
, 7,0));
479 oc
->getDTBPtr()->flushAsid(bits(newVal
, 7,0));
480 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
482 checker
->getITBPtr()->flushAsid(bits(newVal
, 7,0));
483 checker
->getDTBPtr()->flushAsid(bits(newVal
, 7,0));
487 case MISCREG_TLBIMVAAIS
:
488 case MISCREG_TLBIMVAA
:
489 sys
= tc
->getSystemPtr();
490 for (x
= 0; x
< sys
->numContexts(); x
++) {
491 oc
= sys
->getThreadContext(x
);
492 assert(oc
->getITBPtr() && oc
->getDTBPtr());
493 oc
->getITBPtr()->flushMva(mbits(newVal
, 31,12));
494 oc
->getDTBPtr()->flushMva(mbits(newVal
, 31,12));
496 CheckerCPU
*checker
= oc
->getCheckerCpuPtr();
498 checker
->getITBPtr()->flushMva(mbits(newVal
, 31,12));
499 checker
->getDTBPtr()->flushMva(mbits(newVal
, 31,12));
503 case MISCREG_ITLBIMVA
:
504 tc
->getITBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
507 case MISCREG_DTLBIMVA
:
508 tc
->getDTBPtr()->flushMvaAsid(mbits(newVal
, 31, 12),
511 case MISCREG_ITLBIASID
:
512 tc
->getITBPtr()->flushAsid(bits(newVal
, 7,0));
514 case MISCREG_DTLBIASID
:
515 tc
->getDTBPtr()->flushAsid(bits(newVal
, 7,0));
518 warn("Not doing anything for write of miscreg ACTLR\n");
522 // Performance counters not implemented. Instead, interpret
523 // a reset command to this register to reset the simulator
525 // PMCR_E | PMCR_P | PMCR_C
526 const int ResetAndEnableCounters
= 0x7;
527 if (newVal
== ResetAndEnableCounters
) {
528 inform("Resetting all simobject stats\n");
529 Stats::schedStatEvent(false, true);
533 case MISCREG_PMCCNTR
:
535 warn("Not doing anything for write to miscreg %s\n",
536 miscRegName
[misc_reg
]);
538 case MISCREG_V2PCWPR
:
539 case MISCREG_V2PCWPW
:
540 case MISCREG_V2PCWUR
:
541 case MISCREG_V2PCWUW
:
542 case MISCREG_V2POWPR
:
543 case MISCREG_V2POWPW
:
544 case MISCREG_V2POWUR
:
545 case MISCREG_V2POWUW
:
547 RequestPtr req
= new Request
;
552 case MISCREG_V2PCWPR
:
553 flags
= TLB::MustBeOne
;
554 mode
= BaseTLB::Read
;
556 case MISCREG_V2PCWPW
:
557 flags
= TLB::MustBeOne
;
558 mode
= BaseTLB::Write
;
560 case MISCREG_V2PCWUR
:
561 flags
= TLB::MustBeOne
| TLB::UserMode
;
562 mode
= BaseTLB::Read
;
564 case MISCREG_V2PCWUW
:
565 flags
= TLB::MustBeOne
| TLB::UserMode
;
566 mode
= BaseTLB::Write
;
569 panic("Security Extensions not implemented!");
571 warn("Translating via MISCREG in atomic mode! Fix Me!\n");
572 req
->setVirt(0, val
, 1, flags
, tc
->pcState().pc(),
573 Request::funcMasterId
);
574 fault
= tc
->getDTBPtr()->translateAtomic(req
, tc
, mode
);
575 if (fault
== NoFault
) {
576 miscRegs
[MISCREG_PAR
] =
577 (req
->getPaddr() & 0xfffff000) |
578 (tc
->getDTBPtr()->getAttr() );
580 "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
581 val
, miscRegs
[MISCREG_PAR
]);
584 // Set fault bit and FSR
585 FSR fsr
= miscRegs
[MISCREG_DFSR
];
586 miscRegs
[MISCREG_PAR
] =
594 case MISCREG_CONTEXTIDR
:
598 tc
->getITBPtr()->invalidateMiscReg();
599 tc
->getDTBPtr()->invalidateMiscReg();
601 case MISCREG_CPSR_MODE
:
602 // This miscreg is used by copy*Regs to set the CPSR mode
603 // without updating other CPSR variables. It's used to
604 // make sure the register map is in such a state that we can
605 // see all of the registers for the copy.
609 warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
610 miscRegName
[misc_reg
], uint32_t(val
));
613 setMiscRegNoEffect(misc_reg
, newVal
);