disentangle decode.h from other headers
[riscv-isa-sim.git] / riscv / processor.h
1 #ifndef _RISCV_PROCESSOR_H
2 #define _RISCV_PROCESSOR_H
3
4 #include "decode.h"
5 #include <cstring>
6 #include "trap.h"
7 #include "config.h"
8
9 #define MAX_UTS 2048
10
11 class processor_t;
12 class mmu_t;
13 typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t);
14 class sim_t;
15
16 // this class represents one processor in a RISC-V machine.
17 class processor_t
18 {
19 public:
20 processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id);
21 ~processor_t();
22
23 void step(size_t n, bool noisy); // run for n cycles
24 void deliver_ipi(); // register an interprocessor interrupt
25
26 private:
27 sim_t& sim;
28 mmu_t& mmu; // main memory is always accessed via the mmu
29
30 // user-visible architected state
31 reg_t XPR[NXPR];
32 freg_t FPR[NFPR];
33 reg_t pc;
34
35 // counters
36 reg_t cycle;
37
38 // privileged control registers
39 reg_t epc;
40 reg_t badvaddr;
41 reg_t evec;
42 reg_t pcr_k0;
43 reg_t pcr_k1;
44 uint32_t cause;
45 uint32_t interrupts_pending;
46 uint32_t id;
47 uint32_t sr; // only modify the status register using set_sr()
48 uint32_t fsr;
49 uint32_t count;
50 uint32_t compare;
51
52 // # of bits in an XPR (32 or 64). (redundant with sr)
53 int xprlen;
54
55 // is this processor running? (deliver_ipi() sets this)
56 bool run;
57
58 // functions
59 void reset(); // resets architected state; halts processor if it was running
60 void take_interrupt(); // take a trap if any interrupts are pending
61 void set_sr(uint32_t val); // set the status register
62 void set_fsr(uint32_t val); // set the floating-point status register
63 void take_trap(trap_t t, bool noisy); // take an exception
64 void disasm(insn_t insn, reg_t pc); // disassemble and print an instruction
65
66 // vector stuff
67 void vcfg();
68 void setvl(int vlapp);
69
70 reg_t vecbanks;
71 uint32_t vecbanks_count;
72
73 bool utmode;
74 uint32_t utidx;
75 int vlmax;
76 int vl;
77 int nxfpr_bank;
78 int nxpr_use;
79 int nfpr_use;
80 processor_t* uts[MAX_UTS];
81
82 // this constructor is used for each of the uts
83 processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id, uint32_t _utidx);
84
85 friend class sim_t;
86 friend class mmu_t;
87
88 #include "dispatch.h"
89 };
90
91 #ifndef RISCV_ENABLE_RVC
92 # define set_pc(x) \
93 do { if((x) & (sizeof(insn_t)-1)) \
94 { badvaddr = (x); throw trap_instruction_address_misaligned; } \
95 npc = (x); \
96 } while(0)
97 #else
98 # define set_pc(x) \
99 do { if((x) & ((sr & SR_EC) ? 1 : 3)) \
100 { badvaddr = (x); throw trap_instruction_address_misaligned; } \
101 npc = (x); \
102 } while(0)
103 #endif
104
105 #endif