added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / arch / m32r / boot / compressed / misc.c
blobd394292498c0eb245161cd93c17c16b4b8ccca7b
1 /*
2 * arch/m32r/boot/compressed/misc.c
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * Adapted for SH by Stuart Menefy, Aug 1999
11 * 2003-02-12: Support M32R by Takeo Takahashi
12 * This is based on arch/sh/boot/compressed/misc.c.
15 #include <linux/string.h>
18 * gzip declarations
21 #define OF(args) args
22 #define STATIC static
24 #undef memset
25 #undef memcpy
26 #define memzero(s, n) memset ((s), 0, (n))
28 typedef unsigned char uch;
29 typedef unsigned short ush;
30 typedef unsigned long ulg;
32 #define WSIZE 0x8000 /* Window size must be at least 32k, */
33 /* and a power of two */
35 static uch *inbuf; /* input buffer */
36 static uch window[WSIZE]; /* Sliding window buffer */
38 static unsigned insize = 0; /* valid bytes in inbuf */
39 static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
40 static unsigned outcnt = 0; /* bytes in output buffer */
42 /* gzip flag byte */
43 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
44 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
45 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
46 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
47 #define COMMENT 0x10 /* bit 4 set: file comment present */
48 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
49 #define RESERVED 0xC0 /* bit 6,7: reserved */
51 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
53 /* Diagnostic functions */
54 #ifdef DEBUG
55 # define Assert(cond,msg) {if(!(cond)) error(msg);}
56 # define Trace(x) fprintf x
57 # define Tracev(x) {if (verbose) fprintf x ;}
58 # define Tracevv(x) {if (verbose>1) fprintf x ;}
59 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
60 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
61 #else
62 # define Assert(cond,msg)
63 # define Trace(x)
64 # define Tracev(x)
65 # define Tracevv(x)
66 # define Tracec(c,x)
67 # define Tracecv(c,x)
68 #endif
70 static int fill_inbuf(void);
71 static void flush_window(void);
72 static void error(char *m);
74 static unsigned char *input_data;
75 static int input_len;
77 static long bytes_out = 0;
78 static uch *output_data;
79 static unsigned long output_ptr = 0;
81 #include "m32r_sio.c"
83 static unsigned long free_mem_ptr;
84 static unsigned long free_mem_end_ptr;
86 #define HEAP_SIZE 0x10000
88 #include "../../../../lib/inflate.c"
90 void* memset(void* s, int c, size_t n)
92 int i;
93 char *ss = (char*)s;
95 for (i=0;i<n;i++) ss[i] = c;
96 return s;
99 void* memcpy(void* __dest, __const void* __src,
100 size_t __n)
102 int i;
103 char *d = (char *)__dest, *s = (char *)__src;
105 for (i=0;i<__n;i++) d[i] = s[i];
106 return __dest;
109 /* ===========================================================================
110 * Fill the input buffer. This is called only when the buffer is empty
111 * and at least one byte is really needed.
113 static int fill_inbuf(void)
115 if (insize != 0) {
116 error("ran out of input data");
119 inbuf = input_data;
120 insize = input_len;
121 inptr = 1;
122 return inbuf[0];
125 /* ===========================================================================
126 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
127 * (Used for the decompressed data only.)
129 static void flush_window(void)
131 ulg c = crc; /* temporary variable */
132 unsigned n;
133 uch *in, *out, ch;
135 in = window;
136 out = &output_data[output_ptr];
137 for (n = 0; n < outcnt; n++) {
138 ch = *out++ = *in++;
139 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
141 crc = c;
142 bytes_out += (ulg)outcnt;
143 output_ptr += (ulg)outcnt;
144 outcnt = 0;
147 static void error(char *x)
149 puts("\n\n");
150 puts(x);
151 puts("\n\n -- System halted");
153 while(1); /* Halt */
156 /* return decompressed size */
157 void
158 decompress_kernel(int mmu_on, unsigned char *zimage_data,
159 unsigned int zimage_len, unsigned long heap)
161 output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000
162 + (mmu_on ? 0x80000000 : 0);
163 free_mem_ptr = heap;
164 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
165 input_data = zimage_data;
166 input_len = zimage_len;
168 makecrc();
169 puts("Uncompressing Linux... ");
170 gunzip();
171 puts("Ok, booting the kernel.\n");