diff options
Diffstat (limited to 'arch/x86/boot/compressed')
-rw-r--r-- | arch/x86/boot/compressed/Makefile | 8 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_32.S | 5 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_64.S | 5 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.c | 110 | ||||
-rw-r--r-- | arch/x86/boot/compressed/relocs.c | 198 |
5 files changed, 159 insertions, 167 deletions
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 92fdd35bd93e..1771c804e02f 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile | |||
@@ -27,9 +27,8 @@ $(obj)/vmlinux.bin: vmlinux FORCE | |||
27 | $(call if_changed,objcopy) | 27 | $(call if_changed,objcopy) |
28 | 28 | ||
29 | 29 | ||
30 | ifeq ($(CONFIG_X86_32),y) | 30 | targets += vmlinux.bin.all vmlinux.relocs relocs |
31 | targets += vmlinux.bin.all vmlinux.relocs | 31 | hostprogs-$(CONFIG_X86_32) += relocs |
32 | hostprogs-y := relocs | ||
33 | 32 | ||
34 | quiet_cmd_relocs = RELOCS $@ | 33 | quiet_cmd_relocs = RELOCS $@ |
35 | cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $< | 34 | cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $< |
@@ -43,6 +42,8 @@ quiet_cmd_relocbin = BUILD $@ | |||
43 | $(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE | 42 | $(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE |
44 | $(call if_changed,relocbin) | 43 | $(call if_changed,relocbin) |
45 | 44 | ||
45 | ifeq ($(CONFIG_X86_32),y) | ||
46 | |||
46 | ifdef CONFIG_RELOCATABLE | 47 | ifdef CONFIG_RELOCATABLE |
47 | $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE | 48 | $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE |
48 | $(call if_changed,gzip) | 49 | $(call if_changed,gzip) |
@@ -59,6 +60,5 @@ $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE | |||
59 | LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T | 60 | LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T |
60 | endif | 61 | endif |
61 | 62 | ||
62 | |||
63 | $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE | 63 | $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE |
64 | $(call if_changed,ld) | 64 | $(call if_changed,ld) |
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index ba7736cf2ec7..29c5fbf08392 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S | |||
@@ -137,14 +137,15 @@ relocated: | |||
137 | */ | 137 | */ |
138 | movl output_len(%ebx), %eax | 138 | movl output_len(%ebx), %eax |
139 | pushl %eax | 139 | pushl %eax |
140 | # push arguments for decompress_kernel: | ||
140 | pushl %ebp # output address | 141 | pushl %ebp # output address |
141 | movl input_len(%ebx), %eax | 142 | movl input_len(%ebx), %eax |
142 | pushl %eax # input_len | 143 | pushl %eax # input_len |
143 | leal input_data(%ebx), %eax | 144 | leal input_data(%ebx), %eax |
144 | pushl %eax # input_data | 145 | pushl %eax # input_data |
145 | leal boot_heap(%ebx), %eax | 146 | leal boot_heap(%ebx), %eax |
146 | pushl %eax # heap area as third argument | 147 | pushl %eax # heap area |
147 | pushl %esi # real mode pointer as second arg | 148 | pushl %esi # real mode pointer |
148 | call decompress_kernel | 149 | call decompress_kernel |
149 | addl $20, %esp | 150 | addl $20, %esp |
150 | popl %ecx | 151 | popl %ecx |
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index d8819efac81d..1d5dff4123e1 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <asm/page.h> | 30 | #include <asm/page.h> |
31 | #include <asm/boot.h> | 31 | #include <asm/boot.h> |
32 | #include <asm/msr.h> | 32 | #include <asm/msr.h> |
33 | #include <asm/processor-flags.h> | ||
33 | #include <asm/asm-offsets.h> | 34 | #include <asm/asm-offsets.h> |
34 | 35 | ||
35 | .section ".text.head" | 36 | .section ".text.head" |
@@ -109,7 +110,7 @@ startup_32: | |||
109 | 110 | ||
110 | /* Enable PAE mode */ | 111 | /* Enable PAE mode */ |
111 | xorl %eax, %eax | 112 | xorl %eax, %eax |
112 | orl $(1 << 5), %eax | 113 | orl $(X86_CR4_PAE), %eax |
113 | movl %eax, %cr4 | 114 | movl %eax, %cr4 |
114 | 115 | ||
115 | /* | 116 | /* |
@@ -170,7 +171,7 @@ startup_32: | |||
170 | pushl %eax | 171 | pushl %eax |
171 | 172 | ||
172 | /* Enter paged protected Mode, activating Long Mode */ | 173 | /* Enter paged protected Mode, activating Long Mode */ |
173 | movl $0x80000001, %eax /* Enable Paging and Protected mode */ | 174 | movl $(X86_CR0_PG | X86_CR0_PE), %eax /* Enable Paging and Protected mode */ |
174 | movl %eax, %cr0 | 175 | movl %eax, %cr0 |
175 | 176 | ||
176 | /* Jump from 32bit compatibility mode into 64bit mode. */ | 177 | /* Jump from 32bit compatibility mode into 64bit mode. */ |
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 90456cee47c3..5780d361105b 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c | |||
@@ -16,7 +16,7 @@ | |||
16 | */ | 16 | */ |
17 | #undef CONFIG_PARAVIRT | 17 | #undef CONFIG_PARAVIRT |
18 | #ifdef CONFIG_X86_32 | 18 | #ifdef CONFIG_X86_32 |
19 | #define _ASM_DESC_H_ 1 | 19 | #define ASM_X86__DESC_H 1 |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #ifdef CONFIG_X86_64 | 22 | #ifdef CONFIG_X86_64 |
@@ -27,9 +27,10 @@ | |||
27 | #include <linux/linkage.h> | 27 | #include <linux/linkage.h> |
28 | #include <linux/screen_info.h> | 28 | #include <linux/screen_info.h> |
29 | #include <linux/elf.h> | 29 | #include <linux/elf.h> |
30 | #include <asm/io.h> | 30 | #include <linux/io.h> |
31 | #include <asm/page.h> | 31 | #include <asm/page.h> |
32 | #include <asm/boot.h> | 32 | #include <asm/boot.h> |
33 | #include <asm/bootparam.h> | ||
33 | 34 | ||
34 | /* WARNING!! | 35 | /* WARNING!! |
35 | * This code is compiled with -fPIC and it is relocated dynamically | 36 | * This code is compiled with -fPIC and it is relocated dynamically |
@@ -181,32 +182,23 @@ static unsigned outcnt; | |||
181 | static int fill_inbuf(void); | 182 | static int fill_inbuf(void); |
182 | static void flush_window(void); | 183 | static void flush_window(void); |
183 | static void error(char *m); | 184 | static void error(char *m); |
184 | static void gzip_mark(void **); | ||
185 | static void gzip_release(void **); | ||
186 | 185 | ||
187 | /* | 186 | /* |
188 | * This is set up by the setup-routine at boot-time | 187 | * This is set up by the setup-routine at boot-time |
189 | */ | 188 | */ |
190 | static unsigned char *real_mode; /* Pointer to real-mode data */ | 189 | static struct boot_params *real_mode; /* Pointer to real-mode data */ |
191 | 190 | static int quiet; | |
192 | #define RM_EXT_MEM_K (*(unsigned short *)(real_mode + 0x2)) | ||
193 | #ifndef STANDARD_MEMORY_BIOS_CALL | ||
194 | #define RM_ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0)) | ||
195 | #endif | ||
196 | #define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0)) | ||
197 | 191 | ||
198 | extern unsigned char input_data[]; | 192 | extern unsigned char input_data[]; |
199 | extern int input_len; | 193 | extern int input_len; |
200 | 194 | ||
201 | static long bytes_out; | 195 | static long bytes_out; |
202 | 196 | ||
203 | static void *malloc(int size); | ||
204 | static void free(void *where); | ||
205 | |||
206 | static void *memset(void *s, int c, unsigned n); | 197 | static void *memset(void *s, int c, unsigned n); |
207 | static void *memcpy(void *dest, const void *src, unsigned n); | 198 | static void *memcpy(void *dest, const void *src, unsigned n); |
208 | 199 | ||
209 | static void putstr(const char *); | 200 | static void __putstr(int, const char *); |
201 | #define putstr(__x) __putstr(0, __x) | ||
210 | 202 | ||
211 | #ifdef CONFIG_X86_64 | 203 | #ifdef CONFIG_X86_64 |
212 | #define memptr long | 204 | #define memptr long |
@@ -221,46 +213,8 @@ static char *vidmem; | |||
221 | static int vidport; | 213 | static int vidport; |
222 | static int lines, cols; | 214 | static int lines, cols; |
223 | 215 | ||
224 | #ifdef CONFIG_X86_NUMAQ | ||
225 | void *xquad_portio; | ||
226 | #endif | ||
227 | |||
228 | #include "../../../../lib/inflate.c" | 216 | #include "../../../../lib/inflate.c" |
229 | 217 | ||
230 | static void *malloc(int size) | ||
231 | { | ||
232 | void *p; | ||
233 | |||
234 | if (size < 0) | ||
235 | error("Malloc error"); | ||
236 | if (free_mem_ptr <= 0) | ||
237 | error("Memory error"); | ||
238 | |||
239 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
240 | |||
241 | p = (void *)free_mem_ptr; | ||
242 | free_mem_ptr += size; | ||
243 | |||
244 | if (free_mem_ptr >= free_mem_end_ptr) | ||
245 | error("Out of memory"); | ||
246 | |||
247 | return p; | ||
248 | } | ||
249 | |||
250 | static void free(void *where) | ||
251 | { /* Don't care */ | ||
252 | } | ||
253 | |||
254 | static void gzip_mark(void **ptr) | ||
255 | { | ||
256 | *ptr = (void *) free_mem_ptr; | ||
257 | } | ||
258 | |||
259 | static void gzip_release(void **ptr) | ||
260 | { | ||
261 | free_mem_ptr = (memptr) *ptr; | ||
262 | } | ||
263 | |||
264 | static void scroll(void) | 218 | static void scroll(void) |
265 | { | 219 | { |
266 | int i; | 220 | int i; |
@@ -270,18 +224,24 @@ static void scroll(void) | |||
270 | vidmem[i] = ' '; | 224 | vidmem[i] = ' '; |
271 | } | 225 | } |
272 | 226 | ||
273 | static void putstr(const char *s) | 227 | static void __putstr(int error, const char *s) |
274 | { | 228 | { |
275 | int x, y, pos; | 229 | int x, y, pos; |
276 | char c; | 230 | char c; |
277 | 231 | ||
232 | #ifndef CONFIG_X86_VERBOSE_BOOTUP | ||
233 | if (!error) | ||
234 | return; | ||
235 | #endif | ||
236 | |||
278 | #ifdef CONFIG_X86_32 | 237 | #ifdef CONFIG_X86_32 |
279 | if (RM_SCREEN_INFO.orig_video_mode == 0 && lines == 0 && cols == 0) | 238 | if (real_mode->screen_info.orig_video_mode == 0 && |
239 | lines == 0 && cols == 0) | ||
280 | return; | 240 | return; |
281 | #endif | 241 | #endif |
282 | 242 | ||
283 | x = RM_SCREEN_INFO.orig_x; | 243 | x = real_mode->screen_info.orig_x; |
284 | y = RM_SCREEN_INFO.orig_y; | 244 | y = real_mode->screen_info.orig_y; |
285 | 245 | ||
286 | while ((c = *s++) != '\0') { | 246 | while ((c = *s++) != '\0') { |
287 | if (c == '\n') { | 247 | if (c == '\n') { |
@@ -291,7 +251,7 @@ static void putstr(const char *s) | |||
291 | y--; | 251 | y--; |
292 | } | 252 | } |
293 | } else { | 253 | } else { |
294 | vidmem [(x + cols * y) * 2] = c; | 254 | vidmem[(x + cols * y) * 2] = c; |
295 | if (++x >= cols) { | 255 | if (++x >= cols) { |
296 | x = 0; | 256 | x = 0; |
297 | if (++y >= lines) { | 257 | if (++y >= lines) { |
@@ -302,8 +262,8 @@ static void putstr(const char *s) | |||
302 | } | 262 | } |
303 | } | 263 | } |
304 | 264 | ||
305 | RM_SCREEN_INFO.orig_x = x; | 265 | real_mode->screen_info.orig_x = x; |
306 | RM_SCREEN_INFO.orig_y = y; | 266 | real_mode->screen_info.orig_y = y; |
307 | 267 | ||
308 | pos = (x + cols * y) * 2; /* Update cursor position */ | 268 | pos = (x + cols * y) * 2; /* Update cursor position */ |
309 | outb(14, vidport); | 269 | outb(14, vidport); |
@@ -317,7 +277,8 @@ static void *memset(void *s, int c, unsigned n) | |||
317 | int i; | 277 | int i; |
318 | char *ss = s; | 278 | char *ss = s; |
319 | 279 | ||
320 | for (i = 0; i < n; i++) ss[i] = c; | 280 | for (i = 0; i < n; i++) |
281 | ss[i] = c; | ||
321 | return s; | 282 | return s; |
322 | } | 283 | } |
323 | 284 | ||
@@ -327,7 +288,8 @@ static void *memcpy(void *dest, const void *src, unsigned n) | |||
327 | const char *s = src; | 288 | const char *s = src; |
328 | char *d = dest; | 289 | char *d = dest; |
329 | 290 | ||
330 | for (i = 0; i < n; i++) d[i] = s[i]; | 291 | for (i = 0; i < n; i++) |
292 | d[i] = s[i]; | ||
331 | return dest; | 293 | return dest; |
332 | } | 294 | } |
333 | 295 | ||
@@ -366,9 +328,9 @@ static void flush_window(void) | |||
366 | 328 | ||
367 | static void error(char *x) | 329 | static void error(char *x) |
368 | { | 330 | { |
369 | putstr("\n\n"); | 331 | __putstr(1, "\n\n"); |
370 | putstr(x); | 332 | __putstr(1, x); |
371 | putstr("\n\n -- System halted"); | 333 | __putstr(1, "\n\n -- System halted"); |
372 | 334 | ||
373 | while (1) | 335 | while (1) |
374 | asm("hlt"); | 336 | asm("hlt"); |
@@ -395,7 +357,8 @@ static void parse_elf(void *output) | |||
395 | return; | 357 | return; |
396 | } | 358 | } |
397 | 359 | ||
398 | putstr("Parsing ELF... "); | 360 | if (!quiet) |
361 | putstr("Parsing ELF... "); | ||
399 | 362 | ||
400 | phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); | 363 | phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); |
401 | if (!phdrs) | 364 | if (!phdrs) |
@@ -430,7 +393,10 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
430 | { | 393 | { |
431 | real_mode = rmode; | 394 | real_mode = rmode; |
432 | 395 | ||
433 | if (RM_SCREEN_INFO.orig_video_mode == 7) { | 396 | if (real_mode->hdr.loadflags & QUIET_FLAG) |
397 | quiet = 1; | ||
398 | |||
399 | if (real_mode->screen_info.orig_video_mode == 7) { | ||
434 | vidmem = (char *) 0xb0000; | 400 | vidmem = (char *) 0xb0000; |
435 | vidport = 0x3b4; | 401 | vidport = 0x3b4; |
436 | } else { | 402 | } else { |
@@ -438,8 +404,8 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
438 | vidport = 0x3d4; | 404 | vidport = 0x3d4; |
439 | } | 405 | } |
440 | 406 | ||
441 | lines = RM_SCREEN_INFO.orig_video_lines; | 407 | lines = real_mode->screen_info.orig_video_lines; |
442 | cols = RM_SCREEN_INFO.orig_video_cols; | 408 | cols = real_mode->screen_info.orig_video_cols; |
443 | 409 | ||
444 | window = output; /* Output buffer (Normally at 1M) */ | 410 | window = output; /* Output buffer (Normally at 1M) */ |
445 | free_mem_ptr = heap; /* Heap */ | 411 | free_mem_ptr = heap; /* Heap */ |
@@ -465,9 +431,11 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
465 | #endif | 431 | #endif |
466 | 432 | ||
467 | makecrc(); | 433 | makecrc(); |
468 | putstr("\nDecompressing Linux... "); | 434 | if (!quiet) |
435 | putstr("\nDecompressing Linux... "); | ||
469 | gunzip(); | 436 | gunzip(); |
470 | parse_elf(output); | 437 | parse_elf(output); |
471 | putstr("done.\nBooting the kernel.\n"); | 438 | if (!quiet) |
439 | putstr("done.\nBooting the kernel.\n"); | ||
472 | return; | 440 | return; |
473 | } | 441 | } |
diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c index edaadea90aaf..857e492c571e 100644 --- a/arch/x86/boot/compressed/relocs.c +++ b/arch/x86/boot/compressed/relocs.c | |||
@@ -10,16 +10,20 @@ | |||
10 | #define USE_BSD | 10 | #define USE_BSD |
11 | #include <endian.h> | 11 | #include <endian.h> |
12 | 12 | ||
13 | #define MAX_SHDRS 100 | ||
14 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | 13 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
15 | static Elf32_Ehdr ehdr; | 14 | static Elf32_Ehdr ehdr; |
16 | static Elf32_Shdr shdr[MAX_SHDRS]; | ||
17 | static Elf32_Sym *symtab[MAX_SHDRS]; | ||
18 | static Elf32_Rel *reltab[MAX_SHDRS]; | ||
19 | static char *strtab[MAX_SHDRS]; | ||
20 | static unsigned long reloc_count, reloc_idx; | 15 | static unsigned long reloc_count, reloc_idx; |
21 | static unsigned long *relocs; | 16 | static unsigned long *relocs; |
22 | 17 | ||
18 | struct section { | ||
19 | Elf32_Shdr shdr; | ||
20 | struct section *link; | ||
21 | Elf32_Sym *symtab; | ||
22 | Elf32_Rel *reltab; | ||
23 | char *strtab; | ||
24 | }; | ||
25 | static struct section *secs; | ||
26 | |||
23 | /* | 27 | /* |
24 | * Following symbols have been audited. There values are constant and do | 28 | * Following symbols have been audited. There values are constant and do |
25 | * not change if bzImage is loaded at a different physical address than | 29 | * not change if bzImage is loaded at a different physical address than |
@@ -35,7 +39,7 @@ static int is_safe_abs_reloc(const char* sym_name) | |||
35 | { | 39 | { |
36 | int i; | 40 | int i; |
37 | 41 | ||
38 | for(i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) { | 42 | for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) { |
39 | if (!strcmp(sym_name, safe_abs_relocs[i])) | 43 | if (!strcmp(sym_name, safe_abs_relocs[i])) |
40 | /* Match found */ | 44 | /* Match found */ |
41 | return 1; | 45 | return 1; |
@@ -137,10 +141,10 @@ static const char *sec_name(unsigned shndx) | |||
137 | { | 141 | { |
138 | const char *sec_strtab; | 142 | const char *sec_strtab; |
139 | const char *name; | 143 | const char *name; |
140 | sec_strtab = strtab[ehdr.e_shstrndx]; | 144 | sec_strtab = secs[ehdr.e_shstrndx].strtab; |
141 | name = "<noname>"; | 145 | name = "<noname>"; |
142 | if (shndx < ehdr.e_shnum) { | 146 | if (shndx < ehdr.e_shnum) { |
143 | name = sec_strtab + shdr[shndx].sh_name; | 147 | name = sec_strtab + secs[shndx].shdr.sh_name; |
144 | } | 148 | } |
145 | else if (shndx == SHN_ABS) { | 149 | else if (shndx == SHN_ABS) { |
146 | name = "ABSOLUTE"; | 150 | name = "ABSOLUTE"; |
@@ -159,7 +163,7 @@ static const char *sym_name(const char *sym_strtab, Elf32_Sym *sym) | |||
159 | name = sym_strtab + sym->st_name; | 163 | name = sym_strtab + sym->st_name; |
160 | } | 164 | } |
161 | else { | 165 | else { |
162 | name = sec_name(shdr[sym->st_shndx].sh_name); | 166 | name = sec_name(secs[sym->st_shndx].shdr.sh_name); |
163 | } | 167 | } |
164 | return name; | 168 | return name; |
165 | } | 169 | } |
@@ -244,29 +248,34 @@ static void read_ehdr(FILE *fp) | |||
244 | static void read_shdrs(FILE *fp) | 248 | static void read_shdrs(FILE *fp) |
245 | { | 249 | { |
246 | int i; | 250 | int i; |
247 | if (ehdr.e_shnum > MAX_SHDRS) { | 251 | Elf32_Shdr shdr; |
248 | die("%d section headers supported: %d\n", | 252 | |
249 | ehdr.e_shnum, MAX_SHDRS); | 253 | secs = calloc(ehdr.e_shnum, sizeof(struct section)); |
254 | if (!secs) { | ||
255 | die("Unable to allocate %d section headers\n", | ||
256 | ehdr.e_shnum); | ||
250 | } | 257 | } |
251 | if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) { | 258 | if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) { |
252 | die("Seek to %d failed: %s\n", | 259 | die("Seek to %d failed: %s\n", |
253 | ehdr.e_shoff, strerror(errno)); | 260 | ehdr.e_shoff, strerror(errno)); |
254 | } | 261 | } |
255 | if (fread(&shdr, sizeof(shdr[0]), ehdr.e_shnum, fp) != ehdr.e_shnum) { | 262 | for (i = 0; i < ehdr.e_shnum; i++) { |
256 | die("Cannot read ELF section headers: %s\n", | 263 | struct section *sec = &secs[i]; |
257 | strerror(errno)); | 264 | if (fread(&shdr, sizeof shdr, 1, fp) != 1) |
258 | } | 265 | die("Cannot read ELF section headers %d/%d: %s\n", |
259 | for(i = 0; i < ehdr.e_shnum; i++) { | 266 | i, ehdr.e_shnum, strerror(errno)); |
260 | shdr[i].sh_name = elf32_to_cpu(shdr[i].sh_name); | 267 | sec->shdr.sh_name = elf32_to_cpu(shdr.sh_name); |
261 | shdr[i].sh_type = elf32_to_cpu(shdr[i].sh_type); | 268 | sec->shdr.sh_type = elf32_to_cpu(shdr.sh_type); |
262 | shdr[i].sh_flags = elf32_to_cpu(shdr[i].sh_flags); | 269 | sec->shdr.sh_flags = elf32_to_cpu(shdr.sh_flags); |
263 | shdr[i].sh_addr = elf32_to_cpu(shdr[i].sh_addr); | 270 | sec->shdr.sh_addr = elf32_to_cpu(shdr.sh_addr); |
264 | shdr[i].sh_offset = elf32_to_cpu(shdr[i].sh_offset); | 271 | sec->shdr.sh_offset = elf32_to_cpu(shdr.sh_offset); |
265 | shdr[i].sh_size = elf32_to_cpu(shdr[i].sh_size); | 272 | sec->shdr.sh_size = elf32_to_cpu(shdr.sh_size); |
266 | shdr[i].sh_link = elf32_to_cpu(shdr[i].sh_link); | 273 | sec->shdr.sh_link = elf32_to_cpu(shdr.sh_link); |
267 | shdr[i].sh_info = elf32_to_cpu(shdr[i].sh_info); | 274 | sec->shdr.sh_info = elf32_to_cpu(shdr.sh_info); |
268 | shdr[i].sh_addralign = elf32_to_cpu(shdr[i].sh_addralign); | 275 | sec->shdr.sh_addralign = elf32_to_cpu(shdr.sh_addralign); |
269 | shdr[i].sh_entsize = elf32_to_cpu(shdr[i].sh_entsize); | 276 | sec->shdr.sh_entsize = elf32_to_cpu(shdr.sh_entsize); |
277 | if (sec->shdr.sh_link < ehdr.e_shnum) | ||
278 | sec->link = &secs[sec->shdr.sh_link]; | ||
270 | } | 279 | } |
271 | 280 | ||
272 | } | 281 | } |
@@ -274,20 +283,22 @@ static void read_shdrs(FILE *fp) | |||
274 | static void read_strtabs(FILE *fp) | 283 | static void read_strtabs(FILE *fp) |
275 | { | 284 | { |
276 | int i; | 285 | int i; |
277 | for(i = 0; i < ehdr.e_shnum; i++) { | 286 | for (i = 0; i < ehdr.e_shnum; i++) { |
278 | if (shdr[i].sh_type != SHT_STRTAB) { | 287 | struct section *sec = &secs[i]; |
288 | if (sec->shdr.sh_type != SHT_STRTAB) { | ||
279 | continue; | 289 | continue; |
280 | } | 290 | } |
281 | strtab[i] = malloc(shdr[i].sh_size); | 291 | sec->strtab = malloc(sec->shdr.sh_size); |
282 | if (!strtab[i]) { | 292 | if (!sec->strtab) { |
283 | die("malloc of %d bytes for strtab failed\n", | 293 | die("malloc of %d bytes for strtab failed\n", |
284 | shdr[i].sh_size); | 294 | sec->shdr.sh_size); |
285 | } | 295 | } |
286 | if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) { | 296 | if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { |
287 | die("Seek to %d failed: %s\n", | 297 | die("Seek to %d failed: %s\n", |
288 | shdr[i].sh_offset, strerror(errno)); | 298 | sec->shdr.sh_offset, strerror(errno)); |
289 | } | 299 | } |
290 | if (fread(strtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) { | 300 | if (fread(sec->strtab, 1, sec->shdr.sh_size, fp) |
301 | != sec->shdr.sh_size) { | ||
291 | die("Cannot read symbol table: %s\n", | 302 | die("Cannot read symbol table: %s\n", |
292 | strerror(errno)); | 303 | strerror(errno)); |
293 | } | 304 | } |
@@ -297,28 +308,31 @@ static void read_strtabs(FILE *fp) | |||
297 | static void read_symtabs(FILE *fp) | 308 | static void read_symtabs(FILE *fp) |
298 | { | 309 | { |
299 | int i,j; | 310 | int i,j; |
300 | for(i = 0; i < ehdr.e_shnum; i++) { | 311 | for (i = 0; i < ehdr.e_shnum; i++) { |
301 | if (shdr[i].sh_type != SHT_SYMTAB) { | 312 | struct section *sec = &secs[i]; |
313 | if (sec->shdr.sh_type != SHT_SYMTAB) { | ||
302 | continue; | 314 | continue; |
303 | } | 315 | } |
304 | symtab[i] = malloc(shdr[i].sh_size); | 316 | sec->symtab = malloc(sec->shdr.sh_size); |
305 | if (!symtab[i]) { | 317 | if (!sec->symtab) { |
306 | die("malloc of %d bytes for symtab failed\n", | 318 | die("malloc of %d bytes for symtab failed\n", |
307 | shdr[i].sh_size); | 319 | sec->shdr.sh_size); |
308 | } | 320 | } |
309 | if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) { | 321 | if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { |
310 | die("Seek to %d failed: %s\n", | 322 | die("Seek to %d failed: %s\n", |
311 | shdr[i].sh_offset, strerror(errno)); | 323 | sec->shdr.sh_offset, strerror(errno)); |
312 | } | 324 | } |
313 | if (fread(symtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) { | 325 | if (fread(sec->symtab, 1, sec->shdr.sh_size, fp) |
326 | != sec->shdr.sh_size) { | ||
314 | die("Cannot read symbol table: %s\n", | 327 | die("Cannot read symbol table: %s\n", |
315 | strerror(errno)); | 328 | strerror(errno)); |
316 | } | 329 | } |
317 | for(j = 0; j < shdr[i].sh_size/sizeof(symtab[i][0]); j++) { | 330 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) { |
318 | symtab[i][j].st_name = elf32_to_cpu(symtab[i][j].st_name); | 331 | Elf32_Sym *sym = &sec->symtab[j]; |
319 | symtab[i][j].st_value = elf32_to_cpu(symtab[i][j].st_value); | 332 | sym->st_name = elf32_to_cpu(sym->st_name); |
320 | symtab[i][j].st_size = elf32_to_cpu(symtab[i][j].st_size); | 333 | sym->st_value = elf32_to_cpu(sym->st_value); |
321 | symtab[i][j].st_shndx = elf16_to_cpu(symtab[i][j].st_shndx); | 334 | sym->st_size = elf32_to_cpu(sym->st_size); |
335 | sym->st_shndx = elf16_to_cpu(sym->st_shndx); | ||
322 | } | 336 | } |
323 | } | 337 | } |
324 | } | 338 | } |
@@ -327,26 +341,29 @@ static void read_symtabs(FILE *fp) | |||
327 | static void read_relocs(FILE *fp) | 341 | static void read_relocs(FILE *fp) |
328 | { | 342 | { |
329 | int i,j; | 343 | int i,j; |
330 | for(i = 0; i < ehdr.e_shnum; i++) { | 344 | for (i = 0; i < ehdr.e_shnum; i++) { |
331 | if (shdr[i].sh_type != SHT_REL) { | 345 | struct section *sec = &secs[i]; |
346 | if (sec->shdr.sh_type != SHT_REL) { | ||
332 | continue; | 347 | continue; |
333 | } | 348 | } |
334 | reltab[i] = malloc(shdr[i].sh_size); | 349 | sec->reltab = malloc(sec->shdr.sh_size); |
335 | if (!reltab[i]) { | 350 | if (!sec->reltab) { |
336 | die("malloc of %d bytes for relocs failed\n", | 351 | die("malloc of %d bytes for relocs failed\n", |
337 | shdr[i].sh_size); | 352 | sec->shdr.sh_size); |
338 | } | 353 | } |
339 | if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) { | 354 | if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { |
340 | die("Seek to %d failed: %s\n", | 355 | die("Seek to %d failed: %s\n", |
341 | shdr[i].sh_offset, strerror(errno)); | 356 | sec->shdr.sh_offset, strerror(errno)); |
342 | } | 357 | } |
343 | if (fread(reltab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) { | 358 | if (fread(sec->reltab, 1, sec->shdr.sh_size, fp) |
359 | != sec->shdr.sh_size) { | ||
344 | die("Cannot read symbol table: %s\n", | 360 | die("Cannot read symbol table: %s\n", |
345 | strerror(errno)); | 361 | strerror(errno)); |
346 | } | 362 | } |
347 | for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) { | 363 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) { |
348 | reltab[i][j].r_offset = elf32_to_cpu(reltab[i][j].r_offset); | 364 | Elf32_Rel *rel = &sec->reltab[j]; |
349 | reltab[i][j].r_info = elf32_to_cpu(reltab[i][j].r_info); | 365 | rel->r_offset = elf32_to_cpu(rel->r_offset); |
366 | rel->r_info = elf32_to_cpu(rel->r_info); | ||
350 | } | 367 | } |
351 | } | 368 | } |
352 | } | 369 | } |
@@ -357,19 +374,21 @@ static void print_absolute_symbols(void) | |||
357 | int i; | 374 | int i; |
358 | printf("Absolute symbols\n"); | 375 | printf("Absolute symbols\n"); |
359 | printf(" Num: Value Size Type Bind Visibility Name\n"); | 376 | printf(" Num: Value Size Type Bind Visibility Name\n"); |
360 | for(i = 0; i < ehdr.e_shnum; i++) { | 377 | for (i = 0; i < ehdr.e_shnum; i++) { |
378 | struct section *sec = &secs[i]; | ||
361 | char *sym_strtab; | 379 | char *sym_strtab; |
362 | Elf32_Sym *sh_symtab; | 380 | Elf32_Sym *sh_symtab; |
363 | int j; | 381 | int j; |
364 | if (shdr[i].sh_type != SHT_SYMTAB) { | 382 | |
383 | if (sec->shdr.sh_type != SHT_SYMTAB) { | ||
365 | continue; | 384 | continue; |
366 | } | 385 | } |
367 | sh_symtab = symtab[i]; | 386 | sh_symtab = sec->symtab; |
368 | sym_strtab = strtab[shdr[i].sh_link]; | 387 | sym_strtab = sec->link->strtab; |
369 | for(j = 0; j < shdr[i].sh_size/sizeof(symtab[0][0]); j++) { | 388 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) { |
370 | Elf32_Sym *sym; | 389 | Elf32_Sym *sym; |
371 | const char *name; | 390 | const char *name; |
372 | sym = &symtab[i][j]; | 391 | sym = &sec->symtab[j]; |
373 | name = sym_name(sym_strtab, sym); | 392 | name = sym_name(sym_strtab, sym); |
374 | if (sym->st_shndx != SHN_ABS) { | 393 | if (sym->st_shndx != SHN_ABS) { |
375 | continue; | 394 | continue; |
@@ -389,26 +408,27 @@ static void print_absolute_relocs(void) | |||
389 | { | 408 | { |
390 | int i, printed = 0; | 409 | int i, printed = 0; |
391 | 410 | ||
392 | for(i = 0; i < ehdr.e_shnum; i++) { | 411 | for (i = 0; i < ehdr.e_shnum; i++) { |
412 | struct section *sec = &secs[i]; | ||
413 | struct section *sec_applies, *sec_symtab; | ||
393 | char *sym_strtab; | 414 | char *sym_strtab; |
394 | Elf32_Sym *sh_symtab; | 415 | Elf32_Sym *sh_symtab; |
395 | unsigned sec_applies, sec_symtab; | ||
396 | int j; | 416 | int j; |
397 | if (shdr[i].sh_type != SHT_REL) { | 417 | if (sec->shdr.sh_type != SHT_REL) { |
398 | continue; | 418 | continue; |
399 | } | 419 | } |
400 | sec_symtab = shdr[i].sh_link; | 420 | sec_symtab = sec->link; |
401 | sec_applies = shdr[i].sh_info; | 421 | sec_applies = &secs[sec->shdr.sh_info]; |
402 | if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) { | 422 | if (!(sec_applies->shdr.sh_flags & SHF_ALLOC)) { |
403 | continue; | 423 | continue; |
404 | } | 424 | } |
405 | sh_symtab = symtab[sec_symtab]; | 425 | sh_symtab = sec_symtab->symtab; |
406 | sym_strtab = strtab[shdr[sec_symtab].sh_link]; | 426 | sym_strtab = sec_symtab->link->strtab; |
407 | for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) { | 427 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) { |
408 | Elf32_Rel *rel; | 428 | Elf32_Rel *rel; |
409 | Elf32_Sym *sym; | 429 | Elf32_Sym *sym; |
410 | const char *name; | 430 | const char *name; |
411 | rel = &reltab[i][j]; | 431 | rel = &sec->reltab[j]; |
412 | sym = &sh_symtab[ELF32_R_SYM(rel->r_info)]; | 432 | sym = &sh_symtab[ELF32_R_SYM(rel->r_info)]; |
413 | name = sym_name(sym_strtab, sym); | 433 | name = sym_name(sym_strtab, sym); |
414 | if (sym->st_shndx != SHN_ABS) { | 434 | if (sym->st_shndx != SHN_ABS) { |
@@ -456,26 +476,28 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym)) | |||
456 | { | 476 | { |
457 | int i; | 477 | int i; |
458 | /* Walk through the relocations */ | 478 | /* Walk through the relocations */ |
459 | for(i = 0; i < ehdr.e_shnum; i++) { | 479 | for (i = 0; i < ehdr.e_shnum; i++) { |
460 | char *sym_strtab; | 480 | char *sym_strtab; |
461 | Elf32_Sym *sh_symtab; | 481 | Elf32_Sym *sh_symtab; |
462 | unsigned sec_applies, sec_symtab; | 482 | struct section *sec_applies, *sec_symtab; |
463 | int j; | 483 | int j; |
464 | if (shdr[i].sh_type != SHT_REL) { | 484 | struct section *sec = &secs[i]; |
485 | |||
486 | if (sec->shdr.sh_type != SHT_REL) { | ||
465 | continue; | 487 | continue; |
466 | } | 488 | } |
467 | sec_symtab = shdr[i].sh_link; | 489 | sec_symtab = sec->link; |
468 | sec_applies = shdr[i].sh_info; | 490 | sec_applies = &secs[sec->shdr.sh_info]; |
469 | if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) { | 491 | if (!(sec_applies->shdr.sh_flags & SHF_ALLOC)) { |
470 | continue; | 492 | continue; |
471 | } | 493 | } |
472 | sh_symtab = symtab[sec_symtab]; | 494 | sh_symtab = sec_symtab->symtab; |
473 | sym_strtab = strtab[shdr[sec_symtab].sh_link]; | 495 | sym_strtab = sec_symtab->link->strtab; |
474 | for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) { | 496 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) { |
475 | Elf32_Rel *rel; | 497 | Elf32_Rel *rel; |
476 | Elf32_Sym *sym; | 498 | Elf32_Sym *sym; |
477 | unsigned r_type; | 499 | unsigned r_type; |
478 | rel = &reltab[i][j]; | 500 | rel = &sec->reltab[j]; |
479 | sym = &sh_symtab[ELF32_R_SYM(rel->r_info)]; | 501 | sym = &sh_symtab[ELF32_R_SYM(rel->r_info)]; |
480 | r_type = ELF32_R_TYPE(rel->r_info); | 502 | r_type = ELF32_R_TYPE(rel->r_info); |
481 | /* Don't visit relocations to absolute symbols */ | 503 | /* Don't visit relocations to absolute symbols */ |
@@ -539,7 +561,7 @@ static void emit_relocs(int as_text) | |||
539 | */ | 561 | */ |
540 | printf(".section \".data.reloc\",\"a\"\n"); | 562 | printf(".section \".data.reloc\",\"a\"\n"); |
541 | printf(".balign 4\n"); | 563 | printf(".balign 4\n"); |
542 | for(i = 0; i < reloc_count; i++) { | 564 | for (i = 0; i < reloc_count; i++) { |
543 | printf("\t .long 0x%08lx\n", relocs[i]); | 565 | printf("\t .long 0x%08lx\n", relocs[i]); |
544 | } | 566 | } |
545 | printf("\n"); | 567 | printf("\n"); |
@@ -550,7 +572,7 @@ static void emit_relocs(int as_text) | |||
550 | /* Print a stop */ | 572 | /* Print a stop */ |
551 | printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]); | 573 | printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]); |
552 | /* Now print each relocation */ | 574 | /* Now print each relocation */ |
553 | for(i = 0; i < reloc_count; i++) { | 575 | for (i = 0; i < reloc_count; i++) { |
554 | buf[0] = (relocs[i] >> 0) & 0xff; | 576 | buf[0] = (relocs[i] >> 0) & 0xff; |
555 | buf[1] = (relocs[i] >> 8) & 0xff; | 577 | buf[1] = (relocs[i] >> 8) & 0xff; |
556 | buf[2] = (relocs[i] >> 16) & 0xff; | 578 | buf[2] = (relocs[i] >> 16) & 0xff; |
@@ -577,7 +599,7 @@ int main(int argc, char **argv) | |||
577 | show_absolute_relocs = 0; | 599 | show_absolute_relocs = 0; |
578 | as_text = 0; | 600 | as_text = 0; |
579 | fname = NULL; | 601 | fname = NULL; |
580 | for(i = 1; i < argc; i++) { | 602 | for (i = 1; i < argc; i++) { |
581 | char *arg = argv[i]; | 603 | char *arg = argv[i]; |
582 | if (*arg == '-') { | 604 | if (*arg == '-') { |
583 | if (strcmp(argv[1], "--abs-syms") == 0) { | 605 | if (strcmp(argv[1], "--abs-syms") == 0) { |