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));
57 #elif defined(CONFIG_CPU_V7)
59 static void icedcc_putc(int ch)
62 "wait: mrc p14, 0, pc, c0, c1, 0 \n\
64 mcr p14, 0, %0, c0, c5, 0 "
68 #elif defined(CONFIG_CPU_XSCALE)
70 static void icedcc_putc(int ch)
72 int status, i = 0x4000000;
78 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
79 } while (status & (1 << 28));
81 asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
86 static void icedcc_putc(int ch)
88 int status, i = 0x4000000;
94 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
97 asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
102 #define putc(ch) icedcc_putc(ch)
105 static void putstr(const char *ptr)
109 while ((c = *ptr++) != '\0') {
120 #define __ptr_t void *
122 #define memzero(s,n) __memzero(s,n)
125 * Optimised C version of memzero for the ARM.
127 void __memzero (__ptr_t s, size_t n)
129 union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
134 for (i = n >> 5; i > 0; i--) {
169 static inline __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
173 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
175 for (i = __n >> 3; i > 0; i--) {
207 #define STATIC static
209 /* Diagnostic functions */
211 # define Assert(cond,msg) {if(!(cond)) error(msg);}
212 # define Trace(x) fprintf x
213 # define Tracev(x) {if (verbose) fprintf x ;}
214 # define Tracevv(x) {if (verbose>1) fprintf x ;}
215 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
216 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
218 # define Assert(cond,msg)
223 # define Tracecv(c,x)
226 static void error(char *m);
228 extern char input_data[];
229 extern char input_data_end[];
231 static unsigned char *output_data;
232 static unsigned long output_ptr;
234 static void error(char *m);
236 static void putstr(const char *);
238 static unsigned long free_mem_ptr;
239 static unsigned long free_mem_end_ptr;
241 #ifdef STANDALONE_DEBUG
242 #define NO_INFLATE_MALLOC
245 #define ARCH_HAS_DECOMP_WDOG
247 #ifdef CONFIG_KERNEL_GZIP
248 #include "../../../../lib/decompress_inflate.c"
251 #ifdef CONFIG_KERNEL_LZO
252 #include "../../../../lib/decompress_unlzo.c"
256 #define arch_error(x)
259 static void error(char *x)
265 putstr("\n\n -- System halted");
270 asmlinkage void __div0(void)
272 error("Attempting division by 0!");
275 #ifndef STANDALONE_DEBUG
278 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
279 unsigned long free_mem_ptr_end_p,
284 output_data = (unsigned char *)output_start;
285 free_mem_ptr = free_mem_ptr_p;
286 free_mem_end_ptr = free_mem_ptr_end_p;
287 __machine_arch_type = arch_id;
291 tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
292 output_ptr = get_unaligned_le32(tmp);
294 putstr("Uncompressing Linux...");
295 decompress(input_data, input_data_end - input_data,
296 NULL, NULL, output_data, NULL, error);
297 putstr(" done, booting the kernel.\n");
302 char output_buffer[1500*1024];
306 output_data = output_buffer;
308 putstr("Uncompressing Linux...");
309 decompress(input_data, input_data_end - input_data,
310 NULL, NULL, output_data, NULL, error);