uncompress.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:12k
- /* uncompress.c - uncompression module */
- /* Copyright 1990-1992 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 02h,04nov93,caf fixed two more variables that were not being initialized
- during the R3000 bootstrap.
- 02g,07sep93,caf modified not to rely on initialized data, to work around
- a.out assumption in current bootstrap.
- 02f,26may92,rrr the tree shuffle
- 02e,14nov91,rrr shut up some warnings
- 02d,04oct91,rrr passed through the ansification filter
- -changed functions to ansi style
- -fixed #else and #endif
- -changed copyright notice
- 02c,25jul91,yao restore previous version 02a.
- 02b,06jul91,yao made it work with little endian mode. added forward
- declaration.
- 02a,16may90,gae revised initial bootrom uncompression scheme --
- ROM startup in separate module.
- 01a,21apr90,rdc modified from compress source.
- */
- /*
- DESCRIPTION
- This is a modified version of the Public Domain uncompress program.
- It is used to uncompress the VxWorks bootrom executable linked with it.
- Compressing object code typically achieves a 40% compression factor.
- SEE ALSO:
- compress(1), romInit(1)
- AUTHOR
- The original compress program was written by:
- Spencer W. Thomas, Jim McKie, Steve Davies, Ken Turkowski,
- James A. Woods, Joe Orost.
- */
- #include "vxWorks.h"
- /* Set USERMEM to the maximum amount of physical user memory available
- * in bytes. USERMEM is used to determine the maximum BITS that can be used
- * for compression. If USERMEM is big enough, use fast compression algorithm.
- *
- * SACREDMEM is the amount of physical memory saved for others; compress
- * will hog the rest.
- */
- #define USERMEM 500000 /* .5M for uncompression data structures */
- #define SACREDMEM 0
- /*
- * Define FBITS for machines with several MB of physical memory, to use
- * table lookup for (b <= FBITS). If FBITS is made too large, performance
- * will decrease due to increased swapping/paging. Since the program minus
- * the fast lookup table is about a half Meg, we can allocate the rest of
- * available physical memory to the fast lookup table.
- *
- * If FBITS is set to 12, a 2 MB array is allocated, but only 1 MB is
- * addressed for parity-free input (i.e. text).
- *
- * FBITS=10 yields 1/2 meg lookup table + 4K code memory
- * FBITS=11 yields 1 meg lookup table + 8K code memory
- * FBITS=12 yields 2 meg lookup table + 16K code memory
- * FBITS=13 yields 4 meg lookup table + 32K code memory
- *
- */
- #ifdef USERMEM
- # if USERMEM >= (2621440+SACREDMEM)
- # if USERMEM >= (4718592+SACREDMEM)
- # define FBITS 13
- # define PBITS 16
- #else /* 2.5M <= USERMEM < 4.5M */
- # define FBITS 12
- # define PBITS 16
- #endif /* USERMEM <=> 4.5M */
- #else /* USERMEM < 2.5M */
- # if USERMEM >= (1572864+SACREDMEM)
- # define FBITS 11
- # define PBITS 16
- #else /* USERMEM < 1.5M */
- # if USERMEM >= (1048576+SACREDMEM)
- # define FBITS 10
- # define PBITS 16
- #else /* USERMEM < 1M */
- # if USERMEM >= (631808+SACREDMEM)
- # define PBITS 16
- # else
- # if USERMEM >= (329728+SACREDMEM)
- # define PBITS 15
- # else
- # if USERMEM >= (178176+SACREDMEM)
- # define PBITS 14
- # else
- # if USERMEM >= (99328+SACREDMEM)
- # define PBITS 13
- # else
- # define PBITS 12
- # endif
- # endif
- # endif
- # endif
- # undef USERMEM
- #endif /* USERMEM <=> 1M */
- #endif /* USERMEM <=> 1.5M */
- #endif /* USERMEM <=> 2.5M */
- #endif /* USERMEM */
- #ifdef PBITS /* Preferred BITS for this memory size */
- # ifndef BITS
- # define BITS PBITS
- #endif /* BITS */
- #endif /* PBITS */
- #if BITS == 16
- # define HSIZE 69001 /* 95% occupancy */
- #endif /* BITS */
- #if BITS == 15
- # define HSIZE 35023 /* 94% occupancy */
- #endif /* BITS */
- #if BITS == 14
- # define HSIZE 18013 /* 91% occupancy */
- #endif /* BITS */
- #if BITS == 13
- # define HSIZE 9001 /* 91% occupancy */
- #endif /* BITS */
- #if BITS == 12
- # define HSIZE 5003 /* 80% occupancy */
- #endif /* BITS */
- #if BITS == 11
- # define HSIZE 2591 /* 79% occupancy */
- #endif /* BITS */
- #if BITS == 10
- # define HSIZE 1291 /* 79% occupancy */
- #endif /* BITS */
- #if BITS == 9
- # define HSIZE 691 /* 74% occupancy */
- #endif /* BITS */
- /* BITS < 9 will cause an error */
- /*
- * a code_int must be able to hold 2**BITS values of type int, and also -1
- */
- #if BITS > 15
- typedef long int code_int;
- #else
- typedef int code_int;
- #endif /* BITS */
- typedef long int count_int;
- typedef unsigned char char_type;
- /* defines for magic number {"