]> bbs.cooldavid.org Git - net-next-2.6.git/blob - arch/arm/boot/compressed/misc.c
ARM: Eliminate decompressor -Dstatic= PIC hack
[net-next-2.6.git] / arch / arm / boot / compressed / misc.c
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  *
9  * Modified for ARM Linux by Russell King
10  *
11  * Nicolas Pitre <nico@visuaide.com>  1999/04/14 :
12  *  For this code to run directly from Flash, all constant variables must
13  *  be marked with 'const' and all other variables initialized at run-time 
14  *  only.  This way all non constant variables will end up in the bss segment,
15  *  which should point to addresses in RAM and cleared to 0 on start.
16  *  This allows for a much quicker boot time.
17  */
18
19 unsigned int __machine_arch_type;
20
21 #define _LINUX_STRING_H_
22
23 #include <linux/compiler.h>     /* for inline */
24 #include <linux/types.h>        /* for size_t */
25 #include <linux/stddef.h>       /* for NULL */
26 #include <linux/linkage.h>
27 #include <asm/string.h>
28
29 #include <asm/unaligned.h>
30
31 #ifdef STANDALONE_DEBUG
32 #define putstr printf
33 #else
34
35 static void putstr(const char *ptr);
36
37 #include <mach/uncompress.h>
38
39 #ifdef CONFIG_DEBUG_ICEDCC
40
41 #ifdef CONFIG_CPU_V6
42
43 static void icedcc_putc(int ch)
44 {
45         int status, i = 0x4000000;
46
47         do {
48                 if (--i < 0)
49                         return;
50
51                 asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
52         } while (status & (1 << 29));
53
54         asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
55 }
56 #elif defined(CONFIG_CPU_XSCALE)
57
58 static void icedcc_putc(int ch)
59 {
60         int status, i = 0x4000000;
61
62         do {
63                 if (--i < 0)
64                         return;
65
66                 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
67         } while (status & (1 << 28));
68
69         asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
70 }
71
72 #else
73
74 static void icedcc_putc(int ch)
75 {
76         int status, i = 0x4000000;
77
78         do {
79                 if (--i < 0)
80                         return;
81
82                 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
83         } while (status & 2);
84
85         asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
86 }
87
88 #endif
89
90 #define putc(ch)        icedcc_putc(ch)
91 #define flush() do { } while (0)
92 #endif
93
94 static void putstr(const char *ptr)
95 {
96         char c;
97
98         while ((c = *ptr++) != '\0') {
99                 if (c == '\n')
100                         putc('\r');
101                 putc(c);
102         }
103
104         flush();
105 }
106
107 #endif
108
109 void *memcpy(void *__dest, __const void *__src, size_t __n)
110 {
111         int i = 0;
112         unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
113
114         for (i = __n >> 3; i > 0; i--) {
115                 *d++ = *s++;
116                 *d++ = *s++;
117                 *d++ = *s++;
118                 *d++ = *s++;
119                 *d++ = *s++;
120                 *d++ = *s++;
121                 *d++ = *s++;
122                 *d++ = *s++;
123         }
124
125         if (__n & 1 << 2) {
126                 *d++ = *s++;
127                 *d++ = *s++;
128                 *d++ = *s++;
129                 *d++ = *s++;
130         }
131
132         if (__n & 1 << 1) {
133                 *d++ = *s++;
134                 *d++ = *s++;
135         }
136
137         if (__n & 1)
138                 *d++ = *s++;
139
140         return __dest;
141 }
142
143 /*
144  * gzip delarations
145  */
146 extern char input_data[];
147 extern char input_data_end[];
148
149 unsigned char *output_data;
150 unsigned long output_ptr;
151
152 unsigned long free_mem_ptr;
153 unsigned long free_mem_end_ptr;
154
155 #ifndef arch_error
156 #define arch_error(x)
157 #endif
158
159 void error(char *x)
160 {
161         arch_error(x);
162
163         putstr("\n\n");
164         putstr(x);
165         putstr("\n\n -- System halted");
166
167         while(1);       /* Halt */
168 }
169
170 asmlinkage void __div0(void)
171 {
172         error("Attempting division by 0!");
173 }
174
175 extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
176
177 #ifndef STANDALONE_DEBUG
178
179 unsigned long
180 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
181                 unsigned long free_mem_ptr_end_p,
182                 int arch_id)
183 {
184         unsigned char *tmp;
185
186         output_data             = (unsigned char *)output_start;
187         free_mem_ptr            = free_mem_ptr_p;
188         free_mem_end_ptr        = free_mem_ptr_end_p;
189         __machine_arch_type     = arch_id;
190
191         arch_decomp_setup();
192
193         tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
194         output_ptr = get_unaligned_le32(tmp);
195
196         putstr("Uncompressing Linux...");
197         do_decompress(input_data, input_data_end - input_data,
198                         output_data, error);
199         putstr(" done, booting the kernel.\n");
200         return output_ptr;
201 }
202 #else
203
204 char output_buffer[1500*1024];
205
206 int main()
207 {
208         output_data = output_buffer;
209
210         putstr("Uncompressing Linux...");
211         decompress(input_data, input_data_end - input_data,
212                         NULL, NULL, output_data, NULL, error);
213         putstr("done.\n");
214         return 0;
215 }
216 #endif