1 diff -Naur linux-old/arch/i386/boot/compressed/LzmaDecode.c linux-lzma/arch/i386/boot/compressed/LzmaDecode.c
2 --- linux-old/arch/i386/boot/compressed/LzmaDecode.c 1969-12-31 19:00:00.000000000 -0500
3 +++ linux-lzma/arch/i386/boot/compressed/LzmaDecode.c 2005-06-05 00:07:38.000000000 -0400
7 + LZMA Decoder (optimized for Speed version)
9 + LZMA SDK 4.17 Copyright (c) 1999-2005 Igor Pavlov (2005-04-05)
10 + http://www.7-zip.org/
12 + LZMA SDK is licensed under two licenses:
13 + 1) GNU Lesser General Public License (GNU LGPL)
14 + 2) Common Public License (CPL)
15 + It means that you can select one of these two licenses and
16 + follow rules of that license.
19 + Igor Pavlov, as the author of this Code, expressly permits you to
20 + statically or dynamically link your Code (or bind by name) to the
21 + interfaces of this file without subjecting your linked Code to the
22 + terms of the CPL or GNU LGPL. Any modifications or additions
23 + to this file, however, are subject to the LGPL or CPL terms.
26 +#include "LzmaDecode.h"
29 +#define Byte unsigned char
32 +#define kNumTopBits 24
33 +#define kTopValue ((UInt32)1 << kNumTopBits)
35 +#define kNumBitModelTotalBits 11
36 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
37 +#define kNumMoveBits 5
39 +#define RC_READ_BYTE (*Buffer++)
41 +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
42 + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
46 +#define RC_TEST { if (Buffer == BufferLim) \
47 + { UInt32 size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
48 + BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
50 +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
54 +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
56 +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
60 +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
62 +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
63 +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
64 +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
66 +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
67 + { UpdateBit0(p); mi <<= 1; A0; } else \
68 + { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
70 +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
72 +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
73 + { int i = numLevels; res = 1; \
74 + do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
75 + res -= (1 << numLevels); }
78 +#define kNumPosBitsMax 4
79 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
81 +#define kLenNumLowBits 3
82 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
83 +#define kLenNumMidBits 3
84 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
85 +#define kLenNumHighBits 8
86 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
89 +#define LenChoice2 (LenChoice + 1)
90 +#define LenLow (LenChoice2 + 1)
91 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
92 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
93 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
96 +#define kNumStates 12
97 +#define kNumLitStates 7
99 +#define kStartPosModelIndex 4
100 +#define kEndPosModelIndex 14
101 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
103 +#define kNumPosSlotBits 6
104 +#define kNumLenToPosStates 4
106 +#define kNumAlignBits 4
107 +#define kAlignTableSize (1 << kNumAlignBits)
109 +#define kMatchMinLen 2
112 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
113 +#define IsRepG0 (IsRep + kNumStates)
114 +#define IsRepG1 (IsRepG0 + kNumStates)
115 +#define IsRepG2 (IsRepG1 + kNumStates)
116 +#define IsRep0Long (IsRepG2 + kNumStates)
117 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
118 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
119 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
120 +#define LenCoder (Align + kAlignTableSize)
121 +#define RepLenCoder (LenCoder + kNumLenProbs)
122 +#define Literal (RepLenCoder + kNumLenProbs)
124 +#if Literal != LZMA_BASE_SIZE
128 +#ifdef _LZMA_OUT_READ
130 +typedef struct _LzmaVarState
137 + ILzmaInCallback *InCallback;
140 + UInt32 DictionarySize;
141 + UInt32 DictionaryPos;
149 + Byte TempDictionary[4];
152 +int LzmaDecoderInit(
153 + unsigned char *buffer, UInt32 bufferSize,
154 + int lc, int lp, int pb,
155 + unsigned char *dictionary, UInt32 dictionarySize,
157 + ILzmaInCallback *InCallback
159 + unsigned char *inStream, UInt32 inSize
167 + LzmaVarState *vs = (LzmaVarState *)buffer;
168 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
169 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
171 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
172 + return LZMA_RESULT_NOT_ENOUGH_MEM;
173 + vs->Dictionary = dictionary;
174 + vs->DictionarySize = dictionarySize;
175 + vs->DictionaryPos = 0;
177 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
183 + dictionary[dictionarySize - 1] = 0;
184 + for (i = 0; i < numProbs; i++)
185 + p[i] = kBitModelTotal >> 1;
190 + RC_INIT(inStream, inSize);
192 + vs->Buffer = Buffer;
193 + vs->BufferLim = BufferLim;
197 + vs->InCallback = InCallback;
200 + return LZMA_RESULT_OK;
203 +int LzmaDecode(unsigned char *buffer,
204 + unsigned char *outStream, UInt32 outSize,
205 + UInt32 *outSizeProcessed)
207 + LzmaVarState *vs = (LzmaVarState *)buffer;
208 + Byte *Buffer = vs->Buffer;
209 + Byte *BufferLim = vs->BufferLim;
210 + UInt32 Range = vs->Range;
211 + UInt32 Code = vs->Code;
213 + ILzmaInCallback *InCallback = vs->InCallback;
215 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
216 + int state = vs->State;
218 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
220 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
221 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
223 + int len = vs->RemainLen;
224 + UInt32 globalPos = vs->GlobalPos;
226 + Byte *dictionary = vs->Dictionary;
227 + UInt32 dictionarySize = vs->DictionarySize;
228 + UInt32 dictionaryPos = vs->DictionaryPos;
230 + Byte tempDictionary[4];
231 + if (dictionarySize == 0)
233 + dictionary = tempDictionary;
234 + dictionarySize = 1;
235 + tempDictionary[0] = vs->TempDictionary[0];
240 + *outSizeProcessed = 0;
241 + return LZMA_RESULT_OK;
244 + while(len != 0 && nowPos < outSize)
246 + UInt32 pos = dictionaryPos - rep0;
247 + if (pos >= dictionarySize)
248 + pos += dictionarySize;
249 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
250 + if (++dictionaryPos == dictionarySize)
254 + if (dictionaryPos == 0)
255 + previousByte = dictionary[dictionarySize - 1];
257 + previousByte = dictionary[dictionaryPos - 1];
261 + Byte *buffer, UInt32 bufferSize,
262 + int lc, int lp, int pb,
264 + ILzmaInCallback *InCallback,
266 + unsigned char *inStream, UInt32 inSize,
268 + unsigned char *outStream, UInt32 outSize,
269 + UInt32 *outSizeProcessed)
271 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
272 + CProb *p = (CProb *)buffer;
276 + Byte previousByte = 0;
277 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
279 + UInt32 posStateMask = (1 << pb) - 1;
280 + UInt32 literalPosMask = (1 << lp) - 1;
288 + if (bufferSize < numProbs * sizeof(CProb))
289 + return LZMA_RESULT_NOT_ENOUGH_MEM;
290 + for (i = 0; i < numProbs; i++)
291 + p[i] = kBitModelTotal >> 1;
297 + RC_INIT(inStream, inSize);
301 + *outSizeProcessed = 0;
302 + while(nowPos < outSize)
306 + int posState = (int)(
308 + #ifdef _LZMA_OUT_READ
314 + prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
319 + prob = p + Literal + (LZMA_LIT_SIZE *
322 + #ifdef _LZMA_OUT_READ
326 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
328 + if (state >= kNumLitStates)
331 + #ifdef _LZMA_OUT_READ
332 + UInt32 pos = dictionaryPos - rep0;
333 + if (pos >= dictionarySize)
334 + pos += dictionarySize;
335 + matchByte = dictionary[pos];
337 + matchByte = outStream[nowPos - rep0];
344 + bit = (matchByte & 0x100);
345 + probLit = prob + 0x100 + bit + symbol;
346 + RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
348 + while (symbol < 0x100);
350 + while (symbol < 0x100)
352 + CProb *probLit = prob + symbol;
353 + RC_GET_BIT(probLit, symbol)
355 + previousByte = (Byte)symbol;
357 + outStream[nowPos++] = previousByte;
358 + #ifdef _LZMA_OUT_READ
359 + dictionary[dictionaryPos] = previousByte;
360 + if (++dictionaryPos == dictionarySize)
363 + if (state < 4) state = 0;
364 + else if (state < 10) state -= 3;
370 + prob = p + IsRep + state;
377 + state = state < kNumLitStates ? 0 : 3;
378 + prob = p + LenCoder;
383 + prob = p + IsRepG0 + state;
387 + prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
390 + #ifdef _LZMA_OUT_READ
395 + #ifdef _LZMA_OUT_READ
399 + return LZMA_RESULT_DATA_ERROR;
400 + state = state < kNumLitStates ? 9 : 11;
401 + #ifdef _LZMA_OUT_READ
402 + pos = dictionaryPos - rep0;
403 + if (pos >= dictionarySize)
404 + pos += dictionarySize;
405 + previousByte = dictionary[pos];
406 + dictionary[dictionaryPos] = previousByte;
407 + if (++dictionaryPos == dictionarySize)
410 + previousByte = outStream[nowPos - rep0];
412 + outStream[nowPos++] = previousByte;
424 + prob = p + IsRepG1 + state;
433 + prob = p + IsRepG2 + state;
450 + state = state < kNumLitStates ? 8 : 11;
451 + prob = p + RepLenCoder;
454 + int numBits, offset;
455 + CProb *probLen = prob + LenChoice;
458 + UpdateBit0(probLen);
459 + probLen = prob + LenLow + (posState << kLenNumLowBits);
461 + numBits = kLenNumLowBits;
465 + UpdateBit1(probLen);
466 + probLen = prob + LenChoice2;
469 + UpdateBit0(probLen);
470 + probLen = prob + LenMid + (posState << kLenNumMidBits);
471 + offset = kLenNumLowSymbols;
472 + numBits = kLenNumMidBits;
476 + UpdateBit1(probLen);
477 + probLen = prob + LenHigh;
478 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
479 + numBits = kLenNumHighBits;
482 + RangeDecoderBitTreeDecode(probLen, numBits, len);
489 + state += kNumLitStates;
490 + prob = p + PosSlot +
491 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
493 + RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
494 + if (posSlot >= kStartPosModelIndex)
496 + int numDirectBits = ((posSlot >> 1) - 1);
497 + rep0 = (2 | ((UInt32)posSlot & 1));
498 + if (posSlot < kEndPosModelIndex)
500 + rep0 <<= numDirectBits;
501 + prob = p + SpecPos + rep0 - posSlot - 1;
505 + numDirectBits -= kNumAlignBits;
517 + while (--numDirectBits != 0);
519 + rep0 <<= kNumAlignBits;
520 + numDirectBits = kNumAlignBits;
527 + CProb *prob3 = prob + mi;
528 + RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
531 + while(--numDirectBits != 0);
536 + if (++rep0 == (UInt32)(0))
538 + /* it's for stream version */
544 + len += kMatchMinLen;
546 + #ifdef _LZMA_OUT_READ
547 + + globalPos || rep0 > dictionarySize
550 + return LZMA_RESULT_DATA_ERROR;
553 + #ifdef _LZMA_OUT_READ
554 + UInt32 pos = dictionaryPos - rep0;
555 + if (pos >= dictionarySize)
556 + pos += dictionarySize;
557 + previousByte = dictionary[pos];
558 + dictionary[dictionaryPos] = previousByte;
559 + if (++dictionaryPos == dictionarySize)
562 + previousByte = outStream[nowPos - rep0];
565 + outStream[nowPos++] = previousByte;
567 + while(len != 0 && nowPos < outSize);
572 + #ifdef _LZMA_OUT_READ
573 + vs->Buffer = Buffer;
574 + vs->BufferLim = BufferLim;
577 + vs->DictionaryPos = dictionaryPos;
578 + vs->GlobalPos = globalPos + nowPos;
579 + vs->Reps[0] = rep0;
580 + vs->Reps[1] = rep1;
581 + vs->Reps[2] = rep2;
582 + vs->Reps[3] = rep3;
584 + vs->RemainLen = len;
585 + vs->TempDictionary[0] = tempDictionary[0];
588 + *outSizeProcessed = nowPos;
589 + return LZMA_RESULT_OK;
591 diff -Naur linux-old/arch/i386/boot/compressed/LzmaDecode.h linux-lzma/arch/i386/boot/compressed/LzmaDecode.h
592 --- linux-old/arch/i386/boot/compressed/LzmaDecode.h 1969-12-31 19:00:00.000000000 -0500
593 +++ linux-lzma/arch/i386/boot/compressed/LzmaDecode.h 2005-06-05 00:07:39.000000000 -0400
597 + LZMA Decoder interface
599 + LZMA SDK 4.16 Copyright (c) 1999-2005 Igor Pavlov (2005-03-18)
600 + http://www.7-zip.org/
602 + LZMA SDK is licensed under two licenses:
603 + 1) GNU Lesser General Public License (GNU LGPL)
604 + 2) Common Public License (CPL)
605 + It means that you can select one of these two licenses and
606 + follow rules of that license.
609 + Igor Pavlov, as the author of this code, expressly permits you to
610 + statically or dynamically link your code (or bind by name) to the
611 + interfaces of this file without subjecting your linked code to the
612 + terms of the CPL or GNU LGPL. Any modifications or additions
613 + to this file, however, are subject to the LGPL or CPL terms.
616 +#ifndef __LZMADECODE_H
617 +#define __LZMADECODE_H
619 +/* #define _LZMA_IN_CB */
620 +/* Use callback for input data */
622 +/* #define _LZMA_OUT_READ */
623 +/* Use read function for output data */
625 +/* #define _LZMA_PROB32 */
626 +/* It can increase speed on some 32-bit CPUs,
627 + but memory usage will be doubled in that case */
629 +/* #define _LZMA_LOC_OPT */
630 +/* Enable local speed optimizations inside code */
633 +#ifdef _LZMA_UINT32_IS_ULONG
634 +#define UInt32 unsigned long
636 +#define UInt32 unsigned int
641 +#define CProb UInt32
643 +#define CProb unsigned short
646 +#define LZMA_RESULT_OK 0
647 +#define LZMA_RESULT_DATA_ERROR 1
648 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
651 +typedef struct _ILzmaInCallback
653 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
657 +#define LZMA_BASE_SIZE 1846
658 +#define LZMA_LIT_SIZE 768
661 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
662 +bufferSize += 100 in case of _LZMA_OUT_READ
663 +by default CProb is unsigned short,
664 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
667 +#ifdef _LZMA_OUT_READ
668 +int LzmaDecoderInit(
669 + unsigned char *buffer, UInt32 bufferSize,
670 + int lc, int lp, int pb,
671 + unsigned char *dictionary, UInt32 dictionarySize,
673 + ILzmaInCallback *inCallback
675 + unsigned char *inStream, UInt32 inSize
681 + unsigned char *buffer,
682 + #ifndef _LZMA_OUT_READ
684 + int lc, int lp, int pb,
686 + ILzmaInCallback *inCallback,
688 + unsigned char *inStream, UInt32 inSize,
691 + unsigned char *outStream, UInt32 outSize,
692 + UInt32 *outSizeProcessed);
695 diff -Naur linux-old/arch/i386/boot/compressed/Makefile linux-lzma/arch/i386/boot/compressed/Makefile
696 --- linux-old/arch/i386/boot/compressed/Makefile 2005-06-04 21:53:40.000000000 -0400
697 +++ linux-lzma/arch/i386/boot/compressed/Makefile 2005-06-05 00:25:23.000000000 -0400
699 # linux/arch/i386/boot/compressed/Makefile
701 # create a compressed vmlinux image from the original vmlinux
702 +# patched by Ming-Ching Tiew <mctiew@yahoo.com> for kernel 2.6
703 +# requires program 'lzma' from LZMA SDK ( http://www.7-zip.org/ ) to work
706 +# $ tar tvjf ../lzma417.tar.bz2
707 +# $ cd SRC/7zip/Compress/LZMA_Alone
708 +# $ dos2unix makefile
711 +# # cp lzma /usr/bin
714 -targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
715 +targets := vmlinux vmlinux.bin vmlinux.bin.lzma head.o lzma_misc.o piggy.o
716 EXTRA_AFLAGS := -traditional
718 LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
720 -$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
721 +$(obj)/vmlinux: $(obj)/head.o $(obj)/lzma_misc.o $(obj)/piggy.o FORCE
722 $(call if_changed,ld)
725 $(obj)/vmlinux.bin: vmlinux FORCE
726 $(call if_changed,objcopy)
728 -$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
729 - $(call if_changed,gzip)
730 +$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
731 + $(call if_changed,lzma)
733 LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
735 -$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
736 +$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.lzma FORCE
737 $(call if_changed,ld)
738 diff -Naur linux-old/arch/i386/boot/compressed/lzma_misc.c linux-lzma/arch/i386/boot/compressed/lzma_misc.c
739 --- linux-old/arch/i386/boot/compressed/lzma_misc.c 1969-12-31 19:00:00.000000000 -0500
740 +++ linux-lzma/arch/i386/boot/compressed/lzma_misc.c 2005-06-04 21:33:48.000000000 -0400
745 + * Decompress LZMA compressed vmlinuz
746 + * Version 0.9 Copyright (c) Ming-Ching Tiew mctiew@yahoo.com
747 + * Program adapted from misc.c for 2.6 kernel
748 + * Date: 3 June 2005
749 + * Source released under GPL
752 +#include <linux/linkage.h>
753 +#include <linux/vmalloc.h>
754 +#include <linux/tty.h>
755 +#include <linux/screen_info.h>
758 +#define OF(args) args
759 +#define STATIC static
765 + * Why do we do this? Don't ask me..
767 + * Incomprehensible are the ways of bootloaders.
769 +static void* memcpy(void *, __const void *, size_t);
771 +typedef unsigned char uch;
772 +typedef unsigned short ush;
773 +typedef unsigned long ulg;
775 +#define WSIZE 0x8000 /* Window size must be at least 32k, */
776 + /* and a power of two */
778 +static uch *inbuf; /* input buffer */
780 +static unsigned insize = 0; /* valid bytes in inbuf */
781 +static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
783 +#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
785 +/* Diagnostic functions */
787 +# define Assert(cond,msg) {if(!(cond)) error(msg);}
788 +# define Trace(x) fprintf x
789 +# define Tracev(x) {if (verbose) fprintf x ;}
790 +# define Tracevv(x) {if (verbose>1) fprintf x ;}
791 +# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
792 +# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
794 +# define Assert(cond,msg)
798 +# define Tracec(c,x)
799 +# define Tracecv(c,x)
802 +static int fill_inbuf(void);
803 +static void error(char *m);
806 + * This is set up by the setup-routine at boot-time
808 +static unsigned char *real_mode; /* Pointer to real-mode data */
810 +#define RM_EXT_MEM_K (*(unsigned short *)(real_mode + 0x2))
811 +#ifndef STANDARD_MEMORY_BIOS_CALL
812 +#define RM_ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0))
814 +#define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))
816 +extern char input_data[];
817 +extern int input_len;
819 +static long bytes_out = 0;
820 +static uch *output_data;
822 +static void putstr(const char *);
825 +static long free_mem_ptr = (long)&end;
826 +static long free_mem_end_ptr;
828 +#define INPLACE_MOVE_ROUTINE 0x1000
829 +#define LOW_BUFFER_START 0x2000
830 +#define LOW_BUFFER_MAX 0x90000
831 +#define HEAP_SIZE 0x3000
832 +static unsigned int low_buffer_end, low_buffer_size;
833 +static int high_loaded =0;
834 +static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
836 +static char *vidmem = (char *)0xb8000;
838 +static int lines, cols;
840 +static void scroll(void)
844 + memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
845 + for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
849 +static void putstr(const char *s)
854 + x = RM_SCREEN_INFO.orig_x;
855 + y = RM_SCREEN_INFO.orig_y;
857 + while ( ( c = *s++ ) != '\0' ) {
860 + if ( ++y >= lines ) {
865 + vidmem [ ( x + cols * y ) * 2 ] = c;
866 + if ( ++x >= cols ) {
868 + if ( ++y >= lines ) {
876 + RM_SCREEN_INFO.orig_x = x;
877 + RM_SCREEN_INFO.orig_y = y;
879 + pos = (x + cols * y) * 2; /* Update cursor position */
880 + outb_p(14, vidport);
881 + outb_p(0xff & (pos >> 9), vidport+1);
882 + outb_p(15, vidport);
883 + outb_p(0xff & (pos >> 1), vidport+1);
886 +static void* memcpy(void* __dest, __const void* __src,
890 + char *d = (char *)__dest, *s = (char *)__src;
892 + for (i=0;i<__n;i++) d[i] = s[i];
896 +/* ===========================================================================
897 + * Fill the input buffer. This is called only when the buffer is empty
898 + * and at least one byte is really needed.
900 +static int fill_inbuf(void)
903 + error("ran out of input data");
906 + inbuf = input_data;
907 + insize = input_len;
912 +static void error(char *x)
916 + putstr("\n\n -- System halted");
918 + while(1); /* Halt */
921 +#define STACK_SIZE (4096)
923 +long user_stack [STACK_SIZE];
928 + } stack_start = { & user_stack [STACK_SIZE] , __BOOT_DS };
930 +static void setup_normal_output_buffer(void)
932 +#ifdef STANDARD_MEMORY_BIOS_CALL
933 + if (RM_EXT_MEM_K < 1024) error("Less than 2MB of memory");
935 + if ((RM_ALT_MEM_K > RM_EXT_MEM_K ? RM_ALT_MEM_K : RM_EXT_MEM_K) < 1024) error("Less than 2MB of memory");
937 + output_data = (char *)0x100000; /* Points to 1M */
938 + free_mem_end_ptr = (long)real_mode;
942 + uch *low_buffer_start; int lcount;
943 + uch *high_buffer_start; int hcount;
946 +static void setup_output_buffer_if_we_run_high(struct moveparams *mv)
948 + high_buffer_start = (uch *)(((ulg)&end) + HEAP_SIZE);
949 +#ifdef STANDARD_MEMORY_BIOS_CALL
950 + if (RM_EXT_MEM_K < (3*1024)) error("Less than 4MB of memory");
952 + if ((RM_ALT_MEM_K > RM_EXT_MEM_K ? RM_ALT_MEM_K : RM_EXT_MEM_K) <
954 + error("Less than 4MB of memory");
956 + mv->low_buffer_start = output_data = (char *)LOW_BUFFER_START;
957 + low_buffer_end = ((unsigned int)real_mode > LOW_BUFFER_MAX
958 + ? LOW_BUFFER_MAX : (unsigned int)real_mode) & ~0xfff;
959 + low_buffer_size = low_buffer_end - LOW_BUFFER_START;
961 + free_mem_end_ptr = (long)high_buffer_start;
962 + if ( (0x100000 + low_buffer_size) > ((ulg)high_buffer_start)) {
963 + high_buffer_start = (uch *)(0x100000 + low_buffer_size);
964 + mv->hcount = 0; /* say: we need not to move high_buffer */
966 + else mv->hcount = -1;
967 + mv->high_buffer_start = high_buffer_start;
970 +static void close_output_buffer_if_we_run_high(struct moveparams *mv)
972 + if (bytes_out > low_buffer_size) {
973 + mv->lcount = low_buffer_size;
975 + mv->hcount = bytes_out - low_buffer_size;
977 + mv->lcount = bytes_out;
982 +// When using LZMA in callback, the compressed length is not needed.
983 +// Otherwise you need a special version of lzma compression program
984 +// which will pad the compressed length in the header.
986 +#include "LzmaDecode.h"
987 +#include "LzmaDecode.c"
990 +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize);
995 + * Do the lzma decompression
996 + * When using LZMA in callback, the end of input stream is automatically determined
998 +static int lzma_unzip(void)
1001 + unsigned int i; /* temp value */
1002 + unsigned int lc; /* literal context bits */
1003 + unsigned int lp; /* literal pos state bits */
1004 + unsigned int pb; /* pos state bits */
1005 + unsigned char* workspace;
1006 + unsigned int uncompressedSize = 0;
1010 + ILzmaInCallback callback;
1011 + callback.Read = read_byte;
1013 + unsigned char* inputbuf;
1014 + unsigned int lzma_workspace_size;
1015 + unsigned int compressedSize = 0;
1020 + lc = i % 9, i = i / 9;
1021 + lp = i % 5, pb = i / 5;
1023 + /* skip dictionary size */
1024 + for (i = 0; i < 4; i++)
1026 + // get uncompressedSize
1027 + p= (char*)&uncompressedSize;
1028 + for (i = 0; i < 4; i++)
1029 + *p++ = get_byte();
1031 + //get compressedSize
1033 + for (i = 0; i < 4; i++)
1036 + p= (char*)&compressedSize;
1037 + for (i = 0; i < 4; i++)
1038 + *p++ = get_byte();
1042 + if ( (lc == 5 ) && (lp == 0 ) && ( pb == 0 ))
1044 + putstr("got prop!\n");
1047 +#ifndef _LZMA_IN_CB
1048 + if( compressedSize == 496722 )
1050 + putstr( "got the right sizes\n");
1052 + else if ( compressedSize > 496722 )
1054 + putstr( "greater !\n");
1056 + else if ( compressedSize < 496722 )
1057 + putstr( "smaller!\n");
1060 + if ( uncompressedSize == 1187168 )
1062 + putstr( "got the right uncompressed size \n");
1063 + }else if ( uncompressedSize > 1187168 )
1065 + putstr( "uncompressedSize greater!\n");
1067 + putstr( "uncompressedSize smaller!|n");
1070 + // point it beyond uncompresedSize
1071 + workspace = high_buffer_start + uncompressedSize;
1073 +#ifndef _LZMA_IN_CB
1074 + lzma_workspace_size = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * sizeof(CProb);
1075 + inputbuf = high_buffer_start + uncompressedSize + lzma_workspace_size;
1076 + // read the compressed data
1077 + for( i=0; i < compressedSize; i++)
1079 + if ( i % ( 1024 * 10 ) == 0 )
1081 + *inputbuf++ = get_byte();
1085 + /* decompress kernel */
1087 + if (LzmaDecode(workspace, ~0, lc, lp, pb,
1090 + if (LzmaDecode(workspace, lzma_workspace_size, lc, lp, pb,
1091 + inputbuf - compressedSize, compressedSize,
1093 + (unsigned char*)high_buffer_start, uncompressedSize, &i) == LZMA_RESULT_OK)
1095 + if ( i != uncompressedSize )
1096 + error( "kernel corrupted!\n");
1097 + //copy it back to low_buffer
1098 + if( uncompressedSize > low_buffer_size )
1100 + memcpy((char*)LOW_BUFFER_START, high_buffer_start, low_buffer_size);
1101 + memcpy(high_buffer_start, high_buffer_start+low_buffer_size,
1102 + uncompressedSize-low_buffer_size);
1105 + memcpy((char*)LOW_BUFFER_START, high_buffer_start, uncompressedSize );
1114 +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize)
1116 + static unsigned int i = 0;
1117 + static unsigned char val;
1121 + if ( i++ % ( 1024 * 50 ) == 0 )
1123 + return LZMA_RESULT_OK;
1127 +asmlinkage int decompress_kernel(struct moveparams *mv, void *rmode)
1129 + real_mode = rmode;
1131 + if (RM_SCREEN_INFO.orig_video_mode == 7) {
1132 + vidmem = (char *) 0xb0000;
1135 + vidmem = (char *) 0xb8000;
1139 + lines = RM_SCREEN_INFO.orig_video_lines;
1140 + cols = RM_SCREEN_INFO.orig_video_cols;
1142 + if (free_mem_ptr < 0x100000) setup_normal_output_buffer();
1143 + else setup_output_buffer_if_we_run_high(mv);
1145 + putstr("LZMA vmlinuz: Ming-Ching Tiew <mctiew@yahoo.com> ...");
1146 + if( lzma_unzip() != 0 )
1148 + error("inflate error\n");
1150 + putstr("Ok, booting the kernel.\n");
1151 + if (high_loaded) close_output_buffer_if_we_run_high(mv);
1152 + return high_loaded;
1154 diff -urN linux-2.6.19.2/scripts/Makefile.lib linux-2.6.19.2.new/scripts/Makefile.lib
1155 --- linux-2.6.19.2/scripts/Makefile.lib 2007-01-10 20:10:37.000000000 +0100
1156 +++ linux-2.6.19.2.new/scripts/Makefile.lib 2007-04-15 23:51:54.000000000 +0200
1158 quiet_cmd_gzip = GZIP $@
1159 cmd_gzip = gzip -f -9 < $< > $@
1164 +quiet_cmd_lzma = LZMA $@
1165 +cmd_lzma = lzma e $< $@ -lc7 -lp0 -pb0
1167 +# cmd_lzma = lzmacomp $< 700 > $@