forked from HYLcool/ourspike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine.h
99 lines (81 loc) · 1.64 KB
/
machine.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// machine.h
// define the machine class
// which runs the program that has been stored in the memory
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <unistd.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "Instruction.h"
#include "Register.h"
#include "Stack.h"
#include "field.h"
#include "loader.h"
// size of data
#define INSTR_SIZE 4
#define BYTE_SIZE 1
#define HALF_SIZE 2
#define WORD_SIZE 4
#define DOUBLE_WORD_SIZE 8
#define FLOAT_SIZE 4
#define DOUBLE_SIZE 8
// syscall
#define SYS_EXIT 93
#define SYS_READ 63
#define SYS_WRITE 64
#define SYS_GET_TIME_OF_DAY 169
#define SYS_BRK 214
#define SYS_FSTAT 80
#define SYS_LSEEK 62
#define SYS_CLOSE 57
#define STACK_POINTER 0x30000
using namespace std;
class Machine {
public:
Machine(bool, bool);
~Machine();
void Run();
void Fetch();
void Execute();
void WriteBack();
void WriteMemory();
void setFileName(string );
private:
Instruction * instr;
Register * reg;
Stack * stack;
Memory * mem;
Loadelf * loader;
// file
string filename;
// record whether we need to write into register or write into memory
bool wb;
bool wm;
bool exeI;
bool exeF;
bool proFinished;
// some extra functions
// instruction count
bool ic;
int count;
// debug
bool db;
// result of ALU
long long unsigned resi;
double resf;
unsigned char rd;
int memsize;
int memadd;
long long unsigned data;
int SExtension(int);
unsigned UExtension(int);
int LLU2INT(long long unsigned);
unsigned LLU2UNS(long long unsigned);
long long unsigned INT2LLU(int);
long long unsigned UNS2LLU(unsigned);
void PrintMessage();
};