2 * Copyright (c) 2010-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) 2009 The Regents of The University of Michigan
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.
43 #ifndef __ARCH_ARM_MISCREGS_HH__
44 #define __ARCH_ARM_MISCREGS_HH__
49 #include "arch/arm/miscregs_types.hh"
50 #include "base/compiler.hh"
82 MISCREG_PRRR_MAIR0_NS,
85 MISCREG_NMRR_MAIR1_NS,
87 MISCREG_PMXEVTYPER_PMCCFILTR,
91 // AArch32 CP14 registers (debug/trace/ThumbEE/Jazelle control)
133 MISCREG_DBGAUTHSTATUS,
137 MISCREG_TEECR, // not in ARM DDI 0487A.b+
139 MISCREG_TEEHBR, // not in ARM DDI 0487A.b+
143 // AArch32 CP15 registers (system control)
275 MISCREG_TLBIIPAS2LIS,
278 MISCREG_TLBIALLNSNHIS,
335 MISCREG_CONTEXTIDR_NS,
336 MISCREG_CONTEXTIDR_S,
350 MISCREG_CNTP_TVAL_NS,
377 MISCREG_CNTP_CVAL_NS,
385 // AArch64 registers (Op0=2)
415 MISCREG_DBGVCR32_EL2,
421 MISCREG_DBGCLAIMSET_EL1,
422 MISCREG_DBGCLAIMCLR_EL1,
423 MISCREG_DBGAUTHSTATUS_EL1,
424 MISCREG_TEECR32_EL1, // not in ARM DDI 0487A.b+
425 MISCREG_TEEHBR32_EL1, // not in ARM DDI 0487A.b+
427 // AArch64 registers (Op0=1,3)
435 MISCREG_ID_MMFR0_EL1,
436 MISCREG_ID_MMFR1_EL1,
437 MISCREG_ID_MMFR2_EL1,
438 MISCREG_ID_MMFR3_EL1,
439 MISCREG_ID_ISAR0_EL1,
440 MISCREG_ID_ISAR1_EL1,
441 MISCREG_ID_ISAR2_EL1,
442 MISCREG_ID_ISAR3_EL1,
443 MISCREG_ID_ISAR4_EL1,
444 MISCREG_ID_ISAR5_EL1,
448 MISCREG_ID_AA64PFR0_EL1,
449 MISCREG_ID_AA64PFR1_EL1,
450 MISCREG_ID_AA64DFR0_EL1,
451 MISCREG_ID_AA64DFR1_EL1,
452 MISCREG_ID_AA64AFR0_EL1,
453 MISCREG_ID_AA64AFR1_EL1,
454 MISCREG_ID_AA64ISAR0_EL1,
455 MISCREG_ID_AA64ISAR1_EL1,
456 MISCREG_ID_AA64MMFR0_EL1,
457 MISCREG_ID_AA64MMFR1_EL1,
506 MISCREG_SPSR_IRQ_AA64,
507 MISCREG_SPSR_ABT_AA64,
508 MISCREG_SPSR_UND_AA64,
509 MISCREG_SPSR_FIQ_AA64,
546 MISCREG_AT_S12E1R_Xt,
547 MISCREG_AT_S12E1W_Xt,
548 MISCREG_AT_S12E0R_Xt,
549 MISCREG_AT_S12E0W_Xt,
552 MISCREG_TLBI_VMALLE1IS,
553 MISCREG_TLBI_VAE1IS_Xt,
554 MISCREG_TLBI_ASIDE1IS_Xt,
555 MISCREG_TLBI_VAAE1IS_Xt,
556 MISCREG_TLBI_VALE1IS_Xt,
557 MISCREG_TLBI_VAALE1IS_Xt,
558 MISCREG_TLBI_VMALLE1,
559 MISCREG_TLBI_VAE1_Xt,
560 MISCREG_TLBI_ASIDE1_Xt,
561 MISCREG_TLBI_VAAE1_Xt,
562 MISCREG_TLBI_VALE1_Xt,
563 MISCREG_TLBI_VAALE1_Xt,
564 MISCREG_TLBI_IPAS2E1IS_Xt,
565 MISCREG_TLBI_IPAS2LE1IS_Xt,
566 MISCREG_TLBI_ALLE2IS,
567 MISCREG_TLBI_VAE2IS_Xt,
568 MISCREG_TLBI_ALLE1IS,
569 MISCREG_TLBI_VALE2IS_Xt,
570 MISCREG_TLBI_VMALLS12E1IS,
571 MISCREG_TLBI_IPAS2E1_Xt,
572 MISCREG_TLBI_IPAS2LE1_Xt,
574 MISCREG_TLBI_VAE2_Xt,
576 MISCREG_TLBI_VALE2_Xt,
577 MISCREG_TLBI_VMALLS12E1,
578 MISCREG_TLBI_ALLE3IS,
579 MISCREG_TLBI_VAE3IS_Xt,
580 MISCREG_TLBI_VALE3IS_Xt,
582 MISCREG_TLBI_VAE3_Xt,
583 MISCREG_TLBI_VALE3_Xt,
584 MISCREG_PMINTENSET_EL1,
585 MISCREG_PMINTENCLR_EL1,
587 MISCREG_PMCNTENSET_EL0,
588 MISCREG_PMCNTENCLR_EL0,
589 MISCREG_PMOVSCLR_EL0,
595 MISCREG_PMXEVTYPER_EL0,
596 MISCREG_PMCCFILTR_EL0,
597 MISCREG_PMXEVCNTR_EL0,
598 MISCREG_PMUSERENR_EL0,
599 MISCREG_PMOVSSET_EL0,
616 MISCREG_CONTEXTIDR_EL1,
626 MISCREG_CNTP_TVAL_EL0,
627 MISCREG_CNTP_CTL_EL0,
628 MISCREG_CNTP_CVAL_EL0,
629 MISCREG_CNTV_TVAL_EL0,
630 MISCREG_CNTV_CTL_EL0,
631 MISCREG_CNTV_CVAL_EL0,
632 MISCREG_PMEVCNTR0_EL0,
633 MISCREG_PMEVCNTR1_EL0,
634 MISCREG_PMEVCNTR2_EL0,
635 MISCREG_PMEVCNTR3_EL0,
636 MISCREG_PMEVCNTR4_EL0,
637 MISCREG_PMEVCNTR5_EL0,
638 MISCREG_PMEVTYPER0_EL0,
639 MISCREG_PMEVTYPER1_EL0,
640 MISCREG_PMEVTYPER2_EL0,
641 MISCREG_PMEVTYPER3_EL0,
642 MISCREG_PMEVTYPER4_EL0,
643 MISCREG_PMEVTYPER5_EL0,
646 MISCREG_CNTHP_TVAL_EL2,
647 MISCREG_CNTHP_CTL_EL2,
648 MISCREG_CNTHP_CVAL_EL2,
649 MISCREG_CNTPS_TVAL_EL1,
650 MISCREG_CNTPS_CTL_EL1,
651 MISCREG_CNTPS_CVAL_EL1,
652 MISCREG_IL1DATA0_EL1,
653 MISCREG_IL1DATA1_EL1,
654 MISCREG_IL1DATA2_EL1,
655 MISCREG_IL1DATA3_EL1,
656 MISCREG_DL1DATA0_EL1,
657 MISCREG_DL1DATA1_EL1,
658 MISCREG_DL1DATA2_EL1,
659 MISCREG_DL1DATA3_EL1,
660 MISCREG_DL1DATA4_EL1,
662 MISCREG_CPUACTLR_EL1,
663 MISCREG_CPUECTLR_EL1,
664 MISCREG_CPUMERRSR_EL1,
665 MISCREG_L2MERRSR_EL1,
667 MISCREG_CONTEXTIDR_EL2,
669 // Introduced in ARMv8.1
671 MISCREG_CNTHV_CTL_EL2,
672 MISCREG_CNTHV_CVAL_EL2,
673 MISCREG_CNTHV_TVAL_EL2,
675 MISCREG_ID_AA64MMFR2_EL1,
676 // These MISCREG_FREESLOT are available Misc Register
677 // slots for future registers to be implemented.
680 // NUM_PHYS_MISCREGS specifies the number of actual physical
681 // registers, not considering the following pseudo-registers
682 // (dummy registers), like UNKNOWN, CP15_UNIMPL, MISCREG_IMPDEF_UNIMPL.
683 // Checkpointing should use this physical index when
684 // saving/restoring register values.
694 // Implementation defined register: this represent
695 // a pool of unimplemented registers whose access can throw
696 // either UNDEFINED or hypervisor trap exception.
697 MISCREG_IMPDEF_UNIMPL,
699 // RAS extension (unimplemented)
704 MISCREG_ERXSTATUS_EL1,
706 MISCREG_ERXMISC0_EL1,
707 MISCREG_ERXMISC1_EL1,
712 // Total number of Misc Registers: Physical + Dummy
718 MISCREG_UNVERIFIABLE, // Does the value change on every read (e.g. a
719 // arch generic counter)
720 MISCREG_WARN_NOT_FAIL, // If MISCREG_IMPLEMENTED is deasserted, it
721 // tells whether the instruction should raise a
723 MISCREG_MUTEX, // True if the register corresponds to a pair of
724 // mutually exclusive registers
725 MISCREG_BANKED, // True if the register is banked between the two
726 // security states, and this is the parent node of the
727 // two banked registers
728 MISCREG_BANKED_CHILD, // The entry is one of the child registers that
729 // forms a banked set of regs (along with the
732 // Access permissions
738 // Privileged modes other than hypervisor or monitor
746 // Monitor mode, SCR.NS == 0
749 // Monitor mode, SCR.NS == 1
756 extern std::bitset<NUM_MISCREG_INFOS> miscRegInfo[NUM_MISCREGS];
758 // Decodes 32-bit CP14 registers accessible through MCR/MRC instructions
759 MiscRegIndex decodeCP14Reg(unsigned crn, unsigned opc1,
760 unsigned crm, unsigned opc2);
761 MiscRegIndex decodeAArch64SysReg(unsigned op0, unsigned op1,
762 unsigned crn, unsigned crm,
764 // Whether a particular AArch64 system register is -always- read only.
765 bool aarch64SysRegReadOnly(MiscRegIndex miscReg);
767 // Decodes 32-bit CP15 registers accessible through MCR/MRC instructions
768 MiscRegIndex decodeCP15Reg(unsigned crn, unsigned opc1,
769 unsigned crm, unsigned opc2);
771 // Decodes 64-bit CP15 registers accessible through MCRR/MRRC instructions
772 MiscRegIndex decodeCP15Reg64(unsigned crm, unsigned opc1);
775 const char * const miscRegName[] = {
805 "pmxevtyper_pmccfiltr",
809 // AArch32 CP14 registers
861 // AArch32 CP15 registers
1103 // AArch64 registers (Op0=2)
1141 "dbgauthstatus_el1",
1145 // AArch64 registers (Op0=1,3)
1282 "tlbi_ipas2e1is_xt",
1283 "tlbi_ipas2le1is_xt",
1288 "tlbi_vmalls12e1is",
1416 static_assert(sizeof(miscRegName) / sizeof(*miscRegName) == NUM_MISCREGS,
1417 "The miscRegName array and NUM_MISCREGS are inconsistent.");
1419 // This mask selects bits of the CPSR that actually go in the CondCodes
1420 // integer register to allow renaming.
1421 static const uint32_t CondCodesMask = 0xF00F0000;
1422 static const uint32_t CpsrMaskQ = 0x08000000;
1424 // APSR (Application Program Status Register Mask). It is the user level
1425 // alias for the CPSR. The APSR is a subset of the CPSR. Although
1426 // bits[15:0] are UNKNOWN on reads, it is permitted that, on a read of
1428 // Bit[9] returns the value of CPSR.E.
1429 // Bits[8:6] return the value of CPSR.{A,I, F}, the mask bits.
1430 static const uint32_t ApsrMask = CpsrMaskQ | CondCodesMask | 0x000001D0;
1432 // CPSR (Current Program Status Register Mask).
1433 static const uint32_t CpsrMask = ApsrMask | 0x00F003DF;
1435 // This mask selects bits of the FPSCR that actually go in the FpCondCodes
1436 // integer register to allow renaming.
1437 static const uint32_t FpCondCodesMask = 0xF0000000;
1438 // This mask selects the cumulative FP exception flags of the FPSCR.
1439 static const uint32_t FpscrExcMask = 0x0000009F;
1440 // This mask selects the cumulative saturation flag of the FPSCR.
1441 static const uint32_t FpscrQcMask = 0x08000000;
1444 * Check for permission to read coprocessor registers.
1446 * Checks whether an instruction at the current program mode has
1447 * permissions to read the coprocessor registers. This function
1448 * returns whether the check is undefined and if not whether the
1449 * read access is permitted.
1451 * @param the misc reg indicating the coprocessor
1454 * @return a tuple of booleans: can_read, undefined
1456 std::tuple<bool, bool> canReadCoprocReg(MiscRegIndex reg, SCR scr,
1460 * Check for permission to write coprocessor registers.
1462 * Checks whether an instruction at the current program mode has
1463 * permissions to write the coprocessor registers. This function
1464 * returns whether the check is undefined and if not whether the
1465 * write access is permitted.
1467 * @param the misc reg indicating the coprocessor
1470 * @return a tuple of booleans: can_write, undefined
1472 std::tuple<bool, bool> canWriteCoprocReg(MiscRegIndex reg, SCR scr,
1475 // Checks read access permissions to AArch64 system registers
1476 bool canReadAArch64SysReg(MiscRegIndex reg, SCR scr, CPSR cpsr,
1479 // Checks write access permissions to AArch64 system registers
1480 bool canWriteAArch64SysReg(MiscRegIndex reg, SCR scr, CPSR cpsr,
1483 // Uses just the scr.ns bit to pre flatten the misc regs. This is useful
1484 // for MCR/MRC instructions
1486 snsBankedIndex(MiscRegIndex reg, ThreadContext *tc);
1488 // Flattens a misc reg index using the specified security state. This is
1489 // used for opperations (eg address translations) where the security
1490 // state of the register access may differ from the current state of the
1493 snsBankedIndex(MiscRegIndex reg, ThreadContext *tc, bool ns);
1495 // Takes a misc reg index and returns the root reg if its one of a set of
1498 preUnflattenMiscReg();
1501 unflattenMiscReg(int reg);
1505 #endif // __ARCH_ARM_MISCREGS_HH__