ARM: 5882/1: ARM: Fix uncompress code compile for different defines of flush(void)
[safe/jmp/linux-2.6] / 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 <asm/string.h>
27 #include <linux/linkage.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 #endif
92
93 static void putstr(const char *ptr)
94 {
95         char c;
96
97         while ((c = *ptr++) != '\0') {
98                 if (c == '\n')
99                         putc('\r');
100                 putc(c);
101         }
102
103         flush();
104 }
105
106 #endif
107
108 #define __ptr_t void *
109
110 #define memzero(s,n) __memzero(s,n)
111
112 /*
113  * Optimised C version of memzero for the ARM.
114  */
115 void __memzero (__ptr_t s, size_t n)
116 {
117         union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
118         int i;
119
120         u.vp = s;
121
122         for (i = n >> 5; i > 0; i--) {
123                 *u.ulp++ = 0;
124                 *u.ulp++ = 0;
125                 *u.ulp++ = 0;
126                 *u.ulp++ = 0;
127                 *u.ulp++ = 0;
128                 *u.ulp++ = 0;
129                 *u.ulp++ = 0;
130                 *u.ulp++ = 0;
131         }
132
133         if (n & 1 << 4) {
134                 *u.ulp++ = 0;
135                 *u.ulp++ = 0;
136                 *u.ulp++ = 0;
137                 *u.ulp++ = 0;
138         }
139
140         if (n & 1 << 3) {
141                 *u.ulp++ = 0;
142                 *u.ulp++ = 0;
143         }
144
145         if (n & 1 << 2)
146                 *u.ulp++ = 0;
147
148         if (n & 1 << 1) {
149                 *u.ucp++ = 0;
150                 *u.ucp++ = 0;
151         }
152
153         if (n & 1)
154                 *u.ucp++ = 0;
155 }
156
157 static inline __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
158                             size_t __n)
159 {
160         int i = 0;
161         unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
162
163         for (i = __n >> 3; i > 0; i--) {
164                 *d++ = *s++;
165                 *d++ = *s++;
166                 *d++ = *s++;
167                 *d++ = *s++;
168                 *d++ = *s++;
169                 *d++ = *s++;
170                 *d++ = *s++;
171                 *d++ = *s++;
172         }
173
174         if (__n & 1 << 2) {
175                 *d++ = *s++;
176                 *d++ = *s++;
177                 *d++ = *s++;
178                 *d++ = *s++;
179         }
180
181         if (__n & 1 << 1) {
182                 *d++ = *s++;
183                 *d++ = *s++;
184         }
185
186         if (__n & 1)
187                 *d++ = *s++;
188
189         return __dest;
190 }
191
192 /*
193  * gzip delarations
194  */
195 #define STATIC static
196
197 /* Diagnostic functions */
198 #ifdef DEBUG
199 #  define Assert(cond,msg) {if(!(cond)) error(msg);}
200 #  define Trace(x) fprintf x
201 #  define Tracev(x) {if (verbose) fprintf x ;}
202 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
203 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
204 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
205 #else
206 #  define Assert(cond,msg)
207 #  define Trace(x)
208 #  define Tracev(x)
209 #  define Tracevv(x)
210 #  define Tracec(c,x)
211 #  define Tracecv(c,x)
212 #endif
213
214 static void error(char *m);
215
216 extern char input_data[];
217 extern char input_data_end[];
218
219 static unsigned char *output_data;
220 static unsigned long output_ptr;
221
222 static void error(char *m);
223
224 static void putstr(const char *);
225
226 static unsigned long free_mem_ptr;
227 static unsigned long free_mem_end_ptr;
228
229 #ifdef STANDALONE_DEBUG
230 #define NO_INFLATE_MALLOC
231 #endif
232
233 #define ARCH_HAS_DECOMP_WDOG
234
235 #ifdef CONFIG_KERNEL_GZIP
236 #include "../../../../lib/decompress_inflate.c"
237 #endif
238
239 #ifdef CONFIG_KERNEL_LZO
240 #include "../../../../lib/decompress_unlzo.c"
241 #endif
242
243 #ifndef arch_error
244 #define arch_error(x)
245 #endif
246
247 static void error(char *x)
248 {
249         arch_error(x);
250
251         putstr("\n\n");
252         putstr(x);
253         putstr("\n\n -- System halted");
254
255         while(1);       /* Halt */
256 }
257
258 asmlinkage void __div0(void)
259 {
260         error("Attempting division by 0!");
261 }
262
263 #ifndef STANDALONE_DEBUG
264
265 unsigned long
266 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
267                 unsigned long free_mem_ptr_end_p,
268                 int arch_id)
269 {
270         unsigned char *tmp;
271
272         output_data             = (unsigned char *)output_start;
273         free_mem_ptr            = free_mem_ptr_p;
274         free_mem_end_ptr        = free_mem_ptr_end_p;
275         __machine_arch_type     = arch_id;
276
277         arch_decomp_setup();
278
279         tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
280         output_ptr = get_unaligned_le32(tmp);
281
282         putstr("Uncompressing Linux...");
283         decompress(input_data, input_data_end - input_data,
284                         NULL, NULL, output_data, NULL, error);
285         putstr(" done, booting the kernel.\n");
286         return output_ptr;
287 }
288 #else
289
290 char output_buffer[1500*1024];
291
292 int main()
293 {
294         output_data = output_buffer;
295
296         putstr("Uncompressing Linux...");
297         decompress(input_data, input_data_end - input_data,
298                         NULL, NULL, output_data, NULL, error);
299         putstr("done.\n");
300         return 0;
301 }
302 #endif