unhuf.S revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/*****************************************************************************
* NOTE: This code is no longer used in Etherboot. The obsolete
* Makefile target .lzrom refers to it, but it is no longer being
* maintained and may no longer work. Use .zrom instead (which uses
* the unnrv2b decompressor).
*****************************************************************************
*/
/* At entry, the processor is in 16 bit real mode and the code is being
* executed from an address it was not linked to. Code must be pic and
* 32 bit sensitive until things are fixed up.
*/
/* LZHuf (LZSS) Decompressing boot loader for ROM images
*
* this code is based on the work of Haruyasu Yoshizaki and Haruhiko Okumura
* who implemented the original compressor and decompressor in C code
*
* Converted to 32bit assembly 16 July 2002 Eric Biederman <ebiederman@lnxi.com>
* Made PIC 10 Aug 2002 Eric Biederman <ebiederman@lnxi.com>
*
* Copyright 1997 by M. Gutschke <gutschk@math.uni-muenster.de>
*
* Compression pays off, as soon as the uncompressed image is bigger than
* about 1.5kB. This assumes an average compressibility of about 60%.
*/
/* Do not change these values unless you really know what you are doing
* the pre-computed lookup tables rely on the buffer size being 4kB or
* smaller. The buffer size must be a power of two. The lookahead size has
* to fit into 6 bits. If you change any of these numbers, you will also
* have to adjust the compressor accordingly.
*/
#define BUFSZ 4096
#define LOOKAHEAD 60
#define THRESHOLD 2
.text
/* Save the initial register values */
/*
* See where I am running, and compute %ebp
*/
call 1f
/*
* INIT -- initializes all data structures
* ====
*/
init:
lodsw /* update frequencies of non-leaf nodes */
stosw /* sentinel with infinite frequency */
stosw /* update son pointers for leaf nodes */
stosw /* update son ptrs for non-leaf nodes */
stosw /* update parent ptrs for non-leaf nd. */
stosw /* root node has no parent */
stosw /* update parent ptrs for leaf nodes */
stosb /* clear getlen */
stosw /* clear getbuf */
/* fall thru */
/*
* MAIN -- reads compressed codes and writes decompressed data
* ====
*/
stosb /* store verbatim */
done:
/* Start Etherboot */
/*
* GETBIT -- gets one bit pointed to by DS:ESI
* ======
*
* changes: AX,CX,DL
*/
lodsb /* get next byte from input stream */
/*
* DCDPOS -- decodes position in textbuffer as pointed to by DS:SI, result in BX
* ======
*
* changes: AX,EBX,ECX,DX
*/
/*
* DCDCHR -- decodes one compressed character pointed to by DS:SI
* ======
*
* changes: AX,BX,CX,DX
*/
/* fall thru */
/*
* UPDATE -- updates huffman tree after incrementing frequency for code in BX
* ======
*
* changes: BX,CX,DX
*/
/* we do not check whether the frequency count has overrun.
* this will cause problems for large files, but be should be fine
* as long as the compressed size does not exceed 32kB and we
* cannot do more than this anyways, because we load into the
* upper 32kB of conventional memory
*/
lodsw /* check if nodes need reordering */
/*
* constant data. this part of the program resides in ROM and cannot be
* changed
*
* run length encoded tables will be uncompressed into the bss segment
* take care with any symbols here for .com files to add 0x100 to address
*/
/*
* variable data segment (bss)
* this segment will always be found at 0x90000 (i.e. at RELOC - SCRATCH)
*
* do not change the order or the sizes of any of the following tables
* the initialization code makes assumptions on the exact layout of the
* data structures...
*/
.bss
/* lookup table for index into buffer of recently output characters */
/* lookup table for length of code sequence from buffer of recent characters */
/* table with frequency counts for all codes */
/* pointer to child nodes */
/* the first part of this table contains all the codes (0..TABLESZ-1) */
/* the second part contains all leaf nodes (TABLESZ..) */
/* temporary storage for extracting bits from compressed data stream */
/* the initial buffer has to be filled with spaces */
.balign 4
/* uncompressed data will be written here */