RiscV架构则定义了一些控制和状态寄存器(CSR),用于配置或记录一些运行的状态。CSR寄存器是处理器内核内部的寄存器,使用专有的12位地址编码空间,对一个hart,可以配置4k的CSR寄存器。
蜂鸟203支持以下的CSR寄存器:
类型 | CSR地址 | 读写属性 | 名称 | 全称 |
riscv标准csr | 0x001 | MRW | fflags | 浮点累积异常(Floating accrued Exception) |
0x002 | MRW | frm | 浮点动态舍入模式(floating-point dynamic rounding mode) | |
0x003 | MRW | fcsr | 浮点控制和状态寄存器(floating-point control and status register) | |
0x300 | MRW | mstatus | 机器模式状态寄存器(machine status register) | |
0x301 | MRW | misa | 机器模式指令集架构寄存器(machine ISA register) | |
0x304 | MRW | mie | 机器模式中断使能寄存器(machine interrupt enable register) | |
0x305 | MRW | mtvec | 机器模式异常入口基地址寄存器(machine trap-vector base-address register) | |
0x340 | MRW | mscratch | 机器模式擦写寄存器(machine srcatch register) | |
0x341 | MRW | mepc | 机器模式异常pc寄存器(machine exception program counter) | |
0x342 | MRW | mcause | 机器模式异常原因寄存器(machine cause register) | |
0x343 | MRW | mtval(mbadaddr) | 机器模式异常值寄存器(machine trap value register) | |
0x344 | MRW | mip | 机器模式中断等待寄存器(machine interrupt pending register) | |
0xb00 | MRW | mcycle | 周期计数器的低32位(lower 32bits of cycle counter) | |
0xb80 | MRW | mcycleh | 周期计数器的高32位(upper 32bits of cycle counter) | |
0xb02 | MRW | minstret | 退休指令计数器的低32位(lower 32bits of instruction-retired counter) | |
0xb82 | MRW | minstreth | 退休指令计数器的高32位(upper 32bits of instruction-retired counter) | |
0xf11 | MRW | mvendorid | 机器模式供应商编号寄存器(machine vendor ID register),readonly, 供应商编号,如果为0,表示此寄存器未实现或不是一个商业核 | |
0xf12 | MRW | marchid | 机器模式架构编号寄存器(machine architecture ID register),readonly,微架构编号,如果为0,表示未实现该寄存器 | |
0xf13 | MRO | mimpid | 机器模式硬件实现编号寄存器(machine implementation ID register),readonly,硬件实现编号,如果为0,表示未实现该寄存器 | |
0xf14 | MRO | mhartid | hart编号寄存器(hart ID register),readonly,hart的编号。多hart系统中,起码有一个hart编号为0 | |
N/A | MRO | mtime | 机器模式计时器寄存器(machine-mode timer register) | |
N/A | MRW | mtimecmp | 机器模式计数器比较寄存器(machine-mode timer compare register) | |
N/A | MRW | msip | 机器模式软件中断等待寄存器(machine-mode software interrupt pending register) | |
e203自定义 | 0xbff | MRW | mcounterstop | 自定义寄存器用于停止mtime, mcycle, mcycleh,minstret,minstreth对应的计数器 |
常用的CSR寄存器详细介绍
misa寄存器用于指示当前处理器所支持的架构特性。
最高两位表示当前处理器支持的架构位数,值为1表示当前为32位架构(RV32),值为2表示当前为RV64架构,值为3表示当前为128位架构(RV128)。
低26位表示当前支持的扩展指令集模块,如果支持某模块,则对应的位为1。比如E203,支持IMAC,则低26位为:
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | 1 | x | x | x | x | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
bits | 扩展指令集 | 描述 |
0 | A | Atomic extension |
1 | B | Tentatively reserved for Bit-Manipulation extension |
2 | C | Compressed extension |
3 | D | Double-precision ?oating-point extension |
4 | E | RV32E base ISA |
5 | F | Single-precision ?oating-point extension |
6 | G | Additional standard extensions present |
7 | H | Hypervisor extension |
8 | I | RV32I/64I/128I base ISA |
9 | J | Tentatively reserved for Dynamically Translated Languages extension |
10 | K | Reserved |
11 | L | Tentatively reserved for Decimal Floating-Point extension |
12 | M | Integer Multiply/Divide extension |
13 | N | User-level interrupts supported |
14 | O | Reserved |
15 | P | Tentatively reserved for Packed-SIMD extension |
16 | Q | Quad-precision ?oating-point extension |
17 | R | Reserved |
18 | S | Supervisor mode implemented |
19 | T | Tentatively reserved for Transactional Memory extension |
20 | U | User mode implemented |
21 | V | Tentatively reserved for Vector extension |
22 | W | Reserved |
23 | X | Non-standard extensions present |
24 | Y | Reserved |
25 | Z | Reserved |
fflags 为浮点控制状态寄存器(fcsr)中的异常标志位域的别名。
详见https://www.cnblogs.com/mikewolf2002/p/9878603.html
frm寄存器为浮点控制状态寄存器中浮点舍入模式域的别名。
详见https://www.cnblogs.com/mikewolf2002/p/9878603.html
risc-v架构规定,如果支持单精度浮点指令或者双精度浮点指令,则需要增加一个浮点控制状态寄存器。该寄存器包含了浮点异常标志位域和浮点舍入模式域。
详见https://www.cnblogs.com/mikewolf2002/p/9878603.html
mstatus是机器模式下的状态寄存器。我们仅关注SD,XS,FS,MPP,MPIE,MIE。
to do
to do
to do
to do
to do
to do
to do
to do
to do
to do
to do
原文:https://www.cnblogs.com/mikewolf2002/p/11314583.html