2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2008 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #define LZMA_BASE_SIZE 1846
22 #define LZMA_LIT_SIZE 768
24 #define LZMA_PROPERTIES_SIZE 5
26 #define kNumTopBits 24
27 #define kTopValue (1 << kNumTopBits)
29 #define kNumBitModelTotalBits 11
30 #define kBitModelTotal (1 << kNumBitModelTotalBits)
31 #define kNumMoveBits 5
34 #define kNumPosBitsMax 4
35 #define kNumPosStatesMax (1 << kNumPosBitsMax)
37 #define kLenNumLowBits 3
38 #define kLenNumLowSymbols (1 << kLenNumLowBits)
39 #define kLenNumMidBits 3
40 #define kLenNumMidSymbols (1 << kLenNumMidBits)
41 #define kLenNumHighBits 8
42 #define kLenNumHighSymbols (1 << kLenNumHighBits)
45 #define LenChoice2 (LenChoice + 1)
46 #define LenLow (LenChoice2 + 1)
47 #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
48 #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
49 #define kNumLenProbs (LenHigh + kLenNumHighSymbols)
53 #define kNumLitStates 7
55 #define kStartPosModelIndex 4
56 #define kEndPosModelIndex 14
57 #define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
59 #define kNumPosSlotBits 6
60 #define kNumLenToPosStates 4
62 #define kNumAlignBits 4
63 #define kAlignTableSize (1 << kNumAlignBits)
65 #define kMatchMinLen 2
68 #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
69 #define IsRepG0 (IsRep + kNumStates)
70 #define IsRepG1 (IsRepG0 + kNumStates)
71 #define IsRepG2 (IsRepG1 + kNumStates)
72 #define IsRep0Long (IsRepG2 + kNumStates)
73 #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
74 #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
75 #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
76 #define LenCoder (Align + kAlignTableSize)
77 #define RepLenCoder (LenCoder + kNumLenProbs)
78 #define Literal (RepLenCoder + kNumLenProbs)
108 * int LzmaDecodeProperties(CLzmaProperties *propsRes,
109 * const unsigned char *propsData,
113 _LzmaDecodePropertiesA:
124 movl %ecx, 8(%eax) /* pb */
132 movl %ecx, 4(%eax) /* lp */
134 movl %ecx, (%eax) /* lc */
143 #define out_size 8(%ebp)
145 #define now_pos -4(%ebp)
146 #define prev_byte -8(%ebp)
147 #define range -12(%ebp)
148 #define code -16(%ebp)
149 #define state -20(%ebp)
150 #define rep0 -24(%ebp)
151 #define rep1 -28(%ebp)
152 #define rep2 -32(%ebp)
153 #define rep3 -36(%ebp)
161 #define POS_STATE_MASK ((1 << (FIXED_PB)) - 1)
162 #define LIT_POS_MASK ((1 << (FIXED_LP)) - 1)
164 #define LOCAL_SIZE 36
171 #define probs 12(%ebx)
173 #define pos_state_mask -40(%ebp)
174 #define lit_pos_mask -44(%ebp)
176 #define LOCAL_SIZE 44
180 RangeDecoderBitDecode:
182 leal (%ebx, %eax, 4), %eax
192 shrl $kNumBitModelTotalBits, %edx
199 movl $kBitModelTotal, %edx
201 shrl $kNumMoveBits, %edx
206 cmpl $kTopValue, range
219 shrl $kNumMoveBits, %edx
224 RangeDecoderBitTreeDecode:
225 RangeDecoderReverseBitTreeDecode:
238 call RangeDecoderBitDecode
256 subl %ecx, %edx /* RangeDecoderBitTreeDecode */
257 popl %ecx /* RangeDecoderReverseBitTreeDecode */
262 addl $LenChoice, %eax
263 call RangeDecoderBitDecode
267 movb $kLenNumLowBits, %cl
275 call RangeDecoderBitTreeDecode
282 addl $LenChoice2, %eax
283 call RangeDecoderBitDecode
286 pushl $kLenNumLowSymbols
287 movb $kLenNumMidBits, %cl
292 pushl $(kLenNumLowSymbols + kLenNumMidSymbols)
294 movb $kLenNumHighBits, %cl
304 * int LzmaDecode(CLzmaDecoderState *vs,
305 * const unsigned char *inStream,
306 * unsigned char *outStream,
314 subl $LOCAL_SIZE, %esp
332 movl $(Literal + (LZMA_LIT_SIZE << (FIXED_LC + FIXED_LP))), %ecx
334 movl $LZMA_LIT_SIZE, %eax
343 movl $(kBitModelTotal >> 1), %eax
366 movl %edx, pos_state_mask
372 movl %edx, lit_pos_mask;
375 /* RangeDecoderInit */
409 andl $POS_STATE_MASK, %eax
411 andl pos_state_mask, %eax
413 pushl %eax /* posState */
415 shll $kNumPosBitsMax, %edx
417 pushl %eax /* (state << kNumPosBitsMax) + posState */
419 call RangeDecoderBitDecode
425 andl $LIT_POS_MASK, %eax
428 shrl $(8 - FIXED_LC), %edx
430 andl lit_pos_mask, %eax
440 movl $LZMA_LIT_SIZE, %edx
445 incl %edx /* edx = 1 */
449 pushl (%edi, %eax) /* matchByte */
451 cmpb $kNumLitStates, state
454 /* LzmaLiteralDecodeMatch */
468 leal 0x100(%edx, %eax), %eax
470 call RangeDecoderBitDecode
482 /* LzmaLiteralDecode */
490 call RangeDecoderBitDecode
518 call RangeDecoderBitDecode
523 call RangeDecoderBitDecode
527 addl $IsRep0Long, %eax
528 call RangeDecoderBitDecode
544 movb (%edi, %edx), %al
555 call RangeDecoderBitDecode
561 call RangeDecoderBitDecode
574 movl $RepLenCoder, %eax
600 movl $(kNumLenToPosStates - 1), %eax
605 movb $kNumPosSlotBits, %cl
607 leal PosSlot(%edx), %eax
608 call RangeDecoderBitTreeDecode
611 cmpl $kStartPosModelIndex, %edx
624 cmpl $kEndPosModelIndex, %edx
627 addl $(SpecPos - 1), %eax
632 subb $kNumAlignBits, %cl
634 /* RangeDecoderDecodeDirectBits */
648 cmpl $kTopValue, %eax
658 movb $kNumAlignBits, %cl
665 call RangeDecoderReverseBitTreeDecode
674 addl $kMatchMinLen, %edx