-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPU.h
71 lines (53 loc) · 1.13 KB
/
CPU.h
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
#ifndef __CPU_H
#define __CPU_H
#include <iostream>
#include <cstdint>
#include <string>
#include <iomanip>
#include <cstdlib>
#include "Memory.h"
#include "ALU.h"
#include "Debug.h"
#include "Stats.h"
using namespace std;
class CPU {
private:
static const int NREGS = 32;
static const string regNames[];
static const int REG_ZERO = 0;
static const int REG_RA = 31;
static const int REG_HILO = 32;
uint32_t pc;
uint32_t instr;
// Register file
uint32_t regFile[NREGS];
uint32_t hi, lo;
Stats stats;
ALU alu;
Memory &iMem;
Memory &dMem;
int instructions;
bool stop;
// Control signals
bool opIsLoad, opIsStore, opIsMultDiv;
ALU_OP aluOp;
bool writeDest;
int destReg;
uint32_t aluSrc1, aluSrc2;
uint32_t storeData;
// Wires between stages
uint32_t aluOut;
uint32_t writeData;
public:
CPU(uint32_t pc, Memory &iMem, Memory &dMem);
void run();
void printFinalStats();
private:
void fetch();
void decode();
void execute();
void mem();
void writeback();
void printRegFile();
};
#endif