43 static void file_load_srec(
struct machine *m,
struct memory *mem,
44 char *filename, uint64_t *entrypointp)
47 unsigned char buf[516];
48 unsigned char bytes[270];
49 uint64_t entry = 0, vaddr = 0;
52 int buf_len, data_start = 0;
56 int total_bytes_loaded = 0;
58 f = fopen(filename,
"r");
66 memset(buf, 0,
sizeof(buf));
67 if (fgets((
char *)buf,
sizeof(buf)-1,
f) == NULL ||
68 buf[0] == 0 || buf[0]==
'\r' || buf[0]==
'\n')
73 debug(
"WARNING! non-S-record found\n");
78 buf_len =
strlen((
char *)buf);
82 debug(
"WARNING! invalid S-record found\n");
95 for (i=1; i<buf_len; i++) {
96 if (buf[i]>=
'a' && buf[i]<=
'f')
98 else if (buf[i] >=
'A' && buf[i] <=
'F')
100 else if (buf[i] >=
'0' && buf[i] <=
'9')
102 else if (buf[i] ==
'\r' || buf[i] ==
'\n') {
104 fatal(
"invalid characters '%c' in S-record\n",
109 bytes[j++] += buf[i];
111 bytes[j] = buf[i] * 16;
115 count = buf[2] * 16 + buf[3];
122 for (i=2; i<count-1; i++) {
124 if (ch >=
' ' && ch < 127)
136 case 1: data_start = 2;
137 vaddr = (bytes[0] << 8) + bytes[1];
139 case 2: data_start = 3;
140 vaddr = (bytes[0] << 16) + (bytes[1] << 8) +
143 case 3: data_start = 4;
144 vaddr = ((uint64_t)bytes[0] << 24) +
145 (bytes[1] << 16) + (bytes[2]<<8) + bytes[3];
148 &bytes[data_start], count - 1 - data_start,
150 total_bytes_loaded += count - 1 - data_start;
157 case 7: entry = ((uint64_t)bytes[0] << 24) +
158 (bytes[1] << 16) + (bytes[2]<<8) + bytes[3];
160 case 8: entry = (bytes[0] << 16) + (bytes[1] << 8) +
163 case 9: entry = (bytes[0] << 8) + bytes[1];
167 debug(
"entry point 0x%08x\n", (
unsigned int)entry);
170 debug(
"unimplemented S-record type %i\n", buf[1]);
174 debug(
"0x%x bytes loaded\n", total_bytes_loaded);
179 debug(
"WARNING! no entrypoint found!\n");
181 *entrypointp = entry;
183 n_executables_loaded ++;