123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- /*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2008 Free Software Foundation, Inc.
- *
- * GRUB is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GRUB is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
- */
- #define FIXED_PROPS
- #define LZMA_BASE_SIZE 1846
- #define LZMA_LIT_SIZE 768
- #define LZMA_PROPERTIES_SIZE 5
- #define kNumTopBits 24
- #define kTopValue (1 << kNumTopBits)
- #define kNumBitModelTotalBits 11
- #define kBitModelTotal (1 << kNumBitModelTotalBits)
- #define kNumMoveBits 5
- #define kNumPosBitsMax 4
- #define kNumPosStatesMax (1 << kNumPosBitsMax)
- #define kLenNumLowBits 3
- #define kLenNumLowSymbols (1 << kLenNumLowBits)
- #define kLenNumMidBits 3
- #define kLenNumMidSymbols (1 << kLenNumMidBits)
- #define kLenNumHighBits 8
- #define kLenNumHighSymbols (1 << kLenNumHighBits)
- #define LenChoice 0
- #define LenChoice2 (LenChoice + 1)
- #define LenLow (LenChoice2 + 1)
- #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
- #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
- #define kNumLenProbs (LenHigh + kLenNumHighSymbols)
- #define kNumStates 12
- #define kNumLitStates 7
- #define kStartPosModelIndex 4
- #define kEndPosModelIndex 14
- #define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
- #define kNumPosSlotBits 6
- #define kNumLenToPosStates 4
- #define kNumAlignBits 4
- #define kAlignTableSize (1 << kNumAlignBits)
- #define kMatchMinLen 2
- #define IsMatch 0
- #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
- #define IsRepG0 (IsRep + kNumStates)
- #define IsRepG1 (IsRepG0 + kNumStates)
- #define IsRepG2 (IsRepG1 + kNumStates)
- #define IsRep0Long (IsRepG2 + kNumStates)
- #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
- #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
- #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
- #define LenCoder (Align + kAlignTableSize)
- #define RepLenCoder (LenCoder + kNumLenProbs)
- #define Literal (RepLenCoder + kNumLenProbs)
- #if 0
- DbgOut:
- pushf
- pushl %ebp
- pushl %edi
- pushl %esi
- pushl %edx
- pushl %ecx
- pushl %ebx
- pushl %eax
- call _DebugPrint
- popl %eax
- popl %ebx
- popl %ecx
- popl %edx
- popl %esi
- popl %edi
- popl %ebp
- popf
- ret
- /*
- * int LzmaDecodeProperties(CLzmaProperties *propsRes,
- * const unsigned char *propsData,
- * int size);
- */
- _LzmaDecodePropertiesA:
- movb (%edx), %dl
- xorl %ecx, %ecx
- 1:
- cmpb $45, %dl
- jb 2f
- incl %ecx
- subb $45, %dl
- jmp 1b
- 2:
- movl %ecx, 8(%eax) /* pb */
- xorl %ecx, %ecx
- 1:
- cmpb $9, %dl
- jb 2f
- incl %ecx
- subb $9, %dl
- 2:
- movl %ecx, 4(%eax) /* lp */
- movb %dl, %cl
- movl %ecx, (%eax) /* lc */
- #endif
- #ifndef ASM_FILE
- xorl %eax, %eax
- #endif
- ret
- #define out_size 8(%ebp)
- #define now_pos -4(%ebp)
- #define prev_byte -8(%ebp)
- #define range -12(%ebp)
- #define code -16(%ebp)
- #define state -20(%ebp)
- #define rep0 -24(%ebp)
- #define rep1 -28(%ebp)
- #define rep2 -32(%ebp)
- #define rep3 -36(%ebp)
- #ifdef FIXED_PROPS
- #define FIXED_LC 3
- #define FIXED_LP 0
- #define FIXED_PB 2
- #define POS_STATE_MASK ((1 << (FIXED_PB)) - 1)
- #define LIT_POS_MASK ((1 << (FIXED_LP)) - 1)
- #define LOCAL_SIZE 36
- #else
- #define lc (%ebx)
- #define lp 4(%ebx)
- #define pb 8(%ebx)
- #define probs 12(%ebx)
- #define pos_state_mask -40(%ebp)
- #define lit_pos_mask -44(%ebp)
- #define LOCAL_SIZE 44
- #endif
- RangeDecoderBitDecode:
- #ifdef FIXED_PROPS
- leal (%ebx, %eax, 4), %eax
- #else
- shll $2, %eax
- addl probs, %eax
- #endif
- movl %eax, %ecx
- movl (%ecx), %eax
- movl range, %edx
- shrl $kNumBitModelTotalBits, %edx
- mull %edx
- cmpl code, %eax
- jbe 1f
- movl %eax, range
- movl $kBitModelTotal, %edx
- subl (%ecx), %edx
- shrl $kNumMoveBits, %edx
- addl %edx, (%ecx)
- clc
- 3:
- pushf
- cmpl $kTopValue, range
- jnc 2f
- shll $8, code
- lodsb
- movb %al, code
- shll $8, range
- 2:
- popf
- ret
- 1:
- subl %eax, range
- subl %eax, code
- movl (%ecx), %edx
- shrl $kNumMoveBits, %edx
- subl %edx, (%ecx)
- stc
- jmp 3b
- RangeDecoderBitTreeDecode:
- RangeDecoderReverseBitTreeDecode:
- movzbl %cl, %ecx
- xorl %edx, %edx
- pushl %edx
- incl %edx
- pushl %edx
- 1:
- pushl %eax
- pushl %ecx
- pushl %edx
- addl %edx, %eax
- call RangeDecoderBitDecode
- popl %edx
- popl %ecx
- jnc 2f
- movl 4(%esp), %eax
- orl %eax, 8(%esp)
- stc
- 2:
- adcl %edx, %edx
- popl %eax
- shll $1, (%esp)
- loop 1b
- popl %ecx
- subl %ecx, %edx /* RangeDecoderBitTreeDecode */
- popl %ecx /* RangeDecoderReverseBitTreeDecode */
- ret
- LzmaLenDecode:
- pushl %eax
- addl $LenChoice, %eax
- call RangeDecoderBitDecode
- popl %eax
- jc 1f
- pushl $0
- movb $kLenNumLowBits, %cl
- addl $LenLow, %eax
- 2:
- movl 12(%esp), %edx
- shll %cl, %edx
- addl %edx, %eax
- 3:
- call RangeDecoderBitTreeDecode
- popl %eax
- addl %eax, %edx
- ret
- 1:
- pushl %eax
- addl $LenChoice2, %eax
- call RangeDecoderBitDecode
- popl %eax
- jc 1f
- pushl $kLenNumLowSymbols
- movb $kLenNumMidBits, %cl
- addl $LenMid, %eax
- jmp 2b
- 1:
- pushl $(kLenNumLowSymbols + kLenNumMidSymbols)
- addl $LenHigh, %eax
- movb $kLenNumHighBits, %cl
- jmp 3b
- WriteByte:
- movb %al, prev_byte
- stosb
- incl now_pos
- ret
- /*
- * int LzmaDecode(CLzmaDecoderState *vs,
- * const unsigned char *inStream,
- * unsigned char *outStream,
- * SizeT outSize);
- */
- _LzmaDecodeA:
- pushl %ebp
- movl %esp, %ebp
- subl $LOCAL_SIZE, %esp
- #ifndef ASM_FILE
- pushl %esi
- pushl %edi
- pushl %ebx
- movl %eax, %ebx
- movl %edx, %esi
- pushl %ecx
- #else
- pushl %edi
- #endif
- cld
- #ifdef FIXED_PROPS
- movl %ebx, %edi
- movl $(Literal + (LZMA_LIT_SIZE << (FIXED_LC + FIXED_LP))), %ecx
- #else
- movl $LZMA_LIT_SIZE, %eax
- movb lc, %cl
- addb lp, %cl
- shll %cl, %eax
- addl $Literal, %eax
- movl %eax, %ecx
- movl probs, %edi
- #endif
- movl $(kBitModelTotal >> 1), %eax
- rep
- stosl
- popl %edi
- xorl %eax, %eax
- movl %eax, now_pos
- movl %eax, prev_byte
- movl %eax, state
- incl %eax
- movl %eax, rep0
- movl %eax, rep1
- movl %eax, rep2
- movl %eax, rep3
- #ifndef FIXED_PROPS
- movl %eax, %edx
- movb pb, %cl
- shll %cl, %edx
- decl %edx
- movl %edx, pos_state_mask
- movl %eax, %edx
- movb lp, %cl
- shll %cl, %edx
- decl %edx
- movl %edx, lit_pos_mask;
- #endif
- /* RangeDecoderInit */
- negl %eax
- movl %eax, range
- incl %eax
- movb $5, %cl
- 1:
- shll $8, %eax
- lodsb
- loop 1b
- movl %eax, code
- lzma_decode_loop:
- movl now_pos, %eax
- cmpl out_size, %eax
- jb 1f
- #ifndef ASM_FILE
- xorl %eax, %eax
- popl %ebx
- popl %edi
- popl %esi
- #endif
- movl %ebp, %esp
- popl %ebp
- ret
- 1:
- #ifdef FIXED_PROPS
- andl $POS_STATE_MASK, %eax
- #else
- andl pos_state_mask, %eax
- #endif
- pushl %eax /* posState */
- movl state, %edx
- shll $kNumPosBitsMax, %edx
- addl %edx, %eax
- pushl %eax /* (state << kNumPosBitsMax) + posState */
- call RangeDecoderBitDecode
- jc 1f
- movl now_pos, %eax
- #ifdef FIXED_PROPS
- andl $LIT_POS_MASK, %eax
- shll $FIXED_LC, %eax
- movl prev_byte, %edx
- shrl $(8 - FIXED_LC), %edx
- #else
- andl lit_pos_mask, %eax
- movb lc, %cl
- shll %cl, %eax
- negb %cl
- addb $8, %cl
- movl prev_byte, %edx
- shrl %cl, %edx
- #endif
- addl %edx, %eax
- movl $LZMA_LIT_SIZE, %edx
- mull %edx
- addl $Literal, %eax
- pushl %eax
- incl %edx /* edx = 1 */
- movl rep0, %eax
- negl %eax
- pushl (%edi, %eax) /* matchByte */
- cmpb $kNumLitStates, state
- jb 5f
- /* LzmaLiteralDecodeMatch */
- 3:
- cmpl $0x100, %edx
- jae 4f
- xorl %eax, %eax
- shlb $1, (%esp)
- adcl %eax, %eax
- pushl %eax
- pushl %edx
- shll $8, %eax
- leal 0x100(%edx, %eax), %eax
- addl 12(%esp), %eax
- call RangeDecoderBitDecode
- setc %al
- popl %edx
- adcl %edx, %edx
- popl %ecx
- cmpb %cl, %al
- jz 3b
- 5:
- /* LzmaLiteralDecode */
- cmpl $0x100, %edx
- jae 4f
- pushl %edx
- movl %edx, %eax
- addl 8(%esp), %eax
- call RangeDecoderBitDecode
- popl %edx
- adcl %edx, %edx
- jmp 5b
- 4:
- addl $16, %esp
- movb %dl, %al
- call WriteByte
- movb state, %al
- cmpb $4, %al
- jae 2f
- xorb %al, %al
- jmp 3f
- 2:
- subb $3, %al
- cmpb $7, %al
- jb 3f
- subb $3, %al
- 3:
- movb %al, state
- jmp lzma_decode_loop
- 1:
- movl state, %eax
- addl $IsRep, %eax
- call RangeDecoderBitDecode
- jnc 1f
- movl state, %eax
- addl $IsRepG0, %eax
- call RangeDecoderBitDecode
- jc LOCAL(lzma_10a)
- movl (%esp), %eax
- addl $IsRep0Long, %eax
- call RangeDecoderBitDecode
- jc LOCAL(lzma_20a)
- cmpb $7, state
- movb $9, state
- jb LOCAL(lzma_100a)
- addb $2, state
- LOCAL(lzma_100a):
- movl $1, %ecx
- 3:
- movl rep0, %edx
- negl %edx
- 4:
- movb (%edi, %edx), %al
- call WriteByte
- loop 4b
- popl %eax
- popl %eax
- jmp lzma_decode_loop
- LOCAL(lzma_10a):
- movl state, %eax
- addl $IsRepG1, %eax
- call RangeDecoderBitDecode
- movl rep1, %edx
- jnc LOCAL(lzma_100b)
- movl state, %eax
- addl $IsRepG2, %eax
- call RangeDecoderBitDecode
- movl rep2, %edx
- jnc LOCAL(lzma_1000a)
- movl rep2, %edx
- xchgl rep3, %edx
- LOCAL(lzma_1000a):
- pushl rep1
- popl rep2
- LOCAL(lzma_100b):
- xchg rep0, %edx
- movl %edx, rep1
- LOCAL(lzma_20a):
- movl $RepLenCoder, %eax
- call LzmaLenDecode
- cmpb $7, state
- movb $8, state
- jb LOCAL(lzma_100c)
- addb $3, state
- LOCAL(lzma_100c):
- jmp 2f
- 1:
- movl rep0, %eax
- xchgl rep1, %eax
- xchgl rep2, %eax
- movl %eax, rep3
- cmpb $7, state
- movb $7, state
- jb LOCAL(lzma_10b)
- addb $3, state
- LOCAL(lzma_10b):
- movl $LenCoder, %eax
- call LzmaLenDecode
- pushl %edx
- movl $(kNumLenToPosStates - 1), %eax
- cmpl %eax, %edx
- jbe LOCAL(lzma_100d)
- movl %eax, %edx
- LOCAL(lzma_100d):
- movb $kNumPosSlotBits, %cl
- shll %cl, %edx
- leal PosSlot(%edx), %eax
- call RangeDecoderBitTreeDecode
- movl %edx, rep0
- cmpl $kStartPosModelIndex, %edx
- jb LOCAL(lzma_100e)
- movl %edx, %ecx
- shrl $1, %ecx
- decl %ecx
- movzbl %dl, %eax
- andb $1, %al
- orb $2, %al
- shll %cl, %eax
- movl %eax, rep0
- cmpl $kEndPosModelIndex, %edx
- jae LOCAL(lzma_200a)
- movl rep0, %eax
- addl $(SpecPos - 1), %eax
- subl %edx, %eax
- jmp LOCAL(lzma_300a)
- LOCAL(lzma_200a):
- subb $kNumAlignBits, %cl
- /* RangeDecoderDecodeDirectBits */
- xorl %edx, %edx
- LOCAL(lzma_1000b):
- shrl $1, range
- shll $1, %edx
- movl range, %eax
- cmpl %eax, code
- jb LOCAL(lzma_2000a)
- subl %eax, code
- orb $1, %dl
- LOCAL(lzma_2000a):
- cmpl $kTopValue, %eax
- jae LOCAL(lzma_3000a)
- shll $8, range
- shll $8, code
- lodsb
- movb %al, code
- LOCAL(lzma_3000a):
- loop LOCAL(lzma_1000b)
- movb $kNumAlignBits, %cl
- shll %cl, %edx
- addl %edx, rep0
- movl $Align, %eax
- LOCAL(lzma_300a):
- call RangeDecoderReverseBitTreeDecode
- addl %ecx, rep0
- LOCAL(lzma_100e):
- incl rep0
- popl %edx
- 2:
- addl $kMatchMinLen, %edx
- movl %edx, %ecx
- jmp 3b
|