-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.cpp
executable file
·58 lines (44 loc) · 1.02 KB
/
loader.cpp
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
#include"loader.h"
#include"allstdlib.h"
Loader::Loader()
{
ldfile = NULL;
}
Loader::Loader(char* s)
{
ldfile = fopen(s,"r");
if(ldfile == NULL) exit(1);
}
void Loader::setFile(char* s)
{
if(ldfile != NULL)
fclose(ldfile);
ldfile = fopen(s,"r");
}
int Loader::loadmem(int start , mem m[],char endian)
{
uint32_t x;uint32_t bigendian;
char c,data[17];
//TODO-get an instance of memory and load ldfile from start pos
while((c = fgetc(ldfile)) != EOF)
{
ungetc(c,ldfile);
REP(i,0,7)//TODO - take in 8 hex letters (1 hex letter 1 nibble- write instructions bitwise)
{
if(c = fgetc(ldfile))
data[i] = c;
else
exit(3);
}
data[8] = '\0';
//TODO - check big or little endian swap if necessary
x =(uint32_t) strtoul(data,NULL,16); //TODO - convert string to uint64_t
if(endian == 'L')
bigendian = __builtin_bswap32(x);
else
bigendian = x;
start = setDataW(m,bigendian,start);//TODO - write to mem 32 bit word
//start++;
}//TODO - repeat from (a) until EOF
return start;
}