2 * Copyright (c) 2010-2020 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.
41 #ifndef __ARCH_ARM_MISCREGS_HH__
42 #define __ARCH_ARM_MISCREGS_HH__
47 #include "arch/arm/miscregs_types.hh"
48 #include "base/compiler.hh"
80 MISCREG_PRRR_MAIR0_NS,
83 MISCREG_NMRR_MAIR1_NS,
85 MISCREG_PMXEVTYPER_PMCCFILTR,
89 // AArch32 CP14 registers (debug/trace/ThumbEE/Jazelle control)
131 MISCREG_DBGAUTHSTATUS,
135 MISCREG_TEECR, // not in ARM DDI 0487A.b+
137 MISCREG_TEEHBR, // not in ARM DDI 0487A.b+
141 // AArch32 CP15 registers (system control)
274 MISCREG_TLBIIPAS2LIS,
277 MISCREG_TLBIALLNSNHIS,
334 MISCREG_CONTEXTIDR_NS,
335 MISCREG_CONTEXTIDR_S,
349 MISCREG_CNTP_TVAL_NS,
376 MISCREG_CNTP_CVAL_NS,
384 // AArch64 registers (Op0=2)
414 MISCREG_DBGVCR32_EL2,
420 MISCREG_DBGCLAIMSET_EL1,
421 MISCREG_DBGCLAIMCLR_EL1,
422 MISCREG_DBGAUTHSTATUS_EL1,
423 MISCREG_TEECR32_EL1, // not in ARM DDI 0487A.b+
424 MISCREG_TEEHBR32_EL1, // not in ARM DDI 0487A.b+
426 // AArch64 registers (Op0=1,3)
434 MISCREG_ID_MMFR0_EL1,
435 MISCREG_ID_MMFR1_EL1,
436 MISCREG_ID_MMFR2_EL1,
437 MISCREG_ID_MMFR3_EL1,
438 MISCREG_ID_ISAR0_EL1,
439 MISCREG_ID_ISAR1_EL1,
440 MISCREG_ID_ISAR2_EL1,
441 MISCREG_ID_ISAR3_EL1,
442 MISCREG_ID_ISAR4_EL1,
443 MISCREG_ID_ISAR5_EL1,
447 MISCREG_ID_AA64PFR0_EL1,
448 MISCREG_ID_AA64PFR1_EL1,
449 MISCREG_ID_AA64DFR0_EL1,
450 MISCREG_ID_AA64DFR1_EL1,
451 MISCREG_ID_AA64AFR0_EL1,
452 MISCREG_ID_AA64AFR1_EL1,
453 MISCREG_ID_AA64ISAR0_EL1,
454 MISCREG_ID_AA64ISAR1_EL1,
455 MISCREG_ID_AA64MMFR0_EL1,
456 MISCREG_ID_AA64MMFR1_EL1,
505 MISCREG_SPSR_IRQ_AA64,
506 MISCREG_SPSR_ABT_AA64,
507 MISCREG_SPSR_UND_AA64,
508 MISCREG_SPSR_FIQ_AA64,
545 MISCREG_AT_S12E1R_Xt,
546 MISCREG_AT_S12E1W_Xt,
547 MISCREG_AT_S12E0R_Xt,
548 MISCREG_AT_S12E0W_Xt,
551 MISCREG_TLBI_VMALLE1IS,
552 MISCREG_TLBI_VAE1IS_Xt,
553 MISCREG_TLBI_ASIDE1IS_Xt,
554 MISCREG_TLBI_VAAE1IS_Xt,
555 MISCREG_TLBI_VALE1IS_Xt,
556 MISCREG_TLBI_VAALE1IS_Xt,
557 MISCREG_TLBI_VMALLE1,
558 MISCREG_TLBI_VAE1_Xt,
559 MISCREG_TLBI_ASIDE1_Xt,
560 MISCREG_TLBI_VAAE1_Xt,
561 MISCREG_TLBI_VALE1_Xt,
562 MISCREG_TLBI_VAALE1_Xt,
563 MISCREG_TLBI_IPAS2E1IS_Xt,
564 MISCREG_TLBI_IPAS2LE1IS_Xt,
565 MISCREG_TLBI_ALLE2IS,
566 MISCREG_TLBI_VAE2IS_Xt,
567 MISCREG_TLBI_ALLE1IS,
568 MISCREG_TLBI_VALE2IS_Xt,
569 MISCREG_TLBI_VMALLS12E1IS,
570 MISCREG_TLBI_IPAS2E1_Xt,
571 MISCREG_TLBI_IPAS2LE1_Xt,
573 MISCREG_TLBI_VAE2_Xt,
575 MISCREG_TLBI_VALE2_Xt,
576 MISCREG_TLBI_VMALLS12E1,
577 MISCREG_TLBI_ALLE3IS,
578 MISCREG_TLBI_VAE3IS_Xt,
579 MISCREG_TLBI_VALE3IS_Xt,
581 MISCREG_TLBI_VAE3_Xt,
582 MISCREG_TLBI_VALE3_Xt,
583 MISCREG_PMINTENSET_EL1,
584 MISCREG_PMINTENCLR_EL1,
586 MISCREG_PMCNTENSET_EL0,
587 MISCREG_PMCNTENCLR_EL0,
588 MISCREG_PMOVSCLR_EL0,
594 MISCREG_PMXEVTYPER_EL0,
595 MISCREG_PMCCFILTR_EL0,
596 MISCREG_PMXEVCNTR_EL0,
597 MISCREG_PMUSERENR_EL0,
598 MISCREG_PMOVSSET_EL0,
615 MISCREG_CONTEXTIDR_EL1,
625 MISCREG_CNTP_TVAL_EL0,
626 MISCREG_CNTP_CTL_EL0,
627 MISCREG_CNTP_CVAL_EL0,
628 MISCREG_CNTV_TVAL_EL0,
629 MISCREG_CNTV_CTL_EL0,
630 MISCREG_CNTV_CVAL_EL0,
631 MISCREG_PMEVCNTR0_EL0,
632 MISCREG_PMEVCNTR1_EL0,
633 MISCREG_PMEVCNTR2_EL0,
634 MISCREG_PMEVCNTR3_EL0,
635 MISCREG_PMEVCNTR4_EL0,
636 MISCREG_PMEVCNTR5_EL0,
637 MISCREG_PMEVTYPER0_EL0,
638 MISCREG_PMEVTYPER1_EL0,
639 MISCREG_PMEVTYPER2_EL0,
640 MISCREG_PMEVTYPER3_EL0,
641 MISCREG_PMEVTYPER4_EL0,
642 MISCREG_PMEVTYPER5_EL0,
645 MISCREG_CNTHP_TVAL_EL2,
646 MISCREG_CNTHP_CTL_EL2,
647 MISCREG_CNTHP_CVAL_EL2,
648 MISCREG_CNTPS_TVAL_EL1,
649 MISCREG_CNTPS_CTL_EL1,
650 MISCREG_CNTPS_CVAL_EL1,
651 MISCREG_IL1DATA0_EL1,
652 MISCREG_IL1DATA1_EL1,
653 MISCREG_IL1DATA2_EL1,
654 MISCREG_IL1DATA3_EL1,
655 MISCREG_DL1DATA0_EL1,
656 MISCREG_DL1DATA1_EL1,
657 MISCREG_DL1DATA2_EL1,
658 MISCREG_DL1DATA3_EL1,
659 MISCREG_DL1DATA4_EL1,
661 MISCREG_CPUACTLR_EL1,
662 MISCREG_CPUECTLR_EL1,
663 MISCREG_CPUMERRSR_EL1,
664 MISCREG_L2MERRSR_EL1,
666 MISCREG_CONTEXTIDR_EL2,
668 // Introduced in ARMv8.1
670 MISCREG_CNTHV_CTL_EL2,
671 MISCREG_CNTHV_CVAL_EL2,
672 MISCREG_CNTHV_TVAL_EL2,
674 MISCREG_ID_AA64MMFR2_EL1,
676 //PAuth Key Regsiters
677 MISCREG_APDAKeyHi_EL1,
678 MISCREG_APDAKeyLo_EL1,
679 MISCREG_APDBKeyHi_EL1,
680 MISCREG_APDBKeyLo_EL1,
681 MISCREG_APGAKeyHi_EL1,
682 MISCREG_APGAKeyLo_EL1,
683 MISCREG_APIAKeyHi_EL1,
684 MISCREG_APIAKeyLo_EL1,
685 MISCREG_APIBKeyHi_EL1,
686 MISCREG_APIBKeyLo_EL1,
688 // GICv3, CPU interface
690 MISCREG_ICC_IAR0_EL1,
691 MISCREG_ICC_EOIR0_EL1,
692 MISCREG_ICC_HPPIR0_EL1,
693 MISCREG_ICC_BPR0_EL1,
694 MISCREG_ICC_AP0R0_EL1,
695 MISCREG_ICC_AP0R1_EL1,
696 MISCREG_ICC_AP0R2_EL1,
697 MISCREG_ICC_AP0R3_EL1,
698 MISCREG_ICC_AP1R0_EL1,
699 MISCREG_ICC_AP1R0_EL1_NS,
700 MISCREG_ICC_AP1R0_EL1_S,
701 MISCREG_ICC_AP1R1_EL1,
702 MISCREG_ICC_AP1R1_EL1_NS,
703 MISCREG_ICC_AP1R1_EL1_S,
704 MISCREG_ICC_AP1R2_EL1,
705 MISCREG_ICC_AP1R2_EL1_NS,
706 MISCREG_ICC_AP1R2_EL1_S,
707 MISCREG_ICC_AP1R3_EL1,
708 MISCREG_ICC_AP1R3_EL1_NS,
709 MISCREG_ICC_AP1R3_EL1_S,
712 MISCREG_ICC_SGI1R_EL1,
713 MISCREG_ICC_ASGI1R_EL1,
714 MISCREG_ICC_SGI0R_EL1,
715 MISCREG_ICC_IAR1_EL1,
716 MISCREG_ICC_EOIR1_EL1,
717 MISCREG_ICC_HPPIR1_EL1,
718 MISCREG_ICC_BPR1_EL1,
719 MISCREG_ICC_BPR1_EL1_NS,
720 MISCREG_ICC_BPR1_EL1_S,
721 MISCREG_ICC_CTLR_EL1,
722 MISCREG_ICC_CTLR_EL1_NS,
723 MISCREG_ICC_CTLR_EL1_S,
725 MISCREG_ICC_SRE_EL1_NS,
726 MISCREG_ICC_SRE_EL1_S,
727 MISCREG_ICC_IGRPEN0_EL1,
728 MISCREG_ICC_IGRPEN1_EL1,
729 MISCREG_ICC_IGRPEN1_EL1_NS,
730 MISCREG_ICC_IGRPEN1_EL1_S,
732 MISCREG_ICC_CTLR_EL3,
734 MISCREG_ICC_IGRPEN1_EL3,
736 // GICv3, CPU interface, virtualization
737 MISCREG_ICH_AP0R0_EL2,
738 MISCREG_ICH_AP0R1_EL2,
739 MISCREG_ICH_AP0R2_EL2,
740 MISCREG_ICH_AP0R3_EL2,
741 MISCREG_ICH_AP1R0_EL2,
742 MISCREG_ICH_AP1R1_EL2,
743 MISCREG_ICH_AP1R2_EL2,
744 MISCREG_ICH_AP1R3_EL2,
747 MISCREG_ICH_MISR_EL2,
748 MISCREG_ICH_EISR_EL2,
749 MISCREG_ICH_ELRSR_EL2,
750 MISCREG_ICH_VMCR_EL2,
761 MISCREG_ICH_LR10_EL2,
762 MISCREG_ICH_LR11_EL2,
763 MISCREG_ICH_LR12_EL2,
764 MISCREG_ICH_LR13_EL2,
765 MISCREG_ICH_LR14_EL2,
766 MISCREG_ICH_LR15_EL2,
769 MISCREG_ICV_IAR0_EL1,
770 MISCREG_ICV_EOIR0_EL1,
771 MISCREG_ICV_HPPIR0_EL1,
772 MISCREG_ICV_BPR0_EL1,
773 MISCREG_ICV_AP0R0_EL1,
774 MISCREG_ICV_AP0R1_EL1,
775 MISCREG_ICV_AP0R2_EL1,
776 MISCREG_ICV_AP0R3_EL1,
777 MISCREG_ICV_AP1R0_EL1,
778 MISCREG_ICV_AP1R0_EL1_NS,
779 MISCREG_ICV_AP1R0_EL1_S,
780 MISCREG_ICV_AP1R1_EL1,
781 MISCREG_ICV_AP1R1_EL1_NS,
782 MISCREG_ICV_AP1R1_EL1_S,
783 MISCREG_ICV_AP1R2_EL1,
784 MISCREG_ICV_AP1R2_EL1_NS,
785 MISCREG_ICV_AP1R2_EL1_S,
786 MISCREG_ICV_AP1R3_EL1,
787 MISCREG_ICV_AP1R3_EL1_NS,
788 MISCREG_ICV_AP1R3_EL1_S,
791 MISCREG_ICV_SGI1R_EL1,
792 MISCREG_ICV_ASGI1R_EL1,
793 MISCREG_ICV_SGI0R_EL1,
794 MISCREG_ICV_IAR1_EL1,
795 MISCREG_ICV_EOIR1_EL1,
796 MISCREG_ICV_HPPIR1_EL1,
797 MISCREG_ICV_BPR1_EL1,
798 MISCREG_ICV_BPR1_EL1_NS,
799 MISCREG_ICV_BPR1_EL1_S,
800 MISCREG_ICV_CTLR_EL1,
801 MISCREG_ICV_CTLR_EL1_NS,
802 MISCREG_ICV_CTLR_EL1_S,
804 MISCREG_ICV_SRE_EL1_NS,
805 MISCREG_ICV_SRE_EL1_S,
806 MISCREG_ICV_IGRPEN0_EL1,
807 MISCREG_ICV_IGRPEN1_EL1,
808 MISCREG_ICV_IGRPEN1_EL1_NS,
809 MISCREG_ICV_IGRPEN1_EL1_S,
816 MISCREG_ICC_AP1R0_NS,
819 MISCREG_ICC_AP1R1_NS,
822 MISCREG_ICC_AP1R2_NS,
825 MISCREG_ICC_AP1R3_NS,
845 MISCREG_ICC_IGRPEN1_NS,
846 MISCREG_ICC_IGRPEN1_S,
906 MISCREG_ID_AA64ZFR0_EL1,
912 // NUM_PHYS_MISCREGS specifies the number of actual physical
913 // registers, not considering the following pseudo-registers
914 // (dummy registers), like UNKNOWN, CP15_UNIMPL, MISCREG_IMPDEF_UNIMPL.
915 // Checkpointing should use this physical index when
916 // saving/restoring register values.
926 // Implementation defined register: this represent
927 // a pool of unimplemented registers whose access can throw
928 // either UNDEFINED or hypervisor trap exception.
929 MISCREG_IMPDEF_UNIMPL,
931 // RAS extension (unimplemented)
936 MISCREG_ERXSTATUS_EL1,
938 MISCREG_ERXMISC0_EL1,
939 MISCREG_ERXMISC1_EL1,
947 // Total number of Misc Registers: Physical + Dummy
953 MISCREG_UNVERIFIABLE, // Does the value change on every read (e.g. a
954 // arch generic counter)
955 MISCREG_WARN_NOT_FAIL, // If MISCREG_IMPLEMENTED is deasserted, it
956 // tells whether the instruction should raise a
958 MISCREG_MUTEX, // True if the register corresponds to a pair of
959 // mutually exclusive registers
960 MISCREG_BANKED, // True if the register is banked between the two
961 // security states, and this is the parent node of the
962 // two banked registers
963 MISCREG_BANKED64, // True if the register is banked between the two
964 // security states, and this is the parent node of
965 // the two banked registers. Used in AA64 only.
966 MISCREG_BANKED_CHILD, // The entry is one of the child registers that
967 // forms a banked set of regs (along with the
970 // Access permissions
976 // Privileged modes other than hypervisor or monitor
984 // Hypervisor mode, HCR_EL2.E2H == 1
987 // Monitor mode, SCR.NS == 0
990 // Monitor mode, SCR.NS == 1
993 // Monitor mode, HCR_EL2.E2H == 1
1000 extern std::bitset<NUM_MISCREG_INFOS> miscRegInfo[NUM_MISCREGS];
1002 // Decodes 32-bit CP14 registers accessible through MCR/MRC instructions
1003 MiscRegIndex decodeCP14Reg(unsigned crn, unsigned opc1,
1004 unsigned crm, unsigned opc2);
1005 MiscRegIndex decodeAArch64SysReg(unsigned op0, unsigned op1,
1006 unsigned crn, unsigned crm,
1008 // Whether a particular AArch64 system register is -always- read only.
1009 bool aarch64SysRegReadOnly(MiscRegIndex miscReg);
1011 // Decodes 32-bit CP15 registers accessible through MCR/MRC instructions
1012 MiscRegIndex decodeCP15Reg(unsigned crn, unsigned opc1,
1013 unsigned crm, unsigned opc2);
1015 // Decodes 64-bit CP15 registers accessible through MCRR/MRRC instructions
1016 MiscRegIndex decodeCP15Reg64(unsigned crm, unsigned opc1);
1019 const char * const miscRegName[] = {
1049 "pmxevtyper_pmccfiltr",
1053 // AArch32 CP14 registers
1105 // AArch32 CP15 registers
1348 // AArch64 registers (Op0=2)
1386 "dbgauthstatus_el1",
1390 // AArch64 registers (Op0=1,3)
1527 "tlbi_ipas2e1is_xt",
1528 "tlbi_ipas2le1is_xt",
1533 "tlbi_vmalls12e1is",
1648 // GICv3, CPU interface
1689 "icc_igrpen1_el1_ns",
1690 "icc_igrpen1_el1_s",
1696 // GICv3, CPU interface, virtualization
1768 "icv_igrpen1_el1_ns",
1769 "icv_igrpen1_el1_s",
1896 static_assert(sizeof(miscRegName) / sizeof(*miscRegName) == NUM_MISCREGS,
1897 "The miscRegName array and NUM_MISCREGS are inconsistent.");
1899 // This mask selects bits of the CPSR that actually go in the CondCodes
1900 // integer register to allow renaming.
1901 static const uint32_t CondCodesMask = 0xF00F0000;
1902 static const uint32_t CpsrMaskQ = 0x08000000;
1904 // APSR (Application Program Status Register Mask). It is the user level
1905 // alias for the CPSR. The APSR is a subset of the CPSR. Although
1906 // bits[15:0] are UNKNOWN on reads, it is permitted that, on a read of
1908 // Bit[9] returns the value of CPSR.E.
1909 // Bits[8:6] return the value of CPSR.{A,I, F}, the mask bits.
1910 static const uint32_t ApsrMask = CpsrMaskQ | CondCodesMask | 0x000001D0;
1912 // CPSR (Current Program Status Register Mask).
1913 static const uint32_t CpsrMask = ApsrMask | 0x00F003DF;
1915 // This mask selects bits of the FPSCR that actually go in the FpCondCodes
1916 // integer register to allow renaming.
1917 static const uint32_t FpCondCodesMask = 0xF0000000;
1918 // This mask selects the cumulative FP exception flags of the FPSCR.
1919 static const uint32_t FpscrExcMask = 0x0000009F;
1920 // This mask selects the cumulative saturation flag of the FPSCR.
1921 static const uint32_t FpscrQcMask = 0x08000000;
1924 * Check for permission to read coprocessor registers.
1926 * Checks whether an instruction at the current program mode has
1927 * permissions to read the coprocessor registers. This function
1928 * returns whether the check is undefined and if not whether the
1929 * read access is permitted.
1931 * @param the misc reg indicating the coprocessor
1934 * @return a tuple of booleans: can_read, undefined
1936 std::tuple<bool, bool> canReadCoprocReg(MiscRegIndex reg, SCR scr,
1940 * Check for permission to write coprocessor registers.
1942 * Checks whether an instruction at the current program mode has
1943 * permissions to write the coprocessor registers. This function
1944 * returns whether the check is undefined and if not whether the
1945 * write access is permitted.
1947 * @param the misc reg indicating the coprocessor
1950 * @return a tuple of booleans: can_write, undefined
1952 std::tuple<bool, bool> canWriteCoprocReg(MiscRegIndex reg, SCR scr,
1955 // Checks read access permissions to AArch64 system registers
1956 bool canReadAArch64SysReg(MiscRegIndex reg, HCR hcr, SCR scr, CPSR cpsr,
1959 // Checks write access permissions to AArch64 system registers
1960 bool canWriteAArch64SysReg(MiscRegIndex reg, HCR hcr, SCR scr, CPSR cpsr,
1963 // Uses just the scr.ns bit to pre flatten the misc regs. This is useful
1964 // for MCR/MRC instructions
1966 snsBankedIndex(MiscRegIndex reg, ThreadContext *tc);
1968 // Flattens a misc reg index using the specified security state. This is
1969 // used for opperations (eg address translations) where the security
1970 // state of the register access may differ from the current state of the
1973 snsBankedIndex(MiscRegIndex reg, ThreadContext *tc, bool ns);
1976 snsBankedIndex64(MiscRegIndex reg, ThreadContext *tc);
1978 // Takes a misc reg index and returns the root reg if its one of a set of
1981 preUnflattenMiscReg();
1984 unflattenMiscReg(int reg);
1988 #endif // __ARCH_ARM_MISCREGS_HH__