4 * This is a collection of several routines from gzip-1.0.3
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * Modified for ARM Linux by Russell King
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.
19 unsigned int __machine_arch_type
;
21 #define _LINUX_STRING_H_
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>
29 #include <asm/unaligned.h>
31 #ifdef STANDALONE_DEBUG
35 static void putstr(const char *ptr
);
37 #include <mach/uncompress.h>
39 #ifdef CONFIG_DEBUG_ICEDCC
43 static void icedcc_putc(int ch
)
45 int status
, i
= 0x4000000;
51 asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status
));
52 } while (status
& (1 << 29));
54 asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch
));
56 #elif defined(CONFIG_CPU_XSCALE)
58 static void icedcc_putc(int ch
)
60 int status
, i
= 0x4000000;
66 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status
));
67 } while (status
& (1 << 28));
69 asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch
));
74 static void icedcc_putc(int ch
)
76 int status
, i
= 0x4000000;
82 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status
));
85 asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch
));
90 #define putc(ch) icedcc_putc(ch)
91 #define flush() do { } while (0)
94 static void putstr(const char *ptr
)
98 while ((c
= *ptr
++) != '\0') {
109 #define __ptr_t void *
111 #define memzero(s,n) __memzero(s,n)
114 * Optimised C version of memzero for the ARM.
116 void __memzero (__ptr_t s
, size_t n
)
118 union { void *vp
; unsigned long *ulp
; unsigned char *ucp
; } u
;
123 for (i
= n
>> 5; i
> 0; i
--) {
158 static inline __ptr_t
memcpy(__ptr_t __dest
, __const __ptr_t __src
,
162 unsigned char *d
= (unsigned char *)__dest
, *s
= (unsigned char *)__src
;
164 for (i
= __n
>> 3; i
> 0; i
--) {
196 #define STATIC static
198 /* Diagnostic functions */
200 # define Assert(cond,msg) {if(!(cond)) error(msg);}
201 # define Trace(x) fprintf x
202 # define Tracev(x) {if (verbose) fprintf x ;}
203 # define Tracevv(x) {if (verbose>1) fprintf x ;}
204 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
205 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
207 # define Assert(cond,msg)
212 # define Tracecv(c,x)
215 static void error(char *m
);
217 extern char input_data
[];
218 extern char input_data_end
[];
220 static unsigned char *output_data
;
221 static unsigned long output_ptr
;
223 static void error(char *m
);
225 static void putstr(const char *);
227 static unsigned long free_mem_ptr
;
228 static unsigned long free_mem_end_ptr
;
230 #ifdef STANDALONE_DEBUG
231 #define NO_INFLATE_MALLOC
234 #define ARCH_HAS_DECOMP_WDOG
236 #ifdef CONFIG_KERNEL_GZIP
237 #include "../../../../lib/decompress_inflate.c"
240 #ifdef CONFIG_KERNEL_LZO
241 #include "../../../../lib/decompress_unlzo.c"
245 #define arch_error(x)
248 static void error(char *x
)
254 putstr("\n\n -- System halted");
259 asmlinkage
void __div0(void)
261 error("Attempting division by 0!");
264 #ifndef STANDALONE_DEBUG
267 decompress_kernel(unsigned long output_start
, unsigned long free_mem_ptr_p
,
268 unsigned long free_mem_ptr_end_p
,
273 output_data
= (unsigned char *)output_start
;
274 free_mem_ptr
= free_mem_ptr_p
;
275 free_mem_end_ptr
= free_mem_ptr_end_p
;
276 __machine_arch_type
= arch_id
;
280 tmp
= (unsigned char *) (((unsigned long)input_data_end
) - 4);
281 output_ptr
= get_unaligned_le32(tmp
);
283 putstr("Uncompressing Linux...");
284 decompress(input_data
, input_data_end
- input_data
,
285 NULL
, NULL
, output_data
, NULL
, error
);
286 putstr(" done, booting the kernel.\n");
291 char output_buffer
[1500*1024];
295 output_data
= output_buffer
;
297 putstr("Uncompressing Linux...");
298 decompress(input_data
, input_data_end
- input_data
,
299 NULL
, NULL
, output_data
, NULL
, error
);