-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU-simulator.cpp
More file actions
202 lines (169 loc) · 3.61 KB
/
Copy pathCPU-simulator.cpp
File metadata and controls
202 lines (169 loc) · 3.61 KB
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
// CPU-simulator.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "CPU-simulator.h"
#include "ini.h"
#include <string.h>
int _tmain(int argc, char* argv[])
{
ConfigurationStruk configuration;
Memory memory;
int tmp=10;
if(argc!=2)
{
printf("Wronge command line arguments number!\n");
exit(1);
}
if (ini_parse(argv[1], handler, &configuration) < 0) {
printf("Can't load '%s' file\n",argv[1]);
return 1;
}
printf("%X",tmp);
// ReadInitMemory(argv[3],&memory);
getch();
return 0;
}
//private function used by ini_parse
static int handler(void* user, const char* section, const char* name,
const char* value)
{
ConfigurationStruk* pconfig = (ConfigurationStruk*)user;
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if (MATCH("", "addsub_delay"))
{
pconfig->addsub_delay = atoi(value);
}
else if (MATCH("", "mul_delay"))
{
pconfig->mul_delay = atoi(value);
}
else if (MATCH("", "div_delay"))
{
pconfig->div_delay = atoi(value);
}
else if (MATCH("", "instruction_q_depth"))
{
pconfig->instruction_q_depth = atoi(value);
}
else if (MATCH("", "addsub_rs"))
{
pconfig->addsub_rs = atoi(value);
}
else if (MATCH("", "muldiv_rs"))
{
pconfig->muldiv_rs = atoi(value);
}
else if (MATCH("", "load_q_depth"))
{
pconfig->load_q_depth = atoi(value);
}
else if (MATCH("", "reorder_buffer"))
{
pconfig->reorder_buffer = atoi(value);
}
else if (MATCH("", "ghr_width"))
{
pconfig->ghr_width = atoi(value);
}
else if (MATCH("", "two_threads_enabled"))
{
pconfig->two_threads_enabled = atoi(value);
}
else if (MATCH("", "l1_block_size"))
{
pconfig->l1_block_size = atoi(value);
}
else if (MATCH("", "l1_access_delay"))
{
pconfig->l1_access_delay = atoi(value);
}
else if (MATCH("", "l1_cache_size"))
{
pconfig->l1_cache_size = atoi(value);
}
else if (MATCH("", "l2_block_size"))
{
pconfig->l2_block_size = atoi(value);
}
else if (MATCH("", "l2_access_delay"))
{
pconfig->l2_access_delay = atoi(value);
}
else if (MATCH("", "l2_cache_size"))
{
pconfig->l2_cache_size = atoi(value);
}
else if (MATCH("", "mem_access_delay"))
{
pconfig->mem_access_delay = atoi(value);
}
else
{
return 0; /* unknown section/name, error */
}
return 1;
}
int WriteRegisterDumpToFile(char *file_name, RegisterDump *regdump)
{
FILE *file=fopen(file_name,"w");
int i;
if (file==NULL)
{
printf("error in write registery dump file\n %s %s ",__FILE__,__LINE__);
return 0;
}
for(i=0;i<NUMBER_OF_REGISTERS;i++)
{
fprintf(file,"$%d %d\n",i,regdump->reg[i]);
}
fclose(file);
return 1;
}
int WriteMemoryDumpToFile(char *file_name, Memory *memory)
{
FILE *file=fopen(file_name,"w");
int i;
if (file==NULL)
{
printf("error in write memory dump file\n %s %s ",__FILE__,__LINE__);
return 0;
}
for(i=0;i<MEMORY_SIZE;i++)
{
if(i%8==0)
fprintf(file,"%X ",memory->mem[i]);
else
fprintf(file,"\n");
}
fclose(file);
return 1;
}
int ParseCMDfile(char *file_name, Memory *memory, RegisterDump *regdump)
{
FILE *file=fopen(file_name,"w");
char lineBuffer[MAX_LINE_SIZE];
if (file==NULL)
{
printf("error in write CMD file\n %s %s ",__FILE__,__LINE__);
return 0;
}
while ( fgets ( lineBuffer, sizeof lineBuffer, file ) != NULL )
{
ExecuteCMD(lineBuffer,memory, regdump);
}
fclose(file);
return 1;
}
void ExecuteCMD(char *lineBuffer,Memory *memory ,RegisterDump *regdump)
{
char *p;//iterator over the string to tokenize
char cmd[5][10];//to store the command line
p=strtok(lineBuffer, " ");
while(p!=NULL)
{
//TODO
p = strtok (NULL, " ");
}
}