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
7 MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
8 +MAKEZBOOT = $(MAKE) -C arch/$(ARCH)/zboot
9 +BOOT_TARGETS = zImage zImage.initrd zImage.flash
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)
15 vmlinux.ecoff: vmlinux
18 +$(BOOT_TARGETS): vmlinux
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
35 + * BRIEF MODULE DESCRIPTION
36 + * Simple Au1000 uart routines.
38 + * Copyright 2001 MontaVista Software Inc.
39 + * Author: MontaVista Software, Inc.
40 + * ppopov@mvista.com or source@mvista.com
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.
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.
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.
62 +#include <linux/config.h>
64 +#include <asm/au1000.h>
67 +typedef unsigned char uint8;
68 +typedef unsigned int uint32;
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
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
84 +#define UART16550_DATA_5BIT 0x0
85 +#define UART16550_DATA_6BIT 0x1
86 +#define UART16550_DATA_7BIT 0x2
87 +#define UART16550_DATA_8BIT 0x3
89 +#define UART16550_STOP_1BIT 0x0
90 +#define UART16550_STOP_2BIT 0x4
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.
96 +#ifdef CONFIG_COGENT_CSB250
97 +#define UART_BASE UART3_ADDR
99 +#define UART_BASE UART0_ADDR
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))
107 + * We use uart 0, which is already initialized by
110 +volatile struct NS16550 *
111 +serial_init(int chan)
113 + volatile struct NS16550 *com_port;
114 + com_port = (struct NS16550 *) UART_BASE;
119 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
121 + while ((UART16550_READ(UART_LSR)&0x40) == 0);
122 + UART16550_WRITE(UART_TX, c);
126 +serial_getc(volatile struct NS16550 *com_port)
128 + while((UART16550_READ(UART_LSR) & 0x1) == 0);
129 + return UART16550_READ(UART_RX);
133 +serial_tstc(volatile struct NS16550 *com_port)
135 + return((UART16550_READ(UART_LSR) & LSR_DR) != 0);
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
142 + * linux/lib/ctype.c
144 + * Copyright (C) 1991, 1992 Linus Torvalds
147 +#include <linux/ctype.h>
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 */
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
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
189 +# arch/mips/zboot/common/Makefile
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
195 +# Tom Rini January 2001
199 + $(CC) $(CFLAGS) -S -o $*.s $<
203 + $(CC) $(CFLAGS) -c -o $*.o $<
205 + $(CPP) $(AFLAGS) -o $*.o $<
207 + $(CC) $(AFLAGS) -c -o $*.o $<
212 +OBJCOPY_ARGS = -O elf32-tradlittlemips
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
220 + * arch/mips/zboot/common/misc-common.c
222 + * Misc. bootloader code (almost) all platforms can use
224 + * Author: Johnnie Peters <jpeters@mvista.com>
225 + * Editor: Tom Rini <trini@mvista.com>
227 + * Derived from arch/ppc/boot/prep/misc.c
229 + * Ported by Pete Popov <ppopov@mvista.com> to
230 + * support mips board(s). I also got rid of the vga console
233 + * Copyright 2000-2001 MontaVista Software Inc.
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.
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.
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.
256 +#include <linux/config.h>
260 +extern char *avail_ram;
261 +extern char *end_avail;
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);
271 +void _vprintk(void(*)(const char), const char *, va_list ap);
273 +struct NS16550 *com_port;
275 +int serial_tstc(volatile struct NS16550 *);
276 +unsigned char serial_getc(volatile struct NS16550 *);
277 +void serial_putc(volatile struct NS16550 *, unsigned char);
292 + return (serial_tstc(com_port));
298 + if (serial_tstc(com_port))
299 + return (serial_getc(com_port));
308 + serial_putc(com_port, c);
310 + serial_putc(com_port, '\r');
313 +void puts(const char *s)
316 + while ( ( c = *s++ ) != '\0' ) {
317 + serial_putc(com_port, c);
318 + if ( c == '\n' ) serial_putc(com_port, '\r');
326 + puts("\n\n -- System halted");
328 + while(1); /* Halt */
331 +void *zalloc(void *x, unsigned items, unsigned size)
333 + void *p = avail_ram;
336 + size = (size + 7) & -8;
338 + if (avail_ram > end_avail) {
339 + puts("oops... out of memory\n");
345 +void zfree(void *x, void *addr, unsigned nb)
350 +#define EXTRA_FIELD 4
352 +#define COMMENT 0x10
353 +#define RESERVED 0xe0
357 +void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
365 + if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
366 + puts("bad gzipped data\n");
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)
374 + if ((flags & COMMENT) != 0)
375 + while (src[i++] != 0)
377 + if ((flags & HEAD_CRC) != 0)
380 + puts("gunzip: ran out of data in header\n");
386 + r = inflateInit2(&s, -MAX_WBITS);
388 + puts("inflateInit2 returned %d\n");
391 + s.next_in = src + i;
392 + s.avail_in = *lenp - i;
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");
400 + *lenp = s.next_out - (unsigned char *) dst;
405 +puthex(unsigned long val)
408 + unsigned char buf[10];
410 + for (i = 7; i >= 0; i--)
412 + buf[i] = "0123456789ABCDEF"[val & 0x0F];
423 +_printk(char const *fmt, ...)
428 + _vprintk(putc, fmt, ap);
433 +#define is_digit(c) ((c >= '0') && (c <= '9'))
436 +_vprintk(void(*putc)(const char), const char *fmt0, va_list ap)
438 + char c, sign, *cp = 0;
439 + int left_prec, right_prec, zero_fill, length = 0, pad, pad_on_right;
442 + while ((c = *fmt0++))
447 + left_prec = right_prec = pad_on_right = 0;
461 + while (is_digit(c))
463 + left_prec = (left_prec * 10) + (c - '0');
470 + while (is_digit(c))
472 + right_prec = (right_prec * 10) + (c - '0');
477 + right_prec = left_prec;
485 + val = va_arg(ap, long);
494 + length = _cvt(val, buf, 10, "0123456789");
497 + length = _cvt(val, buf, 16, "0123456789abcdef");
500 + length = _cvt(val, buf, 16, "0123456789ABCDEF");
506 + cp = va_arg(ap, char *);
507 + length = strlen(cp);
510 + c = va_arg(ap, long /*char*/);
516 + pad = left_prec - length;
544 + while (length-- > 0)
546 + (*putc)(c = *cp++);
571 +_cvt(unsigned long val, char *buf, long radix, char *digits)
577 + { /* Special case */
582 + *cp++ = digits[val % radix];
595 +_dump_buf_with_offset(unsigned char *p, int s, unsigned char *base)
598 + if ((unsigned int)s > (unsigned int)p)
600 + s = (unsigned int)s - (unsigned int)p;
606 + _printk("%06X: ", (int)p - (int)base);
609 + _printk("%06X: ", p);
611 + for (i = 0; i < 16; i++)
615 + _printk("%02X", p[i] & 0xFF);
620 + if ((i % 2) == 1) _printk(" ");
621 + if ((i % 8) == 7) _printk(" ");
624 + for (i = 0; i < 16; i++)
629 + if ((c < 0x20) || (c >= 0x7F)) c = '.';
643 +_dump_buf(unsigned char *p, int s)
646 + _dump_buf_with_offset(p, s, 0);
651 + * c-indent-level: 8
652 + * c-basic-offset: 8
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
661 + * arch/mips/zboot/common/misc-simple.c
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.
669 + * Author: Matt Porter <mporter@mvista.com>
670 + * Derived from arch/ppc/boot/prep/misc.c
672 + * Copyright 2001 MontaVista Software Inc.
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.
680 +#include <linux/types.h>
681 +#include <linux/elf.h>
682 +#include <linux/config.h>
684 +#include <asm/page.h>
685 +#include <asm/processor.h>
686 +#include <asm/mmu.h>
690 +extern struct NS16550 *com_port;
697 +#ifdef CONFIG_CMDLINE
698 +#define CMDLINE CONFIG_CMDLINE
702 +char cmd_preset[] = CMDLINE;
704 +char *cmd_line = cmd_buf;
706 +/* The linker tells us where the image is.
708 +extern unsigned char __image_begin, __image_end;
709 +extern unsigned char __ramdisk_begin, __ramdisk_end;
710 +unsigned long initrd_size;
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);
724 +decompress_kernel(unsigned long load_addr, int num_words,
725 + unsigned long cksum, unsigned long *sp)
728 + extern unsigned long start;
733 + com_port = (struct NS16550 *)serial_init(0);
735 + initrd_size = (unsigned long)(&__ramdisk_end) -
736 + (unsigned long)(&__ramdisk_begin);
739 + * Reveal where we were loaded at and where we
740 + * were relocated to.
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 )
746 + puts("relocated to: "); puthex((unsigned long)&start);
748 + puthex((unsigned long)((unsigned long)&start + (4*num_words)));
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
757 + zimage_start = (char *)(unsigned long)(&__image_begin);
758 + zimage_size = (unsigned long)(&__image_end) -
759 + (unsigned long)(&__image_begin);
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
765 + puts("zimage at: "); puthex((unsigned long)zimage_start);
766 + puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
769 + if ( initrd_size ) {
770 + puts("initrd at: ");
771 + puthex((unsigned long)(&__ramdisk_begin));
772 + puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
775 + /* assume the chunk below 8M is free */
776 + avail_ram = (char *)AVAIL_RAM_START;
777 + end_avail = (char *)AVAIL_RAM_END;
779 + /* Display standard Linux/MIPS boot prompt for kernel args */
780 + puts("Uncompressing Linux at load address ");
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");
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
791 +char initrd_data[1];
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
801 +#include <linux/config.h>
802 +#include <asm/serial.h>
803 +#include "ns16550.h"
805 +typedef struct NS16550 *NS16550_t;
807 +const NS16550_t COM_PORTS[] = { (NS16550_t) COM1,
810 + (NS16550_t) COM4 };
812 +volatile struct NS16550 *
813 +serial_init(int chan)
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;
821 + if (com_port->ier != 0x0F) return ((struct NS16550 *)0);
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;
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 */
836 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
838 + while ((com_port->lsr & LSR_THRE) == 0) ;
843 +serial_getc(volatile struct NS16550 *com_port)
845 + while ((com_port->lsr & LSR_DR) == 0) ;
846 + return (com_port->rbr);
850 +serial_tstc(volatile struct NS16550 *com_port)
852 + return ((com_port->lsr & LSR_DR) != 0);
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
859 + * linux/lib/string.c
861 + * Copyright (C) 1991, 1992 Linus Torvalds
865 + * stupid library routines.. The optimized versions should generally be found
866 + * as inline code in <asm-xx/string.h>
868 + * These are buggy as well..
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.
875 +#include <linux/types.h>
876 +#include <linux/string.h>
877 +#include <linux/ctype.h>
880 + * strnicmp - Case insensitive, length-limited string comparison
882 + * @s2: The other string
883 + * @len: the maximum number of characters to compare
885 +int strnicmp(const char *s1, const char *s2, size_t len)
887 + /* Yes, Virginia, it had better be unsigned */
888 + unsigned char c1, c2;
893 + c1 = *s1; c2 = *s2;
907 + return (int)c1 - (int)c2;
912 +#ifndef __HAVE_ARCH_STRCPY
914 + * strcpy - Copy a %NUL terminated string
915 + * @dest: Where to copy the string to
916 + * @src: Where to copy the string from
918 +char * strcpy(char * dest,const char *src)
922 + while ((*dest++ = *src++) != '\0')
928 +#ifndef __HAVE_ARCH_STRNCPY
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
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
939 +char * strncpy(char * dest,const char *src,size_t count)
943 + while (count-- && (*dest++ = *src++) != '\0')
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
955 +char * strcat(char * dest, const char * src)
961 + while ((*dest++ = *src++) != '\0')
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
973 + * Note that in contrast to strncpy, strncat ensures the result is
976 +char * strncat(char *dest, const char *src, size_t count)
983 + while ((*dest++ = *src++)) {
984 + if (--count == 0) {
994 +#ifndef __HAVE_ARCH_STRCMP
996 + * strcmp - Compare two strings
998 + * @ct: Another string
1000 +int strcmp(const char * cs,const char * ct)
1002 + register signed char __res;
1005 + if ((__res = *cs - *ct++) != 0 || !*cs++)
1013 +#ifndef __HAVE_ARCH_STRNCMP
1015 + * strncmp - Compare two length-limited strings
1017 + * @ct: Another string
1018 + * @count: The maximum number of bytes to compare
1020 +int strncmp(const char * cs,const char * ct,size_t count)
1022 + register signed char __res = 0;
1025 + if ((__res = *cs - *ct++) != 0 || !*cs++)
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
1039 +char * strchr(const char * s, int c)
1041 + for(; *s != (char) c; ++s)
1044 + return (char *) s;
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
1052 +char * strrchr(const char * s, int c)
1054 + const char *p = s + strlen(s);
1056 + if (*p == (char)c)
1058 + } while (--p >= s);
1063 + * strlen - Find the length of a string
1064 + * @s: The string to be sized
1066 +size_t strlen(const char * s)
1070 + for (sc = s; *sc != '\0'; ++sc)
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
1080 +size_t strnlen(const char * s, size_t count)
1084 + for (sc = s; count-- && *sc != '\0'; ++sc)
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
1095 +size_t strspn(const char *s, const char *accept)
1101 + for (p = s; *p != '\0'; ++p) {
1102 + for (a = accept; *a != '\0'; ++a) {
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
1119 +char * strpbrk(const char * cs,const char * ct)
1121 + const char *sc1,*sc2;
1123 + for( sc1 = cs; *sc1 != '\0'; ++sc1) {
1124 + for( sc2 = ct; *sc2 != '\0'; ++sc2) {
1126 + return (char *) sc1;
1133 + * strtok - Split a string into tokens
1134 + * @s: The string to be searched
1135 + * @ct: The characters to search for
1137 + * WARNING: strtok is deprecated, use strsep instead.
1139 +char * strtok(char * s,const char * ct)
1141 + char *sbegin, *send;
1143 + sbegin = s ? s : ___strtok;
1147 + sbegin += strspn(sbegin,ct);
1148 + if (*sbegin == '\0') {
1152 + send = strpbrk( sbegin, ct);
1153 + if (send && *send != '\0')
1160 + * strsep - Split a string into tokens
1161 + * @s: The string to be searched
1162 + * @ct: The characters to search for
1164 + * strsep() updates @s to point after the token, ready for the next call.
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. ;)
1170 +char * strsep(char **s, const char *ct)
1172 + char *sbegin = *s, *end;
1174 + if (sbegin == NULL)
1177 + end = strpbrk(sbegin, ct);
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.
1191 + * Do not use memset() to access IO space, use memset_io() instead.
1193 +void * memset(void * s,int c, size_t count)
1195 + char *xs = (char *) s;
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.
1209 + * Note that this is the same as memcpy(), with the arguments reversed.
1210 + * memcpy() is the standard, bcopy() is a legacy BSD function.
1212 + * You should not use this function to access IO space, use memcpy_toio()
1213 + * or memcpy_fromio() instead.
1215 +char * bcopy(const char * src, char * dest, int count)
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.
1231 + * You should not use this function to access IO space, use memcpy_toio()
1232 + * or memcpy_fromio() instead.
1234 +void * memcpy(void * dest,const void *src,size_t count)
1236 + char *tmp = (char *) dest, *s = (char *) src;
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.
1250 + * Unlike memcpy(), memmove() copes with overlapping areas.
1252 +void * memmove(void * dest,const void *src,size_t count)
1256 + if (dest <= src) {
1257 + tmp = (char *) dest;
1263 + tmp = (char *) dest + count;
1264 + s = (char *) src + count;
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.
1278 +int memcmp(const void * cs,const void * ct,size_t count)
1280 + const unsigned char *su1, *su2;
1281 + signed char res = 0;
1283 + for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
1284 + if ((res = *su1 - *su2) != 0)
1289 +#ifndef __HAVE_ARCH_MEMSCAN
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.
1296 + * returns the address of the first occurrence of @c, or 1 byte past
1297 + * the area if @c is not found
1299 +void * memscan(void * addr, int c, size_t size)
1301 + unsigned char * p = (unsigned char *) addr;
1302 + unsigned char * e = p + size;
1306 + return (void *) p;
1310 + return (void *) p;
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
1319 +char * strstr(const char * s1,const char * s2)
1325 + return (char *) s1;
1327 + while (l1 >= l2) {
1329 + if (!memcmp(s1,s2,l2))
1330 + return (char *) s1;
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.
1342 + * returns the address of the first occurrence of @c, or %NULL
1343 + * if @c is not found
1345 +void *memchr(const void *s, int c, size_t n)
1347 + const unsigned char *p = s;
1348 + while (n-- != 0) {
1349 + if ((unsigned char)c == *p++) {
1350 + return (void *)(p-1);
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
1360 + * arch/mips/kernel/head.S
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.
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.
1374 + * Head.S contains the MIPS exception handler and startup code.
1376 + **************************************************************************
1378 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
1380 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
1381 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
1382 + **************************************************************************
1384 +#include <linux/config.h>
1385 +#include <linux/threads.h>
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>
1394 +#define IndexInvalidate_I 0x00
1395 +#define IndexWriteBack_D 0x01
1404 + .globl asize /* Someday we'll put the initrd info here. */
1411 + subu s8, ra, 8 /* Where we were loaded */
1412 + la sp, (.stack + 8192)
1414 + move s0, a0 /* Save boot rom start args */
1419 + la a0, start /* Where we were linked to run */
1426 + /* copy text section */
1443 + /* push the D-Cache and invalidate I-Cache */
1444 + li k0, 0x80000000 # start address
1445 + li k1, 0x80004000 # end address (16KB I-Cache)
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)
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 */
1471 + la k0, decompress_kernel
1476 + la a2, __ramdisk_begin
1477 + la a3, initrd_size
1480 + li k0, KERNEL_ENTRY
1493 + li k0, 0x80000000 # start address
1494 + li k1, 0x80004000 # end address (16KB I-Cache)
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)
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
1520 +# arch/mips/zboot/pb1xxx/Makefile
1522 +# Makefile for Cogent CSB250 Au1500 board.
1523 +# All of the boot loader code was derived from the ppc
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.
1532 + $(CC) $(CFLAGS) -S -o $*.s $<
1536 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
1538 + $(CPP) $(AFLAGS) -o $*.o $<
1540 + $(CC) $(AFLAGS) -c -o $*.o $<
1542 +#########################################################################
1543 +# START BOARD SPECIFIC VARIABLES
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
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
1557 +# This one must match the LOADADDR in arch/mips/Makefile!
1558 +LOADADDR=0x80100000
1559 +# END BOARD SPECIFIC VARIABLES
1560 +#########################################################################
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
1566 +ENTRY := ../utils/entry
1567 +OFFSET := ../utils/offset
1568 +SIZE := ../utils/size
1570 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
1571 +OBJCOPY_ARGS = -O elf32-tradbigmips
1576 + rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
1578 +head.o: head.S $(TOPDIR)/vmlinux
1580 + -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
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
1590 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
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
1599 +# Here we manipulate the image in order to get it the necessary
1600 +# srecord file we need.
1602 + mv zvmlinux ../images/zImage.$(BNAME)
1603 + $(OBJCOPY) -O binary ../images/zImage.$(BNAME) ../images/$(BNAME).bin
1605 +zImage.flash: zImage
1606 + $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
1607 + ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
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
1615 +include $(TOPDIR)/Rules.make
1617 +vmlinux.gz: $(TOPDIR)/vmlinux
1618 + $(OBJCOPY) -S -O binary $(TOPDIR)/vmlinux vmlinux
1622 + rm -f vmlinux.* zImage.*
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
1629 + * Copyright (C) Paul Mackerras 1997.
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.
1637 +extern FILE *stdin, *stdout;
1638 +#define NULL ((void *)0)
1640 +#define fopen(n, m) NULL
1641 +#define fflush(f) 0
1642 +#define fclose(f) 0
1643 +extern char *fgets();
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
1651 + * NS16550 Serial Port
1655 + * Figure out which file will have the definitons of COMx
1657 +#if !defined(CONFIG_AU1X00_UART)
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)
1669 + unsigned char rbr; /* 0 */
1671 + unsigned char ier; /* 1 */
1673 + unsigned char fcr; /* 2 */
1675 + unsigned char lcr; /* 3 */
1677 + unsigned char mcr; /* 4 */
1679 + unsigned char lsr; /* 5 */
1681 + unsigned char msr; /* 6 */
1683 + unsigned char scr; /* 7 */
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
1704 + * arch/ppc/boot/include/sandpoint_serial.h
1706 + * Location of the COM ports on Motorola SPS Sandpoint machines
1708 + * Author: Mark A. Greer
1709 + * mgreer@mvista.com
1711 + * Copyright 2001 MontaVista Software Inc.
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.
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
1727 +/* $Id: zlib.h,v 1.2 2002/02/16 16:55:45 ppopov Exp $ */
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.
1737 + * ==FILEVERSION 960122==
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.
1743 +/* zlib.h -- interface of the 'zlib' general purpose compression library
1744 + version 0.95, Aug 16th, 1995.
1746 + Copyright (C) 1995 Jean-loup Gailly and Mark Adler
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.
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:
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.
1764 + Jean-loup Gailly Mark Adler
1765 + gzip@prep.ai.mit.edu madler@alumni.caltech.edu
1771 +/* #include "zconf.h" */ /* included directly here */
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
1778 +/* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
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.
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.
1796 +# if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
1801 +#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
1805 +/* Maximum value for memLevel in deflateInit2 */
1806 +#ifndef MAX_MEM_LEVEL
1808 +# define MAX_MEM_LEVEL 8
1810 +# define MAX_MEM_LEVEL 9
1818 +/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
1820 +# define MAX_WBITS 15 /* 32K LZ77 window */
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).
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.
1836 + /* Type declarations */
1838 +#ifndef OF /* function prototypes */
1840 +# define OF(args) args
1842 +# define OF(args) ()
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 */
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;
1857 + typedef void FAR *voidpf;
1858 + typedef void *voidp;
1860 + typedef Byte FAR *voidpf;
1861 + typedef Byte *voidp;
1864 +/* end of original zconf.h */
1866 +#define ZLIB_VERSION "0.95P"
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
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.
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.
1887 +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
1888 +typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt nbytes));
1890 +struct internal_state;
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 */
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 */
1901 + char *msg; /* last error message, NULL if no error */
1902 + struct internal_state FAR *state; /* not visible by applications */
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 */
1908 + Byte data_type; /* best guess about the data type: ascii or binary */
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.
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
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).
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
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 */
1948 +#define Z_PACKET_FLUSH 5
1949 +/* See deflate() below for the usage of these constants */
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 */
1960 +#define Z_BEST_SPEED 1
1961 +#define Z_BEST_COMPRESSION 9
1962 +#define Z_DEFAULT_COMPRESSION (-1)
1963 +/* compression levels */
1965 +#define Z_FILTERED 1
1966 +#define Z_HUFFMAN_ONLY 2
1967 +#define Z_DEFAULT_STRATEGY 0
1971 +#define Z_UNKNOWN 2
1972 +/* Used to set the data_type field */
1974 +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
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.
1982 + /* basic functions */
1984 +extern int inflateInit OF((z_stream *strm));
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
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
1998 +extern int inflate OF((z_stream *strm, int flush));
2000 + Performs one or both of the following actions:
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().
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).
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().
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.
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.
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. */
2049 +extern int inflateEnd OF((z_stream *strm));
2051 + All dynamically allocated data structures for this stream are freed.
2052 + This function discards any unprocessed input and does not flush any
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).
2060 + /* advanced functions */
2062 +extern int inflateInit2 OF((z_stream *strm,
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.
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.
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().
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.
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
2095 +extern int inflateSync OF((z_stream *strm));
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
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.
2110 +extern int inflateReset OF((z_stream *strm));
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.
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).
2120 +extern int inflateIncomp OF((z_stream *strm));
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).
2129 + /* checksum functions */
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.
2137 +extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
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:
2146 + uLong adler = adler32(0L, Z_NULL, 0);
2148 + while (read_buffer(buffer, length) != EOF) {
2149 + adler = adler32(adler, buffer, length);
2151 + if (adler != original_adler) error();
2155 + struct internal_state {int dummy;}; /* hack for buggy compilers */
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
2167 + /* Read-only sections, merged into text segment: */
2168 + /* . = 0x81000000; */
2169 + .init : { *(.init) } =0
2176 + /* .gnu.warning sections are handled specially by elf32.em. */
2179 + .kstrtab : { *(.kstrtab) }
2181 + . = ALIGN(16); /* Exception table */
2182 + __start___ex_table = .;
2183 + __ex_table : { *(__ex_table) }
2184 + __stop___ex_table = .;
2186 + __start___dbe_table = .; /* Exception table for data bus errors */
2187 + __dbe_table : { *(__dbe_table) }
2188 + __stop___dbe_table = .;
2190 + __start___ksymtab = .; /* Kernel symbol table */
2191 + __ksymtab : { *(__ksymtab) }
2192 + __stop___ksymtab = .;
2197 + .data.init_task : { *(.data.init_task) }
2199 + /* Startup code */
2202 + .text.init : { *(.text.init) }
2203 + .data.init : { *(.data.init) }
2205 + __setup_start = .;
2206 + .setup.init : { *(.setup.init) }
2208 + __initcall_start = .;
2209 + .initcall.init : { *(.initcall.init) }
2210 + __initcall_end = .;
2211 + . = ALIGN(4096); /* Align double page for init_task_union */
2215 + .data.page_aligned : { *(.data.idt) }
2218 + .data.cacheline_aligned : { *(.data.cacheline_aligned) }
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:
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). */
2242 + /* Put the compressed image here, so bss is on the end. */
2243 + __image_begin = .;
2246 + /* Align the initial ramdisk image (INITRD) on page boundaries. */
2248 + __ramdisk_begin = .;
2250 + __ramdisk_end = .;
2255 + .data1 : { *(.data1) }
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) }
2269 + PROVIDE (edata = .);
2273 + .sbss : { *(.sbss) *(.scommon) }
2281 + PROVIDE (end = .);
2284 + /* Sections to be discarded */
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) }
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
2319 +# Makefile for some libs needed by zImage.
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
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.
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
2344 + * $Id: zlib.c,v 1.2 2002/02/16 16:55:45 ppopov Exp $
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
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.
2358 +/* From: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp */
2365 +# define local static
2367 +/* compile with -Dlocal if your debugger can't find static symbols */
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;
2377 +extern char *z_errmsg[]; /* indexed by 1-zlib_error */
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 */
2383 +#define NULL ((void *) 0)
2386 + /* common constants */
2391 +# define DEF_WBITS MAX_WBITS
2393 +/* default windowBits for decompression. MAX_WBITS is for compression only */
2395 +#if MAX_MEM_LEVEL >= 8
2396 +# define DEF_MEM_LEVEL 8
2398 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL
2400 +/* default memLevel */
2402 +#define STORED_BLOCK 0
2403 +#define STATIC_TREES 1
2404 +#define DYN_TREES 2
2405 +/* The three kinds of block type */
2407 +#define MIN_MATCH 3
2408 +#define MAX_MATCH 258
2409 +/* The minimum and maximum match lengths */
2413 +#include <linux/string.h>
2414 +#define zmemcpy memcpy
2415 +#define zmemzero(dest, len) memset(dest, 0, len)
2417 +/* Diagnostic functions */
2419 +# include <stdio.h>
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 ;}
2430 +# define Assert(cond,msg)
2433 +# define Tracevv(x)
2434 +# define Tracec(c,x)
2435 +# define Tracecv(c,x)
2439 +typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
2441 +/* voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); */
2442 +/* void zcfree OF((voidpf opaque, voidpf ptr)); */
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);}
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
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.
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
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.
2471 +struct inflate_blocks_state;
2472 +typedef struct inflate_blocks_state FAR inflate_blocks_statef;
2474 +local inflate_blocks_statef * inflate_blocks_new OF((
2476 + check_func c, /* check function */
2477 + uInt w)); /* window size */
2479 +local int inflate_blocks OF((
2480 + inflate_blocks_statef *,
2482 + int)); /* initial return code */
2484 +local void inflate_blocks_reset OF((
2485 + inflate_blocks_statef *,
2487 + uLongf *)); /* check value on output */
2489 +local int inflate_blocks_free OF((
2490 + inflate_blocks_statef *,
2492 + uLongf *)); /* check value on output */
2494 +local int inflate_addhistory OF((
2495 + inflate_blocks_statef *,
2498 +local int inflate_packet_flush OF((
2499 + inflate_blocks_statef *));
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
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.
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). */
2515 +typedef struct inflate_huft_s FAR inflate_huft;
2517 +struct inflate_huft_s {
2520 + Byte Exop; /* number of extra bits or operation */
2521 + Byte Bits; /* number of bits in this code or subcode */
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) */
2527 + uInt Base; /* literal, length base, or distance base */
2528 + inflate_huft *Next; /* pointer to next level of table */
2533 + local uInt inflate_hufts;
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 */
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 */
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 */
2558 +local int inflate_trees_free OF((
2559 + inflate_huft *, /* tables to free */
2560 + z_stream *)); /* for zfree function */
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
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.
2574 +struct inflate_codes_state;
2575 +typedef struct inflate_codes_state FAR inflate_codes_statef;
2577 +local inflate_codes_statef *inflate_codes_new OF((
2579 + inflate_huft *, inflate_huft *,
2582 +local int inflate_codes OF((
2583 + inflate_blocks_statef *,
2587 +local void inflate_codes_free OF((
2588 + inflate_codes_statef *,
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
2598 +/* inflate private state */
2599 +struct internal_state {
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 */
2614 + /* mode dependent information */
2616 + uInt method; /* if FLAGS, method byte */
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 */
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 */
2633 +int inflateReset(z)
2638 + if (z == Z_NULL || z->state == Z_NULL)
2639 + return Z_STREAM_ERROR;
2640 + z->total_in = z->total_out = 0;
2642 + z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
2643 + inflate_blocks_reset(z->state->blocks, z, &c);
2644 + Trace((stderr, "inflate: reset\n"));
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"));
2665 +int inflateInit2(z, w)
2669 + /* initialize state */
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;
2679 + /* handle undocumented nowrap option (no zlib header or check) */
2680 + z->state->nowrap = 0;
2684 + z->state->nowrap = 1;
2687 + /* set window size */
2688 + if (w < 8 || w > 15)
2691 + return Z_STREAM_ERROR;
2693 + z->state->wbits = (uInt)w;
2695 + /* create inflate_blocks state */
2696 + if ((z->state->blocks =
2697 + inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w))
2701 + return Z_MEM_ERROR;
2703 + Trace((stderr, "inflate: allocated\n"));
2714 + return inflateInit2(z, DEF_WBITS);
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++)
2728 + if (z == Z_NULL || z->next_in == Z_NULL)
2729 + return Z_STREAM_ERROR;
2731 + while (1) switch (z->state->mode)
2735 + if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED)
2737 + z->state->mode = BAD;
2738 + z->msg = "unknown compression method";
2739 + z->state->sub.marker = 5; /* can't try inflateSync */
2742 + if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
2744 + z->state->mode = BAD;
2745 + z->msg = "invalid window size";
2746 + z->state->sub.marker = 5; /* can't try inflateSync */
2749 + z->state->mode = FLAG;
2752 + if ((b = NEXTBYTE) & 0x20)
2754 + z->state->mode = BAD;
2755 + z->msg = "invalid reserved bit";
2756 + z->state->sub.marker = 5; /* can't try inflateSync */
2759 + if (((z->state->sub.method << 8) + b) % 31)
2761 + z->state->mode = BAD;
2762 + z->msg = "incorrect header check";
2763 + z->state->sub.marker = 5; /* can't try inflateSync */
2766 + Trace((stderr, "inflate: zlib header ok\n"));
2767 + z->state->mode = 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)
2774 + z->state->mode = BAD;
2775 + z->state->sub.marker = 0; /* can try inflateSync */
2778 + if (r != Z_STREAM_END)
2781 + inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
2782 + if (z->state->nowrap)
2784 + z->state->mode = DONE;
2787 + z->state->mode = CHECK4;
2790 + z->state->sub.check.need = (uLong)NEXTBYTE << 24;
2791 + z->state->mode = CHECK3;
2794 + z->state->sub.check.need += (uLong)NEXTBYTE << 16;
2795 + z->state->mode = CHECK2;
2798 + z->state->sub.check.need += (uLong)NEXTBYTE << 8;
2799 + z->state->mode = CHECK1;
2802 + z->state->sub.check.need += (uLong)NEXTBYTE;
2804 + if (z->state->sub.check.was != z->state->sub.check.need)
2806 + z->state->mode = BAD;
2807 + z->msg = "incorrect data check";
2808 + z->state->sub.marker = 5; /* can't try inflateSync */
2811 + Trace((stderr, "inflate: zlib check ok\n"));
2812 + z->state->mode = DONE;
2814 + return Z_STREAM_END;
2816 + return Z_DATA_ERROR;
2818 + return Z_STREAM_ERROR;
2822 + if (f != Z_PACKET_FLUSH)
2824 + z->state->mode = BAD;
2825 + z->state->sub.marker = 0; /* can try inflateSync */
2826 + return Z_DATA_ERROR;
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.
2838 +int inflateIncomp(z)
2841 + if (z->state->mode != BLOCKS)
2842 + return Z_DATA_ERROR;
2843 + return inflate_addhistory(z->state->blocks, z);
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 */
2856 + if (z == Z_NULL || z->state == Z_NULL)
2857 + return Z_STREAM_ERROR;
2858 + if (z->state->mode != BAD)
2860 + z->state->mode = BAD;
2861 + z->state->sub.marker = 0;
2863 + if ((n = z->avail_in) == 0)
2864 + return Z_BUF_ERROR;
2866 + m = z->state->sub.marker;
2869 + while (n && m < 4)
2871 + if (*p == (Byte)(m < 2 ? 0 : 0xff))
2881 + z->total_in += p - z->next_in;
2884 + z->state->sub.marker = m;
2886 + /* return no joy or set up to restart on a new block */
2888 + return Z_DATA_ERROR;
2889 + r = z->total_in; w = z->total_out;
2891 + z->total_in = r; z->total_out = w;
2892 + z->state->mode = BLOCKS;
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
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.
2910 +/* inflate blocks semi-private state */
2911 +struct inflate_blocks_state {
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 */
2927 + /* mode dependent information */
2929 + uInt left; /* if STORED, bytes left to copy */
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 */
2939 + inflate_huft *tl, *td; /* trees to free */
2940 + inflate_codes_statef
2942 + } decode; /* if CODES, current state */
2943 + } sub; /* submode */
2944 + uInt last; /* true if this block is the last block */
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 */
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);}
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}
2983 + * The IBM 150 firmware munges the data right after _etext[]. This
2984 + * protects it. -- Cort
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[] = {
2990 + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
2991 + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
2994 +/* copy as much as possible from the sliding window to the output area */
2995 +local int inflate_flush OF((
2996 + inflate_blocks_statef *,
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
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.
3011 +local int inflate_fast OF((
3016 + inflate_blocks_statef *,
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
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};
3031 + Notes beyond the 1.93a appnote.txt:
3033 + 1. Distance pointers never point before the beginning of the output
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
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.
3076 +local void inflate_blocks_reset(s, z, c)
3077 +inflate_blocks_statef *s;
3081 + if (s->checkfn != Z_NULL)
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)
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);
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"));
3101 +local inflate_blocks_statef *inflate_blocks_new(z, c, w)
3106 + inflate_blocks_statef *s;
3108 + if ((s = (inflate_blocks_statef *)ZALLOC
3109 + (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
3111 + if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
3113 + ZFREE(z, s, sizeof(struct inflate_blocks_state));
3116 + s->end = s->window + w;
3119 + Trace((stderr, "inflate: blocks allocated\n"));
3120 + inflate_blocks_reset(s, z, &s->check);
3125 +local int inflate_blocks(s, z, r)
3126 +inflate_blocks_statef *s;
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 */
3138 + /* copy input/output information to locals (UPDATE macro restores) */
3141 + /* process input based on current state */
3142 + while (1) switch (s->mode)
3150 + case 0: /* stored */
3151 + Trace((stderr, "inflate: stored block%s\n",
3152 + s->last ? " (last)" : ""));
3154 + t = k & 7; /* go to byte boundary */
3156 + s->mode = LENS; /* get length of stored block */
3158 + case 1: /* fixed */
3159 + Trace((stderr, "inflate: fixed codes block%s\n",
3160 + s->last ? " (last)" : ""));
3163 + inflate_huft *tl, *td;
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)
3172 + s->sub.decode.tl = Z_NULL; /* don't try to free these */
3173 + s->sub.decode.td = Z_NULL;
3178 + case 2: /* dynamic */
3179 + Trace((stderr, "inflate: dynamic codes block%s\n",
3180 + s->last ? " (last)" : ""));
3184 + case 3: /* illegal */
3187 + z->msg = "invalid block type";
3194 + if (((~b) >> 16) != (b & 0xffff))
3197 + z->msg = "invalid stored block lengths";
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;
3216 + if ((s->sub.left -= t) != 0)
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;
3225 + s->sub.trees.table = t = (uInt)b & 0x3fff;
3226 +#ifndef PKZIP_BUG_WORKAROUND
3227 + if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
3230 + z->msg = "too many length or distance symbols";
3235 + t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
3238 + if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
3243 + s->sub.trees.nblens = t;
3245 + s->sub.trees.index = 0;
3246 + Tracev((stderr, "inflate: table sizes ok\n"));
3249 + while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
3252 + s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
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);
3263 + if (r == Z_DATA_ERROR)
3267 + s->sub.trees.index = 0;
3268 + Tracev((stderr, "inflate: bits tree ok\n"));
3271 + while (t = s->sub.trees.table,
3272 + s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
3277 + t = s->sub.trees.bb;
3279 + h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
3280 + t = h->word.what.Bits;
3285 + s->sub.trees.blens[s->sub.trees.index++] = c;
3287 + else /* c == 16..18 */
3289 + i = c == 18 ? 7 : c - 14;
3290 + j = c == 18 ? 11 : 3;
3293 + j += (uInt)b & inflate_mask[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))
3301 + z->msg = "invalid bit length repeat";
3305 + c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
3307 + s->sub.trees.blens[i++] = c;
3309 + s->sub.trees.index = i;
3312 + inflate_trees_free(s->sub.trees.tb, z);
3313 + s->sub.trees.tb = Z_NULL;
3316 + inflate_huft *tl, *td;
3317 + inflate_codes_statef *c;
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);
3326 + if (t == (uInt)Z_DATA_ERROR)
3331 + Tracev((stderr, "inflate: trees ok\n"));
3332 + if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
3334 + inflate_trees_free(td, z);
3335 + inflate_trees_free(tl, z);
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;
3347 + if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
3348 + return inflate_flush(s, z, r);
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);
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))));
3362 + if (k > 7) /* return unused byte, if any */
3364 + Assert(k < 16, "inflate_codes grabbed too many bytes")
3367 + p--; /* can always return one */
3372 + if (s->read != s->write)
3382 + r = Z_STREAM_ERROR;
3388 +local int inflate_blocks_free(s, z, c)
3389 +inflate_blocks_statef *s;
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"));
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.
3408 +local int inflate_addhistory(s, z)
3409 +inflate_blocks_statef *s;
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 */
3420 + if (s->read != s->write)
3421 + return Z_STREAM_ERROR;
3422 + if (s->mode != TYPE)
3423 + return Z_DATA_ERROR;
3425 + /* we're ready to rock */
3427 + /* while there is input ready, copy to output buffer, moving
3428 + * pointers as needed.
3431 + t = n; /* how many to do */
3432 + /* is there room until end of buffer? */
3434 + /* update check information */
3435 + if (s->checkfn != Z_NULL)
3436 + s->check = (*s->checkfn)(s->check, q, 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;
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.
3458 +local int inflate_packet_flush(s)
3459 + inflate_blocks_statef *s;
3461 + if (s->mode != LENS)
3462 + return Z_DATA_ERROR;
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
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
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 */
3491 +local voidpf falloc OF((
3492 + voidpf, /* opaque pointer (not used) */
3493 + uInt, /* number of items */
3494 + uInt)); /* size of item */
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) */
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,
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.
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
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.
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 */
3556 + uInt inflate_hufts;
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. */
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 */
3596 + /* Generate counts for each bit length */
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 */
3604 + c[*p++]++; /* assume all entries <= BMAX */
3606 + if (c[0] == n) /* null input--all zero length codes */
3608 + *t = (inflate_huft *)Z_NULL;
3614 + /* Find minimum and maximum length, bound *m by those */
3616 + for (j = 1; j <= BMAX; j++)
3619 + k = j; /* minimum code length */
3622 + for (i = BMAX; i; i--)
3625 + g = i; /* maximum code length */
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;
3640 + /* Generate starting offsets into the value table for each length */
3642 + p = c + 1; xp = x + 2;
3643 + while (--i) { /* note that i == g from above */
3644 + *xp++ = (j += *p++);
3648 + /* Make a table of values in order of bit lengths */
3651 + if ((j = *p++) != 0)
3653 + } while (++i < n);
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 */
3665 + /* go through the bit lengths (k already is bits in shortest code) */
3666 + for (; k <= g; k++)
3671 + /* here i is the Huffman code of length k bits for value *p */
3672 + /* make tables up to required level */
3676 + w += l; /* previous table always l bits */
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 */
3685 + while (++j < z) /* try smaller tables up to z bits */
3687 + if ((f <<= 1) <= *++xp)
3688 + break; /* enough codes to use up j bits */
3689 + f -= *xp; /* else deduct codes from patterns */
3692 + z = 1 << j; /* table entries for j-bit table */
3694 + /* allocate and link in new table */
3695 + if ((q = (inflate_huft *)ZALLOC
3696 + (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
3699 + inflate_trees_free(u[0], zs);
3700 + return Z_MEM_ERROR; /* not enough memory */
3702 + q->word.Nalloc = z + 1;
3704 + inflate_hufts += z + 1;
3706 + *t = q + 1; /* link to list for huft_free() */
3707 + *(t = &(q->next)) = Z_NULL;
3708 + u[h] = ++q; /* table starts after link */
3710 + /* connect to last table, if there is one */
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 */
3722 + /* set up table entry in r */
3723 + r.bits = (Byte)(k - w);
3725 + r.exop = 128 + 64; /* out of values--invalid code */
3728 + r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
3729 + r.base = *p++; /* simple code is just the value */
3733 + r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */
3734 + r.base = d[*p++ - s];
3737 + /* fill code-like entries with r */
3739 + for (j = i >> w; j < z; j += f)
3742 + /* backwards increment the k-bit code i */
3743 + for (j = 1 << (k - 1); i & j; j >>= 1)
3747 + /* backup over finished tables */
3748 + while ((i & ((1 << w) - 1)) != x[h])
3750 + h--; /* don't need to update q */
3757 + /* Return Z_BUF_ERROR if we were given an incomplete table */
3758 + return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
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 */
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)
3775 + inflate_trees_free(*tb, z);
3776 + z->msg = "incomplete dynamic bit lengths tree";
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 */
3795 + /* build literal/length tree */
3796 + if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK)
3798 + if (r == Z_DATA_ERROR)
3799 + z->msg = "oversubscribed literal/length tree";
3800 + else if (r == Z_BUF_ERROR)
3802 + inflate_trees_free(*tl, z);
3803 + z->msg = "incomplete literal/length tree";
3809 + /* build distance tree */
3810 + if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK)
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
3819 + inflate_trees_free(*td, z);
3820 + z->msg = "incomplete literal/length tree";
3823 + inflate_trees_free(*tl, z);
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;
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 */
3850 + Assert(s == sizeof(inflate_huft) && n <= fixed_left,
3851 + "inflate_trees falloc overflow");
3852 + if (q) s++; /* to make some compilers happy */
3854 + return (voidpf)(fixed_mem + fixed_left);
3858 +local void ffree(q, p, n)
3863 + Assert(0, "inflate_trees ffree called!");
3864 + if (q) q = p; /* to make some compilers happy */
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 */
3874 + /* build fixed tables if not built already--lock out other instances */
3875 + while (++fixed_lock > 1)
3879 + int k; /* temporary variable */
3880 + unsigned c[288]; /* length list for huft_build */
3881 + z_stream z; /* for falloc function */
3883 + /* set up fake z_stream for memory routines */
3884 + z.zalloc = falloc;
3886 + z.opaque = Z_NULL;
3888 + /* literal table */
3889 + for (k = 0; k < 144; k++)
3891 + for (; k < 256; k++)
3893 + for (; k < 280; k++)
3895 + for (; k < 288; k++)
3898 + huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
3900 + /* distance table */
3901 + for (k = 0; k < 30; k++)
3904 + huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
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
3925 + register inflate_huft *p, *q;
3927 + /* Go through linked list, freeing from the malloced (t[-1]) address. */
3929 + while (p != Z_NULL)
3932 + ZFREE(z, p, p->word.Nalloc * sizeof(inflate_huft));
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
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
3950 +/* inflate codes private state */
3951 +struct inflate_codes_state {
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 */
3967 + /* mode dependent information */
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 */
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 */
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 */
3990 +local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
3992 +inflate_huft *tl, *td;
3995 + inflate_codes_statef *c;
3997 + if ((c = (inflate_codes_statef *)
3998 + ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
4001 + c->lbits = (Byte)bl;
4002 + c->dbits = (Byte)bd;
4005 + Tracev((stderr, "inflate: codes new\n"));
4011 +local int inflate_codes(s, z, r)
4012 +inflate_blocks_statef *s;
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 */
4028 + /* copy input/output information to locals (UPDATE macro restores) */
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 */
4036 + if (m >= 258 && n >= 10)
4039 + r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
4043 + c->mode = r == Z_STREAM_END ? WASH : BADCODE;
4048 + c->sub.code.need = c->lbits;
4049 + c->sub.code.tree = c->ltree;
4051 + case LEN: /* i: get length/literal/eob next */
4052 + j = c->sub.code.need;
4054 + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4056 + e = (uInt)(t->exop);
4057 + if (e == 0) /* literal */
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));
4066 + if (e & 16) /* length */
4068 + c->sub.copy.get = e & 15;
4073 + if ((e & 64) == 0) /* next table */
4075 + c->sub.code.need = e;
4076 + c->sub.code.tree = t->next;
4079 + if (e & 32) /* end of block */
4081 + Tracevv((stderr, "inflate: end of block\n"));
4085 + c->mode = BADCODE; /* invalid code */
4086 + z->msg = "invalid literal/length code";
4089 + case LENEXT: /* i: getting length extra (have base) */
4090 + j = c->sub.copy.get;
4092 + c->len += (uInt)b & inflate_mask[j];
4094 + c->sub.code.need = c->dbits;
4095 + c->sub.code.tree = c->dtree;
4096 + Tracevv((stderr, "inflate: length %u\n", c->len));
4098 + case DIST: /* i: get distance next */
4099 + j = c->sub.code.need;
4101 + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4103 + e = (uInt)(t->exop);
4104 + if (e & 16) /* distance */
4106 + c->sub.copy.get = e & 15;
4107 + c->sub.copy.dist = t->base;
4108 + c->mode = DISTEXT;
4111 + if ((e & 64) == 0) /* next table */
4113 + c->sub.code.need = e;
4114 + c->sub.code.tree = t->next;
4117 + c->mode = BADCODE; /* invalid code */
4118 + z->msg = "invalid distance code";
4121 + case DISTEXT: /* i: getting distance extra */
4122 + j = c->sub.copy.get;
4124 + c->sub.copy.dist += (uInt)b & inflate_mask[j];
4126 + Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
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;
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));
4148 + case LIT: /* o: got literal, waiting for output space */
4150 + OUTBYTE(c->sub.lit)
4153 + case WASH: /* o: got eob, possibly more output */
4155 + if (s->read != s->write)
4161 + case BADCODE: /* x: got error */
4165 + r = Z_STREAM_ERROR;
4171 +local void inflate_codes_free(c, z)
4172 +inflate_codes_statef *c;
4175 + ZFREE(z, c, sizeof(struct inflate_codes_state));
4176 + Tracev((stderr, "inflate: codes free\n"));
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
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;
4194 + /* local copies of source and destination pointers */
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;
4203 + /* update counters */
4204 + z->avail_out -= n;
4205 + z->total_out += n;
4207 + /* update check information */
4208 + if (s->checkfn != Z_NULL)
4209 + s->check = (*s->checkfn)(s->check, q, n);
4211 + /* copy as far as end of window */
4216 + /* see if more to copy at beginning of window */
4219 + /* wrap pointers */
4221 + if (s->write == s->end)
4222 + s->write = s->window;
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;
4229 + /* update counters */
4230 + z->avail_out -= n;
4231 + z->total_out += n;
4233 + /* update check information */
4234 + if (s->checkfn != Z_NULL)
4235 + s->check = (*s->checkfn)(s->check, q, n);
4243 + /* update pointers */
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
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
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;}
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. */
4273 +local int inflate_fast(bl, bd, tl, td, s, z)
4275 +inflate_huft *tl, *td;
4276 +inflate_blocks_statef *s;
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 */
4293 + /* load input, output, bit values */
4296 + /* initialize masks */
4297 + ml = inflate_mask[bl];
4298 + md = inflate_mask[bd];
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)
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;
4318 + /* get extra bits for length */
4320 + c = t->base + ((uInt)b & inflate_mask[e]);
4322 + Tracevv((stderr, "inflate: * length %u\n", c));
4324 + /* decode distance base of block to copy */
4325 + GRABBITS(15); /* max bits for distance code */
4326 + e = (t = td + ((uInt)b & md))->exop;
4331 + /* get extra bits to add to distance base */
4333 + GRABBITS(e) /* get extra bits (up to 13) */
4334 + d = t->base + ((uInt)b & inflate_mask[e]);
4336 + Tracevv((stderr, "inflate: * distance %u\n", d));
4340 + if ((uInt)(q - s->window) >= d) /* offset before dest */
4343 + *q++ = *r++; c--; /* minimum count is three, */
4344 + *q++ = *r++; c--; /* so unroll loop a little */
4346 + else /* else offset after destination */
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, */
4352 + c -= e; /* copy to end of window */
4356 + r = s->window; /* copy rest from start of window */
4359 + do { /* copy all or what's left */
4364 + else if ((e & 64) == 0)
4365 + e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
4368 + z->msg = "invalid distance code";
4371 + return Z_DATA_ERROR;
4376 + if ((e & 64) == 0)
4378 + if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
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;
4391 + Tracevv((stderr, "inflate: * end of block\n"));
4394 + return Z_STREAM_END;
4398 + z->msg = "invalid literal/length code";
4401 + return Z_DATA_ERROR;
4404 + } while (m >= 258 && n >= 10);
4406 + /* not enough input or output--restore pointers and return */
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
4419 +/* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */
4421 +char *zlib_version = ZLIB_VERSION;
4423 +char *z_errmsg[] = {
4424 +"stream end", /* Z_STREAM_END 1 */
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) */
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
4440 +/* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */
4442 +#define BASE 65521L /* largest prime smaller than 65536 */
4444 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
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);
4452 +/* ========================================================================= */
4453 +uLong adler32(adler, buf, len)
4458 + unsigned long s1 = adler & 0xffff;
4459 + unsigned long s2 = (adler >> 16) & 0xffff;
4462 + if (buf == Z_NULL) return 1L;
4465 + k = len < NMAX ? len : NMAX;
4477 + return (s2 << 16) | s1;
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
4484 +# arch/mips/zboot/Makefile
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.
4490 +# Adapted for MIPS Pete Popov, Dan Malek
4492 +# Copyright (C) 1994 by Linus Torvalds
4493 +# Adapted for PowerPC by Gary Thomas
4494 +# modified by Cort (cort@cs.nmt.edu)
4498 + $(CC) $(CFLAGS) -S -o $*.s $<
4502 + $(CC) $(CFLAGS) -c -o $*.o $<
4504 + $(CPP) $(AFLAGS) -o $*.o $<
4506 + $(CC) $(AFLAGS) -c -o $*.o $<
4510 +CFLAGS += -D__BOOTER__ -I$(TOPDIR)/arch/$(ARCH)/zboot/include
4511 +AFLAGS += -D__BOOTER__
4513 +BOOT_TARGETS = zImage zImage.initrd zImage.flash zImage.initrd.flash
4518 +images/vmlinux.gz: $(TOPDIR)/vmlinux
4519 + $(MAKE) -C images vmlinux.gz
4521 +$(BOOT_TARGETS): lib/zlib.a images/vmlinux.gz
4522 +ifdef CONFIG_MIPS_PB1000
4523 + $(MAKE) -C pb1xxx $@
4525 +ifdef CONFIG_MIPS_PB1500
4526 + $(MAKE) -C pb1xxx $@
4528 +ifdef CONFIG_MIPS_PB1100
4529 + $(MAKE) -C pb1xxx $@
4531 +ifdef CONFIG_MIPS_PB1550
4532 + $(MAKE) -C pb1xxx $@
4534 +ifdef CONFIG_MIPS_DB1000
4535 + $(MAKE) -C pb1xxx $@
4537 +ifdef CONFIG_MIPS_DB1100
4538 + $(MAKE) -C pb1xxx $@
4540 +ifdef CONFIG_MIPS_DB1500
4541 + $(MAKE) -C pb1xxx $@
4543 +ifdef CONFIG_MIPS_BOSPORUS
4544 + $(MAKE) -C pb1xxx $@
4546 +ifdef CONFIG_MIPS_MIRAGE
4547 + $(MAKE) -C pb1xxx $@
4549 +ifdef CONFIG_MIPS_MTX1
4550 + $(MAKE) -C pb1xxx $@
4552 +ifdef CONFIG_COGENT_CSB250
4553 + $(MAKE) -C csb250 $@
4555 +ifdef CONFIG_MIPS_XXS1500
4561 + $(MAKE) -C common clean
4562 + $(MAKE) -C images clean
4563 + $(MAKE) -C pb1xxx clean
4564 + $(MAKE) -C xxs1500 clean
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
4572 + * arch/mips/kernel/head.S
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.
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.
4586 + * Head.S contains the MIPS exception handler and startup code.
4588 + **************************************************************************
4590 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
4592 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4593 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4594 + **************************************************************************
4596 +#include <linux/config.h>
4597 +#include <linux/threads.h>
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>
4606 +#define IndexInvalidate_I 0x00
4607 +#define IndexWriteBack_D 0x01
4616 + subu s8, ra, 8 /* Where we were loaded */
4617 + la sp, (.stack + 8192)
4619 + move s0, a0 /* Save boot rom start args */
4624 + la a0, start /* Where we were linked to run */
4631 + /* copy text section */
4648 + /* push the D-Cache and invalidate I-Cache */
4649 + li k0, 0x80000000 # start address
4650 + li k1, 0x80004000 # end address (16KB I-Cache)
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)
4669 + move a0, s8 /* load address */
4670 + move a1, t1 /* length in words */
4671 + move a2, t0 /* checksum */
4675 + la k0, decompress_kernel
4684 + li k0, KERNEL_ENTRY
4697 + li k0, 0x80000000 # start address
4698 + li k1, 0x80004000 # end address (16KB I-Cache)
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)
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
4724 +# arch/mips/zboot/pb1xxx/Makefile
4726 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
4727 +# All of the boot loader code was derived from the ppc
4730 +# Copyright 2001,2002 MontaVista Software Inc.
4732 +# Author: Mark A. Greer
4733 +# mgreer@mvista.com
4734 +# Ported and modified for mips support by
4735 +# Pete Popov <ppopov@mvista.com>
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.
4743 + $(CC) $(CFLAGS) -S -o $*.s $<
4747 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
4749 + $(CPP) $(AFLAGS) -o $*.o $<
4751 + $(CC) $(AFLAGS) -c -o $*.o $<
4753 +#########################################################################
4754 +# START BOARD SPECIFIC VARIABLES
4755 +ifdef CONFIG_MIPS_PB1000
4759 +ifdef CONFIG_MIPS_PB1100
4763 +ifdef CONFIG_MIPS_PB1500
4767 +ifdef CONFIG_MIPS_PB1550
4771 +ifdef CONFIG_MIPS_DB1000
4775 +ifdef CONFIG_MIPS_DB1100
4779 +ifdef CONFIG_MIPS_DB1500
4783 +ifdef CONFIG_MIPS_BOSPORUS
4787 +ifdef CONFIG_MIPS_MIRAGE
4791 +ifdef CONFIG_MIPS_MTX1
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
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
4806 +# This one must match the LOADADDR in arch/mips/Makefile!
4807 +LOADADDR=0x80100000
4808 +# END BOARD SPECIFIC VARIABLES
4809 +#########################################################################
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
4815 +ENTRY := ../utils/entry
4816 +OFFSET := ../utils/offset
4817 +SIZE := ../utils/size
4819 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
4820 +OBJCOPY_ARGS = -O elf32-tradlittlemips
4825 + rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
4827 +head.o: head.S $(TOPDIR)/vmlinux
4829 + -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
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
4839 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
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
4848 +# Here we manipulate the image in order to get it the necessary
4849 +# srecord file we need.
4851 + mv zvmlinux ../images/zImage.$(BNAME)
4852 + $(OBJCOPY) -O srec ../images/zImage.$(BNAME) ../images/$(BNAME).srec
4854 +zImage.flash: zImage
4855 + $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
4856 + ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
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
4865 +# grab the kernel_entry address from the vmlinux elf image
4866 +entry=`$1 $2 | grep kernel_entry`
4868 +fs=`echo $entry | grep ffffffff` # check toolchain output
4870 +if [ -n "$fs" ]; then
4871 + echo "0x"`$1 $2 | grep kernel_entry | cut -c9- | awk '{print $1}'`
4873 + echo "0x"`$1 $2 | grep kernel_entry | cut -c1- | awk '{print $1}'`
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
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
4888 +OFFSET=`$1 -h $2 | grep $3 | grep -v zvmlinux | awk '{print $3}'`
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
4895 + * arch/mips/kernel/head.S
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.
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.
4909 + * Head.S contains the MIPS exception handler and startup code.
4911 + **************************************************************************
4913 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
4915 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4916 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4917 + **************************************************************************
4919 +#include <linux/config.h>
4920 +#include <linux/threads.h>
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>
4929 +#define IndexInvalidate_I 0x00
4945 + li a1, FLASH_LOAD_ADDR
4950 + /* copy text section */
4967 + /* flush the I-Cache */
4968 + li k0, 0x80000000 # start address
4969 + li k1, 0x80004000 # end address (16KB I-Cache)
4974 + cache IndexInvalidate_I, 0(k0)
4975 + cache IndexInvalidate_I, 32(k0)
4976 + cache IndexInvalidate_I, 64(k0)
4977 + cache IndexInvalidate_I, 96(k0)
4984 + li a0, FLASH_LOAD_ADDR /* load address */
4985 + move a1, t1 /* length in words */
4986 + move a2, t0 /* checksum */
4990 + la k0, decompress_kernel
4999 + li k0, KERNEL_ENTRY
5012 + li k0, 0x80000000 # start address
5013 + li k1, 0x80004000 # end address (16KB I-Cache)
5018 + cache IndexInvalidate_I, 0(k0)
5019 + cache IndexInvalidate_I, 32(k0)
5020 + cache IndexInvalidate_I, 64(k0)
5021 + cache IndexInvalidate_I, 96(k0)
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
5039 + /* Read-only sections, merged into text segment: */
5040 + /* . = 0x81000000; */
5041 + .init : { *(.init) } =0
5048 + /* .gnu.warning sections are handled specially by elf32.em. */
5051 + .kstrtab : { *(.kstrtab) }
5053 + . = ALIGN(16); /* Exception table */
5054 + __start___ex_table = .;
5055 + __ex_table : { *(__ex_table) }
5056 + __stop___ex_table = .;
5058 + __start___dbe_table = .; /* Exception table for data bus errors */
5059 + __dbe_table : { *(__dbe_table) }
5060 + __stop___dbe_table = .;
5062 + __start___ksymtab = .; /* Kernel symbol table */
5063 + __ksymtab : { *(__ksymtab) }
5064 + __stop___ksymtab = .;
5069 + .data.init_task : { *(.data.init_task) }
5071 + /* Startup code */
5074 + .text.init : { *(.text.init) }
5075 + .data.init : { *(.data.init) }
5077 + __setup_start = .;
5078 + .setup.init : { *(.setup.init) }
5080 + __initcall_start = .;
5081 + .initcall.init : { *(.initcall.init) }
5082 + __initcall_end = .;
5083 + . = ALIGN(4096); /* Align double page for init_task_union */
5087 + .data.page_aligned : { *(.data.idt) }
5090 + .data.cacheline_aligned : { *(.data.cacheline_aligned) }
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:
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). */
5114 + /* Align the initial ramdisk image (INITRD) on page boundaries. */
5123 + .data1 : { *(.data1) }
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) }
5137 + PROVIDE (edata = .);
5141 + .sbss : { *(.sbss) *(.scommon) }
5149 + PROVIDE (end = .);
5152 + /* Sections to be discarded */
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) }
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
5186 +# arch/mips/compressed/alchemy/Makefile
5188 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
5189 +# All of the boot loader code was derived from the ppc
5192 +# Copyright 2001,2002 MontaVista Software Inc.
5194 +# Author: Mark A. Greer
5195 +# mgreer@mvista.com
5196 +# Ported and modified for mips support by
5197 +# Pete Popov <ppopov@mvista.com>
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.
5205 + $(CC) $(CFLAGS) -S -o $*.s $<
5209 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
5211 + $(CPP) $(AFLAGS) -o $*.o $<
5213 + $(CC) $(AFLAGS) -c -o $*.o $<
5215 +#########################################################################
5216 +# START BOARD SPECIFIC VARIABLES
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
5224 +RAM_LOAD_ADDR = 0x81000000
5225 +FLASH_LOAD_ADDR = 0xBF000000
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
5232 +# This one must match the LOADADDR in arch/mips/Makefile!
5233 +LOADADDR=0x80100000
5234 +# END BOARD SPECIFIC VARIABLES
5235 +#########################################################################
5237 +ZLINKFLAGS = -T ld.script -Ttext $(RAM_LOAD_ADDR)
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
5243 +ENTRY := ../utils/entry
5244 +OFFSET := ../utils/offset
5245 +SIZE := ../utils/size
5250 + rm -rf *.o vmlinux* zvmlinux.*
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 ) \
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
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 \
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) \
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 \
5292 + $(OBJCOPY) --adjust-section-vma=image+$(RAM_LOAD_ADDR) $@
5293 + $(OBJCOPY) --adjust-section-vma=image+$(shell sh $(OFFSET) \
5294 + $(OBJDUMP) $@.no image ) $@
5299 +# Here we manipulate the image in order to get it the necessary
5300 +# srecord file we need.
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
5308 +include $(TOPDIR)/Rules.make