cemu
载入中...
搜索中...
未找到
csr.h
浏览该文件的文档.
1
12#ifndef CSR_H
13#define CSR_H
14
15// ==================================================================== //
16// Include
17// ==================================================================== //
18
19#include "cpu.h"
20
21// ==================================================================== //
22// Define
23// ==================================================================== //
24
25
26//-----------------------------------------------------------------------------
27// Name Number Priv Description
28//-----------------------------------------------------------------------------
29
30// User Trap Setup
31#define USTATUS 0x000 // URW User status register.
32#define UIE 0x004 // URW User interrupt-enable register.
33#define UTVEC 0x005 // URW User trap handler base address.
34
35//User Trap Handling
36#define USCRATCH 0x040 // URW Scratch register for user trap handlers.
37#define UEPC 0x041 // URW User exception program counter.
38#define UCAUSE 0x042 // URW User trap cause.
39#define UTVAL 0x043 // URW User bad address or instruction.
40#define UIP 0x044 // URW User interrupt pending.
41
42//User Floating-Point CSRs
43#define FFLAGS 0x001 // URW Floating-Point Accrued Exceptions.
44#define FRM 0x002 // URW Floating-Point Dynamic Rounding Mode.
45#define FCSR 0x003 // URW Floating-Point Control and Status Register (frm + fflags)
46
47//User Counter/Timers
48#define CYCLE 0xC00 // URO Cycle counter for RDCYCLE instruction.
49#define TIME 0xC01 // URO Timer for RDTIME instruction.
50#define INSTRET 0xC02 // URO Instructions-retired counter for RDINSTRET instruction.
51#define HPMCOUNTER3 0xC03 // URO Performance-monitoring counter.
52#define HPMCOUNTER4 0xC04 // URO Performance-monitoring counter.
53// ... hpm counter 4-31 (TODO)
54#define HPMCOUNTER31 0xC1F // URO Performance-monitoring counter.
55#define CYCLEH 0xC80 // URO Upper 32 bits of cycle, RV32I only.
56#define TIMEH 0xC81 // URO Upper 32 bits of time, RV32I only.
57#define INSTRETH 0xC82 // URO Upper 32 bits of instret, RV32I only.
58#define HPMCOUNTER3H 0xC83 // URO Upper 32 bits of hpmcounter3, RV32I only.
59#define HPMCOUNTER4H 0xC84 // URO Upper 32 bits of hpmcounter4, RV32I only.
60// ... hpm counter 4-31 (TODO)
61#define HPMCOUNTER31H 0xC9F URO
62
63
64//Supervisor Trap Setup
65#define SSTATUS 0x100 // SRW Supervisor status register.
66#define SEDELEG 0x102 // SRW Supervisor exception delegation register.
67#define SIDELEG 0x103 // SRW Supervisor interrupt delegation register.
68#define SIE 0x104 // SRW Supervisor interrupt-enable register.
69#define STVEC 0x105 // SRW Supervisor trap handler base address.
70#define SCOUNTEREN 0x106 // SRW Supervisor counter enable.
71
72//Supervisor Trap Handling
73#define SSCRATCH 0x140 // SRW Scratch register for supervisor trap handlers.
74#define SEPC 0x141 // SRW Supervisor exception program counter.
75#define SCAUSE 0x142 // SRW Supervisor trap cause.
76#define STVAL 0x143 // SRW Supervisor bad address or instruction.
77#define SIP 0x144 // SRW Supervisor interrupt pending.
78
79//Supervisor Protection and Translation
80#define SATP 0x180 // SRW Supervisor address translation and protection.
81
82//Machine Information Registers
83#define MVENDORID 0xF11 // MRO Vendor ID.
84#define MARCHID 0xF12 // MRO Architecture ID.
85#define MIMPID 0xF13 // MRO Implementation ID.
86#define MHARTID 0xF14 // MRO Hardware thread ID.
87
88//Machine Trap Setup
89#define MSTATUS 0x300 // MRW Machine status register.
90#define MISA 0x301 // MRW ISA and extensions
91#define MEDELEG 0x302 // MRW Machine exception delegation register.
92#define MIDELEG 0x303 // MRW Machine interrupt delegation register.
93#define MIE 0x304 // MRW Machine interrupt-enable register.
94#define MTVEC 0x305 // MRW Machine trap-handler base address.
95#define MCOUNTEREN 0x306 // MRW Machine counter enable.
96
97//Machine Trap Handling
98#define MSCRATCH 0x340 // MRW Scratch register for machine trap handlers.
99#define MEPC 0x341 // MRW Machine exception program counter.
100#define MCAUSE 0x342 // MRW Machine trap cause.
101#define MTVAL 0x343 // MRW Machine bad address or instruction.
102#define MIP 0x344 // MRW Machine interrupt pending.
103
104//Machine Memory Protection
105#define PMPCFG0 0x3A0 // MRW Physical memory protection configuration.
106#define PMPCFG1 0x3A1 // MRW Physical memory protection configuration, RV32 only.
107#define PMPCFG2 0x3A2 // MRW Physical memory protection configuration.
108#define PMPCFG3 0x3A3 // MRW Physical memory protection configuration, RV32 only.
109#define PMPADDR0 0x3B0 // MRW Physical memory protection address register.
110#define PMPADDR1 0x3B1 // MRW Physical memory protection address register.
111// ... 2-15 /TODO
112#define PMPADDR15 0x3BF // MRW Physical memory protection address register.
113
114//Machine Counter/Timers
115#define MCYCLE 0xB00 // MRW Machine cycle counter.
116#define MINSTRET 0xB02 // MRW Machine instructions-retired counter.
117#define MHPMCOUNTER3 0xB03 // MRW Machine performance-monitoring counter.
118#define MHPMCOUNTER4 0xB04 // MRW Machine performance-monitoring counter.
119// #define ...
120#define MHPMCOUNTER31 0xB1F // MRW Machine performance-monitoring counter.
121#define MCYCLEH 0xB80 // MRW Upper 32 bits of mcycle, RV32I only.
122#define MINSTRETH 0xB82 // MRW Upper 32 bits of minstret, RV32I only.
123#define MHPMCOUNTER3H 0xB83 // MRW Upper 32 bits of mhpmcounter3, RV32I only.
124#define MHPMCOUNTER4H 0xB84 // MRW Upper 32 bits of mhpmcounter4, RV32I only.
125// ...
126#define MHPMCOUNTER31H 0xB9F // MRW Upper 32 bits of mhpmcounter31, RV32I only.
127
128//Machine Counter Setup
129#define MCOUNTINHIBIT 0x320 // MRW Machine counter-inhibit register.
130#define MHPMEVENT3 0x323 // MRW Machine performance-monitoring event selector.
131#define MHPMEVENT4 0x324 // MRW Machine performance-monitoring event selector.
132//#define ...
133#define MHPMEVENT31 0x33F // MRW Machine performance-monitoring event selector.
134
135//Debug/Trace Registers (shared with Debug Mode)
136#define TSELECT 0x7A0 // MRW Debug/Trace trigger register select.
137#define TDATA1 0x7A1 // MRW First Debug/Trace trigger data register.
138#define TDATA2 0x7A2 // MRW Second Debug/Trace trigger data register.
139#define TDATA3 0x7A3 // MRW Third Debug/Trace trigger data register.
140
141//Debug Mode Registers
142#define DCSR 0x7B0 // DRW Debug control and status register.
143#define DPC 0x7B1 // DRW Debug PC.
144#define DSCRATCH0 0x7B2 // DRW Debug scratch register 0.
145#define DSCRATCH1 0x7B3 // DRW Debug scratch register 1.
146
147
148// ==================================================================== //
149// Declare API: CSR
150// ==================================================================== //
151
152u64 csr_read(CPU* cpu, u64 csr);
153void csr_write(CPU* cpu, u64 csr, u64 value);
154
155#endif
中央处理器头文件
中央处理器结构体
Definition cpu.h:35