ar71xx: enable the IP17xx driver for the nand subtarget
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.25 / 002-lzma_decompress.patch
1 --- /dev/null
2 +++ b/include/linux/LzmaDecode.h
3 @@ -0,0 +1,100 @@
4 +/*
5 + LzmaDecode.h
6 + LZMA Decoder interface
7 +
8 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
9 + http://www.7-zip.org/
10 +
11 + LZMA SDK is licensed under two licenses:
12 + 1) GNU Lesser General Public License (GNU LGPL)
13 + 2) Common Public License (CPL)
14 + It means that you can select one of these two licenses and
15 + follow rules of that license.
16 +
17 + SPECIAL EXCEPTION:
18 + Igor Pavlov, as the author of this code, expressly permits you to
19 + statically or dynamically link your code (or bind by name) to the
20 + interfaces of this file without subjecting your linked code to the
21 + terms of the CPL or GNU LGPL. Any modifications or additions
22 + to this file, however, are subject to the LGPL or CPL terms.
23 +*/
24 +
25 +#ifndef __LZMADECODE_H
26 +#define __LZMADECODE_H
27 +
28 +/* #define _LZMA_IN_CB */
29 +/* Use callback for input data */
30 +
31 +/* #define _LZMA_OUT_READ */
32 +/* Use read function for output data */
33 +
34 +/* #define _LZMA_PROB32 */
35 +/* It can increase speed on some 32-bit CPUs,
36 + but memory usage will be doubled in that case */
37 +
38 +/* #define _LZMA_LOC_OPT */
39 +/* Enable local speed optimizations inside code */
40 +
41 +#ifndef UInt32
42 +#ifdef _LZMA_UINT32_IS_ULONG
43 +#define UInt32 unsigned long
44 +#else
45 +#define UInt32 unsigned int
46 +#endif
47 +#endif
48 +
49 +#ifdef _LZMA_PROB32
50 +#define CProb UInt32
51 +#else
52 +#define CProb unsigned short
53 +#endif
54 +
55 +#define LZMA_RESULT_OK 0
56 +#define LZMA_RESULT_DATA_ERROR 1
57 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
58 +
59 +#ifdef _LZMA_IN_CB
60 +typedef struct _ILzmaInCallback
61 +{
62 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
63 +} ILzmaInCallback;
64 +#endif
65 +
66 +#define LZMA_BASE_SIZE 1846
67 +#define LZMA_LIT_SIZE 768
68 +
69 +/*
70 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
71 +bufferSize += 100 in case of _LZMA_OUT_READ
72 +by default CProb is unsigned short,
73 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
74 +*/
75 +
76 +#ifdef _LZMA_OUT_READ
77 +int LzmaDecoderInit(
78 + unsigned char *buffer, UInt32 bufferSize,
79 + int lc, int lp, int pb,
80 + unsigned char *dictionary, UInt32 dictionarySize,
81 + #ifdef _LZMA_IN_CB
82 + ILzmaInCallback *inCallback
83 + #else
84 + unsigned char *inStream, UInt32 inSize
85 + #endif
86 +);
87 +#endif
88 +
89 +int LzmaDecode(
90 + unsigned char *buffer,
91 + #ifndef _LZMA_OUT_READ
92 + UInt32 bufferSize,
93 + int lc, int lp, int pb,
94 + #ifdef _LZMA_IN_CB
95 + ILzmaInCallback *inCallback,
96 + #else
97 + unsigned char *inStream, UInt32 inSize,
98 + #endif
99 + #endif
100 + unsigned char *outStream, UInt32 outSize,
101 + UInt32 *outSizeProcessed);
102 +
103 +#endif
104 --- /dev/null
105 +++ b/lib/LzmaDecode.c
106 @@ -0,0 +1,663 @@
107 +/*
108 + LzmaDecode.c
109 + LZMA Decoder
110 +
111 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
112 + http://www.7-zip.org/
113 +
114 + LZMA SDK is licensed under two licenses:
115 + 1) GNU Lesser General Public License (GNU LGPL)
116 + 2) Common Public License (CPL)
117 + It means that you can select one of these two licenses and
118 + follow rules of that license.
119 +
120 + SPECIAL EXCEPTION:
121 + Igor Pavlov, as the author of this code, expressly permits you to
122 + statically or dynamically link your code (or bind by name) to the
123 + interfaces of this file without subjecting your linked code to the
124 + terms of the CPL or GNU LGPL. Any modifications or additions
125 + to this file, however, are subject to the LGPL or CPL terms.
126 +*/
127 +
128 +#include <linux/LzmaDecode.h>
129 +
130 +#ifndef Byte
131 +#define Byte unsigned char
132 +#endif
133 +
134 +#define kNumTopBits 24
135 +#define kTopValue ((UInt32)1 << kNumTopBits)
136 +
137 +#define kNumBitModelTotalBits 11
138 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
139 +#define kNumMoveBits 5
140 +
141 +typedef struct _CRangeDecoder
142 +{
143 + Byte *Buffer;
144 + Byte *BufferLim;
145 + UInt32 Range;
146 + UInt32 Code;
147 + #ifdef _LZMA_IN_CB
148 + ILzmaInCallback *InCallback;
149 + int Result;
150 + #endif
151 + int ExtraBytes;
152 +} CRangeDecoder;
153 +
154 +Byte RangeDecoderReadByte(CRangeDecoder *rd)
155 +{
156 + if (rd->Buffer == rd->BufferLim)
157 + {
158 + #ifdef _LZMA_IN_CB
159 + UInt32 size;
160 + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
161 + rd->BufferLim = rd->Buffer + size;
162 + if (size == 0)
163 + #endif
164 + {
165 + rd->ExtraBytes = 1;
166 + return 0xFF;
167 + }
168 + }
169 + return (*rd->Buffer++);
170 +}
171 +
172 +/* #define ReadByte (*rd->Buffer++) */
173 +#define ReadByte (RangeDecoderReadByte(rd))
174 +
175 +void RangeDecoderInit(CRangeDecoder *rd,
176 + #ifdef _LZMA_IN_CB
177 + ILzmaInCallback *inCallback
178 + #else
179 + Byte *stream, UInt32 bufferSize
180 + #endif
181 + )
182 +{
183 + int i;
184 + #ifdef _LZMA_IN_CB
185 + rd->InCallback = inCallback;
186 + rd->Buffer = rd->BufferLim = 0;
187 + #else
188 + rd->Buffer = stream;
189 + rd->BufferLim = stream + bufferSize;
190 + #endif
191 + rd->ExtraBytes = 0;
192 + rd->Code = 0;
193 + rd->Range = (0xFFFFFFFF);
194 + for(i = 0; i < 5; i++)
195 + rd->Code = (rd->Code << 8) | ReadByte;
196 +}
197 +
198 +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
199 +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
200 +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
201 +
202 +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
203 +{
204 + RC_INIT_VAR
205 + UInt32 result = 0;
206 + int i;
207 + for (i = numTotalBits; i > 0; i--)
208 + {
209 + /* UInt32 t; */
210 + range >>= 1;
211 +
212 + result <<= 1;
213 + if (code >= range)
214 + {
215 + code -= range;
216 + result |= 1;
217 + }
218 + /*
219 + t = (code - range) >> 31;
220 + t &= 1;
221 + code -= range & (t - 1);
222 + result = (result + result) | (1 - t);
223 + */
224 + RC_NORMALIZE
225 + }
226 + RC_FLUSH_VAR
227 + return result;
228 +}
229 +
230 +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
231 +{
232 + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
233 + if (rd->Code < bound)
234 + {
235 + rd->Range = bound;
236 + *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
237 + if (rd->Range < kTopValue)
238 + {
239 + rd->Code = (rd->Code << 8) | ReadByte;
240 + rd->Range <<= 8;
241 + }
242 + return 0;
243 + }
244 + else
245 + {
246 + rd->Range -= bound;
247 + rd->Code -= bound;
248 + *prob -= (*prob) >> kNumMoveBits;
249 + if (rd->Range < kTopValue)
250 + {
251 + rd->Code = (rd->Code << 8) | ReadByte;
252 + rd->Range <<= 8;
253 + }
254 + return 1;
255 + }
256 +}
257 +
258 +#define RC_GET_BIT2(prob, mi, A0, A1) \
259 + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
260 + if (code < bound) \
261 + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
262 + else \
263 + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
264 + RC_NORMALIZE
265 +
266 +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
267 +
268 +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
269 +{
270 + int mi = 1;
271 + int i;
272 + #ifdef _LZMA_LOC_OPT
273 + RC_INIT_VAR
274 + #endif
275 + for(i = numLevels; i > 0; i--)
276 + {
277 + #ifdef _LZMA_LOC_OPT
278 + CProb *prob = probs + mi;
279 + RC_GET_BIT(prob, mi)
280 + #else
281 + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
282 + #endif
283 + }
284 + #ifdef _LZMA_LOC_OPT
285 + RC_FLUSH_VAR
286 + #endif
287 + return mi - (1 << numLevels);
288 +}
289 +
290 +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
291 +{
292 + int mi = 1;
293 + int i;
294 + int symbol = 0;
295 + #ifdef _LZMA_LOC_OPT
296 + RC_INIT_VAR
297 + #endif
298 + for(i = 0; i < numLevels; i++)
299 + {
300 + #ifdef _LZMA_LOC_OPT
301 + CProb *prob = probs + mi;
302 + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
303 + #else
304 + int bit = RangeDecoderBitDecode(probs + mi, rd);
305 + mi = mi + mi + bit;
306 + symbol |= (bit << i);
307 + #endif
308 + }
309 + #ifdef _LZMA_LOC_OPT
310 + RC_FLUSH_VAR
311 + #endif
312 + return symbol;
313 +}
314 +
315 +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
316 +{
317 + int symbol = 1;
318 + #ifdef _LZMA_LOC_OPT
319 + RC_INIT_VAR
320 + #endif
321 + do
322 + {
323 + #ifdef _LZMA_LOC_OPT
324 + CProb *prob = probs + symbol;
325 + RC_GET_BIT(prob, symbol)
326 + #else
327 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
328 + #endif
329 + }
330 + while (symbol < 0x100);
331 + #ifdef _LZMA_LOC_OPT
332 + RC_FLUSH_VAR
333 + #endif
334 + return symbol;
335 +}
336 +
337 +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
338 +{
339 + int symbol = 1;
340 + #ifdef _LZMA_LOC_OPT
341 + RC_INIT_VAR
342 + #endif
343 + do
344 + {
345 + int bit;
346 + int matchBit = (matchByte >> 7) & 1;
347 + matchByte <<= 1;
348 + #ifdef _LZMA_LOC_OPT
349 + {
350 + CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
351 + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
352 + }
353 + #else
354 + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
355 + symbol = (symbol << 1) | bit;
356 + #endif
357 + if (matchBit != bit)
358 + {
359 + while (symbol < 0x100)
360 + {
361 + #ifdef _LZMA_LOC_OPT
362 + CProb *prob = probs + symbol;
363 + RC_GET_BIT(prob, symbol)
364 + #else
365 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
366 + #endif
367 + }
368 + break;
369 + }
370 + }
371 + while (symbol < 0x100);
372 + #ifdef _LZMA_LOC_OPT
373 + RC_FLUSH_VAR
374 + #endif
375 + return symbol;
376 +}
377 +
378 +#define kNumPosBitsMax 4
379 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
380 +
381 +#define kLenNumLowBits 3
382 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
383 +#define kLenNumMidBits 3
384 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
385 +#define kLenNumHighBits 8
386 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
387 +
388 +#define LenChoice 0
389 +#define LenChoice2 (LenChoice + 1)
390 +#define LenLow (LenChoice2 + 1)
391 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
392 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
393 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
394 +
395 +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
396 +{
397 + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
398 + return RangeDecoderBitTreeDecode(p + LenLow +
399 + (posState << kLenNumLowBits), kLenNumLowBits, rd);
400 + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
401 + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
402 + (posState << kLenNumMidBits), kLenNumMidBits, rd);
403 + return kLenNumLowSymbols + kLenNumMidSymbols +
404 + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
405 +}
406 +
407 +#define kNumStates 12
408 +
409 +#define kStartPosModelIndex 4
410 +#define kEndPosModelIndex 14
411 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
412 +
413 +#define kNumPosSlotBits 6
414 +#define kNumLenToPosStates 4
415 +
416 +#define kNumAlignBits 4
417 +#define kAlignTableSize (1 << kNumAlignBits)
418 +
419 +#define kMatchMinLen 2
420 +
421 +#define IsMatch 0
422 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
423 +#define IsRepG0 (IsRep + kNumStates)
424 +#define IsRepG1 (IsRepG0 + kNumStates)
425 +#define IsRepG2 (IsRepG1 + kNumStates)
426 +#define IsRep0Long (IsRepG2 + kNumStates)
427 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
428 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
429 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
430 +#define LenCoder (Align + kAlignTableSize)
431 +#define RepLenCoder (LenCoder + kNumLenProbs)
432 +#define Literal (RepLenCoder + kNumLenProbs)
433 +
434 +#if Literal != LZMA_BASE_SIZE
435 +StopCompilingDueBUG
436 +#endif
437 +
438 +#ifdef _LZMA_OUT_READ
439 +
440 +typedef struct _LzmaVarState
441 +{
442 + CRangeDecoder RangeDecoder;
443 + Byte *Dictionary;
444 + UInt32 DictionarySize;
445 + UInt32 DictionaryPos;
446 + UInt32 GlobalPos;
447 + UInt32 Reps[4];
448 + int lc;
449 + int lp;
450 + int pb;
451 + int State;
452 + int PreviousIsMatch;
453 + int RemainLen;
454 +} LzmaVarState;
455 +
456 +int LzmaDecoderInit(
457 + unsigned char *buffer, UInt32 bufferSize,
458 + int lc, int lp, int pb,
459 + unsigned char *dictionary, UInt32 dictionarySize,
460 + #ifdef _LZMA_IN_CB
461 + ILzmaInCallback *inCallback
462 + #else
463 + unsigned char *inStream, UInt32 inSize
464 + #endif
465 + )
466 +{
467 + LzmaVarState *vs = (LzmaVarState *)buffer;
468 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
469 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
470 + UInt32 i;
471 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
472 + return LZMA_RESULT_NOT_ENOUGH_MEM;
473 + vs->Dictionary = dictionary;
474 + vs->DictionarySize = dictionarySize;
475 + vs->DictionaryPos = 0;
476 + vs->GlobalPos = 0;
477 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
478 + vs->lc = lc;
479 + vs->lp = lp;
480 + vs->pb = pb;
481 + vs->State = 0;
482 + vs->PreviousIsMatch = 0;
483 + vs->RemainLen = 0;
484 + dictionary[dictionarySize - 1] = 0;
485 + for (i = 0; i < numProbs; i++)
486 + p[i] = kBitModelTotal >> 1;
487 + RangeDecoderInit(&vs->RangeDecoder,
488 + #ifdef _LZMA_IN_CB
489 + inCallback
490 + #else
491 + inStream, inSize
492 + #endif
493 + );
494 + return LZMA_RESULT_OK;
495 +}
496 +
497 +int LzmaDecode(unsigned char *buffer,
498 + unsigned char *outStream, UInt32 outSize,
499 + UInt32 *outSizeProcessed)
500 +{
501 + LzmaVarState *vs = (LzmaVarState *)buffer;
502 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
503 + CRangeDecoder rd = vs->RangeDecoder;
504 + int state = vs->State;
505 + int previousIsMatch = vs->PreviousIsMatch;
506 + Byte previousByte;
507 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
508 + UInt32 nowPos = 0;
509 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
510 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
511 + int lc = vs->lc;
512 + int len = vs->RemainLen;
513 + UInt32 globalPos = vs->GlobalPos;
514 +
515 + Byte *dictionary = vs->Dictionary;
516 + UInt32 dictionarySize = vs->DictionarySize;
517 + UInt32 dictionaryPos = vs->DictionaryPos;
518 +
519 + if (len == -1)
520 + {
521 + *outSizeProcessed = 0;
522 + return LZMA_RESULT_OK;
523 + }
524 +
525 + while(len > 0 && nowPos < outSize)
526 + {
527 + UInt32 pos = dictionaryPos - rep0;
528 + if (pos >= dictionarySize)
529 + pos += dictionarySize;
530 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
531 + if (++dictionaryPos == dictionarySize)
532 + dictionaryPos = 0;
533 + len--;
534 + }
535 + if (dictionaryPos == 0)
536 + previousByte = dictionary[dictionarySize - 1];
537 + else
538 + previousByte = dictionary[dictionaryPos - 1];
539 +#else
540 +
541 +int LzmaDecode(
542 + Byte *buffer, UInt32 bufferSize,
543 + int lc, int lp, int pb,
544 + #ifdef _LZMA_IN_CB
545 + ILzmaInCallback *inCallback,
546 + #else
547 + unsigned char *inStream, UInt32 inSize,
548 + #endif
549 + unsigned char *outStream, UInt32 outSize,
550 + UInt32 *outSizeProcessed)
551 +{
552 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
553 + CProb *p = (CProb *)buffer;
554 + CRangeDecoder rd;
555 + UInt32 i;
556 + int state = 0;
557 + int previousIsMatch = 0;
558 + Byte previousByte = 0;
559 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
560 + UInt32 nowPos = 0;
561 + UInt32 posStateMask = (1 << pb) - 1;
562 + UInt32 literalPosMask = (1 << lp) - 1;
563 + int len = 0;
564 + if (bufferSize < numProbs * sizeof(CProb))
565 + return LZMA_RESULT_NOT_ENOUGH_MEM;
566 + for (i = 0; i < numProbs; i++)
567 + p[i] = kBitModelTotal >> 1;
568 + RangeDecoderInit(&rd,
569 + #ifdef _LZMA_IN_CB
570 + inCallback
571 + #else
572 + inStream, inSize
573 + #endif
574 + );
575 +#endif
576 +
577 + *outSizeProcessed = 0;
578 + while(nowPos < outSize)
579 + {
580 + int posState = (int)(
581 + (nowPos
582 + #ifdef _LZMA_OUT_READ
583 + + globalPos
584 + #endif
585 + )
586 + & posStateMask);
587 + #ifdef _LZMA_IN_CB
588 + if (rd.Result != LZMA_RESULT_OK)
589 + return rd.Result;
590 + #endif
591 + if (rd.ExtraBytes != 0)
592 + return LZMA_RESULT_DATA_ERROR;
593 + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
594 + {
595 + CProb *probs = p + Literal + (LZMA_LIT_SIZE *
596 + (((
597 + (nowPos
598 + #ifdef _LZMA_OUT_READ
599 + + globalPos
600 + #endif
601 + )
602 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
603 +
604 + if (state < 4) state = 0;
605 + else if (state < 10) state -= 3;
606 + else state -= 6;
607 + if (previousIsMatch)
608 + {
609 + Byte matchByte;
610 + #ifdef _LZMA_OUT_READ
611 + UInt32 pos = dictionaryPos - rep0;
612 + if (pos >= dictionarySize)
613 + pos += dictionarySize;
614 + matchByte = dictionary[pos];
615 + #else
616 + matchByte = outStream[nowPos - rep0];
617 + #endif
618 + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
619 + previousIsMatch = 0;
620 + }
621 + else
622 + previousByte = LzmaLiteralDecode(probs, &rd);
623 + outStream[nowPos++] = previousByte;
624 + #ifdef _LZMA_OUT_READ
625 + dictionary[dictionaryPos] = previousByte;
626 + if (++dictionaryPos == dictionarySize)
627 + dictionaryPos = 0;
628 + #endif
629 + }
630 + else
631 + {
632 + previousIsMatch = 1;
633 + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
634 + {
635 + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
636 + {
637 + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
638 + {
639 + #ifdef _LZMA_OUT_READ
640 + UInt32 pos;
641 + #endif
642 + if (
643 + (nowPos
644 + #ifdef _LZMA_OUT_READ
645 + + globalPos
646 + #endif
647 + )
648 + == 0)
649 + return LZMA_RESULT_DATA_ERROR;
650 + state = state < 7 ? 9 : 11;
651 + #ifdef _LZMA_OUT_READ
652 + pos = dictionaryPos - rep0;
653 + if (pos >= dictionarySize)
654 + pos += dictionarySize;
655 + previousByte = dictionary[pos];
656 + dictionary[dictionaryPos] = previousByte;
657 + if (++dictionaryPos == dictionarySize)
658 + dictionaryPos = 0;
659 + #else
660 + previousByte = outStream[nowPos - rep0];
661 + #endif
662 + outStream[nowPos++] = previousByte;
663 + continue;
664 + }
665 + }
666 + else
667 + {
668 + UInt32 distance;
669 + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
670 + distance = rep1;
671 + else
672 + {
673 + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
674 + distance = rep2;
675 + else
676 + {
677 + distance = rep3;
678 + rep3 = rep2;
679 + }
680 + rep2 = rep1;
681 + }
682 + rep1 = rep0;
683 + rep0 = distance;
684 + }
685 + len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
686 + state = state < 7 ? 8 : 11;
687 + }
688 + else
689 + {
690 + int posSlot;
691 + rep3 = rep2;
692 + rep2 = rep1;
693 + rep1 = rep0;
694 + state = state < 7 ? 7 : 10;
695 + len = LzmaLenDecode(p + LenCoder, &rd, posState);
696 + posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
697 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
698 + kNumPosSlotBits), kNumPosSlotBits, &rd);
699 + if (posSlot >= kStartPosModelIndex)
700 + {
701 + int numDirectBits = ((posSlot >> 1) - 1);
702 + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
703 + if (posSlot < kEndPosModelIndex)
704 + {
705 + rep0 += RangeDecoderReverseBitTreeDecode(
706 + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
707 + }
708 + else
709 + {
710 + rep0 += RangeDecoderDecodeDirectBits(&rd,
711 + numDirectBits - kNumAlignBits) << kNumAlignBits;
712 + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
713 + }
714 + }
715 + else
716 + rep0 = posSlot;
717 + rep0++;
718 + }
719 + if (rep0 == (UInt32)(0))
720 + {
721 + /* it's for stream version */
722 + len = -1;
723 + break;
724 + }
725 + if (rep0 > nowPos
726 + #ifdef _LZMA_OUT_READ
727 + + globalPos
728 + #endif
729 + )
730 + {
731 + return LZMA_RESULT_DATA_ERROR;
732 + }
733 + len += kMatchMinLen;
734 + do
735 + {
736 + #ifdef _LZMA_OUT_READ
737 + UInt32 pos = dictionaryPos - rep0;
738 + if (pos >= dictionarySize)
739 + pos += dictionarySize;
740 + previousByte = dictionary[pos];
741 + dictionary[dictionaryPos] = previousByte;
742 + if (++dictionaryPos == dictionarySize)
743 + dictionaryPos = 0;
744 + #else
745 + previousByte = outStream[nowPos - rep0];
746 + #endif
747 + outStream[nowPos++] = previousByte;
748 + len--;
749 + }
750 + while(len > 0 && nowPos < outSize);
751 + }
752 + }
753 +
754 + #ifdef _LZMA_OUT_READ
755 + vs->RangeDecoder = rd;
756 + vs->DictionaryPos = dictionaryPos;
757 + vs->GlobalPos = globalPos + nowPos;
758 + vs->Reps[0] = rep0;
759 + vs->Reps[1] = rep1;
760 + vs->Reps[2] = rep2;
761 + vs->Reps[3] = rep3;
762 + vs->State = state;
763 + vs->PreviousIsMatch = previousIsMatch;
764 + vs->RemainLen = len;
765 + #endif
766 +
767 + *outSizeProcessed = nowPos;
768 + return LZMA_RESULT_OK;
769 +}
770 --- a/lib/Makefile
771 +++ b/lib/Makefile
772 @@ -14,7 +14,7 @@ lib-$(CONFIG_SMP) += cpumask.o
773 lib-y += kobject.o kref.o klist.o
774
775 obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
776 - bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o
777 + bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o LzmaDecode.o
778
779 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
780 CFLAGS_kobject.o += -DDEBUG
This page took 0.074918 seconds and 5 git commands to generate.