25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: file.c,v 1.96 2005/06/02 12:31:39 debug Exp $ |
* $Id: file.c,v 1.99 2005/06/26 09:21:28 debug Exp $ |
29 |
* |
* |
30 |
* This file contains functions which load executable images into (emulated) |
* This file contains functions which load executable images into (emulated) |
31 |
* memory. File formats recognized so far: |
* memory. File formats recognized so far: |
165 |
symbsize = 0; |
symbsize = 0; |
166 |
fseek(f, 0, SEEK_END); |
fseek(f, 0, SEEK_END); |
167 |
/* This is of course wrong, but should work anyway: */ |
/* This is of course wrong, but should work anyway: */ |
168 |
textsize = ftell(f) - 512; |
textsize = ftello(f) - 512; |
169 |
datasize = 0; |
datasize = 0; |
170 |
fseek(f, 512, SEEK_SET); |
fseek(f, 512, SEEK_SET); |
171 |
} else { |
} else { |
226 |
char *string_symbols; |
char *string_symbols; |
227 |
off_t oldpos; |
off_t oldpos; |
228 |
|
|
229 |
debug("symbols: %i bytes @ 0x%x\n", symbsize, (int)ftell(f)); |
debug("symbols: %i bytes @ 0x%x\n", symbsize, (int)ftello(f)); |
230 |
syms = malloc(symbsize); |
syms = malloc(symbsize); |
231 |
if (syms == NULL) { |
if (syms == NULL) { |
232 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
239 |
exit(1); |
exit(1); |
240 |
} |
} |
241 |
|
|
242 |
oldpos = ftell(f); |
oldpos = ftello(f); |
243 |
fseek(f, 0, SEEK_END); |
fseek(f, 0, SEEK_END); |
244 |
strings_len = ftell(f) - oldpos; |
strings_len = ftello(f) - oldpos; |
245 |
fseek(f, oldpos, SEEK_SET); |
fseek(f, oldpos, SEEK_SET); |
246 |
debug("strings: %i bytes @ 0x%x\n", strings_len, (int)ftell(f)); |
debug("strings: %i bytes @ 0x%x\n", strings_len,(int)ftello(f)); |
247 |
string_symbols = malloc(strings_len); |
string_symbols = malloc(strings_len); |
248 |
if (string_symbols == NULL) { |
if (string_symbols == NULL) { |
249 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
474 |
if (s_scnptr != 0 && s_size != 0 && |
if (s_scnptr != 0 && s_size != 0 && |
475 |
s_vaddr != 0 && !(s_flags & 0x02)) { |
s_vaddr != 0 && !(s_flags & 0x02)) { |
476 |
/* Remember the current file offset: */ |
/* Remember the current file offset: */ |
477 |
oldpos = ftell(f); |
oldpos = ftello(f); |
478 |
|
|
479 |
/* Load the section into emulated memory: */ |
/* Load the section into emulated memory: */ |
480 |
fseek(f, s_scnptr, SEEK_SET); |
fseek(f, s_scnptr, SEEK_SET); |
900 |
} |
} |
901 |
|
|
902 |
debug("RAW: 0x%llx bytes @ 0x%08llx", |
debug("RAW: 0x%llx bytes @ 0x%08llx", |
903 |
(long long) (ftell(f) - skip), (long long)loadaddr); |
(long long) (ftello(f) - skip), (long long)loadaddr); |
904 |
if (skip != 0) |
if (skip != 0) |
905 |
debug(" (0x%llx bytes of header skipped)", (long long)skip); |
debug(" (0x%llx bytes of header skipped)", (long long)skip); |
906 |
debug("\n"); |
debug("\n"); |
1211 |
|
|
1212 |
debug(" len=0x%llx\n", (long long)p_memsz); |
debug(" len=0x%llx\n", (long long)p_memsz); |
1213 |
|
|
1214 |
if (p_vaddr != p_paddr) { |
if (p_vaddr != p_paddr) |
1215 |
fprintf(stderr, "%s: vaddr != paddr. TODO: " |
fatal("WARNING! vaddr (0x%llx) and paddr " |
1216 |
"how to handle this? vaddr=%016llx paddr" |
"(0x%llx) differ; using vaddr\n", |
1217 |
"=%016llx\n", filename, (long long)p_vaddr, |
(long long)p_vaddr, (long long)p_paddr); |
|
(long long)p_paddr); |
|
|
exit(1); |
|
|
} |
|
1218 |
|
|
1219 |
if (p_memsz < p_filesz) { |
if (p_memsz < p_filesz) { |
1220 |
fprintf(stderr, "%s: memsz < filesz. TODO: how" |
fprintf(stderr, "%s: memsz < filesz. TODO: how" |
1577 |
} |
} |
1578 |
|
|
1579 |
fseek(f, 0, SEEK_END); |
fseek(f, 0, SEEK_END); |
1580 |
size = ftell(f); |
size = ftello(f); |
1581 |
fseek(f, 0, SEEK_SET); |
fseek(f, 0, SEEK_SET); |
1582 |
|
|
1583 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |