registers.hh revision 14238
111723Sar4jc@virginia.edu/*
211723Sar4jc@virginia.edu * Copyright (c) 2013 ARM Limited
311723Sar4jc@virginia.edu * Copyright (c) 2014-2015 Sven Karlsson
414177Sliu.ad2039@gmail.com * Copyright (c) 2019 Yifei Liu
511723Sar4jc@virginia.edu * All rights reserved
611723Sar4jc@virginia.edu *
711723Sar4jc@virginia.edu * The license below extends only to copyright in the software and shall
811723Sar4jc@virginia.edu * not be construed as granting a license to any other intellectual
911723Sar4jc@virginia.edu * property including but not limited to intellectual property relating
1011723Sar4jc@virginia.edu * to a hardware implementation of the functionality of the software
1111723Sar4jc@virginia.edu * licensed hereunder.  You may use the software subject to the license
1211723Sar4jc@virginia.edu * terms below provided that you ensure that this notice is replicated
1311723Sar4jc@virginia.edu * unmodified and in its entirety in all distributions of the software,
1411723Sar4jc@virginia.edu * modified or unmodified, in source code or in binary form.
1511723Sar4jc@virginia.edu *
1611723Sar4jc@virginia.edu * Copyright (c) 2016 RISC-V Foundation
1711723Sar4jc@virginia.edu * Copyright (c) 2016 The University of Virginia
1811723Sar4jc@virginia.edu * All rights reserved.
1911723Sar4jc@virginia.edu *
2011723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
2111723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are
2211723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright
2311723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer;
2411723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright
2511723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the
2611723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution;
2711723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its
2811723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from
2911723Sar4jc@virginia.edu * this software without specific prior written permission.
3011723Sar4jc@virginia.edu *
3111723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3211723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3311723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3411723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3511723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3611723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3711723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3811723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3911723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4011723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4111723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4211723Sar4jc@virginia.edu *
4311723Sar4jc@virginia.edu * Authors: Andreas Hansson
4411723Sar4jc@virginia.edu *          Sven Karlsson
4511723Sar4jc@virginia.edu *          Alec Roelke
4614177Sliu.ad2039@gmail.com *          Yifei Liu
4714177Sliu.ad2039@gmail.com *          Lin Cheng
4814177Sliu.ad2039@gmail.com *          Xihao Chen
4914177Sliu.ad2039@gmail.com *          Cheng Tan
5011723Sar4jc@virginia.edu */
5111723Sar4jc@virginia.edu
5211723Sar4jc@virginia.edu#ifndef __ARCH_RISCV_REGISTERS_HH__
5311723Sar4jc@virginia.edu#define __ARCH_RISCV_REGISTERS_HH__
5411723Sar4jc@virginia.edu
5511723Sar4jc@virginia.edu#include <map>
5611723Sar4jc@virginia.edu#include <string>
5712119Sar4jc@virginia.edu#include <vector>
5811723Sar4jc@virginia.edu
5912104Snathanael.premillieu@arm.com#include "arch/generic/types.hh"
6013610Sgiacomo.gabrielli@arm.com#include "arch/generic/vec_pred_reg.hh"
6112109SRekai.GonzalezAlberquilla@arm.com#include "arch/generic/vec_reg.hh"
6211911SBrandon.Potter@amd.com#include "arch/isa_traits.hh"
6311723Sar4jc@virginia.edu#include "arch/riscv/generated/max_inst_regs.hh"
6411723Sar4jc@virginia.edu#include "base/types.hh"
6511723Sar4jc@virginia.edu
6611723Sar4jc@virginia.edunamespace RiscvISA {
6711723Sar4jc@virginia.edu
6811723Sar4jc@virginia.eduusing RiscvISAInst::MaxInstSrcRegs;
6911723Sar4jc@virginia.eduusing RiscvISAInst::MaxInstDestRegs;
7011723Sar4jc@virginia.educonst int MaxMiscDestRegs = 1;
7111723Sar4jc@virginia.edu
7213610Sgiacomo.gabrielli@arm.com// Not applicable to RISC-V
7313610Sgiacomo.gabrielli@arm.comusing VecElem = ::DummyVecElem;
7413610Sgiacomo.gabrielli@arm.comusing VecReg = ::DummyVecReg;
7513610Sgiacomo.gabrielli@arm.comusing ConstVecReg = ::DummyConstVecReg;
7613610Sgiacomo.gabrielli@arm.comusing VecRegContainer = ::DummyVecRegContainer;
7713610Sgiacomo.gabrielli@arm.comconstexpr unsigned NumVecElemPerVecReg = ::DummyNumVecElemPerVecReg;
7813610Sgiacomo.gabrielli@arm.comconstexpr size_t VecRegSizeBytes = ::DummyVecRegSizeBytes;
7913610Sgiacomo.gabrielli@arm.com
8013610Sgiacomo.gabrielli@arm.com// Not applicable to RISC-V
8113610Sgiacomo.gabrielli@arm.comusing VecPredReg = ::DummyVecPredReg;
8213610Sgiacomo.gabrielli@arm.comusing ConstVecPredReg = ::DummyConstVecPredReg;
8313610Sgiacomo.gabrielli@arm.comusing VecPredRegContainer = ::DummyVecPredRegContainer;
8413610Sgiacomo.gabrielli@arm.comconstexpr size_t VecPredRegSizeBits = ::DummyVecPredRegSizeBits;
8513610Sgiacomo.gabrielli@arm.comconstexpr bool VecPredRegHasPackedRepr = ::DummyVecPredRegHasPackedRepr;
8612109SRekai.GonzalezAlberquilla@arm.com
8711723Sar4jc@virginia.educonst int NumIntArchRegs = 32;
8811726Sar4jc@virginia.educonst int NumMicroIntRegs = 1;
8911726Sar4jc@virginia.educonst int NumIntRegs = NumIntArchRegs + NumMicroIntRegs;
9011725Sar4jc@virginia.educonst int NumFloatRegs = 32;
9113610Sgiacomo.gabrielli@arm.com
9213610Sgiacomo.gabrielli@arm.comconst unsigned NumVecRegs = 1;  // Not applicable to RISC-V
9313610Sgiacomo.gabrielli@arm.com                                // (1 to prevent warnings)
9413610Sgiacomo.gabrielli@arm.comconst int NumVecPredRegs = 1;  // Not applicable to RISC-V
9513610Sgiacomo.gabrielli@arm.com                               // (1 to prevent warnings)
9613610Sgiacomo.gabrielli@arm.com
9711723Sar4jc@virginia.educonst int NumCCRegs = 0;
9811723Sar4jc@virginia.edu
9911723Sar4jc@virginia.edu// Semantically meaningful register indices
10011723Sar4jc@virginia.educonst int ZeroReg = 0;
10111723Sar4jc@virginia.educonst int ReturnAddrReg = 1;
10211723Sar4jc@virginia.educonst int StackPointerReg = 2;
10311723Sar4jc@virginia.educonst int GlobalPointerReg = 3;
10411723Sar4jc@virginia.educonst int ThreadPointerReg = 4;
10511723Sar4jc@virginia.educonst int FramePointerReg = 8;
10612139Sar4jc@virginia.educonst int ReturnValueReg = 10;
10712119Sar4jc@virginia.educonst std::vector<int> ReturnValueRegs = {10, 11};
10812119Sar4jc@virginia.educonst std::vector<int> ArgumentRegs = {10, 11, 12, 13, 14, 15, 16, 17};
10911726Sar4jc@virginia.educonst int AMOTempReg = 32;
11011723Sar4jc@virginia.edu
11112413Sar4jc@virginia.educonst int SyscallPseudoReturnReg = 10;
11212413Sar4jc@virginia.educonst std::vector<int> SyscallArgumentRegs = {10, 11, 12, 13, 14, 15, 16};
11312413Sar4jc@virginia.educonst int SyscallNumReg = 17;
11412413Sar4jc@virginia.edu
11512119Sar4jc@virginia.educonst std::vector<std::string> IntRegNames = {
11612119Sar4jc@virginia.edu    "zero", "ra", "sp", "gp",
11711723Sar4jc@virginia.edu    "tp", "t0", "t1", "t2",
11811723Sar4jc@virginia.edu    "s0", "s1", "a0", "a1",
11911723Sar4jc@virginia.edu    "a2", "a3", "a4", "a5",
12011723Sar4jc@virginia.edu    "a6", "a7", "s2", "s3",
12111723Sar4jc@virginia.edu    "s4", "s5", "s6", "s7",
12211723Sar4jc@virginia.edu    "s8", "s9", "s10", "s11",
12312119Sar4jc@virginia.edu    "t3", "t4", "t5", "t6"
12412119Sar4jc@virginia.edu};
12512119Sar4jc@virginia.educonst std::vector<std::string> FloatRegNames = {
12612119Sar4jc@virginia.edu    "ft0", "ft1", "ft2", "ft3",
12712119Sar4jc@virginia.edu    "ft4", "ft5", "ft6", "ft7",
12812119Sar4jc@virginia.edu    "fs0", "fs1", "fa0", "fa1",
12912119Sar4jc@virginia.edu    "fa2", "fa3", "fa4", "fa5",
13012119Sar4jc@virginia.edu    "fa6", "fa7", "fs2", "fs3",
13112119Sar4jc@virginia.edu    "fs4", "fs5", "fs6", "fs7",
13212119Sar4jc@virginia.edu    "fs8", "fs9", "fs10", "fs11",
13312119Sar4jc@virginia.edu    "ft8", "ft9", "ft10", "ft11"
13412119Sar4jc@virginia.edu};
13511723Sar4jc@virginia.edu
13611723Sar4jc@virginia.eduenum MiscRegIndex {
13712695Sar4jc@virginia.edu    MISCREG_PRV = 0,
13812695Sar4jc@virginia.edu    MISCREG_ISA,
13912695Sar4jc@virginia.edu    MISCREG_VENDORID,
14012695Sar4jc@virginia.edu    MISCREG_ARCHID,
14112695Sar4jc@virginia.edu    MISCREG_IMPID,
14212695Sar4jc@virginia.edu    MISCREG_HARTID,
14312695Sar4jc@virginia.edu    MISCREG_STATUS,
14412695Sar4jc@virginia.edu    MISCREG_IP,
14512695Sar4jc@virginia.edu    MISCREG_IE,
14612695Sar4jc@virginia.edu    MISCREG_CYCLE,
14712695Sar4jc@virginia.edu    MISCREG_TIME,
14812695Sar4jc@virginia.edu    MISCREG_INSTRET,
14912695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER03,
15012695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER04,
15112695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER05,
15212695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER06,
15312695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER07,
15412695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER08,
15512695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER09,
15612695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER10,
15712695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER11,
15812695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER12,
15912695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER13,
16012695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER14,
16112695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER15,
16212695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER16,
16312695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER17,
16412695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER18,
16512695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER19,
16612695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER20,
16712695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER21,
16812695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER22,
16912695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER23,
17012695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER24,
17112695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER25,
17212695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER26,
17312695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER27,
17412695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER28,
17512695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER29,
17612695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER30,
17712695Sar4jc@virginia.edu    MISCREG_HPMCOUNTER31,
17812695Sar4jc@virginia.edu    MISCREG_HPMEVENT03,
17912695Sar4jc@virginia.edu    MISCREG_HPMEVENT04,
18012695Sar4jc@virginia.edu    MISCREG_HPMEVENT05,
18112695Sar4jc@virginia.edu    MISCREG_HPMEVENT06,
18212695Sar4jc@virginia.edu    MISCREG_HPMEVENT07,
18312695Sar4jc@virginia.edu    MISCREG_HPMEVENT08,
18412695Sar4jc@virginia.edu    MISCREG_HPMEVENT09,
18512695Sar4jc@virginia.edu    MISCREG_HPMEVENT10,
18612695Sar4jc@virginia.edu    MISCREG_HPMEVENT11,
18712695Sar4jc@virginia.edu    MISCREG_HPMEVENT12,
18812695Sar4jc@virginia.edu    MISCREG_HPMEVENT13,
18912695Sar4jc@virginia.edu    MISCREG_HPMEVENT14,
19012695Sar4jc@virginia.edu    MISCREG_HPMEVENT15,
19112695Sar4jc@virginia.edu    MISCREG_HPMEVENT16,
19212695Sar4jc@virginia.edu    MISCREG_HPMEVENT17,
19312695Sar4jc@virginia.edu    MISCREG_HPMEVENT18,
19412695Sar4jc@virginia.edu    MISCREG_HPMEVENT19,
19512695Sar4jc@virginia.edu    MISCREG_HPMEVENT20,
19612695Sar4jc@virginia.edu    MISCREG_HPMEVENT21,
19712695Sar4jc@virginia.edu    MISCREG_HPMEVENT22,
19812695Sar4jc@virginia.edu    MISCREG_HPMEVENT23,
19912695Sar4jc@virginia.edu    MISCREG_HPMEVENT24,
20012695Sar4jc@virginia.edu    MISCREG_HPMEVENT25,
20112695Sar4jc@virginia.edu    MISCREG_HPMEVENT26,
20212695Sar4jc@virginia.edu    MISCREG_HPMEVENT27,
20312695Sar4jc@virginia.edu    MISCREG_HPMEVENT28,
20412695Sar4jc@virginia.edu    MISCREG_HPMEVENT29,
20512695Sar4jc@virginia.edu    MISCREG_HPMEVENT30,
20612695Sar4jc@virginia.edu    MISCREG_HPMEVENT31,
20712695Sar4jc@virginia.edu    MISCREG_TSELECT,
20812695Sar4jc@virginia.edu    MISCREG_TDATA1,
20912695Sar4jc@virginia.edu    MISCREG_TDATA2,
21012695Sar4jc@virginia.edu    MISCREG_TDATA3,
21112695Sar4jc@virginia.edu    MISCREG_DCSR,
21212695Sar4jc@virginia.edu    MISCREG_DPC,
21312695Sar4jc@virginia.edu    MISCREG_DSCRATCH,
21411723Sar4jc@virginia.edu
21512695Sar4jc@virginia.edu    MISCREG_MEDELEG,
21612695Sar4jc@virginia.edu    MISCREG_MIDELEG,
21712695Sar4jc@virginia.edu    MISCREG_MTVEC,
21812695Sar4jc@virginia.edu    MISCREG_MCOUNTEREN,
21912695Sar4jc@virginia.edu    MISCREG_MSCRATCH,
22012695Sar4jc@virginia.edu    MISCREG_MEPC,
22112695Sar4jc@virginia.edu    MISCREG_MCAUSE,
22212695Sar4jc@virginia.edu    MISCREG_MTVAL,
22312695Sar4jc@virginia.edu    MISCREG_PMPCFG0,
22412695Sar4jc@virginia.edu    // pmpcfg1 rv32 only
22512695Sar4jc@virginia.edu    MISCREG_PMPCFG2,
22612695Sar4jc@virginia.edu    // pmpcfg3 rv32 only
22712695Sar4jc@virginia.edu    MISCREG_PMPADDR00,
22812695Sar4jc@virginia.edu    MISCREG_PMPADDR01,
22912695Sar4jc@virginia.edu    MISCREG_PMPADDR02,
23012695Sar4jc@virginia.edu    MISCREG_PMPADDR03,
23112695Sar4jc@virginia.edu    MISCREG_PMPADDR04,
23212695Sar4jc@virginia.edu    MISCREG_PMPADDR05,
23312695Sar4jc@virginia.edu    MISCREG_PMPADDR06,
23412695Sar4jc@virginia.edu    MISCREG_PMPADDR07,
23512695Sar4jc@virginia.edu    MISCREG_PMPADDR08,
23612695Sar4jc@virginia.edu    MISCREG_PMPADDR09,
23712695Sar4jc@virginia.edu    MISCREG_PMPADDR10,
23812695Sar4jc@virginia.edu    MISCREG_PMPADDR11,
23912695Sar4jc@virginia.edu    MISCREG_PMPADDR12,
24012695Sar4jc@virginia.edu    MISCREG_PMPADDR13,
24112695Sar4jc@virginia.edu    MISCREG_PMPADDR14,
24212695Sar4jc@virginia.edu    MISCREG_PMPADDR15,
24311723Sar4jc@virginia.edu
24412695Sar4jc@virginia.edu    MISCREG_SEDELEG,
24512695Sar4jc@virginia.edu    MISCREG_SIDELEG,
24612695Sar4jc@virginia.edu    MISCREG_STVEC,
24712695Sar4jc@virginia.edu    MISCREG_SCOUNTEREN,
24812695Sar4jc@virginia.edu    MISCREG_SSCRATCH,
24912695Sar4jc@virginia.edu    MISCREG_SEPC,
25012695Sar4jc@virginia.edu    MISCREG_SCAUSE,
25112695Sar4jc@virginia.edu    MISCREG_STVAL,
25212695Sar4jc@virginia.edu    MISCREG_SATP,
25311723Sar4jc@virginia.edu
25412695Sar4jc@virginia.edu    MISCREG_UTVEC,
25512695Sar4jc@virginia.edu    MISCREG_USCRATCH,
25612695Sar4jc@virginia.edu    MISCREG_UEPC,
25712695Sar4jc@virginia.edu    MISCREG_UCAUSE,
25812695Sar4jc@virginia.edu    MISCREG_UTVAL,
25912695Sar4jc@virginia.edu    MISCREG_FFLAGS,
26012695Sar4jc@virginia.edu    MISCREG_FRM,
26111963Sar4jc@virginia.edu
26212695Sar4jc@virginia.edu    NUM_MISCREGS
26312695Sar4jc@virginia.edu};
26412695Sar4jc@virginia.educonst int NumMiscRegs = NUM_MISCREGS;
26512695Sar4jc@virginia.edu
26612695Sar4jc@virginia.eduenum CSRIndex {
26712695Sar4jc@virginia.edu    CSR_USTATUS = 0x000,
26812695Sar4jc@virginia.edu    CSR_UIE = 0x004,
26912695Sar4jc@virginia.edu    CSR_UTVEC = 0x005,
27012695Sar4jc@virginia.edu    CSR_USCRATCH = 0x040,
27112695Sar4jc@virginia.edu    CSR_UEPC = 0x041,
27212695Sar4jc@virginia.edu    CSR_UCAUSE = 0x042,
27312695Sar4jc@virginia.edu    CSR_UTVAL = 0x043,
27412695Sar4jc@virginia.edu    CSR_UIP = 0x044,
27512695Sar4jc@virginia.edu    CSR_FFLAGS = 0x001,
27612695Sar4jc@virginia.edu    CSR_FRM = 0x002,
27712695Sar4jc@virginia.edu    CSR_FCSR = 0x003,
27812695Sar4jc@virginia.edu    CSR_CYCLE = 0xC00,
27912695Sar4jc@virginia.edu    CSR_TIME = 0xC01,
28012695Sar4jc@virginia.edu    CSR_INSTRET = 0xC02,
28112695Sar4jc@virginia.edu    CSR_HPMCOUNTER03 = 0xC03,
28212695Sar4jc@virginia.edu    CSR_HPMCOUNTER04 = 0xC04,
28312695Sar4jc@virginia.edu    CSR_HPMCOUNTER05 = 0xC05,
28412695Sar4jc@virginia.edu    CSR_HPMCOUNTER06 = 0xC06,
28512695Sar4jc@virginia.edu    CSR_HPMCOUNTER07 = 0xC07,
28612695Sar4jc@virginia.edu    CSR_HPMCOUNTER08 = 0xC08,
28712695Sar4jc@virginia.edu    CSR_HPMCOUNTER09 = 0xC09,
28812695Sar4jc@virginia.edu    CSR_HPMCOUNTER10 = 0xC0A,
28912695Sar4jc@virginia.edu    CSR_HPMCOUNTER11 = 0xC0B,
29012695Sar4jc@virginia.edu    CSR_HPMCOUNTER12 = 0xC0C,
29112695Sar4jc@virginia.edu    CSR_HPMCOUNTER13 = 0xC0D,
29212695Sar4jc@virginia.edu    CSR_HPMCOUNTER14 = 0xC0E,
29312695Sar4jc@virginia.edu    CSR_HPMCOUNTER15 = 0xC0F,
29412695Sar4jc@virginia.edu    CSR_HPMCOUNTER16 = 0xC10,
29512695Sar4jc@virginia.edu    CSR_HPMCOUNTER17 = 0xC11,
29612695Sar4jc@virginia.edu    CSR_HPMCOUNTER18 = 0xC12,
29712695Sar4jc@virginia.edu    CSR_HPMCOUNTER19 = 0xC13,
29812695Sar4jc@virginia.edu    CSR_HPMCOUNTER20 = 0xC14,
29912695Sar4jc@virginia.edu    CSR_HPMCOUNTER21 = 0xC15,
30012695Sar4jc@virginia.edu    CSR_HPMCOUNTER22 = 0xC16,
30112695Sar4jc@virginia.edu    CSR_HPMCOUNTER23 = 0xC17,
30212695Sar4jc@virginia.edu    CSR_HPMCOUNTER24 = 0xC18,
30312695Sar4jc@virginia.edu    CSR_HPMCOUNTER25 = 0xC19,
30412695Sar4jc@virginia.edu    CSR_HPMCOUNTER26 = 0xC1A,
30512695Sar4jc@virginia.edu    CSR_HPMCOUNTER27 = 0xC1B,
30612695Sar4jc@virginia.edu    CSR_HPMCOUNTER28 = 0xC1C,
30712695Sar4jc@virginia.edu    CSR_HPMCOUNTER29 = 0xC1D,
30812695Sar4jc@virginia.edu    CSR_HPMCOUNTER30 = 0xC1E,
30912695Sar4jc@virginia.edu    CSR_HPMCOUNTER31 = 0xC1F,
31012695Sar4jc@virginia.edu    // HPMCOUNTERH rv32 only
31112695Sar4jc@virginia.edu
31212695Sar4jc@virginia.edu    CSR_SSTATUS = 0x100,
31312695Sar4jc@virginia.edu    CSR_SEDELEG = 0x102,
31412695Sar4jc@virginia.edu    CSR_SIDELEG = 0x103,
31512695Sar4jc@virginia.edu    CSR_SIE = 0x104,
31612695Sar4jc@virginia.edu    CSR_STVEC = 0x105,
31714177Sliu.ad2039@gmail.com    CSR_SCOUNTEREN = 0x106,
31812695Sar4jc@virginia.edu    CSR_SSCRATCH = 0x140,
31912695Sar4jc@virginia.edu    CSR_SEPC = 0x141,
32012695Sar4jc@virginia.edu    CSR_SCAUSE = 0x142,
32112695Sar4jc@virginia.edu    CSR_STVAL = 0x143,
32212695Sar4jc@virginia.edu    CSR_SIP = 0x144,
32312695Sar4jc@virginia.edu    CSR_SATP = 0x180,
32412695Sar4jc@virginia.edu
32512695Sar4jc@virginia.edu    CSR_MVENDORID = 0xF11,
32612695Sar4jc@virginia.edu    CSR_MARCHID = 0xF12,
32712695Sar4jc@virginia.edu    CSR_MIMPID = 0xF13,
32812695Sar4jc@virginia.edu    CSR_MHARTID = 0xF14,
32912695Sar4jc@virginia.edu    CSR_MSTATUS = 0x300,
33012695Sar4jc@virginia.edu    CSR_MISA = 0x301,
33112695Sar4jc@virginia.edu    CSR_MEDELEG = 0x302,
33212695Sar4jc@virginia.edu    CSR_MIDELEG = 0x303,
33312695Sar4jc@virginia.edu    CSR_MIE = 0x304,
33412695Sar4jc@virginia.edu    CSR_MTVEC = 0x305,
33514177Sliu.ad2039@gmail.com    CSR_MCOUNTEREN = 0x306,
33612695Sar4jc@virginia.edu    CSR_MSCRATCH = 0x340,
33712695Sar4jc@virginia.edu    CSR_MEPC = 0x341,
33812695Sar4jc@virginia.edu    CSR_MCAUSE = 0x342,
33912695Sar4jc@virginia.edu    CSR_MTVAL = 0x343,
34012695Sar4jc@virginia.edu    CSR_MIP = 0x344,
34112695Sar4jc@virginia.edu    CSR_PMPCFG0 = 0x3A0,
34212695Sar4jc@virginia.edu    // pmpcfg1 rv32 only
34312695Sar4jc@virginia.edu    CSR_PMPCFG2 = 0x3A2,
34412695Sar4jc@virginia.edu    // pmpcfg3 rv32 only
34512695Sar4jc@virginia.edu    CSR_PMPADDR00 = 0x3B0,
34612695Sar4jc@virginia.edu    CSR_PMPADDR01 = 0x3B1,
34712695Sar4jc@virginia.edu    CSR_PMPADDR02 = 0x3B2,
34812695Sar4jc@virginia.edu    CSR_PMPADDR03 = 0x3B3,
34912695Sar4jc@virginia.edu    CSR_PMPADDR04 = 0x3B4,
35012695Sar4jc@virginia.edu    CSR_PMPADDR05 = 0x3B5,
35112695Sar4jc@virginia.edu    CSR_PMPADDR06 = 0x3B6,
35212695Sar4jc@virginia.edu    CSR_PMPADDR07 = 0x3B7,
35312695Sar4jc@virginia.edu    CSR_PMPADDR08 = 0x3B8,
35412695Sar4jc@virginia.edu    CSR_PMPADDR09 = 0x3B9,
35512695Sar4jc@virginia.edu    CSR_PMPADDR10 = 0x3BA,
35612695Sar4jc@virginia.edu    CSR_PMPADDR11 = 0x3BB,
35712695Sar4jc@virginia.edu    CSR_PMPADDR12 = 0x3BC,
35812695Sar4jc@virginia.edu    CSR_PMPADDR13 = 0x3BD,
35912695Sar4jc@virginia.edu    CSR_PMPADDR14 = 0x3BE,
36012695Sar4jc@virginia.edu    CSR_PMPADDR15 = 0x3BF,
36112695Sar4jc@virginia.edu    CSR_MCYCLE = 0xB00,
36212695Sar4jc@virginia.edu    CSR_MINSTRET = 0xB02,
36312695Sar4jc@virginia.edu    CSR_MHPMCOUNTER03 = 0xC03,
36412695Sar4jc@virginia.edu    CSR_MHPMCOUNTER04 = 0xC04,
36512695Sar4jc@virginia.edu    CSR_MHPMCOUNTER05 = 0xC05,
36612695Sar4jc@virginia.edu    CSR_MHPMCOUNTER06 = 0xC06,
36712695Sar4jc@virginia.edu    CSR_MHPMCOUNTER07 = 0xC07,
36812695Sar4jc@virginia.edu    CSR_MHPMCOUNTER08 = 0xC08,
36912695Sar4jc@virginia.edu    CSR_MHPMCOUNTER09 = 0xC09,
37012695Sar4jc@virginia.edu    CSR_MHPMCOUNTER10 = 0xC0A,
37112695Sar4jc@virginia.edu    CSR_MHPMCOUNTER11 = 0xC0B,
37212695Sar4jc@virginia.edu    CSR_MHPMCOUNTER12 = 0xC0C,
37312695Sar4jc@virginia.edu    CSR_MHPMCOUNTER13 = 0xC0D,
37412695Sar4jc@virginia.edu    CSR_MHPMCOUNTER14 = 0xC0E,
37512695Sar4jc@virginia.edu    CSR_MHPMCOUNTER15 = 0xC0F,
37612695Sar4jc@virginia.edu    CSR_MHPMCOUNTER16 = 0xC10,
37712695Sar4jc@virginia.edu    CSR_MHPMCOUNTER17 = 0xC11,
37812695Sar4jc@virginia.edu    CSR_MHPMCOUNTER18 = 0xC12,
37912695Sar4jc@virginia.edu    CSR_MHPMCOUNTER19 = 0xC13,
38012695Sar4jc@virginia.edu    CSR_MHPMCOUNTER20 = 0xC14,
38112695Sar4jc@virginia.edu    CSR_MHPMCOUNTER21 = 0xC15,
38212695Sar4jc@virginia.edu    CSR_MHPMCOUNTER22 = 0xC16,
38312695Sar4jc@virginia.edu    CSR_MHPMCOUNTER23 = 0xC17,
38412695Sar4jc@virginia.edu    CSR_MHPMCOUNTER24 = 0xC18,
38512695Sar4jc@virginia.edu    CSR_MHPMCOUNTER25 = 0xC19,
38612695Sar4jc@virginia.edu    CSR_MHPMCOUNTER26 = 0xC1A,
38712695Sar4jc@virginia.edu    CSR_MHPMCOUNTER27 = 0xC1B,
38812695Sar4jc@virginia.edu    CSR_MHPMCOUNTER28 = 0xC1C,
38912695Sar4jc@virginia.edu    CSR_MHPMCOUNTER29 = 0xC1D,
39012695Sar4jc@virginia.edu    CSR_MHPMCOUNTER30 = 0xC1E,
39112695Sar4jc@virginia.edu    CSR_MHPMCOUNTER31 = 0xC1F,
39212695Sar4jc@virginia.edu    // MHPMCOUNTERH rv32 only
39312695Sar4jc@virginia.edu    CSR_MHPMEVENT03 = 0x323,
39412695Sar4jc@virginia.edu    CSR_MHPMEVENT04 = 0x324,
39512695Sar4jc@virginia.edu    CSR_MHPMEVENT05 = 0x325,
39612695Sar4jc@virginia.edu    CSR_MHPMEVENT06 = 0x326,
39712695Sar4jc@virginia.edu    CSR_MHPMEVENT07 = 0x327,
39812695Sar4jc@virginia.edu    CSR_MHPMEVENT08 = 0x328,
39912695Sar4jc@virginia.edu    CSR_MHPMEVENT09 = 0x329,
40012695Sar4jc@virginia.edu    CSR_MHPMEVENT10 = 0x32A,
40112695Sar4jc@virginia.edu    CSR_MHPMEVENT11 = 0x32B,
40212695Sar4jc@virginia.edu    CSR_MHPMEVENT12 = 0x32C,
40312695Sar4jc@virginia.edu    CSR_MHPMEVENT13 = 0x32D,
40412695Sar4jc@virginia.edu    CSR_MHPMEVENT14 = 0x32E,
40512695Sar4jc@virginia.edu    CSR_MHPMEVENT15 = 0x32F,
40612695Sar4jc@virginia.edu    CSR_MHPMEVENT16 = 0x330,
40712695Sar4jc@virginia.edu    CSR_MHPMEVENT17 = 0x331,
40812695Sar4jc@virginia.edu    CSR_MHPMEVENT18 = 0x332,
40912695Sar4jc@virginia.edu    CSR_MHPMEVENT19 = 0x333,
41012695Sar4jc@virginia.edu    CSR_MHPMEVENT20 = 0x334,
41112695Sar4jc@virginia.edu    CSR_MHPMEVENT21 = 0x335,
41212695Sar4jc@virginia.edu    CSR_MHPMEVENT22 = 0x336,
41312695Sar4jc@virginia.edu    CSR_MHPMEVENT23 = 0x337,
41412695Sar4jc@virginia.edu    CSR_MHPMEVENT24 = 0x338,
41512695Sar4jc@virginia.edu    CSR_MHPMEVENT25 = 0x339,
41612695Sar4jc@virginia.edu    CSR_MHPMEVENT26 = 0x33A,
41712695Sar4jc@virginia.edu    CSR_MHPMEVENT27 = 0x33B,
41812695Sar4jc@virginia.edu    CSR_MHPMEVENT28 = 0x33C,
41912695Sar4jc@virginia.edu    CSR_MHPMEVENT29 = 0x33D,
42012695Sar4jc@virginia.edu    CSR_MHPMEVENT30 = 0x33E,
42112695Sar4jc@virginia.edu    CSR_MHPMEVENT31 = 0x33F,
42212695Sar4jc@virginia.edu
42312695Sar4jc@virginia.edu    CSR_TSELECT = 0x7A0,
42412695Sar4jc@virginia.edu    CSR_TDATA1 = 0x7A1,
42512695Sar4jc@virginia.edu    CSR_TDATA2 = 0x7A2,
42612695Sar4jc@virginia.edu    CSR_TDATA3 = 0x7A3,
42712695Sar4jc@virginia.edu    CSR_DCSR = 0x7B0,
42812695Sar4jc@virginia.edu    CSR_DPC = 0x7B1,
42912695Sar4jc@virginia.edu    CSR_DSCRATCH = 0x7B2
43011723Sar4jc@virginia.edu};
43111723Sar4jc@virginia.edu
43212695Sar4jc@virginia.edustruct CSRMetadata
43312695Sar4jc@virginia.edu{
43412695Sar4jc@virginia.edu    const std::string name;
43512695Sar4jc@virginia.edu    const int physIndex;
43612695Sar4jc@virginia.edu};
43712119Sar4jc@virginia.edu
43812695Sar4jc@virginia.educonst std::map<int, CSRMetadata> CSRData = {
43912695Sar4jc@virginia.edu    {CSR_USTATUS, {"ustatus", MISCREG_STATUS}},
44012695Sar4jc@virginia.edu    {CSR_UIE, {"uie", MISCREG_IE}},
44112695Sar4jc@virginia.edu    {CSR_UTVEC, {"utvec", MISCREG_UTVEC}},
44212695Sar4jc@virginia.edu    {CSR_USCRATCH, {"uscratch", MISCREG_USCRATCH}},
44312695Sar4jc@virginia.edu    {CSR_UEPC, {"uepc", MISCREG_UEPC}},
44412695Sar4jc@virginia.edu    {CSR_UCAUSE, {"ucause", MISCREG_UCAUSE}},
44512695Sar4jc@virginia.edu    {CSR_UTVAL, {"utval", MISCREG_UTVAL}},
44612695Sar4jc@virginia.edu    {CSR_UIP, {"uip", MISCREG_IP}},
44712695Sar4jc@virginia.edu    {CSR_FFLAGS, {"fflags", MISCREG_FFLAGS}},
44812695Sar4jc@virginia.edu    {CSR_FRM, {"frm", MISCREG_FRM}},
44912695Sar4jc@virginia.edu    {CSR_FCSR, {"fcsr", MISCREG_FFLAGS}}, // Actually FRM << 5 | FFLAGS
45012695Sar4jc@virginia.edu    {CSR_CYCLE, {"cycle", MISCREG_CYCLE}},
45112695Sar4jc@virginia.edu    {CSR_TIME, {"time", MISCREG_TIME}},
45212695Sar4jc@virginia.edu    {CSR_INSTRET, {"instret", MISCREG_INSTRET}},
45312695Sar4jc@virginia.edu    {CSR_HPMCOUNTER03, {"hpmcounter03", MISCREG_HPMCOUNTER03}},
45412695Sar4jc@virginia.edu    {CSR_HPMCOUNTER04, {"hpmcounter04", MISCREG_HPMCOUNTER04}},
45512695Sar4jc@virginia.edu    {CSR_HPMCOUNTER05, {"hpmcounter05", MISCREG_HPMCOUNTER05}},
45612695Sar4jc@virginia.edu    {CSR_HPMCOUNTER06, {"hpmcounter06", MISCREG_HPMCOUNTER06}},
45712695Sar4jc@virginia.edu    {CSR_HPMCOUNTER07, {"hpmcounter07", MISCREG_HPMCOUNTER07}},
45812695Sar4jc@virginia.edu    {CSR_HPMCOUNTER08, {"hpmcounter08", MISCREG_HPMCOUNTER08}},
45912695Sar4jc@virginia.edu    {CSR_HPMCOUNTER09, {"hpmcounter09", MISCREG_HPMCOUNTER09}},
46012695Sar4jc@virginia.edu    {CSR_HPMCOUNTER10, {"hpmcounter10", MISCREG_HPMCOUNTER10}},
46112695Sar4jc@virginia.edu    {CSR_HPMCOUNTER11, {"hpmcounter11", MISCREG_HPMCOUNTER11}},
46212695Sar4jc@virginia.edu    {CSR_HPMCOUNTER12, {"hpmcounter12", MISCREG_HPMCOUNTER12}},
46312695Sar4jc@virginia.edu    {CSR_HPMCOUNTER13, {"hpmcounter13", MISCREG_HPMCOUNTER13}},
46412695Sar4jc@virginia.edu    {CSR_HPMCOUNTER14, {"hpmcounter14", MISCREG_HPMCOUNTER14}},
46512695Sar4jc@virginia.edu    {CSR_HPMCOUNTER15, {"hpmcounter15", MISCREG_HPMCOUNTER15}},
46612695Sar4jc@virginia.edu    {CSR_HPMCOUNTER16, {"hpmcounter16", MISCREG_HPMCOUNTER16}},
46712695Sar4jc@virginia.edu    {CSR_HPMCOUNTER17, {"hpmcounter17", MISCREG_HPMCOUNTER17}},
46812695Sar4jc@virginia.edu    {CSR_HPMCOUNTER18, {"hpmcounter18", MISCREG_HPMCOUNTER18}},
46912695Sar4jc@virginia.edu    {CSR_HPMCOUNTER19, {"hpmcounter19", MISCREG_HPMCOUNTER19}},
47012695Sar4jc@virginia.edu    {CSR_HPMCOUNTER20, {"hpmcounter20", MISCREG_HPMCOUNTER20}},
47112695Sar4jc@virginia.edu    {CSR_HPMCOUNTER21, {"hpmcounter21", MISCREG_HPMCOUNTER21}},
47212695Sar4jc@virginia.edu    {CSR_HPMCOUNTER22, {"hpmcounter22", MISCREG_HPMCOUNTER22}},
47312695Sar4jc@virginia.edu    {CSR_HPMCOUNTER23, {"hpmcounter23", MISCREG_HPMCOUNTER23}},
47412695Sar4jc@virginia.edu    {CSR_HPMCOUNTER24, {"hpmcounter24", MISCREG_HPMCOUNTER24}},
47512695Sar4jc@virginia.edu    {CSR_HPMCOUNTER25, {"hpmcounter25", MISCREG_HPMCOUNTER25}},
47612695Sar4jc@virginia.edu    {CSR_HPMCOUNTER26, {"hpmcounter26", MISCREG_HPMCOUNTER26}},
47712695Sar4jc@virginia.edu    {CSR_HPMCOUNTER27, {"hpmcounter27", MISCREG_HPMCOUNTER27}},
47812695Sar4jc@virginia.edu    {CSR_HPMCOUNTER28, {"hpmcounter28", MISCREG_HPMCOUNTER28}},
47912695Sar4jc@virginia.edu    {CSR_HPMCOUNTER29, {"hpmcounter29", MISCREG_HPMCOUNTER29}},
48012695Sar4jc@virginia.edu    {CSR_HPMCOUNTER30, {"hpmcounter30", MISCREG_HPMCOUNTER30}},
48112695Sar4jc@virginia.edu    {CSR_HPMCOUNTER31, {"hpmcounter31", MISCREG_HPMCOUNTER31}},
48212119Sar4jc@virginia.edu
48312695Sar4jc@virginia.edu    {CSR_SSTATUS, {"sstatus", MISCREG_STATUS}},
48412695Sar4jc@virginia.edu    {CSR_SEDELEG, {"sedeleg", MISCREG_SEDELEG}},
48512695Sar4jc@virginia.edu    {CSR_SIDELEG, {"sideleg", MISCREG_SIDELEG}},
48612695Sar4jc@virginia.edu    {CSR_SIE, {"sie", MISCREG_IE}},
48712695Sar4jc@virginia.edu    {CSR_STVEC, {"stvec", MISCREG_STVEC}},
48814177Sliu.ad2039@gmail.com    {CSR_SCOUNTEREN, {"scounteren", MISCREG_SCOUNTEREN}},
48912695Sar4jc@virginia.edu    {CSR_SSCRATCH, {"sscratch", MISCREG_SSCRATCH}},
49012695Sar4jc@virginia.edu    {CSR_SEPC, {"sepc", MISCREG_SEPC}},
49112695Sar4jc@virginia.edu    {CSR_SCAUSE, {"scause", MISCREG_SCAUSE}},
49212695Sar4jc@virginia.edu    {CSR_STVAL, {"stval", MISCREG_STVAL}},
49312695Sar4jc@virginia.edu    {CSR_SIP, {"sip", MISCREG_IP}},
49412695Sar4jc@virginia.edu    {CSR_SATP, {"satp", MISCREG_SATP}},
49512119Sar4jc@virginia.edu
49612695Sar4jc@virginia.edu    {CSR_MVENDORID, {"mvendorid", MISCREG_VENDORID}},
49712695Sar4jc@virginia.edu    {CSR_MARCHID, {"marchid", MISCREG_ARCHID}},
49812695Sar4jc@virginia.edu    {CSR_MIMPID, {"mimpid", MISCREG_IMPID}},
49912695Sar4jc@virginia.edu    {CSR_MHARTID, {"mhartid", MISCREG_HARTID}},
50012695Sar4jc@virginia.edu    {CSR_MSTATUS, {"mstatus", MISCREG_STATUS}},
50112695Sar4jc@virginia.edu    {CSR_MISA, {"misa", MISCREG_ISA}},
50212695Sar4jc@virginia.edu    {CSR_MEDELEG, {"medeleg", MISCREG_MEDELEG}},
50312695Sar4jc@virginia.edu    {CSR_MIDELEG, {"mideleg", MISCREG_MIDELEG}},
50412695Sar4jc@virginia.edu    {CSR_MIE, {"mie", MISCREG_IE}},
50512695Sar4jc@virginia.edu    {CSR_MTVEC, {"mtvec", MISCREG_MTVEC}},
50614177Sliu.ad2039@gmail.com    {CSR_MCOUNTEREN, {"mcounteren", MISCREG_MCOUNTEREN}},
50712695Sar4jc@virginia.edu    {CSR_MSCRATCH, {"mscratch", MISCREG_MSCRATCH}},
50812695Sar4jc@virginia.edu    {CSR_MEPC, {"mepc", MISCREG_MEPC}},
50912695Sar4jc@virginia.edu    {CSR_MCAUSE, {"mcause", MISCREG_MCAUSE}},
51012695Sar4jc@virginia.edu    {CSR_MTVAL, {"mtval", MISCREG_MTVAL}},
51112695Sar4jc@virginia.edu    {CSR_MIP, {"mip", MISCREG_IP}},
51212695Sar4jc@virginia.edu    {CSR_PMPCFG0, {"pmpcfg0", MISCREG_PMPCFG0}},
51312695Sar4jc@virginia.edu    // pmpcfg1 rv32 only
51412695Sar4jc@virginia.edu    {CSR_PMPCFG2, {"pmpcfg2", MISCREG_PMPCFG2}},
51512695Sar4jc@virginia.edu    // pmpcfg3 rv32 only
51612695Sar4jc@virginia.edu    {CSR_PMPADDR00, {"pmpaddr0", MISCREG_PMPADDR00}},
51712695Sar4jc@virginia.edu    {CSR_PMPADDR01, {"pmpaddr1", MISCREG_PMPADDR01}},
51812695Sar4jc@virginia.edu    {CSR_PMPADDR02, {"pmpaddr2", MISCREG_PMPADDR02}},
51912695Sar4jc@virginia.edu    {CSR_PMPADDR03, {"pmpaddr3", MISCREG_PMPADDR03}},
52012695Sar4jc@virginia.edu    {CSR_PMPADDR04, {"pmpaddr4", MISCREG_PMPADDR04}},
52112695Sar4jc@virginia.edu    {CSR_PMPADDR05, {"pmpaddr5", MISCREG_PMPADDR05}},
52212695Sar4jc@virginia.edu    {CSR_PMPADDR06, {"pmpaddr6", MISCREG_PMPADDR06}},
52312695Sar4jc@virginia.edu    {CSR_PMPADDR07, {"pmpaddr7", MISCREG_PMPADDR07}},
52412695Sar4jc@virginia.edu    {CSR_PMPADDR08, {"pmpaddr8", MISCREG_PMPADDR08}},
52512695Sar4jc@virginia.edu    {CSR_PMPADDR09, {"pmpaddr9", MISCREG_PMPADDR09}},
52612695Sar4jc@virginia.edu    {CSR_PMPADDR10, {"pmpaddr10", MISCREG_PMPADDR10}},
52712695Sar4jc@virginia.edu    {CSR_PMPADDR11, {"pmpaddr11", MISCREG_PMPADDR11}},
52812695Sar4jc@virginia.edu    {CSR_PMPADDR12, {"pmpaddr12", MISCREG_PMPADDR12}},
52912695Sar4jc@virginia.edu    {CSR_PMPADDR13, {"pmpaddr13", MISCREG_PMPADDR13}},
53012695Sar4jc@virginia.edu    {CSR_PMPADDR14, {"pmpaddr14", MISCREG_PMPADDR14}},
53112695Sar4jc@virginia.edu    {CSR_PMPADDR15, {"pmpaddr15", MISCREG_PMPADDR15}},
53212695Sar4jc@virginia.edu    {CSR_MCYCLE, {"mcycle", MISCREG_CYCLE}},
53312695Sar4jc@virginia.edu    {CSR_MINSTRET, {"minstret", MISCREG_INSTRET}},
53412695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER03, {"mhpmcounter03", MISCREG_HPMCOUNTER03}},
53512695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER04, {"mhpmcounter04", MISCREG_HPMCOUNTER04}},
53612695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER05, {"mhpmcounter05", MISCREG_HPMCOUNTER05}},
53712695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER06, {"mhpmcounter06", MISCREG_HPMCOUNTER06}},
53812695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER07, {"mhpmcounter07", MISCREG_HPMCOUNTER07}},
53912695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER08, {"mhpmcounter08", MISCREG_HPMCOUNTER08}},
54012695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER09, {"mhpmcounter09", MISCREG_HPMCOUNTER09}},
54112695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER10, {"mhpmcounter10", MISCREG_HPMCOUNTER10}},
54212695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER11, {"mhpmcounter11", MISCREG_HPMCOUNTER11}},
54312695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER12, {"mhpmcounter12", MISCREG_HPMCOUNTER12}},
54412695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER13, {"mhpmcounter13", MISCREG_HPMCOUNTER13}},
54512695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER14, {"mhpmcounter14", MISCREG_HPMCOUNTER14}},
54612695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER15, {"mhpmcounter15", MISCREG_HPMCOUNTER15}},
54712695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER16, {"mhpmcounter16", MISCREG_HPMCOUNTER16}},
54812695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER17, {"mhpmcounter17", MISCREG_HPMCOUNTER17}},
54912695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER18, {"mhpmcounter18", MISCREG_HPMCOUNTER18}},
55012695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER19, {"mhpmcounter19", MISCREG_HPMCOUNTER19}},
55112695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER20, {"mhpmcounter20", MISCREG_HPMCOUNTER20}},
55212695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER21, {"mhpmcounter21", MISCREG_HPMCOUNTER21}},
55312695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER22, {"mhpmcounter22", MISCREG_HPMCOUNTER22}},
55412695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER23, {"mhpmcounter23", MISCREG_HPMCOUNTER23}},
55512695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER24, {"mhpmcounter24", MISCREG_HPMCOUNTER24}},
55612695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER25, {"mhpmcounter25", MISCREG_HPMCOUNTER25}},
55712695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER26, {"mhpmcounter26", MISCREG_HPMCOUNTER26}},
55812695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER27, {"mhpmcounter27", MISCREG_HPMCOUNTER27}},
55912695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER28, {"mhpmcounter28", MISCREG_HPMCOUNTER28}},
56012695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER29, {"mhpmcounter29", MISCREG_HPMCOUNTER29}},
56112695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER30, {"mhpmcounter30", MISCREG_HPMCOUNTER30}},
56212695Sar4jc@virginia.edu    {CSR_MHPMCOUNTER31, {"mhpmcounter31", MISCREG_HPMCOUNTER31}},
56312695Sar4jc@virginia.edu    {CSR_MHPMEVENT03, {"mhpmevent03", MISCREG_HPMEVENT03}},
56412695Sar4jc@virginia.edu    {CSR_MHPMEVENT04, {"mhpmevent04", MISCREG_HPMEVENT04}},
56512695Sar4jc@virginia.edu    {CSR_MHPMEVENT05, {"mhpmevent05", MISCREG_HPMEVENT05}},
56612695Sar4jc@virginia.edu    {CSR_MHPMEVENT06, {"mhpmevent06", MISCREG_HPMEVENT06}},
56712695Sar4jc@virginia.edu    {CSR_MHPMEVENT07, {"mhpmevent07", MISCREG_HPMEVENT07}},
56812695Sar4jc@virginia.edu    {CSR_MHPMEVENT08, {"mhpmevent08", MISCREG_HPMEVENT08}},
56912695Sar4jc@virginia.edu    {CSR_MHPMEVENT09, {"mhpmevent09", MISCREG_HPMEVENT09}},
57012695Sar4jc@virginia.edu    {CSR_MHPMEVENT10, {"mhpmevent10", MISCREG_HPMEVENT10}},
57112695Sar4jc@virginia.edu    {CSR_MHPMEVENT11, {"mhpmevent11", MISCREG_HPMEVENT11}},
57212695Sar4jc@virginia.edu    {CSR_MHPMEVENT12, {"mhpmevent12", MISCREG_HPMEVENT12}},
57312695Sar4jc@virginia.edu    {CSR_MHPMEVENT13, {"mhpmevent13", MISCREG_HPMEVENT13}},
57412695Sar4jc@virginia.edu    {CSR_MHPMEVENT14, {"mhpmevent14", MISCREG_HPMEVENT14}},
57512695Sar4jc@virginia.edu    {CSR_MHPMEVENT15, {"mhpmevent15", MISCREG_HPMEVENT15}},
57612695Sar4jc@virginia.edu    {CSR_MHPMEVENT16, {"mhpmevent16", MISCREG_HPMEVENT16}},
57712695Sar4jc@virginia.edu    {CSR_MHPMEVENT17, {"mhpmevent17", MISCREG_HPMEVENT17}},
57812695Sar4jc@virginia.edu    {CSR_MHPMEVENT18, {"mhpmevent18", MISCREG_HPMEVENT18}},
57912695Sar4jc@virginia.edu    {CSR_MHPMEVENT19, {"mhpmevent19", MISCREG_HPMEVENT19}},
58012695Sar4jc@virginia.edu    {CSR_MHPMEVENT20, {"mhpmevent20", MISCREG_HPMEVENT20}},
58112695Sar4jc@virginia.edu    {CSR_MHPMEVENT21, {"mhpmevent21", MISCREG_HPMEVENT21}},
58212695Sar4jc@virginia.edu    {CSR_MHPMEVENT22, {"mhpmevent22", MISCREG_HPMEVENT22}},
58312695Sar4jc@virginia.edu    {CSR_MHPMEVENT23, {"mhpmevent23", MISCREG_HPMEVENT23}},
58412695Sar4jc@virginia.edu    {CSR_MHPMEVENT24, {"mhpmevent24", MISCREG_HPMEVENT24}},
58512695Sar4jc@virginia.edu    {CSR_MHPMEVENT25, {"mhpmevent25", MISCREG_HPMEVENT25}},
58612695Sar4jc@virginia.edu    {CSR_MHPMEVENT26, {"mhpmevent26", MISCREG_HPMEVENT26}},
58712695Sar4jc@virginia.edu    {CSR_MHPMEVENT27, {"mhpmevent27", MISCREG_HPMEVENT27}},
58812695Sar4jc@virginia.edu    {CSR_MHPMEVENT28, {"mhpmevent28", MISCREG_HPMEVENT28}},
58912695Sar4jc@virginia.edu    {CSR_MHPMEVENT29, {"mhpmevent29", MISCREG_HPMEVENT29}},
59012695Sar4jc@virginia.edu    {CSR_MHPMEVENT30, {"mhpmevent30", MISCREG_HPMEVENT30}},
59112695Sar4jc@virginia.edu    {CSR_MHPMEVENT31, {"mhpmevent31", MISCREG_HPMEVENT31}},
59212119Sar4jc@virginia.edu
59312695Sar4jc@virginia.edu    {CSR_TSELECT, {"tselect", MISCREG_TSELECT}},
59412695Sar4jc@virginia.edu    {CSR_TDATA1, {"tdata1", MISCREG_TDATA1}},
59512695Sar4jc@virginia.edu    {CSR_TDATA2, {"tdata2", MISCREG_TDATA2}},
59612695Sar4jc@virginia.edu    {CSR_TDATA3, {"tdata3", MISCREG_TDATA3}},
59712695Sar4jc@virginia.edu    {CSR_DCSR, {"dcsr", MISCREG_DCSR}},
59812695Sar4jc@virginia.edu    {CSR_DPC, {"dpc", MISCREG_DPC}},
59912695Sar4jc@virginia.edu    {CSR_DSCRATCH, {"dscratch", MISCREG_DSCRATCH}}
60012695Sar4jc@virginia.edu};
60112695Sar4jc@virginia.edu
60212850Salec.roelke@gmail.com/**
60312850Salec.roelke@gmail.com * These fields are specified in the RISC-V Instruction Set Manual, Volume II,
60412850Salec.roelke@gmail.com * v1.10, accessible at www.riscv.org. in Figure 3.7. The main register that
60512850Salec.roelke@gmail.com * uses these fields is the MSTATUS register, which is shadowed by two others
60612850Salec.roelke@gmail.com * accessible at lower privilege levels (SSTATUS and USTATUS) that can't see
60712850Salec.roelke@gmail.com * the fields for higher privileges.
60812850Salec.roelke@gmail.com */
60912850Salec.roelke@gmail.comBitUnion64(STATUS)
61012850Salec.roelke@gmail.com    Bitfield<63> sd;
61112850Salec.roelke@gmail.com    Bitfield<35, 34> sxl;
61212850Salec.roelke@gmail.com    Bitfield<33, 32> uxl;
61312850Salec.roelke@gmail.com    Bitfield<22> tsr;
61412850Salec.roelke@gmail.com    Bitfield<21> tw;
61512850Salec.roelke@gmail.com    Bitfield<20> tvm;
61612850Salec.roelke@gmail.com    Bitfield<19> mxr;
61712850Salec.roelke@gmail.com    Bitfield<18> sum;
61812850Salec.roelke@gmail.com    Bitfield<17> mprv;
61912850Salec.roelke@gmail.com    Bitfield<16, 15> xs;
62012850Salec.roelke@gmail.com    Bitfield<14, 13> fs;
62112850Salec.roelke@gmail.com    Bitfield<12, 11> mpp;
62212850Salec.roelke@gmail.com    Bitfield<8> spp;
62312850Salec.roelke@gmail.com    Bitfield<7> mpie;
62412850Salec.roelke@gmail.com    Bitfield<5> spie;
62512850Salec.roelke@gmail.com    Bitfield<4> upie;
62612850Salec.roelke@gmail.com    Bitfield<3> mie;
62712850Salec.roelke@gmail.com    Bitfield<1> sie;
62812850Salec.roelke@gmail.com    Bitfield<0> uie;
62912850Salec.roelke@gmail.comEndBitUnion(STATUS)
63012850Salec.roelke@gmail.com
63112850Salec.roelke@gmail.com/**
63212850Salec.roelke@gmail.com * These fields are specified in the RISC-V Instruction Set Manual, Volume II,
63312850Salec.roelke@gmail.com * v1.10 in Figures 3.11 and 3.12, accessible at www.riscv.org. Both the MIP
63412850Salec.roelke@gmail.com * and MIE registers have the same fields, so accesses to either should use
63512850Salec.roelke@gmail.com * this bit union.
63612850Salec.roelke@gmail.com */
63712850Salec.roelke@gmail.comBitUnion64(INTERRUPT)
63812850Salec.roelke@gmail.com    Bitfield<11> mei;
63912850Salec.roelke@gmail.com    Bitfield<9> sei;
64012850Salec.roelke@gmail.com    Bitfield<8> uei;
64112850Salec.roelke@gmail.com    Bitfield<7> mti;
64212850Salec.roelke@gmail.com    Bitfield<5> sti;
64312850Salec.roelke@gmail.com    Bitfield<4> uti;
64412850Salec.roelke@gmail.com    Bitfield<3> msi;
64512850Salec.roelke@gmail.com    Bitfield<1> ssi;
64612850Salec.roelke@gmail.com    Bitfield<0> usi;
64712850Salec.roelke@gmail.comEndBitUnion(INTERRUPT)
64812850Salec.roelke@gmail.com
64913612Sgabeblack@google.comconst off_t MXL_OFFSET = (sizeof(uint64_t) * 8 - 2);
65012695Sar4jc@virginia.educonst off_t SXL_OFFSET = 34;
65112695Sar4jc@virginia.educonst off_t UXL_OFFSET = 32;
65212695Sar4jc@virginia.educonst off_t FS_OFFSET = 13;
65312695Sar4jc@virginia.educonst off_t FRM_OFFSET = 5;
65412695Sar4jc@virginia.edu
65513612Sgabeblack@google.comconst RegVal ISA_MXL_MASK = 3ULL << MXL_OFFSET;
65613612Sgabeblack@google.comconst RegVal ISA_EXT_MASK = mask(26);
65713612Sgabeblack@google.comconst RegVal MISA_MASK = ISA_MXL_MASK | ISA_EXT_MASK;
65812695Sar4jc@virginia.edu
65913612Sgabeblack@google.comconst RegVal STATUS_SD_MASK = 1ULL << ((sizeof(uint64_t) * 8) - 1);
66013612Sgabeblack@google.comconst RegVal STATUS_SXL_MASK = 3ULL << SXL_OFFSET;
66113612Sgabeblack@google.comconst RegVal STATUS_UXL_MASK = 3ULL << UXL_OFFSET;
66213612Sgabeblack@google.comconst RegVal STATUS_TSR_MASK = 1ULL << 22;
66313612Sgabeblack@google.comconst RegVal STATUS_TW_MASK = 1ULL << 21;
66413612Sgabeblack@google.comconst RegVal STATUS_TVM_MASK = 1ULL << 20;
66513612Sgabeblack@google.comconst RegVal STATUS_MXR_MASK = 1ULL << 19;
66613612Sgabeblack@google.comconst RegVal STATUS_SUM_MASK = 1ULL << 18;
66713612Sgabeblack@google.comconst RegVal STATUS_MPRV_MASK = 1ULL << 17;
66813612Sgabeblack@google.comconst RegVal STATUS_XS_MASK = 3ULL << 15;
66913612Sgabeblack@google.comconst RegVal STATUS_FS_MASK = 3ULL << FS_OFFSET;
67013612Sgabeblack@google.comconst RegVal STATUS_MPP_MASK = 3ULL << 11;
67113612Sgabeblack@google.comconst RegVal STATUS_SPP_MASK = 1ULL << 8;
67213612Sgabeblack@google.comconst RegVal STATUS_MPIE_MASK = 1ULL << 7;
67313612Sgabeblack@google.comconst RegVal STATUS_SPIE_MASK = 1ULL << 5;
67413612Sgabeblack@google.comconst RegVal STATUS_UPIE_MASK = 1ULL << 4;
67513612Sgabeblack@google.comconst RegVal STATUS_MIE_MASK = 1ULL << 3;
67613612Sgabeblack@google.comconst RegVal STATUS_SIE_MASK = 1ULL << 1;
67713612Sgabeblack@google.comconst RegVal STATUS_UIE_MASK = 1ULL << 0;
67813612Sgabeblack@google.comconst RegVal MSTATUS_MASK = STATUS_SD_MASK | STATUS_SXL_MASK |
67913612Sgabeblack@google.com                            STATUS_UXL_MASK | STATUS_TSR_MASK |
68013612Sgabeblack@google.com                            STATUS_TW_MASK | STATUS_TVM_MASK |
68113612Sgabeblack@google.com                            STATUS_MXR_MASK | STATUS_SUM_MASK |
68213612Sgabeblack@google.com                            STATUS_MPRV_MASK | STATUS_XS_MASK |
68313612Sgabeblack@google.com                            STATUS_FS_MASK | STATUS_MPP_MASK |
68413612Sgabeblack@google.com                            STATUS_SPP_MASK | STATUS_MPIE_MASK |
68513612Sgabeblack@google.com                            STATUS_SPIE_MASK | STATUS_UPIE_MASK |
68613612Sgabeblack@google.com                            STATUS_MIE_MASK | STATUS_SIE_MASK |
68713612Sgabeblack@google.com                            STATUS_UIE_MASK;
68813612Sgabeblack@google.comconst RegVal SSTATUS_MASK = STATUS_SD_MASK | STATUS_UXL_MASK |
68913612Sgabeblack@google.com                            STATUS_MXR_MASK | STATUS_SUM_MASK |
69013612Sgabeblack@google.com                            STATUS_XS_MASK | STATUS_FS_MASK |
69113612Sgabeblack@google.com                            STATUS_SPP_MASK | STATUS_SPIE_MASK |
69213612Sgabeblack@google.com                            STATUS_UPIE_MASK | STATUS_SIE_MASK |
69313612Sgabeblack@google.com                            STATUS_UIE_MASK;
69413612Sgabeblack@google.comconst RegVal USTATUS_MASK = STATUS_SD_MASK | STATUS_MXR_MASK |
69513612Sgabeblack@google.com                            STATUS_SUM_MASK | STATUS_XS_MASK |
69613612Sgabeblack@google.com                            STATUS_FS_MASK | STATUS_UPIE_MASK |
69713612Sgabeblack@google.com                            STATUS_UIE_MASK;
69812695Sar4jc@virginia.edu
69913612Sgabeblack@google.comconst RegVal MEI_MASK = 1ULL << 11;
70013612Sgabeblack@google.comconst RegVal SEI_MASK = 1ULL << 9;
70113612Sgabeblack@google.comconst RegVal UEI_MASK = 1ULL << 8;
70213612Sgabeblack@google.comconst RegVal MTI_MASK = 1ULL << 7;
70313612Sgabeblack@google.comconst RegVal STI_MASK = 1ULL << 5;
70413612Sgabeblack@google.comconst RegVal UTI_MASK = 1ULL << 4;
70513612Sgabeblack@google.comconst RegVal MSI_MASK = 1ULL << 3;
70613612Sgabeblack@google.comconst RegVal SSI_MASK = 1ULL << 1;
70713612Sgabeblack@google.comconst RegVal USI_MASK = 1ULL << 0;
70813612Sgabeblack@google.comconst RegVal MI_MASK = MEI_MASK | SEI_MASK | UEI_MASK |
70913612Sgabeblack@google.com                       MTI_MASK | STI_MASK | UTI_MASK |
71013612Sgabeblack@google.com                       MSI_MASK | SSI_MASK | USI_MASK;
71113612Sgabeblack@google.comconst RegVal SI_MASK = SEI_MASK | UEI_MASK |
71213612Sgabeblack@google.com                       STI_MASK | UTI_MASK |
71313612Sgabeblack@google.com                       SSI_MASK | USI_MASK;
71413612Sgabeblack@google.comconst RegVal UI_MASK = UEI_MASK | UTI_MASK | USI_MASK;
71513612Sgabeblack@google.comconst RegVal FFLAGS_MASK = (1 << FRM_OFFSET) - 1;
71613612Sgabeblack@google.comconst RegVal FRM_MASK = 0x7;
71712695Sar4jc@virginia.edu
71813612Sgabeblack@google.comconst std::map<int, RegVal> CSRMasks = {
71912695Sar4jc@virginia.edu    {CSR_USTATUS, USTATUS_MASK},
72012695Sar4jc@virginia.edu    {CSR_UIE, UI_MASK},
72112695Sar4jc@virginia.edu    {CSR_UIP, UI_MASK},
72212695Sar4jc@virginia.edu    {CSR_FFLAGS, FFLAGS_MASK},
72312695Sar4jc@virginia.edu    {CSR_FRM, FRM_MASK},
72412695Sar4jc@virginia.edu    {CSR_FCSR, FFLAGS_MASK | (FRM_MASK << FRM_OFFSET)},
72512695Sar4jc@virginia.edu    {CSR_SSTATUS, SSTATUS_MASK},
72612695Sar4jc@virginia.edu    {CSR_SIE, SI_MASK},
72712695Sar4jc@virginia.edu    {CSR_SIP, SI_MASK},
72812695Sar4jc@virginia.edu    {CSR_MSTATUS, MSTATUS_MASK},
72912695Sar4jc@virginia.edu    {CSR_MISA, MISA_MASK},
73012695Sar4jc@virginia.edu    {CSR_MIE, MI_MASK},
73112695Sar4jc@virginia.edu    {CSR_MIP, MI_MASK}
73212119Sar4jc@virginia.edu};
73312119Sar4jc@virginia.edu
73411723Sar4jc@virginia.edu}
73511723Sar4jc@virginia.edu
73611723Sar4jc@virginia.edu#endif // __ARCH_RISCV_REGISTERS_HH__
737