]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-mtx-1-2.4.27/06-zboot-2.4.26.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-mtx-1-2.4.27 / 06-zboot-2.4.26.patch
1 diff -Naru linux/arch/mips/Makefile linux.spi/arch/mips/Makefile
2 --- linux/arch/mips/Makefile    2004-05-06 15:23:41.000000000 -0400
3 +++ linux.spi/arch/mips/Makefile        2004-05-11 23:19:24.000000000 -0400
4 @@ -29,6 +29,8 @@
5  endif
6  
7  MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
8 +MAKEZBOOT = $(MAKE) -C arch/$(ARCH)/zboot
9 +BOOT_TARGETS = zImage zImage.initrd zImage.flash
10  
11  check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
12  
13 @@ -757,12 +749,16 @@
14  
15  vmlinux.ecoff: vmlinux
16         @$(MAKEBOOT) $@
17 +  
18 +$(BOOT_TARGETS): vmlinux
19 +       @$(MAKEZBOOT) $@
20  
21  vmlinux.srec: vmlinux
22         @$(MAKEBOOT) $@
23  
24  archclean:
25         @$(MAKEBOOT) clean
26 +       @$(MAKEZBOOT) clean
27         rm -f arch/$(ARCH)/ld.script
28         $(MAKE) -C arch/$(ARCH)/tools clean
29         $(MAKE) -C arch/mips/baget clean
30 diff -Naru linux/arch/mips/zboot/common/au1k_uart.c linux.spi/arch/mips/zboot/common/au1k_uart.c
31 --- linux/arch/mips/zboot/common/au1k_uart.c    1969-12-31 19:00:00.000000000 -0500
32 +++ linux.spi/arch/mips/zboot/common/au1k_uart.c        2004-05-11 23:19:24.000000000 -0400
33 @@ -0,0 +1,103 @@
34 +/*
35 + * BRIEF MODULE DESCRIPTION
36 + *     Simple Au1000 uart routines.
37 + *
38 + * Copyright 2001 MontaVista Software Inc.
39 + * Author: MontaVista Software, Inc.
40 + *             ppopov@mvista.com or source@mvista.com
41 + *
42 + *  This program is free software; you can redistribute         it and/or modify it
43 + *  under  the terms of         the GNU General  Public License as published by the
44 + *  Free Software Foundation;  either version 2 of the License, or (at your
45 + *  option) any later version.
46 + *
47 + *  THIS  SOFTWARE  IS PROVIDED          ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
48 + *  WARRANTIES,          INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
49 + *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
50 + *  NO EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
51 + *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 + *  NOT LIMITED          TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
53 + *  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
54 + *  ANY THEORY OF LIABILITY, WHETHER IN         CONTRACT, STRICT LIABILITY, OR TORT
55 + *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 + *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 + *
58 + *  You should have received a copy of the  GNU General Public License along
59 + *  with this program; if not, write  to the Free Software Foundation, Inc.,
60 + *  675 Mass Ave, Cambridge, MA 02139, USA.
61 + */
62 +#include <linux/config.h>
63 +#include <asm/io.h>
64 +#include <asm/au1000.h>
65 +#include "ns16550.h"
66 +
67 +typedef         unsigned char uint8;
68 +typedef         unsigned int  uint32;
69 +
70 +#define         UART16550_BAUD_2400             2400
71 +#define         UART16550_BAUD_4800             4800
72 +#define         UART16550_BAUD_9600             9600
73 +#define         UART16550_BAUD_19200            19200
74 +#define         UART16550_BAUD_38400            38400
75 +#define         UART16550_BAUD_57600            57600
76 +#define         UART16550_BAUD_115200           115200
77 +
78 +#define         UART16550_PARITY_NONE           0
79 +#define         UART16550_PARITY_ODD            0x08
80 +#define         UART16550_PARITY_EVEN           0x18
81 +#define         UART16550_PARITY_MARK           0x28
82 +#define         UART16550_PARITY_SPACE          0x38
83 +
84 +#define         UART16550_DATA_5BIT             0x0
85 +#define         UART16550_DATA_6BIT             0x1
86 +#define         UART16550_DATA_7BIT             0x2
87 +#define         UART16550_DATA_8BIT             0x3
88 +
89 +#define         UART16550_STOP_1BIT             0x0
90 +#define         UART16550_STOP_2BIT             0x4
91 +
92 +/* It would be nice if we had a better way to do this.
93 + * It could be a variable defined in one of the board specific files.
94 + */
95 +#undef UART_BASE
96 +#ifdef CONFIG_COGENT_CSB250
97 +#define UART_BASE UART3_ADDR
98 +#else
99 +#define UART_BASE UART0_ADDR
100 +#endif
101 +
102 +/* memory-mapped read/write of the port */
103 +#define UART16550_READ(y)    (readl(UART_BASE + y) & 0xff)
104 +#define UART16550_WRITE(y,z) (writel(z&0xff, UART_BASE + y))
105 +
106 +/*
107 + * We use uart 0, which is already initialized by
108 + * yamon. 
109 + */
110 +volatile struct NS16550 *
111 +serial_init(int chan)
112 +{
113 +       volatile struct NS16550 *com_port;
114 +       com_port = (struct NS16550 *) UART_BASE;
115 +       return (com_port);
116 +}
117 +
118 +void
119 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
120 +{
121 +       while ((UART16550_READ(UART_LSR)&0x40) == 0);
122 +       UART16550_WRITE(UART_TX, c);
123 +}
124 +
125 +unsigned char
126 +serial_getc(volatile struct NS16550 *com_port)
127 +{
128 +       while((UART16550_READ(UART_LSR) & 0x1) == 0);
129 +       return UART16550_READ(UART_RX);
130 +}
131 +
132 +int
133 +serial_tstc(volatile struct NS16550 *com_port)
134 +{
135 +       return((UART16550_READ(UART_LSR) & LSR_DR) != 0);
136 +}
137 diff -Naru linux/arch/mips/zboot/common/ctype.c linux.spi/arch/mips/zboot/common/ctype.c
138 --- linux/arch/mips/zboot/common/ctype.c        1969-12-31 19:00:00.000000000 -0500
139 +++ linux.spi/arch/mips/zboot/common/ctype.c    2004-05-11 23:19:24.000000000 -0400
140 @@ -0,0 +1,35 @@
141 +/*
142 + *  linux/lib/ctype.c
143 + *
144 + *  Copyright (C) 1991, 1992  Linus Torvalds
145 + */
146 +
147 +#include <linux/ctype.h>
148 +
149 +unsigned char _ctype[] = {
150 +_C,_C,_C,_C,_C,_C,_C,_C,                       /* 0-7 */
151 +_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,                /* 8-15 */
152 +_C,_C,_C,_C,_C,_C,_C,_C,                       /* 16-23 */
153 +_C,_C,_C,_C,_C,_C,_C,_C,                       /* 24-31 */
154 +_S|_SP,_P,_P,_P,_P,_P,_P,_P,                   /* 32-39 */
155 +_P,_P,_P,_P,_P,_P,_P,_P,                       /* 40-47 */
156 +_D,_D,_D,_D,_D,_D,_D,_D,                       /* 48-55 */
157 +_D,_D,_P,_P,_P,_P,_P,_P,                       /* 56-63 */
158 +_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,     /* 64-71 */
159 +_U,_U,_U,_U,_U,_U,_U,_U,                       /* 72-79 */
160 +_U,_U,_U,_U,_U,_U,_U,_U,                       /* 80-87 */
161 +_U,_U,_U,_P,_P,_P,_P,_P,                       /* 88-95 */
162 +_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,     /* 96-103 */
163 +_L,_L,_L,_L,_L,_L,_L,_L,                       /* 104-111 */
164 +_L,_L,_L,_L,_L,_L,_L,_L,                       /* 112-119 */
165 +_L,_L,_L,_P,_P,_P,_P,_C,                       /* 120-127 */
166 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,               /* 128-143 */
167 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,               /* 144-159 */
168 +_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,   /* 160-175 */
169 +_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,       /* 176-191 */
170 +_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,       /* 192-207 */
171 +_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,       /* 208-223 */
172 +_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,       /* 224-239 */
173 +_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};      /* 240-255 */
174 +
175 +
176 diff -Naru linux/arch/mips/zboot/common/dummy.c linux.spi/arch/mips/zboot/common/dummy.c
177 --- linux/arch/mips/zboot/common/dummy.c        1969-12-31 19:00:00.000000000 -0500
178 +++ linux.spi/arch/mips/zboot/common/dummy.c    2004-05-11 23:19:24.000000000 -0400
179 @@ -0,0 +1,4 @@
180 +int main(void)
181 +{
182 +       return 0;
183 +}
184 diff -Naru linux/arch/mips/zboot/common/Makefile linux.spi/arch/mips/zboot/common/Makefile
185 --- linux/arch/mips/zboot/common/Makefile       1969-12-31 19:00:00.000000000 -0500
186 +++ linux.spi/arch/mips/zboot/common/Makefile   2004-05-11 23:19:24.000000000 -0400
187 @@ -0,0 +1,27 @@
188 +#
189 +# arch/mips/zboot/common/Makefile
190 +#
191 +# This file is subject to the terms and conditions of the GNU General Public
192 +# License.  See the file "COPYING" in the main directory of this archive
193 +# for more details.
194 +#
195 +# Tom Rini     January 2001
196 +#
197 +
198 +.c.s:
199 +       $(CC) $(CFLAGS) -S -o $*.s $<
200 +.s.o:
201 +       $(AS) -o $*.o $<
202 +.c.o:
203 +       $(CC) $(CFLAGS) -c -o $*.o $<
204 +.S.s:
205 +       $(CPP) $(AFLAGS) -o $*.o $<
206 +.S.o:
207 +       $(CC) $(AFLAGS) -c -o $*.o $<
208 +
209 +clean:
210 +       rm -rf *.o
211 +
212 +OBJCOPY_ARGS = -O elf32-tradlittlemips
213 +
214 +include $(TOPDIR)/Rules.make
215 diff -Naru linux/arch/mips/zboot/common/misc-common.c linux.spi/arch/mips/zboot/common/misc-common.c
216 --- linux/arch/mips/zboot/common/misc-common.c  1969-12-31 19:00:00.000000000 -0500
217 +++ linux.spi/arch/mips/zboot/common/misc-common.c      2004-05-11 23:19:24.000000000 -0400
218 @@ -0,0 +1,437 @@
219 +/*
220 + * arch/mips/zboot/common/misc-common.c
221 + * 
222 + * Misc. bootloader code (almost) all platforms can use
223 + *
224 + * Author: Johnnie Peters <jpeters@mvista.com>
225 + * Editor: Tom Rini <trini@mvista.com>
226 + *
227 + * Derived from arch/ppc/boot/prep/misc.c
228 + *
229 + * Ported by Pete Popov <ppopov@mvista.com> to
230 + * support mips board(s).  I also got rid of the vga console
231 + * code.
232 + *
233 + * Copyright 2000-2001 MontaVista Software Inc.
234 + *
235 + * This program is free software; you can redistribute  it and/or modify it
236 + * under  the terms of  the GNU General  Public License as published by the
237 + * Free Software Foundation;  either version 2 of the  License, or (at your
238 + * option) any later version.
239 + *
240 + * THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR   IMPLIED
241 + * WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
242 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
243 + * NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT,  INDIRECT,
244 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
245 + * NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
246 + * USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
247 + * ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
248 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
249 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250 + *
251 + * You should have received a copy of the  GNU General Public License along
252 + * with this program; if not, write  to the Free Software Foundation, Inc.,
253 + * 675 Mass Ave, Cambridge, MA 02139, USA.
254 + */
255 +
256 +#include <linux/config.h>
257 +#include "zlib.h"
258 +#include <stdarg.h>
259 +
260 +extern char *avail_ram;
261 +extern char *end_avail;
262 +extern char _end[];
263 +
264 +void puts(const char *);
265 +void putc(const char c);
266 +void puthex(unsigned long val);
267 +void _bcopy(char *src, char *dst, int len);
268 +void gunzip(void *, int, unsigned char *, int *);
269 +static int _cvt(unsigned long val, char *buf, long radix, char *digits);
270 +
271 +void _vprintk(void(*)(const char), const char *, va_list ap);
272 +
273 +struct NS16550 *com_port;
274 +
275 +int serial_tstc(volatile struct NS16550 *);
276 +unsigned char serial_getc(volatile struct NS16550 *);
277 +void serial_putc(volatile struct NS16550 *, unsigned char);
278 +
279 +void pause(void)
280 +{
281 +       puts("pause\n");
282 +}
283 +
284 +void exit(void)
285 +{
286 +       puts("exit\n");
287 +       while(1); 
288 +}
289 +
290 +int tstc(void)
291 +{
292 +       return (serial_tstc(com_port));
293 +}
294 +
295 +int getc(void)
296 +{
297 +       while (1) {
298 +               if (serial_tstc(com_port))
299 +                       return (serial_getc(com_port));
300 +       }
301 +}
302 +
303 +void 
304 +putc(const char c)
305 +{
306 +       int x,y;
307 +
308 +       serial_putc(com_port, c);
309 +       if ( c == '\n' )
310 +               serial_putc(com_port, '\r');
311 +}
312 +
313 +void puts(const char *s)
314 +{
315 +       char c;
316 +       while ( ( c = *s++ ) != '\0' ) {
317 +               serial_putc(com_port, c);
318 +               if ( c == '\n' ) serial_putc(com_port, '\r');
319 +       }
320 +}
321 +
322 +void error(char *x)
323 +{
324 +       puts("\n\n");
325 +       puts(x);
326 +       puts("\n\n -- System halted");
327 +
328 +       while(1);       /* Halt */
329 +}
330 +
331 +void *zalloc(void *x, unsigned items, unsigned size)
332 +{
333 +       void *p = avail_ram;
334 +       
335 +       size *= items;
336 +       size = (size + 7) & -8;
337 +       avail_ram += size;
338 +       if (avail_ram > end_avail) {
339 +               puts("oops... out of memory\n");
340 +               pause();
341 +       }
342 +       return p;
343 +}
344 +
345 +void zfree(void *x, void *addr, unsigned nb)
346 +{
347 +}
348 +
349 +#define HEAD_CRC       2
350 +#define EXTRA_FIELD    4
351 +#define ORIG_NAME      8
352 +#define COMMENT                0x10
353 +#define RESERVED       0xe0
354 +
355 +#define DEFLATED       8
356 +
357 +void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
358 +{
359 +       z_stream s;
360 +       int r, i, flags;
361 +       
362 +       /* skip header */
363 +       i = 10;
364 +       flags = src[3];
365 +       if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
366 +               puts("bad gzipped data\n");
367 +               exit();
368 +       }
369 +       if ((flags & EXTRA_FIELD) != 0)
370 +               i = 12 + src[10] + (src[11] << 8);
371 +       if ((flags & ORIG_NAME) != 0)
372 +               while (src[i++] != 0)
373 +                       ;
374 +       if ((flags & COMMENT) != 0)
375 +               while (src[i++] != 0)
376 +                       ;
377 +       if ((flags & HEAD_CRC) != 0)
378 +               i += 2;
379 +       if (i >= *lenp) {
380 +               puts("gunzip: ran out of data in header\n");
381 +               exit();
382 +       }
383 +       
384 +       s.zalloc = zalloc;
385 +       s.zfree = zfree;
386 +       r = inflateInit2(&s, -MAX_WBITS);
387 +       if (r != Z_OK) {
388 +               puts("inflateInit2 returned %d\n");
389 +               exit();
390 +       }
391 +       s.next_in = src + i;
392 +       s.avail_in = *lenp - i;
393 +       s.next_out = dst;
394 +       s.avail_out = dstlen;
395 +       r = inflate(&s, Z_FINISH);
396 +       if (r != Z_OK && r != Z_STREAM_END) {
397 +               puts("inflate returned %d\n");
398 +               exit();
399 +       }
400 +       *lenp = s.next_out - (unsigned char *) dst;
401 +       inflateEnd(&s);
402 +}
403 +
404 +void
405 +puthex(unsigned long val)
406 +{
407 +
408 +       unsigned char buf[10];
409 +       int i;
410 +       for (i = 7;  i >= 0;  i--)
411 +       {
412 +               buf[i] = "0123456789ABCDEF"[val & 0x0F];
413 +               val >>= 4;
414 +       }
415 +       buf[8] = '\0';
416 +       puts(buf);
417 +}
418 +
419 +#define FALSE 0
420 +#define TRUE  1
421 +
422 +void
423 +_printk(char const *fmt, ...)
424 +{
425 +       va_list ap;
426 +
427 +       va_start(ap, fmt);
428 +       _vprintk(putc, fmt, ap);
429 +       va_end(ap);
430 +       return;
431 +}
432 +
433 +#define is_digit(c) ((c >= '0') && (c <= '9'))
434 +
435 +void
436 +_vprintk(void(*putc)(const char), const char *fmt0, va_list ap)
437 +{
438 +       char c, sign, *cp = 0;
439 +       int left_prec, right_prec, zero_fill, length = 0, pad, pad_on_right;
440 +       char buf[32];
441 +       long val;
442 +       while ((c = *fmt0++))
443 +       {
444 +               if (c == '%')
445 +               {
446 +                       c = *fmt0++;
447 +                       left_prec = right_prec = pad_on_right = 0;
448 +                       if (c == '-')
449 +                       {
450 +                               c = *fmt0++;
451 +                               pad_on_right++;
452 +                       }
453 +                       if (c == '0')
454 +                       {
455 +                               zero_fill = TRUE;
456 +                               c = *fmt0++;
457 +                       } else
458 +                       {
459 +                               zero_fill = FALSE;
460 +                       }
461 +                       while (is_digit(c))
462 +                       {
463 +                               left_prec = (left_prec * 10) + (c - '0');
464 +                               c = *fmt0++;
465 +                       }
466 +                       if (c == '.')
467 +                       {
468 +                               c = *fmt0++;
469 +                               zero_fill++;
470 +                               while (is_digit(c))
471 +                               {
472 +                                       right_prec = (right_prec * 10) + (c - '0');
473 +                                       c = *fmt0++;
474 +                               }
475 +                       } else
476 +                       {
477 +                               right_prec = left_prec;
478 +                       }
479 +                       sign = '\0';
480 +                       switch (c)
481 +                       {
482 +                       case 'd':
483 +                       case 'x':
484 +                       case 'X':
485 +                               val = va_arg(ap, long);
486 +                               switch (c)
487 +                               {
488 +                               case 'd':
489 +                                       if (val < 0)
490 +                                       {
491 +                                               sign = '-';
492 +                                               val = -val;
493 +                                       }
494 +                                       length = _cvt(val, buf, 10, "0123456789");
495 +                                       break;
496 +                               case 'x':
497 +                                       length = _cvt(val, buf, 16, "0123456789abcdef");
498 +                                       break;
499 +                               case 'X':
500 +                                       length = _cvt(val, buf, 16, "0123456789ABCDEF");
501 +                                       break;
502 +                               }
503 +                               cp = buf;
504 +                               break;
505 +                       case 's':
506 +                               cp = va_arg(ap, char *);
507 +                               length = strlen(cp);
508 +                               break;
509 +                       case 'c':
510 +                               c = va_arg(ap, long /*char*/);
511 +                               (*putc)(c);
512 +                               continue;
513 +                       default:
514 +                               (*putc)('?');
515 +                       }
516 +                       pad = left_prec - length;
517 +                       if (sign != '\0')
518 +                       {
519 +                               pad--;
520 +                       }
521 +                       if (zero_fill)
522 +                       {
523 +                               c = '0';
524 +                               if (sign != '\0')
525 +                               {
526 +                                       (*putc)(sign);
527 +                                       sign = '\0';
528 +                               }
529 +                       } else
530 +                       {
531 +                               c = ' ';
532 +                       }
533 +                       if (!pad_on_right)
534 +                       {
535 +                               while (pad-- > 0)
536 +                               {
537 +                                       (*putc)(c);
538 +                               }
539 +                       }
540 +                       if (sign != '\0')
541 +                       {
542 +                               (*putc)(sign);
543 +                       }
544 +                       while (length-- > 0)
545 +                       {
546 +                               (*putc)(c = *cp++);
547 +                               if (c == '\n')
548 +                               {
549 +                                       (*putc)('\r');
550 +                               }
551 +                       }
552 +                       if (pad_on_right)
553 +                       {
554 +                               while (pad-- > 0)
555 +                               {
556 +                                       (*putc)(c);
557 +                               }
558 +                       }
559 +               } else
560 +               {
561 +                       (*putc)(c);
562 +                       if (c == '\n')
563 +                       {
564 +                               (*putc)('\r');
565 +                       }
566 +               }
567 +       }
568 +}
569 +
570 +int
571 +_cvt(unsigned long val, char *buf, long radix, char *digits)
572 +{
573 +       char temp[80];
574 +       char *cp = temp;
575 +       int length = 0;
576 +       if (val == 0)
577 +       { /* Special case */
578 +               *cp++ = '0';
579 +       } else
580 +               while (val)
581 +               {
582 +                       *cp++ = digits[val % radix];
583 +                       val /= radix;
584 +               }
585 +       while (cp != temp)
586 +       {
587 +               *buf++ = *--cp;
588 +               length++;
589 +       }
590 +       *buf = '\0';
591 +       return (length);
592 +}
593 +
594 +void
595 +_dump_buf_with_offset(unsigned char *p, int s, unsigned char *base)
596 +{
597 +       int i, c;
598 +       if ((unsigned int)s > (unsigned int)p)
599 +       {
600 +               s = (unsigned int)s - (unsigned int)p;
601 +       }
602 +       while (s > 0)
603 +       {
604 +               if (base)
605 +               {
606 +                       _printk("%06X: ", (int)p - (int)base);
607 +               } else
608 +               {
609 +                       _printk("%06X: ", p);
610 +               }
611 +               for (i = 0;  i < 16;  i++)
612 +               {
613 +                       if (i < s)
614 +                       {
615 +                               _printk("%02X", p[i] & 0xFF);
616 +                       } else
617 +                       {
618 +                               _printk("  ");
619 +                       }
620 +                       if ((i % 2) == 1) _printk(" ");
621 +                       if ((i % 8) == 7) _printk(" ");
622 +               }
623 +               _printk(" |");
624 +               for (i = 0;  i < 16;  i++)
625 +               {
626 +                       if (i < s)
627 +                       {
628 +                               c = p[i] & 0xFF;
629 +                               if ((c < 0x20) || (c >= 0x7F)) c = '.';
630 +                       } else
631 +                       {
632 +                               c = ' ';
633 +                       }
634 +                       _printk("%c", c);
635 +               }
636 +               _printk("|\n");
637 +               s -= 16;
638 +               p += 16;
639 +       }
640 +}
641 +
642 +void
643 +_dump_buf(unsigned char *p, int s)
644 +{
645 +       _printk("\n");
646 +       _dump_buf_with_offset(p, s, 0);
647 +}
648 +
649 +/*
650 + * Local variables:
651 + *  c-indent-level: 8
652 + *  c-basic-offset: 8
653 + *  tab-width: 8
654 + * End:
655 + */
656 diff -Naru linux/arch/mips/zboot/common/misc-simple.c linux.spi/arch/mips/zboot/common/misc-simple.c
657 --- linux/arch/mips/zboot/common/misc-simple.c  1969-12-31 19:00:00.000000000 -0500
658 +++ linux.spi/arch/mips/zboot/common/misc-simple.c      2004-05-11 23:19:24.000000000 -0400
659 @@ -0,0 +1,127 @@
660 +/*
661 + * arch/mips/zboot/common/misc-simple.c
662 + *
663 + * Misc. bootloader code for many machines.  This assumes you have are using
664 + * a 6xx/7xx/74xx CPU in your machine.  This assumes the chunk of memory
665 + * below 8MB is free.  Finally, it assumes you have a NS16550-style uart for 
666 + * your serial console.  If a machine meets these requirements, it can quite
667 + * likely use this code during boot.
668 + * 
669 + * Author: Matt Porter <mporter@mvista.com>
670 + * Derived from arch/ppc/boot/prep/misc.c
671 + *
672 + * Copyright 2001 MontaVista Software Inc.
673 + *
674 + * This program is free software; you can redistribute  it and/or modify it
675 + * under  the terms of  the GNU General  Public License as published by the
676 + * Free Software Foundation;  either version 2 of the  License, or (at your
677 + * option) any later version.
678 + */
679 +
680 +#include <linux/types.h>
681 +#include <linux/elf.h>
682 +#include <linux/config.h>
683 +
684 +#include <asm/page.h>
685 +#include <asm/processor.h>
686 +#include <asm/mmu.h>
687 +
688 +#include "zlib.h"
689 +
690 +extern struct NS16550 *com_port;
691 +
692 +char *avail_ram;
693 +char *end_avail;
694 +extern char _end[];
695 +char *zimage_start;
696 +
697 +#ifdef CONFIG_CMDLINE
698 +#define CMDLINE CONFIG_CMDLINE
699 +#else
700 +#define CMDLINE ""
701 +#endif
702 +char cmd_preset[] = CMDLINE;
703 +char cmd_buf[256];
704 +char *cmd_line = cmd_buf;
705 +
706 +/* The linker tells us where the image is.
707 +*/
708 +extern unsigned char __image_begin, __image_end;
709 +extern unsigned char __ramdisk_begin, __ramdisk_end;
710 +unsigned long initrd_size;
711 +
712 +extern void puts(const char *);
713 +extern void putc(const char c);
714 +extern void puthex(unsigned long val);
715 +extern void *memcpy(void * __dest, __const void * __src,
716 +                           __kernel_size_t __n);
717 +extern void gunzip(void *, int, unsigned char *, int *);
718 +extern void udelay(long delay);
719 +extern int tstc(void);
720 +extern int getc(void);
721 +extern volatile struct NS16550 *serial_init(int chan);
722 +
723 +void
724 +decompress_kernel(unsigned long load_addr, int num_words, 
725 +               unsigned long cksum, unsigned long *sp)
726 +{
727 +       int timer = 0;
728 +       extern unsigned long start;
729 +       char *cp, ch;
730 +       int i;
731 +       int     zimage_size;
732 +
733 +       com_port = (struct NS16550 *)serial_init(0);
734 +
735 +       initrd_size = (unsigned long)(&__ramdisk_end) -
736 +               (unsigned long)(&__ramdisk_begin);
737 +
738 +       /*
739 +        * Reveal where we were loaded at and where we
740 +        * were relocated to.
741 +        */
742 +       puts("loaded at:     "); puthex(load_addr);
743 +       puts(" "); puthex((unsigned long)(load_addr + (4*num_words))); puts("\n");
744 +       if ( (unsigned long)load_addr != (unsigned long)&start )
745 +       {
746 +               puts("relocated to:  "); puthex((unsigned long)&start);
747 +               puts(" ");
748 +               puthex((unsigned long)((unsigned long)&start + (4*num_words)));
749 +               puts("\n");
750 +       }
751 +
752 +       /*
753 +        * We link ourself to an arbitrary low address.  When we run, we
754 +        * relocate outself to that address.  __image_being points to
755 +        * the part of the image where the zImage is. -- Tom
756 +        */
757 +       zimage_start = (char *)(unsigned long)(&__image_begin);
758 +       zimage_size = (unsigned long)(&__image_end) -
759 +                       (unsigned long)(&__image_begin);
760 +
761 +       /*
762 +        * The zImage and initrd will be between start and _end, so they've
763 +        * already been moved once.  We're good to go now. -- Tom
764 +        */
765 +       puts("zimage at:     "); puthex((unsigned long)zimage_start);
766 +       puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
767 +       puts("\n");
768 +
769 +       if ( initrd_size ) {
770 +               puts("initrd at:     ");
771 +               puthex((unsigned long)(&__ramdisk_begin));
772 +               puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
773 +       }
774 +
775 +       /* assume the chunk below 8M is free */
776 +       avail_ram = (char *)AVAIL_RAM_START;
777 +       end_avail = (char *)AVAIL_RAM_END;
778 +
779 +       /* Display standard Linux/MIPS boot prompt for kernel args */
780 +       puts("Uncompressing Linux at load address ");
781 +       puthex(LOADADDR);
782 +       puts("\n");
783 +       /* I don't like this hard coded gunzip size (fixme) */
784 +       gunzip((void *)LOADADDR, 0x400000, zimage_start, &zimage_size);
785 +       puts("Now booting the kernel\n");
786 +}
787 diff -Naru linux/arch/mips/zboot/common/no_initrd.c linux.spi/arch/mips/zboot/common/no_initrd.c
788 --- linux/arch/mips/zboot/common/no_initrd.c    1969-12-31 19:00:00.000000000 -0500
789 +++ linux.spi/arch/mips/zboot/common/no_initrd.c        2004-05-11 23:19:24.000000000 -0400
790 @@ -0,0 +1,2 @@
791 +char initrd_data[1];
792 +int initrd_len = 0;
793 diff -Naru linux/arch/mips/zboot/common/ns16550.c linux.spi/arch/mips/zboot/common/ns16550.c
794 --- linux/arch/mips/zboot/common/ns16550.c      1969-12-31 19:00:00.000000000 -0500
795 +++ linux.spi/arch/mips/zboot/common/ns16550.c  2004-05-11 23:19:24.000000000 -0400
796 @@ -0,0 +1,57 @@
797 +/*
798 + * NS16550 support
799 + */
800 +
801 +#include <linux/config.h>
802 +#include <asm/serial.h>
803 +#include "ns16550.h"
804 +
805 +typedef struct NS16550 *NS16550_t;
806 +
807 +const NS16550_t COM_PORTS[] = { (NS16550_t) COM1,
808 +    (NS16550_t) COM2,
809 +    (NS16550_t) COM3,
810 +    (NS16550_t) COM4 };
811 +
812 +volatile struct NS16550 *
813 +serial_init(int chan)
814 +{
815 +       volatile struct NS16550 *com_port;
816 +       com_port = (struct NS16550 *) COM_PORTS[chan];
817 +       /* See if port is present */
818 +       com_port->lcr = 0x00;
819 +       com_port->ier = 0xFF;
820 +#if 0
821 +       if (com_port->ier != 0x0F) return ((struct NS16550 *)0);
822 +#endif
823 +       com_port->ier = 0x00;
824 +       com_port->lcr = 0x80;  /* Access baud rate */
825 +#ifdef CONFIG_SERIAL_CONSOLE_NONSTD
826 +       com_port->dll = (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD);
827 +       com_port->dlm = (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD) >> 8;
828 +#endif
829 +       com_port->lcr = 0x03;  /* 8 data, 1 stop, no parity */
830 +       com_port->mcr = 0x03;  /* RTS/DTR */
831 +       com_port->fcr = 0x07;  /* Clear & enable FIFOs */
832 +       return (com_port);
833 +}
834 +
835 +void
836 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
837 +{
838 +       while ((com_port->lsr & LSR_THRE) == 0) ;
839 +       com_port->thr = c;
840 +}
841 +
842 +unsigned char
843 +serial_getc(volatile struct NS16550 *com_port)
844 +{
845 +       while ((com_port->lsr & LSR_DR) == 0) ;
846 +       return (com_port->rbr);
847 +}
848 +
849 +int
850 +serial_tstc(volatile struct NS16550 *com_port)
851 +{
852 +       return ((com_port->lsr & LSR_DR) != 0);
853 +}
854 diff -Naru linux/arch/mips/zboot/common/string.c linux.spi/arch/mips/zboot/common/string.c
855 --- linux/arch/mips/zboot/common/string.c       1969-12-31 19:00:00.000000000 -0500
856 +++ linux.spi/arch/mips/zboot/common/string.c   2004-05-11 23:19:24.000000000 -0400
857 @@ -0,0 +1,497 @@
858 +/*
859 + *  linux/lib/string.c
860 + *
861 + *  Copyright (C) 1991, 1992  Linus Torvalds
862 + */
863 +
864 +/*
865 + * stupid library routines.. The optimized versions should generally be found
866 + * as inline code in <asm-xx/string.h>
867 + *
868 + * These are buggy as well..
869 + *
870 + * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
871 + * -  Added strsep() which will replace strtok() soon (because strsep() is
872 + *    reentrant and should be faster). Use only strsep() in new code, please.
873 + */
874
875 +#include <linux/types.h>
876 +#include <linux/string.h>
877 +#include <linux/ctype.h>
878 +
879 +/**
880 + * strnicmp - Case insensitive, length-limited string comparison
881 + * @s1: One string
882 + * @s2: The other string
883 + * @len: the maximum number of characters to compare
884 + */
885 +int strnicmp(const char *s1, const char *s2, size_t len)
886 +{
887 +       /* Yes, Virginia, it had better be unsigned */
888 +       unsigned char c1, c2;
889 +
890 +       c1 = 0; c2 = 0;
891 +       if (len) {
892 +               do {
893 +                       c1 = *s1; c2 = *s2;
894 +                       s1++; s2++;
895 +                       if (!c1)
896 +                               break;
897 +                       if (!c2)
898 +                               break;
899 +                       if (c1 == c2)
900 +                               continue;
901 +                       c1 = tolower(c1);
902 +                       c2 = tolower(c2);
903 +                       if (c1 != c2)
904 +                               break;
905 +               } while (--len);
906 +       }
907 +       return (int)c1 - (int)c2;
908 +}
909 +
910 +char * ___strtok;
911 +
912 +#ifndef __HAVE_ARCH_STRCPY
913 +/**
914 + * strcpy - Copy a %NUL terminated string
915 + * @dest: Where to copy the string to
916 + * @src: Where to copy the string from
917 + */
918 +char * strcpy(char * dest,const char *src)
919 +{
920 +       char *tmp = dest;
921 +
922 +       while ((*dest++ = *src++) != '\0')
923 +               /* nothing */;
924 +       return tmp;
925 +}
926 +#endif
927 +
928 +#ifndef __HAVE_ARCH_STRNCPY
929 +/**
930 + * strncpy - Copy a length-limited, %NUL-terminated string
931 + * @dest: Where to copy the string to
932 + * @src: Where to copy the string from
933 + * @count: The maximum number of bytes to copy
934 + *
935 + * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
936 + * However, the result is not %NUL-terminated if the source exceeds
937 + * @count bytes.
938 + */
939 +char * strncpy(char * dest,const char *src,size_t count)
940 +{
941 +       char *tmp = dest;
942 +
943 +       while (count-- && (*dest++ = *src++) != '\0')
944 +               /* nothing */;
945 +
946 +       return tmp;
947 +}
948 +#endif
949 +
950 +/**
951 + * strcat - Append one %NUL-terminated string to another
952 + * @dest: The string to be appended to
953 + * @src: The string to append to it
954 + */
955 +char * strcat(char * dest, const char * src)
956 +{
957 +       char *tmp = dest;
958 +
959 +       while (*dest)
960 +               dest++;
961 +       while ((*dest++ = *src++) != '\0')
962 +               ;
963 +
964 +       return tmp;
965 +}
966 +
967 +/**
968 + * strncat - Append a length-limited, %NUL-terminated string to another
969 + * @dest: The string to be appended to
970 + * @src: The string to append to it
971 + * @count: The maximum numbers of bytes to copy
972 + *
973 + * Note that in contrast to strncpy, strncat ensures the result is
974 + * terminated.
975 + */
976 +char * strncat(char *dest, const char *src, size_t count)
977 +{
978 +       char *tmp = dest;
979 +
980 +       if (count) {
981 +               while (*dest)
982 +                       dest++;
983 +               while ((*dest++ = *src++)) {
984 +                       if (--count == 0) {
985 +                               *dest = '\0';
986 +                               break;
987 +                       }
988 +               }
989 +       }
990 +
991 +       return tmp;
992 +}
993 +
994 +#ifndef __HAVE_ARCH_STRCMP
995 +/**
996 + * strcmp - Compare two strings
997 + * @cs: One string
998 + * @ct: Another string
999 + */
1000 +int strcmp(const char * cs,const char * ct)
1001 +{
1002 +       register signed char __res;
1003 +
1004 +       while (1) {
1005 +               if ((__res = *cs - *ct++) != 0 || !*cs++)
1006 +                       break;
1007 +       }
1008 +
1009 +       return __res;
1010 +}
1011 +#endif
1012 +
1013 +#ifndef __HAVE_ARCH_STRNCMP
1014 +/**
1015 + * strncmp - Compare two length-limited strings
1016 + * @cs: One string
1017 + * @ct: Another string
1018 + * @count: The maximum number of bytes to compare
1019 + */
1020 +int strncmp(const char * cs,const char * ct,size_t count)
1021 +{
1022 +       register signed char __res = 0;
1023 +
1024 +       while (count) {
1025 +               if ((__res = *cs - *ct++) != 0 || !*cs++)
1026 +                       break;
1027 +               count--;
1028 +       }
1029 +
1030 +       return __res;
1031 +}
1032 +#endif
1033 +
1034 +/**
1035 + * strchr - Find the first occurrence of a character in a string
1036 + * @s: The string to be searched
1037 + * @c: The character to search for
1038 + */
1039 +char * strchr(const char * s, int c)
1040 +{
1041 +       for(; *s != (char) c; ++s)
1042 +               if (*s == '\0')
1043 +                       return NULL;
1044 +       return (char *) s;
1045 +}
1046 +
1047 +/**
1048 + * strrchr - Find the last occurrence of a character in a string
1049 + * @s: The string to be searched
1050 + * @c: The character to search for
1051 + */
1052 +char * strrchr(const char * s, int c)
1053 +{
1054 +       const char *p = s + strlen(s);
1055 +       do {
1056 +           if (*p == (char)c)
1057 +               return (char *)p;
1058 +       } while (--p >= s);
1059 +       return NULL;
1060 +}
1061 +
1062 +/**
1063 + * strlen - Find the length of a string
1064 + * @s: The string to be sized
1065 + */
1066 +size_t strlen(const char * s)
1067 +{
1068 +       const char *sc;
1069 +
1070 +       for (sc = s; *sc != '\0'; ++sc)
1071 +               /* nothing */;
1072 +       return sc - s;
1073 +}
1074 +
1075 +/**
1076 + * strnlen - Find the length of a length-limited string
1077 + * @s: The string to be sized
1078 + * @count: The maximum number of bytes to search
1079 + */
1080 +size_t strnlen(const char * s, size_t count)
1081 +{
1082 +       const char *sc;
1083 +
1084 +       for (sc = s; count-- && *sc != '\0'; ++sc)
1085 +               /* nothing */;
1086 +       return sc - s;
1087 +}
1088 +
1089 +/**
1090 + * strspn - Calculate the length of the initial substring of @s which only
1091 + *     contain letters in @accept
1092 + * @s: The string to be searched
1093 + * @accept: The string to search for
1094 + */
1095 +size_t strspn(const char *s, const char *accept)
1096 +{
1097 +       const char *p;
1098 +       const char *a;
1099 +       size_t count = 0;
1100 +
1101 +       for (p = s; *p != '\0'; ++p) {
1102 +               for (a = accept; *a != '\0'; ++a) {
1103 +                       if (*p == *a)
1104 +                               break;
1105 +               }
1106 +               if (*a == '\0')
1107 +                       return count;
1108 +               ++count;
1109 +       }
1110 +
1111 +       return count;
1112 +}
1113 +
1114 +/**
1115 + * strpbrk - Find the first occurrence of a set of characters
1116 + * @cs: The string to be searched
1117 + * @ct: The characters to search for
1118 + */
1119 +char * strpbrk(const char * cs,const char * ct)
1120 +{
1121 +       const char *sc1,*sc2;
1122 +
1123 +       for( sc1 = cs; *sc1 != '\0'; ++sc1) {
1124 +               for( sc2 = ct; *sc2 != '\0'; ++sc2) {
1125 +                       if (*sc1 == *sc2)
1126 +                               return (char *) sc1;
1127 +               }
1128 +       }
1129 +       return NULL;
1130 +}
1131 +
1132 +/**
1133 + * strtok - Split a string into tokens
1134 + * @s: The string to be searched
1135 + * @ct: The characters to search for
1136 + *
1137 + * WARNING: strtok is deprecated, use strsep instead.
1138 + */
1139 +char * strtok(char * s,const char * ct)
1140 +{
1141 +       char *sbegin, *send;
1142 +
1143 +       sbegin  = s ? s : ___strtok;
1144 +       if (!sbegin) {
1145 +               return NULL;
1146 +       }
1147 +       sbegin += strspn(sbegin,ct);
1148 +       if (*sbegin == '\0') {
1149 +               ___strtok = NULL;
1150 +               return( NULL );
1151 +       }
1152 +       send = strpbrk( sbegin, ct);
1153 +       if (send && *send != '\0')
1154 +               *send++ = '\0';
1155 +       ___strtok = send;
1156 +       return (sbegin);
1157 +}
1158 +
1159 +/**
1160 + * strsep - Split a string into tokens
1161 + * @s: The string to be searched
1162 + * @ct: The characters to search for
1163 + *
1164 + * strsep() updates @s to point after the token, ready for the next call.
1165 + *
1166 + * It returns empty tokens, too, behaving exactly like the libc function
1167 + * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
1168 + * Same semantics, slimmer shape. ;)
1169 + */
1170 +char * strsep(char **s, const char *ct)
1171 +{
1172 +       char *sbegin = *s, *end;
1173 +
1174 +       if (sbegin == NULL)
1175 +               return NULL;
1176 +
1177 +       end = strpbrk(sbegin, ct);
1178 +       if (end)
1179 +               *end++ = '\0';
1180 +       *s = end;
1181 +
1182 +       return sbegin;
1183 +}
1184 +
1185 +/**
1186 + * memset - Fill a region of memory with the given value
1187 + * @s: Pointer to the start of the area.
1188 + * @c: The byte to fill the area with
1189 + * @count: The size of the area.
1190 + *
1191 + * Do not use memset() to access IO space, use memset_io() instead.
1192 + */
1193 +void * memset(void * s,int c, size_t count)
1194 +{
1195 +       char *xs = (char *) s;
1196 +
1197 +       while (count--)
1198 +               *xs++ = c;
1199 +
1200 +       return s;
1201 +}
1202 +
1203 +/**
1204 + * bcopy - Copy one area of memory to another
1205 + * @src: Where to copy from
1206 + * @dest: Where to copy to
1207 + * @count: The size of the area.
1208 + *
1209 + * Note that this is the same as memcpy(), with the arguments reversed.
1210 + * memcpy() is the standard, bcopy() is a legacy BSD function.
1211 + *
1212 + * You should not use this function to access IO space, use memcpy_toio()
1213 + * or memcpy_fromio() instead.
1214 + */
1215 +char * bcopy(const char * src, char * dest, int count)
1216 +{
1217 +       char *tmp = dest;
1218 +
1219 +       while (count--)
1220 +               *tmp++ = *src++;
1221 +
1222 +       return dest;
1223 +}
1224 +
1225 +/**
1226 + * memcpy - Copy one area of memory to another
1227 + * @dest: Where to copy to
1228 + * @src: Where to copy from
1229 + * @count: The size of the area.
1230 + *
1231 + * You should not use this function to access IO space, use memcpy_toio()
1232 + * or memcpy_fromio() instead.
1233 + */
1234 +void * memcpy(void * dest,const void *src,size_t count)
1235 +{
1236 +       char *tmp = (char *) dest, *s = (char *) src;
1237 +
1238 +       while (count--)
1239 +               *tmp++ = *s++;
1240 +
1241 +       return dest;
1242 +}
1243 +
1244 +/**
1245 + * memmove - Copy one area of memory to another
1246 + * @dest: Where to copy to
1247 + * @src: Where to copy from
1248 + * @count: The size of the area.
1249 + *
1250 + * Unlike memcpy(), memmove() copes with overlapping areas.
1251 + */
1252 +void * memmove(void * dest,const void *src,size_t count)
1253 +{
1254 +       char *tmp, *s;
1255 +
1256 +       if (dest <= src) {
1257 +               tmp = (char *) dest;
1258 +               s = (char *) src;
1259 +               while (count--)
1260 +                       *tmp++ = *s++;
1261 +               }
1262 +       else {
1263 +               tmp = (char *) dest + count;
1264 +               s = (char *) src + count;
1265 +               while (count--)
1266 +                       *--tmp = *--s;
1267 +               }
1268 +
1269 +       return dest;
1270 +}
1271 +
1272 +/**
1273 + * memcmp - Compare two areas of memory
1274 + * @cs: One area of memory
1275 + * @ct: Another area of memory
1276 + * @count: The size of the area.
1277 + */
1278 +int memcmp(const void * cs,const void * ct,size_t count)
1279 +{
1280 +       const unsigned char *su1, *su2;
1281 +       signed char res = 0;
1282 +
1283 +       for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
1284 +               if ((res = *su1 - *su2) != 0)
1285 +                       break;
1286 +       return res;
1287 +}
1288 +
1289 +#ifndef __HAVE_ARCH_MEMSCAN
1290 +/**
1291 + * memscan - Find a character in an area of memory.
1292 + * @addr: The memory area
1293 + * @c: The byte to search for
1294 + * @size: The size of the area.
1295 + *
1296 + * returns the address of the first occurrence of @c, or 1 byte past
1297 + * the area if @c is not found
1298 + */
1299 +void * memscan(void * addr, int c, size_t size)
1300 +{
1301 +       unsigned char * p = (unsigned char *) addr;
1302 +       unsigned char * e = p + size;
1303 +
1304 +       while (p != e) {
1305 +               if (*p == c)
1306 +                       return (void *) p;
1307 +               p++;
1308 +       }
1309 +
1310 +       return (void *) p;
1311 +}
1312 +#endif
1313 +
1314 +/**
1315 + * strstr - Find the first substring in a %NUL terminated string
1316 + * @s1: The string to be searched
1317 + * @s2: The string to search for
1318 + */
1319 +char * strstr(const char * s1,const char * s2)
1320 +{
1321 +       int l1, l2;
1322 +
1323 +       l2 = strlen(s2);
1324 +       if (!l2)
1325 +               return (char *) s1;
1326 +       l1 = strlen(s1);
1327 +       while (l1 >= l2) {
1328 +               l1--;
1329 +               if (!memcmp(s1,s2,l2))
1330 +                       return (char *) s1;
1331 +               s1++;
1332 +       }
1333 +       return NULL;
1334 +}
1335 +
1336 +/**
1337 + * memchr - Find a character in an area of memory.
1338 + * @s: The memory area
1339 + * @c: The byte to search for
1340 + * @n: The size of the area.
1341 + *
1342 + * returns the address of the first occurrence of @c, or %NULL
1343 + * if @c is not found
1344 + */
1345 +void *memchr(const void *s, int c, size_t n)
1346 +{
1347 +       const unsigned char *p = s;
1348 +       while (n-- != 0) {
1349 +               if ((unsigned char)c == *p++) {
1350 +                       return (void *)(p-1);
1351 +               }
1352 +       }
1353 +       return NULL;
1354 +}
1355 diff -Naru linux/arch/mips/zboot/csb250/head.S linux.spi/arch/mips/zboot/csb250/head.S
1356 --- linux/arch/mips/zboot/csb250/head.S 1969-12-31 19:00:00.000000000 -0500
1357 +++ linux.spi/arch/mips/zboot/csb250/head.S     2004-05-11 23:19:24.000000000 -0400
1358 @@ -0,0 +1,157 @@
1359 +/*
1360 + * arch/mips/kernel/head.S
1361 + *
1362 + * This file is subject to the terms and conditions of the GNU General Public
1363 + * License.  See the file "COPYING" in the main directory of this archive
1364 + * for more details.
1365 + *
1366 + * Copyright (C) 1994, 1995 Waldorf Electronics
1367 + * Written by Ralf Baechle and Andreas Busse
1368 + * Copyright (C) 1995 - 1999 Ralf Baechle
1369 + * Copyright (C) 1996 Paul M. Antoine
1370 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
1371 + * Further modifications by David S. Miller and Harald Koerfgen
1372 + * Copyright (C) 1999 Silicon Graphics, Inc.
1373 + *
1374 + * Head.S contains the MIPS exception handler and startup code.
1375 + *
1376 + **************************************************************************
1377 + *  9 Nov, 2000.
1378 + *  Added Cache Error exception handler and SBDDP EJTAG debug exception.
1379 + *
1380 + *  Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
1381 + *  Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
1382 + **************************************************************************
1383 + */
1384 +#include <linux/config.h>
1385 +#include <linux/threads.h>
1386 +
1387 +#include <asm/asm.h>
1388 +#include <asm/cacheops.h>
1389 +#include <asm/mipsregs.h>
1390 +#include <asm/offset.h>
1391 +#include <asm/cachectl.h>
1392 +#include <asm/regdef.h>
1393 +
1394 +#define IndexInvalidate_I       0x00
1395 +#define IndexWriteBack_D        0x01
1396 +
1397 +       .set noreorder
1398 +       .cprestore
1399 +       LEAF(start)
1400 +start:
1401 +       bal     locate
1402 +       nop
1403 +
1404 +       .globl  asize           /* Someday we'll put the initrd info here. */
1405 +asize: .word   0
1406 +       .word   0
1407 +       .word   0
1408 +       .word   0
1409 +
1410 +locate:
1411 +       subu    s8, ra, 8       /* Where we were loaded */
1412 +       la      sp, (.stack + 8192)
1413 +
1414 +       move    s0, a0          /* Save boot rom start args */
1415 +       move    s1, a1
1416 +       move    s2, a2
1417 +       move    s3, a3
1418 +
1419 +       la      a0, start       /* Where we were linked to run */
1420 +
1421 +       move    a1, s8
1422 +       la      a2, _edata
1423 +       subu    t1, a2, a0
1424 +       srl     t1, t1, 2
1425 +
1426 +       /* copy text section */
1427 +       li      t0, 0
1428 +1:     lw      v0, 0(a1)
1429 +       nop
1430 +       sw      v0, 0(a0)
1431 +       xor     t0, t0, v0
1432 +       addu    a0, 4
1433 +       bne     a2, a0, 1b
1434 +       addu    a1, 4
1435 +
1436 +       /* Clear BSS */
1437 +       la      a0, _edata
1438 +       la      a2, _end
1439 +2:     sw      zero, 0(a0)
1440 +       bne     a2, a0, 2b
1441 +       addu    a0, 4
1442 +
1443 +       /* push the D-Cache and invalidate I-Cache */
1444 +       li      k0, 0x80000000  # start address
1445 +       li      k1, 0x80004000  # end address (16KB I-Cache)
1446 +       subu    k1, 128
1447 +
1448 +1:
1449 +       .set mips3
1450 +       cache   IndexWriteBack_D, 0(k0)
1451 +       cache   IndexWriteBack_D, 32(k0)
1452 +       cache   IndexWriteBack_D, 64(k0)
1453 +       cache   IndexWriteBack_D, 96(k0)
1454 +       cache   IndexInvalidate_I, 0(k0)
1455 +       cache   IndexInvalidate_I, 32(k0)
1456 +       cache   IndexInvalidate_I, 64(k0)
1457 +       cache   IndexInvalidate_I, 96(k0)
1458 +       .set mips0
1459 +
1460 +       bne     k0, k1, 1b
1461 +       addu    k0, k0, 128
1462 +       /* done */
1463 +
1464 +/*     move    a0, s8               /* load address */
1465 +       subu    a0, s8, 0x1000               /* load address */
1466 +       move    a1, t1               /* length in words */
1467 +       move    a2, t0               /* checksum */
1468 +       move    a3, sp
1469 +
1470 +       la      ra, 1f
1471 +       la      k0, decompress_kernel
1472 +       jr      k0
1473 +       nop
1474 +1:
1475 +
1476 +       la      a2, __ramdisk_begin
1477 +       la      a3, initrd_size
1478 +       lw      a0, 0(a2)
1479 +       lw      a1, 0(a3)
1480 +       li      k0, KERNEL_ENTRY
1481 +       jr      k0
1482 +       nop
1483 +3:
1484 +       b 3b
1485 +       END(start)
1486 +
1487 +       LEAF(udelay)
1488 +udelay:
1489 +       END(udelay)
1490 +
1491 +
1492 +       LEAF(FlushCache)
1493 +       li      k0, 0x80000000  # start address
1494 +       li      k1, 0x80004000  # end address (16KB I-Cache)
1495 +       subu    k1, 128
1496 +
1497 +1:
1498 +       .set mips3
1499 +       cache   IndexWriteBack_D, 0(k0)
1500 +       cache   IndexWriteBack_D, 32(k0)
1501 +       cache   IndexWriteBack_D, 64(k0)
1502 +       cache   IndexWriteBack_D, 96(k0)
1503 +       cache   IndexInvalidate_I, 0(k0)
1504 +       cache   IndexInvalidate_I, 32(k0)
1505 +       cache   IndexInvalidate_I, 64(k0)
1506 +       cache   IndexInvalidate_I, 96(k0)
1507 +       .set mips0
1508 +
1509 +       bne     k0, k1, 1b
1510 +       addu    k0, k0, 128
1511 +       jr      ra
1512 +       nop
1513 +       END(FlushCache)
1514 +
1515 +       .comm .stack,4096*2,4
1516 diff -Naru linux/arch/mips/zboot/csb250/Makefile linux.spi/arch/mips/zboot/csb250/Makefile
1517 --- linux/arch/mips/zboot/csb250/Makefile       1969-12-31 19:00:00.000000000 -0500
1518 +++ linux.spi/arch/mips/zboot/csb250/Makefile   2004-05-11 23:19:24.000000000 -0400
1519 @@ -0,0 +1,90 @@
1520 +# arch/mips/zboot/pb1xxx/Makefile
1521 +# 
1522 +# Makefile for Cogent CSB250 Au1500 board.
1523 +# All of the boot loader code was derived from the ppc
1524 +# boot code.
1525 +#
1526 +# This program is free software; you can redistribute  it and/or modify it
1527 +# under  the terms of  the GNU General  Public License as published by the
1528 +# Free Software Foundation;  either version 2 of the  License, or (at your
1529 +# option) any later version.
1530 +
1531 +.c.s:
1532 +       $(CC) $(CFLAGS) -S -o $*.s $<
1533 +.s.o:
1534 +       $(AS) -o $*.o $<
1535 +.c.o:
1536 +       $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
1537 +.S.s:
1538 +       $(CPP) $(AFLAGS) -o $*.o $<
1539 +.S.o:
1540 +       $(CC) $(AFLAGS) -c -o $*.o $<
1541 +
1542 +#########################################################################
1543 +# START BOARD SPECIFIC VARIABLES
1544 +BNAME=csb250
1545 +
1546 +# These two variables control where the zImage is stored
1547 +# in flash and loaded in memory.  It only controls how the srec
1548 +# file is generated, the code is the same.
1549 +RAM_RUN_ADDR = 0x80a00000
1550 +FLASH_LOAD_ADDR = 0xBFD00000
1551 +
1552 +# These two variables specify the free ram region
1553 +# that can be used for temporary malloc area
1554 +AVAIL_RAM_START=0x80400000
1555 +AVAIL_RAM_END=0x80800000
1556 +
1557 +# This one must match the LOADADDR in arch/mips/Makefile!
1558 +LOADADDR=0x80100000
1559 +# END BOARD SPECIFIC VARIABLES
1560 +#########################################################################
1561 +
1562 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
1563 +       ../common/au1k_uart.o ../common/string.o ../common/ctype.o
1564 +LIBS := ../lib/zlib.a
1565 +
1566 +ENTRY := ../utils/entry
1567 +OFFSET := ../utils/offset
1568 +SIZE := ../utils/size
1569 +
1570 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
1571 +OBJCOPY_ARGS = -O elf32-tradbigmips
1572 +
1573 +all: zImage
1574 +
1575 +clean:
1576 +       rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
1577 +
1578 +head.o: head.S $(TOPDIR)/vmlinux
1579 +       $(CC) $(AFLAGS) \
1580 +       -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
1581 +       -c -o $*.o $<
1582 +
1583 +../common/misc-simple.o:
1584 +       $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
1585 +               -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
1586 +               -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
1587 +               -DLOADADDR=$(LOADADDR) \
1588 +               -DZIMAGE_SIZE=0 -c -o $@ $*.c
1589 +
1590 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
1591 +       $(OBJCOPY) \
1592 +               --add-section=.image=../images/vmlinux.gz \
1593 +               --set-section-flags=.image=contents,alloc,load,readonly,data \
1594 +               ../common/dummy.o image.o
1595 +       $(LD) $(LD_ARGS) -o $@ $(OBJECTS) image.o $(LIBS)
1596 +       $(OBJCOPY) $(OBJCOPY_ARGS) $@ $@ -R .comment -R .stab -R .stabstr \
1597 +               -R .initrd -R .sysmap
1598 +
1599 +# Here we manipulate the image in order to get it the necessary
1600 +# srecord file we need.
1601 +zImage: zvmlinux
1602 +       mv zvmlinux ../images/zImage.$(BNAME)
1603 +       $(OBJCOPY) -O binary ../images/zImage.$(BNAME) ../images/$(BNAME).bin
1604 +
1605 +zImage.flash: zImage
1606 +       $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
1607 +               ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
1608 +
1609 +include $(TOPDIR)/Rules.make
1610 diff -Naru linux/arch/mips/zboot/images/Makefile linux.spi/arch/mips/zboot/images/Makefile
1611 --- linux/arch/mips/zboot/images/Makefile       1969-12-31 19:00:00.000000000 -0500
1612 +++ linux.spi/arch/mips/zboot/images/Makefile   2004-05-11 23:19:24.000000000 -0400
1613 @@ -0,0 +1,10 @@
1614 +
1615 +include $(TOPDIR)/Rules.make
1616 +
1617 +vmlinux.gz: $(TOPDIR)/vmlinux
1618 +       $(OBJCOPY) -S -O binary $(TOPDIR)/vmlinux vmlinux
1619 +       gzip -vf vmlinux
1620 +
1621 +clean:
1622 +       rm -f vmlinux.*  zImage.*
1623 +
1624 diff -Naru linux/arch/mips/zboot/include/nonstdio.h linux.spi/arch/mips/zboot/include/nonstdio.h
1625 --- linux/arch/mips/zboot/include/nonstdio.h    1969-12-31 19:00:00.000000000 -0500
1626 +++ linux.spi/arch/mips/zboot/include/nonstdio.h        2004-05-11 23:19:24.000000000 -0400
1627 @@ -0,0 +1,18 @@
1628 +/*
1629 + * Copyright (C) Paul Mackerras 1997.
1630 + *
1631 + * This program is free software; you can redistribute it and/or
1632 + * modify it under the terms of the GNU General Public License
1633 + * as published by the Free Software Foundation; either version
1634 + * 2 of the License, or (at your option) any later version.
1635 + */
1636 +typedef int    FILE;
1637 +extern FILE *stdin, *stdout;
1638 +#define NULL   ((void *)0)
1639 +#define EOF    (-1)
1640 +#define fopen(n, m)    NULL
1641 +#define fflush(f)      0
1642 +#define fclose(f)      0
1643 +extern char *fgets();
1644 +
1645 +#define perror(s)      printf("%s: no files!\n", (s))
1646 diff -Naru linux/arch/mips/zboot/include/ns16550.h linux.spi/arch/mips/zboot/include/ns16550.h
1647 --- linux/arch/mips/zboot/include/ns16550.h     1969-12-31 19:00:00.000000000 -0500
1648 +++ linux.spi/arch/mips/zboot/include/ns16550.h 2004-05-11 23:19:24.000000000 -0400
1649 @@ -0,0 +1,49 @@
1650 +/*
1651 + * NS16550 Serial Port
1652 + */
1653 +
1654 +/*
1655 + * Figure out which file will have the definitons of COMx
1656 + */
1657 +#if !defined(CONFIG_AU1X00_UART)
1658 +#error no serial.h
1659 +#endif
1660 +
1661 +/* Some machines have their uart registers 16 bytes apart.  Most don't.
1662 + * TODO: Make this work like drivers/char/serial does - Tom */
1663 +#if !defined(UART_REG_PAD)
1664 +#define UART_REG_PAD(x)
1665 +#endif
1666 +
1667 +struct NS16550
1668 + {
1669 +  unsigned char rbr;  /* 0 */
1670 +  UART_REG_PAD(rbr)
1671 +  unsigned char ier;  /* 1 */
1672 +  UART_REG_PAD(ier)
1673 +  unsigned char fcr;  /* 2 */
1674 +  UART_REG_PAD(fcr)
1675 +  unsigned char lcr;  /* 3 */
1676 +  UART_REG_PAD(lcr)
1677 +  unsigned char mcr;  /* 4 */
1678 +  UART_REG_PAD(mcr)
1679 +  unsigned char lsr;  /* 5 */
1680 +  UART_REG_PAD(lsr)
1681 +  unsigned char msr;  /* 6 */
1682 +  UART_REG_PAD(msr)
1683 +  unsigned char scr;  /* 7 */
1684 + };
1685 +
1686 +#define thr rbr
1687 +#define iir fcr
1688 +#define dll rbr
1689 +#define dlm ier
1690 +
1691 +#define LSR_DR   0x01  /* Data ready */
1692 +#define LSR_OE   0x02  /* Overrun */
1693 +#define LSR_PE   0x04  /* Parity error */
1694 +#define LSR_FE   0x08  /* Framing error */
1695 +#define LSR_BI   0x10  /* Break */
1696 +#define LSR_THRE 0x20  /* Xmit holding register empty */
1697 +#define LSR_TEMT 0x40  /* Xmitter empty */
1698 +#define LSR_ERR  0x80  /* Error */
1699 diff -Naru linux/arch/mips/zboot/include/pb1000_serial.h linux.spi/arch/mips/zboot/include/pb1000_serial.h
1700 --- linux/arch/mips/zboot/include/pb1000_serial.h       1969-12-31 19:00:00.000000000 -0500
1701 +++ linux.spi/arch/mips/zboot/include/pb1000_serial.h   2004-05-11 23:19:24.000000000 -0400
1702 @@ -0,0 +1,20 @@
1703 +/*
1704 + * arch/ppc/boot/include/sandpoint_serial.h
1705 + * 
1706 + * Location of the COM ports on Motorola SPS Sandpoint machines
1707 + *
1708 + * Author: Mark A. Greer
1709 + *        mgreer@mvista.com
1710 + *
1711 + * Copyright 2001 MontaVista Software Inc.
1712 + *
1713 + * This program is free software; you can redistribute  it and/or modify it
1714 + * under  the terms of  the GNU General  Public License as published by the
1715 + * Free Software Foundation;  either version 2 of the  License, or (at your
1716 + * option) any later version.
1717 + */
1718 +
1719 +#define COM1 0xfe0003f8
1720 +#define COM2 0xfe0002f8
1721 +#define COM3 0x00000000                /* No COM3 */
1722 +#define COM4 0x00000000                /* No COM4 */
1723 diff -Naru linux/arch/mips/zboot/include/zlib.h linux.spi/arch/mips/zboot/include/zlib.h
1724 --- linux/arch/mips/zboot/include/zlib.h        1969-12-31 19:00:00.000000000 -0500
1725 +++ linux.spi/arch/mips/zboot/include/zlib.h    2004-05-11 23:19:24.000000000 -0400
1726 @@ -0,0 +1,432 @@
1727 +/*     $Id: zlib.h,v 1.2 2002/02/16 16:55:45 ppopov Exp $      */
1728 +
1729 +/*
1730 + * This file is derived from zlib.h and zconf.h from the zlib-0.95
1731 + * distribution by Jean-loup Gailly and Mark Adler, with some additions
1732 + * by Paul Mackerras to aid in implementing Deflate compression and
1733 + * decompression for PPP packets.
1734 + */
1735 +
1736 +/*
1737 + *  ==FILEVERSION 960122==
1738 + *
1739 + * This marker is used by the Linux installation script to determine
1740 + * whether an up-to-date version of this file is already installed.
1741 + */
1742 +
1743 +/* zlib.h -- interface of the 'zlib' general purpose compression library
1744 +  version 0.95, Aug 16th, 1995.
1745 +
1746 +  Copyright (C) 1995 Jean-loup Gailly and Mark Adler
1747 +
1748 +  This software is provided 'as-is', without any express or implied
1749 +  warranty.  In no event will the authors be held liable for any damages
1750 +  arising from the use of this software.
1751 +
1752 +  Permission is granted to anyone to use this software for any purpose,
1753 +  including commercial applications, and to alter it and redistribute it
1754 +  freely, subject to the following restrictions:
1755 +
1756 +  1. The origin of this software must not be misrepresented; you must not
1757 +     claim that you wrote the original software. If you use this software
1758 +     in a product, an acknowledgment in the product documentation would be
1759 +     appreciated but is not required.
1760 +  2. Altered source versions must be plainly marked as such, and must not be
1761 +     misrepresented as being the original software.
1762 +  3. This notice may not be removed or altered from any source distribution.
1763 +
1764 +  Jean-loup Gailly        Mark Adler
1765 +  gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
1766 + */
1767 +
1768 +#ifndef _ZLIB_H
1769 +#define _ZLIB_H
1770 +
1771 +/* #include "zconf.h" */       /* included directly here */
1772 +
1773 +/* zconf.h -- configuration of the zlib compression library
1774 + * Copyright (C) 1995 Jean-loup Gailly.
1775 + * For conditions of distribution and use, see copyright notice in zlib.h 
1776 + */
1777 +
1778 +/* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
1779 +
1780 +/*
1781 +     The library does not install any signal handler. It is recommended to
1782 +  add at least a handler for SIGSEGV when decompressing; the library checks
1783 +  the consistency of the input data whenever possible but may go nuts
1784 +  for some forms of corrupted input.
1785 + */
1786 +
1787 +/*
1788 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
1789 + * than 64k bytes at a time (needed on systems with 16-bit int).
1790 + * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
1791 + * at addresses which are not a multiple of their size.
1792 + * Under DOS, -DFAR=far or -DFAR=__far may be needed.
1793 + */
1794 +
1795 +#ifndef STDC
1796 +#  if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
1797 +#    define STDC
1798 +#  endif
1799 +#endif
1800 +
1801 +#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
1802 +#  include <unix.h>
1803 +#endif
1804 +
1805 +/* Maximum value for memLevel in deflateInit2 */
1806 +#ifndef MAX_MEM_LEVEL
1807 +#  ifdef MAXSEG_64K
1808 +#    define MAX_MEM_LEVEL 8
1809 +#  else
1810 +#    define MAX_MEM_LEVEL 9
1811 +#  endif
1812 +#endif
1813 +
1814 +#ifndef FAR
1815 +#  define FAR
1816 +#endif
1817 +
1818 +/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
1819 +#ifndef MAX_WBITS
1820 +#  define MAX_WBITS   15 /* 32K LZ77 window */
1821 +#endif
1822 +
1823 +/* The memory requirements for deflate are (in bytes):
1824 +            1 << (windowBits+2)   +  1 << (memLevel+9)
1825 + that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
1826 + plus a few kilobytes for small objects. For example, if you want to reduce
1827 + the default memory requirements from 256K to 128K, compile with
1828 +     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
1829 + Of course this will generally degrade compression (there's no free lunch).
1830 +
1831 +   The memory requirements for inflate are (in bytes) 1 << windowBits
1832 + that is, 32K for windowBits=15 (default value) plus a few kilobytes
1833 + for small objects.
1834 +*/
1835 +
1836 +                        /* Type declarations */
1837 +
1838 +#ifndef OF /* function prototypes */
1839 +#  ifdef STDC
1840 +#    define OF(args)  args
1841 +#  else
1842 +#    define OF(args)  ()
1843 +#  endif
1844 +#endif
1845 +
1846 +typedef unsigned char  Byte;  /* 8 bits */
1847 +typedef unsigned int   uInt;  /* 16 bits or more */
1848 +typedef unsigned long  uLong; /* 32 bits or more */
1849 +
1850 +typedef Byte FAR Bytef;
1851 +typedef char FAR charf;
1852 +typedef int FAR intf;
1853 +typedef uInt FAR uIntf;
1854 +typedef uLong FAR uLongf;
1855 +
1856 +#ifdef STDC
1857 +   typedef void FAR *voidpf;
1858 +   typedef void     *voidp;
1859 +#else
1860 +   typedef Byte FAR *voidpf;
1861 +   typedef Byte     *voidp;
1862 +#endif
1863 +
1864 +/* end of original zconf.h */
1865 +
1866 +#define ZLIB_VERSION "0.95P"
1867 +
1868 +/* 
1869 +     The 'zlib' compression library provides in-memory compression and
1870 +  decompression functions, including integrity checks of the uncompressed
1871 +  data.  This version of the library supports only one compression method
1872 +  (deflation) but other algorithms may be added later and will have the same
1873 +  stream interface.
1874 +
1875 +     For compression the application must provide the output buffer and
1876 +  may optionally provide the input buffer for optimization. For decompression,
1877 +  the application must provide the input buffer and may optionally provide
1878 +  the output buffer for optimization.
1879 +
1880 +     Compression can be done in a single step if the buffers are large
1881 +  enough (for example if an input file is mmap'ed), or can be done by
1882 +  repeated calls of the compression function.  In the latter case, the
1883 +  application must provide more input and/or consume the output
1884 +  (providing more output space) before each call.
1885 +*/
1886 +
1887 +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
1888 +typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt nbytes));
1889 +
1890 +struct internal_state;
1891 +
1892 +typedef struct z_stream_s {
1893 +    Bytef    *next_in;  /* next input byte */
1894 +    uInt     avail_in;  /* number of bytes available at next_in */
1895 +    uLong    total_in;  /* total nb of input bytes read so far */
1896 +
1897 +    Bytef    *next_out; /* next output byte should be put there */
1898 +    uInt     avail_out; /* remaining free space at next_out */
1899 +    uLong    total_out; /* total nb of bytes output so far */
1900 +
1901 +    char     *msg;      /* last error message, NULL if no error */
1902 +    struct internal_state FAR *state; /* not visible by applications */
1903 +
1904 +    alloc_func zalloc;  /* used to allocate the internal state */
1905 +    free_func  zfree;   /* used to free the internal state */
1906 +    voidp      opaque;  /* private data object passed to zalloc and zfree */
1907 +
1908 +    Byte     data_type; /* best guess about the data type: ascii or binary */
1909 +
1910 +} z_stream;
1911 +
1912 +/*
1913 +   The application must update next_in and avail_in when avail_in has
1914 +   dropped to zero. It must update next_out and avail_out when avail_out
1915 +   has dropped to zero. The application must initialize zalloc, zfree and
1916 +   opaque before calling the init function. All other fields are set by the
1917 +   compression library and must not be updated by the application.
1918 +
1919 +   The opaque value provided by the application will be passed as the first
1920 +   parameter for calls of zalloc and zfree. This can be useful for custom
1921 +   memory management. The compression library attaches no meaning to the
1922 +   opaque value.
1923 +
1924 +   zalloc must return Z_NULL if there is not enough memory for the object.
1925 +   On 16-bit systems, the functions zalloc and zfree must be able to allocate
1926 +   exactly 65536 bytes, but will not be required to allocate more than this
1927 +   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
1928 +   pointers returned by zalloc for objects of exactly 65536 bytes *must*
1929 +   have their offset normalized to zero. The default allocation function
1930 +   provided by this library ensures this (see zutil.c). To reduce memory
1931 +   requirements and avoid any allocation of 64K objects, at the expense of
1932 +   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
1933 +
1934 +   The fields total_in and total_out can be used for statistics or
1935 +   progress reports. After compression, total_in holds the total size of
1936 +   the uncompressed data and may be saved for use in the decompressor
1937 +   (particularly if the decompressor wants to decompress everything in
1938 +   a single step).
1939 +*/
1940 +
1941 +                        /* constants */
1942 +
1943 +#define Z_NO_FLUSH      0
1944 +#define Z_PARTIAL_FLUSH 1
1945 +#define Z_FULL_FLUSH    2
1946 +#define Z_SYNC_FLUSH    3 /* experimental: partial_flush + byte align */
1947 +#define Z_FINISH        4
1948 +#define Z_PACKET_FLUSH 5
1949 +/* See deflate() below for the usage of these constants */
1950 +
1951 +#define Z_OK            0
1952 +#define Z_STREAM_END    1
1953 +#define Z_ERRNO        (-1)
1954 +#define Z_STREAM_ERROR (-2)
1955 +#define Z_DATA_ERROR   (-3)
1956 +#define Z_MEM_ERROR    (-4)
1957 +#define Z_BUF_ERROR    (-5)
1958 +/* error codes for the compression/decompression functions */
1959 +
1960 +#define Z_BEST_SPEED             1
1961 +#define Z_BEST_COMPRESSION       9
1962 +#define Z_DEFAULT_COMPRESSION  (-1)
1963 +/* compression levels */
1964 +
1965 +#define Z_FILTERED            1
1966 +#define Z_HUFFMAN_ONLY        2
1967 +#define Z_DEFAULT_STRATEGY    0
1968 +
1969 +#define Z_BINARY   0
1970 +#define Z_ASCII    1
1971 +#define Z_UNKNOWN  2
1972 +/* Used to set the data_type field */
1973 +
1974 +#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
1975 +
1976 +extern char *zlib_version;
1977 +/* The application can compare zlib_version and ZLIB_VERSION for consistency.
1978 +   If the first character differs, the library code actually used is
1979 +   not compatible with the zlib.h header file used by the application.
1980 + */
1981 +
1982 +                        /* basic functions */
1983 +
1984 +extern int inflateInit OF((z_stream *strm));
1985 +/* 
1986 +     Initializes the internal stream state for decompression. The fields
1987 +   zalloc and zfree must be initialized before by the caller.  If zalloc and
1988 +   zfree are set to Z_NULL, inflateInit updates them to use default allocation
1989 +   functions.
1990 +
1991 +     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
1992 +   enough memory.  msg is set to null if there is no error message.
1993 +   inflateInit does not perform any decompression: this will be done by
1994 +   inflate().
1995 +*/
1996 +
1997 +
1998 +extern int inflate OF((z_stream *strm, int flush));
1999 +/*
2000 +  Performs one or both of the following actions:
2001 +
2002 +  - Decompress more input starting at next_in and update next_in and avail_in
2003 +    accordingly. If not all input can be processed (because there is not
2004 +    enough room in the output buffer), next_in is updated and processing
2005 +    will resume at this point for the next call of inflate().
2006 +
2007 +  - Provide more output starting at next_out and update next_out and avail_out
2008 +    accordingly.  inflate() always provides as much output as possible
2009 +    (until there is no more input data or no more space in the output buffer).
2010 +
2011 +  Before the call of inflate(), the application should ensure that at least
2012 +  one of the actions is possible, by providing more input and/or consuming
2013 +  more output, and updating the next_* and avail_* values accordingly.
2014 +  The application can consume the uncompressed output when it wants, for
2015 +  example when the output buffer is full (avail_out == 0), or after each
2016 +  call of inflate().
2017 +
2018 +    If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
2019 +  inflate flushes as much output as possible to the output buffer. The
2020 +  flushing behavior of inflate is not specified for values of the flush
2021 +  parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
2022 +  current implementation actually flushes as much output as possible
2023 +  anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
2024 +  has been consumed, it is expecting to see the length field of a stored
2025 +  block; if not, it returns Z_DATA_ERROR.
2026 +
2027 +    inflate() should normally be called until it returns Z_STREAM_END or an
2028 +  error. However if all decompression is to be performed in a single step
2029 +  (a single call of inflate), the parameter flush should be set to
2030 +  Z_FINISH. In this case all pending input is processed and all pending
2031 +  output is flushed; avail_out must be large enough to hold all the
2032 +  uncompressed data. (The size of the uncompressed data may have been saved
2033 +  by the compressor for this purpose.) The next operation on this stream must
2034 +  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
2035 +  is never required, but can be used to inform inflate that a faster routine
2036 +  may be used for the single inflate() call.
2037 +
2038 +    inflate() returns Z_OK if some progress has been made (more input
2039 +  processed or more output produced), Z_STREAM_END if the end of the
2040 +  compressed data has been reached and all uncompressed output has been
2041 +  produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
2042 +  the stream structure was inconsistent (for example if next_in or next_out
2043 +  was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
2044 +  progress is possible or if there was not enough room in the output buffer
2045 +  when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
2046 +  call inflateSync to look for a good compression block.  */
2047 +
2048 +
2049 +extern int inflateEnd OF((z_stream *strm));
2050 +/*
2051 +     All dynamically allocated data structures for this stream are freed.
2052 +   This function discards any unprocessed input and does not flush any
2053 +   pending output.
2054 +
2055 +     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
2056 +   was inconsistent. In the error case, msg may be set but then points to a
2057 +   static string (which must not be deallocated).
2058 +*/
2059 +
2060 +                        /* advanced functions */
2061 +
2062 +extern int inflateInit2 OF((z_stream *strm,
2063 +                            int  windowBits));
2064 +/*   
2065 +     This is another version of inflateInit with more compression options. The
2066 +   fields next_out, zalloc and zfree must be initialized before by the caller.
2067 +
2068 +     The windowBits parameter is the base two logarithm of the maximum window
2069 +   size (the size of the history buffer).  It should be in the range 8..15 for
2070 +   this version of the library (the value 16 will be allowed soon). The
2071 +   default value is 15 if inflateInit is used instead. If a compressed stream
2072 +   with a larger window size is given as input, inflate() will return with
2073 +   the error code Z_DATA_ERROR instead of trying to allocate a larger window.
2074 +
2075 +     If next_out is not null, the library will use this buffer for the history
2076 +   buffer; the buffer must either be large enough to hold the entire output
2077 +   data, or have at least 1<<windowBits bytes.  If next_out is null, the
2078 +   library will allocate its own buffer (and leave next_out null). next_in
2079 +   need not be provided here but must be provided by the application for the
2080 +   next call of inflate().
2081 +
2082 +     If the history buffer is provided by the application, next_out must
2083 +   never be changed by the application since the decompressor maintains
2084 +   history information inside this buffer from call to call; the application
2085 +   can only reset next_out to the beginning of the history buffer when
2086 +   avail_out is zero and all output has been consumed.
2087 +
2088 +      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
2089 +   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
2090 +   windowBits < 8). msg is set to null if there is no error message.
2091 +   inflateInit2 does not perform any decompression: this will be done by
2092 +   inflate().
2093 +*/
2094 +
2095 +extern int inflateSync OF((z_stream *strm));
2096 +/* 
2097 +    Skips invalid compressed data until the special marker (see deflate()
2098 +  above) can be found, or until all available input is skipped. No output
2099 +  is provided.
2100 +
2101 +    inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
2102 +  if no more input was provided, Z_DATA_ERROR if no marker has been found,
2103 +  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
2104 +  case, the application may save the current current value of total_in which
2105 +  indicates where valid compressed data was found. In the error case, the
2106 +  application may repeatedly call inflateSync, providing more input each time,
2107 +  until success or end of the input data.
2108 +*/
2109 +
2110 +extern int inflateReset OF((z_stream *strm));
2111 +/*
2112 +     This function is equivalent to inflateEnd followed by inflateInit,
2113 +   but does not free and reallocate all the internal decompression state.
2114 +   The stream will keep attributes that may have been set by inflateInit2.
2115 +
2116 +      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
2117 +   stream state was inconsistent (such as zalloc or state being NULL).
2118 +*/
2119 +
2120 +extern int inflateIncomp OF((z_stream *strm));
2121 +/*
2122 +     This function adds the data at next_in (avail_in bytes) to the output
2123 +   history without performing any output.  There must be no pending output,
2124 +   and the decompressor must be expecting to see the start of a block.
2125 +   Calling this function is equivalent to decompressing a stored block
2126 +   containing the data at next_in (except that the data is not output).
2127 +*/
2128 +
2129 +                        /* checksum functions */
2130 +
2131 +/*
2132 +     This function is not related to compression but is exported
2133 +   anyway because it might be useful in applications using the
2134 +   compression library.
2135 +*/
2136 +
2137 +extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
2138 +
2139 +/*
2140 +     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
2141 +   return the updated checksum. If buf is NULL, this function returns
2142 +   the required initial value for the checksum.
2143 +   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
2144 +   much faster. Usage example:
2145 +
2146 +     uLong adler = adler32(0L, Z_NULL, 0);
2147 +
2148 +     while (read_buffer(buffer, length) != EOF) {
2149 +       adler = adler32(adler, buffer, length);
2150 +     }
2151 +     if (adler != original_adler) error();
2152 +*/
2153 +
2154 +#ifndef _Z_UTIL_H
2155 +    struct internal_state {int dummy;}; /* hack for buggy compilers */
2156 +#endif
2157 +
2158 +#endif /* _ZLIB_H */
2159 diff -Naru linux/arch/mips/zboot/ld.script linux.spi/arch/mips/zboot/ld.script
2160 --- linux/arch/mips/zboot/ld.script     1969-12-31 19:00:00.000000000 -0500
2161 +++ linux.spi/arch/mips/zboot/ld.script 2004-05-11 23:19:24.000000000 -0400
2162 @@ -0,0 +1,151 @@
2163 +OUTPUT_ARCH(mips)
2164 +ENTRY(start)
2165 +SECTIONS
2166 +{
2167 +  /* Read-only sections, merged into text segment: */
2168 +  /* . = 0x81000000; */
2169 +  .init          : { *(.init)          } =0
2170 +  .text      :
2171 +  {
2172 +    _ftext = . ;
2173 +    *(.text)
2174 +    *(.rodata)
2175 +    *(.rodata1)
2176 +    /* .gnu.warning sections are handled specially by elf32.em.  */
2177 +    *(.gnu.warning)
2178 +  } =0
2179 +  .kstrtab : { *(.kstrtab) }
2180 +
2181 +  . = ALIGN(16);               /* Exception table */
2182 +  __start___ex_table = .;
2183 +  __ex_table : { *(__ex_table) }
2184 +  __stop___ex_table = .;
2185 +
2186 +  __start___dbe_table = .;     /* Exception table for data bus errors */
2187 +  __dbe_table : { *(__dbe_table) }
2188 +  __stop___dbe_table = .;
2189 +
2190 +  __start___ksymtab = .;       /* Kernel symbol table */
2191 +  __ksymtab : { *(__ksymtab) }
2192 +  __stop___ksymtab = .;
2193 +
2194 +  _etext = .;
2195 +
2196 +  . = ALIGN(8192);
2197 +  .data.init_task : { *(.data.init_task) }
2198 +
2199 +  /* Startup code */
2200 +  . = ALIGN(4096);
2201 +  __init_begin = .;
2202 +  .text.init : { *(.text.init) }
2203 +  .data.init : { *(.data.init) }
2204 +  . = ALIGN(16);
2205 +  __setup_start = .;
2206 +  .setup.init : { *(.setup.init) }
2207 +  __setup_end = .;
2208 +  __initcall_start = .;
2209 +  .initcall.init : { *(.initcall.init) }
2210 +  __initcall_end = .;
2211 +  . = ALIGN(4096);     /* Align double page for init_task_union */
2212 +  __init_end = .;
2213 +
2214 +  . = ALIGN(4096);
2215 +  .data.page_aligned : { *(.data.idt) }
2216 +
2217 +  . = ALIGN(32);
2218 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
2219 +
2220 +  .fini      : { *(.fini)    } =0
2221 +  .reginfo : { *(.reginfo) }
2222 +  /* Adjust the address for the data segment.  We want to adjust up to
2223 +     the same address within the page on the next page up.  It would
2224 +     be more correct to do this:
2225 +       . = .;
2226 +     The current expression does not correctly handle the case of a
2227 +     text segment ending precisely at the end of a page; it causes the
2228 +     data segment to skip a page.  The above expression does not have
2229 +     this problem, but it will currently (2/95) cause BFD to allocate
2230 +     a single segment, combining both text and data, for this case.
2231 +     This will prevent the text segment from being shared among
2232 +     multiple executions of the program; I think that is more
2233 +     important than losing a page of the virtual address space (note
2234 +     that no actual memory is lost; the page which is skipped can not
2235 +     be referenced).  */
2236 +  . = .;
2237 +  .data    :
2238 +  {
2239 +    _fdata = . ;
2240 +    *(.data)
2241 +
2242 +   /* Put the compressed image here, so bss is on the end. */
2243 +   __image_begin = .;
2244 +   *(.image)
2245 +   __image_end = .;
2246 +   /* Align the initial ramdisk image (INITRD) on page boundaries. */
2247 +   . = ALIGN(4096);
2248 +   __ramdisk_begin = .;
2249 +   *(.initrd)
2250 +   __ramdisk_end = .;
2251 +   . = ALIGN(4096);
2252 +
2253 +    CONSTRUCTORS
2254 +  }
2255 +  .data1   : { *(.data1) }
2256 +  _gp = . + 0x8000;
2257 +  .lit8 : { *(.lit8) }
2258 +  .lit4 : { *(.lit4) }
2259 +  .ctors         : { *(.ctors)   }
2260 +  .dtors         : { *(.dtors)   }
2261 +  .got           : { *(.got.plt) *(.got) }
2262 +  .dynamic       : { *(.dynamic) }
2263 +  /* We want the small data sections together, so single-instruction offsets
2264 +     can access them all, and initialized data all before uninitialized, so
2265 +     we can shorten the on-disk segment size.  */
2266 +  .sdata     : { *(.sdata) }
2267 +  . = ALIGN(4);
2268 +  _edata  =  .;
2269 +  PROVIDE (edata = .);
2270 +
2271 +  __bss_start = .;
2272 +  _fbss = .;
2273 +  .sbss      : { *(.sbss) *(.scommon) }
2274 +  .bss       :
2275 +  {
2276 +   *(.dynbss)
2277 +   *(.bss)
2278 +   *(COMMON)
2279 +   .  = ALIGN(4);
2280 +  _end = . ;
2281 +  PROVIDE (end = .);
2282 +  }
2283 +
2284 +  /* Sections to be discarded */
2285 +  /DISCARD/ :
2286 +  {
2287 +        *(.text.exit)
2288 +        *(.data.exit)
2289 +        *(.exitcall.exit)
2290 +  }
2291 +
2292 +  /* This is the MIPS specific mdebug section.  */
2293 +  .mdebug : { *(.mdebug) }
2294 +  /* These are needed for ELF backends which have not yet been
2295 +     converted to the new style linker.  */
2296 +  .stab 0 : { *(.stab) }
2297 +  .stabstr 0 : { *(.stabstr) }
2298 +  /* DWARF debug sections.
2299 +     Symbols in the .debug DWARF section are relative to the beginning of the
2300 +     section so we begin .debug at 0.  It's not clear yet what needs to happen
2301 +     for the others.   */
2302 +  .debug          0 : { *(.debug) }
2303 +  .debug_srcinfo  0 : { *(.debug_srcinfo) }
2304 +  .debug_aranges  0 : { *(.debug_aranges) }
2305 +  .debug_pubnames 0 : { *(.debug_pubnames) }
2306 +  .debug_sfnames  0 : { *(.debug_sfnames) }
2307 +  .line           0 : { *(.line) }
2308 +  /* These must appear regardless of  .  */
2309 +  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
2310 +  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
2311 +  .comment : { *(.comment) }
2312 +  .note : { *(.note) }
2313 +}
2314 diff -Naru linux/arch/mips/zboot/lib/Makefile linux.spi/arch/mips/zboot/lib/Makefile
2315 --- linux/arch/mips/zboot/lib/Makefile  1969-12-31 19:00:00.000000000 -0500
2316 +++ linux.spi/arch/mips/zboot/lib/Makefile      2004-05-11 23:19:24.000000000 -0400
2317 @@ -0,0 +1,9 @@
2318 +#
2319 +# Makefile for some libs needed by zImage.
2320 +#
2321 +
2322 +L_TARGET := zlib.a
2323 +
2324 +obj-y := zlib.o
2325 +
2326 +include $(TOPDIR)/Rules.make
2327 diff -Naru linux/arch/mips/zboot/lib/zlib.c linux.spi/arch/mips/zboot/lib/zlib.c
2328 --- linux/arch/mips/zboot/lib/zlib.c    1969-12-31 19:00:00.000000000 -0500
2329 +++ linux.spi/arch/mips/zboot/lib/zlib.c        2004-05-11 23:19:24.000000000 -0400
2330 @@ -0,0 +1,2148 @@
2331 +/*
2332 + * This file is derived from various .h and .c files from the zlib-0.95
2333 + * distribution by Jean-loup Gailly and Mark Adler, with some additions
2334 + * by Paul Mackerras to aid in implementing Deflate compression and
2335 + * decompression for PPP packets.  See zlib.h for conditions of
2336 + * distribution and use.
2337 + *
2338 + * Changes that have been made include:
2339 + * - changed functions not used outside this file to "local"
2340 + * - added minCompression parameter to deflateInit2
2341 + * - added Z_PACKET_FLUSH (see zlib.h for details)
2342 + * - added inflateIncomp
2343 + *
2344 + * $Id: zlib.c,v 1.2 2002/02/16 16:55:45 ppopov Exp $
2345 + */
2346 +
2347 +/*+++++*/
2348 +/* zutil.h -- internal interface and configuration of the compression library
2349 + * Copyright (C) 1995 Jean-loup Gailly.
2350 + * For conditions of distribution and use, see copyright notice in zlib.h
2351 + */
2352 +
2353 +/* WARNING: this file should *not* be used by applications. It is
2354 +   part of the implementation of the compression library and is
2355 +   subject to change. Applications should only use zlib.h.
2356 + */
2357 +
2358 +/* From: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp */
2359 +
2360 +#define _Z_UTIL_H
2361 +
2362 +#include "zlib.h"
2363 +
2364 +#ifndef local
2365 +#  define local static
2366 +#endif
2367 +/* compile with -Dlocal if your debugger can't find static symbols */
2368 +
2369 +#define FAR
2370 +
2371 +typedef unsigned char  uch;
2372 +typedef uch FAR uchf;
2373 +typedef unsigned short ush;
2374 +typedef ush FAR ushf;
2375 +typedef unsigned long  ulg;
2376 +
2377 +extern char *z_errmsg[]; /* indexed by 1-zlib_error */
2378 +
2379 +#define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
2380 +/* To be used only when the state is known to be valid */
2381 +
2382 +#ifndef NULL
2383 +#define NULL   ((void *) 0)
2384 +#endif
2385 +
2386 +        /* common constants */
2387 +
2388 +#define DEFLATED   8
2389 +
2390 +#ifndef DEF_WBITS
2391 +#  define DEF_WBITS MAX_WBITS
2392 +#endif
2393 +/* default windowBits for decompression. MAX_WBITS is for compression only */
2394 +
2395 +#if MAX_MEM_LEVEL >= 8
2396 +#  define DEF_MEM_LEVEL 8
2397 +#else
2398 +#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
2399 +#endif
2400 +/* default memLevel */
2401 +
2402 +#define STORED_BLOCK 0
2403 +#define STATIC_TREES 1
2404 +#define DYN_TREES    2
2405 +/* The three kinds of block type */
2406 +
2407 +#define MIN_MATCH  3
2408 +#define MAX_MATCH  258
2409 +/* The minimum and maximum match lengths */
2410 +
2411 +         /* functions */
2412 +
2413 +#include <linux/string.h>
2414 +#define zmemcpy memcpy
2415 +#define zmemzero(dest, len)    memset(dest, 0, len)
2416 +
2417 +/* Diagnostic functions */
2418 +#ifdef DEBUG_ZLIB
2419 +#  include <stdio.h>
2420 +#  ifndef verbose
2421 +#    define verbose 0
2422 +#  endif
2423 +#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
2424 +#  define Trace(x) fprintf x
2425 +#  define Tracev(x) {if (verbose) fprintf x ;}
2426 +#  define Tracevv(x) {if (verbose>1) fprintf x ;}
2427 +#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
2428 +#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
2429 +#else
2430 +#  define Assert(cond,msg)
2431 +#  define Trace(x)
2432 +#  define Tracev(x)
2433 +#  define Tracevv(x)
2434 +#  define Tracec(c,x)
2435 +#  define Tracecv(c,x)
2436 +#endif
2437 +
2438 +
2439 +typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
2440 +
2441 +/* voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); */
2442 +/* void   zcfree  OF((voidpf opaque, voidpf ptr)); */
2443 +
2444 +#define ZALLOC(strm, items, size) \
2445 +           (*((strm)->zalloc))((strm)->opaque, (items), (size))
2446 +#define ZFREE(strm, addr, size)        \
2447 +          (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size))
2448 +#define TRY_FREE(s, p, n) {if (p) ZFREE(s, p, n);}
2449 +
2450 +/* deflate.h -- internal compression state
2451 + * Copyright (C) 1995 Jean-loup Gailly
2452 + * For conditions of distribution and use, see copyright notice in zlib.h 
2453 + */
2454 +
2455 +/* WARNING: this file should *not* be used by applications. It is
2456 +   part of the implementation of the compression library and is
2457 +   subject to change. Applications should only use zlib.h.
2458 + */
2459 +
2460 +/*+++++*/
2461 +/* infblock.h -- header to use infblock.c
2462 + * Copyright (C) 1995 Mark Adler
2463 + * For conditions of distribution and use, see copyright notice in zlib.h 
2464 + */
2465 +
2466 +/* WARNING: this file should *not* be used by applications. It is
2467 +   part of the implementation of the compression library and is
2468 +   subject to change. Applications should only use zlib.h.
2469 + */
2470 +
2471 +struct inflate_blocks_state;
2472 +typedef struct inflate_blocks_state FAR inflate_blocks_statef;
2473 +
2474 +local inflate_blocks_statef * inflate_blocks_new OF((
2475 +    z_stream *z,
2476 +    check_func c,               /* check function */
2477 +    uInt w));                   /* window size */
2478 +
2479 +local int inflate_blocks OF((
2480 +    inflate_blocks_statef *,
2481 +    z_stream *,
2482 +    int));                      /* initial return code */
2483 +
2484 +local void inflate_blocks_reset OF((
2485 +    inflate_blocks_statef *,
2486 +    z_stream *,
2487 +    uLongf *));                  /* check value on output */
2488 +
2489 +local int inflate_blocks_free OF((
2490 +    inflate_blocks_statef *,
2491 +    z_stream *,
2492 +    uLongf *));                  /* check value on output */
2493 +
2494 +local int inflate_addhistory OF((
2495 +    inflate_blocks_statef *,
2496 +    z_stream *));
2497 +
2498 +local int inflate_packet_flush OF((
2499 +    inflate_blocks_statef *));
2500 +
2501 +/*+++++*/
2502 +/* inftrees.h -- header to use inftrees.c
2503 + * Copyright (C) 1995 Mark Adler
2504 + * For conditions of distribution and use, see copyright notice in zlib.h 
2505 + */
2506 +
2507 +/* WARNING: this file should *not* be used by applications. It is
2508 +   part of the implementation of the compression library and is
2509 +   subject to change. Applications should only use zlib.h.
2510 + */
2511 +
2512 +/* Huffman code lookup table entry--this entry is four bytes for machines
2513 +   that have 16-bit pointers (e.g. PC's in the small or medium model). */
2514 +
2515 +typedef struct inflate_huft_s FAR inflate_huft;
2516 +
2517 +struct inflate_huft_s {
2518 +  union {
2519 +    struct {
2520 +      Byte Exop;        /* number of extra bits or operation */
2521 +      Byte Bits;        /* number of bits in this code or subcode */
2522 +    } what;
2523 +    uInt Nalloc;       /* number of these allocated here */
2524 +    Bytef *pad;         /* pad structure to a power of 2 (4 bytes for */
2525 +  } word;               /*  16-bit, 8 bytes for 32-bit machines) */
2526 +  union {
2527 +    uInt Base;          /* literal, length base, or distance base */
2528 +    inflate_huft *Next; /* pointer to next level of table */
2529 +  } more;
2530 +};
2531 +
2532 +#ifdef DEBUG_ZLIB
2533 +  local uInt inflate_hufts;
2534 +#endif
2535 +
2536 +local int inflate_trees_bits OF((
2537 +    uIntf *,                    /* 19 code lengths */
2538 +    uIntf *,                    /* bits tree desired/actual depth */
2539 +    inflate_huft * FAR *,       /* bits tree result */
2540 +    z_stream *));               /* for zalloc, zfree functions */
2541 +
2542 +local int inflate_trees_dynamic OF((
2543 +    uInt,                       /* number of literal/length codes */
2544 +    uInt,                       /* number of distance codes */
2545 +    uIntf *,                    /* that many (total) code lengths */
2546 +    uIntf *,                    /* literal desired/actual bit depth */
2547 +    uIntf *,                    /* distance desired/actual bit depth */
2548 +    inflate_huft * FAR *,       /* literal/length tree result */
2549 +    inflate_huft * FAR *,       /* distance tree result */
2550 +    z_stream *));               /* for zalloc, zfree functions */
2551 +
2552 +local int inflate_trees_fixed OF((
2553 +    uIntf *,                    /* literal desired/actual bit depth */
2554 +    uIntf *,                    /* distance desired/actual bit depth */
2555 +    inflate_huft * FAR *,       /* literal/length tree result */
2556 +    inflate_huft * FAR *));     /* distance tree result */
2557 +
2558 +local int inflate_trees_free OF((
2559 +    inflate_huft *,             /* tables to free */
2560 +    z_stream *));               /* for zfree function */
2561 +
2562 +
2563 +/*+++++*/
2564 +/* infcodes.h -- header to use infcodes.c
2565 + * Copyright (C) 1995 Mark Adler
2566 + * For conditions of distribution and use, see copyright notice in zlib.h 
2567 + */
2568 +
2569 +/* WARNING: this file should *not* be used by applications. It is
2570 +   part of the implementation of the compression library and is
2571 +   subject to change. Applications should only use zlib.h.
2572 + */
2573 +
2574 +struct inflate_codes_state;
2575 +typedef struct inflate_codes_state FAR inflate_codes_statef;
2576 +
2577 +local inflate_codes_statef *inflate_codes_new OF((
2578 +    uInt, uInt,
2579 +    inflate_huft *, inflate_huft *,
2580 +    z_stream *));
2581 +
2582 +local int inflate_codes OF((
2583 +    inflate_blocks_statef *,
2584 +    z_stream *,
2585 +    int));
2586 +
2587 +local void inflate_codes_free OF((
2588 +    inflate_codes_statef *,
2589 +    z_stream *));
2590 +
2591 +
2592 +/*+++++*/
2593 +/* inflate.c -- zlib interface to inflate modules
2594 + * Copyright (C) 1995 Mark Adler
2595 + * For conditions of distribution and use, see copyright notice in zlib.h 
2596 + */
2597 +
2598 +/* inflate private state */
2599 +struct internal_state {
2600 +
2601 +  /* mode */
2602 +  enum {
2603 +      METHOD,   /* waiting for method byte */
2604 +      FLAG,     /* waiting for flag byte */
2605 +      BLOCKS,   /* decompressing blocks */
2606 +      CHECK4,   /* four check bytes to go */
2607 +      CHECK3,   /* three check bytes to go */
2608 +      CHECK2,   /* two check bytes to go */
2609 +      CHECK1,   /* one check byte to go */
2610 +      DONE,     /* finished check, done */
2611 +      BAD}      /* got an error--stay here */
2612 +    mode;               /* current inflate mode */
2613 +
2614 +  /* mode dependent information */
2615 +  union {
2616 +    uInt method;        /* if FLAGS, method byte */
2617 +    struct {
2618 +      uLong was;                /* computed check value */
2619 +      uLong need;               /* stream check value */
2620 +    } check;            /* if CHECK, check values to compare */
2621 +    uInt marker;        /* if BAD, inflateSync's marker bytes count */
2622 +  } sub;        /* submode */
2623 +
2624 +  /* mode independent information */
2625 +  int  nowrap;          /* flag for no wrapper */
2626 +  uInt wbits;           /* log2(window size)  (8..15, defaults to 15) */
2627 +  inflate_blocks_statef 
2628 +    *blocks;            /* current inflate_blocks state */
2629 +
2630 +};
2631 +
2632 +
2633 +int inflateReset(z)
2634 +z_stream *z;
2635 +{
2636 +  uLong c;
2637 +
2638 +  if (z == Z_NULL || z->state == Z_NULL)
2639 +    return Z_STREAM_ERROR;
2640 +  z->total_in = z->total_out = 0;
2641 +  z->msg = Z_NULL;
2642 +  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
2643 +  inflate_blocks_reset(z->state->blocks, z, &c);
2644 +  Trace((stderr, "inflate: reset\n"));
2645 +  return Z_OK;
2646 +}
2647 +
2648 +
2649 +int inflateEnd(z)
2650 +z_stream *z;
2651 +{
2652 +  uLong c;
2653 +
2654 +  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
2655 +    return Z_STREAM_ERROR;
2656 +  if (z->state->blocks != Z_NULL)
2657 +    inflate_blocks_free(z->state->blocks, z, &c);
2658 +  ZFREE(z, z->state, sizeof(struct internal_state));
2659 +  z->state = Z_NULL;
2660 +  Trace((stderr, "inflate: end\n"));
2661 +  return Z_OK;
2662 +}
2663 +
2664 +
2665 +int inflateInit2(z, w)
2666 +z_stream *z;
2667 +int w;
2668 +{
2669 +  /* initialize state */
2670 +  if (z == Z_NULL)
2671 +    return Z_STREAM_ERROR;
2672 +/*  if (z->zalloc == Z_NULL) z->zalloc = zcalloc; */
2673 +/*  if (z->zfree == Z_NULL) z->zfree = zcfree; */
2674 +  if ((z->state = (struct internal_state FAR *)
2675 +       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
2676 +    return Z_MEM_ERROR;
2677 +  z->state->blocks = Z_NULL;
2678 +
2679 +  /* handle undocumented nowrap option (no zlib header or check) */
2680 +  z->state->nowrap = 0;
2681 +  if (w < 0)
2682 +  {
2683 +    w = - w;
2684 +    z->state->nowrap = 1;
2685 +  }
2686 +
2687 +  /* set window size */
2688 +  if (w < 8 || w > 15)
2689 +  {
2690 +    inflateEnd(z);
2691 +    return Z_STREAM_ERROR;
2692 +  }
2693 +  z->state->wbits = (uInt)w;
2694 +
2695 +  /* create inflate_blocks state */
2696 +  if ((z->state->blocks =
2697 +       inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w))
2698 +      == Z_NULL)
2699 +  {
2700 +    inflateEnd(z);
2701 +    return Z_MEM_ERROR;
2702 +  }
2703 +  Trace((stderr, "inflate: allocated\n"));
2704 +
2705 +  /* reset state */
2706 +  inflateReset(z);
2707 +  return Z_OK;
2708 +}
2709 +
2710 +
2711 +int inflateInit(z)
2712 +z_stream *z;
2713 +{
2714 +  return inflateInit2(z, DEF_WBITS);
2715 +}
2716 +
2717 +
2718 +#define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;}
2719 +#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
2720 +
2721 +int inflate(z, f)
2722 +z_stream *z;
2723 +int f;
2724 +{
2725 +  int r;
2726 +  uInt b;
2727 +
2728 +  if (z == Z_NULL || z->next_in == Z_NULL)
2729 +    return Z_STREAM_ERROR;
2730 +  r = Z_BUF_ERROR;
2731 +  while (1) switch (z->state->mode)
2732 +  {
2733 +    case METHOD:
2734 +      NEEDBYTE
2735 +      if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED)
2736 +      {
2737 +        z->state->mode = BAD;
2738 +        z->msg = "unknown compression method";
2739 +        z->state->sub.marker = 5;       /* can't try inflateSync */
2740 +        break;
2741 +      }
2742 +      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
2743 +      {
2744 +        z->state->mode = BAD;
2745 +        z->msg = "invalid window size";
2746 +        z->state->sub.marker = 5;       /* can't try inflateSync */
2747 +        break;
2748 +      }
2749 +      z->state->mode = FLAG;
2750 +    case FLAG:
2751 +      NEEDBYTE
2752 +      if ((b = NEXTBYTE) & 0x20)
2753 +      {
2754 +        z->state->mode = BAD;
2755 +        z->msg = "invalid reserved bit";
2756 +        z->state->sub.marker = 5;       /* can't try inflateSync */
2757 +        break;
2758 +      }
2759 +      if (((z->state->sub.method << 8) + b) % 31)
2760 +      {
2761 +        z->state->mode = BAD;
2762 +        z->msg = "incorrect header check";
2763 +        z->state->sub.marker = 5;       /* can't try inflateSync */
2764 +        break;
2765 +      }
2766 +      Trace((stderr, "inflate: zlib header ok\n"));
2767 +      z->state->mode = BLOCKS;
2768 +    case BLOCKS:
2769 +      r = inflate_blocks(z->state->blocks, z, r);
2770 +      if (f == Z_PACKET_FLUSH && z->avail_in == 0 && z->avail_out != 0)
2771 +         r = inflate_packet_flush(z->state->blocks);
2772 +      if (r == Z_DATA_ERROR)
2773 +      {
2774 +        z->state->mode = BAD;
2775 +        z->state->sub.marker = 0;       /* can try inflateSync */
2776 +        break;
2777 +      }
2778 +      if (r != Z_STREAM_END)
2779 +        return r;
2780 +      r = Z_OK;
2781 +      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
2782 +      if (z->state->nowrap)
2783 +      {
2784 +        z->state->mode = DONE;
2785 +        break;
2786 +      }
2787 +      z->state->mode = CHECK4;
2788 +    case CHECK4:
2789 +      NEEDBYTE
2790 +      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
2791 +      z->state->mode = CHECK3;
2792 +    case CHECK3:
2793 +      NEEDBYTE
2794 +      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
2795 +      z->state->mode = CHECK2;
2796 +    case CHECK2:
2797 +      NEEDBYTE
2798 +      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
2799 +      z->state->mode = CHECK1;
2800 +    case CHECK1:
2801 +      NEEDBYTE
2802 +      z->state->sub.check.need += (uLong)NEXTBYTE;
2803 +
2804 +      if (z->state->sub.check.was != z->state->sub.check.need)
2805 +      {
2806 +        z->state->mode = BAD;
2807 +        z->msg = "incorrect data check";
2808 +        z->state->sub.marker = 5;       /* can't try inflateSync */
2809 +        break;
2810 +      }
2811 +      Trace((stderr, "inflate: zlib check ok\n"));
2812 +      z->state->mode = DONE;
2813 +    case DONE:
2814 +      return Z_STREAM_END;
2815 +    case BAD:
2816 +      return Z_DATA_ERROR;
2817 +    default:
2818 +      return Z_STREAM_ERROR;
2819 +  }
2820 +
2821 + empty:
2822 +  if (f != Z_PACKET_FLUSH)
2823 +    return r;
2824 +  z->state->mode = BAD;
2825 +  z->state->sub.marker = 0;       /* can try inflateSync */
2826 +  return Z_DATA_ERROR;
2827 +}
2828 +
2829 +/*
2830 + * This subroutine adds the data at next_in/avail_in to the output history
2831 + * without performing any output.  The output buffer must be "caught up";
2832 + * i.e. no pending output (hence s->read equals s->write), and the state must
2833 + * be BLOCKS (i.e. we should be willing to see the start of a series of
2834 + * BLOCKS).  On exit, the output will also be caught up, and the checksum
2835 + * will have been updated if need be.
2836 + */
2837 +
2838 +int inflateIncomp(z)
2839 +z_stream *z;
2840 +{
2841 +    if (z->state->mode != BLOCKS)
2842 +       return Z_DATA_ERROR;
2843 +    return inflate_addhistory(z->state->blocks, z);
2844 +}
2845 +
2846 +
2847 +int inflateSync(z)
2848 +z_stream *z;
2849 +{
2850 +  uInt n;       /* number of bytes to look at */
2851 +  Bytef *p;     /* pointer to bytes */
2852 +  uInt m;       /* number of marker bytes found in a row */
2853 +  uLong r, w;   /* temporaries to save total_in and total_out */
2854 +
2855 +  /* set up */
2856 +  if (z == Z_NULL || z->state == Z_NULL)
2857 +    return Z_STREAM_ERROR;
2858 +  if (z->state->mode != BAD)
2859 +  {
2860 +    z->state->mode = BAD;
2861 +    z->state->sub.marker = 0;
2862 +  }
2863 +  if ((n = z->avail_in) == 0)
2864 +    return Z_BUF_ERROR;
2865 +  p = z->next_in;
2866 +  m = z->state->sub.marker;
2867 +
2868 +  /* search */
2869 +  while (n && m < 4)
2870 +  {
2871 +    if (*p == (Byte)(m < 2 ? 0 : 0xff))
2872 +      m++;
2873 +    else if (*p)
2874 +      m = 0;
2875 +    else
2876 +      m = 4 - m;
2877 +    p++, n--;
2878 +  }
2879 +
2880 +  /* restore */
2881 +  z->total_in += p - z->next_in;
2882 +  z->next_in = p;
2883 +  z->avail_in = n;
2884 +  z->state->sub.marker = m;
2885 +
2886 +  /* return no joy or set up to restart on a new block */
2887 +  if (m != 4)
2888 +    return Z_DATA_ERROR;
2889 +  r = z->total_in;  w = z->total_out;
2890 +  inflateReset(z);
2891 +  z->total_in = r;  z->total_out = w;
2892 +  z->state->mode = BLOCKS;
2893 +  return Z_OK;
2894 +}
2895 +
2896 +#undef NEEDBYTE
2897 +#undef NEXTBYTE
2898 +
2899 +/*+++++*/
2900 +/* infutil.h -- types and macros common to blocks and codes
2901 + * Copyright (C) 1995 Mark Adler
2902 + * For conditions of distribution and use, see copyright notice in zlib.h 
2903 + */
2904 +
2905 +/* WARNING: this file should *not* be used by applications. It is
2906 +   part of the implementation of the compression library and is
2907 +   subject to change. Applications should only use zlib.h.
2908 + */
2909 +
2910 +/* inflate blocks semi-private state */
2911 +struct inflate_blocks_state {
2912 +
2913 +  /* mode */
2914 +  enum {
2915 +      TYPE,     /* get type bits (3, including end bit) */
2916 +      LENS,     /* get lengths for stored */
2917 +      STORED,   /* processing stored block */
2918 +      TABLE,    /* get table lengths */
2919 +      BTREE,    /* get bit lengths tree for a dynamic block */
2920 +      DTREE,    /* get length, distance trees for a dynamic block */
2921 +      CODES,    /* processing fixed or dynamic block */
2922 +      DRY,      /* output remaining window bytes */
2923 +      DONEB,     /* finished last block, done */
2924 +      BADB}      /* got a data error--stuck here */
2925 +    mode;               /* current inflate_block mode */
2926 +
2927 +  /* mode dependent information */
2928 +  union {
2929 +    uInt left;          /* if STORED, bytes left to copy */
2930 +    struct {
2931 +      uInt table;               /* table lengths (14 bits) */
2932 +      uInt index;               /* index into blens (or border) */
2933 +      uIntf *blens;             /* bit lengths of codes */
2934 +      uInt bb;                  /* bit length tree depth */
2935 +      inflate_huft *tb;         /* bit length decoding tree */
2936 +      int nblens;              /* # elements allocated at blens */
2937 +    } trees;            /* if DTREE, decoding info for trees */
2938 +    struct {
2939 +      inflate_huft *tl, *td;    /* trees to free */
2940 +      inflate_codes_statef 
2941 +         *codes;
2942 +    } decode;           /* if CODES, current state */
2943 +  } sub;                /* submode */
2944 +  uInt last;            /* true if this block is the last block */
2945 +
2946 +  /* mode independent information */
2947 +  uInt bitk;            /* bits in bit buffer */
2948 +  uLong bitb;           /* bit buffer */
2949 +  Bytef *window;        /* sliding window */
2950 +  Bytef *end;           /* one byte after sliding window */
2951 +  Bytef *read;          /* window read pointer */
2952 +  Bytef *write;         /* window write pointer */
2953 +  check_func checkfn;   /* check function */
2954 +  uLong check;          /* check on output */
2955 +
2956 +};
2957 +
2958 +
2959 +/* defines for inflate input/output */
2960 +/*   update pointers and return */
2961 +#define UPDBITS {s->bitb=b;s->bitk=k;}
2962 +#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
2963 +#define UPDOUT {s->write=q;}
2964 +#define UPDATE {UPDBITS UPDIN UPDOUT}
2965 +#define LEAVE {UPDATE return inflate_flush(s,z,r);}
2966 +/*   get bytes and bits */
2967 +#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
2968 +#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
2969 +#define NEXTBYTE (n--,*p++)
2970 +#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
2971 +#define DUMPBITS(j) {b>>=(j);k-=(j);}
2972 +/*   output bytes */
2973 +#define WAVAIL (q<s->read?s->read-q-1:s->end-q)
2974 +#define LOADOUT {q=s->write;m=WAVAIL;}
2975 +#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}}
2976 +#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
2977 +#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
2978 +#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
2979 +/*   load local pointers */
2980 +#define LOAD {LOADIN LOADOUT}
2981 +
2982 +/*
2983 + * The IBM 150 firmware munges the data right after _etext[].  This
2984 + * protects it. -- Cort
2985 + */
2986 +local uInt protect_mask[] = {0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0};
2987 +/* And'ing with mask[n] masks the lower n bits */
2988 +local uInt inflate_mask[] = {
2989 +    0x0000,
2990 +    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
2991 +    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
2992 +};
2993 +
2994 +/* copy as much as possible from the sliding window to the output area */
2995 +local int inflate_flush OF((
2996 +    inflate_blocks_statef *,
2997 +    z_stream *,
2998 +    int));
2999 +
3000 +/*+++++*/
3001 +/* inffast.h -- header to use inffast.c
3002 + * Copyright (C) 1995 Mark Adler
3003 + * For conditions of distribution and use, see copyright notice in zlib.h 
3004 + */
3005 +
3006 +/* WARNING: this file should *not* be used by applications. It is
3007 +   part of the implementation of the compression library and is
3008 +   subject to change. Applications should only use zlib.h.
3009 + */
3010 +
3011 +local int inflate_fast OF((
3012 +    uInt,
3013 +    uInt,
3014 +    inflate_huft *,
3015 +    inflate_huft *,
3016 +    inflate_blocks_statef *,
3017 +    z_stream *));
3018 +
3019 +
3020 +/*+++++*/
3021 +/* infblock.c -- interpret and process block types to last block
3022 + * Copyright (C) 1995 Mark Adler
3023 + * For conditions of distribution and use, see copyright notice in zlib.h 
3024 + */
3025 +
3026 +/* Table for deflate from PKZIP's appnote.txt. */
3027 +local uInt border[] = { /* Order of the bit length code lengths */
3028 +        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
3029 +
3030 +/*
3031 +   Notes beyond the 1.93a appnote.txt:
3032 +
3033 +   1. Distance pointers never point before the beginning of the output
3034 +      stream.
3035 +   2. Distance pointers can point back across blocks, up to 32k away.
3036 +   3. There is an implied maximum of 7 bits for the bit length table and
3037 +      15 bits for the actual data.
3038 +   4. If only one code exists, then it is encoded using one bit.  (Zero
3039 +      would be more efficient, but perhaps a little confusing.)  If two
3040 +      codes exist, they are coded using one bit each (0 and 1).
3041 +   5. There is no way of sending zero distance codes--a dummy must be
3042 +      sent if there are none.  (History: a pre 2.0 version of PKZIP would
3043 +      store blocks with no distance codes, but this was discovered to be
3044 +      too harsh a criterion.)  Valid only for 1.93a.  2.04c does allow
3045 +      zero distance codes, which is sent as one code of zero bits in
3046 +      length.
3047 +   6. There are up to 286 literal/length codes.  Code 256 represents the
3048 +      end-of-block.  Note however that the static length tree defines
3049 +      288 codes just to fill out the Huffman codes.  Codes 286 and 287
3050 +      cannot be used though, since there is no length base or extra bits
3051 +      defined for them.  Similarily, there are up to 30 distance codes.
3052 +      However, static trees define 32 codes (all 5 bits) to fill out the
3053 +      Huffman codes, but the last two had better not show up in the data.
3054 +   7. Unzip can check dynamic Huffman blocks for complete code sets.
3055 +      The exception is that a single code would not be complete (see #4).
3056 +   8. The five bits following the block type is really the number of
3057 +      literal codes sent minus 257.
3058 +   9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
3059 +      (1+6+6).  Therefore, to output three times the length, you output
3060 +      three codes (1+1+1), whereas to output four times the same length,
3061 +      you only need two codes (1+3).  Hmm.
3062 +  10. In the tree reconstruction algorithm, Code = Code + Increment
3063 +      only if BitLength(i) is not zero.  (Pretty obvious.)
3064 +  11. Correction: 4 Bits: # of Bit Length codes - 4     (4 - 19)
3065 +  12. Note: length code 284 can represent 227-258, but length code 285
3066 +      really is 258.  The last length deserves its own, short code
3067 +      since it gets used a lot in very redundant files.  The length
3068 +      258 is special since 258 - 3 (the min match length) is 255.
3069 +  13. The literal/length and distance code bit lengths are read as a
3070 +      single stream of lengths.  It is possible (and advantageous) for
3071 +      a repeat code (16, 17, or 18) to go across the boundary between
3072 +      the two sets of lengths.
3073 + */
3074 +
3075 +
3076 +local void inflate_blocks_reset(s, z, c)
3077 +inflate_blocks_statef *s;
3078 +z_stream *z;
3079 +uLongf *c;
3080 +{
3081 +  if (s->checkfn != Z_NULL)
3082 +    *c = s->check;
3083 +  if (s->mode == BTREE || s->mode == DTREE)
3084 +    ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
3085 +  if (s->mode == CODES)
3086 +  {
3087 +    inflate_codes_free(s->sub.decode.codes, z);
3088 +    inflate_trees_free(s->sub.decode.td, z);
3089 +    inflate_trees_free(s->sub.decode.tl, z);
3090 +  }
3091 +  s->mode = TYPE;
3092 +  s->bitk = 0;
3093 +  s->bitb = 0;
3094 +  s->read = s->write = s->window;
3095 +  if (s->checkfn != Z_NULL)
3096 +    s->check = (*s->checkfn)(0L, Z_NULL, 0);
3097 +  Trace((stderr, "inflate:   blocks reset\n"));
3098 +}
3099 +
3100 +
3101 +local inflate_blocks_statef *inflate_blocks_new(z, c, w)
3102 +z_stream *z;
3103 +check_func c;
3104 +uInt w;
3105 +{
3106 +  inflate_blocks_statef *s;
3107 +
3108 +  if ((s = (inflate_blocks_statef *)ZALLOC
3109 +       (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
3110 +    return s;
3111 +  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
3112 +  {
3113 +    ZFREE(z, s, sizeof(struct inflate_blocks_state));
3114 +    return Z_NULL;
3115 +  }
3116 +  s->end = s->window + w;
3117 +  s->checkfn = c;
3118 +  s->mode = TYPE;
3119 +  Trace((stderr, "inflate:   blocks allocated\n"));
3120 +  inflate_blocks_reset(s, z, &s->check);
3121 +  return s;
3122 +}
3123 +
3124 +
3125 +local int inflate_blocks(s, z, r)
3126 +inflate_blocks_statef *s;
3127 +z_stream *z;
3128 +int r;
3129 +{
3130 +  uInt t;               /* temporary storage */
3131 +  uLong b;              /* bit buffer */
3132 +  uInt k;               /* bits in bit buffer */
3133 +  Bytef *p;             /* input data pointer */
3134 +  uInt n;               /* bytes available there */
3135 +  Bytef *q;             /* output window write pointer */
3136 +  uInt m;               /* bytes to end of window or read pointer */
3137 +
3138 +  /* copy input/output information to locals (UPDATE macro restores) */
3139 +  LOAD
3140 +
3141 +  /* process input based on current state */
3142 +  while (1) switch (s->mode)
3143 +  {
3144 +    case TYPE:
3145 +      NEEDBITS(3)
3146 +      t = (uInt)b & 7;
3147 +      s->last = t & 1;
3148 +      switch (t >> 1)
3149 +      {
3150 +        case 0:                         /* stored */
3151 +          Trace((stderr, "inflate:     stored block%s\n",
3152 +                 s->last ? " (last)" : ""));
3153 +          DUMPBITS(3)
3154 +          t = k & 7;                    /* go to byte boundary */
3155 +          DUMPBITS(t)
3156 +          s->mode = LENS;               /* get length of stored block */
3157 +          break;
3158 +        case 1:                         /* fixed */
3159 +          Trace((stderr, "inflate:     fixed codes block%s\n",
3160 +                 s->last ? " (last)" : ""));
3161 +          {
3162 +            uInt bl, bd;
3163 +            inflate_huft *tl, *td;
3164 +
3165 +            inflate_trees_fixed(&bl, &bd, &tl, &td);
3166 +            s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
3167 +            if (s->sub.decode.codes == Z_NULL)
3168 +            {
3169 +              r = Z_MEM_ERROR;
3170 +              LEAVE
3171 +            }
3172 +            s->sub.decode.tl = Z_NULL;  /* don't try to free these */
3173 +            s->sub.decode.td = Z_NULL;
3174 +          }
3175 +          DUMPBITS(3)
3176 +          s->mode = CODES;
3177 +          break;
3178 +        case 2:                         /* dynamic */
3179 +          Trace((stderr, "inflate:     dynamic codes block%s\n",
3180 +                 s->last ? " (last)" : ""));
3181 +          DUMPBITS(3)
3182 +          s->mode = TABLE;
3183 +          break;
3184 +        case 3:                         /* illegal */
3185 +          DUMPBITS(3)
3186 +          s->mode = BADB;
3187 +          z->msg = "invalid block type";
3188 +          r = Z_DATA_ERROR;
3189 +          LEAVE
3190 +      }
3191 +      break;
3192 +    case LENS:
3193 +      NEEDBITS(32)
3194 +      if (((~b) >> 16) != (b & 0xffff))
3195 +      {
3196 +        s->mode = BADB;
3197 +        z->msg = "invalid stored block lengths";
3198 +        r = Z_DATA_ERROR;
3199 +        LEAVE
3200 +      }
3201 +      s->sub.left = (uInt)b & 0xffff;
3202 +      b = k = 0;                      /* dump bits */
3203 +      Tracev((stderr, "inflate:       stored length %u\n", s->sub.left));
3204 +      s->mode = s->sub.left ? STORED : TYPE;
3205 +      break;
3206 +    case STORED:
3207 +      if (n == 0)
3208 +        LEAVE
3209 +      NEEDOUT
3210 +      t = s->sub.left;
3211 +      if (t > n) t = n;
3212 +      if (t > m) t = m;
3213 +      zmemcpy(q, p, t);
3214 +      p += t;  n -= t;
3215 +      q += t;  m -= t;
3216 +      if ((s->sub.left -= t) != 0)
3217 +        break;
3218 +      Tracev((stderr, "inflate:       stored end, %lu total out\n",
3219 +              z->total_out + (q >= s->read ? q - s->read :
3220 +              (s->end - s->read) + (q - s->window))));
3221 +      s->mode = s->last ? DRY : TYPE;
3222 +      break;
3223 +    case TABLE:
3224 +      NEEDBITS(14)
3225 +      s->sub.trees.table = t = (uInt)b & 0x3fff;
3226 +#ifndef PKZIP_BUG_WORKAROUND
3227 +      if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
3228 +      {
3229 +        s->mode = BADB;
3230 +        z->msg = "too many length or distance symbols";
3231 +        r = Z_DATA_ERROR;
3232 +        LEAVE
3233 +      }
3234 +#endif
3235 +      t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
3236 +      if (t < 19)
3237 +        t = 19;
3238 +      if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
3239 +      {
3240 +        r = Z_MEM_ERROR;
3241 +        LEAVE
3242 +      }
3243 +      s->sub.trees.nblens = t;
3244 +      DUMPBITS(14)
3245 +      s->sub.trees.index = 0;
3246 +      Tracev((stderr, "inflate:       table sizes ok\n"));
3247 +      s->mode = BTREE;
3248 +    case BTREE:
3249 +      while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
3250 +      {
3251 +        NEEDBITS(3)
3252 +        s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
3253 +        DUMPBITS(3)
3254 +      }
3255 +      while (s->sub.trees.index < 19)
3256 +        s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
3257 +      s->sub.trees.bb = 7;
3258 +      t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
3259 +                             &s->sub.trees.tb, z);
3260 +      if (t != Z_OK)
3261 +      {
3262 +        r = t;
3263 +        if (r == Z_DATA_ERROR)
3264 +          s->mode = BADB;
3265 +        LEAVE
3266 +      }
3267 +      s->sub.trees.index = 0;
3268 +      Tracev((stderr, "inflate:       bits tree ok\n"));
3269 +      s->mode = DTREE;
3270 +    case DTREE:
3271 +      while (t = s->sub.trees.table,
3272 +             s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
3273 +      {
3274 +        inflate_huft *h;
3275 +        uInt i, j, c;
3276 +
3277 +        t = s->sub.trees.bb;
3278 +        NEEDBITS(t)
3279 +        h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
3280 +        t = h->word.what.Bits;
3281 +        c = h->more.Base;
3282 +        if (c < 16)
3283 +        {
3284 +          DUMPBITS(t)
3285 +          s->sub.trees.blens[s->sub.trees.index++] = c;
3286 +        }
3287 +        else /* c == 16..18 */
3288 +        {
3289 +          i = c == 18 ? 7 : c - 14;
3290 +          j = c == 18 ? 11 : 3;
3291 +          NEEDBITS(t + i)
3292 +          DUMPBITS(t)
3293 +          j += (uInt)b & inflate_mask[i];
3294 +          DUMPBITS(i)
3295 +          i = s->sub.trees.index;
3296 +          t = s->sub.trees.table;
3297 +          if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
3298 +              (c == 16 && i < 1))
3299 +          {
3300 +            s->mode = BADB;
3301 +            z->msg = "invalid bit length repeat";
3302 +            r = Z_DATA_ERROR;
3303 +            LEAVE
3304 +          }
3305 +          c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
3306 +          do {
3307 +            s->sub.trees.blens[i++] = c;
3308 +          } while (--j);
3309 +          s->sub.trees.index = i;
3310 +        }
3311 +      }
3312 +      inflate_trees_free(s->sub.trees.tb, z);
3313 +      s->sub.trees.tb = Z_NULL;
3314 +      {
3315 +        uInt bl, bd;
3316 +        inflate_huft *tl, *td;
3317 +        inflate_codes_statef *c;
3318 +
3319 +        bl = 9;         /* must be <= 9 for lookahead assumptions */
3320 +        bd = 6;         /* must be <= 9 for lookahead assumptions */
3321 +        t = s->sub.trees.table;
3322 +        t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
3323 +                                  s->sub.trees.blens, &bl, &bd, &tl, &td, z);
3324 +        if (t != Z_OK)
3325 +        {
3326 +          if (t == (uInt)Z_DATA_ERROR)
3327 +            s->mode = BADB;
3328 +          r = t;
3329 +          LEAVE
3330 +        }
3331 +        Tracev((stderr, "inflate:       trees ok\n"));
3332 +        if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
3333 +        {
3334 +          inflate_trees_free(td, z);
3335 +          inflate_trees_free(tl, z);
3336 +          r = Z_MEM_ERROR;
3337 +          LEAVE
3338 +        }
3339 +        ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
3340 +        s->sub.decode.codes = c;
3341 +        s->sub.decode.tl = tl;
3342 +        s->sub.decode.td = td;
3343 +      }
3344 +      s->mode = CODES;
3345 +    case CODES:
3346 +      UPDATE
3347 +      if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
3348 +        return inflate_flush(s, z, r);
3349 +      r = Z_OK;
3350 +      inflate_codes_free(s->sub.decode.codes, z);
3351 +      inflate_trees_free(s->sub.decode.td, z);
3352 +      inflate_trees_free(s->sub.decode.tl, z);
3353 +      LOAD
3354 +      Tracev((stderr, "inflate:       codes end, %lu total out\n",
3355 +              z->total_out + (q >= s->read ? q - s->read :
3356 +              (s->end - s->read) + (q - s->window))));
3357 +      if (!s->last)
3358 +      {
3359 +        s->mode = TYPE;
3360 +        break;
3361 +      }
3362 +      if (k > 7)              /* return unused byte, if any */
3363 +      {
3364 +        Assert(k < 16, "inflate_codes grabbed too many bytes")
3365 +        k -= 8;
3366 +        n++;
3367 +        p--;                    /* can always return one */
3368 +      }
3369 +      s->mode = DRY;
3370 +    case DRY:
3371 +      FLUSH
3372 +      if (s->read != s->write)
3373 +        LEAVE
3374 +      s->mode = DONEB;
3375 +    case DONEB:
3376 +      r = Z_STREAM_END;
3377 +      LEAVE
3378 +    case BADB:
3379 +      r = Z_DATA_ERROR;
3380 +      LEAVE
3381 +    default:
3382 +      r = Z_STREAM_ERROR;
3383 +      LEAVE
3384 +  }
3385 +}
3386 +
3387 +
3388 +local int inflate_blocks_free(s, z, c)
3389 +inflate_blocks_statef *s;
3390 +z_stream *z;
3391 +uLongf *c;
3392 +{
3393 +  inflate_blocks_reset(s, z, c);
3394 +  ZFREE(z, s->window, s->end - s->window);
3395 +  ZFREE(z, s, sizeof(struct inflate_blocks_state));
3396 +  Trace((stderr, "inflate:   blocks freed\n"));
3397 +  return Z_OK;
3398 +}
3399 +
3400 +/*
3401 + * This subroutine adds the data at next_in/avail_in to the output history
3402 + * without performing any output.  The output buffer must be "caught up";
3403 + * i.e. no pending output (hence s->read equals s->write), and the state must
3404 + * be BLOCKS (i.e. we should be willing to see the start of a series of
3405 + * BLOCKS).  On exit, the output will also be caught up, and the checksum
3406 + * will have been updated if need be.
3407 + */
3408 +local int inflate_addhistory(s, z)
3409 +inflate_blocks_statef *s;
3410 +z_stream *z;
3411 +{
3412 +    uLong b;              /* bit buffer */  /* NOT USED HERE */
3413 +    uInt k;               /* bits in bit buffer */ /* NOT USED HERE */
3414 +    uInt t;               /* temporary storage */
3415 +    Bytef *p;             /* input data pointer */
3416 +    uInt n;               /* bytes available there */
3417 +    Bytef *q;             /* output window write pointer */
3418 +    uInt m;               /* bytes to end of window or read pointer */
3419 +
3420 +    if (s->read != s->write)
3421 +       return Z_STREAM_ERROR;
3422 +    if (s->mode != TYPE)
3423 +       return Z_DATA_ERROR;
3424 +
3425 +    /* we're ready to rock */
3426 +    LOAD
3427 +    /* while there is input ready, copy to output buffer, moving
3428 +     * pointers as needed.
3429 +     */
3430 +    while (n) {
3431 +       t = n;  /* how many to do */
3432 +       /* is there room until end of buffer? */
3433 +       if (t > m) t = m;
3434 +       /* update check information */
3435 +       if (s->checkfn != Z_NULL)
3436 +           s->check = (*s->checkfn)(s->check, q, t);
3437 +       zmemcpy(q, p, t);
3438 +       q += t;
3439 +       p += t;
3440 +       n -= t;
3441 +       z->total_out += t;
3442 +       s->read = q;    /* drag read pointer forward */
3443 +/*      WRAP  */       /* expand WRAP macro by hand to handle s->read */
3444 +       if (q == s->end) {
3445 +           s->read = q = s->window;
3446 +           m = WAVAIL;
3447 +       }
3448 +    }
3449 +    UPDATE
3450 +    return Z_OK;
3451 +}
3452 +
3453 +
3454 +/*
3455 + * At the end of a Deflate-compressed PPP packet, we expect to have seen
3456 + * a `stored' block type value but not the (zero) length bytes.
3457 + */
3458 +local int inflate_packet_flush(s)
3459 +    inflate_blocks_statef *s;
3460 +{
3461 +    if (s->mode != LENS)
3462 +       return Z_DATA_ERROR;
3463 +    s->mode = TYPE;
3464 +    return Z_OK;
3465 +}
3466 +
3467 +
3468 +/*+++++*/
3469 +/* inftrees.c -- generate Huffman trees for efficient decoding
3470 + * Copyright (C) 1995 Mark Adler
3471 + * For conditions of distribution and use, see copyright notice in zlib.h 
3472 + */
3473 +
3474 +/* simplify the use of the inflate_huft type with some defines */
3475 +#define base more.Base
3476 +#define next more.Next
3477 +#define exop word.what.Exop
3478 +#define bits word.what.Bits
3479 +
3480 +
3481 +local int huft_build OF((
3482 +    uIntf *,            /* code lengths in bits */
3483 +    uInt,               /* number of codes */
3484 +    uInt,               /* number of "simple" codes */
3485 +    uIntf *,            /* list of base values for non-simple codes */
3486 +    uIntf *,            /* list of extra bits for non-simple codes */
3487 +    inflate_huft * FAR*,/* result: starting table */
3488 +    uIntf *,            /* maximum lookup bits (returns actual) */
3489 +    z_stream *));       /* for zalloc function */
3490 +
3491 +local voidpf falloc OF((
3492 +    voidpf,             /* opaque pointer (not used) */
3493 +    uInt,               /* number of items */
3494 +    uInt));             /* size of item */
3495 +
3496 +local void ffree OF((
3497 +    voidpf q,           /* opaque pointer (not used) */
3498 +    voidpf p,           /* what to free (not used) */
3499 +    uInt n));          /* number of bytes (not used) */
3500 +
3501 +/* Tables for deflate from PKZIP's appnote.txt. */
3502 +local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
3503 +        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
3504 +        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
3505 +        /* actually lengths - 2; also see note #13 above about 258 */
3506 +local uInt cplext[] = { /* Extra bits for literal codes 257..285 */
3507 +        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3508 +        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */
3509 +local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */
3510 +        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
3511 +        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
3512 +        8193, 12289, 16385, 24577};
3513 +local uInt cpdext[] = { /* Extra bits for distance codes */
3514 +        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
3515 +        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
3516 +        12, 12, 13, 13};
3517 +
3518 +/*
3519 +   Huffman code decoding is performed using a multi-level table lookup.
3520 +   The fastest way to decode is to simply build a lookup table whose
3521 +   size is determined by the longest code.  However, the time it takes
3522 +   to build this table can also be a factor if the data being decoded
3523 +   is not very long.  The most common codes are necessarily the
3524 +   shortest codes, so those codes dominate the decoding time, and hence
3525 +   the speed.  The idea is you can have a shorter table that decodes the
3526 +   shorter, more probable codes, and then point to subsidiary tables for
3527 +   the longer codes.  The time it costs to decode the longer codes is
3528 +   then traded against the time it takes to make longer tables.
3529 +
3530 +   This results of this trade are in the variables lbits and dbits
3531 +   below.  lbits is the number of bits the first level table for literal/
3532 +   length codes can decode in one step, and dbits is the same thing for
3533 +   the distance codes.  Subsequent tables are also less than or equal to
3534 +   those sizes.  These values may be adjusted either when all of the
3535 +   codes are shorter than that, in which case the longest code length in
3536 +   bits is used, or when the shortest code is *longer* than the requested
3537 +   table size, in which case the length of the shortest code in bits is
3538 +   used.
3539 +
3540 +   There are two different values for the two tables, since they code a
3541 +   different number of possibilities each.  The literal/length table
3542 +   codes 286 possible values, or in a flat code, a little over eight
3543 +   bits.  The distance table codes 30 possible values, or a little less
3544 +   than five bits, flat.  The optimum values for speed end up being
3545 +   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
3546 +   The optimum values may differ though from machine to machine, and
3547 +   possibly even between compilers.  Your mileage may vary.
3548 + */
3549 +
3550 +
3551 +/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
3552 +#define BMAX 15         /* maximum bit length of any code */
3553 +#define N_MAX 288       /* maximum number of codes in any set */
3554 +
3555 +#ifdef DEBUG_ZLIB
3556 +  uInt inflate_hufts;
3557 +#endif
3558 +
3559 +local int huft_build(b, n, s, d, e, t, m, zs)
3560 +uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
3561 +uInt n;                 /* number of codes (assumed <= N_MAX) */
3562 +uInt s;                 /* number of simple-valued codes (0..s-1) */
3563 +uIntf *d;               /* list of base values for non-simple codes */
3564 +uIntf *e;               /* list of extra bits for non-simple codes */  
3565 +inflate_huft * FAR *t;  /* result: starting table */
3566 +uIntf *m;               /* maximum lookup bits, returns actual */
3567 +z_stream *zs;           /* for zalloc function */
3568 +/* Given a list of code lengths and a maximum table size, make a set of
3569 +   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
3570 +   if the given code set is incomplete (the tables are still built in this
3571 +   case), Z_DATA_ERROR if the input is invalid (all zero length codes or an
3572 +   over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */
3573 +{
3574 +
3575 +  uInt a;                       /* counter for codes of length k */
3576 +  uInt c[BMAX+1];               /* bit length count table */
3577 +  uInt f;                       /* i repeats in table every f entries */
3578 +  int g;                        /* maximum code length */
3579 +  int h;                        /* table level */
3580 +  register uInt i;              /* counter, current code */
3581 +  register uInt j;              /* counter */
3582 +  register int k;               /* number of bits in current code */
3583 +  int l;                        /* bits per table (returned in m) */
3584 +  register uIntf *p;            /* pointer into c[], b[], or v[] */
3585 +  inflate_huft *q;              /* points to current table */
3586 +  struct inflate_huft_s r;      /* table entry for structure assignment */
3587 +  inflate_huft *u[BMAX];        /* table stack */
3588 +  uInt v[N_MAX];                /* values in order of bit length */
3589 +  register int w;               /* bits before this table == (l * h) */
3590 +  uInt x[BMAX+1];               /* bit offsets, then code stack */
3591 +  uIntf *xp;                    /* pointer into x */
3592 +  int y;                        /* number of dummy codes added */
3593 +  uInt z;                       /* number of entries in current table */
3594 +
3595 +
3596 +  /* Generate counts for each bit length */
3597 +  p = c;
3598 +#define C0 *p++ = 0;
3599 +#define C2 C0 C0 C0 C0
3600 +#define C4 C2 C2 C2 C2
3601 +  C4                            /* clear c[]--assume BMAX+1 is 16 */
3602 +  p = b;  i = n;
3603 +  do {
3604 +    c[*p++]++;                  /* assume all entries <= BMAX */
3605 +  } while (--i);
3606 +  if (c[0] == n)                /* null input--all zero length codes */
3607 +  {
3608 +    *t = (inflate_huft *)Z_NULL;
3609 +    *m = 0;
3610 +    return Z_OK;
3611 +  }
3612 +
3613 +
3614 +  /* Find minimum and maximum length, bound *m by those */
3615 +  l = *m;
3616 +  for (j = 1; j <= BMAX; j++)
3617 +    if (c[j])
3618 +      break;
3619 +  k = j;                        /* minimum code length */
3620 +  if ((uInt)l < j)
3621 +    l = j;
3622 +  for (i = BMAX; i; i--)
3623 +    if (c[i])
3624 +      break;
3625 +  g = i;                        /* maximum code length */
3626 +  if ((uInt)l > i)
3627 +    l = i;
3628 +  *m = l;
3629 +
3630 +
3631 +  /* Adjust last length count to fill out codes, if needed */
3632 +  for (y = 1 << j; j < i; j++, y <<= 1)
3633 +    if ((y -= c[j]) < 0)
3634 +      return Z_DATA_ERROR;
3635 +  if ((y -= c[i]) < 0)
3636 +    return Z_DATA_ERROR;
3637 +  c[i] += y;
3638 +
3639 +
3640 +  /* Generate starting offsets into the value table for each length */
3641 +  x[1] = j = 0;
3642 +  p = c + 1;  xp = x + 2;
3643 +  while (--i) {                 /* note that i == g from above */
3644 +    *xp++ = (j += *p++);
3645 +  }
3646 +
3647 +
3648 +  /* Make a table of values in order of bit lengths */
3649 +  p = b;  i = 0;
3650 +  do {
3651 +    if ((j = *p++) != 0)
3652 +      v[x[j]++] = i;
3653 +  } while (++i < n);
3654 +
3655 +
3656 +  /* Generate the Huffman codes and for each, make the table entries */
3657 +  x[0] = i = 0;                 /* first Huffman code is zero */
3658 +  p = v;                        /* grab values in bit order */
3659 +  h = -1;                       /* no tables yet--level -1 */
3660 +  w = -l;                       /* bits decoded == (l * h) */
3661 +  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
3662 +  q = (inflate_huft *)Z_NULL;   /* ditto */
3663 +  z = 0;                        /* ditto */
3664 +
3665 +  /* go through the bit lengths (k already is bits in shortest code) */
3666 +  for (; k <= g; k++)
3667 +  {
3668 +    a = c[k];
3669 +    while (a--)
3670 +    {
3671 +      /* here i is the Huffman code of length k bits for value *p */
3672 +      /* make tables up to required level */
3673 +      while (k > w + l)
3674 +      {
3675 +        h++;
3676 +        w += l;                 /* previous table always l bits */
3677 +
3678 +        /* compute minimum size table less than or equal to l bits */
3679 +        z = (z = g - w) > (uInt)l ? l : z;      /* table size upper limit */
3680 +        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
3681 +        {                       /* too few codes for k-w bit table */
3682 +          f -= a + 1;           /* deduct codes from patterns left */
3683 +          xp = c + k;
3684 +          if (j < z)
3685 +            while (++j < z)     /* try smaller tables up to z bits */
3686 +            {
3687 +              if ((f <<= 1) <= *++xp)
3688 +                break;          /* enough codes to use up j bits */
3689 +              f -= *xp;         /* else deduct codes from patterns */
3690 +            }
3691 +        }
3692 +        z = 1 << j;             /* table entries for j-bit table */
3693 +
3694 +        /* allocate and link in new table */
3695 +        if ((q = (inflate_huft *)ZALLOC
3696 +             (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
3697 +        {
3698 +          if (h)
3699 +            inflate_trees_free(u[0], zs);
3700 +          return Z_MEM_ERROR;   /* not enough memory */
3701 +        }
3702 +       q->word.Nalloc = z + 1;
3703 +#ifdef DEBUG_ZLIB
3704 +        inflate_hufts += z + 1;
3705 +#endif
3706 +        *t = q + 1;             /* link to list for huft_free() */
3707 +        *(t = &(q->next)) = Z_NULL;
3708 +        u[h] = ++q;             /* table starts after link */
3709 +
3710 +        /* connect to last table, if there is one */
3711 +        if (h)
3712 +        {
3713 +          x[h] = i;             /* save pattern for backing up */
3714 +          r.bits = (Byte)l;     /* bits to dump before this table */
3715 +          r.exop = (Byte)j;     /* bits in this table */
3716 +          r.next = q;           /* pointer to this table */
3717 +          j = i >> (w - l);     /* (get around Turbo C bug) */
3718 +          u[h-1][j] = r;        /* connect to last table */
3719 +        }
3720 +      }
3721 +
3722 +      /* set up table entry in r */
3723 +      r.bits = (Byte)(k - w);
3724 +      if (p >= v + n)
3725 +        r.exop = 128 + 64;      /* out of values--invalid code */
3726 +      else if (*p < s)
3727 +      {
3728 +        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
3729 +        r.base = *p++;          /* simple code is just the value */
3730 +      }
3731 +      else
3732 +      {
3733 +        r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */
3734 +        r.base = d[*p++ - s];
3735 +      }
3736 +
3737 +      /* fill code-like entries with r */
3738 +      f = 1 << (k - w);
3739 +      for (j = i >> w; j < z; j += f)
3740 +        q[j] = r;
3741 +
3742 +      /* backwards increment the k-bit code i */
3743 +      for (j = 1 << (k - 1); i & j; j >>= 1)
3744 +        i ^= j;
3745 +      i ^= j;
3746 +
3747 +      /* backup over finished tables */
3748 +      while ((i & ((1 << w) - 1)) != x[h])
3749 +      {
3750 +        h--;                    /* don't need to update q */
3751 +        w -= l;
3752 +      }
3753 +    }
3754 +  }
3755 +
3756 +
3757 +  /* Return Z_BUF_ERROR if we were given an incomplete table */
3758 +  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
3759 +}
3760 +
3761 +
3762 +local int inflate_trees_bits(c, bb, tb, z)
3763 +uIntf *c;               /* 19 code lengths */
3764 +uIntf *bb;              /* bits tree desired/actual depth */
3765 +inflate_huft * FAR *tb; /* bits tree result */
3766 +z_stream *z;            /* for zfree function */
3767 +{
3768 +  int r;
3769 +
3770 +  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
3771 +  if (r == Z_DATA_ERROR)
3772 +    z->msg = "oversubscribed dynamic bit lengths tree";
3773 +  else if (r == Z_BUF_ERROR)
3774 +  {
3775 +    inflate_trees_free(*tb, z);
3776 +    z->msg = "incomplete dynamic bit lengths tree";
3777 +    r = Z_DATA_ERROR;
3778 +  }
3779 +  return r;
3780 +}
3781 +
3782 +
3783 +local int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
3784 +uInt nl;                /* number of literal/length codes */
3785 +uInt nd;                /* number of distance codes */
3786 +uIntf *c;               /* that many (total) code lengths */
3787 +uIntf *bl;              /* literal desired/actual bit depth */
3788 +uIntf *bd;              /* distance desired/actual bit depth */
3789 +inflate_huft * FAR *tl; /* literal/length tree result */
3790 +inflate_huft * FAR *td; /* distance tree result */
3791 +z_stream *z;            /* for zfree function */
3792 +{
3793 +  int r;
3794 +
3795 +  /* build literal/length tree */
3796 +  if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK)
3797 +  {
3798 +    if (r == Z_DATA_ERROR)
3799 +      z->msg = "oversubscribed literal/length tree";
3800 +    else if (r == Z_BUF_ERROR)
3801 +    {
3802 +      inflate_trees_free(*tl, z);
3803 +      z->msg = "incomplete literal/length tree";
3804 +      r = Z_DATA_ERROR;
3805 +    }
3806 +    return r;
3807 +  }
3808 +
3809 +  /* build distance tree */
3810 +  if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK)
3811 +  {
3812 +    if (r == Z_DATA_ERROR)
3813 +      z->msg = "oversubscribed literal/length tree";
3814 +    else if (r == Z_BUF_ERROR) {
3815 +#ifdef PKZIP_BUG_WORKAROUND
3816 +      r = Z_OK;
3817 +    }
3818 +#else
3819 +      inflate_trees_free(*td, z);
3820 +      z->msg = "incomplete literal/length tree";
3821 +      r = Z_DATA_ERROR;
3822 +    }
3823 +    inflate_trees_free(*tl, z);
3824 +    return r;
3825 +#endif
3826 +  }
3827 +
3828 +  /* done */
3829 +  return Z_OK;
3830 +}
3831 +
3832 +
3833 +/* build fixed tables only once--keep them here */
3834 +local int fixed_lock = 0;
3835 +local int fixed_built = 0;
3836 +#define FIXEDH 530      /* number of hufts used by fixed tables */
3837 +local uInt fixed_left = FIXEDH;
3838 +local inflate_huft fixed_mem[FIXEDH];
3839 +local uInt fixed_bl;
3840 +local uInt fixed_bd;
3841 +local inflate_huft *fixed_tl;
3842 +local inflate_huft *fixed_td;
3843 +
3844 +
3845 +local voidpf falloc(q, n, s)
3846 +voidpf q;        /* opaque pointer (not used) */
3847 +uInt n;         /* number of items */
3848 +uInt s;         /* size of item */
3849 +{
3850 +  Assert(s == sizeof(inflate_huft) && n <= fixed_left,
3851 +         "inflate_trees falloc overflow");
3852 +  if (q) s++; /* to make some compilers happy */
3853 +  fixed_left -= n;
3854 +  return (voidpf)(fixed_mem + fixed_left);
3855 +}
3856 +
3857 +
3858 +local void ffree(q, p, n)
3859 +voidpf q;
3860 +voidpf p;
3861 +uInt n;
3862 +{
3863 +  Assert(0, "inflate_trees ffree called!");
3864 +  if (q) q = p; /* to make some compilers happy */
3865 +}
3866 +
3867 +
3868 +local int inflate_trees_fixed(bl, bd, tl, td)
3869 +uIntf *bl;               /* literal desired/actual bit depth */
3870 +uIntf *bd;               /* distance desired/actual bit depth */
3871 +inflate_huft * FAR *tl;  /* literal/length tree result */
3872 +inflate_huft * FAR *td;  /* distance tree result */
3873 +{
3874 +  /* build fixed tables if not built already--lock out other instances */
3875 +  while (++fixed_lock > 1)
3876 +    fixed_lock--;
3877 +  if (!fixed_built)
3878 +  {
3879 +    int k;              /* temporary variable */
3880 +    unsigned c[288];    /* length list for huft_build */
3881 +    z_stream z;         /* for falloc function */
3882 +
3883 +    /* set up fake z_stream for memory routines */
3884 +    z.zalloc = falloc;
3885 +    z.zfree = ffree;
3886 +    z.opaque = Z_NULL;
3887 +
3888 +    /* literal table */
3889 +    for (k = 0; k < 144; k++)
3890 +      c[k] = 8;
3891 +    for (; k < 256; k++)
3892 +      c[k] = 9;
3893 +    for (; k < 280; k++)
3894 +      c[k] = 7;
3895 +    for (; k < 288; k++)
3896 +      c[k] = 8;
3897 +    fixed_bl = 7;
3898 +    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
3899 +
3900 +    /* distance table */
3901 +    for (k = 0; k < 30; k++)
3902 +      c[k] = 5;
3903 +    fixed_bd = 5;
3904 +    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
3905 +
3906 +    /* done */
3907 +    fixed_built = 1;
3908 +  }
3909 +  fixed_lock--;
3910 +  *bl = fixed_bl;
3911 +  *bd = fixed_bd;
3912 +  *tl = fixed_tl;
3913 +  *td = fixed_td;
3914 +  return Z_OK;
3915 +}
3916 +
3917 +
3918 +local int inflate_trees_free(t, z)
3919 +inflate_huft *t;        /* table to free */
3920 +z_stream *z;            /* for zfree function */
3921 +/* Free the malloc'ed tables built by huft_build(), which makes a linked
3922 +   list of the tables it made, with the links in a dummy first entry of
3923 +   each table. */
3924 +{
3925 +  register inflate_huft *p, *q;
3926 +
3927 +  /* Go through linked list, freeing from the malloced (t[-1]) address. */
3928 +  p = t;
3929 +  while (p != Z_NULL)
3930 +  {
3931 +    q = (--p)->next;
3932 +    ZFREE(z, p, p->word.Nalloc * sizeof(inflate_huft));
3933 +    p = q;
3934 +  } 
3935 +  return Z_OK;
3936 +}
3937 +
3938 +/*+++++*/
3939 +/* infcodes.c -- process literals and length/distance pairs
3940 + * Copyright (C) 1995 Mark Adler
3941 + * For conditions of distribution and use, see copyright notice in zlib.h 
3942 + */
3943 +
3944 +/* simplify the use of the inflate_huft type with some defines */
3945 +#define base more.Base
3946 +#define next more.Next
3947 +#define exop word.what.Exop
3948 +#define bits word.what.Bits
3949 +
3950 +/* inflate codes private state */
3951 +struct inflate_codes_state {
3952 +
3953 +  /* mode */
3954 +  enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
3955 +      START,    /* x: set up for LEN */
3956 +      LEN,      /* i: get length/literal/eob next */
3957 +      LENEXT,   /* i: getting length extra (have base) */
3958 +      DIST,     /* i: get distance next */
3959 +      DISTEXT,  /* i: getting distance extra */
3960 +      COPY,     /* o: copying bytes in window, waiting for space */
3961 +      LIT,      /* o: got literal, waiting for output space */
3962 +      WASH,     /* o: got eob, possibly still output waiting */
3963 +      END,      /* x: got eob and all data flushed */
3964 +      BADCODE}  /* x: got error */
3965 +    mode;               /* current inflate_codes mode */
3966 +
3967 +  /* mode dependent information */
3968 +  uInt len;
3969 +  union {
3970 +    struct {
3971 +      inflate_huft *tree;       /* pointer into tree */
3972 +      uInt need;                /* bits needed */
3973 +    } code;             /* if LEN or DIST, where in tree */
3974 +    uInt lit;           /* if LIT, literal */
3975 +    struct {
3976 +      uInt get;                 /* bits to get for extra */
3977 +      uInt dist;                /* distance back to copy from */
3978 +    } copy;             /* if EXT or COPY, where and how much */
3979 +  } sub;                /* submode */
3980 +
3981 +  /* mode independent information */
3982 +  Byte lbits;           /* ltree bits decoded per branch */
3983 +  Byte dbits;           /* dtree bits decoder per branch */
3984 +  inflate_huft *ltree;          /* literal/length/eob tree */
3985 +  inflate_huft *dtree;          /* distance tree */
3986 +
3987 +};
3988 +
3989 +
3990 +local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
3991 +uInt bl, bd;
3992 +inflate_huft *tl, *td;
3993 +z_stream *z;
3994 +{
3995 +  inflate_codes_statef *c;
3996 +
3997 +  if ((c = (inflate_codes_statef *)
3998 +       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
3999 +  {
4000 +    c->mode = START;
4001 +    c->lbits = (Byte)bl;
4002 +    c->dbits = (Byte)bd;
4003 +    c->ltree = tl;
4004 +    c->dtree = td;
4005 +    Tracev((stderr, "inflate:       codes new\n"));
4006 +  }
4007 +  return c;
4008 +}
4009 +
4010 +
4011 +local int inflate_codes(s, z, r)
4012 +inflate_blocks_statef *s;
4013 +z_stream *z;
4014 +int r;
4015 +{
4016 +  uInt j;               /* temporary storage */
4017 +  inflate_huft *t;      /* temporary pointer */
4018 +  uInt e;               /* extra bits or operation */
4019 +  uLong b;              /* bit buffer */
4020 +  uInt k;               /* bits in bit buffer */
4021 +  Bytef *p;             /* input data pointer */
4022 +  uInt n;               /* bytes available there */
4023 +  Bytef *q;             /* output window write pointer */
4024 +  uInt m;               /* bytes to end of window or read pointer */
4025 +  Bytef *f;             /* pointer to copy strings from */
4026 +  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */
4027 +
4028 +  /* copy input/output information to locals (UPDATE macro restores) */
4029 +  LOAD
4030 +
4031 +  /* process input and output based on current state */
4032 +  while (1) switch (c->mode)
4033 +  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
4034 +    case START:         /* x: set up for LEN */
4035 +#ifndef SLOW
4036 +      if (m >= 258 && n >= 10)
4037 +      {
4038 +        UPDATE
4039 +        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
4040 +        LOAD
4041 +        if (r != Z_OK)
4042 +        {
4043 +          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
4044 +          break;
4045 +        }
4046 +      }
4047 +#endif /* !SLOW */
4048 +      c->sub.code.need = c->lbits;
4049 +      c->sub.code.tree = c->ltree;
4050 +      c->mode = LEN;
4051 +    case LEN:           /* i: get length/literal/eob next */
4052 +      j = c->sub.code.need;
4053 +      NEEDBITS(j)
4054 +      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4055 +      DUMPBITS(t->bits)
4056 +      e = (uInt)(t->exop);
4057 +      if (e == 0)               /* literal */
4058 +      {
4059 +        c->sub.lit = t->base;
4060 +        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4061 +                 "inflate:         literal '%c'\n" :
4062 +                 "inflate:         literal 0x%02x\n", t->base));
4063 +        c->mode = LIT;
4064 +        break;
4065 +      }
4066 +      if (e & 16)               /* length */
4067 +      {
4068 +        c->sub.copy.get = e & 15;
4069 +        c->len = t->base;
4070 +        c->mode = LENEXT;
4071 +        break;
4072 +      }
4073 +      if ((e & 64) == 0)        /* next table */
4074 +      {
4075 +        c->sub.code.need = e;
4076 +        c->sub.code.tree = t->next;
4077 +        break;
4078 +      }
4079 +      if (e & 32)               /* end of block */
4080 +      {
4081 +        Tracevv((stderr, "inflate:         end of block\n"));
4082 +        c->mode = WASH;
4083 +        break;
4084 +      }
4085 +      c->mode = BADCODE;        /* invalid code */
4086 +      z->msg = "invalid literal/length code";
4087 +      r = Z_DATA_ERROR;
4088 +      LEAVE
4089 +    case LENEXT:        /* i: getting length extra (have base) */
4090 +      j = c->sub.copy.get;
4091 +      NEEDBITS(j)
4092 +      c->len += (uInt)b & inflate_mask[j];
4093 +      DUMPBITS(j)
4094 +      c->sub.code.need = c->dbits;
4095 +      c->sub.code.tree = c->dtree;
4096 +      Tracevv((stderr, "inflate:         length %u\n", c->len));
4097 +      c->mode = DIST;
4098 +    case DIST:          /* i: get distance next */
4099 +      j = c->sub.code.need;
4100 +      NEEDBITS(j)
4101 +      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4102 +      DUMPBITS(t->bits)
4103 +      e = (uInt)(t->exop);
4104 +      if (e & 16)               /* distance */
4105 +      {
4106 +        c->sub.copy.get = e & 15;
4107 +        c->sub.copy.dist = t->base;
4108 +        c->mode = DISTEXT;
4109 +        break;
4110 +      }
4111 +      if ((e & 64) == 0)        /* next table */
4112 +      {
4113 +        c->sub.code.need = e;
4114 +        c->sub.code.tree = t->next;
4115 +        break;
4116 +      }
4117 +      c->mode = BADCODE;        /* invalid code */
4118 +      z->msg = "invalid distance code";
4119 +      r = Z_DATA_ERROR;
4120 +      LEAVE
4121 +    case DISTEXT:       /* i: getting distance extra */
4122 +      j = c->sub.copy.get;
4123 +      NEEDBITS(j)
4124 +      c->sub.copy.dist += (uInt)b & inflate_mask[j];
4125 +      DUMPBITS(j)
4126 +      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
4127 +      c->mode = COPY;
4128 +    case COPY:          /* o: copying bytes in window, waiting for space */
4129 +#ifndef __TURBOC__ /* Turbo C bug for following expression */
4130 +      f = (uInt)(q - s->window) < c->sub.copy.dist ?
4131 +          s->end - (c->sub.copy.dist - (q - s->window)) :
4132 +          q - c->sub.copy.dist;
4133 +#else
4134 +      f = q - c->sub.copy.dist;
4135 +      if ((uInt)(q - s->window) < c->sub.copy.dist)
4136 +        f = s->end - (c->sub.copy.dist - (q - s->window));
4137 +#endif
4138 +      while (c->len)
4139 +      {
4140 +        NEEDOUT
4141 +        OUTBYTE(*f++)
4142 +        if (f == s->end)
4143 +          f = s->window;
4144 +        c->len--;
4145 +      }
4146 +      c->mode = START;
4147 +      break;
4148 +    case LIT:           /* o: got literal, waiting for output space */
4149 +      NEEDOUT
4150 +      OUTBYTE(c->sub.lit)
4151 +      c->mode = START;
4152 +      break;
4153 +    case WASH:          /* o: got eob, possibly more output */
4154 +      FLUSH
4155 +      if (s->read != s->write)
4156 +        LEAVE
4157 +      c->mode = END;
4158 +    case END:
4159 +      r = Z_STREAM_END;
4160 +      LEAVE
4161 +    case BADCODE:       /* x: got error */
4162 +      r = Z_DATA_ERROR;
4163 +      LEAVE
4164 +    default:
4165 +      r = Z_STREAM_ERROR;
4166 +      LEAVE
4167 +  }
4168 +}
4169 +
4170 +
4171 +local void inflate_codes_free(c, z)
4172 +inflate_codes_statef *c;
4173 +z_stream *z;
4174 +{
4175 +  ZFREE(z, c, sizeof(struct inflate_codes_state));
4176 +  Tracev((stderr, "inflate:       codes free\n"));
4177 +}
4178 +
4179 +/*+++++*/
4180 +/* inflate_util.c -- data and routines common to blocks and codes
4181 + * Copyright (C) 1995 Mark Adler
4182 + * For conditions of distribution and use, see copyright notice in zlib.h 
4183 + */
4184 +
4185 +/* copy as much as possible from the sliding window to the output area */
4186 +local int inflate_flush(s, z, r)
4187 +inflate_blocks_statef *s;
4188 +z_stream *z;
4189 +int r;
4190 +{
4191 +  uInt n;
4192 +  Bytef *p, *q;
4193 +
4194 +  /* local copies of source and destination pointers */
4195 +  p = z->next_out;
4196 +  q = s->read;
4197 +
4198 +  /* compute number of bytes to copy as far as end of window */
4199 +  n = (uInt)((q <= s->write ? s->write : s->end) - q);
4200 +  if (n > z->avail_out) n = z->avail_out;
4201 +  if (n && r == Z_BUF_ERROR) r = Z_OK;
4202 +
4203 +  /* update counters */
4204 +  z->avail_out -= n;
4205 +  z->total_out += n;
4206 +
4207 +  /* update check information */
4208 +  if (s->checkfn != Z_NULL)
4209 +    s->check = (*s->checkfn)(s->check, q, n);
4210 +
4211 +  /* copy as far as end of window */
4212 +  zmemcpy(p, q, n);
4213 +  p += n;
4214 +  q += n;
4215 +
4216 +  /* see if more to copy at beginning of window */
4217 +  if (q == s->end)
4218 +  {
4219 +    /* wrap pointers */
4220 +    q = s->window;
4221 +    if (s->write == s->end)
4222 +      s->write = s->window;
4223 +
4224 +    /* compute bytes to copy */
4225 +    n = (uInt)(s->write - q);
4226 +    if (n > z->avail_out) n = z->avail_out;
4227 +    if (n && r == Z_BUF_ERROR) r = Z_OK;
4228 +
4229 +    /* update counters */
4230 +    z->avail_out -= n;
4231 +    z->total_out += n;
4232 +
4233 +    /* update check information */
4234 +    if (s->checkfn != Z_NULL)
4235 +      s->check = (*s->checkfn)(s->check, q, n);
4236 +
4237 +    /* copy */
4238 +    zmemcpy(p, q, n);
4239 +    p += n;
4240 +    q += n;
4241 +  }
4242 +
4243 +  /* update pointers */
4244 +  z->next_out = p;
4245 +  s->read = q;
4246 +
4247 +  /* done */
4248 +  return r;
4249 +}
4250 +
4251 +
4252 +/*+++++*/
4253 +/* inffast.c -- process literals and length/distance pairs fast
4254 + * Copyright (C) 1995 Mark Adler
4255 + * For conditions of distribution and use, see copyright notice in zlib.h 
4256 + */
4257 +
4258 +/* simplify the use of the inflate_huft type with some defines */
4259 +#define base more.Base
4260 +#define next more.Next
4261 +#define exop word.what.Exop
4262 +#define bits word.what.Bits
4263 +
4264 +/* macros for bit input with no checking and for returning unused bytes */
4265 +#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
4266 +#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
4267 +
4268 +/* Called with number of bytes left to write in window at least 258
4269 +   (the maximum string length) and number of input bytes available
4270 +   at least ten.  The ten bytes are six bytes for the longest length/
4271 +   distance pair plus four bytes for overloading the bit buffer. */
4272 +
4273 +local int inflate_fast(bl, bd, tl, td, s, z)
4274 +uInt bl, bd;
4275 +inflate_huft *tl, *td;
4276 +inflate_blocks_statef *s;
4277 +z_stream *z;
4278 +{
4279 +  inflate_huft *t;      /* temporary pointer */
4280 +  uInt e;               /* extra bits or operation */
4281 +  uLong b;              /* bit buffer */
4282 +  uInt k;               /* bits in bit buffer */
4283 +  Bytef *p;             /* input data pointer */
4284 +  uInt n;               /* bytes available there */
4285 +  Bytef *q;             /* output window write pointer */
4286 +  uInt m;               /* bytes to end of window or read pointer */
4287 +  uInt ml;              /* mask for literal/length tree */
4288 +  uInt md;              /* mask for distance tree */
4289 +  uInt c;               /* bytes to copy */
4290 +  uInt d;               /* distance back to copy from */
4291 +  Bytef *r;             /* copy source pointer */
4292 +
4293 +  /* load input, output, bit values */
4294 +  LOAD
4295 +
4296 +  /* initialize masks */
4297 +  ml = inflate_mask[bl];
4298 +  md = inflate_mask[bd];
4299 +
4300 +  /* do until not enough input or output space for fast loop */
4301 +  do {                          /* assume called with m >= 258 && n >= 10 */
4302 +    /* get literal/length code */
4303 +    GRABBITS(20)                /* max bits for literal/length code */
4304 +    if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
4305 +    {
4306 +      DUMPBITS(t->bits)
4307 +      Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4308 +                "inflate:         * literal '%c'\n" :
4309 +                "inflate:         * literal 0x%02x\n", t->base));
4310 +      *q++ = (Byte)t->base;
4311 +      m--;
4312 +      continue;
4313 +    }
4314 +    do {
4315 +      DUMPBITS(t->bits)
4316 +      if (e & 16)
4317 +      {
4318 +        /* get extra bits for length */
4319 +        e &= 15;
4320 +        c = t->base + ((uInt)b & inflate_mask[e]);
4321 +        DUMPBITS(e)
4322 +        Tracevv((stderr, "inflate:         * length %u\n", c));
4323 +
4324 +        /* decode distance base of block to copy */
4325 +        GRABBITS(15);           /* max bits for distance code */
4326 +        e = (t = td + ((uInt)b & md))->exop;
4327 +        do {
4328 +          DUMPBITS(t->bits)
4329 +          if (e & 16)
4330 +          {
4331 +            /* get extra bits to add to distance base */
4332 +            e &= 15;
4333 +            GRABBITS(e)         /* get extra bits (up to 13) */
4334 +            d = t->base + ((uInt)b & inflate_mask[e]);
4335 +            DUMPBITS(e)
4336 +            Tracevv((stderr, "inflate:         * distance %u\n", d));
4337 +
4338 +            /* do the copy */
4339 +            m -= c;
4340 +            if ((uInt)(q - s->window) >= d)     /* offset before dest */
4341 +            {                                   /*  just copy */
4342 +              r = q - d;
4343 +              *q++ = *r++;  c--;        /* minimum count is three, */
4344 +              *q++ = *r++;  c--;        /*  so unroll loop a little */
4345 +            }
4346 +            else                        /* else offset after destination */
4347 +            {
4348 +              e = d - (q - s->window);  /* bytes from offset to end */
4349 +              r = s->end - e;           /* pointer to offset */
4350 +              if (c > e)                /* if source crosses, */
4351 +              {
4352 +                c -= e;                 /* copy to end of window */
4353 +                do {
4354 +                  *q++ = *r++;
4355 +                } while (--e);
4356 +                r = s->window;          /* copy rest from start of window */
4357 +              }
4358 +            }
4359 +            do {                        /* copy all or what's left */
4360 +              *q++ = *r++;
4361 +            } while (--c);
4362 +            break;
4363 +          }
4364 +          else if ((e & 64) == 0)
4365 +            e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
4366 +          else
4367 +          {
4368 +            z->msg = "invalid distance code";
4369 +            UNGRAB
4370 +            UPDATE
4371 +            return Z_DATA_ERROR;
4372 +          }
4373 +        } while (1);
4374 +        break;
4375 +      }
4376 +      if ((e & 64) == 0)
4377 +      {
4378 +        if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
4379 +        {
4380 +          DUMPBITS(t->bits)
4381 +          Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4382 +                    "inflate:         * literal '%c'\n" :
4383 +                    "inflate:         * literal 0x%02x\n", t->base));
4384 +          *q++ = (Byte)t->base;
4385 +          m--;
4386 +          break;
4387 +        }
4388 +      }
4389 +      else if (e & 32)
4390 +      {
4391 +        Tracevv((stderr, "inflate:         * end of block\n"));
4392 +        UNGRAB
4393 +        UPDATE
4394 +        return Z_STREAM_END;
4395 +      }
4396 +      else
4397 +      {
4398 +        z->msg = "invalid literal/length code";
4399 +        UNGRAB
4400 +        UPDATE
4401 +        return Z_DATA_ERROR;
4402 +      }
4403 +    } while (1);
4404 +  } while (m >= 258 && n >= 10);
4405 +
4406 +  /* not enough input or output--restore pointers and return */
4407 +  UNGRAB
4408 +  UPDATE
4409 +  return Z_OK;
4410 +}
4411 +
4412 +
4413 +/*+++++*/
4414 +/* zutil.c -- target dependent utility functions for the compression library
4415 + * Copyright (C) 1995 Jean-loup Gailly.
4416 + * For conditions of distribution and use, see copyright notice in zlib.h 
4417 + */
4418 +
4419 +/* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */
4420 +
4421 +char *zlib_version = ZLIB_VERSION;
4422 +
4423 +char *z_errmsg[] = {
4424 +"stream end",          /* Z_STREAM_END    1 */
4425 +"",                    /* Z_OK            0 */
4426 +"file error",          /* Z_ERRNO        (-1) */
4427 +"stream error",        /* Z_STREAM_ERROR (-2) */
4428 +"data error",          /* Z_DATA_ERROR   (-3) */
4429 +"insufficient memory", /* Z_MEM_ERROR    (-4) */
4430 +"buffer error",        /* Z_BUF_ERROR    (-5) */
4431 +""};
4432 +
4433 +
4434 +/*+++++*/
4435 +/* adler32.c -- compute the Adler-32 checksum of a data stream
4436 + * Copyright (C) 1995 Mark Adler
4437 + * For conditions of distribution and use, see copyright notice in zlib.h 
4438 + */
4439 +
4440 +/* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */
4441 +
4442 +#define BASE 65521L /* largest prime smaller than 65536 */
4443 +#define NMAX 5552
4444 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
4445 +
4446 +#define DO1(buf)  {s1 += *buf++; s2 += s1;}
4447 +#define DO2(buf)  DO1(buf); DO1(buf);
4448 +#define DO4(buf)  DO2(buf); DO2(buf);
4449 +#define DO8(buf)  DO4(buf); DO4(buf);
4450 +#define DO16(buf) DO8(buf); DO8(buf);
4451 +
4452 +/* ========================================================================= */
4453 +uLong adler32(adler, buf, len)
4454 +    uLong adler;
4455 +    Bytef *buf;
4456 +    uInt len;
4457 +{
4458 +    unsigned long s1 = adler & 0xffff;
4459 +    unsigned long s2 = (adler >> 16) & 0xffff;
4460 +    int k;
4461 +
4462 +    if (buf == Z_NULL) return 1L;
4463 +
4464 +    while (len > 0) {
4465 +        k = len < NMAX ? len : NMAX;
4466 +        len -= k;
4467 +        while (k >= 16) {
4468 +            DO16(buf);
4469 +            k -= 16;
4470 +        }
4471 +        if (k != 0) do {
4472 +            DO1(buf);
4473 +        } while (--k);
4474 +        s1 %= BASE;
4475 +        s2 %= BASE;
4476 +    }
4477 +    return (s2 << 16) | s1;
4478 +}
4479 diff -Naru linux/arch/mips/zboot/Makefile linux.spi/arch/mips/zboot/Makefile
4480 --- linux/arch/mips/zboot/Makefile      1969-12-31 19:00:00.000000000 -0500
4481 +++ linux.spi/arch/mips/zboot/Makefile  2004-05-11 23:19:24.000000000 -0400
4482 @@ -0,0 +1,84 @@
4483 +#
4484 +# arch/mips/zboot/Makefile
4485 +#
4486 +# This file is subject to the terms and conditions of the GNU General Public
4487 +# License.  See the file "COPYING" in the main directory of this archive
4488 +# for more details.
4489 +
4490 +# Adapted for MIPS Pete Popov, Dan Malek
4491 +#
4492 +# Copyright (C) 1994 by Linus Torvalds
4493 +# Adapted for PowerPC by Gary Thomas
4494 +# modified by Cort (cort@cs.nmt.edu)
4495 +#
4496 +
4497 +.c.s:
4498 +       $(CC) $(CFLAGS) -S -o $*.s $<
4499 +.s.o:
4500 +       $(AS) -o $*.o $<
4501 +.c.o:
4502 +       $(CC) $(CFLAGS) -c -o $*.o $<
4503 +.S.s:
4504 +       $(CPP) $(AFLAGS) -o $*.o $<
4505 +.S.o:
4506 +       $(CC) $(AFLAGS) -c -o $*.o $<
4507 +
4508 +GZIP_FLAGS = -v9f
4509 +
4510 +CFLAGS  += -D__BOOTER__ -I$(TOPDIR)/arch/$(ARCH)/zboot/include
4511 +AFLAGS += -D__BOOTER__
4512 +
4513 +BOOT_TARGETS = zImage zImage.initrd zImage.flash zImage.initrd.flash
4514 +
4515 +lib/zlib.a:
4516 +       $(MAKE) -C lib
4517 +
4518 +images/vmlinux.gz: $(TOPDIR)/vmlinux
4519 +       $(MAKE) -C images vmlinux.gz
4520 +
4521 +$(BOOT_TARGETS): lib/zlib.a images/vmlinux.gz
4522 +ifdef CONFIG_MIPS_PB1000
4523 +       $(MAKE) -C pb1xxx $@
4524 +endif
4525 +ifdef CONFIG_MIPS_PB1500
4526 +       $(MAKE) -C pb1xxx $@
4527 +endif
4528 +ifdef CONFIG_MIPS_PB1100
4529 +       $(MAKE) -C pb1xxx $@
4530 +endif
4531 +ifdef CONFIG_MIPS_PB1550
4532 +       $(MAKE) -C pb1xxx $@
4533 +endif
4534 +ifdef CONFIG_MIPS_DB1000
4535 +       $(MAKE) -C pb1xxx $@
4536 +endif
4537 +ifdef CONFIG_MIPS_DB1100
4538 +       $(MAKE) -C pb1xxx $@
4539 +endif
4540 +ifdef CONFIG_MIPS_DB1500
4541 +       $(MAKE) -C pb1xxx $@
4542 +endif
4543 +ifdef CONFIG_MIPS_BOSPORUS
4544 +       $(MAKE) -C pb1xxx $@
4545 +endif
4546 +ifdef CONFIG_MIPS_MIRAGE
4547 +       $(MAKE) -C pb1xxx $@
4548 +endif
4549 +ifdef CONFIG_MIPS_MTX1
4550 +       $(MAKE) -C pb1xxx $@
4551 +endif
4552 +ifdef CONFIG_COGENT_CSB250
4553 +       $(MAKE) -C csb250 $@
4554 +endif
4555 +ifdef CONFIG_MIPS_XXS1500
4556 +BOOT_DIR = xxs1500
4557 +endif
4558 +
4559 +# Do the dirs
4560 +clean:
4561 +       $(MAKE) -C common clean
4562 +       $(MAKE) -C images clean
4563 +       $(MAKE) -C pb1xxx clean
4564 +       $(MAKE) -C xxs1500 clean
4565 +
4566 +include $(TOPDIR)/Rules.make
4567 diff -Naru linux/arch/mips/zboot/pb1xxx/head.S linux.spi/arch/mips/zboot/pb1xxx/head.S
4568 --- linux/arch/mips/zboot/pb1xxx/head.S 1969-12-31 19:00:00.000000000 -0500
4569 +++ linux.spi/arch/mips/zboot/pb1xxx/head.S     2004-05-11 23:19:24.000000000 -0400
4570 @@ -0,0 +1,149 @@
4571 +/*
4572 + * arch/mips/kernel/head.S
4573 + *
4574 + * This file is subject to the terms and conditions of the GNU General Public
4575 + * License.  See the file "COPYING" in the main directory of this archive
4576 + * for more details.
4577 + *
4578 + * Copyright (C) 1994, 1995 Waldorf Electronics
4579 + * Written by Ralf Baechle and Andreas Busse
4580 + * Copyright (C) 1995 - 1999 Ralf Baechle
4581 + * Copyright (C) 1996 Paul M. Antoine
4582 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
4583 + * Further modifications by David S. Miller and Harald Koerfgen
4584 + * Copyright (C) 1999 Silicon Graphics, Inc.
4585 + *
4586 + * Head.S contains the MIPS exception handler and startup code.
4587 + *
4588 + **************************************************************************
4589 + *  9 Nov, 2000.
4590 + *  Added Cache Error exception handler and SBDDP EJTAG debug exception.
4591 + *
4592 + *  Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4593 + *  Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
4594 + **************************************************************************
4595 + */
4596 +#include <linux/config.h>
4597 +#include <linux/threads.h>
4598 +
4599 +#include <asm/asm.h>
4600 +#include <asm/cacheops.h>
4601 +#include <asm/mipsregs.h>
4602 +#include <asm/offset.h>
4603 +#include <asm/cachectl.h>
4604 +#include <asm/regdef.h>
4605 +
4606 +#define IndexInvalidate_I       0x00
4607 +#define IndexWriteBack_D        0x01
4608 +
4609 +       .set noreorder
4610 +       .cprestore
4611 +       LEAF(start)
4612 +start:
4613 +       bal     locate
4614 +       nop
4615 +locate:
4616 +       subu    s8, ra, 8       /* Where we were loaded */
4617 +       la      sp, (.stack + 8192)
4618 +
4619 +       move    s0, a0          /* Save boot rom start args */
4620 +       move    s1, a1
4621 +       move    s2, a2
4622 +       move    s3, a3
4623 +
4624 +       la      a0, start       /* Where we were linked to run */
4625 +
4626 +       move    a1, s8
4627 +       la      a2, _edata
4628 +       subu    t1, a2, a0
4629 +       srl     t1, t1, 2
4630 +
4631 +       /* copy text section */
4632 +       li      t0, 0
4633 +1:     lw      v0, 0(a1)
4634 +       nop
4635 +       sw      v0, 0(a0)
4636 +       xor     t0, t0, v0
4637 +       addu    a0, 4
4638 +       bne     a2, a0, 1b
4639 +       addu    a1, 4
4640 +
4641 +       /* Clear BSS */
4642 +       la      a0, _edata
4643 +       la      a2, _end
4644 +2:     sw      zero, 0(a0)
4645 +       bne     a2, a0, 2b
4646 +       addu    a0, 4
4647 +
4648 +       /* push the D-Cache and invalidate I-Cache */
4649 +       li      k0, 0x80000000  # start address
4650 +       li      k1, 0x80004000  # end address (16KB I-Cache)
4651 +       subu    k1, 128
4652 +
4653 +1:
4654 +       .set mips3
4655 +       cache   IndexWriteBack_D, 0(k0)
4656 +       cache   IndexWriteBack_D, 32(k0)
4657 +       cache   IndexWriteBack_D, 64(k0)
4658 +       cache   IndexWriteBack_D, 96(k0)
4659 +       cache   IndexInvalidate_I, 0(k0)
4660 +       cache   IndexInvalidate_I, 32(k0)
4661 +       cache   IndexInvalidate_I, 64(k0)
4662 +       cache   IndexInvalidate_I, 96(k0)
4663 +       .set mips0
4664 +
4665 +       bne     k0, k1, 1b
4666 +       addu    k0, k0, 128
4667 +       /* done */
4668 +
4669 +       move    a0, s8               /* load address */
4670 +       move    a1, t1               /* length in words */
4671 +       move    a2, t0               /* checksum */
4672 +       move    a3, sp
4673 +
4674 +       la      ra, 1f
4675 +       la      k0, decompress_kernel
4676 +       jr      k0
4677 +       nop
4678 +1:
4679 +
4680 +       move    a0, s0
4681 +       move    a1, s1
4682 +       move    a2, s2
4683 +       move    a3, s3
4684 +       li      k0, KERNEL_ENTRY
4685 +       jr      k0
4686 +       nop
4687 +3:
4688 +       b 3b
4689 +       END(start)
4690 +
4691 +       LEAF(udelay)
4692 +udelay:
4693 +       END(udelay)
4694 +
4695 +
4696 +       LEAF(FlushCache)
4697 +       li      k0, 0x80000000  # start address
4698 +       li      k1, 0x80004000  # end address (16KB I-Cache)
4699 +       subu    k1, 128
4700 +
4701 +1:
4702 +       .set mips3
4703 +       cache   IndexWriteBack_D, 0(k0)
4704 +       cache   IndexWriteBack_D, 32(k0)
4705 +       cache   IndexWriteBack_D, 64(k0)
4706 +       cache   IndexWriteBack_D, 96(k0)
4707 +       cache   IndexInvalidate_I, 0(k0)
4708 +       cache   IndexInvalidate_I, 32(k0)
4709 +       cache   IndexInvalidate_I, 64(k0)
4710 +       cache   IndexInvalidate_I, 96(k0)
4711 +       .set mips0
4712 +
4713 +       bne     k0, k1, 1b
4714 +       addu    k0, k0, 128
4715 +       jr      ra
4716 +       nop
4717 +       END(FlushCache)
4718 +
4719 +       .comm .stack,4096*2,4
4720 diff -Naru linux/arch/mips/zboot/pb1xxx/Makefile linux.spi/arch/mips/zboot/pb1xxx/Makefile
4721 --- linux/arch/mips/zboot/pb1xxx/Makefile       1969-12-31 19:00:00.000000000 -0500
4722 +++ linux.spi/arch/mips/zboot/pb1xxx/Makefile   2004-05-11 23:19:24.000000000 -0400
4723 @@ -0,0 +1,135 @@
4724 +# arch/mips/zboot/pb1xxx/Makefile
4725 +# 
4726 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
4727 +# All of the boot loader code was derived from the ppc
4728 +# boot code.
4729 +#
4730 +# Copyright 2001,2002 MontaVista Software Inc.
4731 +#
4732 +# Author: Mark A. Greer
4733 +#        mgreer@mvista.com
4734 +# Ported and modified for mips support by 
4735 +# Pete Popov <ppopov@mvista.com>
4736 +#
4737 +# This program is free software; you can redistribute  it and/or modify it
4738 +# under  the terms of  the GNU General  Public License as published by the
4739 +# Free Software Foundation;  either version 2 of the  License, or (at your
4740 +# option) any later version.
4741 +
4742 +.c.s:
4743 +       $(CC) $(CFLAGS) -S -o $*.s $<
4744 +.s.o:
4745 +       $(AS) -o $*.o $<
4746 +.c.o:
4747 +       $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
4748 +.S.s:
4749 +       $(CPP) $(AFLAGS) -o $*.o $<
4750 +.S.o:
4751 +       $(CC) $(AFLAGS) -c -o $*.o $<
4752 +
4753 +#########################################################################
4754 +# START BOARD SPECIFIC VARIABLES
4755 +ifdef CONFIG_MIPS_PB1000
4756 +BNAME=pb1000
4757 +endif
4758 +
4759 +ifdef CONFIG_MIPS_PB1100
4760 +BNAME=pb1100
4761 +endif
4762 +
4763 +ifdef CONFIG_MIPS_PB1500
4764 +BNAME=pb1500
4765 +endif
4766 +
4767 +ifdef CONFIG_MIPS_PB1550
4768 +BNAME=pb1550
4769 +endif
4770 +
4771 +ifdef CONFIG_MIPS_DB1000
4772 +BNAME=db1000
4773 +endif
4774 +
4775 +ifdef CONFIG_MIPS_DB1100
4776 +BNAME=db1100
4777 +endif
4778 +
4779 +ifdef CONFIG_MIPS_DB1500
4780 +BNAME=db1500
4781 +endif
4782 +
4783 +ifdef CONFIG_MIPS_BOSPORUS
4784 +BNAME=bosporus
4785 +endif
4786 +
4787 +ifdef CONFIG_MIPS_MIRAGE
4788 +BNAME=mirage
4789 +endif
4790 +
4791 +ifdef CONFIG_MIPS_MTX1
4792 +BNAME=mtx-1
4793 +endif
4794 +
4795 +# These two variables control where the zImage is stored
4796 +# in flash and loaded in memory.  It only controls how the srec
4797 +# file is generated, the code is the same.
4798 +RAM_RUN_ADDR = 0x81000000
4799 +FLASH_LOAD_ADDR = 0xBFD00000
4800 +
4801 +# These two variables specify the free ram region
4802 +# that can be used for temporary malloc area
4803 +AVAIL_RAM_START=0x80400000
4804 +AVAIL_RAM_END=0x80800000
4805 +
4806 +# This one must match the LOADADDR in arch/mips/Makefile!
4807 +LOADADDR=0x80100000
4808 +# END BOARD SPECIFIC VARIABLES
4809 +#########################################################################
4810 +
4811 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
4812 +       ../common/au1k_uart.o ../common/string.o ../common/ctype.o
4813 +LIBS := ../lib/zlib.a
4814 +
4815 +ENTRY := ../utils/entry
4816 +OFFSET := ../utils/offset
4817 +SIZE := ../utils/size
4818 +
4819 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
4820 +OBJCOPY_ARGS = -O elf32-tradlittlemips
4821 +
4822 +all: zImage
4823 +
4824 +clean:
4825 +       rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
4826 +
4827 +head.o: head.S $(TOPDIR)/vmlinux
4828 +       $(CC) $(AFLAGS) \
4829 +       -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
4830 +       -c -o $*.o $<
4831 +
4832 +../common/misc-simple.o:
4833 +       $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
4834 +               -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
4835 +               -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
4836 +               -DLOADADDR=$(LOADADDR) \
4837 +               -DZIMAGE_SIZE=0 -c -o $@ $*.c
4838 +
4839 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
4840 +       $(OBJCOPY) \
4841 +               --add-section=.image=../images/vmlinux.gz \
4842 +               --set-section-flags=.image=contents,alloc,load,readonly,data \
4843 +               ../common/dummy.o image.o
4844 +       $(LD) $(LD_ARGS) -o $@ $(OBJECTS) image.o $(LIBS)
4845 +       $(OBJCOPY) $(OBJCOPY_ARGS) $@ $@ -R .comment -R .stab -R .stabstr \
4846 +               -R .initrd -R .sysmap
4847 +
4848 +# Here we manipulate the image in order to get it the necessary
4849 +# srecord file we need.
4850 +zImage: zvmlinux
4851 +       mv zvmlinux ../images/zImage.$(BNAME)
4852 +       $(OBJCOPY) -O srec ../images/zImage.$(BNAME) ../images/$(BNAME).srec
4853 +
4854 +zImage.flash: zImage
4855 +       $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
4856 +               ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
4857 +
4858 +include $(TOPDIR)/Rules.make
4859 diff -Naru linux/arch/mips/zboot/utils/entry linux.spi/arch/mips/zboot/utils/entry
4860 --- linux/arch/mips/zboot/utils/entry   1969-12-31 19:00:00.000000000 -0500
4861 +++ linux.spi/arch/mips/zboot/utils/entry       2004-05-11 23:19:24.000000000 -0400
4862 @@ -0,0 +1,12 @@
4863 +#!/bin/sh
4864 +
4865 +# grab the kernel_entry address from the vmlinux elf image
4866 +entry=`$1 $2  | grep kernel_entry`
4867 +
4868 +fs=`echo $entry | grep ffffffff`  # check toolchain output
4869 +
4870 +if [ -n "$fs" ]; then
4871 +       echo "0x"`$1 $2  | grep kernel_entry | cut -c9- | awk '{print $1}'`
4872 +else
4873 +       echo "0x"`$1 $2  | grep kernel_entry | cut -c1- | awk '{print $1}'`
4874 +fi
4875 diff -Naru linux/arch/mips/zboot/utils/offset linux.spi/arch/mips/zboot/utils/offset
4876 --- linux/arch/mips/zboot/utils/offset  1969-12-31 19:00:00.000000000 -0500
4877 +++ linux.spi/arch/mips/zboot/utils/offset      2004-05-11 23:19:24.000000000 -0400
4878 @@ -0,0 +1,3 @@
4879 +#!/bin/sh
4880 +
4881 +echo "0x"`$1 -h $2  | grep $3 | grep -v zvmlinux| awk '{print $6}'`
4882 diff -Naru linux/arch/mips/zboot/utils/size linux.spi/arch/mips/zboot/utils/size
4883 --- linux/arch/mips/zboot/utils/size    1969-12-31 19:00:00.000000000 -0500
4884 +++ linux.spi/arch/mips/zboot/utils/size        2004-05-11 23:19:24.000000000 -0400
4885 @@ -0,0 +1,4 @@
4886 +#!/bin/sh
4887 +
4888 +OFFSET=`$1 -h $2  | grep $3 | grep -v zvmlinux | awk '{print $3}'`
4889 +echo "0x"$OFFSET
4890 diff -Naru linux/arch/mips/zboot/xxs1500/head.S linux.spi/arch/mips/zboot/xxs1500/head.S
4891 --- linux/arch/mips/zboot/xxs1500/head.S        1969-12-31 19:00:00.000000000 -0500
4892 +++ linux.spi/arch/mips/zboot/xxs1500/head.S    2004-05-11 23:19:24.000000000 -0400
4893 @@ -0,0 +1,137 @@
4894 +/*
4895 + * arch/mips/kernel/head.S
4896 + *
4897 + * This file is subject to the terms and conditions of the GNU General Public
4898 + * License.  See the file "COPYING" in the main directory of this archive
4899 + * for more details.
4900 + *
4901 + * Copyright (C) 1994, 1995 Waldorf Electronics
4902 + * Written by Ralf Baechle and Andreas Busse
4903 + * Copyright (C) 1995 - 1999 Ralf Baechle
4904 + * Copyright (C) 1996 Paul M. Antoine
4905 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
4906 + * Further modifications by David S. Miller and Harald Koerfgen
4907 + * Copyright (C) 1999 Silicon Graphics, Inc.
4908 + *
4909 + * Head.S contains the MIPS exception handler and startup code.
4910 + *
4911 + **************************************************************************
4912 + *  9 Nov, 2000.
4913 + *  Added Cache Error exception handler and SBDDP EJTAG debug exception.
4914 + *
4915 + *  Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4916 + *  Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
4917 + **************************************************************************
4918 + */
4919 +#include <linux/config.h>
4920 +#include <linux/threads.h>
4921 +
4922 +#include <asm/asm.h>
4923 +#include <asm/cacheops.h>
4924 +#include <asm/mipsregs.h>
4925 +#include <asm/offset.h>
4926 +#include <asm/cachectl.h>
4927 +#include <asm/regdef.h>
4928 +
4929 +#define IndexInvalidate_I       0x00
4930 +
4931 +       .set noreorder
4932 +       .cprestore
4933 +       LEAF(start)
4934 +start:
4935 +
4936 +locate:
4937 +       la      sp, .stack
4938 +       move    s0, a0
4939 +       move    s1, a1
4940 +       move    s2, a2
4941 +       move    s3, a3
4942 +
4943 +       la      a0, start
4944 +
4945 +       li      a1, FLASH_LOAD_ADDR
4946 +       la      a2, _edata
4947 +       subu    t1, a2, a0
4948 +       srl     t1, t1, 2
4949 +
4950 +       /* copy text section */
4951 +       li      t0, 0
4952 +1:     lw      v0, 0(a1)
4953 +       nop
4954 +       sw      v0, 0(a0)
4955 +       xor     t0, t0, v0
4956 +       addu    a0, 4
4957 +       bne     a2, a0, 1b
4958 +       addu    a1, 4
4959 +
4960 +       /* Clear BSS */
4961 +       la      a0, _edata
4962 +       la      a2, _end
4963 +2:     sw      zero, 0(a0)
4964 +       bne     a2, a0, 2b
4965 +       addu    a0, 4
4966 +
4967 +       /* flush the I-Cache */
4968 +       li      k0, 0x80000000  # start address
4969 +       li      k1, 0x80004000  # end address (16KB I-Cache)
4970 +       subu    k1, 128
4971 +
4972 +1:
4973 +       .set mips3
4974 +       cache   IndexInvalidate_I, 0(k0)
4975 +       cache   IndexInvalidate_I, 32(k0)
4976 +       cache   IndexInvalidate_I, 64(k0)
4977 +       cache   IndexInvalidate_I, 96(k0)
4978 +       .set mips0
4979 +
4980 +       bne     k0, k1, 1b
4981 +       addu    k0, k0, 128
4982 +       /* done */
4983 +
4984 +       li      a0, FLASH_LOAD_ADDR  /* load address */
4985 +       move    a1, t1               /* length in words */
4986 +       move    a2, t0               /* checksum */
4987 +       move    a3, sp
4988 +
4989 +       la      ra, 1f
4990 +       la      k0, decompress_kernel
4991 +       jr      k0
4992 +       nop
4993 +1:
4994 +
4995 +       move    a0, s0
4996 +       move    a1, s1
4997 +       move    a2, s2
4998 +       move    a3, s3
4999 +       li      k0, KERNEL_ENTRY
5000 +       jr      k0
5001 +       nop
5002 +3:
5003 +       b 3b
5004 +       END(start)
5005 +
5006 +       LEAF(udelay)
5007 +udelay:
5008 +       END(udelay)
5009 +
5010 +
5011 +       LEAF(FlushCache)
5012 +       li      k0, 0x80000000  # start address
5013 +       li      k1, 0x80004000  # end address (16KB I-Cache)
5014 +       subu    k1, 128
5015 +
5016 +1:
5017 +       .set mips3
5018 +       cache   IndexInvalidate_I, 0(k0)
5019 +       cache   IndexInvalidate_I, 32(k0)
5020 +       cache   IndexInvalidate_I, 64(k0)
5021 +       cache   IndexInvalidate_I, 96(k0)
5022 +       .set mips0
5023 +
5024 +       bne     k0, k1, 1b
5025 +       addu    k0, k0, 128
5026 +       jr      ra
5027 +       nop
5028 +       END(FlushCache)
5029 +
5030 +       .comm .stack,4096*2,4
5031 diff -Naru linux/arch/mips/zboot/xxs1500/ld.script linux.spi/arch/mips/zboot/xxs1500/ld.script
5032 --- linux/arch/mips/zboot/xxs1500/ld.script     1969-12-31 19:00:00.000000000 -0500
5033 +++ linux.spi/arch/mips/zboot/xxs1500/ld.script 2004-05-11 23:19:24.000000000 -0400
5034 @@ -0,0 +1,147 @@
5035 +OUTPUT_ARCH(mips)
5036 +ENTRY(start)
5037 +SECTIONS
5038 +{
5039 +  /* Read-only sections, merged into text segment: */
5040 +  /* . = 0x81000000; */
5041 +  .init          : { *(.init)          } =0
5042 +  .text      :
5043 +  {
5044 +    _ftext = . ;
5045 +    *(.text)
5046 +    *(.rodata)
5047 +    *(.rodata1)
5048 +    /* .gnu.warning sections are handled specially by elf32.em.  */
5049 +    *(.gnu.warning)
5050 +  } =0
5051 +  .kstrtab : { *(.kstrtab) }
5052 +
5053 +  . = ALIGN(16);               /* Exception table */
5054 +  __start___ex_table = .;
5055 +  __ex_table : { *(__ex_table) }
5056 +  __stop___ex_table = .;
5057 +
5058 +  __start___dbe_table = .;     /* Exception table for data bus errors */
5059 +  __dbe_table : { *(__dbe_table) }
5060 +  __stop___dbe_table = .;
5061 +
5062 +  __start___ksymtab = .;       /* Kernel symbol table */
5063 +  __ksymtab : { *(__ksymtab) }
5064 +  __stop___ksymtab = .;
5065 +
5066 +  _etext = .;
5067 +
5068 +  . = ALIGN(8192);
5069 +  .data.init_task : { *(.data.init_task) }
5070 +
5071 +  /* Startup code */
5072 +  . = ALIGN(4096);
5073 +  __init_begin = .;
5074 +  .text.init : { *(.text.init) }
5075 +  .data.init : { *(.data.init) }
5076 +  . = ALIGN(16);
5077 +  __setup_start = .;
5078 +  .setup.init : { *(.setup.init) }
5079 +  __setup_end = .;
5080 +  __initcall_start = .;
5081 +  .initcall.init : { *(.initcall.init) }
5082 +  __initcall_end = .;
5083 +  . = ALIGN(4096);     /* Align double page for init_task_union */
5084 +  __init_end = .;
5085 +
5086 +  . = ALIGN(4096);
5087 +  .data.page_aligned : { *(.data.idt) }
5088 +
5089 +  . = ALIGN(32);
5090 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
5091 +
5092 +  .fini      : { *(.fini)    } =0
5093 +  .reginfo : { *(.reginfo) }
5094 +  /* Adjust the address for the data segment.  We want to adjust up to
5095 +     the same address within the page on the next page up.  It would
5096 +     be more correct to do this:
5097 +       . = .;
5098 +     The current expression does not correctly handle the case of a
5099 +     text segment ending precisely at the end of a page; it causes the
5100 +     data segment to skip a page.  The above expression does not have
5101 +     this problem, but it will currently (2/95) cause BFD to allocate
5102 +     a single segment, combining both text and data, for this case.
5103 +     This will prevent the text segment from being shared among
5104 +     multiple executions of the program; I think that is more
5105 +     important than losing a page of the virtual address space (note
5106 +     that no actual memory is lost; the page which is skipped can not
5107 +     be referenced).  */
5108 +  . = .;
5109 +  .data    :
5110 +  {
5111 +    _fdata = . ;
5112 +    *(.data)
5113 +
5114 +   /* Align the initial ramdisk image (INITRD) on page boundaries. */
5115 +   . = ALIGN(4096);
5116 +   __rd_start = .;
5117 +   *(.initrd)
5118 +   __rd_end = .;
5119 +   . = ALIGN(4096);
5120 +
5121 +    CONSTRUCTORS
5122 +  }
5123 +  .data1   : { *(.data1) }
5124 +  _gp = . + 0x8000;
5125 +  .lit8 : { *(.lit8) }
5126 +  .lit4 : { *(.lit4) }
5127 +  .ctors         : { *(.ctors)   }
5128 +  .dtors         : { *(.dtors)   }
5129 +  .got           : { *(.got.plt) *(.got) }
5130 +  .dynamic       : { *(.dynamic) }
5131 +  /* We want the small data sections together, so single-instruction offsets
5132 +     can access them all, and initialized data all before uninitialized, so
5133 +     we can shorten the on-disk segment size.  */
5134 +  .sdata     : { *(.sdata) }
5135 +  . = ALIGN(4);
5136 +  _edata  =  .;
5137 +  PROVIDE (edata = .);
5138 +
5139 +  __bss_start = .;
5140 +  _fbss = .;
5141 +  .sbss      : { *(.sbss) *(.scommon) }
5142 +  .bss       :
5143 +  {
5144 +   *(.dynbss)
5145 +   *(.bss)
5146 +   *(COMMON)
5147 +   .  = ALIGN(4);
5148 +  _end = . ;
5149 +  PROVIDE (end = .);
5150 +  }
5151 +
5152 +  /* Sections to be discarded */
5153 +  /DISCARD/ :
5154 +  {
5155 +        *(.text.exit)
5156 +        *(.data.exit)
5157 +        *(.exitcall.exit)
5158 +  }
5159 +
5160 +  /* This is the MIPS specific mdebug section.  */
5161 +  .mdebug : { *(.mdebug) }
5162 +  /* These are needed for ELF backends which have not yet been
5163 +     converted to the new style linker.  */
5164 +  .stab 0 : { *(.stab) }
5165 +  .stabstr 0 : { *(.stabstr) }
5166 +  /* DWARF debug sections.
5167 +     Symbols in the .debug DWARF section are relative to the beginning of the
5168 +     section so we begin .debug at 0.  It's not clear yet what needs to happen
5169 +     for the others.   */
5170 +  .debug          0 : { *(.debug) }
5171 +  .debug_srcinfo  0 : { *(.debug_srcinfo) }
5172 +  .debug_aranges  0 : { *(.debug_aranges) }
5173 +  .debug_pubnames 0 : { *(.debug_pubnames) }
5174 +  .debug_sfnames  0 : { *(.debug_sfnames) }
5175 +  .line           0 : { *(.line) }
5176 +  /* These must appear regardless of  .  */
5177 +  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
5178 +  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
5179 +  .comment : { *(.comment) }
5180 +  .note : { *(.note) }
5181 +}
5182 diff -Naru linux/arch/mips/zboot/xxs1500/Makefile linux.spi/arch/mips/zboot/xxs1500/Makefile
5183 --- linux/arch/mips/zboot/xxs1500/Makefile      1969-12-31 19:00:00.000000000 -0500
5184 +++ linux.spi/arch/mips/zboot/xxs1500/Makefile  2004-05-11 23:19:24.000000000 -0400
5185 @@ -0,0 +1,123 @@
5186 +# arch/mips/compressed/alchemy/Makefile
5187 +# 
5188 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
5189 +# All of the boot loader code was derived from the ppc
5190 +# boot code.
5191 +#
5192 +# Copyright 2001,2002 MontaVista Software Inc.
5193 +#
5194 +# Author: Mark A. Greer
5195 +#        mgreer@mvista.com
5196 +# Ported and modified for mips support by 
5197 +# Pete Popov <ppopov@mvista.com>
5198 +#
5199 +# This program is free software; you can redistribute  it and/or modify it
5200 +# under  the terms of  the GNU General  Public License as published by the
5201 +# Free Software Foundation;  either version 2 of the  License, or (at your
5202 +# option) any later version.
5203 +
5204 +.c.s:
5205 +       $(CC) $(CFLAGS) -S -o $*.s $<
5206 +.s.o:
5207 +       $(AS) -o $*.o $<
5208 +.c.o:
5209 +       $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
5210 +.S.s:
5211 +       $(CPP) $(AFLAGS) -o $*.o $<
5212 +.S.o:
5213 +       $(CC) $(AFLAGS) -c -o $*.o $<
5214 +
5215 +#########################################################################
5216 +# START BOARD SPECIFIC VARIABLES
5217 +BNAME=xxs1500
5218 +
5219 +
5220 +# These two variables control where the zImage is stored
5221 +# in flash and loaded in memory. If you change either one,
5222 +# be sure to make the appropriate change to the zImage
5223 +# rule.
5224 +RAM_LOAD_ADDR = 0x81000000
5225 +FLASH_LOAD_ADDR = 0xBF000000
5226 +
5227 +# These two variables specify the free ram region
5228 +# that can be used for temporary malloc area
5229 +AVAIL_RAM_START=0x80400000
5230 +AVAIL_RAM_END=0x80800000
5231 +
5232 +# This one must match the LOADADDR in arch/mips/Makefile!
5233 +LOADADDR=0x80100000
5234 +# END BOARD SPECIFIC VARIABLES
5235 +#########################################################################
5236 +
5237 +ZLINKFLAGS = -T ld.script -Ttext $(RAM_LOAD_ADDR)
5238 +
5239 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
5240 +       ../common/au1k_uart.o ../common/string.o ../common/ctype.o
5241 +LIBS := ../lib/zlib.a
5242 +
5243 +ENTRY := ../utils/entry
5244 +OFFSET := ../utils/offset
5245 +SIZE := ../utils/size
5246 +
5247 +all: zImage
5248 +
5249 +clean:
5250 +       rm -rf *.o vmlinux* zvmlinux.*
5251 +
5252 +head.o: head.S $(TOPDIR)/vmlinux
5253 +       $(CC) -DFLASH_LOAD_ADDR=$(FLASH_LOAD_ADDR) $(AFLAGS) \
5254 +       -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
5255 +       -c -o $*.o $<
5256 +
5257 +../common/misc-simple.o:
5258 +       $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
5259 +               -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
5260 +               -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
5261 +               -DLOADADDR=$(LOADADDR) \
5262 +               -DZIMAGE_SIZE=0 -c -o $@ $*.c
5263 +
5264 +# This is the first pass at building the boot loader image,
5265 +# without knowing the file offset where the vmlinuz.gz
5266 +# kernel will end up.  We build this image, check the offset,
5267 +# and then rebuild it with the correct offset and size
5268 +# passed to mips-simple.c
5269 +zvmlinux.no: $(OBJECTS) $(LIBS) ../images/vmlinux.gz
5270 +       $(LD) $(ZLINKFLAGS) -o $@.tmp $(OBJECTS) $(LIBS)
5271 +       $(OBJCOPY) -R .comment \
5272 +               --add-section=image=../images/vmlinux.gz \
5273 +               $@.tmp $@
5274 +       # rm -f $@.tmp
5275 +
5276 +
5277 +# This is the final image we build, now that we know what
5278 +# the vmlinuz.gz offset is.
5279 +zvmlinux: $(OBJECTS) $(LIBS) ../images/vmlinux.gz zvmlinux.no
5280 +       $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 \
5281 +               -DZIMAGE_OFFSET=$(shell sh $(OFFSET) $(OBJDUMP) $@.no image) \
5282 +               -DZIMAGE_SIZE=$(shell sh $(SIZE) $(OBJDUMP) $@.no image) \
5283 +               -D__BOOTER__ \
5284 +               -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
5285 +               -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
5286 +               -DLOADADDR=$(LOADADDR) \
5287 +               -c -o ../common/misc-simple.o ../common/misc-simple.c
5288 +       $(LD) $(ZLINKFLAGS) -o $@.tmp $(OBJECTS) $(LIBS)
5289 +       $(OBJCOPY) -R .comment \
5290 +               --add-section=image=../images/vmlinux.gz \
5291 +               $@.tmp $@
5292 +       $(OBJCOPY) --adjust-section-vma=image+$(RAM_LOAD_ADDR) $@
5293 +       $(OBJCOPY) --adjust-section-vma=image+$(shell sh $(OFFSET) \
5294 +       $(OBJDUMP) $@.no image ) $@
5295 +       # rm -f $@.tmp
5296 +       # rm -f $@.no
5297 +
5298 +
5299 +# Here we manipulate the image in order to get it the necessary
5300 +# srecord file we need.
5301 +zImage: zvmlinux
5302 +       mv zvmlinux ../images/$@.$(BNAME)
5303 +       $(OBJCOPY) --set-section-flags=image=alloc,load,code ../images/$@.$(BNAME)
5304 +       $(OBJCOPY) -O srec --adjust-vma 0x3e000000 \
5305 +       ../images/$@.$(BNAME) ../images/$@.$(BNAME).srec
5306 +       # rm ../images/vmlinux.gz
5307 +
5308 +include $(TOPDIR)/Rules.make