per-core tohost/fromhost registers
[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 reset();
24 void step(size_t n, bool noisy); // run for n cycles
25 void deliver_ipi(); // register an interprocessor interrupt
26 bool running() { return run; }
27 void set_pcr(int which, reg_t val);
28 reg_t get_pcr(int which);
29
30 private:
31 sim_t& sim;
32 mmu_t& mmu; // main memory is always accessed via the mmu
33
34 // user-visible architected state
35 regfile_t<reg_t, NXPR, true> XPR;
36 regfile_t<freg_t, NFPR, false> FPR;
37 reg_t pc;
38
39 // counters
40 reg_t cycle;
41
42 // privileged control registers
43 reg_t epc;
44 reg_t badvaddr;
45 reg_t evec;
46 reg_t pcr_k0;
47 reg_t pcr_k1;
48 reg_t cause;
49 reg_t tohost;
50 reg_t fromhost;
51 uint32_t interrupts_pending;
52 uint32_t id;
53 uint32_t sr; // only modify the status register using set_pcr()
54 uint32_t fsr;
55 uint32_t count;
56 uint32_t compare;
57
58 // # of bits in an XPR (32 or 64). (redundant with sr)
59 int xprlen;
60
61 // is this processor running? (deliver_ipi() sets this)
62 bool run;
63
64 // functions
65 void take_interrupt(); // take a trap if any interrupts are pending
66 void set_fsr(uint32_t val); // set the floating-point status register
67 void take_trap(reg_t t, bool noisy); // take an exception
68 void disasm(insn_t insn, reg_t pc); // disassemble and print an instruction
69
70 // vector stuff
71 void vcfg();
72 void setvl(int vlapp);
73
74 reg_t vecbanks;
75 uint32_t vecbanks_count;
76
77 bool utmode;
78 uint32_t utidx;
79 int vlmax;
80 int vl;
81 int nxfpr_bank;
82 int nxpr_use;
83 int nfpr_use;
84 processor_t* uts[MAX_UTS];
85
86 // this constructor is used for each of the uts
87 processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id, uint32_t _utidx);
88
89 friend class sim_t;
90 friend class mmu_t;
91
92 #include "dispatch.h"
93 };
94
95 #ifndef RISCV_ENABLE_RVC
96 # define set_pc(x) \
97 do { if((x) & (sizeof(insn_t)-1)) \
98 { badvaddr = (x); throw trap_instruction_address_misaligned; } \
99 npc = (x); \
100 } while(0)
101 #else
102 # define set_pc(x) \
103 do { if((x) & ((sr & SR_EC) ? 1 : 3)) \
104 { badvaddr = (x); throw trap_instruction_address_misaligned; } \
105 npc = (x); \
106 } while(0)
107 #endif
108
109 #endif