|
| 1 | +/* |
| 2 | + Copyright (c) 2013, The Regents of the University of California (Regents). |
| 3 | + All Rights Reserved. |
| 4 | +
|
| 5 | + Redistribution and use in source and binary forms, with or without |
| 6 | + modification, are permitted provided that the following conditions are met: |
| 7 | + 1. Redistributions of source code must retain the above copyright |
| 8 | + notice, this list of conditions and the following disclaimer. |
| 9 | + 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer in the |
| 11 | + documentation and/or other materials provided with the distribution. |
| 12 | + 3. Neither the name of the Regents nor the |
| 13 | + names of its contributors may be used to endorse or promote products |
| 14 | + derived from this software without specific prior written permission. |
| 15 | +
|
| 16 | + IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, |
| 17 | + SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING |
| 18 | + OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS |
| 19 | + BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 20 | +
|
| 21 | + REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 22 | + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED |
| 24 | + HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE |
| 25 | + MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 26 | +*/ |
| 27 | + |
| 28 | +#ifndef _ARCH_RISCV_CSR_H_ |
| 29 | +#define _ARCH_RISCV_CSR_H_ |
| 30 | + |
| 31 | +#define MSTATUS_UIE 0x00000001 |
| 32 | +#define MSTATUS_SIE 0x00000002 |
| 33 | +#define MSTATUS_HIE 0x00000004 |
| 34 | +#define MSTATUS_MIE 0x00000008 |
| 35 | +#define MSTATUS_UPIE 0x00000010 |
| 36 | +#define MSTATUS_SPIE 0x00000020 |
| 37 | +#define MSTATUS_HPIE 0x00000040 |
| 38 | +#define MSTATUS_MPIE 0x00000080 |
| 39 | +#define MSTATUS_SPP 0x00000100 |
| 40 | +#define MSTATUS_HPP 0x00000600 |
| 41 | +#define MSTATUS_MPP 0x00001800 |
| 42 | +#define MSTATUS_VS 0x01800000 |
| 43 | +#define MSTATUS_FS 0x00006000 |
| 44 | +#define MSTATUS_XS 0x00018000 |
| 45 | +#define MSTATUS_MPRV 0x00020000 |
| 46 | +#define MSTATUS_SUM 0x00040000 |
| 47 | +#define MSTATUS_MXR 0x00080000 |
| 48 | +#define MSTATUS_TVM 0x00100000 |
| 49 | +#define MSTATUS_TW 0x00200000 |
| 50 | +#define MSTATUS_TSR 0x00400000 |
| 51 | +#define MSTATUS_UXL 0x0000000300000000 |
| 52 | +#define MSTATUS_SXL 0x0000000C00000000 |
| 53 | +#define MSTATUS_SD 0x8000000000000000 |
| 54 | + |
| 55 | +#define SSTATUS_UIE 0x00000001 |
| 56 | +#define SSTATUS_SIE 0x00000002 |
| 57 | +#define SSTATUS_UPIE 0x00000010 |
| 58 | +#define SSTATUS_SPIE 0x00000020 |
| 59 | +#define SSTATUS_SPP 0x00000100 |
| 60 | +#define SSTATUS_VS 0x01800000 |
| 61 | +#define SSTATUS_FS 0x00006000 |
| 62 | +#define SSTATUS_XS 0x00018000 |
| 63 | +#define SSTATUS_SUM 0x00040000 |
| 64 | +#define SSTATUS_MXR 0x00080000 |
| 65 | +#define SSTATUS_UXL 0x0000000300000000 |
| 66 | +#define SSTATUS_SD 0x8000000000000000 |
| 67 | + |
| 68 | +#define DCSR_XDEBUGVER (3U<<30) |
| 69 | +#define DCSR_NDRESET (1<<29) |
| 70 | +#define DCSR_FULLRESET (1<<28) |
| 71 | +#define DCSR_EBREAKM (1<<15) |
| 72 | +#define DCSR_EBREAKH (1<<14) |
| 73 | +#define DCSR_EBREAKS (1<<13) |
| 74 | +#define DCSR_EBREAKU (1<<12) |
| 75 | +#define DCSR_STOPCYCLE (1<<10) |
| 76 | +#define DCSR_STOPTIME (1<<9) |
| 77 | +#define DCSR_CAUSE (7<<6) |
| 78 | +#define DCSR_DEBUGINT (1<<5) |
| 79 | +#define DCSR_HALT (1<<3) |
| 80 | +#define DCSR_STEP (1<<2) |
| 81 | +#define DCSR_PRV (3<<0) |
| 82 | + |
| 83 | +#define DCSR_CAUSE_NONE 0 |
| 84 | +#define DCSR_CAUSE_SWBP 1 |
| 85 | +#define DCSR_CAUSE_HWBP 2 |
| 86 | +#define DCSR_CAUSE_DEBUGINT 3 |
| 87 | +#define DCSR_CAUSE_STEP 4 |
| 88 | +#define DCSR_CAUSE_HALT 5 |
| 89 | + |
| 90 | +#define MCONTROL_TYPE(xlen) (0xfULL<<((xlen)-4)) |
| 91 | +#define MCONTROL_DMODE(xlen) (1ULL<<((xlen)-5)) |
| 92 | +#define MCONTROL_MASKMAX(xlen) (0x3fULL<<((xlen)-11)) |
| 93 | + |
| 94 | +#define MCONTROL_SELECT (1<<19) |
| 95 | +#define MCONTROL_TIMING (1<<18) |
| 96 | +#define MCONTROL_ACTION (0x3f<<12) |
| 97 | +#define MCONTROL_CHAIN (1<<11) |
| 98 | +#define MCONTROL_MATCH (0xf<<7) |
| 99 | +#define MCONTROL_M (1<<6) |
| 100 | +#define MCONTROL_H (1<<5) |
| 101 | +#define MCONTROL_S (1<<4) |
| 102 | +#define MCONTROL_U (1<<3) |
| 103 | +#define MCONTROL_EXECUTE (1<<2) |
| 104 | +#define MCONTROL_STORE (1<<1) |
| 105 | +#define MCONTROL_LOAD (1<<0) |
| 106 | + |
| 107 | +#define MCONTROL_TYPE_NONE 0 |
| 108 | +#define MCONTROL_TYPE_MATCH 2 |
| 109 | + |
| 110 | +#define MCONTROL_ACTION_DEBUG_EXCEPTION 0 |
| 111 | +#define MCONTROL_ACTION_DEBUG_MODE 1 |
| 112 | +#define MCONTROL_ACTION_TRACE_START 2 |
| 113 | +#define MCONTROL_ACTION_TRACE_STOP 3 |
| 114 | +#define MCONTROL_ACTION_TRACE_EMIT 4 |
| 115 | + |
| 116 | +#define MCONTROL_MATCH_EQUAL 0 |
| 117 | +#define MCONTROL_MATCH_NAPOT 1 |
| 118 | +#define MCONTROL_MATCH_GE 2 |
| 119 | +#define MCONTROL_MATCH_LT 3 |
| 120 | +#define MCONTROL_MATCH_MASK_LOW 4 |
| 121 | +#define MCONTROL_MATCH_MASK_HIGH 5 |
| 122 | + |
| 123 | +#define MIP_SSIP (1 << IRQ_S_SOFT) |
| 124 | +#define MIP_HSIP (1 << IRQ_H_SOFT) |
| 125 | +#define MIP_MSIP (1 << IRQ_M_SOFT) |
| 126 | +#define MIP_STIP (1 << IRQ_S_TIMER) |
| 127 | +#define MIP_HTIP (1 << IRQ_H_TIMER) |
| 128 | +#define MIP_MTIP (1 << IRQ_M_TIMER) |
| 129 | +#define MIP_SEIP (1 << IRQ_S_EXT) |
| 130 | +#define MIP_HEIP (1 << IRQ_H_EXT) |
| 131 | +#define MIP_MEIP (1 << IRQ_M_EXT) |
| 132 | + |
| 133 | +#define SIP_SSIP MIP_SSIP |
| 134 | +#define SIP_STIP MIP_STIP |
| 135 | + |
| 136 | +#define PRV_U 0 |
| 137 | +#define PRV_S 1 |
| 138 | +#define PRV_H 2 |
| 139 | +#define PRV_M 3 |
| 140 | + |
| 141 | +#define PMP_R 0x01 |
| 142 | +#define PMP_W 0x02 |
| 143 | +#define PMP_X 0x04 |
| 144 | +#define PMP_A 0x18 |
| 145 | +#define PMP_L 0x80 |
| 146 | +#define PMP_SHIFT 2 |
| 147 | + |
| 148 | +#define PMP_TOR 0x08 |
| 149 | +#define PMP_NA4 0x10 |
| 150 | +#define PMP_NAPOT 0x18 |
| 151 | + |
| 152 | +#define IRQ_S_SOFT 1 |
| 153 | +#define IRQ_H_SOFT 2 |
| 154 | +#define IRQ_M_SOFT 3 |
| 155 | +#define IRQ_S_TIMER 5 |
| 156 | +#define IRQ_H_TIMER 6 |
| 157 | +#define IRQ_M_TIMER 7 |
| 158 | +#define IRQ_S_EXT 9 |
| 159 | +#define IRQ_H_EXT 10 |
| 160 | +#define IRQ_M_EXT 11 |
| 161 | +#define IRQ_COP 12 |
| 162 | +#define IRQ_HOST 13 |
| 163 | + |
| 164 | +#define DEFAULT_RSTVEC 0x00001000 |
| 165 | +#define CLINT_BASE 0x02000000 |
| 166 | +#define CLINT_SIZE 0x000c0000 |
| 167 | + |
| 168 | +#ifdef __riscv |
| 169 | + |
| 170 | +#ifndef __ASSEMBLER__ |
| 171 | + |
| 172 | +#ifdef __GNUC__ |
| 173 | + |
| 174 | +#define read_csr(reg) ({ unsigned long __tmp; \ |
| 175 | + asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ |
| 176 | + __tmp; }) |
| 177 | + |
| 178 | +#define write_csr(reg, val) ({ \ |
| 179 | + asm volatile ("csrw " #reg ", %0" :: "rK"(val)); }) |
| 180 | + |
| 181 | +#define swap_csr(reg, val) ({ unsigned long __tmp; \ |
| 182 | + asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "rK"(val)); \ |
| 183 | + __tmp; }) |
| 184 | + |
| 185 | +#define set_csr(reg, bit) ({ unsigned long __tmp; \ |
| 186 | + asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ |
| 187 | + __tmp; }) |
| 188 | + |
| 189 | +#define clear_csr(reg, bit) ({ unsigned long __tmp; \ |
| 190 | + asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ |
| 191 | + __tmp; }) |
| 192 | + |
| 193 | +#define rdtime() read_csr(time) |
| 194 | +#define rdcycle() read_csr(cycle) |
| 195 | +#define rdinstret() read_csr(instret) |
| 196 | + |
| 197 | +#endif |
| 198 | + |
| 199 | +#endif |
| 200 | + |
| 201 | +#endif |
| 202 | + |
| 203 | +#endif |
0 commit comments