aboutsummaryrefslogtreecommitdiff
path: root/riscv/processor.h
blob: 5c524c0fef183834c5b523f3c91ffc7d2f704a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _RISCV_PROCESSOR_H
#define _RISCV_PROCESSOR_H

#include "decode.h"
#include <cstring>
#include "trap.h"
#include "mmu.h"
#include "icsim.h"

#define MAX_UTS 32

class sim_t;

class processor_t
{
public:
  processor_t(sim_t* _sim, char* _mem, size_t _memsz);
  ~processor_t();
  void init(uint32_t _id);
  void step(size_t n, bool noisy);

private:
  sim_t* sim;

  // architected state
  reg_t XPR[NXPR];
  freg_t FPR[NFPR];

  // privileged control registers
  reg_t pc;
  reg_t epc;
  reg_t badvaddr;
  reg_t cause;
  reg_t evec;
  reg_t tohost;
  reg_t fromhost;
  reg_t pcr_k0;
  reg_t pcr_k1;
  uint32_t id;
  uint32_t sr;
  uint32_t count;
  uint32_t compare;

  // unprivileged control registers
  uint32_t fsr;

  // # of bits in an XPR (32 or 64). (redundant with sr)
  int xprlen;

  // shared memory
  mmu_t mmu;

  // counters
  reg_t counters[32];

  // functions
  void set_sr(uint32_t val);
  void set_fsr(uint32_t val);
  void take_trap(trap_t t, bool noisy);
  void disasm(insn_t insn, reg_t pc);

  // vector stuff
  void vcfg();
  void setvl(int vlapp);

  bool utmode;
  int utidx;
  int vlmax;
  int vl;
  int nxpr_all;
  int nfpr_all;
  int nxpr_use;
  int nfpr_use;
  processor_t* uts[MAX_UTS];

  // icache sim
  icsim_t* icsim;

  friend class sim_t;
};

#endif