aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2007-10-11 05:16:43 -0400
committerThomas Gleixner <tglx@linutronix.de>2007-10-11 05:16:43 -0400
commit0530bf37cebcf22a73652937c2340bc1ebd92000 (patch)
treeac2918d5eca7b0775875ad81fe98a0248ae5924f /arch/i386
parent19d8d79ccfd2fb67b1eb86e3c634a2e68a4c4b11 (diff)
i386: move boot
Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/i386')
-rw-r--r--arch/i386/boot/compressed/.gitignore1
-rw-r--r--arch/i386/boot/compressed/Makefile5
-rw-r--r--arch/i386/boot/compressed/Makefile_3250
-rw-r--r--arch/i386/boot/compressed/head_32.S180
-rw-r--r--arch/i386/boot/compressed/misc_32.c379
-rw-r--r--arch/i386/boot/compressed/relocs.c631
-rw-r--r--arch/i386/boot/compressed/vmlinux_32.lds43
-rw-r--r--arch/i386/boot/compressed/vmlinux_32.scr10
8 files changed, 0 insertions, 1299 deletions
diff --git a/arch/i386/boot/compressed/.gitignore b/arch/i386/boot/compressed/.gitignore
deleted file mode 100644
index be0ed065249b..000000000000
--- a/arch/i386/boot/compressed/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
1relocs
diff --git a/arch/i386/boot/compressed/Makefile b/arch/i386/boot/compressed/Makefile
deleted file mode 100644
index 78514f3f626f..000000000000
--- a/arch/i386/boot/compressed/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/i386/boot/compressed/Makefile_32
3else
4include ${srctree}/arch/x86_64/boot/compressed/Makefile_64
5endif
diff --git a/arch/i386/boot/compressed/Makefile_32 b/arch/i386/boot/compressed/Makefile_32
deleted file mode 100644
index 0c64c314eadb..000000000000
--- a/arch/i386/boot/compressed/Makefile_32
+++ /dev/null
@@ -1,50 +0,0 @@
1#
2# linux/arch/i386/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head_32.o misc_32.o piggy.o \
8 vmlinux.bin.all vmlinux.relocs
9EXTRA_AFLAGS := -traditional
10
11LDFLAGS_vmlinux := -T
12hostprogs-y := relocs
13
14CFLAGS := -m32 -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
15 -fno-strict-aliasing -fPIC \
16 $(call cc-option,-ffreestanding) \
17 $(call cc-option,-fno-stack-protector)
18LDFLAGS := -m elf_i386
19
20$(obj)/vmlinux: $(src)/vmlinux_32.lds $(obj)/head_32.o $(obj)/misc_32.o $(obj)/piggy.o FORCE
21 $(call if_changed,ld)
22 @:
23
24$(obj)/vmlinux.bin: vmlinux FORCE
25 $(call if_changed,objcopy)
26
27quiet_cmd_relocs = RELOCS $@
28 cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $<
29$(obj)/vmlinux.relocs: vmlinux $(obj)/relocs FORCE
30 $(call if_changed,relocs)
31
32vmlinux.bin.all-y := $(obj)/vmlinux.bin
33vmlinux.bin.all-$(CONFIG_RELOCATABLE) += $(obj)/vmlinux.relocs
34quiet_cmd_relocbin = BUILD $@
35 cmd_relocbin = cat $(filter-out FORCE,$^) > $@
36$(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE
37 $(call if_changed,relocbin)
38
39ifdef CONFIG_RELOCATABLE
40$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
41 $(call if_changed,gzip)
42else
43$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
44 $(call if_changed,gzip)
45endif
46
47LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
48
49$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.gz FORCE
50 $(call if_changed,ld)
diff --git a/arch/i386/boot/compressed/head_32.S b/arch/i386/boot/compressed/head_32.S
deleted file mode 100644
index f35ea2237522..000000000000
--- a/arch/i386/boot/compressed/head_32.S
+++ /dev/null
@@ -1,180 +0,0 @@
1/*
2 * linux/boot/head.S
3 *
4 * Copyright (C) 1991, 1992, 1993 Linus Torvalds
5 */
6
7/*
8 * head.S contains the 32-bit startup code.
9 *
10 * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
11 * the page directory will exist. The startup code will be overwritten by
12 * the page directory. [According to comments etc elsewhere on a compressed
13 * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
14 *
15 * Page 0 is deliberately kept safe, since System Management Mode code in
16 * laptops may need to access the BIOS data stored there. This is also
17 * useful for future device drivers that either access the BIOS via VM86
18 * mode.
19 */
20
21/*
22 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
23 */
24.text
25
26#include <linux/linkage.h>
27#include <asm/segment.h>
28#include <asm/page.h>
29#include <asm/boot.h>
30
31.section ".text.head","ax",@progbits
32 .globl startup_32
33
34startup_32:
35 cld
36 cli
37 movl $(__BOOT_DS),%eax
38 movl %eax,%ds
39 movl %eax,%es
40 movl %eax,%fs
41 movl %eax,%gs
42 movl %eax,%ss
43
44/* Calculate the delta between where we were compiled to run
45 * at and where we were actually loaded at. This can only be done
46 * with a short local call on x86. Nothing else will tell us what
47 * address we are running at. The reserved chunk of the real-mode
48 * data at 0x1e4 (defined as a scratch field) are used as the stack
49 * for this calculation. Only 4 bytes are needed.
50 */
51 leal (0x1e4+4)(%esi), %esp
52 call 1f
531: popl %ebp
54 subl $1b, %ebp
55
56/* %ebp contains the address we are loaded at by the boot loader and %ebx
57 * contains the address where we should move the kernel image temporarily
58 * for safe in-place decompression.
59 */
60
61#ifdef CONFIG_RELOCATABLE
62 movl %ebp, %ebx
63 addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
64 andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
65#else
66 movl $LOAD_PHYSICAL_ADDR, %ebx
67#endif
68
69 /* Replace the compressed data size with the uncompressed size */
70 subl input_len(%ebp), %ebx
71 movl output_len(%ebp), %eax
72 addl %eax, %ebx
73 /* Add 8 bytes for every 32K input block */
74 shrl $12, %eax
75 addl %eax, %ebx
76 /* Add 32K + 18 bytes of extra slack */
77 addl $(32768 + 18), %ebx
78 /* Align on a 4K boundary */
79 addl $4095, %ebx
80 andl $~4095, %ebx
81
82/* Copy the compressed kernel to the end of our buffer
83 * where decompression in place becomes safe.
84 */
85 pushl %esi
86 leal _end(%ebp), %esi
87 leal _end(%ebx), %edi
88 movl $(_end - startup_32), %ecx
89 std
90 rep
91 movsb
92 cld
93 popl %esi
94
95/* Compute the kernel start address.
96 */
97#ifdef CONFIG_RELOCATABLE
98 addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
99 andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
100#else
101 movl $LOAD_PHYSICAL_ADDR, %ebp
102#endif
103
104/*
105 * Jump to the relocated address.
106 */
107 leal relocated(%ebx), %eax
108 jmp *%eax
109.section ".text"
110relocated:
111
112/*
113 * Clear BSS
114 */
115 xorl %eax,%eax
116 leal _edata(%ebx),%edi
117 leal _end(%ebx), %ecx
118 subl %edi,%ecx
119 cld
120 rep
121 stosb
122
123/*
124 * Setup the stack for the decompressor
125 */
126 leal stack_end(%ebx), %esp
127
128/*
129 * Do the decompression, and jump to the new kernel..
130 */
131 movl output_len(%ebx), %eax
132 pushl %eax
133 pushl %ebp # output address
134 movl input_len(%ebx), %eax
135 pushl %eax # input_len
136 leal input_data(%ebx), %eax
137 pushl %eax # input_data
138 leal _end(%ebx), %eax
139 pushl %eax # end of the image as third argument
140 pushl %esi # real mode pointer as second arg
141 call decompress_kernel
142 addl $20, %esp
143 popl %ecx
144
145#if CONFIG_RELOCATABLE
146/* Find the address of the relocations.
147 */
148 movl %ebp, %edi
149 addl %ecx, %edi
150
151/* Calculate the delta between where vmlinux was compiled to run
152 * and where it was actually loaded.
153 */
154 movl %ebp, %ebx
155 subl $LOAD_PHYSICAL_ADDR, %ebx
156 jz 2f /* Nothing to be done if loaded at compiled addr. */
157/*
158 * Process relocations.
159 */
160
1611: subl $4, %edi
162 movl 0(%edi), %ecx
163 testl %ecx, %ecx
164 jz 2f
165 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
166 jmp 1b
1672:
168#endif
169
170/*
171 * Jump to the decompressed kernel.
172 */
173 xorl %ebx,%ebx
174 jmp *%ebp
175
176.bss
177.balign 4
178stack:
179 .fill 4096, 1, 0
180stack_end:
diff --git a/arch/i386/boot/compressed/misc_32.c b/arch/i386/boot/compressed/misc_32.c
deleted file mode 100644
index b28505c544c9..000000000000
--- a/arch/i386/boot/compressed/misc_32.c
+++ /dev/null
@@ -1,379 +0,0 @@
1/*
2 * misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
9 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
10 */
11
12#undef CONFIG_PARAVIRT
13#include <linux/linkage.h>
14#include <linux/vmalloc.h>
15#include <linux/screen_info.h>
16#include <asm/io.h>
17#include <asm/page.h>
18#include <asm/boot.h>
19
20/* WARNING!!
21 * This code is compiled with -fPIC and it is relocated dynamically
22 * at run time, but no relocation processing is performed.
23 * This means that it is not safe to place pointers in static structures.
24 */
25
26/*
27 * Getting to provable safe in place decompression is hard.
28 * Worst case behaviours need to be analized.
29 * Background information:
30 *
31 * The file layout is:
32 * magic[2]
33 * method[1]
34 * flags[1]
35 * timestamp[4]
36 * extraflags[1]
37 * os[1]
38 * compressed data blocks[N]
39 * crc[4] orig_len[4]
40 *
41 * resulting in 18 bytes of non compressed data overhead.
42 *
43 * Files divided into blocks
44 * 1 bit (last block flag)
45 * 2 bits (block type)
46 *
47 * 1 block occurs every 32K -1 bytes or when there 50% compression has been achieved.
48 * The smallest block type encoding is always used.
49 *
50 * stored:
51 * 32 bits length in bytes.
52 *
53 * fixed:
54 * magic fixed tree.
55 * symbols.
56 *
57 * dynamic:
58 * dynamic tree encoding.
59 * symbols.
60 *
61 *
62 * The buffer for decompression in place is the length of the
63 * uncompressed data, plus a small amount extra to keep the algorithm safe.
64 * The compressed data is placed at the end of the buffer. The output
65 * pointer is placed at the start of the buffer and the input pointer
66 * is placed where the compressed data starts. Problems will occur
67 * when the output pointer overruns the input pointer.
68 *
69 * The output pointer can only overrun the input pointer if the input
70 * pointer is moving faster than the output pointer. A condition only
71 * triggered by data whose compressed form is larger than the uncompressed
72 * form.
73 *
74 * The worst case at the block level is a growth of the compressed data
75 * of 5 bytes per 32767 bytes.
76 *
77 * The worst case internal to a compressed block is very hard to figure.
78 * The worst case can at least be boundined by having one bit that represents
79 * 32764 bytes and then all of the rest of the bytes representing the very
80 * very last byte.
81 *
82 * All of which is enough to compute an amount of extra data that is required
83 * to be safe. To avoid problems at the block level allocating 5 extra bytes
84 * per 32767 bytes of data is sufficient. To avoind problems internal to a block
85 * adding an extra 32767 bytes (the worst case uncompressed block size) is
86 * sufficient, to ensure that in the worst case the decompressed data for
87 * block will stop the byte before the compressed data for a block begins.
88 * To avoid problems with the compressed data's meta information an extra 18
89 * bytes are needed. Leading to the formula:
90 *
91 * extra_bytes = (uncompressed_size >> 12) + 32768 + 18 + decompressor_size.
92 *
93 * Adding 8 bytes per 32K is a bit excessive but much easier to calculate.
94 * Adding 32768 instead of 32767 just makes for round numbers.
95 * Adding the decompressor_size is necessary as it musht live after all
96 * of the data as well. Last I measured the decompressor is about 14K.
97 * 10K of actuall data and 4K of bss.
98 *
99 */
100
101/*
102 * gzip declarations
103 */
104
105#define OF(args) args
106#define STATIC static
107
108#undef memset
109#undef memcpy
110#define memzero(s, n) memset ((s), 0, (n))
111
112typedef unsigned char uch;
113typedef unsigned short ush;
114typedef unsigned long ulg;
115
116#define WSIZE 0x80000000 /* Window size must be at least 32k,
117 * and a power of two
118 * We don't actually have a window just
119 * a huge output buffer so I report
120 * a 2G windows size, as that should
121 * always be larger than our output buffer.
122 */
123
124static uch *inbuf; /* input buffer */
125static uch *window; /* Sliding window buffer, (and final output buffer) */
126
127static unsigned insize; /* valid bytes in inbuf */
128static unsigned inptr; /* index of next byte to be processed in inbuf */
129static unsigned outcnt; /* bytes in output buffer */
130
131/* gzip flag byte */
132#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
133#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
134#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
135#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
136#define COMMENT 0x10 /* bit 4 set: file comment present */
137#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
138#define RESERVED 0xC0 /* bit 6,7: reserved */
139
140#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
141
142/* Diagnostic functions */
143#ifdef DEBUG
144# define Assert(cond,msg) {if(!(cond)) error(msg);}
145# define Trace(x) fprintf x
146# define Tracev(x) {if (verbose) fprintf x ;}
147# define Tracevv(x) {if (verbose>1) fprintf x ;}
148# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
149# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
150#else
151# define Assert(cond,msg)
152# define Trace(x)
153# define Tracev(x)
154# define Tracevv(x)
155# define Tracec(c,x)
156# define Tracecv(c,x)
157#endif
158
159static int fill_inbuf(void);
160static void flush_window(void);
161static void error(char *m);
162static void gzip_mark(void **);
163static void gzip_release(void **);
164
165/*
166 * This is set up by the setup-routine at boot-time
167 */
168static unsigned char *real_mode; /* Pointer to real-mode data */
169
170#define RM_EXT_MEM_K (*(unsigned short *)(real_mode + 0x2))
171#ifndef STANDARD_MEMORY_BIOS_CALL
172#define RM_ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0))
173#endif
174#define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))
175
176extern unsigned char input_data[];
177extern int input_len;
178
179static long bytes_out = 0;
180
181static void *malloc(int size);
182static void free(void *where);
183
184static void *memset(void *s, int c, unsigned n);
185static void *memcpy(void *dest, const void *src, unsigned n);
186
187static void putstr(const char *);
188
189static unsigned long free_mem_ptr;
190static unsigned long free_mem_end_ptr;
191
192#define HEAP_SIZE 0x4000
193
194static char *vidmem = (char *)0xb8000;
195static int vidport;
196static int lines, cols;
197
198#ifdef CONFIG_X86_NUMAQ
199void *xquad_portio;
200#endif
201
202#include "../../../../lib/inflate.c"
203
204static void *malloc(int size)
205{
206 void *p;
207
208 if (size <0) error("Malloc error");
209 if (free_mem_ptr <= 0) error("Memory error");
210
211 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
212
213 p = (void *)free_mem_ptr;
214 free_mem_ptr += size;
215
216 if (free_mem_ptr >= free_mem_end_ptr)
217 error("Out of memory");
218
219 return p;
220}
221
222static void free(void *where)
223{ /* Don't care */
224}
225
226static void gzip_mark(void **ptr)
227{
228 *ptr = (void *) free_mem_ptr;
229}
230
231static void gzip_release(void **ptr)
232{
233 free_mem_ptr = (unsigned long) *ptr;
234}
235
236static void scroll(void)
237{
238 int i;
239
240 memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
241 for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
242 vidmem[i] = ' ';
243}
244
245static void putstr(const char *s)
246{
247 int x,y,pos;
248 char c;
249
250 x = RM_SCREEN_INFO.orig_x;
251 y = RM_SCREEN_INFO.orig_y;
252
253 while ( ( c = *s++ ) != '\0' ) {
254 if ( c == '\n' ) {
255 x = 0;
256 if ( ++y >= lines ) {
257 scroll();
258 y--;
259 }
260 } else {
261 vidmem [ ( x + cols * y ) * 2 ] = c;
262 if ( ++x >= cols ) {
263 x = 0;
264 if ( ++y >= lines ) {
265 scroll();
266 y--;
267 }
268 }
269 }
270 }
271
272 RM_SCREEN_INFO.orig_x = x;
273 RM_SCREEN_INFO.orig_y = y;
274
275 pos = (x + cols * y) * 2; /* Update cursor position */
276 outb_p(14, vidport);
277 outb_p(0xff & (pos >> 9), vidport+1);
278 outb_p(15, vidport);
279 outb_p(0xff & (pos >> 1), vidport+1);
280}
281
282static void* memset(void* s, int c, unsigned n)
283{
284 int i;
285 char *ss = (char*)s;
286
287 for (i=0;i<n;i++) ss[i] = c;
288 return s;
289}
290
291static void* memcpy(void* dest, const void* src, unsigned n)
292{
293 int i;
294 char *d = (char *)dest, *s = (char *)src;
295
296 for (i=0;i<n;i++) d[i] = s[i];
297 return dest;
298}
299
300/* ===========================================================================
301 * Fill the input buffer. This is called only when the buffer is empty
302 * and at least one byte is really needed.
303 */
304static int fill_inbuf(void)
305{
306 error("ran out of input data");
307 return 0;
308}
309
310/* ===========================================================================
311 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
312 * (Used for the decompressed data only.)
313 */
314static void flush_window(void)
315{
316 /* With my window equal to my output buffer
317 * I only need to compute the crc here.
318 */
319 ulg c = crc; /* temporary variable */
320 unsigned n;
321 uch *in, ch;
322
323 in = window;
324 for (n = 0; n < outcnt; n++) {
325 ch = *in++;
326 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
327 }
328 crc = c;
329 bytes_out += (ulg)outcnt;
330 outcnt = 0;
331}
332
333static void error(char *x)
334{
335 putstr("\n\n");
336 putstr(x);
337 putstr("\n\n -- System halted");
338
339 while(1); /* Halt */
340}
341
342asmlinkage void decompress_kernel(void *rmode, unsigned long end,
343 uch *input_data, unsigned long input_len, uch *output)
344{
345 real_mode = rmode;
346
347 if (RM_SCREEN_INFO.orig_video_mode == 7) {
348 vidmem = (char *) 0xb0000;
349 vidport = 0x3b4;
350 } else {
351 vidmem = (char *) 0xb8000;
352 vidport = 0x3d4;
353 }
354
355 lines = RM_SCREEN_INFO.orig_video_lines;
356 cols = RM_SCREEN_INFO.orig_video_cols;
357
358 window = output; /* Output buffer (Normally at 1M) */
359 free_mem_ptr = end; /* Heap */
360 free_mem_end_ptr = end + HEAP_SIZE;
361 inbuf = input_data; /* Input buffer */
362 insize = input_len;
363 inptr = 0;
364
365 if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1))
366 error("Destination address not CONFIG_PHYSICAL_ALIGN aligned");
367 if (end > ((-__PAGE_OFFSET-(512 <<20)-1) & 0x7fffffff))
368 error("Destination address too large");
369#ifndef CONFIG_RELOCATABLE
370 if ((u32)output != LOAD_PHYSICAL_ADDR)
371 error("Wrong destination address");
372#endif
373
374 makecrc();
375 putstr("Uncompressing Linux... ");
376 gunzip();
377 putstr("Ok, booting the kernel.\n");
378 return;
379}
diff --git a/arch/i386/boot/compressed/relocs.c b/arch/i386/boot/compressed/relocs.c
deleted file mode 100644
index 2d77ee728f92..000000000000
--- a/arch/i386/boot/compressed/relocs.c
+++ /dev/null
@@ -1,631 +0,0 @@
1#include <stdio.h>
2#include <stdarg.h>
3#include <stdlib.h>
4#include <stdint.h>
5#include <string.h>
6#include <errno.h>
7#include <unistd.h>
8#include <elf.h>
9#include <byteswap.h>
10#define USE_BSD
11#include <endian.h>
12
13#define MAX_SHDRS 100
14#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
15static Elf32_Ehdr ehdr;
16static Elf32_Shdr shdr[MAX_SHDRS];
17static Elf32_Sym *symtab[MAX_SHDRS];
18static Elf32_Rel *reltab[MAX_SHDRS];
19static char *strtab[MAX_SHDRS];
20static unsigned long reloc_count, reloc_idx;
21static unsigned long *relocs;
22
23/*
24 * Following symbols have been audited. There values are constant and do
25 * not change if bzImage is loaded at a different physical address than
26 * the address for which it has been compiled. Don't warn user about
27 * absolute relocations present w.r.t these symbols.
28 */
29static const char* safe_abs_relocs[] = {
30 "__kernel_vsyscall",
31 "__kernel_rt_sigreturn",
32 "__kernel_sigreturn",
33 "SYSENTER_RETURN",
34 "VDSO_NOTE_MASK",
35 "xen_irq_disable_direct_reloc",
36 "xen_save_fl_direct_reloc",
37};
38
39static int is_safe_abs_reloc(const char* sym_name)
40{
41 int i, array_size;
42
43 array_size = sizeof(safe_abs_relocs)/sizeof(char*);
44
45 for(i = 0; i < array_size; i++) {
46 if (!strcmp(sym_name, safe_abs_relocs[i]))
47 /* Match found */
48 return 1;
49 }
50 if (strncmp(sym_name, "__crc_", 6) == 0)
51 return 1;
52 return 0;
53}
54
55static void die(char *fmt, ...)
56{
57 va_list ap;
58 va_start(ap, fmt);
59 vfprintf(stderr, fmt, ap);
60 va_end(ap);
61 exit(1);
62}
63
64static const char *sym_type(unsigned type)
65{
66 static const char *type_name[] = {
67#define SYM_TYPE(X) [X] = #X
68 SYM_TYPE(STT_NOTYPE),
69 SYM_TYPE(STT_OBJECT),
70 SYM_TYPE(STT_FUNC),
71 SYM_TYPE(STT_SECTION),
72 SYM_TYPE(STT_FILE),
73 SYM_TYPE(STT_COMMON),
74 SYM_TYPE(STT_TLS),
75#undef SYM_TYPE
76 };
77 const char *name = "unknown sym type name";
78 if (type < ARRAY_SIZE(type_name)) {
79 name = type_name[type];
80 }
81 return name;
82}
83
84static const char *sym_bind(unsigned bind)
85{
86 static const char *bind_name[] = {
87#define SYM_BIND(X) [X] = #X
88 SYM_BIND(STB_LOCAL),
89 SYM_BIND(STB_GLOBAL),
90 SYM_BIND(STB_WEAK),
91#undef SYM_BIND
92 };
93 const char *name = "unknown sym bind name";
94 if (bind < ARRAY_SIZE(bind_name)) {
95 name = bind_name[bind];
96 }
97 return name;
98}
99
100static const char *sym_visibility(unsigned visibility)
101{
102 static const char *visibility_name[] = {
103#define SYM_VISIBILITY(X) [X] = #X
104 SYM_VISIBILITY(STV_DEFAULT),
105 SYM_VISIBILITY(STV_INTERNAL),
106 SYM_VISIBILITY(STV_HIDDEN),
107 SYM_VISIBILITY(STV_PROTECTED),
108#undef SYM_VISIBILITY
109 };
110 const char *name = "unknown sym visibility name";
111 if (visibility < ARRAY_SIZE(visibility_name)) {
112 name = visibility_name[visibility];
113 }
114 return name;
115}
116
117static const char *rel_type(unsigned type)
118{
119 static const char *type_name[] = {
120#define REL_TYPE(X) [X] = #X
121 REL_TYPE(R_386_NONE),
122 REL_TYPE(R_386_32),
123 REL_TYPE(R_386_PC32),
124 REL_TYPE(R_386_GOT32),
125 REL_TYPE(R_386_PLT32),
126 REL_TYPE(R_386_COPY),
127 REL_TYPE(R_386_GLOB_DAT),
128 REL_TYPE(R_386_JMP_SLOT),
129 REL_TYPE(R_386_RELATIVE),
130 REL_TYPE(R_386_GOTOFF),
131 REL_TYPE(R_386_GOTPC),
132#undef REL_TYPE
133 };
134 const char *name = "unknown type rel type name";
135 if (type < ARRAY_SIZE(type_name)) {
136 name = type_name[type];
137 }
138 return name;
139}
140
141static const char *sec_name(unsigned shndx)
142{
143 const char *sec_strtab;
144 const char *name;
145 sec_strtab = strtab[ehdr.e_shstrndx];
146 name = "<noname>";
147 if (shndx < ehdr.e_shnum) {
148 name = sec_strtab + shdr[shndx].sh_name;
149 }
150 else if (shndx == SHN_ABS) {
151 name = "ABSOLUTE";
152 }
153 else if (shndx == SHN_COMMON) {
154 name = "COMMON";
155 }
156 return name;
157}
158
159static const char *sym_name(const char *sym_strtab, Elf32_Sym *sym)
160{
161 const char *name;
162 name = "<noname>";
163 if (sym->st_name) {
164 name = sym_strtab + sym->st_name;
165 }
166 else {
167 name = sec_name(shdr[sym->st_shndx].sh_name);
168 }
169 return name;
170}
171
172
173
174#if BYTE_ORDER == LITTLE_ENDIAN
175#define le16_to_cpu(val) (val)
176#define le32_to_cpu(val) (val)
177#endif
178#if BYTE_ORDER == BIG_ENDIAN
179#define le16_to_cpu(val) bswap_16(val)
180#define le32_to_cpu(val) bswap_32(val)
181#endif
182
183static uint16_t elf16_to_cpu(uint16_t val)
184{
185 return le16_to_cpu(val);
186}
187
188static uint32_t elf32_to_cpu(uint32_t val)
189{
190 return le32_to_cpu(val);
191}
192
193static void read_ehdr(FILE *fp)
194{
195 if (fread(&ehdr, sizeof(ehdr), 1, fp) != 1) {
196 die("Cannot read ELF header: %s\n",
197 strerror(errno));
198 }
199 if (memcmp(ehdr.e_ident, ELFMAG, 4) != 0) {
200 die("No ELF magic\n");
201 }
202 if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
203 die("Not a 32 bit executable\n");
204 }
205 if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) {
206 die("Not a LSB ELF executable\n");
207 }
208 if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) {
209 die("Unknown ELF version\n");
210 }
211 /* Convert the fields to native endian */
212 ehdr.e_type = elf16_to_cpu(ehdr.e_type);
213 ehdr.e_machine = elf16_to_cpu(ehdr.e_machine);
214 ehdr.e_version = elf32_to_cpu(ehdr.e_version);
215 ehdr.e_entry = elf32_to_cpu(ehdr.e_entry);
216 ehdr.e_phoff = elf32_to_cpu(ehdr.e_phoff);
217 ehdr.e_shoff = elf32_to_cpu(ehdr.e_shoff);
218 ehdr.e_flags = elf32_to_cpu(ehdr.e_flags);
219 ehdr.e_ehsize = elf16_to_cpu(ehdr.e_ehsize);
220 ehdr.e_phentsize = elf16_to_cpu(ehdr.e_phentsize);
221 ehdr.e_phnum = elf16_to_cpu(ehdr.e_phnum);
222 ehdr.e_shentsize = elf16_to_cpu(ehdr.e_shentsize);
223 ehdr.e_shnum = elf16_to_cpu(ehdr.e_shnum);
224 ehdr.e_shstrndx = elf16_to_cpu(ehdr.e_shstrndx);
225
226 if ((ehdr.e_type != ET_EXEC) && (ehdr.e_type != ET_DYN)) {
227 die("Unsupported ELF header type\n");
228 }
229 if (ehdr.e_machine != EM_386) {
230 die("Not for x86\n");
231 }
232 if (ehdr.e_version != EV_CURRENT) {
233 die("Unknown ELF version\n");
234 }
235 if (ehdr.e_ehsize != sizeof(Elf32_Ehdr)) {
236 die("Bad Elf header size\n");
237 }
238 if (ehdr.e_phentsize != sizeof(Elf32_Phdr)) {
239 die("Bad program header entry\n");
240 }
241 if (ehdr.e_shentsize != sizeof(Elf32_Shdr)) {
242 die("Bad section header entry\n");
243 }
244 if (ehdr.e_shstrndx >= ehdr.e_shnum) {
245 die("String table index out of bounds\n");
246 }
247}
248
249static void read_shdrs(FILE *fp)
250{
251 int i;
252 if (ehdr.e_shnum > MAX_SHDRS) {
253 die("%d section headers supported: %d\n",
254 ehdr.e_shnum, MAX_SHDRS);
255 }
256 if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
257 die("Seek to %d failed: %s\n",
258 ehdr.e_shoff, strerror(errno));
259 }
260 if (fread(&shdr, sizeof(shdr[0]), ehdr.e_shnum, fp) != ehdr.e_shnum) {
261 die("Cannot read ELF section headers: %s\n",
262 strerror(errno));
263 }
264 for(i = 0; i < ehdr.e_shnum; i++) {
265 shdr[i].sh_name = elf32_to_cpu(shdr[i].sh_name);
266 shdr[i].sh_type = elf32_to_cpu(shdr[i].sh_type);
267 shdr[i].sh_flags = elf32_to_cpu(shdr[i].sh_flags);
268 shdr[i].sh_addr = elf32_to_cpu(shdr[i].sh_addr);
269 shdr[i].sh_offset = elf32_to_cpu(shdr[i].sh_offset);
270 shdr[i].sh_size = elf32_to_cpu(shdr[i].sh_size);
271 shdr[i].sh_link = elf32_to_cpu(shdr[i].sh_link);
272 shdr[i].sh_info = elf32_to_cpu(shdr[i].sh_info);
273 shdr[i].sh_addralign = elf32_to_cpu(shdr[i].sh_addralign);
274 shdr[i].sh_entsize = elf32_to_cpu(shdr[i].sh_entsize);
275 }
276
277}
278
279static void read_strtabs(FILE *fp)
280{
281 int i;
282 for(i = 0; i < ehdr.e_shnum; i++) {
283 if (shdr[i].sh_type != SHT_STRTAB) {
284 continue;
285 }
286 strtab[i] = malloc(shdr[i].sh_size);
287 if (!strtab[i]) {
288 die("malloc of %d bytes for strtab failed\n",
289 shdr[i].sh_size);
290 }
291 if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
292 die("Seek to %d failed: %s\n",
293 shdr[i].sh_offset, strerror(errno));
294 }
295 if (fread(strtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
296 die("Cannot read symbol table: %s\n",
297 strerror(errno));
298 }
299 }
300}
301
302static void read_symtabs(FILE *fp)
303{
304 int i,j;
305 for(i = 0; i < ehdr.e_shnum; i++) {
306 if (shdr[i].sh_type != SHT_SYMTAB) {
307 continue;
308 }
309 symtab[i] = malloc(shdr[i].sh_size);
310 if (!symtab[i]) {
311 die("malloc of %d bytes for symtab failed\n",
312 shdr[i].sh_size);
313 }
314 if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
315 die("Seek to %d failed: %s\n",
316 shdr[i].sh_offset, strerror(errno));
317 }
318 if (fread(symtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
319 die("Cannot read symbol table: %s\n",
320 strerror(errno));
321 }
322 for(j = 0; j < shdr[i].sh_size/sizeof(symtab[i][0]); j++) {
323 symtab[i][j].st_name = elf32_to_cpu(symtab[i][j].st_name);
324 symtab[i][j].st_value = elf32_to_cpu(symtab[i][j].st_value);
325 symtab[i][j].st_size = elf32_to_cpu(symtab[i][j].st_size);
326 symtab[i][j].st_shndx = elf16_to_cpu(symtab[i][j].st_shndx);
327 }
328 }
329}
330
331
332static void read_relocs(FILE *fp)
333{
334 int i,j;
335 for(i = 0; i < ehdr.e_shnum; i++) {
336 if (shdr[i].sh_type != SHT_REL) {
337 continue;
338 }
339 reltab[i] = malloc(shdr[i].sh_size);
340 if (!reltab[i]) {
341 die("malloc of %d bytes for relocs failed\n",
342 shdr[i].sh_size);
343 }
344 if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
345 die("Seek to %d failed: %s\n",
346 shdr[i].sh_offset, strerror(errno));
347 }
348 if (fread(reltab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
349 die("Cannot read symbol table: %s\n",
350 strerror(errno));
351 }
352 for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
353 reltab[i][j].r_offset = elf32_to_cpu(reltab[i][j].r_offset);
354 reltab[i][j].r_info = elf32_to_cpu(reltab[i][j].r_info);
355 }
356 }
357}
358
359
360static void print_absolute_symbols(void)
361{
362 int i;
363 printf("Absolute symbols\n");
364 printf(" Num: Value Size Type Bind Visibility Name\n");
365 for(i = 0; i < ehdr.e_shnum; i++) {
366 char *sym_strtab;
367 Elf32_Sym *sh_symtab;
368 int j;
369 if (shdr[i].sh_type != SHT_SYMTAB) {
370 continue;
371 }
372 sh_symtab = symtab[i];
373 sym_strtab = strtab[shdr[i].sh_link];
374 for(j = 0; j < shdr[i].sh_size/sizeof(symtab[0][0]); j++) {
375 Elf32_Sym *sym;
376 const char *name;
377 sym = &symtab[i][j];
378 name = sym_name(sym_strtab, sym);
379 if (sym->st_shndx != SHN_ABS) {
380 continue;
381 }
382 printf("%5d %08x %5d %10s %10s %12s %s\n",
383 j, sym->st_value, sym->st_size,
384 sym_type(ELF32_ST_TYPE(sym->st_info)),
385 sym_bind(ELF32_ST_BIND(sym->st_info)),
386 sym_visibility(ELF32_ST_VISIBILITY(sym->st_other)),
387 name);
388 }
389 }
390 printf("\n");
391}
392
393static void print_absolute_relocs(void)
394{
395 int i, printed = 0;
396
397 for(i = 0; i < ehdr.e_shnum; i++) {
398 char *sym_strtab;
399 Elf32_Sym *sh_symtab;
400 unsigned sec_applies, sec_symtab;
401 int j;
402 if (shdr[i].sh_type != SHT_REL) {
403 continue;
404 }
405 sec_symtab = shdr[i].sh_link;
406 sec_applies = shdr[i].sh_info;
407 if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
408 continue;
409 }
410 sh_symtab = symtab[sec_symtab];
411 sym_strtab = strtab[shdr[sec_symtab].sh_link];
412 for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
413 Elf32_Rel *rel;
414 Elf32_Sym *sym;
415 const char *name;
416 rel = &reltab[i][j];
417 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
418 name = sym_name(sym_strtab, sym);
419 if (sym->st_shndx != SHN_ABS) {
420 continue;
421 }
422
423 /* Absolute symbols are not relocated if bzImage is
424 * loaded at a non-compiled address. Display a warning
425 * to user at compile time about the absolute
426 * relocations present.
427 *
428 * User need to audit the code to make sure
429 * some symbols which should have been section
430 * relative have not become absolute because of some
431 * linker optimization or wrong programming usage.
432 *
433 * Before warning check if this absolute symbol
434 * relocation is harmless.
435 */
436 if (is_safe_abs_reloc(name))
437 continue;
438
439 if (!printed) {
440 printf("WARNING: Absolute relocations"
441 " present\n");
442 printf("Offset Info Type Sym.Value "
443 "Sym.Name\n");
444 printed = 1;
445 }
446
447 printf("%08x %08x %10s %08x %s\n",
448 rel->r_offset,
449 rel->r_info,
450 rel_type(ELF32_R_TYPE(rel->r_info)),
451 sym->st_value,
452 name);
453 }
454 }
455
456 if (printed)
457 printf("\n");
458}
459
460static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
461{
462 int i;
463 /* Walk through the relocations */
464 for(i = 0; i < ehdr.e_shnum; i++) {
465 char *sym_strtab;
466 Elf32_Sym *sh_symtab;
467 unsigned sec_applies, sec_symtab;
468 int j;
469 if (shdr[i].sh_type != SHT_REL) {
470 continue;
471 }
472 sec_symtab = shdr[i].sh_link;
473 sec_applies = shdr[i].sh_info;
474 if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
475 continue;
476 }
477 sh_symtab = symtab[sec_symtab];
478 sym_strtab = strtab[shdr[sec_symtab].sh_link];
479 for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
480 Elf32_Rel *rel;
481 Elf32_Sym *sym;
482 unsigned r_type;
483 rel = &reltab[i][j];
484 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
485 r_type = ELF32_R_TYPE(rel->r_info);
486 /* Don't visit relocations to absolute symbols */
487 if (sym->st_shndx == SHN_ABS) {
488 continue;
489 }
490 if (r_type == R_386_PC32) {
491 /* PC relative relocations don't need to be adjusted */
492 }
493 else if (r_type == R_386_32) {
494 /* Visit relocations that need to be adjusted */
495 visit(rel, sym);
496 }
497 else {
498 die("Unsupported relocation type: %d\n", r_type);
499 }
500 }
501 }
502}
503
504static void count_reloc(Elf32_Rel *rel, Elf32_Sym *sym)
505{
506 reloc_count += 1;
507}
508
509static void collect_reloc(Elf32_Rel *rel, Elf32_Sym *sym)
510{
511 /* Remember the address that needs to be adjusted. */
512 relocs[reloc_idx++] = rel->r_offset;
513}
514
515static int cmp_relocs(const void *va, const void *vb)
516{
517 const unsigned long *a, *b;
518 a = va; b = vb;
519 return (*a == *b)? 0 : (*a > *b)? 1 : -1;
520}
521
522static void emit_relocs(int as_text)
523{
524 int i;
525 /* Count how many relocations I have and allocate space for them. */
526 reloc_count = 0;
527 walk_relocs(count_reloc);
528 relocs = malloc(reloc_count * sizeof(relocs[0]));
529 if (!relocs) {
530 die("malloc of %d entries for relocs failed\n",
531 reloc_count);
532 }
533 /* Collect up the relocations */
534 reloc_idx = 0;
535 walk_relocs(collect_reloc);
536
537 /* Order the relocations for more efficient processing */
538 qsort(relocs, reloc_count, sizeof(relocs[0]), cmp_relocs);
539
540 /* Print the relocations */
541 if (as_text) {
542 /* Print the relocations in a form suitable that
543 * gas will like.
544 */
545 printf(".section \".data.reloc\",\"a\"\n");
546 printf(".balign 4\n");
547 for(i = 0; i < reloc_count; i++) {
548 printf("\t .long 0x%08lx\n", relocs[i]);
549 }
550 printf("\n");
551 }
552 else {
553 unsigned char buf[4];
554 buf[0] = buf[1] = buf[2] = buf[3] = 0;
555 /* Print a stop */
556 printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]);
557 /* Now print each relocation */
558 for(i = 0; i < reloc_count; i++) {
559 buf[0] = (relocs[i] >> 0) & 0xff;
560 buf[1] = (relocs[i] >> 8) & 0xff;
561 buf[2] = (relocs[i] >> 16) & 0xff;
562 buf[3] = (relocs[i] >> 24) & 0xff;
563 printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]);
564 }
565 }
566}
567
568static void usage(void)
569{
570 die("relocs [--abs-syms |--abs-relocs | --text] vmlinux\n");
571}
572
573int main(int argc, char **argv)
574{
575 int show_absolute_syms, show_absolute_relocs;
576 int as_text;
577 const char *fname;
578 FILE *fp;
579 int i;
580
581 show_absolute_syms = 0;
582 show_absolute_relocs = 0;
583 as_text = 0;
584 fname = NULL;
585 for(i = 1; i < argc; i++) {
586 char *arg = argv[i];
587 if (*arg == '-') {
588 if (strcmp(argv[1], "--abs-syms") == 0) {
589 show_absolute_syms = 1;
590 continue;
591 }
592
593 if (strcmp(argv[1], "--abs-relocs") == 0) {
594 show_absolute_relocs = 1;
595 continue;
596 }
597 else if (strcmp(argv[1], "--text") == 0) {
598 as_text = 1;
599 continue;
600 }
601 }
602 else if (!fname) {
603 fname = arg;
604 continue;
605 }
606 usage();
607 }
608 if (!fname) {
609 usage();
610 }
611 fp = fopen(fname, "r");
612 if (!fp) {
613 die("Cannot open %s: %s\n",
614 fname, strerror(errno));
615 }
616 read_ehdr(fp);
617 read_shdrs(fp);
618 read_strtabs(fp);
619 read_symtabs(fp);
620 read_relocs(fp);
621 if (show_absolute_syms) {
622 print_absolute_symbols();
623 return 0;
624 }
625 if (show_absolute_relocs) {
626 print_absolute_relocs();
627 return 0;
628 }
629 emit_relocs(as_text);
630 return 0;
631}
diff --git a/arch/i386/boot/compressed/vmlinux_32.lds b/arch/i386/boot/compressed/vmlinux_32.lds
deleted file mode 100644
index cc4854f6c6c1..000000000000
--- a/arch/i386/boot/compressed/vmlinux_32.lds
+++ /dev/null
@@ -1,43 +0,0 @@
1OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
2OUTPUT_ARCH(i386)
3ENTRY(startup_32)
4SECTIONS
5{
6 /* Be careful parts of head.S assume startup_32 is at
7 * address 0.
8 */
9 . = 0 ;
10 .text.head : {
11 _head = . ;
12 *(.text.head)
13 _ehead = . ;
14 }
15 .data.compressed : {
16 *(.data.compressed)
17 }
18 .text : {
19 _text = .; /* Text */
20 *(.text)
21 *(.text.*)
22 _etext = . ;
23 }
24 .rodata : {
25 _rodata = . ;
26 *(.rodata) /* read-only data */
27 *(.rodata.*)
28 _erodata = . ;
29 }
30 .data : {
31 _data = . ;
32 *(.data)
33 *(.data.*)
34 _edata = . ;
35 }
36 .bss : {
37 _bss = . ;
38 *(.bss)
39 *(.bss.*)
40 *(COMMON)
41 _end = . ;
42 }
43}
diff --git a/arch/i386/boot/compressed/vmlinux_32.scr b/arch/i386/boot/compressed/vmlinux_32.scr
deleted file mode 100644
index 707a88f7f29e..000000000000
--- a/arch/i386/boot/compressed/vmlinux_32.scr
+++ /dev/null
@@ -1,10 +0,0 @@
1SECTIONS
2{
3 .data.compressed : {
4 input_len = .;
5 LONG(input_data_end - input_data) input_data = .;
6 *(.data)
7 output_len = . - 4;
8 input_data_end = .;
9 }
10}