7 uint32_t a_info
; /* Use macros N_MAGIC, etc for access */
8 uint32_t a_text
; /* length of text, in bytes */
9 uint32_t a_data
; /* length of data, in bytes */
10 uint32_t a_bss
; /* length of uninitialized data area, in bytes */
11 uint32_t a_syms
; /* length of symbol table data in file, in bytes */
12 uint32_t a_entry
; /* start address */
13 uint32_t a_trsize
; /* length of relocation info for text, in bytes */
14 uint32_t a_drsize
; /* length of relocation info for data, in bytes */
18 static void bswap_ahdr(struct exec
*e
)
25 bswap32s(&e
->a_entry
);
26 bswap32s(&e
->a_trsize
);
27 bswap32s(&e
->a_drsize
);
30 #define bswap_ahdr(x) do { } while (0)
33 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
38 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
40 (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
41 (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
42 #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? TARGET_PAGE_SIZE : 0)
43 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
44 #define _N_SEGMENT_ROUND(x) (((x) + TARGET_PAGE_SIZE - 1) & ~(TARGET_PAGE_SIZE - 1))
46 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
48 #define N_DATADDR(x) \
49 (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
50 : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
53 #define ELF_CLASS ELFCLASS32
54 #define ELF_DATA ELFDATA2MSB
55 #define ELF_ARCH EM_SPARC
60 #define bswap_ehdr32(e) do { } while (0)
61 #define bswap_phdr32(e) do { } while (0)
62 #define bswap_shdr32(e) do { } while (0)
63 #define bswap_sym32(e) do { } while (0)
65 #define bswap_ehdr64(e) do { } while (0)
66 #define bswap_phdr64(e) do { } while (0)
67 #define bswap_shdr64(e) do { } while (0)
68 #define bswap_sym64(e) do { } while (0)
73 #define elf_word uint32_t
74 #define bswapSZs bswap32s
86 #define elfhdr elf64_hdr
87 #define elf_phdr elf64_phdr
88 #define elf_note elf64_note
89 #define elf_shdr elf64_shdr
90 #define elf_sym elf64_sym
91 #define elf_word uint64_t
92 #define bswapSZs bswap64s
97 int load_elf(const char *filename
, uint8_t *addr
)
99 struct elf32_hdr ehdr
;
103 fd
= open(filename
, O_RDONLY
| O_BINARY
);
107 retval
= read(fd
, &ehdr
, sizeof(ehdr
));
111 if (ehdr
.e_ident
[0] != 0x7f || ehdr
.e_ident
[1] != 'E'
112 || ehdr
.e_ident
[2] != 'L' || ehdr
.e_ident
[3] != 'F')
114 machine
= tswap16(ehdr
.e_machine
);
115 if (machine
== EM_SPARC
|| machine
== EM_SPARC32PLUS
) {
116 struct elf32_phdr phdr
;
120 if (find_phdr32(&ehdr
, fd
, &phdr
, PT_LOAD
))
122 retval
= read_program32(fd
, &phdr
, addr
, ehdr
.e_entry
);
125 load_symbols32(&ehdr
, fd
);
127 #ifdef TARGET_SPARC64
128 else if (machine
== EM_SPARCV9
) {
129 struct elf64_hdr ehdr64
;
130 struct elf64_phdr phdr
;
132 lseek(fd
, 0, SEEK_SET
);
134 retval
= read(fd
, &ehdr64
, sizeof(ehdr64
));
138 bswap_ehdr64(&ehdr64
);
140 if (find_phdr64(&ehdr64
, fd
, &phdr
, PT_LOAD
))
142 retval
= read_program64(fd
, &phdr
, phys_ram_base
+ ehdr64
.e_entry
, ehdr64
.e_entry
);
145 load_symbols64(&ehdr64
, fd
);
156 int load_aout(const char *filename
, uint8_t *addr
)
162 fd
= open(filename
, O_RDONLY
| O_BINARY
);
166 size
= read(fd
, &e
, sizeof(e
));
177 lseek(fd
, N_TXTOFF(e
), SEEK_SET
);
178 size
= read(fd
, addr
, e
.a_text
+ e
.a_data
);
183 lseek(fd
, N_TXTOFF(e
), SEEK_SET
);
184 size
= read(fd
, addr
, e
.a_text
);
187 ret
= read(fd
, addr
+ N_DATADDR(e
), e
.a_data
);