-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruction.h
203 lines (155 loc) · 4.31 KB
/
instruction.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//#include "useful-functions.h"
#include "register.h"
#include <iostream>
#include <limits>
#include <map>
/**
*
*
**/
class instruction{
public:
// Various Constructors for different scenarios
instruction ();
instruction (std::string command, reg* ar1);
instruction (std::string command, uint32_t ar1);
instruction (std::string command, reg* ar1, reg* ar2);
instruction (std::string command, reg* ar1, uint32_t ar2);
instruction (std::string command, reg* ar1, reg* ar2, reg* ar3);
instruction (std::string command, reg* ar1, uint32_t ar2, uint32_t ar3);
instruction (std::string command, reg* ar1, reg* ar2, uint32_t ar3);
instruction (std::string command, reg* ar1, uint32_t ar2, reg* ar3);
enum enum_operats{
// X designates that it has been implemented
UNDEFINED,
ADC,
ADD, // X
AND, // X
B, // X
BIC, // X
BL, // Got my eyes on you
BX, // you too laddy
BLX,
CDP,
CMN,
CMP,
EOR, // X
LDC,
LDM,
LDR,
MCR,
MLA,
MOV, // X
MRC,
MRS,
MSR,
MUL, // X
MVN,
ORR, // X
RSB,
RSC,
SBC,
STC,
STM,
STR,
SUB, // X
SWI,
SWP,
TEQ,
TST
};
enum enum_condition_code{
UNDEFINED_C,
NO_COND_CODE,
EQ,
NE,
CS,
CC,
MI,
PL,
VS,
VC,
HI,
LS,
GE,
LT,
GT,
LE,
AL
};
// Get Machine code 32 bit instruction
uint32_t getMachineInstruction ();
// Set condition Flags pointer
void setCondFlags (uint8_t *ptr);
void setSpecialRegPointer (reg* p, reg* l, reg* s);
void setinstructStr (std::string str);
enum_operats string2Operats (std::string input);
// Called by Emulator to execute each instruction independently
void execute ();
void printInstructionInfo ();
void printInstructionStr ();
private:
// To be implemented soon !!!!!
void generateMachineInstruction ();
// Returns true if string contains a S to designate flag updates
bool updateFlags (std::string instruc, int command_length);
// returns condition code
enum_condition_code getCondCode (std::string instruc, int command_length);
// check if there is any conditions to execution (condition codes (EQ etc.))
bool executePermission ();
// helper function that updates N and Z flags when called
void updateNegZero ();
//Helper funcions to modify flags
void set_N_High ();
void set_N_Low ();
void set_Z_High ();
void set_Z_Low ();
void set_C_High ();
void set_C_Low ();
void set_V_High ();
void set_V_Low ();
// Helper functions to test uint32_t traits
bool isNeg (uint32_t num);
bool isDiffSigns (uint32_t num1, uint32_t num2);
// Helper functions for execute () to keep code clean and maintainable
void executeADD ();
void executeAND ();
void executeB ();
void executeBL ();
void executeBX ();
void executeBLX ();
void executeBIC ();
void executeCMP ();
void executeEOR ();
void executeMOV ();
void executeMUL ();
void executeORR ();
void executeSUB ();
// what the instuction line initial displayed
std::string instructStr;
// General Organisation Variables
uint8_t numberOperands;
// MOV, SUB etc.
enum_operats Operat;
enum_condition_code cond_code;
// Register arguments
reg* opperand1;
reg* opperand2;
reg* opperand3;
// Pointer to PC register (needed for branching)
reg* pc;
reg* lr;
reg* sp;
// Non-register arguments
uint32_t NR_operand1;
uint32_t NR_operand2; // Not Register Opperands
uint32_t NR_operand3;
// Pointer to cond flags which are owned by ARM-file
uint8_t *cond_flags;
// Should cond_flags be updated with this instruction (i.e. is s present)
bool update_flag;
// instruction and opperands coverted into a 32 bit instruction
uint32_t machineInstruction;
// Has MachineCode been generated yet
bool machineCodeGenerated;
};