25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: file_elf.c,v 1.2 2007/04/18 14:08:35 debug Exp $ |
* $Id: file_elf.c,v 1.5 2007/06/15 17:02:39 debug Exp $ |
29 |
* |
* |
30 |
* ELF file support. |
* ELF file support. |
31 |
*/ |
*/ |
215 |
ok = 1; |
ok = 1; |
216 |
} |
} |
217 |
break; |
break; |
218 |
case ARCH_AVR: |
/* case ARCH_AVR: |
219 |
switch (emachine) { |
switch (emachine) { |
220 |
case EM_AVR: |
case EM_AVR: |
221 |
ok = 1; |
ok = 1; |
222 |
} |
} |
223 |
break; |
break; |
224 |
/* case ARCH_AVR32: |
case ARCH_AVR32: |
225 |
switch (emachine) { |
switch (emachine) { |
226 |
case 6317: |
case 6317: |
227 |
ok = 1; |
ok = 1; |
320 |
* SH64: 32-bit instruction encoding? |
* SH64: 32-bit instruction encoding? |
321 |
*/ |
*/ |
322 |
if (arch == ARCH_SH && (eentry & 1)) { |
if (arch == ARCH_SH && (eentry & 1)) { |
323 |
debug("SH64: 32-bit instruction encoding\n"); |
fatal("SH64: 32-bit instruction encoding: TODO\n"); |
324 |
m->cpus[0]->cd.sh.compact = 0; |
/* m->cpus[0]->cd.sh.compact = 0; */ |
325 |
m->cpus[0]->cd.sh.cpu_type.bits = 64; |
m->cpus[0]->cd.sh.cpu_type.bits = 64; |
326 |
|
exit(1); |
327 |
} |
} |
328 |
|
|
329 |
/* Read the program headers: */ |
/* Read the program headers: */ |
422 |
if ((p_vaddr & 0xffff)==0) align_len = 0x10000; |
if ((p_vaddr & 0xffff)==0) align_len = 0x10000; |
423 |
ofs = 0; len = chunk_len = align_len; |
ofs = 0; len = chunk_len = align_len; |
424 |
while (ofs < (int64_t)p_filesz && len==chunk_len) { |
while (ofs < (int64_t)p_filesz && len==chunk_len) { |
425 |
unsigned char *ch = malloc(chunk_len); |
unsigned char *ch; |
426 |
int i = 0; |
int i = 0; |
427 |
|
|
428 |
|
CHECK_ALLOCATION(ch = malloc(chunk_len)); |
429 |
|
|
430 |
/* Switch to larger size, if possible: */ |
/* Switch to larger size, if possible: */ |
431 |
if (align_len < 0x10000 && |
if (align_len < 0x10000 && |
432 |
((p_vaddr + ofs) & 0xffff)==0) { |
((p_vaddr + ofs) & 0xffff)==0) { |
433 |
align_len = 0x10000; |
align_len = 0x10000; |
434 |
len = chunk_len = align_len; |
len = chunk_len = align_len; |
435 |
free(ch); |
free(ch); |
436 |
ch = malloc(chunk_len); |
CHECK_ALLOCATION(ch=malloc(chunk_len)); |
437 |
} else if (align_len < 0x1000 && |
} else if (align_len < 0x1000 && |
438 |
((p_vaddr + ofs) & 0xfff)==0) { |
((p_vaddr + ofs) & 0xfff)==0) { |
439 |
align_len = 0x1000; |
align_len = 0x1000; |
440 |
len = chunk_len = align_len; |
len = chunk_len = align_len; |
441 |
free(ch); |
free(ch); |
442 |
ch = malloc(chunk_len); |
CHECK_ALLOCATION(ch=malloc(chunk_len)); |
|
} |
|
|
|
|
|
if (ch == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
443 |
} |
} |
444 |
|
|
445 |
len = fread(&ch[0], 1, chunk_len, f); |
len = fread(&ch[0], 1, chunk_len, f); |
533 |
if (elf64) { |
if (elf64) { |
534 |
if (symbols_sym64 != NULL) |
if (symbols_sym64 != NULL) |
535 |
free(symbols_sym64); |
free(symbols_sym64); |
536 |
symbols_sym64 = malloc(sh_size); |
|
537 |
if (symbols_sym64 == NULL) { |
CHECK_ALLOCATION(symbols_sym64 = |
538 |
fprintf(stderr, "out of memory\n"); |
malloc(sh_size)); |
|
exit(1); |
|
|
} |
|
539 |
|
|
540 |
len = fread(symbols_sym64, 1, sh_entsize * |
len = fread(symbols_sym64, 1, sh_entsize * |
541 |
n_entries, f); |
n_entries, f); |
542 |
} else { |
} else { |
543 |
if (symbols_sym32 != NULL) |
if (symbols_sym32 != NULL) |
544 |
free(symbols_sym32); |
free(symbols_sym32); |
545 |
symbols_sym32 = malloc(sh_size); |
|
546 |
if (symbols_sym32 == NULL) { |
CHECK_ALLOCATION(symbols_sym32 = |
547 |
fprintf(stderr, "out of memory\n"); |
malloc(sh_size)); |
|
exit(1); |
|
|
} |
|
548 |
|
|
549 |
len = fread(symbols_sym32, 1, |
len = fread(symbols_sym32, 1, |
550 |
sh_entsize * n_entries, f); |
sh_entsize * n_entries, f); |
576 |
if (symbol_strings != NULL) |
if (symbol_strings != NULL) |
577 |
free(symbol_strings); |
free(symbol_strings); |
578 |
|
|
579 |
symbol_strings = malloc(sh_size + 1); |
CHECK_ALLOCATION(symbol_strings = malloc(sh_size + 1)); |
|
if (symbol_strings == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
580 |
|
|
581 |
fseek(f, sh_offset, SEEK_SET); |
fseek(f, sh_offset, SEEK_SET); |
582 |
len = fread(symbol_strings, 1, sh_size, f); |
len = fread(symbol_strings, 1, sh_size, f); |