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 #include <linux/string.h>
23 #ifdef STANDALONE_DEBUG
27 static void putstr(const char *ptr);
29 #include <linux/compiler.h>
30 #include <mach/uncompress.h>
32 #ifdef CONFIG_DEBUG_ICEDCC
36 static void icedcc_putc(int ch)
38 int status, i = 0x4000000;
44 asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
45 } while (status & (1 << 29));
47 asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
49 #elif defined(CONFIG_CPU_XSCALE)
51 static void icedcc_putc(int ch)
53 int status, i = 0x4000000;
59 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
60 } while (status & (1 << 28));
62 asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
67 static void icedcc_putc(int ch)
69 int status, i = 0x4000000;
75 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
78 asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
83 #define putc(ch) icedcc_putc(ch)
84 #define flush() do { } while (0)
87 static void putstr(const char *ptr)
91 while ((c = *ptr++) != '\0') {
102 #define __ptr_t void *
104 #define memzero(s,n) __memzero(s,n)
107 * Optimised C version of memzero for the ARM.
109 void __memzero (__ptr_t s, size_t n)
111 union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
116 for (i = n >> 5; i > 0; i--) {
151 static inline __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
155 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
157 for (i = __n >> 3; i > 0; i--) {
189 #define OF(args) args
190 #define STATIC static
192 typedef unsigned char uch;
193 typedef unsigned short ush;
194 typedef unsigned long ulg;
196 #define WSIZE 0x8000 /* Window size must be at least 32k, */
197 /* and a power of two */
199 static uch *inbuf; /* input buffer */
200 static uch window[WSIZE]; /* Sliding window buffer */
202 static unsigned insize; /* valid bytes in inbuf */
203 static unsigned inptr; /* index of next byte to be processed in inbuf */
204 static unsigned outcnt; /* bytes in output buffer */
207 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
208 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
209 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
210 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
211 #define COMMENT 0x10 /* bit 4 set: file comment present */
212 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
213 #define RESERVED 0xC0 /* bit 6,7: reserved */
215 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
217 /* Diagnostic functions */
219 # define Assert(cond,msg) {if(!(cond)) error(msg);}
220 # define Trace(x) fprintf x
221 # define Tracev(x) {if (verbose) fprintf x ;}
222 # define Tracevv(x) {if (verbose>1) fprintf x ;}
223 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
224 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
226 # define Assert(cond,msg)
231 # define Tracecv(c,x)
234 static int fill_inbuf(void);
235 static void flush_window(void);
236 static void error(char *m);
238 extern char input_data[];
239 extern char input_data_end[];
241 static uch *output_data;
242 static ulg output_ptr;
243 static ulg bytes_out;
245 static void error(char *m);
247 static void putstr(const char *);
250 static ulg free_mem_ptr;
251 static ulg free_mem_end_ptr;
253 #ifdef STANDALONE_DEBUG
254 #define NO_INFLATE_MALLOC
257 #define ARCH_HAS_DECOMP_WDOG
259 #include "../../../../lib/inflate.c"
261 /* ===========================================================================
262 * Fill the input buffer. This is called only when the buffer is empty
263 * and at least one byte is really needed.
268 error("ran out of input data");
271 insize = &input_data_end[0] - &input_data[0];
277 /* ===========================================================================
278 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
279 * (Used for the decompressed data only.)
281 void flush_window(void)
288 out = &output_data[output_ptr];
289 for (n = 0; n < outcnt; n++) {
291 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
294 bytes_out += (ulg)outcnt;
295 output_ptr += (ulg)outcnt;
301 #define arch_error(x)
304 static void error(char *x)
310 putstr("\n\n -- System halted");
315 #ifndef STANDALONE_DEBUG
318 decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
321 output_data = (uch *)output_start; /* Points to kernel start */
322 free_mem_ptr = free_mem_ptr_p;
323 free_mem_end_ptr = free_mem_ptr_end_p;
324 __machine_arch_type = arch_id;
329 putstr("Uncompressing Linux...");
331 putstr(" done, booting the kernel.\n");
336 char output_buffer[1500*1024];
340 output_data = output_buffer;
343 putstr("Uncompressing Linux...");