1 diff -Naru linux/arch/mips/Makefile linux-new/arch/mips/Makefile
2 --- linux/arch/mips/Makefile 2003-10-22 02:58:37.000000000 -0400
3 +++ linux-new/arch/mips/Makefile 2003-12-18 14:26:20.000000000 -0500
7 MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
8 +MAKEZBOOT = $(MAKE) -C arch/$(ARCH)/zboot
9 +BOOT_TARGETS = zImage zImage.initrd zImage.flash
11 vmlinux.ecoff: vmlinux
14 + $(BOOT_TARGETS): vmlinux
23 rm -f arch/$(ARCH)/ld.script
24 $(MAKE) -C arch/$(ARCH)/tools clean
25 $(MAKE) -C arch/mips/baget clean
26 diff -Naru linux/arch/mips/zboot/common/au1k_uart.c linux-new/arch/mips/zboot/common/au1k_uart.c
27 --- linux/arch/mips/zboot/common/au1k_uart.c 1969-12-31 19:00:00.000000000 -0500
28 +++ linux-new/arch/mips/zboot/common/au1k_uart.c 2003-12-18 14:26:20.000000000 -0500
31 + * BRIEF MODULE DESCRIPTION
32 + * Simple Au1000 uart routines.
34 + * Copyright 2001 MontaVista Software Inc.
35 + * Author: MontaVista Software, Inc.
36 + * ppopov@mvista.com or source@mvista.com
38 + * This program is free software; you can redistribute it and/or modify it
39 + * under the terms of the GNU General Public License as published by the
40 + * Free Software Foundation; either version 2 of the License, or (at your
41 + * option) any later version.
43 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
44 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
46 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
50 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 + * You should have received a copy of the GNU General Public License along
55 + * with this program; if not, write to the Free Software Foundation, Inc.,
56 + * 675 Mass Ave, Cambridge, MA 02139, USA.
58 +#include <linux/config.h>
60 +#include <asm/au1000.h>
63 +typedef unsigned char uint8;
64 +typedef unsigned int uint32;
66 +#define UART16550_BAUD_2400 2400
67 +#define UART16550_BAUD_4800 4800
68 +#define UART16550_BAUD_9600 9600
69 +#define UART16550_BAUD_19200 19200
70 +#define UART16550_BAUD_38400 38400
71 +#define UART16550_BAUD_57600 57600
72 +#define UART16550_BAUD_115200 115200
74 +#define UART16550_PARITY_NONE 0
75 +#define UART16550_PARITY_ODD 0x08
76 +#define UART16550_PARITY_EVEN 0x18
77 +#define UART16550_PARITY_MARK 0x28
78 +#define UART16550_PARITY_SPACE 0x38
80 +#define UART16550_DATA_5BIT 0x0
81 +#define UART16550_DATA_6BIT 0x1
82 +#define UART16550_DATA_7BIT 0x2
83 +#define UART16550_DATA_8BIT 0x3
85 +#define UART16550_STOP_1BIT 0x0
86 +#define UART16550_STOP_2BIT 0x4
88 +/* It would be nice if we had a better way to do this.
89 + * It could be a variable defined in one of the board specific files.
92 +#ifdef CONFIG_COGENT_CSB250
93 +#define UART_BASE UART3_ADDR
95 +#define UART_BASE UART0_ADDR
98 +/* memory-mapped read/write of the port */
99 +#define UART16550_READ(y) (readl(UART_BASE + y) & 0xff)
100 +#define UART16550_WRITE(y,z) (writel(z&0xff, UART_BASE + y))
103 + * We use uart 0, which is already initialized by
106 +volatile struct NS16550 *
107 +serial_init(int chan)
109 + volatile struct NS16550 *com_port;
110 + com_port = (struct NS16550 *) UART_BASE;
115 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
117 + while ((UART16550_READ(UART_LSR)&0x40) == 0);
118 + UART16550_WRITE(UART_TX, c);
122 +serial_getc(volatile struct NS16550 *com_port)
124 + while((UART16550_READ(UART_LSR) & 0x1) == 0);
125 + return UART16550_READ(UART_RX);
129 +serial_tstc(volatile struct NS16550 *com_port)
131 + return((UART16550_READ(UART_LSR) & LSR_DR) != 0);
133 diff -Naru linux/arch/mips/zboot/common/ctype.c linux-new/arch/mips/zboot/common/ctype.c
134 --- linux/arch/mips/zboot/common/ctype.c 1969-12-31 19:00:00.000000000 -0500
135 +++ linux-new/arch/mips/zboot/common/ctype.c 2003-12-18 14:26:20.000000000 -0500
138 + * linux/lib/ctype.c
140 + * Copyright (C) 1991, 1992 Linus Torvalds
143 +#include <linux/ctype.h>
145 +unsigned char _ctype[] = {
146 +_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
147 +_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
148 +_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
149 +_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
150 +_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
151 +_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
152 +_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
153 +_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
154 +_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
155 +_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
156 +_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
157 +_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
158 +_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
159 +_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
160 +_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
161 +_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
162 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
163 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
164 +_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
165 +_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
166 +_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
167 +_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
168 +_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
169 +_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
172 diff -Naru linux/arch/mips/zboot/common/dummy.c linux-new/arch/mips/zboot/common/dummy.c
173 --- linux/arch/mips/zboot/common/dummy.c 1969-12-31 19:00:00.000000000 -0500
174 +++ linux-new/arch/mips/zboot/common/dummy.c 2003-12-18 14:26:20.000000000 -0500
180 diff -Naru linux/arch/mips/zboot/common/Makefile linux-new/arch/mips/zboot/common/Makefile
181 --- linux/arch/mips/zboot/common/Makefile 1969-12-31 19:00:00.000000000 -0500
182 +++ linux-new/arch/mips/zboot/common/Makefile 2003-12-18 14:26:20.000000000 -0500
185 +# arch/mips/zboot/common/Makefile
187 +# This file is subject to the terms and conditions of the GNU General Public
188 +# License. See the file "COPYING" in the main directory of this archive
191 +# Tom Rini January 2001
195 + $(CC) $(CFLAGS) -S -o $*.s $<
199 + $(CC) $(CFLAGS) -c -o $*.o $<
201 + $(CPP) $(AFLAGS) -o $*.o $<
203 + $(CC) $(AFLAGS) -c -o $*.o $<
208 +OBJCOPY_ARGS = -O elf32-tradlittlemips
210 +include $(TOPDIR)/Rules.make
211 diff -Naru linux/arch/mips/zboot/common/misc-common.c linux-new/arch/mips/zboot/common/misc-common.c
212 --- linux/arch/mips/zboot/common/misc-common.c 1969-12-31 19:00:00.000000000 -0500
213 +++ linux-new/arch/mips/zboot/common/misc-common.c 2003-12-18 14:26:20.000000000 -0500
216 + * arch/mips/zboot/common/misc-common.c
218 + * Misc. bootloader code (almost) all platforms can use
220 + * Author: Johnnie Peters <jpeters@mvista.com>
221 + * Editor: Tom Rini <trini@mvista.com>
223 + * Derived from arch/ppc/boot/prep/misc.c
225 + * Ported by Pete Popov <ppopov@mvista.com> to
226 + * support mips board(s). I also got rid of the vga console
229 + * Copyright 2000-2001 MontaVista Software Inc.
231 + * This program is free software; you can redistribute it and/or modify it
232 + * under the terms of the GNU General Public License as published by the
233 + * Free Software Foundation; either version 2 of the License, or (at your
234 + * option) any later version.
236 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
237 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
238 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
239 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
240 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
242 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
243 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
245 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
247 + * You should have received a copy of the GNU General Public License along
248 + * with this program; if not, write to the Free Software Foundation, Inc.,
249 + * 675 Mass Ave, Cambridge, MA 02139, USA.
252 +#include <linux/config.h>
256 +extern char *avail_ram;
257 +extern char *end_avail;
260 +void puts(const char *);
261 +void putc(const char c);
262 +void puthex(unsigned long val);
263 +void _bcopy(char *src, char *dst, int len);
264 +void gunzip(void *, int, unsigned char *, int *);
265 +static int _cvt(unsigned long val, char *buf, long radix, char *digits);
267 +void _vprintk(void(*)(const char), const char *, va_list ap);
269 +struct NS16550 *com_port;
271 +int serial_tstc(volatile struct NS16550 *);
272 +unsigned char serial_getc(volatile struct NS16550 *);
273 +void serial_putc(volatile struct NS16550 *, unsigned char);
288 + return (serial_tstc(com_port));
294 + if (serial_tstc(com_port))
295 + return (serial_getc(com_port));
304 + serial_putc(com_port, c);
306 + serial_putc(com_port, '\r');
309 +void puts(const char *s)
312 + while ( ( c = *s++ ) != '\0' ) {
313 + serial_putc(com_port, c);
314 + if ( c == '\n' ) serial_putc(com_port, '\r');
322 + puts("\n\n -- System halted");
324 + while(1); /* Halt */
327 +void *zalloc(void *x, unsigned items, unsigned size)
329 + void *p = avail_ram;
332 + size = (size + 7) & -8;
334 + if (avail_ram > end_avail) {
335 + puts("oops... out of memory\n");
341 +void zfree(void *x, void *addr, unsigned nb)
346 +#define EXTRA_FIELD 4
348 +#define COMMENT 0x10
349 +#define RESERVED 0xe0
353 +void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
361 + if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
362 + puts("bad gzipped data\n");
365 + if ((flags & EXTRA_FIELD) != 0)
366 + i = 12 + src[10] + (src[11] << 8);
367 + if ((flags & ORIG_NAME) != 0)
368 + while (src[i++] != 0)
370 + if ((flags & COMMENT) != 0)
371 + while (src[i++] != 0)
373 + if ((flags & HEAD_CRC) != 0)
376 + puts("gunzip: ran out of data in header\n");
382 + r = inflateInit2(&s, -MAX_WBITS);
384 + puts("inflateInit2 returned %d\n");
387 + s.next_in = src + i;
388 + s.avail_in = *lenp - i;
390 + s.avail_out = dstlen;
391 + r = inflate(&s, Z_FINISH);
392 + if (r != Z_OK && r != Z_STREAM_END) {
393 + puts("inflate returned %d\n");
396 + *lenp = s.next_out - (unsigned char *) dst;
401 +puthex(unsigned long val)
404 + unsigned char buf[10];
406 + for (i = 7; i >= 0; i--)
408 + buf[i] = "0123456789ABCDEF"[val & 0x0F];
419 +_printk(char const *fmt, ...)
424 + _vprintk(putc, fmt, ap);
429 +#define is_digit(c) ((c >= '0') && (c <= '9'))
432 +_vprintk(void(*putc)(const char), const char *fmt0, va_list ap)
434 + char c, sign, *cp = 0;
435 + int left_prec, right_prec, zero_fill, length = 0, pad, pad_on_right;
438 + while ((c = *fmt0++))
443 + left_prec = right_prec = pad_on_right = 0;
457 + while (is_digit(c))
459 + left_prec = (left_prec * 10) + (c - '0');
466 + while (is_digit(c))
468 + right_prec = (right_prec * 10) + (c - '0');
473 + right_prec = left_prec;
481 + val = va_arg(ap, long);
490 + length = _cvt(val, buf, 10, "0123456789");
493 + length = _cvt(val, buf, 16, "0123456789abcdef");
496 + length = _cvt(val, buf, 16, "0123456789ABCDEF");
502 + cp = va_arg(ap, char *);
503 + length = strlen(cp);
506 + c = va_arg(ap, long /*char*/);
512 + pad = left_prec - length;
540 + while (length-- > 0)
542 + (*putc)(c = *cp++);
567 +_cvt(unsigned long val, char *buf, long radix, char *digits)
573 + { /* Special case */
578 + *cp++ = digits[val % radix];
591 +_dump_buf_with_offset(unsigned char *p, int s, unsigned char *base)
594 + if ((unsigned int)s > (unsigned int)p)
596 + s = (unsigned int)s - (unsigned int)p;
602 + _printk("%06X: ", (int)p - (int)base);
605 + _printk("%06X: ", p);
607 + for (i = 0; i < 16; i++)
611 + _printk("%02X", p[i] & 0xFF);
616 + if ((i % 2) == 1) _printk(" ");
617 + if ((i % 8) == 7) _printk(" ");
620 + for (i = 0; i < 16; i++)
625 + if ((c < 0x20) || (c >= 0x7F)) c = '.';
639 +_dump_buf(unsigned char *p, int s)
642 + _dump_buf_with_offset(p, s, 0);
647 + * c-indent-level: 8
648 + * c-basic-offset: 8
652 diff -Naru linux/arch/mips/zboot/common/misc-simple.c linux-new/arch/mips/zboot/common/misc-simple.c
653 --- linux/arch/mips/zboot/common/misc-simple.c 1969-12-31 19:00:00.000000000 -0500
654 +++ linux-new/arch/mips/zboot/common/misc-simple.c 2003-12-18 14:26:20.000000000 -0500
657 + * arch/mips/zboot/common/misc-simple.c
659 + * Misc. bootloader code for many machines. This assumes you have are using
660 + * a 6xx/7xx/74xx CPU in your machine. This assumes the chunk of memory
661 + * below 8MB is free. Finally, it assumes you have a NS16550-style uart for
662 + * your serial console. If a machine meets these requirements, it can quite
663 + * likely use this code during boot.
665 + * Author: Matt Porter <mporter@mvista.com>
666 + * Derived from arch/ppc/boot/prep/misc.c
668 + * Copyright 2001 MontaVista Software Inc.
670 + * This program is free software; you can redistribute it and/or modify it
671 + * under the terms of the GNU General Public License as published by the
672 + * Free Software Foundation; either version 2 of the License, or (at your
673 + * option) any later version.
676 +#include <linux/types.h>
677 +#include <linux/elf.h>
678 +#include <linux/config.h>
680 +#include <asm/page.h>
681 +#include <asm/processor.h>
682 +#include <asm/mmu.h>
686 +extern struct NS16550 *com_port;
693 +#ifdef CONFIG_CMDLINE
694 +#define CMDLINE CONFIG_CMDLINE
698 +char cmd_preset[] = CMDLINE;
700 +char *cmd_line = cmd_buf;
702 +/* The linker tells us where the image is.
704 +extern unsigned char __image_begin, __image_end;
705 +extern unsigned char __ramdisk_begin, __ramdisk_end;
706 +unsigned long initrd_size;
708 +extern void puts(const char *);
709 +extern void putc(const char c);
710 +extern void puthex(unsigned long val);
711 +extern void *memcpy(void * __dest, __const void * __src,
712 + __kernel_size_t __n);
713 +extern void gunzip(void *, int, unsigned char *, int *);
714 +extern void udelay(long delay);
715 +extern int tstc(void);
716 +extern int getc(void);
717 +extern volatile struct NS16550 *serial_init(int chan);
720 +decompress_kernel(unsigned long load_addr, int num_words,
721 + unsigned long cksum, unsigned long *sp)
724 + extern unsigned long start;
729 + com_port = (struct NS16550 *)serial_init(0);
731 + initrd_size = (unsigned long)(&__ramdisk_end) -
732 + (unsigned long)(&__ramdisk_begin);
735 + * Reveal where we were loaded at and where we
736 + * were relocated to.
738 + puts("loaded at: "); puthex(load_addr);
739 + puts(" "); puthex((unsigned long)(load_addr + (4*num_words))); puts("\n");
740 + if ( (unsigned long)load_addr != (unsigned long)&start )
742 + puts("relocated to: "); puthex((unsigned long)&start);
744 + puthex((unsigned long)((unsigned long)&start + (4*num_words)));
749 + * We link ourself to an arbitrary low address. When we run, we
750 + * relocate outself to that address. __image_being points to
751 + * the part of the image where the zImage is. -- Tom
753 + zimage_start = (char *)(unsigned long)(&__image_begin);
754 + zimage_size = (unsigned long)(&__image_end) -
755 + (unsigned long)(&__image_begin);
758 + * The zImage and initrd will be between start and _end, so they've
759 + * already been moved once. We're good to go now. -- Tom
761 + puts("zimage at: "); puthex((unsigned long)zimage_start);
762 + puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
765 + if ( initrd_size ) {
766 + puts("initrd at: ");
767 + puthex((unsigned long)(&__ramdisk_begin));
768 + puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
771 + /* assume the chunk below 8M is free */
772 + avail_ram = (char *)AVAIL_RAM_START;
773 + end_avail = (char *)AVAIL_RAM_END;
775 + /* Display standard Linux/MIPS boot prompt for kernel args */
776 + puts("Uncompressing Linux at load address ");
779 + /* I don't like this hard coded gunzip size (fixme) */
780 + gunzip((void *)LOADADDR, 0x400000, zimage_start, &zimage_size);
781 + puts("Now booting the kernel\n");
783 diff -Naru linux/arch/mips/zboot/common/no_initrd.c linux-new/arch/mips/zboot/common/no_initrd.c
784 --- linux/arch/mips/zboot/common/no_initrd.c 1969-12-31 19:00:00.000000000 -0500
785 +++ linux-new/arch/mips/zboot/common/no_initrd.c 2003-12-18 14:26:20.000000000 -0500
787 +char initrd_data[1];
789 diff -Naru linux/arch/mips/zboot/common/ns16550.c linux-new/arch/mips/zboot/common/ns16550.c
790 --- linux/arch/mips/zboot/common/ns16550.c 1969-12-31 19:00:00.000000000 -0500
791 +++ linux-new/arch/mips/zboot/common/ns16550.c 2003-12-18 14:26:20.000000000 -0500
797 +#include <linux/config.h>
798 +#include <asm/serial.h>
799 +#include "ns16550.h"
801 +typedef struct NS16550 *NS16550_t;
803 +const NS16550_t COM_PORTS[] = { (NS16550_t) COM1,
806 + (NS16550_t) COM4 };
808 +volatile struct NS16550 *
809 +serial_init(int chan)
811 + volatile struct NS16550 *com_port;
812 + com_port = (struct NS16550 *) COM_PORTS[chan];
813 + /* See if port is present */
814 + com_port->lcr = 0x00;
815 + com_port->ier = 0xFF;
817 + if (com_port->ier != 0x0F) return ((struct NS16550 *)0);
819 + com_port->ier = 0x00;
820 + com_port->lcr = 0x80; /* Access baud rate */
821 +#ifdef CONFIG_SERIAL_CONSOLE_NONSTD
822 + com_port->dll = (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD);
823 + com_port->dlm = (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD) >> 8;
825 + com_port->lcr = 0x03; /* 8 data, 1 stop, no parity */
826 + com_port->mcr = 0x03; /* RTS/DTR */
827 + com_port->fcr = 0x07; /* Clear & enable FIFOs */
832 +serial_putc(volatile struct NS16550 *com_port, unsigned char c)
834 + while ((com_port->lsr & LSR_THRE) == 0) ;
839 +serial_getc(volatile struct NS16550 *com_port)
841 + while ((com_port->lsr & LSR_DR) == 0) ;
842 + return (com_port->rbr);
846 +serial_tstc(volatile struct NS16550 *com_port)
848 + return ((com_port->lsr & LSR_DR) != 0);
850 --- linux/arch/mips/zboot/common/string.c 1969-12-31 19:00:00.000000000 -0500
851 +++ linux-new/arch/mips/zboot/common/string.c 2003-12-18 17:11:10.000000000 -0500
854 + * linux/lib/string.c
856 + * Copyright (C) 1991, 1992 Linus Torvalds
860 + * stupid library routines.. The optimized versions should generally be found
861 + * as inline code in <asm-xx/string.h>
863 + * These are buggy as well..
865 + * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
866 + * - Added strsep() which will replace strtok() soon (because strsep() is
867 + * reentrant and should be faster). Use only strsep() in new code, please.
870 +#include <linux/types.h>
871 +#include <linux/string.h>
872 +#include <linux/ctype.h>
875 + * strnicmp - Case insensitive, length-limited string comparison
877 + * @s2: The other string
878 + * @len: the maximum number of characters to compare
880 +int strnicmp(const char *s1, const char *s2, size_t len)
882 + /* Yes, Virginia, it had better be unsigned */
883 + unsigned char c1, c2;
888 + c1 = *s1; c2 = *s2;
902 + return (int)c1 - (int)c2;
907 +#ifndef __HAVE_ARCH_STRCPY
909 + * strcpy - Copy a %NUL terminated string
910 + * @dest: Where to copy the string to
911 + * @src: Where to copy the string from
913 +char * strcpy(char * dest,const char *src)
917 + while ((*dest++ = *src++) != '\0')
923 +#ifndef __HAVE_ARCH_STRNCPY
925 + * strncpy - Copy a length-limited, %NUL-terminated string
926 + * @dest: Where to copy the string to
927 + * @src: Where to copy the string from
928 + * @count: The maximum number of bytes to copy
930 + * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
931 + * However, the result is not %NUL-terminated if the source exceeds
934 +char * strncpy(char * dest,const char *src,size_t count)
938 + while (count-- && (*dest++ = *src++) != '\0')
946 + * strcat - Append one %NUL-terminated string to another
947 + * @dest: The string to be appended to
948 + * @src: The string to append to it
950 +char * strcat(char * dest, const char * src)
956 + while ((*dest++ = *src++) != '\0')
963 + * strncat - Append a length-limited, %NUL-terminated string to another
964 + * @dest: The string to be appended to
965 + * @src: The string to append to it
966 + * @count: The maximum numbers of bytes to copy
968 + * Note that in contrast to strncpy, strncat ensures the result is
971 +char * strncat(char *dest, const char *src, size_t count)
978 + while ((*dest++ = *src++)) {
979 + if (--count == 0) {
989 +#ifndef __HAVE_ARCH_STRCMP
991 + * strcmp - Compare two strings
993 + * @ct: Another string
995 +int strcmp(const char * cs,const char * ct)
997 + register signed char __res;
1000 + if ((__res = *cs - *ct++) != 0 || !*cs++)
1008 +#ifndef __HAVE_ARCH_STRNCMP
1010 + * strncmp - Compare two length-limited strings
1012 + * @ct: Another string
1013 + * @count: The maximum number of bytes to compare
1015 +int strncmp(const char * cs,const char * ct,size_t count)
1017 + register signed char __res = 0;
1020 + if ((__res = *cs - *ct++) != 0 || !*cs++)
1030 + * strchr - Find the first occurrence of a character in a string
1031 + * @s: The string to be searched
1032 + * @c: The character to search for
1034 +char * strchr(const char * s, int c)
1036 + for(; *s != (char) c; ++s)
1039 + return (char *) s;
1043 + * strrchr - Find the last occurrence of a character in a string
1044 + * @s: The string to be searched
1045 + * @c: The character to search for
1047 +char * strrchr(const char * s, int c)
1049 + const char *p = s + strlen(s);
1051 + if (*p == (char)c)
1053 + } while (--p >= s);
1058 + * strlen - Find the length of a string
1059 + * @s: The string to be sized
1061 +size_t strlen(const char * s)
1065 + for (sc = s; *sc != '\0'; ++sc)
1071 + * strnlen - Find the length of a length-limited string
1072 + * @s: The string to be sized
1073 + * @count: The maximum number of bytes to search
1075 +size_t strnlen(const char * s, size_t count)
1079 + for (sc = s; count-- && *sc != '\0'; ++sc)
1085 + * strspn - Calculate the length of the initial substring of @s which only
1086 + * contain letters in @accept
1087 + * @s: The string to be searched
1088 + * @accept: The string to search for
1090 +size_t strspn(const char *s, const char *accept)
1096 + for (p = s; *p != '\0'; ++p) {
1097 + for (a = accept; *a != '\0'; ++a) {
1110 + * strpbrk - Find the first occurrence of a set of characters
1111 + * @cs: The string to be searched
1112 + * @ct: The characters to search for
1114 +char * strpbrk(const char * cs,const char * ct)
1116 + const char *sc1,*sc2;
1118 + for( sc1 = cs; *sc1 != '\0'; ++sc1) {
1119 + for( sc2 = ct; *sc2 != '\0'; ++sc2) {
1121 + return (char *) sc1;
1128 + * strtok - Split a string into tokens
1129 + * @s: The string to be searched
1130 + * @ct: The characters to search for
1132 + * WARNING: strtok is deprecated, use strsep instead.
1134 +char * strtok(char * s,const char * ct)
1136 + char *sbegin, *send;
1138 + sbegin = s ? s : ___strtok;
1142 + sbegin += strspn(sbegin,ct);
1143 + if (*sbegin == '\0') {
1147 + send = strpbrk( sbegin, ct);
1148 + if (send && *send != '\0')
1155 + * strsep - Split a string into tokens
1156 + * @s: The string to be searched
1157 + * @ct: The characters to search for
1159 + * strsep() updates @s to point after the token, ready for the next call.
1161 + * It returns empty tokens, too, behaving exactly like the libc function
1162 + * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
1163 + * Same semantics, slimmer shape. ;)
1165 +char * strsep(char **s, const char *ct)
1167 + char *sbegin = *s, *end;
1169 + if (sbegin == NULL)
1172 + end = strpbrk(sbegin, ct);
1181 + * memset - Fill a region of memory with the given value
1182 + * @s: Pointer to the start of the area.
1183 + * @c: The byte to fill the area with
1184 + * @count: The size of the area.
1186 + * Do not use memset() to access IO space, use memset_io() instead.
1188 +void * memset(void * s,int c, size_t count)
1190 + char *xs = (char *) s;
1199 + * bcopy - Copy one area of memory to another
1200 + * @src: Where to copy from
1201 + * @dest: Where to copy to
1202 + * @count: The size of the area.
1204 + * Note that this is the same as memcpy(), with the arguments reversed.
1205 + * memcpy() is the standard, bcopy() is a legacy BSD function.
1207 + * You should not use this function to access IO space, use memcpy_toio()
1208 + * or memcpy_fromio() instead.
1210 +char * bcopy(const char * src, char * dest, int count)
1221 + * memcpy - Copy one area of memory to another
1222 + * @dest: Where to copy to
1223 + * @src: Where to copy from
1224 + * @count: The size of the area.
1226 + * You should not use this function to access IO space, use memcpy_toio()
1227 + * or memcpy_fromio() instead.
1229 +void * memcpy(void * dest,const void *src,size_t count)
1231 + char *tmp = (char *) dest, *s = (char *) src;
1240 + * memmove - Copy one area of memory to another
1241 + * @dest: Where to copy to
1242 + * @src: Where to copy from
1243 + * @count: The size of the area.
1245 + * Unlike memcpy(), memmove() copes with overlapping areas.
1247 +void * memmove(void * dest,const void *src,size_t count)
1251 + if (dest <= src) {
1252 + tmp = (char *) dest;
1258 + tmp = (char *) dest + count;
1259 + s = (char *) src + count;
1268 + * memcmp - Compare two areas of memory
1269 + * @cs: One area of memory
1270 + * @ct: Another area of memory
1271 + * @count: The size of the area.
1273 +int memcmp(const void * cs,const void * ct,size_t count)
1275 + const unsigned char *su1, *su2;
1276 + signed char res = 0;
1278 + for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
1279 + if ((res = *su1 - *su2) != 0)
1284 +#ifndef __HAVE_ARCH_MEMSCAN
1286 + * memscan - Find a character in an area of memory.
1287 + * @addr: The memory area
1288 + * @c: The byte to search for
1289 + * @size: The size of the area.
1291 + * returns the address of the first occurrence of @c, or 1 byte past
1292 + * the area if @c is not found
1294 +void * memscan(void * addr, int c, size_t size)
1296 + unsigned char * p = (unsigned char *) addr;
1297 + unsigned char * e = p + size;
1301 + return (void *) p;
1305 + return (void *) p;
1310 + * strstr - Find the first substring in a %NUL terminated string
1311 + * @s1: The string to be searched
1312 + * @s2: The string to search for
1314 +char * strstr(const char * s1,const char * s2)
1320 + return (char *) s1;
1322 + while (l1 >= l2) {
1324 + if (!memcmp(s1,s2,l2))
1325 + return (char *) s1;
1332 + * memchr - Find a character in an area of memory.
1333 + * @s: The memory area
1334 + * @c: The byte to search for
1335 + * @n: The size of the area.
1337 + * returns the address of the first occurrence of @c, or %NULL
1338 + * if @c is not found
1340 +void *memchr(const void *s, int c, size_t n)
1342 + const unsigned char *p = s;
1343 + while (n-- != 0) {
1344 + if ((unsigned char)c == *p++) {
1345 + return (void *)(p-1);
1350 diff -Naru linux/arch/mips/zboot/csb250/head.S linux-new/arch/mips/zboot/csb250/head.S
1351 --- linux/arch/mips/zboot/csb250/head.S 1969-12-31 19:00:00.000000000 -0500
1352 +++ linux-new/arch/mips/zboot/csb250/head.S 2003-12-18 14:26:20.000000000 -0500
1355 + * arch/mips/kernel/head.S
1357 + * This file is subject to the terms and conditions of the GNU General Public
1358 + * License. See the file "COPYING" in the main directory of this archive
1359 + * for more details.
1361 + * Copyright (C) 1994, 1995 Waldorf Electronics
1362 + * Written by Ralf Baechle and Andreas Busse
1363 + * Copyright (C) 1995 - 1999 Ralf Baechle
1364 + * Copyright (C) 1996 Paul M. Antoine
1365 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
1366 + * Further modifications by David S. Miller and Harald Koerfgen
1367 + * Copyright (C) 1999 Silicon Graphics, Inc.
1369 + * Head.S contains the MIPS exception handler and startup code.
1371 + **************************************************************************
1373 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
1375 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
1376 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
1377 + **************************************************************************
1379 +#include <linux/config.h>
1380 +#include <linux/threads.h>
1382 +#include <asm/asm.h>
1383 +#include <asm/cacheops.h>
1384 +#include <asm/mipsregs.h>
1385 +#include <asm/offset.h>
1386 +#include <asm/cachectl.h>
1387 +#include <asm/regdef.h>
1389 +#define IndexInvalidate_I 0x00
1390 +#define IndexWriteBack_D 0x01
1399 + .globl asize /* Someday we'll put the initrd info here. */
1406 + subu s8, ra, 8 /* Where we were loaded */
1407 + la sp, (.stack + 8192)
1409 + move s0, a0 /* Save boot rom start args */
1414 + la a0, start /* Where we were linked to run */
1421 + /* copy text section */
1438 + /* push the D-Cache and invalidate I-Cache */
1439 + li k0, 0x80000000 # start address
1440 + li k1, 0x80004000 # end address (16KB I-Cache)
1445 + cache IndexWriteBack_D, 0(k0)
1446 + cache IndexWriteBack_D, 32(k0)
1447 + cache IndexWriteBack_D, 64(k0)
1448 + cache IndexWriteBack_D, 96(k0)
1449 + cache IndexInvalidate_I, 0(k0)
1450 + cache IndexInvalidate_I, 32(k0)
1451 + cache IndexInvalidate_I, 64(k0)
1452 + cache IndexInvalidate_I, 96(k0)
1459 +/* move a0, s8 /* load address */
1460 + subu a0, s8, 0x1000 /* load address */
1461 + move a1, t1 /* length in words */
1462 + move a2, t0 /* checksum */
1466 + la k0, decompress_kernel
1471 + la a2, __ramdisk_begin
1472 + la a3, initrd_size
1475 + li k0, KERNEL_ENTRY
1488 + li k0, 0x80000000 # start address
1489 + li k1, 0x80004000 # end address (16KB I-Cache)
1494 + cache IndexWriteBack_D, 0(k0)
1495 + cache IndexWriteBack_D, 32(k0)
1496 + cache IndexWriteBack_D, 64(k0)
1497 + cache IndexWriteBack_D, 96(k0)
1498 + cache IndexInvalidate_I, 0(k0)
1499 + cache IndexInvalidate_I, 32(k0)
1500 + cache IndexInvalidate_I, 64(k0)
1501 + cache IndexInvalidate_I, 96(k0)
1510 + .comm .stack,4096*2,4
1511 diff -Naru linux/arch/mips/zboot/csb250/Makefile linux-new/arch/mips/zboot/csb250/Makefile
1512 --- linux/arch/mips/zboot/csb250/Makefile 1969-12-31 19:00:00.000000000 -0500
1513 +++ linux-new/arch/mips/zboot/csb250/Makefile 2003-12-18 14:26:20.000000000 -0500
1515 +# arch/mips/zboot/pb1xxx/Makefile
1517 +# Makefile for Cogent CSB250 Au1500 board.
1518 +# All of the boot loader code was derived from the ppc
1521 +# This program is free software; you can redistribute it and/or modify it
1522 +# under the terms of the GNU General Public License as published by the
1523 +# Free Software Foundation; either version 2 of the License, or (at your
1524 +# option) any later version.
1527 + $(CC) $(CFLAGS) -S -o $*.s $<
1531 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
1533 + $(CPP) $(AFLAGS) -o $*.o $<
1535 + $(CC) $(AFLAGS) -c -o $*.o $<
1537 +#########################################################################
1538 +# START BOARD SPECIFIC VARIABLES
1541 +# These two variables control where the zImage is stored
1542 +# in flash and loaded in memory. It only controls how the srec
1543 +# file is generated, the code is the same.
1544 +RAM_RUN_ADDR = 0x80a00000
1545 +FLASH_LOAD_ADDR = 0xBFD00000
1547 +# These two variables specify the free ram region
1548 +# that can be used for temporary malloc area
1549 +AVAIL_RAM_START=0x80400000
1550 +AVAIL_RAM_END=0x80800000
1552 +# This one must match the LOADADDR in arch/mips/Makefile!
1553 +LOADADDR=0x80100000
1554 +# END BOARD SPECIFIC VARIABLES
1555 +#########################################################################
1557 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
1558 + ../common/au1k_uart.o ../common/string.o ../common/ctype.o
1559 +LIBS := ../lib/zlib.a
1561 +ENTRY := ../utils/entry
1562 +OFFSET := ../utils/offset
1563 +SIZE := ../utils/size
1565 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
1566 +OBJCOPY_ARGS = -O elf32-tradbigmips
1571 + rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
1573 +head.o: head.S $(TOPDIR)/vmlinux
1575 + -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
1578 +../common/misc-simple.o:
1579 + $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
1580 + -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
1581 + -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
1582 + -DLOADADDR=$(LOADADDR) \
1583 + -DZIMAGE_SIZE=0 -c -o $@ $*.c
1585 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
1587 + --add-section=.image=../images/vmlinux.gz \
1588 + --set-section-flags=.image=contents,alloc,load,readonly,data \
1589 + ../common/dummy.o image.o
1590 + $(LD) $(LD_ARGS) -o $@ $(OBJECTS) image.o $(LIBS)
1591 + $(OBJCOPY) $(OBJCOPY_ARGS) $@ $@ -R .comment -R .stab -R .stabstr \
1592 + -R .initrd -R .sysmap
1594 +# Here we manipulate the image in order to get it the necessary
1595 +# srecord file we need.
1597 + mv zvmlinux ../images/zImage.$(BNAME)
1598 + $(OBJCOPY) -O binary ../images/zImage.$(BNAME) ../images/$(BNAME).bin
1600 +zImage.flash: zImage
1601 + $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
1602 + ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
1604 +include $(TOPDIR)/Rules.make
1605 diff -Naru linux/arch/mips/zboot/images/Makefile linux-new/arch/mips/zboot/images/Makefile
1606 --- linux/arch/mips/zboot/images/Makefile 1969-12-31 19:00:00.000000000 -0500
1607 +++ linux-new/arch/mips/zboot/images/Makefile 2003-12-18 14:26:20.000000000 -0500
1610 +include $(TOPDIR)/Rules.make
1612 +vmlinux.gz: $(TOPDIR)/vmlinux
1613 + $(OBJCOPY) -S -O binary $(TOPDIR)/vmlinux vmlinux
1617 + rm -f vmlinux.* zImage.*
1619 diff -Naru linux/arch/mips/zboot/include/nonstdio.h linux-new/arch/mips/zboot/include/nonstdio.h
1620 --- linux/arch/mips/zboot/include/nonstdio.h 1969-12-31 19:00:00.000000000 -0500
1621 +++ linux-new/arch/mips/zboot/include/nonstdio.h 2003-12-18 14:26:20.000000000 -0500
1624 + * Copyright (C) Paul Mackerras 1997.
1626 + * This program is free software; you can redistribute it and/or
1627 + * modify it under the terms of the GNU General Public License
1628 + * as published by the Free Software Foundation; either version
1629 + * 2 of the License, or (at your option) any later version.
1632 +extern FILE *stdin, *stdout;
1633 +#define NULL ((void *)0)
1635 +#define fopen(n, m) NULL
1636 +#define fflush(f) 0
1637 +#define fclose(f) 0
1638 +extern char *fgets();
1640 +#define perror(s) printf("%s: no files!\n", (s))
1641 diff -Naru linux/arch/mips/zboot/include/ns16550.h linux-new/arch/mips/zboot/include/ns16550.h
1642 --- linux/arch/mips/zboot/include/ns16550.h 1969-12-31 19:00:00.000000000 -0500
1643 +++ linux-new/arch/mips/zboot/include/ns16550.h 2003-12-18 14:26:20.000000000 -0500
1646 + * NS16550 Serial Port
1650 + * Figure out which file will have the definitons of COMx
1652 +#if !defined(CONFIG_AU1X00_UART)
1656 +/* Some machines have their uart registers 16 bytes apart. Most don't.
1657 + * TODO: Make this work like drivers/char/serial does - Tom */
1658 +#if !defined(UART_REG_PAD)
1659 +#define UART_REG_PAD(x)
1664 + unsigned char rbr; /* 0 */
1666 + unsigned char ier; /* 1 */
1668 + unsigned char fcr; /* 2 */
1670 + unsigned char lcr; /* 3 */
1672 + unsigned char mcr; /* 4 */
1674 + unsigned char lsr; /* 5 */
1676 + unsigned char msr; /* 6 */
1678 + unsigned char scr; /* 7 */
1686 +#define LSR_DR 0x01 /* Data ready */
1687 +#define LSR_OE 0x02 /* Overrun */
1688 +#define LSR_PE 0x04 /* Parity error */
1689 +#define LSR_FE 0x08 /* Framing error */
1690 +#define LSR_BI 0x10 /* Break */
1691 +#define LSR_THRE 0x20 /* Xmit holding register empty */
1692 +#define LSR_TEMT 0x40 /* Xmitter empty */
1693 +#define LSR_ERR 0x80 /* Error */
1694 diff -Naru linux/arch/mips/zboot/include/pb1000_serial.h linux-new/arch/mips/zboot/include/pb1000_serial.h
1695 --- linux/arch/mips/zboot/include/pb1000_serial.h 1969-12-31 19:00:00.000000000 -0500
1696 +++ linux-new/arch/mips/zboot/include/pb1000_serial.h 2003-12-18 14:26:20.000000000 -0500
1699 + * arch/ppc/boot/include/sandpoint_serial.h
1701 + * Location of the COM ports on Motorola SPS Sandpoint machines
1703 + * Author: Mark A. Greer
1704 + * mgreer@mvista.com
1706 + * Copyright 2001 MontaVista Software Inc.
1708 + * This program is free software; you can redistribute it and/or modify it
1709 + * under the terms of the GNU General Public License as published by the
1710 + * Free Software Foundation; either version 2 of the License, or (at your
1711 + * option) any later version.
1714 +#define COM1 0xfe0003f8
1715 +#define COM2 0xfe0002f8
1716 +#define COM3 0x00000000 /* No COM3 */
1717 +#define COM4 0x00000000 /* No COM4 */
1718 diff -Naru linux/arch/mips/zboot/include/zlib.h linux-new/arch/mips/zboot/include/zlib.h
1719 --- linux/arch/mips/zboot/include/zlib.h 1969-12-31 19:00:00.000000000 -0500
1720 +++ linux-new/arch/mips/zboot/include/zlib.h 2003-12-18 14:26:21.000000000 -0500
1722 +/* $Id: zlib.h,v 1.2 2002/02/16 16:55:45 ppopov Exp $ */
1725 + * This file is derived from zlib.h and zconf.h from the zlib-0.95
1726 + * distribution by Jean-loup Gailly and Mark Adler, with some additions
1727 + * by Paul Mackerras to aid in implementing Deflate compression and
1728 + * decompression for PPP packets.
1732 + * ==FILEVERSION 960122==
1734 + * This marker is used by the Linux installation script to determine
1735 + * whether an up-to-date version of this file is already installed.
1738 +/* zlib.h -- interface of the 'zlib' general purpose compression library
1739 + version 0.95, Aug 16th, 1995.
1741 + Copyright (C) 1995 Jean-loup Gailly and Mark Adler
1743 + This software is provided 'as-is', without any express or implied
1744 + warranty. In no event will the authors be held liable for any damages
1745 + arising from the use of this software.
1747 + Permission is granted to anyone to use this software for any purpose,
1748 + including commercial applications, and to alter it and redistribute it
1749 + freely, subject to the following restrictions:
1751 + 1. The origin of this software must not be misrepresented; you must not
1752 + claim that you wrote the original software. If you use this software
1753 + in a product, an acknowledgment in the product documentation would be
1754 + appreciated but is not required.
1755 + 2. Altered source versions must be plainly marked as such, and must not be
1756 + misrepresented as being the original software.
1757 + 3. This notice may not be removed or altered from any source distribution.
1759 + Jean-loup Gailly Mark Adler
1760 + gzip@prep.ai.mit.edu madler@alumni.caltech.edu
1766 +/* #include "zconf.h" */ /* included directly here */
1768 +/* zconf.h -- configuration of the zlib compression library
1769 + * Copyright (C) 1995 Jean-loup Gailly.
1770 + * For conditions of distribution and use, see copyright notice in zlib.h
1773 +/* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
1776 + The library does not install any signal handler. It is recommended to
1777 + add at least a handler for SIGSEGV when decompressing; the library checks
1778 + the consistency of the input data whenever possible but may go nuts
1779 + for some forms of corrupted input.
1783 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
1784 + * than 64k bytes at a time (needed on systems with 16-bit int).
1785 + * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
1786 + * at addresses which are not a multiple of their size.
1787 + * Under DOS, -DFAR=far or -DFAR=__far may be needed.
1791 +# if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
1796 +#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
1800 +/* Maximum value for memLevel in deflateInit2 */
1801 +#ifndef MAX_MEM_LEVEL
1803 +# define MAX_MEM_LEVEL 8
1805 +# define MAX_MEM_LEVEL 9
1813 +/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
1815 +# define MAX_WBITS 15 /* 32K LZ77 window */
1818 +/* The memory requirements for deflate are (in bytes):
1819 + 1 << (windowBits+2) + 1 << (memLevel+9)
1820 + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
1821 + plus a few kilobytes for small objects. For example, if you want to reduce
1822 + the default memory requirements from 256K to 128K, compile with
1823 + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
1824 + Of course this will generally degrade compression (there's no free lunch).
1826 + The memory requirements for inflate are (in bytes) 1 << windowBits
1827 + that is, 32K for windowBits=15 (default value) plus a few kilobytes
1828 + for small objects.
1831 + /* Type declarations */
1833 +#ifndef OF /* function prototypes */
1835 +# define OF(args) args
1837 +# define OF(args) ()
1841 +typedef unsigned char Byte; /* 8 bits */
1842 +typedef unsigned int uInt; /* 16 bits or more */
1843 +typedef unsigned long uLong; /* 32 bits or more */
1845 +typedef Byte FAR Bytef;
1846 +typedef char FAR charf;
1847 +typedef int FAR intf;
1848 +typedef uInt FAR uIntf;
1849 +typedef uLong FAR uLongf;
1852 + typedef void FAR *voidpf;
1853 + typedef void *voidp;
1855 + typedef Byte FAR *voidpf;
1856 + typedef Byte *voidp;
1859 +/* end of original zconf.h */
1861 +#define ZLIB_VERSION "0.95P"
1864 + The 'zlib' compression library provides in-memory compression and
1865 + decompression functions, including integrity checks of the uncompressed
1866 + data. This version of the library supports only one compression method
1867 + (deflation) but other algorithms may be added later and will have the same
1870 + For compression the application must provide the output buffer and
1871 + may optionally provide the input buffer for optimization. For decompression,
1872 + the application must provide the input buffer and may optionally provide
1873 + the output buffer for optimization.
1875 + Compression can be done in a single step if the buffers are large
1876 + enough (for example if an input file is mmap'ed), or can be done by
1877 + repeated calls of the compression function. In the latter case, the
1878 + application must provide more input and/or consume the output
1879 + (providing more output space) before each call.
1882 +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
1883 +typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt nbytes));
1885 +struct internal_state;
1887 +typedef struct z_stream_s {
1888 + Bytef *next_in; /* next input byte */
1889 + uInt avail_in; /* number of bytes available at next_in */
1890 + uLong total_in; /* total nb of input bytes read so far */
1892 + Bytef *next_out; /* next output byte should be put there */
1893 + uInt avail_out; /* remaining free space at next_out */
1894 + uLong total_out; /* total nb of bytes output so far */
1896 + char *msg; /* last error message, NULL if no error */
1897 + struct internal_state FAR *state; /* not visible by applications */
1899 + alloc_func zalloc; /* used to allocate the internal state */
1900 + free_func zfree; /* used to free the internal state */
1901 + voidp opaque; /* private data object passed to zalloc and zfree */
1903 + Byte data_type; /* best guess about the data type: ascii or binary */
1908 + The application must update next_in and avail_in when avail_in has
1909 + dropped to zero. It must update next_out and avail_out when avail_out
1910 + has dropped to zero. The application must initialize zalloc, zfree and
1911 + opaque before calling the init function. All other fields are set by the
1912 + compression library and must not be updated by the application.
1914 + The opaque value provided by the application will be passed as the first
1915 + parameter for calls of zalloc and zfree. This can be useful for custom
1916 + memory management. The compression library attaches no meaning to the
1919 + zalloc must return Z_NULL if there is not enough memory for the object.
1920 + On 16-bit systems, the functions zalloc and zfree must be able to allocate
1921 + exactly 65536 bytes, but will not be required to allocate more than this
1922 + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
1923 + pointers returned by zalloc for objects of exactly 65536 bytes *must*
1924 + have their offset normalized to zero. The default allocation function
1925 + provided by this library ensures this (see zutil.c). To reduce memory
1926 + requirements and avoid any allocation of 64K objects, at the expense of
1927 + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
1929 + The fields total_in and total_out can be used for statistics or
1930 + progress reports. After compression, total_in holds the total size of
1931 + the uncompressed data and may be saved for use in the decompressor
1932 + (particularly if the decompressor wants to decompress everything in
1938 +#define Z_NO_FLUSH 0
1939 +#define Z_PARTIAL_FLUSH 1
1940 +#define Z_FULL_FLUSH 2
1941 +#define Z_SYNC_FLUSH 3 /* experimental: partial_flush + byte align */
1943 +#define Z_PACKET_FLUSH 5
1944 +/* See deflate() below for the usage of these constants */
1947 +#define Z_STREAM_END 1
1948 +#define Z_ERRNO (-1)
1949 +#define Z_STREAM_ERROR (-2)
1950 +#define Z_DATA_ERROR (-3)
1951 +#define Z_MEM_ERROR (-4)
1952 +#define Z_BUF_ERROR (-5)
1953 +/* error codes for the compression/decompression functions */
1955 +#define Z_BEST_SPEED 1
1956 +#define Z_BEST_COMPRESSION 9
1957 +#define Z_DEFAULT_COMPRESSION (-1)
1958 +/* compression levels */
1960 +#define Z_FILTERED 1
1961 +#define Z_HUFFMAN_ONLY 2
1962 +#define Z_DEFAULT_STRATEGY 0
1966 +#define Z_UNKNOWN 2
1967 +/* Used to set the data_type field */
1969 +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
1971 +extern char *zlib_version;
1972 +/* The application can compare zlib_version and ZLIB_VERSION for consistency.
1973 + If the first character differs, the library code actually used is
1974 + not compatible with the zlib.h header file used by the application.
1977 + /* basic functions */
1979 +extern int inflateInit OF((z_stream *strm));
1981 + Initializes the internal stream state for decompression. The fields
1982 + zalloc and zfree must be initialized before by the caller. If zalloc and
1983 + zfree are set to Z_NULL, inflateInit updates them to use default allocation
1986 + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
1987 + enough memory. msg is set to null if there is no error message.
1988 + inflateInit does not perform any decompression: this will be done by
1993 +extern int inflate OF((z_stream *strm, int flush));
1995 + Performs one or both of the following actions:
1997 + - Decompress more input starting at next_in and update next_in and avail_in
1998 + accordingly. If not all input can be processed (because there is not
1999 + enough room in the output buffer), next_in is updated and processing
2000 + will resume at this point for the next call of inflate().
2002 + - Provide more output starting at next_out and update next_out and avail_out
2003 + accordingly. inflate() always provides as much output as possible
2004 + (until there is no more input data or no more space in the output buffer).
2006 + Before the call of inflate(), the application should ensure that at least
2007 + one of the actions is possible, by providing more input and/or consuming
2008 + more output, and updating the next_* and avail_* values accordingly.
2009 + The application can consume the uncompressed output when it wants, for
2010 + example when the output buffer is full (avail_out == 0), or after each
2011 + call of inflate().
2013 + If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
2014 + inflate flushes as much output as possible to the output buffer. The
2015 + flushing behavior of inflate is not specified for values of the flush
2016 + parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
2017 + current implementation actually flushes as much output as possible
2018 + anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data
2019 + has been consumed, it is expecting to see the length field of a stored
2020 + block; if not, it returns Z_DATA_ERROR.
2022 + inflate() should normally be called until it returns Z_STREAM_END or an
2023 + error. However if all decompression is to be performed in a single step
2024 + (a single call of inflate), the parameter flush should be set to
2025 + Z_FINISH. In this case all pending input is processed and all pending
2026 + output is flushed; avail_out must be large enough to hold all the
2027 + uncompressed data. (The size of the uncompressed data may have been saved
2028 + by the compressor for this purpose.) The next operation on this stream must
2029 + be inflateEnd to deallocate the decompression state. The use of Z_FINISH
2030 + is never required, but can be used to inform inflate that a faster routine
2031 + may be used for the single inflate() call.
2033 + inflate() returns Z_OK if some progress has been made (more input
2034 + processed or more output produced), Z_STREAM_END if the end of the
2035 + compressed data has been reached and all uncompressed output has been
2036 + produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
2037 + the stream structure was inconsistent (for example if next_in or next_out
2038 + was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
2039 + progress is possible or if there was not enough room in the output buffer
2040 + when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
2041 + call inflateSync to look for a good compression block. */
2044 +extern int inflateEnd OF((z_stream *strm));
2046 + All dynamically allocated data structures for this stream are freed.
2047 + This function discards any unprocessed input and does not flush any
2050 + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
2051 + was inconsistent. In the error case, msg may be set but then points to a
2052 + static string (which must not be deallocated).
2055 + /* advanced functions */
2057 +extern int inflateInit2 OF((z_stream *strm,
2060 + This is another version of inflateInit with more compression options. The
2061 + fields next_out, zalloc and zfree must be initialized before by the caller.
2063 + The windowBits parameter is the base two logarithm of the maximum window
2064 + size (the size of the history buffer). It should be in the range 8..15 for
2065 + this version of the library (the value 16 will be allowed soon). The
2066 + default value is 15 if inflateInit is used instead. If a compressed stream
2067 + with a larger window size is given as input, inflate() will return with
2068 + the error code Z_DATA_ERROR instead of trying to allocate a larger window.
2070 + If next_out is not null, the library will use this buffer for the history
2071 + buffer; the buffer must either be large enough to hold the entire output
2072 + data, or have at least 1<<windowBits bytes. If next_out is null, the
2073 + library will allocate its own buffer (and leave next_out null). next_in
2074 + need not be provided here but must be provided by the application for the
2075 + next call of inflate().
2077 + If the history buffer is provided by the application, next_out must
2078 + never be changed by the application since the decompressor maintains
2079 + history information inside this buffer from call to call; the application
2080 + can only reset next_out to the beginning of the history buffer when
2081 + avail_out is zero and all output has been consumed.
2083 + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
2084 + not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
2085 + windowBits < 8). msg is set to null if there is no error message.
2086 + inflateInit2 does not perform any decompression: this will be done by
2090 +extern int inflateSync OF((z_stream *strm));
2092 + Skips invalid compressed data until the special marker (see deflate()
2093 + above) can be found, or until all available input is skipped. No output
2096 + inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
2097 + if no more input was provided, Z_DATA_ERROR if no marker has been found,
2098 + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
2099 + case, the application may save the current current value of total_in which
2100 + indicates where valid compressed data was found. In the error case, the
2101 + application may repeatedly call inflateSync, providing more input each time,
2102 + until success or end of the input data.
2105 +extern int inflateReset OF((z_stream *strm));
2107 + This function is equivalent to inflateEnd followed by inflateInit,
2108 + but does not free and reallocate all the internal decompression state.
2109 + The stream will keep attributes that may have been set by inflateInit2.
2111 + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
2112 + stream state was inconsistent (such as zalloc or state being NULL).
2115 +extern int inflateIncomp OF((z_stream *strm));
2117 + This function adds the data at next_in (avail_in bytes) to the output
2118 + history without performing any output. There must be no pending output,
2119 + and the decompressor must be expecting to see the start of a block.
2120 + Calling this function is equivalent to decompressing a stored block
2121 + containing the data at next_in (except that the data is not output).
2124 + /* checksum functions */
2127 + This function is not related to compression but is exported
2128 + anyway because it might be useful in applications using the
2129 + compression library.
2132 +extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
2135 + Update a running Adler-32 checksum with the bytes buf[0..len-1] and
2136 + return the updated checksum. If buf is NULL, this function returns
2137 + the required initial value for the checksum.
2138 + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
2139 + much faster. Usage example:
2141 + uLong adler = adler32(0L, Z_NULL, 0);
2143 + while (read_buffer(buffer, length) != EOF) {
2144 + adler = adler32(adler, buffer, length);
2146 + if (adler != original_adler) error();
2150 + struct internal_state {int dummy;}; /* hack for buggy compilers */
2153 +#endif /* _ZLIB_H */
2154 diff -Naru linux/arch/mips/zboot/ld.script linux-new/arch/mips/zboot/ld.script
2155 --- linux/arch/mips/zboot/ld.script 1969-12-31 19:00:00.000000000 -0500
2156 +++ linux-new/arch/mips/zboot/ld.script 2003-12-18 14:26:21.000000000 -0500
2162 + /* Read-only sections, merged into text segment: */
2163 + /* . = 0x81000000; */
2164 + .init : { *(.init) } =0
2171 + /* .gnu.warning sections are handled specially by elf32.em. */
2174 + .kstrtab : { *(.kstrtab) }
2176 + . = ALIGN(16); /* Exception table */
2177 + __start___ex_table = .;
2178 + __ex_table : { *(__ex_table) }
2179 + __stop___ex_table = .;
2181 + __start___dbe_table = .; /* Exception table for data bus errors */
2182 + __dbe_table : { *(__dbe_table) }
2183 + __stop___dbe_table = .;
2185 + __start___ksymtab = .; /* Kernel symbol table */
2186 + __ksymtab : { *(__ksymtab) }
2187 + __stop___ksymtab = .;
2192 + .data.init_task : { *(.data.init_task) }
2194 + /* Startup code */
2197 + .text.init : { *(.text.init) }
2198 + .data.init : { *(.data.init) }
2200 + __setup_start = .;
2201 + .setup.init : { *(.setup.init) }
2203 + __initcall_start = .;
2204 + .initcall.init : { *(.initcall.init) }
2205 + __initcall_end = .;
2206 + . = ALIGN(4096); /* Align double page for init_task_union */
2210 + .data.page_aligned : { *(.data.idt) }
2213 + .data.cacheline_aligned : { *(.data.cacheline_aligned) }
2215 + .fini : { *(.fini) } =0
2216 + .reginfo : { *(.reginfo) }
2217 + /* Adjust the address for the data segment. We want to adjust up to
2218 + the same address within the page on the next page up. It would
2219 + be more correct to do this:
2221 + The current expression does not correctly handle the case of a
2222 + text segment ending precisely at the end of a page; it causes the
2223 + data segment to skip a page. The above expression does not have
2224 + this problem, but it will currently (2/95) cause BFD to allocate
2225 + a single segment, combining both text and data, for this case.
2226 + This will prevent the text segment from being shared among
2227 + multiple executions of the program; I think that is more
2228 + important than losing a page of the virtual address space (note
2229 + that no actual memory is lost; the page which is skipped can not
2230 + be referenced). */
2237 + /* Put the compressed image here, so bss is on the end. */
2238 + __image_begin = .;
2241 + /* Align the initial ramdisk image (INITRD) on page boundaries. */
2243 + __ramdisk_begin = .;
2245 + __ramdisk_end = .;
2250 + .data1 : { *(.data1) }
2252 + .lit8 : { *(.lit8) }
2253 + .lit4 : { *(.lit4) }
2254 + .ctors : { *(.ctors) }
2255 + .dtors : { *(.dtors) }
2256 + .got : { *(.got.plt) *(.got) }
2257 + .dynamic : { *(.dynamic) }
2258 + /* We want the small data sections together, so single-instruction offsets
2259 + can access them all, and initialized data all before uninitialized, so
2260 + we can shorten the on-disk segment size. */
2261 + .sdata : { *(.sdata) }
2264 + PROVIDE (edata = .);
2268 + .sbss : { *(.sbss) *(.scommon) }
2276 + PROVIDE (end = .);
2279 + /* Sections to be discarded */
2287 + /* This is the MIPS specific mdebug section. */
2288 + .mdebug : { *(.mdebug) }
2289 + /* These are needed for ELF backends which have not yet been
2290 + converted to the new style linker. */
2291 + .stab 0 : { *(.stab) }
2292 + .stabstr 0 : { *(.stabstr) }
2293 + /* DWARF debug sections.
2294 + Symbols in the .debug DWARF section are relative to the beginning of the
2295 + section so we begin .debug at 0. It's not clear yet what needs to happen
2296 + for the others. */
2297 + .debug 0 : { *(.debug) }
2298 + .debug_srcinfo 0 : { *(.debug_srcinfo) }
2299 + .debug_aranges 0 : { *(.debug_aranges) }
2300 + .debug_pubnames 0 : { *(.debug_pubnames) }
2301 + .debug_sfnames 0 : { *(.debug_sfnames) }
2302 + .line 0 : { *(.line) }
2303 + /* These must appear regardless of . */
2304 + .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
2305 + .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
2306 + .comment : { *(.comment) }
2307 + .note : { *(.note) }
2309 diff -Naru linux/arch/mips/zboot/lib/Makefile linux-new/arch/mips/zboot/lib/Makefile
2310 --- linux/arch/mips/zboot/lib/Makefile 1969-12-31 19:00:00.000000000 -0500
2311 +++ linux-new/arch/mips/zboot/lib/Makefile 2003-12-18 14:26:21.000000000 -0500
2314 +# Makefile for some libs needed by zImage.
2321 +include $(TOPDIR)/Rules.make
2322 diff -Naru linux/arch/mips/zboot/lib/zlib.c linux-new/arch/mips/zboot/lib/zlib.c
2323 --- linux/arch/mips/zboot/lib/zlib.c 1969-12-31 19:00:00.000000000 -0500
2324 +++ linux-new/arch/mips/zboot/lib/zlib.c 2003-12-18 14:26:21.000000000 -0500
2327 + * This file is derived from various .h and .c files from the zlib-0.95
2328 + * distribution by Jean-loup Gailly and Mark Adler, with some additions
2329 + * by Paul Mackerras to aid in implementing Deflate compression and
2330 + * decompression for PPP packets. See zlib.h for conditions of
2331 + * distribution and use.
2333 + * Changes that have been made include:
2334 + * - changed functions not used outside this file to "local"
2335 + * - added minCompression parameter to deflateInit2
2336 + * - added Z_PACKET_FLUSH (see zlib.h for details)
2337 + * - added inflateIncomp
2339 + * $Id: zlib.c,v 1.2 2002/02/16 16:55:45 ppopov Exp $
2343 +/* zutil.h -- internal interface and configuration of the compression library
2344 + * Copyright (C) 1995 Jean-loup Gailly.
2345 + * For conditions of distribution and use, see copyright notice in zlib.h
2348 +/* WARNING: this file should *not* be used by applications. It is
2349 + part of the implementation of the compression library and is
2350 + subject to change. Applications should only use zlib.h.
2353 +/* From: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp */
2360 +# define local static
2362 +/* compile with -Dlocal if your debugger can't find static symbols */
2366 +typedef unsigned char uch;
2367 +typedef uch FAR uchf;
2368 +typedef unsigned short ush;
2369 +typedef ush FAR ushf;
2370 +typedef unsigned long ulg;
2372 +extern char *z_errmsg[]; /* indexed by 1-zlib_error */
2374 +#define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
2375 +/* To be used only when the state is known to be valid */
2378 +#define NULL ((void *) 0)
2381 + /* common constants */
2386 +# define DEF_WBITS MAX_WBITS
2388 +/* default windowBits for decompression. MAX_WBITS is for compression only */
2390 +#if MAX_MEM_LEVEL >= 8
2391 +# define DEF_MEM_LEVEL 8
2393 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL
2395 +/* default memLevel */
2397 +#define STORED_BLOCK 0
2398 +#define STATIC_TREES 1
2399 +#define DYN_TREES 2
2400 +/* The three kinds of block type */
2402 +#define MIN_MATCH 3
2403 +#define MAX_MATCH 258
2404 +/* The minimum and maximum match lengths */
2408 +#include <linux/string.h>
2409 +#define zmemcpy memcpy
2410 +#define zmemzero(dest, len) memset(dest, 0, len)
2412 +/* Diagnostic functions */
2414 +# include <stdio.h>
2418 +# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
2419 +# define Trace(x) fprintf x
2420 +# define Tracev(x) {if (verbose) fprintf x ;}
2421 +# define Tracevv(x) {if (verbose>1) fprintf x ;}
2422 +# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
2423 +# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
2425 +# define Assert(cond,msg)
2428 +# define Tracevv(x)
2429 +# define Tracec(c,x)
2430 +# define Tracecv(c,x)
2434 +typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
2436 +/* voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); */
2437 +/* void zcfree OF((voidpf opaque, voidpf ptr)); */
2439 +#define ZALLOC(strm, items, size) \
2440 + (*((strm)->zalloc))((strm)->opaque, (items), (size))
2441 +#define ZFREE(strm, addr, size) \
2442 + (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size))
2443 +#define TRY_FREE(s, p, n) {if (p) ZFREE(s, p, n);}
2445 +/* deflate.h -- internal compression state
2446 + * Copyright (C) 1995 Jean-loup Gailly
2447 + * For conditions of distribution and use, see copyright notice in zlib.h
2450 +/* WARNING: this file should *not* be used by applications. It is
2451 + part of the implementation of the compression library and is
2452 + subject to change. Applications should only use zlib.h.
2456 +/* infblock.h -- header to use infblock.c
2457 + * Copyright (C) 1995 Mark Adler
2458 + * For conditions of distribution and use, see copyright notice in zlib.h
2461 +/* WARNING: this file should *not* be used by applications. It is
2462 + part of the implementation of the compression library and is
2463 + subject to change. Applications should only use zlib.h.
2466 +struct inflate_blocks_state;
2467 +typedef struct inflate_blocks_state FAR inflate_blocks_statef;
2469 +local inflate_blocks_statef * inflate_blocks_new OF((
2471 + check_func c, /* check function */
2472 + uInt w)); /* window size */
2474 +local int inflate_blocks OF((
2475 + inflate_blocks_statef *,
2477 + int)); /* initial return code */
2479 +local void inflate_blocks_reset OF((
2480 + inflate_blocks_statef *,
2482 + uLongf *)); /* check value on output */
2484 +local int inflate_blocks_free OF((
2485 + inflate_blocks_statef *,
2487 + uLongf *)); /* check value on output */
2489 +local int inflate_addhistory OF((
2490 + inflate_blocks_statef *,
2493 +local int inflate_packet_flush OF((
2494 + inflate_blocks_statef *));
2497 +/* inftrees.h -- header to use inftrees.c
2498 + * Copyright (C) 1995 Mark Adler
2499 + * For conditions of distribution and use, see copyright notice in zlib.h
2502 +/* WARNING: this file should *not* be used by applications. It is
2503 + part of the implementation of the compression library and is
2504 + subject to change. Applications should only use zlib.h.
2507 +/* Huffman code lookup table entry--this entry is four bytes for machines
2508 + that have 16-bit pointers (e.g. PC's in the small or medium model). */
2510 +typedef struct inflate_huft_s FAR inflate_huft;
2512 +struct inflate_huft_s {
2515 + Byte Exop; /* number of extra bits or operation */
2516 + Byte Bits; /* number of bits in this code or subcode */
2518 + uInt Nalloc; /* number of these allocated here */
2519 + Bytef *pad; /* pad structure to a power of 2 (4 bytes for */
2520 + } word; /* 16-bit, 8 bytes for 32-bit machines) */
2522 + uInt Base; /* literal, length base, or distance base */
2523 + inflate_huft *Next; /* pointer to next level of table */
2528 + local uInt inflate_hufts;
2531 +local int inflate_trees_bits OF((
2532 + uIntf *, /* 19 code lengths */
2533 + uIntf *, /* bits tree desired/actual depth */
2534 + inflate_huft * FAR *, /* bits tree result */
2535 + z_stream *)); /* for zalloc, zfree functions */
2537 +local int inflate_trees_dynamic OF((
2538 + uInt, /* number of literal/length codes */
2539 + uInt, /* number of distance codes */
2540 + uIntf *, /* that many (total) code lengths */
2541 + uIntf *, /* literal desired/actual bit depth */
2542 + uIntf *, /* distance desired/actual bit depth */
2543 + inflate_huft * FAR *, /* literal/length tree result */
2544 + inflate_huft * FAR *, /* distance tree result */
2545 + z_stream *)); /* for zalloc, zfree functions */
2547 +local int inflate_trees_fixed OF((
2548 + uIntf *, /* literal desired/actual bit depth */
2549 + uIntf *, /* distance desired/actual bit depth */
2550 + inflate_huft * FAR *, /* literal/length tree result */
2551 + inflate_huft * FAR *)); /* distance tree result */
2553 +local int inflate_trees_free OF((
2554 + inflate_huft *, /* tables to free */
2555 + z_stream *)); /* for zfree function */
2559 +/* infcodes.h -- header to use infcodes.c
2560 + * Copyright (C) 1995 Mark Adler
2561 + * For conditions of distribution and use, see copyright notice in zlib.h
2564 +/* WARNING: this file should *not* be used by applications. It is
2565 + part of the implementation of the compression library and is
2566 + subject to change. Applications should only use zlib.h.
2569 +struct inflate_codes_state;
2570 +typedef struct inflate_codes_state FAR inflate_codes_statef;
2572 +local inflate_codes_statef *inflate_codes_new OF((
2574 + inflate_huft *, inflate_huft *,
2577 +local int inflate_codes OF((
2578 + inflate_blocks_statef *,
2582 +local void inflate_codes_free OF((
2583 + inflate_codes_statef *,
2588 +/* inflate.c -- zlib interface to inflate modules
2589 + * Copyright (C) 1995 Mark Adler
2590 + * For conditions of distribution and use, see copyright notice in zlib.h
2593 +/* inflate private state */
2594 +struct internal_state {
2598 + METHOD, /* waiting for method byte */
2599 + FLAG, /* waiting for flag byte */
2600 + BLOCKS, /* decompressing blocks */
2601 + CHECK4, /* four check bytes to go */
2602 + CHECK3, /* three check bytes to go */
2603 + CHECK2, /* two check bytes to go */
2604 + CHECK1, /* one check byte to go */
2605 + DONE, /* finished check, done */
2606 + BAD} /* got an error--stay here */
2607 + mode; /* current inflate mode */
2609 + /* mode dependent information */
2611 + uInt method; /* if FLAGS, method byte */
2613 + uLong was; /* computed check value */
2614 + uLong need; /* stream check value */
2615 + } check; /* if CHECK, check values to compare */
2616 + uInt marker; /* if BAD, inflateSync's marker bytes count */
2617 + } sub; /* submode */
2619 + /* mode independent information */
2620 + int nowrap; /* flag for no wrapper */
2621 + uInt wbits; /* log2(window size) (8..15, defaults to 15) */
2622 + inflate_blocks_statef
2623 + *blocks; /* current inflate_blocks state */
2628 +int inflateReset(z)
2633 + if (z == Z_NULL || z->state == Z_NULL)
2634 + return Z_STREAM_ERROR;
2635 + z->total_in = z->total_out = 0;
2637 + z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
2638 + inflate_blocks_reset(z->state->blocks, z, &c);
2639 + Trace((stderr, "inflate: reset\n"));
2649 + if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
2650 + return Z_STREAM_ERROR;
2651 + if (z->state->blocks != Z_NULL)
2652 + inflate_blocks_free(z->state->blocks, z, &c);
2653 + ZFREE(z, z->state, sizeof(struct internal_state));
2654 + z->state = Z_NULL;
2655 + Trace((stderr, "inflate: end\n"));
2660 +int inflateInit2(z, w)
2664 + /* initialize state */
2666 + return Z_STREAM_ERROR;
2667 +/* if (z->zalloc == Z_NULL) z->zalloc = zcalloc; */
2668 +/* if (z->zfree == Z_NULL) z->zfree = zcfree; */
2669 + if ((z->state = (struct internal_state FAR *)
2670 + ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
2671 + return Z_MEM_ERROR;
2672 + z->state->blocks = Z_NULL;
2674 + /* handle undocumented nowrap option (no zlib header or check) */
2675 + z->state->nowrap = 0;
2679 + z->state->nowrap = 1;
2682 + /* set window size */
2683 + if (w < 8 || w > 15)
2686 + return Z_STREAM_ERROR;
2688 + z->state->wbits = (uInt)w;
2690 + /* create inflate_blocks state */
2691 + if ((z->state->blocks =
2692 + inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w))
2696 + return Z_MEM_ERROR;
2698 + Trace((stderr, "inflate: allocated\n"));
2709 + return inflateInit2(z, DEF_WBITS);
2713 +#define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;}
2714 +#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
2723 + if (z == Z_NULL || z->next_in == Z_NULL)
2724 + return Z_STREAM_ERROR;
2726 + while (1) switch (z->state->mode)
2730 + if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED)
2732 + z->state->mode = BAD;
2733 + z->msg = "unknown compression method";
2734 + z->state->sub.marker = 5; /* can't try inflateSync */
2737 + if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
2739 + z->state->mode = BAD;
2740 + z->msg = "invalid window size";
2741 + z->state->sub.marker = 5; /* can't try inflateSync */
2744 + z->state->mode = FLAG;
2747 + if ((b = NEXTBYTE) & 0x20)
2749 + z->state->mode = BAD;
2750 + z->msg = "invalid reserved bit";
2751 + z->state->sub.marker = 5; /* can't try inflateSync */
2754 + if (((z->state->sub.method << 8) + b) % 31)
2756 + z->state->mode = BAD;
2757 + z->msg = "incorrect header check";
2758 + z->state->sub.marker = 5; /* can't try inflateSync */
2761 + Trace((stderr, "inflate: zlib header ok\n"));
2762 + z->state->mode = BLOCKS;
2764 + r = inflate_blocks(z->state->blocks, z, r);
2765 + if (f == Z_PACKET_FLUSH && z->avail_in == 0 && z->avail_out != 0)
2766 + r = inflate_packet_flush(z->state->blocks);
2767 + if (r == Z_DATA_ERROR)
2769 + z->state->mode = BAD;
2770 + z->state->sub.marker = 0; /* can try inflateSync */
2773 + if (r != Z_STREAM_END)
2776 + inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
2777 + if (z->state->nowrap)
2779 + z->state->mode = DONE;
2782 + z->state->mode = CHECK4;
2785 + z->state->sub.check.need = (uLong)NEXTBYTE << 24;
2786 + z->state->mode = CHECK3;
2789 + z->state->sub.check.need += (uLong)NEXTBYTE << 16;
2790 + z->state->mode = CHECK2;
2793 + z->state->sub.check.need += (uLong)NEXTBYTE << 8;
2794 + z->state->mode = CHECK1;
2797 + z->state->sub.check.need += (uLong)NEXTBYTE;
2799 + if (z->state->sub.check.was != z->state->sub.check.need)
2801 + z->state->mode = BAD;
2802 + z->msg = "incorrect data check";
2803 + z->state->sub.marker = 5; /* can't try inflateSync */
2806 + Trace((stderr, "inflate: zlib check ok\n"));
2807 + z->state->mode = DONE;
2809 + return Z_STREAM_END;
2811 + return Z_DATA_ERROR;
2813 + return Z_STREAM_ERROR;
2817 + if (f != Z_PACKET_FLUSH)
2819 + z->state->mode = BAD;
2820 + z->state->sub.marker = 0; /* can try inflateSync */
2821 + return Z_DATA_ERROR;
2825 + * This subroutine adds the data at next_in/avail_in to the output history
2826 + * without performing any output. The output buffer must be "caught up";
2827 + * i.e. no pending output (hence s->read equals s->write), and the state must
2828 + * be BLOCKS (i.e. we should be willing to see the start of a series of
2829 + * BLOCKS). On exit, the output will also be caught up, and the checksum
2830 + * will have been updated if need be.
2833 +int inflateIncomp(z)
2836 + if (z->state->mode != BLOCKS)
2837 + return Z_DATA_ERROR;
2838 + return inflate_addhistory(z->state->blocks, z);
2845 + uInt n; /* number of bytes to look at */
2846 + Bytef *p; /* pointer to bytes */
2847 + uInt m; /* number of marker bytes found in a row */
2848 + uLong r, w; /* temporaries to save total_in and total_out */
2851 + if (z == Z_NULL || z->state == Z_NULL)
2852 + return Z_STREAM_ERROR;
2853 + if (z->state->mode != BAD)
2855 + z->state->mode = BAD;
2856 + z->state->sub.marker = 0;
2858 + if ((n = z->avail_in) == 0)
2859 + return Z_BUF_ERROR;
2861 + m = z->state->sub.marker;
2864 + while (n && m < 4)
2866 + if (*p == (Byte)(m < 2 ? 0 : 0xff))
2876 + z->total_in += p - z->next_in;
2879 + z->state->sub.marker = m;
2881 + /* return no joy or set up to restart on a new block */
2883 + return Z_DATA_ERROR;
2884 + r = z->total_in; w = z->total_out;
2886 + z->total_in = r; z->total_out = w;
2887 + z->state->mode = BLOCKS;
2895 +/* infutil.h -- types and macros common to blocks and codes
2896 + * Copyright (C) 1995 Mark Adler
2897 + * For conditions of distribution and use, see copyright notice in zlib.h
2900 +/* WARNING: this file should *not* be used by applications. It is
2901 + part of the implementation of the compression library and is
2902 + subject to change. Applications should only use zlib.h.
2905 +/* inflate blocks semi-private state */
2906 +struct inflate_blocks_state {
2910 + TYPE, /* get type bits (3, including end bit) */
2911 + LENS, /* get lengths for stored */
2912 + STORED, /* processing stored block */
2913 + TABLE, /* get table lengths */
2914 + BTREE, /* get bit lengths tree for a dynamic block */
2915 + DTREE, /* get length, distance trees for a dynamic block */
2916 + CODES, /* processing fixed or dynamic block */
2917 + DRY, /* output remaining window bytes */
2918 + DONEB, /* finished last block, done */
2919 + BADB} /* got a data error--stuck here */
2920 + mode; /* current inflate_block mode */
2922 + /* mode dependent information */
2924 + uInt left; /* if STORED, bytes left to copy */
2926 + uInt table; /* table lengths (14 bits) */
2927 + uInt index; /* index into blens (or border) */
2928 + uIntf *blens; /* bit lengths of codes */
2929 + uInt bb; /* bit length tree depth */
2930 + inflate_huft *tb; /* bit length decoding tree */
2931 + int nblens; /* # elements allocated at blens */
2932 + } trees; /* if DTREE, decoding info for trees */
2934 + inflate_huft *tl, *td; /* trees to free */
2935 + inflate_codes_statef
2937 + } decode; /* if CODES, current state */
2938 + } sub; /* submode */
2939 + uInt last; /* true if this block is the last block */
2941 + /* mode independent information */
2942 + uInt bitk; /* bits in bit buffer */
2943 + uLong bitb; /* bit buffer */
2944 + Bytef *window; /* sliding window */
2945 + Bytef *end; /* one byte after sliding window */
2946 + Bytef *read; /* window read pointer */
2947 + Bytef *write; /* window write pointer */
2948 + check_func checkfn; /* check function */
2949 + uLong check; /* check on output */
2954 +/* defines for inflate input/output */
2955 +/* update pointers and return */
2956 +#define UPDBITS {s->bitb=b;s->bitk=k;}
2957 +#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
2958 +#define UPDOUT {s->write=q;}
2959 +#define UPDATE {UPDBITS UPDIN UPDOUT}
2960 +#define LEAVE {UPDATE return inflate_flush(s,z,r);}
2961 +/* get bytes and bits */
2962 +#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
2963 +#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
2964 +#define NEXTBYTE (n--,*p++)
2965 +#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
2966 +#define DUMPBITS(j) {b>>=(j);k-=(j);}
2968 +#define WAVAIL (q<s->read?s->read-q-1:s->end-q)
2969 +#define LOADOUT {q=s->write;m=WAVAIL;}
2970 +#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}}
2971 +#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
2972 +#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
2973 +#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
2974 +/* load local pointers */
2975 +#define LOAD {LOADIN LOADOUT}
2978 + * The IBM 150 firmware munges the data right after _etext[]. This
2979 + * protects it. -- Cort
2981 +local uInt protect_mask[] = {0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0};
2982 +/* And'ing with mask[n] masks the lower n bits */
2983 +local uInt inflate_mask[] = {
2985 + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
2986 + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
2989 +/* copy as much as possible from the sliding window to the output area */
2990 +local int inflate_flush OF((
2991 + inflate_blocks_statef *,
2996 +/* inffast.h -- header to use inffast.c
2997 + * Copyright (C) 1995 Mark Adler
2998 + * For conditions of distribution and use, see copyright notice in zlib.h
3001 +/* WARNING: this file should *not* be used by applications. It is
3002 + part of the implementation of the compression library and is
3003 + subject to change. Applications should only use zlib.h.
3006 +local int inflate_fast OF((
3011 + inflate_blocks_statef *,
3016 +/* infblock.c -- interpret and process block types to last block
3017 + * Copyright (C) 1995 Mark Adler
3018 + * For conditions of distribution and use, see copyright notice in zlib.h
3021 +/* Table for deflate from PKZIP's appnote.txt. */
3022 +local uInt border[] = { /* Order of the bit length code lengths */
3023 + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
3026 + Notes beyond the 1.93a appnote.txt:
3028 + 1. Distance pointers never point before the beginning of the output
3030 + 2. Distance pointers can point back across blocks, up to 32k away.
3031 + 3. There is an implied maximum of 7 bits for the bit length table and
3032 + 15 bits for the actual data.
3033 + 4. If only one code exists, then it is encoded using one bit. (Zero
3034 + would be more efficient, but perhaps a little confusing.) If two
3035 + codes exist, they are coded using one bit each (0 and 1).
3036 + 5. There is no way of sending zero distance codes--a dummy must be
3037 + sent if there are none. (History: a pre 2.0 version of PKZIP would
3038 + store blocks with no distance codes, but this was discovered to be
3039 + too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
3040 + zero distance codes, which is sent as one code of zero bits in
3042 + 6. There are up to 286 literal/length codes. Code 256 represents the
3043 + end-of-block. Note however that the static length tree defines
3044 + 288 codes just to fill out the Huffman codes. Codes 286 and 287
3045 + cannot be used though, since there is no length base or extra bits
3046 + defined for them. Similarily, there are up to 30 distance codes.
3047 + However, static trees define 32 codes (all 5 bits) to fill out the
3048 + Huffman codes, but the last two had better not show up in the data.
3049 + 7. Unzip can check dynamic Huffman blocks for complete code sets.
3050 + The exception is that a single code would not be complete (see #4).
3051 + 8. The five bits following the block type is really the number of
3052 + literal codes sent minus 257.
3053 + 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
3054 + (1+6+6). Therefore, to output three times the length, you output
3055 + three codes (1+1+1), whereas to output four times the same length,
3056 + you only need two codes (1+3). Hmm.
3057 + 10. In the tree reconstruction algorithm, Code = Code + Increment
3058 + only if BitLength(i) is not zero. (Pretty obvious.)
3059 + 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
3060 + 12. Note: length code 284 can represent 227-258, but length code 285
3061 + really is 258. The last length deserves its own, short code
3062 + since it gets used a lot in very redundant files. The length
3063 + 258 is special since 258 - 3 (the min match length) is 255.
3064 + 13. The literal/length and distance code bit lengths are read as a
3065 + single stream of lengths. It is possible (and advantageous) for
3066 + a repeat code (16, 17, or 18) to go across the boundary between
3067 + the two sets of lengths.
3071 +local void inflate_blocks_reset(s, z, c)
3072 +inflate_blocks_statef *s;
3076 + if (s->checkfn != Z_NULL)
3078 + if (s->mode == BTREE || s->mode == DTREE)
3079 + ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
3080 + if (s->mode == CODES)
3082 + inflate_codes_free(s->sub.decode.codes, z);
3083 + inflate_trees_free(s->sub.decode.td, z);
3084 + inflate_trees_free(s->sub.decode.tl, z);
3089 + s->read = s->write = s->window;
3090 + if (s->checkfn != Z_NULL)
3091 + s->check = (*s->checkfn)(0L, Z_NULL, 0);
3092 + Trace((stderr, "inflate: blocks reset\n"));
3096 +local inflate_blocks_statef *inflate_blocks_new(z, c, w)
3101 + inflate_blocks_statef *s;
3103 + if ((s = (inflate_blocks_statef *)ZALLOC
3104 + (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
3106 + if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
3108 + ZFREE(z, s, sizeof(struct inflate_blocks_state));
3111 + s->end = s->window + w;
3114 + Trace((stderr, "inflate: blocks allocated\n"));
3115 + inflate_blocks_reset(s, z, &s->check);
3120 +local int inflate_blocks(s, z, r)
3121 +inflate_blocks_statef *s;
3125 + uInt t; /* temporary storage */
3126 + uLong b; /* bit buffer */
3127 + uInt k; /* bits in bit buffer */
3128 + Bytef *p; /* input data pointer */
3129 + uInt n; /* bytes available there */
3130 + Bytef *q; /* output window write pointer */
3131 + uInt m; /* bytes to end of window or read pointer */
3133 + /* copy input/output information to locals (UPDATE macro restores) */
3136 + /* process input based on current state */
3137 + while (1) switch (s->mode)
3145 + case 0: /* stored */
3146 + Trace((stderr, "inflate: stored block%s\n",
3147 + s->last ? " (last)" : ""));
3149 + t = k & 7; /* go to byte boundary */
3151 + s->mode = LENS; /* get length of stored block */
3153 + case 1: /* fixed */
3154 + Trace((stderr, "inflate: fixed codes block%s\n",
3155 + s->last ? " (last)" : ""));
3158 + inflate_huft *tl, *td;
3160 + inflate_trees_fixed(&bl, &bd, &tl, &td);
3161 + s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
3162 + if (s->sub.decode.codes == Z_NULL)
3167 + s->sub.decode.tl = Z_NULL; /* don't try to free these */
3168 + s->sub.decode.td = Z_NULL;
3173 + case 2: /* dynamic */
3174 + Trace((stderr, "inflate: dynamic codes block%s\n",
3175 + s->last ? " (last)" : ""));
3179 + case 3: /* illegal */
3182 + z->msg = "invalid block type";
3189 + if (((~b) >> 16) != (b & 0xffff))
3192 + z->msg = "invalid stored block lengths";
3196 + s->sub.left = (uInt)b & 0xffff;
3197 + b = k = 0; /* dump bits */
3198 + Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
3199 + s->mode = s->sub.left ? STORED : TYPE;
3211 + if ((s->sub.left -= t) != 0)
3213 + Tracev((stderr, "inflate: stored end, %lu total out\n",
3214 + z->total_out + (q >= s->read ? q - s->read :
3215 + (s->end - s->read) + (q - s->window))));
3216 + s->mode = s->last ? DRY : TYPE;
3220 + s->sub.trees.table = t = (uInt)b & 0x3fff;
3221 +#ifndef PKZIP_BUG_WORKAROUND
3222 + if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
3225 + z->msg = "too many length or distance symbols";
3230 + t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
3233 + if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
3238 + s->sub.trees.nblens = t;
3240 + s->sub.trees.index = 0;
3241 + Tracev((stderr, "inflate: table sizes ok\n"));
3244 + while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
3247 + s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
3250 + while (s->sub.trees.index < 19)
3251 + s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
3252 + s->sub.trees.bb = 7;
3253 + t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
3254 + &s->sub.trees.tb, z);
3258 + if (r == Z_DATA_ERROR)
3262 + s->sub.trees.index = 0;
3263 + Tracev((stderr, "inflate: bits tree ok\n"));
3266 + while (t = s->sub.trees.table,
3267 + s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
3272 + t = s->sub.trees.bb;
3274 + h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
3275 + t = h->word.what.Bits;
3280 + s->sub.trees.blens[s->sub.trees.index++] = c;
3282 + else /* c == 16..18 */
3284 + i = c == 18 ? 7 : c - 14;
3285 + j = c == 18 ? 11 : 3;
3288 + j += (uInt)b & inflate_mask[i];
3290 + i = s->sub.trees.index;
3291 + t = s->sub.trees.table;
3292 + if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
3293 + (c == 16 && i < 1))
3296 + z->msg = "invalid bit length repeat";
3300 + c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
3302 + s->sub.trees.blens[i++] = c;
3304 + s->sub.trees.index = i;
3307 + inflate_trees_free(s->sub.trees.tb, z);
3308 + s->sub.trees.tb = Z_NULL;
3311 + inflate_huft *tl, *td;
3312 + inflate_codes_statef *c;
3314 + bl = 9; /* must be <= 9 for lookahead assumptions */
3315 + bd = 6; /* must be <= 9 for lookahead assumptions */
3316 + t = s->sub.trees.table;
3317 + t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
3318 + s->sub.trees.blens, &bl, &bd, &tl, &td, z);
3321 + if (t == (uInt)Z_DATA_ERROR)
3326 + Tracev((stderr, "inflate: trees ok\n"));
3327 + if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
3329 + inflate_trees_free(td, z);
3330 + inflate_trees_free(tl, z);
3334 + ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
3335 + s->sub.decode.codes = c;
3336 + s->sub.decode.tl = tl;
3337 + s->sub.decode.td = td;
3342 + if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
3343 + return inflate_flush(s, z, r);
3345 + inflate_codes_free(s->sub.decode.codes, z);
3346 + inflate_trees_free(s->sub.decode.td, z);
3347 + inflate_trees_free(s->sub.decode.tl, z);
3349 + Tracev((stderr, "inflate: codes end, %lu total out\n",
3350 + z->total_out + (q >= s->read ? q - s->read :
3351 + (s->end - s->read) + (q - s->window))));
3357 + if (k > 7) /* return unused byte, if any */
3359 + Assert(k < 16, "inflate_codes grabbed too many bytes")
3362 + p--; /* can always return one */
3367 + if (s->read != s->write)
3377 + r = Z_STREAM_ERROR;
3383 +local int inflate_blocks_free(s, z, c)
3384 +inflate_blocks_statef *s;
3388 + inflate_blocks_reset(s, z, c);
3389 + ZFREE(z, s->window, s->end - s->window);
3390 + ZFREE(z, s, sizeof(struct inflate_blocks_state));
3391 + Trace((stderr, "inflate: blocks freed\n"));
3396 + * This subroutine adds the data at next_in/avail_in to the output history
3397 + * without performing any output. The output buffer must be "caught up";
3398 + * i.e. no pending output (hence s->read equals s->write), and the state must
3399 + * be BLOCKS (i.e. we should be willing to see the start of a series of
3400 + * BLOCKS). On exit, the output will also be caught up, and the checksum
3401 + * will have been updated if need be.
3403 +local int inflate_addhistory(s, z)
3404 +inflate_blocks_statef *s;
3407 + uLong b; /* bit buffer */ /* NOT USED HERE */
3408 + uInt k; /* bits in bit buffer */ /* NOT USED HERE */
3409 + uInt t; /* temporary storage */
3410 + Bytef *p; /* input data pointer */
3411 + uInt n; /* bytes available there */
3412 + Bytef *q; /* output window write pointer */
3413 + uInt m; /* bytes to end of window or read pointer */
3415 + if (s->read != s->write)
3416 + return Z_STREAM_ERROR;
3417 + if (s->mode != TYPE)
3418 + return Z_DATA_ERROR;
3420 + /* we're ready to rock */
3422 + /* while there is input ready, copy to output buffer, moving
3423 + * pointers as needed.
3426 + t = n; /* how many to do */
3427 + /* is there room until end of buffer? */
3429 + /* update check information */
3430 + if (s->checkfn != Z_NULL)
3431 + s->check = (*s->checkfn)(s->check, q, t);
3436 + z->total_out += t;
3437 + s->read = q; /* drag read pointer forward */
3438 +/* WRAP */ /* expand WRAP macro by hand to handle s->read */
3439 + if (q == s->end) {
3440 + s->read = q = s->window;
3450 + * At the end of a Deflate-compressed PPP packet, we expect to have seen
3451 + * a `stored' block type value but not the (zero) length bytes.
3453 +local int inflate_packet_flush(s)
3454 + inflate_blocks_statef *s;
3456 + if (s->mode != LENS)
3457 + return Z_DATA_ERROR;
3464 +/* inftrees.c -- generate Huffman trees for efficient decoding
3465 + * Copyright (C) 1995 Mark Adler
3466 + * For conditions of distribution and use, see copyright notice in zlib.h
3469 +/* simplify the use of the inflate_huft type with some defines */
3470 +#define base more.Base
3471 +#define next more.Next
3472 +#define exop word.what.Exop
3473 +#define bits word.what.Bits
3476 +local int huft_build OF((
3477 + uIntf *, /* code lengths in bits */
3478 + uInt, /* number of codes */
3479 + uInt, /* number of "simple" codes */
3480 + uIntf *, /* list of base values for non-simple codes */
3481 + uIntf *, /* list of extra bits for non-simple codes */
3482 + inflate_huft * FAR*,/* result: starting table */
3483 + uIntf *, /* maximum lookup bits (returns actual) */
3484 + z_stream *)); /* for zalloc function */
3486 +local voidpf falloc OF((
3487 + voidpf, /* opaque pointer (not used) */
3488 + uInt, /* number of items */
3489 + uInt)); /* size of item */
3491 +local void ffree OF((
3492 + voidpf q, /* opaque pointer (not used) */
3493 + voidpf p, /* what to free (not used) */
3494 + uInt n)); /* number of bytes (not used) */
3496 +/* Tables for deflate from PKZIP's appnote.txt. */
3497 +local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
3498 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
3499 + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
3500 + /* actually lengths - 2; also see note #13 above about 258 */
3501 +local uInt cplext[] = { /* Extra bits for literal codes 257..285 */
3502 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3503 + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */
3504 +local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */
3505 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
3506 + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
3507 + 8193, 12289, 16385, 24577};
3508 +local uInt cpdext[] = { /* Extra bits for distance codes */
3509 + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
3510 + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
3514 + Huffman code decoding is performed using a multi-level table lookup.
3515 + The fastest way to decode is to simply build a lookup table whose
3516 + size is determined by the longest code. However, the time it takes
3517 + to build this table can also be a factor if the data being decoded
3518 + is not very long. The most common codes are necessarily the
3519 + shortest codes, so those codes dominate the decoding time, and hence
3520 + the speed. The idea is you can have a shorter table that decodes the
3521 + shorter, more probable codes, and then point to subsidiary tables for
3522 + the longer codes. The time it costs to decode the longer codes is
3523 + then traded against the time it takes to make longer tables.
3525 + This results of this trade are in the variables lbits and dbits
3526 + below. lbits is the number of bits the first level table for literal/
3527 + length codes can decode in one step, and dbits is the same thing for
3528 + the distance codes. Subsequent tables are also less than or equal to
3529 + those sizes. These values may be adjusted either when all of the
3530 + codes are shorter than that, in which case the longest code length in
3531 + bits is used, or when the shortest code is *longer* than the requested
3532 + table size, in which case the length of the shortest code in bits is
3535 + There are two different values for the two tables, since they code a
3536 + different number of possibilities each. The literal/length table
3537 + codes 286 possible values, or in a flat code, a little over eight
3538 + bits. The distance table codes 30 possible values, or a little less
3539 + than five bits, flat. The optimum values for speed end up being
3540 + about one bit more than those, so lbits is 8+1 and dbits is 5+1.
3541 + The optimum values may differ though from machine to machine, and
3542 + possibly even between compilers. Your mileage may vary.
3546 +/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
3547 +#define BMAX 15 /* maximum bit length of any code */
3548 +#define N_MAX 288 /* maximum number of codes in any set */
3551 + uInt inflate_hufts;
3554 +local int huft_build(b, n, s, d, e, t, m, zs)
3555 +uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
3556 +uInt n; /* number of codes (assumed <= N_MAX) */
3557 +uInt s; /* number of simple-valued codes (0..s-1) */
3558 +uIntf *d; /* list of base values for non-simple codes */
3559 +uIntf *e; /* list of extra bits for non-simple codes */
3560 +inflate_huft * FAR *t; /* result: starting table */
3561 +uIntf *m; /* maximum lookup bits, returns actual */
3562 +z_stream *zs; /* for zalloc function */
3563 +/* Given a list of code lengths and a maximum table size, make a set of
3564 + tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
3565 + if the given code set is incomplete (the tables are still built in this
3566 + case), Z_DATA_ERROR if the input is invalid (all zero length codes or an
3567 + over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */
3570 + uInt a; /* counter for codes of length k */
3571 + uInt c[BMAX+1]; /* bit length count table */
3572 + uInt f; /* i repeats in table every f entries */
3573 + int g; /* maximum code length */
3574 + int h; /* table level */
3575 + register uInt i; /* counter, current code */
3576 + register uInt j; /* counter */
3577 + register int k; /* number of bits in current code */
3578 + int l; /* bits per table (returned in m) */
3579 + register uIntf *p; /* pointer into c[], b[], or v[] */
3580 + inflate_huft *q; /* points to current table */
3581 + struct inflate_huft_s r; /* table entry for structure assignment */
3582 + inflate_huft *u[BMAX]; /* table stack */
3583 + uInt v[N_MAX]; /* values in order of bit length */
3584 + register int w; /* bits before this table == (l * h) */
3585 + uInt x[BMAX+1]; /* bit offsets, then code stack */
3586 + uIntf *xp; /* pointer into x */
3587 + int y; /* number of dummy codes added */
3588 + uInt z; /* number of entries in current table */
3591 + /* Generate counts for each bit length */
3593 +#define C0 *p++ = 0;
3594 +#define C2 C0 C0 C0 C0
3595 +#define C4 C2 C2 C2 C2
3596 + C4 /* clear c[]--assume BMAX+1 is 16 */
3599 + c[*p++]++; /* assume all entries <= BMAX */
3601 + if (c[0] == n) /* null input--all zero length codes */
3603 + *t = (inflate_huft *)Z_NULL;
3609 + /* Find minimum and maximum length, bound *m by those */
3611 + for (j = 1; j <= BMAX; j++)
3614 + k = j; /* minimum code length */
3617 + for (i = BMAX; i; i--)
3620 + g = i; /* maximum code length */
3626 + /* Adjust last length count to fill out codes, if needed */
3627 + for (y = 1 << j; j < i; j++, y <<= 1)
3628 + if ((y -= c[j]) < 0)
3629 + return Z_DATA_ERROR;
3630 + if ((y -= c[i]) < 0)
3631 + return Z_DATA_ERROR;
3635 + /* Generate starting offsets into the value table for each length */
3637 + p = c + 1; xp = x + 2;
3638 + while (--i) { /* note that i == g from above */
3639 + *xp++ = (j += *p++);
3643 + /* Make a table of values in order of bit lengths */
3646 + if ((j = *p++) != 0)
3648 + } while (++i < n);
3651 + /* Generate the Huffman codes and for each, make the table entries */
3652 + x[0] = i = 0; /* first Huffman code is zero */
3653 + p = v; /* grab values in bit order */
3654 + h = -1; /* no tables yet--level -1 */
3655 + w = -l; /* bits decoded == (l * h) */
3656 + u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
3657 + q = (inflate_huft *)Z_NULL; /* ditto */
3658 + z = 0; /* ditto */
3660 + /* go through the bit lengths (k already is bits in shortest code) */
3661 + for (; k <= g; k++)
3666 + /* here i is the Huffman code of length k bits for value *p */
3667 + /* make tables up to required level */
3671 + w += l; /* previous table always l bits */
3673 + /* compute minimum size table less than or equal to l bits */
3674 + z = (z = g - w) > (uInt)l ? l : z; /* table size upper limit */
3675 + if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
3676 + { /* too few codes for k-w bit table */
3677 + f -= a + 1; /* deduct codes from patterns left */
3680 + while (++j < z) /* try smaller tables up to z bits */
3682 + if ((f <<= 1) <= *++xp)
3683 + break; /* enough codes to use up j bits */
3684 + f -= *xp; /* else deduct codes from patterns */
3687 + z = 1 << j; /* table entries for j-bit table */
3689 + /* allocate and link in new table */
3690 + if ((q = (inflate_huft *)ZALLOC
3691 + (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
3694 + inflate_trees_free(u[0], zs);
3695 + return Z_MEM_ERROR; /* not enough memory */
3697 + q->word.Nalloc = z + 1;
3699 + inflate_hufts += z + 1;
3701 + *t = q + 1; /* link to list for huft_free() */
3702 + *(t = &(q->next)) = Z_NULL;
3703 + u[h] = ++q; /* table starts after link */
3705 + /* connect to last table, if there is one */
3708 + x[h] = i; /* save pattern for backing up */
3709 + r.bits = (Byte)l; /* bits to dump before this table */
3710 + r.exop = (Byte)j; /* bits in this table */
3711 + r.next = q; /* pointer to this table */
3712 + j = i >> (w - l); /* (get around Turbo C bug) */
3713 + u[h-1][j] = r; /* connect to last table */
3717 + /* set up table entry in r */
3718 + r.bits = (Byte)(k - w);
3720 + r.exop = 128 + 64; /* out of values--invalid code */
3723 + r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
3724 + r.base = *p++; /* simple code is just the value */
3728 + r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */
3729 + r.base = d[*p++ - s];
3732 + /* fill code-like entries with r */
3734 + for (j = i >> w; j < z; j += f)
3737 + /* backwards increment the k-bit code i */
3738 + for (j = 1 << (k - 1); i & j; j >>= 1)
3742 + /* backup over finished tables */
3743 + while ((i & ((1 << w) - 1)) != x[h])
3745 + h--; /* don't need to update q */
3752 + /* Return Z_BUF_ERROR if we were given an incomplete table */
3753 + return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
3757 +local int inflate_trees_bits(c, bb, tb, z)
3758 +uIntf *c; /* 19 code lengths */
3759 +uIntf *bb; /* bits tree desired/actual depth */
3760 +inflate_huft * FAR *tb; /* bits tree result */
3761 +z_stream *z; /* for zfree function */
3765 + r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
3766 + if (r == Z_DATA_ERROR)
3767 + z->msg = "oversubscribed dynamic bit lengths tree";
3768 + else if (r == Z_BUF_ERROR)
3770 + inflate_trees_free(*tb, z);
3771 + z->msg = "incomplete dynamic bit lengths tree";
3778 +local int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
3779 +uInt nl; /* number of literal/length codes */
3780 +uInt nd; /* number of distance codes */
3781 +uIntf *c; /* that many (total) code lengths */
3782 +uIntf *bl; /* literal desired/actual bit depth */
3783 +uIntf *bd; /* distance desired/actual bit depth */
3784 +inflate_huft * FAR *tl; /* literal/length tree result */
3785 +inflate_huft * FAR *td; /* distance tree result */
3786 +z_stream *z; /* for zfree function */
3790 + /* build literal/length tree */
3791 + if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK)
3793 + if (r == Z_DATA_ERROR)
3794 + z->msg = "oversubscribed literal/length tree";
3795 + else if (r == Z_BUF_ERROR)
3797 + inflate_trees_free(*tl, z);
3798 + z->msg = "incomplete literal/length tree";
3804 + /* build distance tree */
3805 + if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK)
3807 + if (r == Z_DATA_ERROR)
3808 + z->msg = "oversubscribed literal/length tree";
3809 + else if (r == Z_BUF_ERROR) {
3810 +#ifdef PKZIP_BUG_WORKAROUND
3814 + inflate_trees_free(*td, z);
3815 + z->msg = "incomplete literal/length tree";
3818 + inflate_trees_free(*tl, z);
3828 +/* build fixed tables only once--keep them here */
3829 +local int fixed_lock = 0;
3830 +local int fixed_built = 0;
3831 +#define FIXEDH 530 /* number of hufts used by fixed tables */
3832 +local uInt fixed_left = FIXEDH;
3833 +local inflate_huft fixed_mem[FIXEDH];
3834 +local uInt fixed_bl;
3835 +local uInt fixed_bd;
3836 +local inflate_huft *fixed_tl;
3837 +local inflate_huft *fixed_td;
3840 +local voidpf falloc(q, n, s)
3841 +voidpf q; /* opaque pointer (not used) */
3842 +uInt n; /* number of items */
3843 +uInt s; /* size of item */
3845 + Assert(s == sizeof(inflate_huft) && n <= fixed_left,
3846 + "inflate_trees falloc overflow");
3847 + if (q) s++; /* to make some compilers happy */
3849 + return (voidpf)(fixed_mem + fixed_left);
3853 +local void ffree(q, p, n)
3858 + Assert(0, "inflate_trees ffree called!");
3859 + if (q) q = p; /* to make some compilers happy */
3863 +local int inflate_trees_fixed(bl, bd, tl, td)
3864 +uIntf *bl; /* literal desired/actual bit depth */
3865 +uIntf *bd; /* distance desired/actual bit depth */
3866 +inflate_huft * FAR *tl; /* literal/length tree result */
3867 +inflate_huft * FAR *td; /* distance tree result */
3869 + /* build fixed tables if not built already--lock out other instances */
3870 + while (++fixed_lock > 1)
3874 + int k; /* temporary variable */
3875 + unsigned c[288]; /* length list for huft_build */
3876 + z_stream z; /* for falloc function */
3878 + /* set up fake z_stream for memory routines */
3879 + z.zalloc = falloc;
3881 + z.opaque = Z_NULL;
3883 + /* literal table */
3884 + for (k = 0; k < 144; k++)
3886 + for (; k < 256; k++)
3888 + for (; k < 280; k++)
3890 + for (; k < 288; k++)
3893 + huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
3895 + /* distance table */
3896 + for (k = 0; k < 30; k++)
3899 + huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
3913 +local int inflate_trees_free(t, z)
3914 +inflate_huft *t; /* table to free */
3915 +z_stream *z; /* for zfree function */
3916 +/* Free the malloc'ed tables built by huft_build(), which makes a linked
3917 + list of the tables it made, with the links in a dummy first entry of
3920 + register inflate_huft *p, *q;
3922 + /* Go through linked list, freeing from the malloced (t[-1]) address. */
3924 + while (p != Z_NULL)
3927 + ZFREE(z, p, p->word.Nalloc * sizeof(inflate_huft));
3934 +/* infcodes.c -- process literals and length/distance pairs
3935 + * Copyright (C) 1995 Mark Adler
3936 + * For conditions of distribution and use, see copyright notice in zlib.h
3939 +/* simplify the use of the inflate_huft type with some defines */
3940 +#define base more.Base
3941 +#define next more.Next
3942 +#define exop word.what.Exop
3943 +#define bits word.what.Bits
3945 +/* inflate codes private state */
3946 +struct inflate_codes_state {
3949 + enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
3950 + START, /* x: set up for LEN */
3951 + LEN, /* i: get length/literal/eob next */
3952 + LENEXT, /* i: getting length extra (have base) */
3953 + DIST, /* i: get distance next */
3954 + DISTEXT, /* i: getting distance extra */
3955 + COPY, /* o: copying bytes in window, waiting for space */
3956 + LIT, /* o: got literal, waiting for output space */
3957 + WASH, /* o: got eob, possibly still output waiting */
3958 + END, /* x: got eob and all data flushed */
3959 + BADCODE} /* x: got error */
3960 + mode; /* current inflate_codes mode */
3962 + /* mode dependent information */
3966 + inflate_huft *tree; /* pointer into tree */
3967 + uInt need; /* bits needed */
3968 + } code; /* if LEN or DIST, where in tree */
3969 + uInt lit; /* if LIT, literal */
3971 + uInt get; /* bits to get for extra */
3972 + uInt dist; /* distance back to copy from */
3973 + } copy; /* if EXT or COPY, where and how much */
3974 + } sub; /* submode */
3976 + /* mode independent information */
3977 + Byte lbits; /* ltree bits decoded per branch */
3978 + Byte dbits; /* dtree bits decoder per branch */
3979 + inflate_huft *ltree; /* literal/length/eob tree */
3980 + inflate_huft *dtree; /* distance tree */
3985 +local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
3987 +inflate_huft *tl, *td;
3990 + inflate_codes_statef *c;
3992 + if ((c = (inflate_codes_statef *)
3993 + ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
3996 + c->lbits = (Byte)bl;
3997 + c->dbits = (Byte)bd;
4000 + Tracev((stderr, "inflate: codes new\n"));
4006 +local int inflate_codes(s, z, r)
4007 +inflate_blocks_statef *s;
4011 + uInt j; /* temporary storage */
4012 + inflate_huft *t; /* temporary pointer */
4013 + uInt e; /* extra bits or operation */
4014 + uLong b; /* bit buffer */
4015 + uInt k; /* bits in bit buffer */
4016 + Bytef *p; /* input data pointer */
4017 + uInt n; /* bytes available there */
4018 + Bytef *q; /* output window write pointer */
4019 + uInt m; /* bytes to end of window or read pointer */
4020 + Bytef *f; /* pointer to copy strings from */
4021 + inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
4023 + /* copy input/output information to locals (UPDATE macro restores) */
4026 + /* process input and output based on current state */
4027 + while (1) switch (c->mode)
4028 + { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
4029 + case START: /* x: set up for LEN */
4031 + if (m >= 258 && n >= 10)
4034 + r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
4038 + c->mode = r == Z_STREAM_END ? WASH : BADCODE;
4043 + c->sub.code.need = c->lbits;
4044 + c->sub.code.tree = c->ltree;
4046 + case LEN: /* i: get length/literal/eob next */
4047 + j = c->sub.code.need;
4049 + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4051 + e = (uInt)(t->exop);
4052 + if (e == 0) /* literal */
4054 + c->sub.lit = t->base;
4055 + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4056 + "inflate: literal '%c'\n" :
4057 + "inflate: literal 0x%02x\n", t->base));
4061 + if (e & 16) /* length */
4063 + c->sub.copy.get = e & 15;
4068 + if ((e & 64) == 0) /* next table */
4070 + c->sub.code.need = e;
4071 + c->sub.code.tree = t->next;
4074 + if (e & 32) /* end of block */
4076 + Tracevv((stderr, "inflate: end of block\n"));
4080 + c->mode = BADCODE; /* invalid code */
4081 + z->msg = "invalid literal/length code";
4084 + case LENEXT: /* i: getting length extra (have base) */
4085 + j = c->sub.copy.get;
4087 + c->len += (uInt)b & inflate_mask[j];
4089 + c->sub.code.need = c->dbits;
4090 + c->sub.code.tree = c->dtree;
4091 + Tracevv((stderr, "inflate: length %u\n", c->len));
4093 + case DIST: /* i: get distance next */
4094 + j = c->sub.code.need;
4096 + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
4098 + e = (uInt)(t->exop);
4099 + if (e & 16) /* distance */
4101 + c->sub.copy.get = e & 15;
4102 + c->sub.copy.dist = t->base;
4103 + c->mode = DISTEXT;
4106 + if ((e & 64) == 0) /* next table */
4108 + c->sub.code.need = e;
4109 + c->sub.code.tree = t->next;
4112 + c->mode = BADCODE; /* invalid code */
4113 + z->msg = "invalid distance code";
4116 + case DISTEXT: /* i: getting distance extra */
4117 + j = c->sub.copy.get;
4119 + c->sub.copy.dist += (uInt)b & inflate_mask[j];
4121 + Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
4123 + case COPY: /* o: copying bytes in window, waiting for space */
4124 +#ifndef __TURBOC__ /* Turbo C bug for following expression */
4125 + f = (uInt)(q - s->window) < c->sub.copy.dist ?
4126 + s->end - (c->sub.copy.dist - (q - s->window)) :
4127 + q - c->sub.copy.dist;
4129 + f = q - c->sub.copy.dist;
4130 + if ((uInt)(q - s->window) < c->sub.copy.dist)
4131 + f = s->end - (c->sub.copy.dist - (q - s->window));
4143 + case LIT: /* o: got literal, waiting for output space */
4145 + OUTBYTE(c->sub.lit)
4148 + case WASH: /* o: got eob, possibly more output */
4150 + if (s->read != s->write)
4156 + case BADCODE: /* x: got error */
4160 + r = Z_STREAM_ERROR;
4166 +local void inflate_codes_free(c, z)
4167 +inflate_codes_statef *c;
4170 + ZFREE(z, c, sizeof(struct inflate_codes_state));
4171 + Tracev((stderr, "inflate: codes free\n"));
4175 +/* inflate_util.c -- data and routines common to blocks and codes
4176 + * Copyright (C) 1995 Mark Adler
4177 + * For conditions of distribution and use, see copyright notice in zlib.h
4180 +/* copy as much as possible from the sliding window to the output area */
4181 +local int inflate_flush(s, z, r)
4182 +inflate_blocks_statef *s;
4189 + /* local copies of source and destination pointers */
4193 + /* compute number of bytes to copy as far as end of window */
4194 + n = (uInt)((q <= s->write ? s->write : s->end) - q);
4195 + if (n > z->avail_out) n = z->avail_out;
4196 + if (n && r == Z_BUF_ERROR) r = Z_OK;
4198 + /* update counters */
4199 + z->avail_out -= n;
4200 + z->total_out += n;
4202 + /* update check information */
4203 + if (s->checkfn != Z_NULL)
4204 + s->check = (*s->checkfn)(s->check, q, n);
4206 + /* copy as far as end of window */
4211 + /* see if more to copy at beginning of window */
4214 + /* wrap pointers */
4216 + if (s->write == s->end)
4217 + s->write = s->window;
4219 + /* compute bytes to copy */
4220 + n = (uInt)(s->write - q);
4221 + if (n > z->avail_out) n = z->avail_out;
4222 + if (n && r == Z_BUF_ERROR) r = Z_OK;
4224 + /* update counters */
4225 + z->avail_out -= n;
4226 + z->total_out += n;
4228 + /* update check information */
4229 + if (s->checkfn != Z_NULL)
4230 + s->check = (*s->checkfn)(s->check, q, n);
4238 + /* update pointers */
4248 +/* inffast.c -- process literals and length/distance pairs fast
4249 + * Copyright (C) 1995 Mark Adler
4250 + * For conditions of distribution and use, see copyright notice in zlib.h
4253 +/* simplify the use of the inflate_huft type with some defines */
4254 +#define base more.Base
4255 +#define next more.Next
4256 +#define exop word.what.Exop
4257 +#define bits word.what.Bits
4259 +/* macros for bit input with no checking and for returning unused bytes */
4260 +#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
4261 +#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
4263 +/* Called with number of bytes left to write in window at least 258
4264 + (the maximum string length) and number of input bytes available
4265 + at least ten. The ten bytes are six bytes for the longest length/
4266 + distance pair plus four bytes for overloading the bit buffer. */
4268 +local int inflate_fast(bl, bd, tl, td, s, z)
4270 +inflate_huft *tl, *td;
4271 +inflate_blocks_statef *s;
4274 + inflate_huft *t; /* temporary pointer */
4275 + uInt e; /* extra bits or operation */
4276 + uLong b; /* bit buffer */
4277 + uInt k; /* bits in bit buffer */
4278 + Bytef *p; /* input data pointer */
4279 + uInt n; /* bytes available there */
4280 + Bytef *q; /* output window write pointer */
4281 + uInt m; /* bytes to end of window or read pointer */
4282 + uInt ml; /* mask for literal/length tree */
4283 + uInt md; /* mask for distance tree */
4284 + uInt c; /* bytes to copy */
4285 + uInt d; /* distance back to copy from */
4286 + Bytef *r; /* copy source pointer */
4288 + /* load input, output, bit values */
4291 + /* initialize masks */
4292 + ml = inflate_mask[bl];
4293 + md = inflate_mask[bd];
4295 + /* do until not enough input or output space for fast loop */
4296 + do { /* assume called with m >= 258 && n >= 10 */
4297 + /* get literal/length code */
4298 + GRABBITS(20) /* max bits for literal/length code */
4299 + if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
4302 + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4303 + "inflate: * literal '%c'\n" :
4304 + "inflate: * literal 0x%02x\n", t->base));
4305 + *q++ = (Byte)t->base;
4313 + /* get extra bits for length */
4315 + c = t->base + ((uInt)b & inflate_mask[e]);
4317 + Tracevv((stderr, "inflate: * length %u\n", c));
4319 + /* decode distance base of block to copy */
4320 + GRABBITS(15); /* max bits for distance code */
4321 + e = (t = td + ((uInt)b & md))->exop;
4326 + /* get extra bits to add to distance base */
4328 + GRABBITS(e) /* get extra bits (up to 13) */
4329 + d = t->base + ((uInt)b & inflate_mask[e]);
4331 + Tracevv((stderr, "inflate: * distance %u\n", d));
4335 + if ((uInt)(q - s->window) >= d) /* offset before dest */
4338 + *q++ = *r++; c--; /* minimum count is three, */
4339 + *q++ = *r++; c--; /* so unroll loop a little */
4341 + else /* else offset after destination */
4343 + e = d - (q - s->window); /* bytes from offset to end */
4344 + r = s->end - e; /* pointer to offset */
4345 + if (c > e) /* if source crosses, */
4347 + c -= e; /* copy to end of window */
4351 + r = s->window; /* copy rest from start of window */
4354 + do { /* copy all or what's left */
4359 + else if ((e & 64) == 0)
4360 + e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
4363 + z->msg = "invalid distance code";
4366 + return Z_DATA_ERROR;
4371 + if ((e & 64) == 0)
4373 + if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
4376 + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
4377 + "inflate: * literal '%c'\n" :
4378 + "inflate: * literal 0x%02x\n", t->base));
4379 + *q++ = (Byte)t->base;
4386 + Tracevv((stderr, "inflate: * end of block\n"));
4389 + return Z_STREAM_END;
4393 + z->msg = "invalid literal/length code";
4396 + return Z_DATA_ERROR;
4399 + } while (m >= 258 && n >= 10);
4401 + /* not enough input or output--restore pointers and return */
4409 +/* zutil.c -- target dependent utility functions for the compression library
4410 + * Copyright (C) 1995 Jean-loup Gailly.
4411 + * For conditions of distribution and use, see copyright notice in zlib.h
4414 +/* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */
4416 +char *zlib_version = ZLIB_VERSION;
4418 +char *z_errmsg[] = {
4419 +"stream end", /* Z_STREAM_END 1 */
4421 +"file error", /* Z_ERRNO (-1) */
4422 +"stream error", /* Z_STREAM_ERROR (-2) */
4423 +"data error", /* Z_DATA_ERROR (-3) */
4424 +"insufficient memory", /* Z_MEM_ERROR (-4) */
4425 +"buffer error", /* Z_BUF_ERROR (-5) */
4430 +/* adler32.c -- compute the Adler-32 checksum of a data stream
4431 + * Copyright (C) 1995 Mark Adler
4432 + * For conditions of distribution and use, see copyright notice in zlib.h
4435 +/* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */
4437 +#define BASE 65521L /* largest prime smaller than 65536 */
4439 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
4441 +#define DO1(buf) {s1 += *buf++; s2 += s1;}
4442 +#define DO2(buf) DO1(buf); DO1(buf);
4443 +#define DO4(buf) DO2(buf); DO2(buf);
4444 +#define DO8(buf) DO4(buf); DO4(buf);
4445 +#define DO16(buf) DO8(buf); DO8(buf);
4447 +/* ========================================================================= */
4448 +uLong adler32(adler, buf, len)
4453 + unsigned long s1 = adler & 0xffff;
4454 + unsigned long s2 = (adler >> 16) & 0xffff;
4457 + if (buf == Z_NULL) return 1L;
4460 + k = len < NMAX ? len : NMAX;
4472 + return (s2 << 16) | s1;
4474 diff -Naru linux/arch/mips/zboot/Makefile linux-new/arch/mips/zboot/Makefile
4475 --- linux/arch/mips/zboot/Makefile 1969-12-31 19:00:00.000000000 -0500
4476 +++ linux-new/arch/mips/zboot/Makefile 2003-12-18 14:26:21.000000000 -0500
4479 +# arch/mips/zboot/Makefile
4481 +# This file is subject to the terms and conditions of the GNU General Public
4482 +# License. See the file "COPYING" in the main directory of this archive
4483 +# for more details.
4485 +# Adapted for MIPS Pete Popov, Dan Malek
4487 +# Copyright (C) 1994 by Linus Torvalds
4488 +# Adapted for PowerPC by Gary Thomas
4489 +# modified by Cort (cort@cs.nmt.edu)
4493 + $(CC) $(CFLAGS) -S -o $*.s $<
4497 + $(CC) $(CFLAGS) -c -o $*.o $<
4499 + $(CPP) $(AFLAGS) -o $*.o $<
4501 + $(CC) $(AFLAGS) -c -o $*.o $<
4505 +CFLAGS := $(CPPFLAGS) -O2 -D__BOOTER__ \
4506 + -fomit-frame-pointer -fno-strict-aliasing -fno-common \
4507 + -G 0 -mno-abicalls -fno-pic -mcpu=r4600 -mips2 \
4508 + -I$(TOPDIR)/arch/$(ARCH)/zboot/include \
4509 + -I$(TOPDIR)/include/asm
4510 +AFLAGS += -D__BOOTER__
4512 +BOOT_TARGETS = zImage zImage.initrd zImage.flash zImage.initrd.flash
4517 +images/vmlinux.gz: $(TOPDIR)/vmlinux
4518 + $(MAKE) -C images vmlinux.gz
4520 +$(BOOT_TARGETS): lib/zlib.a images/vmlinux.gz
4521 +ifdef CONFIG_MIPS_PB1000
4522 + $(MAKE) -C pb1xxx $@
4524 +ifdef CONFIG_MIPS_PB1500
4525 + $(MAKE) -C pb1xxx $@
4527 +ifdef CONFIG_MIPS_PB1100
4528 + $(MAKE) -C pb1xxx $@
4530 +ifdef CONFIG_MIPS_DB1000
4531 + $(MAKE) -C pb1xxx $@
4533 +ifdef CONFIG_MIPS_DB1100
4534 + $(MAKE) -C pb1xxx $@
4536 +ifdef CONFIG_MIPS_DB1500
4537 + $(MAKE) -C pb1xxx $@
4539 +ifdef CONFIG_MIPS_BOSPORUS
4540 + $(MAKE) -C pb1xxx $@
4542 +ifdef CONFIG_COGENT_CSB250
4543 + $(MAKE) -C csb250 $@
4545 +ifdef CONFIG_MIPS_XXS1500
4551 + $(MAKE) -C common clean
4552 + $(MAKE) -C images clean
4553 + $(MAKE) -C pb1xxx clean
4554 + $(MAKE) -C xxs1500 clean
4556 +include $(TOPDIR)/Rules.make
4557 diff -Naru linux/arch/mips/zboot/pb1xxx/head.S linux-new/arch/mips/zboot/pb1xxx/head.S
4558 --- linux/arch/mips/zboot/pb1xxx/head.S 1969-12-31 19:00:00.000000000 -0500
4559 +++ linux-new/arch/mips/zboot/pb1xxx/head.S 2003-12-18 14:26:21.000000000 -0500
4562 + * arch/mips/kernel/head.S
4564 + * This file is subject to the terms and conditions of the GNU General Public
4565 + * License. See the file "COPYING" in the main directory of this archive
4566 + * for more details.
4568 + * Copyright (C) 1994, 1995 Waldorf Electronics
4569 + * Written by Ralf Baechle and Andreas Busse
4570 + * Copyright (C) 1995 - 1999 Ralf Baechle
4571 + * Copyright (C) 1996 Paul M. Antoine
4572 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
4573 + * Further modifications by David S. Miller and Harald Koerfgen
4574 + * Copyright (C) 1999 Silicon Graphics, Inc.
4576 + * Head.S contains the MIPS exception handler and startup code.
4578 + **************************************************************************
4580 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
4582 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4583 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4584 + **************************************************************************
4586 +#include <linux/config.h>
4587 +#include <linux/threads.h>
4589 +#include <asm/asm.h>
4590 +#include <asm/cacheops.h>
4591 +#include <asm/mipsregs.h>
4592 +#include <asm/offset.h>
4593 +#include <asm/cachectl.h>
4594 +#include <asm/regdef.h>
4596 +#define IndexInvalidate_I 0x00
4597 +#define IndexWriteBack_D 0x01
4606 + subu s8, ra, 8 /* Where we were loaded */
4607 + la sp, (.stack + 8192)
4609 + move s0, a0 /* Save boot rom start args */
4614 + la a0, start /* Where we were linked to run */
4621 + /* copy text section */
4638 + /* push the D-Cache and invalidate I-Cache */
4639 + li k0, 0x80000000 # start address
4640 + li k1, 0x80004000 # end address (16KB I-Cache)
4645 + cache IndexWriteBack_D, 0(k0)
4646 + cache IndexWriteBack_D, 32(k0)
4647 + cache IndexWriteBack_D, 64(k0)
4648 + cache IndexWriteBack_D, 96(k0)
4649 + cache IndexInvalidate_I, 0(k0)
4650 + cache IndexInvalidate_I, 32(k0)
4651 + cache IndexInvalidate_I, 64(k0)
4652 + cache IndexInvalidate_I, 96(k0)
4659 + move a0, s8 /* load address */
4660 + move a1, t1 /* length in words */
4661 + move a2, t0 /* checksum */
4665 + la k0, decompress_kernel
4674 + li k0, KERNEL_ENTRY
4687 + li k0, 0x80000000 # start address
4688 + li k1, 0x80004000 # end address (16KB I-Cache)
4693 + cache IndexWriteBack_D, 0(k0)
4694 + cache IndexWriteBack_D, 32(k0)
4695 + cache IndexWriteBack_D, 64(k0)
4696 + cache IndexWriteBack_D, 96(k0)
4697 + cache IndexInvalidate_I, 0(k0)
4698 + cache IndexInvalidate_I, 32(k0)
4699 + cache IndexInvalidate_I, 64(k0)
4700 + cache IndexInvalidate_I, 96(k0)
4709 + .comm .stack,4096*2,4
4710 diff -Naru linux/arch/mips/zboot/pb1xxx/Makefile linux-new/arch/mips/zboot/pb1xxx/Makefile
4711 --- linux/arch/mips/zboot/pb1xxx/Makefile 1969-12-31 19:00:00.000000000 -0500
4712 +++ linux-new/arch/mips/zboot/pb1xxx/Makefile 2003-12-18 14:26:21.000000000 -0500
4714 +# arch/mips/zboot/pb1xxx/Makefile
4716 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
4717 +# All of the boot loader code was derived from the ppc
4720 +# Copyright 2001,2002 MontaVista Software Inc.
4722 +# Author: Mark A. Greer
4723 +# mgreer@mvista.com
4724 +# Ported and modified for mips support by
4725 +# Pete Popov <ppopov@mvista.com>
4727 +# This program is free software; you can redistribute it and/or modify it
4728 +# under the terms of the GNU General Public License as published by the
4729 +# Free Software Foundation; either version 2 of the License, or (at your
4730 +# option) any later version.
4733 + $(CC) $(CFLAGS) -S -o $*.s $<
4737 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
4739 + $(CPP) $(AFLAGS) -o $*.o $<
4741 + $(CC) $(AFLAGS) -c -o $*.o $<
4743 +#########################################################################
4744 +# START BOARD SPECIFIC VARIABLES
4745 +ifdef CONFIG_MIPS_PB1000
4749 +ifdef CONFIG_MIPS_PB1100
4753 +ifdef CONFIG_MIPS_PB1500
4757 +ifdef CONFIG_MIPS_DB1000
4761 +ifdef CONFIG_MIPS_DB1100
4765 +ifdef CONFIG_MIPS_DB1500
4769 +ifdef CONFIG_MIPS_BOSPORUS
4773 +# These two variables control where the zImage is stored
4774 +# in flash and loaded in memory. It only controls how the srec
4775 +# file is generated, the code is the same.
4776 +RAM_RUN_ADDR = 0x81000000
4777 +FLASH_LOAD_ADDR = 0xBFD00000
4779 +# These two variables specify the free ram region
4780 +# that can be used for temporary malloc area
4781 +AVAIL_RAM_START=0x80400000
4782 +AVAIL_RAM_END=0x80800000
4784 +# This one must match the LOADADDR in arch/mips/Makefile!
4785 +LOADADDR=0x80100000
4786 +# END BOARD SPECIFIC VARIABLES
4787 +#########################################################################
4789 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
4790 + ../common/au1k_uart.o ../common/string.o ../common/ctype.o
4791 +LIBS := ../lib/zlib.a
4793 +ENTRY := ../utils/entry
4794 +OFFSET := ../utils/offset
4795 +SIZE := ../utils/size
4797 +LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
4798 +OBJCOPY_ARGS = -O elf32-tradlittlemips
4803 + rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec
4805 +head.o: head.S $(TOPDIR)/vmlinux
4807 + -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
4810 +../common/misc-simple.o:
4811 + $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
4812 + -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
4813 + -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
4814 + -DLOADADDR=$(LOADADDR) \
4815 + -DZIMAGE_SIZE=0 -c -o $@ $*.c
4817 +zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
4819 + --add-section=.image=../images/vmlinux.gz \
4820 + --set-section-flags=.image=contents,alloc,load,readonly,data \
4821 + ../common/dummy.o image.o
4822 + $(LD) $(LD_ARGS) -o $@ $(OBJECTS) image.o $(LIBS)
4823 + $(OBJCOPY) $(OBJCOPY_ARGS) $@ $@ -R .comment -R .stab -R .stabstr \
4824 + -R .initrd -R .sysmap
4826 +# Here we manipulate the image in order to get it the necessary
4827 +# srecord file we need.
4829 + mv zvmlinux ../images/zImage.$(BNAME)
4830 + $(OBJCOPY) -O srec ../images/zImage.$(BNAME) ../images/$(BNAME).srec
4832 +zImage.flash: zImage
4833 + $(OBJCOPY) -O srec --adjust-vma 0x3ed00000 \
4834 + ../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec
4836 +include $(TOPDIR)/Rules.make
4837 diff -Naru linux/arch/mips/zboot/utils/entry linux-new/arch/mips/zboot/utils/entry
4838 --- linux/arch/mips/zboot/utils/entry 1969-12-31 19:00:00.000000000 -0500
4839 +++ linux-new/arch/mips/zboot/utils/entry 2003-12-18 14:26:21.000000000 -0500
4843 +# grab the kernel_entry address from the vmlinux elf image
4844 +entry=`$1 $2 | grep kernel_entry`
4846 +fs=`echo $entry | grep ffffffff` # check toolchain output
4848 +if [ -n "$fs" ]; then
4849 + echo "0x"`$1 $2 | grep kernel_entry | cut -c9- | awk '{print $1}'`
4851 + echo "0x"`$1 $2 | grep kernel_entry | cut -c1- | awk '{print $1}'`
4853 diff -Naru linux/arch/mips/zboot/utils/offset linux-new/arch/mips/zboot/utils/offset
4854 --- linux/arch/mips/zboot/utils/offset 1969-12-31 19:00:00.000000000 -0500
4855 +++ linux-new/arch/mips/zboot/utils/offset 2003-12-18 14:26:21.000000000 -0500
4859 +echo "0x"`$1 -h $2 | grep $3 | grep -v zvmlinux| awk '{print $6}'`
4860 diff -Naru linux/arch/mips/zboot/utils/size linux-new/arch/mips/zboot/utils/size
4861 --- linux/arch/mips/zboot/utils/size 1969-12-31 19:00:00.000000000 -0500
4862 +++ linux-new/arch/mips/zboot/utils/size 2003-12-18 14:26:21.000000000 -0500
4866 +OFFSET=`$1 -h $2 | grep $3 | grep -v zvmlinux | awk '{print $3}'`
4868 diff -Naru linux/arch/mips/zboot/xxs1500/head.S linux-new/arch/mips/zboot/xxs1500/head.S
4869 --- linux/arch/mips/zboot/xxs1500/head.S 1969-12-31 19:00:00.000000000 -0500
4870 +++ linux-new/arch/mips/zboot/xxs1500/head.S 2003-12-18 14:26:21.000000000 -0500
4873 + * arch/mips/kernel/head.S
4875 + * This file is subject to the terms and conditions of the GNU General Public
4876 + * License. See the file "COPYING" in the main directory of this archive
4877 + * for more details.
4879 + * Copyright (C) 1994, 1995 Waldorf Electronics
4880 + * Written by Ralf Baechle and Andreas Busse
4881 + * Copyright (C) 1995 - 1999 Ralf Baechle
4882 + * Copyright (C) 1996 Paul M. Antoine
4883 + * Modified for DECStation and hence R3000 support by Paul M. Antoine
4884 + * Further modifications by David S. Miller and Harald Koerfgen
4885 + * Copyright (C) 1999 Silicon Graphics, Inc.
4887 + * Head.S contains the MIPS exception handler and startup code.
4889 + **************************************************************************
4891 + * Added Cache Error exception handler and SBDDP EJTAG debug exception.
4893 + * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
4894 + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4895 + **************************************************************************
4897 +#include <linux/config.h>
4898 +#include <linux/threads.h>
4900 +#include <asm/asm.h>
4901 +#include <asm/cacheops.h>
4902 +#include <asm/mipsregs.h>
4903 +#include <asm/offset.h>
4904 +#include <asm/cachectl.h>
4905 +#include <asm/regdef.h>
4907 +#define IndexInvalidate_I 0x00
4923 + li a1, FLASH_LOAD_ADDR
4928 + /* copy text section */
4945 + /* flush the I-Cache */
4946 + li k0, 0x80000000 # start address
4947 + li k1, 0x80004000 # end address (16KB I-Cache)
4952 + cache IndexInvalidate_I, 0(k0)
4953 + cache IndexInvalidate_I, 32(k0)
4954 + cache IndexInvalidate_I, 64(k0)
4955 + cache IndexInvalidate_I, 96(k0)
4962 + li a0, FLASH_LOAD_ADDR /* load address */
4963 + move a1, t1 /* length in words */
4964 + move a2, t0 /* checksum */
4968 + la k0, decompress_kernel
4977 + li k0, KERNEL_ENTRY
4990 + li k0, 0x80000000 # start address
4991 + li k1, 0x80004000 # end address (16KB I-Cache)
4996 + cache IndexInvalidate_I, 0(k0)
4997 + cache IndexInvalidate_I, 32(k0)
4998 + cache IndexInvalidate_I, 64(k0)
4999 + cache IndexInvalidate_I, 96(k0)
5008 + .comm .stack,4096*2,4
5009 diff -Naru linux/arch/mips/zboot/xxs1500/ld.script linux-new/arch/mips/zboot/xxs1500/ld.script
5010 --- linux/arch/mips/zboot/xxs1500/ld.script 1969-12-31 19:00:00.000000000 -0500
5011 +++ linux-new/arch/mips/zboot/xxs1500/ld.script 2003-12-18 14:26:21.000000000 -0500
5017 + /* Read-only sections, merged into text segment: */
5018 + /* . = 0x81000000; */
5019 + .init : { *(.init) } =0
5026 + /* .gnu.warning sections are handled specially by elf32.em. */
5029 + .kstrtab : { *(.kstrtab) }
5031 + . = ALIGN(16); /* Exception table */
5032 + __start___ex_table = .;
5033 + __ex_table : { *(__ex_table) }
5034 + __stop___ex_table = .;
5036 + __start___dbe_table = .; /* Exception table for data bus errors */
5037 + __dbe_table : { *(__dbe_table) }
5038 + __stop___dbe_table = .;
5040 + __start___ksymtab = .; /* Kernel symbol table */
5041 + __ksymtab : { *(__ksymtab) }
5042 + __stop___ksymtab = .;
5047 + .data.init_task : { *(.data.init_task) }
5049 + /* Startup code */
5052 + .text.init : { *(.text.init) }
5053 + .data.init : { *(.data.init) }
5055 + __setup_start = .;
5056 + .setup.init : { *(.setup.init) }
5058 + __initcall_start = .;
5059 + .initcall.init : { *(.initcall.init) }
5060 + __initcall_end = .;
5061 + . = ALIGN(4096); /* Align double page for init_task_union */
5065 + .data.page_aligned : { *(.data.idt) }
5068 + .data.cacheline_aligned : { *(.data.cacheline_aligned) }
5070 + .fini : { *(.fini) } =0
5071 + .reginfo : { *(.reginfo) }
5072 + /* Adjust the address for the data segment. We want to adjust up to
5073 + the same address within the page on the next page up. It would
5074 + be more correct to do this:
5076 + The current expression does not correctly handle the case of a
5077 + text segment ending precisely at the end of a page; it causes the
5078 + data segment to skip a page. The above expression does not have
5079 + this problem, but it will currently (2/95) cause BFD to allocate
5080 + a single segment, combining both text and data, for this case.
5081 + This will prevent the text segment from being shared among
5082 + multiple executions of the program; I think that is more
5083 + important than losing a page of the virtual address space (note
5084 + that no actual memory is lost; the page which is skipped can not
5085 + be referenced). */
5092 + /* Align the initial ramdisk image (INITRD) on page boundaries. */
5101 + .data1 : { *(.data1) }
5103 + .lit8 : { *(.lit8) }
5104 + .lit4 : { *(.lit4) }
5105 + .ctors : { *(.ctors) }
5106 + .dtors : { *(.dtors) }
5107 + .got : { *(.got.plt) *(.got) }
5108 + .dynamic : { *(.dynamic) }
5109 + /* We want the small data sections together, so single-instruction offsets
5110 + can access them all, and initialized data all before uninitialized, so
5111 + we can shorten the on-disk segment size. */
5112 + .sdata : { *(.sdata) }
5115 + PROVIDE (edata = .);
5119 + .sbss : { *(.sbss) *(.scommon) }
5127 + PROVIDE (end = .);
5130 + /* Sections to be discarded */
5138 + /* This is the MIPS specific mdebug section. */
5139 + .mdebug : { *(.mdebug) }
5140 + /* These are needed for ELF backends which have not yet been
5141 + converted to the new style linker. */
5142 + .stab 0 : { *(.stab) }
5143 + .stabstr 0 : { *(.stabstr) }
5144 + /* DWARF debug sections.
5145 + Symbols in the .debug DWARF section are relative to the beginning of the
5146 + section so we begin .debug at 0. It's not clear yet what needs to happen
5147 + for the others. */
5148 + .debug 0 : { *(.debug) }
5149 + .debug_srcinfo 0 : { *(.debug_srcinfo) }
5150 + .debug_aranges 0 : { *(.debug_aranges) }
5151 + .debug_pubnames 0 : { *(.debug_pubnames) }
5152 + .debug_sfnames 0 : { *(.debug_sfnames) }
5153 + .line 0 : { *(.line) }
5154 + /* These must appear regardless of . */
5155 + .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
5156 + .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
5157 + .comment : { *(.comment) }
5158 + .note : { *(.note) }
5160 diff -Naru linux/arch/mips/zboot/xxs1500/Makefile linux-new/arch/mips/zboot/xxs1500/Makefile
5161 --- linux/arch/mips/zboot/xxs1500/Makefile 1969-12-31 19:00:00.000000000 -0500
5162 +++ linux-new/arch/mips/zboot/xxs1500/Makefile 2003-12-18 14:26:21.000000000 -0500
5164 +# arch/mips/compressed/alchemy/Makefile
5166 +# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
5167 +# All of the boot loader code was derived from the ppc
5170 +# Copyright 2001,2002 MontaVista Software Inc.
5172 +# Author: Mark A. Greer
5173 +# mgreer@mvista.com
5174 +# Ported and modified for mips support by
5175 +# Pete Popov <ppopov@mvista.com>
5177 +# This program is free software; you can redistribute it and/or modify it
5178 +# under the terms of the GNU General Public License as published by the
5179 +# Free Software Foundation; either version 2 of the License, or (at your
5180 +# option) any later version.
5183 + $(CC) $(CFLAGS) -S -o $*.s $<
5187 + $(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
5189 + $(CPP) $(AFLAGS) -o $*.o $<
5191 + $(CC) $(AFLAGS) -c -o $*.o $<
5193 +#########################################################################
5194 +# START BOARD SPECIFIC VARIABLES
5198 +# These two variables control where the zImage is stored
5199 +# in flash and loaded in memory. If you change either one,
5200 +# be sure to make the appropriate change to the zImage
5202 +RAM_LOAD_ADDR = 0x81000000
5203 +FLASH_LOAD_ADDR = 0xBF000000
5205 +# These two variables specify the free ram region
5206 +# that can be used for temporary malloc area
5207 +AVAIL_RAM_START=0x80400000
5208 +AVAIL_RAM_END=0x80800000
5210 +# This one must match the LOADADDR in arch/mips/Makefile!
5211 +LOADADDR=0x80100000
5212 +# END BOARD SPECIFIC VARIABLES
5213 +#########################################################################
5215 +ZLINKFLAGS = -T ld.script -Ttext $(RAM_LOAD_ADDR)
5217 +OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
5218 + ../common/au1k_uart.o ../common/string.o ../common/ctype.o
5219 +LIBS := ../lib/zlib.a
5221 +ENTRY := ../utils/entry
5222 +OFFSET := ../utils/offset
5223 +SIZE := ../utils/size
5228 + rm -rf *.o vmlinux* zvmlinux.*
5230 +head.o: head.S $(TOPDIR)/vmlinux
5231 + $(CC) -DFLASH_LOAD_ADDR=$(FLASH_LOAD_ADDR) $(AFLAGS) \
5232 + -DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
5235 +../common/misc-simple.o:
5236 + $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
5237 + -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
5238 + -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
5239 + -DLOADADDR=$(LOADADDR) \
5240 + -DZIMAGE_SIZE=0 -c -o $@ $*.c
5242 +# This is the first pass at building the boot loader image,
5243 +# without knowing the file offset where the vmlinuz.gz
5244 +# kernel will end up. We build this image, check the offset,
5245 +# and then rebuild it with the correct offset and size
5246 +# passed to mips-simple.c
5247 +zvmlinux.no: $(OBJECTS) $(LIBS) ../images/vmlinux.gz
5248 + $(LD) $(ZLINKFLAGS) -o $@.tmp $(OBJECTS) $(LIBS)
5249 + $(OBJCOPY) -R .comment \
5250 + --add-section=image=../images/vmlinux.gz \
5255 +# This is the final image we build, now that we know what
5256 +# the vmlinuz.gz offset is.
5257 +zvmlinux: $(OBJECTS) $(LIBS) ../images/vmlinux.gz zvmlinux.no
5258 + $(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 \
5259 + -DZIMAGE_OFFSET=$(shell sh $(OFFSET) $(OBJDUMP) $@.no image) \
5260 + -DZIMAGE_SIZE=$(shell sh $(SIZE) $(OBJDUMP) $@.no image) \
5262 + -DAVAIL_RAM_START=$(AVAIL_RAM_START) \
5263 + -DAVAIL_RAM_END=$(AVAIL_RAM_END) \
5264 + -DLOADADDR=$(LOADADDR) \
5265 + -c -o ../common/misc-simple.o ../common/misc-simple.c
5266 + $(LD) $(ZLINKFLAGS) -o $@.tmp $(OBJECTS) $(LIBS)
5267 + $(OBJCOPY) -R .comment \
5268 + --add-section=image=../images/vmlinux.gz \
5270 + $(OBJCOPY) --adjust-section-vma=image+$(RAM_LOAD_ADDR) $@
5271 + $(OBJCOPY) --adjust-section-vma=image+$(shell sh $(OFFSET) \
5272 + $(OBJDUMP) $@.no image ) $@
5277 +# Here we manipulate the image in order to get it the necessary
5278 +# srecord file we need.
5280 + mv zvmlinux ../images/$@.$(BNAME)
5281 + $(OBJCOPY) --set-section-flags=image=alloc,load,code ../images/$@.$(BNAME)
5282 + $(OBJCOPY) -O srec --adjust-vma 0x3e000000 \
5283 + ../images/$@.$(BNAME) ../images/$@.$(BNAME).srec
5284 + # rm ../images/vmlinux.gz
5286 +include $(TOPDIR)/Rules.make