wok-next annotate grub4dos/stuff/lzma.diff @ rev 17516

Remove some categories (system -> system-tools, web -> network, devel -> development, news -> network).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jan 15 01:14:17 2015 +0200 (2015-01-15)
parents
children
rev   line source
pascal@9240 1 From http://code.google.com/p/grub4dos-chenall/issues/detail?id=6
pascal@9240 2
pascal@9240 3 diff -Naur ../grub4dos-chenall-r63/stage2/common.c ./stage2/common.c
pascal@9240 4 --- grub4dos-chenall-r63/stage2/common.c 2010-11-19 12:41:03.196955000 +0700
pascal@9240 5 +++ grub4dos/stage2/common.c 2010-11-23 21:28:26.509102100 +0700
pascal@9240 6 @@ -143,6 +143,7 @@
pascal@9240 7 [ERR_WRITE_GZIP_FILE] = "Attempt to write a gzip file",
pascal@9240 8 [ERR_FUNC_CALL] = "Invalid function call",
pascal@9240 9 // [ERR_WRITE_TO_NON_MEM_DRIVE] = "Only RAM drives can be written when running in a script",
pascal@9240 10 + [ERR_NOT_ENOUGH_MEMORY] = "Not enough memory",
pascal@9240 11
pascal@9240 12 };
pascal@9240 13
pascal@9240 14 diff -Naur ../grub4dos-chenall-r63/stage2/dec_lzma.c ./stage2/dec_lzma.c
pascal@9240 15 --- grub4dos-chenall-r63/stage2/dec_lzma.c 1970-01-01 07:00:00.000000000 +0700
pascal@9240 16 +++ grub4dos/stage2/dec_lzma.c 2010-11-28 22:12:06.452791800 +0700
pascal@9240 17 @@ -0,0 +1,1384 @@
pascal@9240 18 +/*
pascal@9240 19 + * GRUB4DOS -- GRand Unified Bootloader
pascal@9240 20 + * Copyright (C) 1999 Free Software Foundation, Inc.
pascal@9240 21 + *
pascal@9240 22 + * This program is free software; you can redistribute it and/or modify
pascal@9240 23 + * it under the terms of the GNU General Public License as published by
pascal@9240 24 + * the Free Software Foundation; either version 2 of the License, or
pascal@9240 25 + * (at your option) any later version.
pascal@9240 26 + *
pascal@9240 27 + * This program is distributed in the hope that it will be useful,
pascal@9240 28 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
pascal@9240 29 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
pascal@9240 30 + * GNU General Public License for more details.
pascal@9240 31 + *
pascal@9240 32 + * You should have received a copy of the GNU General Public License
pascal@9240 33 + * along with this program; if not, write to the Free Software
pascal@9240 34 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
pascal@9240 35 + */
pascal@9240 36 +
pascal@9240 37 +/*
pascal@9240 38 + * Most of this file is derives from LZMA SDK 9.12 beta
pascal@9240 39 + * files Types.h, LzmaDec.h, LzmaDec.c by Igor Pavlov
pascal@9240 40 + * It has been modified for used in GRUB4DOS.
pascal@9240 41 + */
pascal@9240 42 +
pascal@9240 43 +#ifndef NO_DECOMPRESSION
pascal@9240 44 +
pascal@9240 45 +#include "shared.h"
pascal@9240 46 +#include "decomp.h"
pascal@9240 47 +
pascal@9240 48 +/* Types.h -- Basic types
pascal@9240 49 +2010-03-11 : Igor Pavlov : Public domain */
pascal@9240 50 +
pascal@9240 51 +#define SZ_OK 0
pascal@9240 52 +
pascal@9240 53 +#define SZ_ERROR_DATA 1
pascal@9240 54 +#define SZ_ERROR_MEM 2
pascal@9240 55 +#define SZ_ERROR_CRC 3
pascal@9240 56 +#define SZ_ERROR_UNSUPPORTED 4
pascal@9240 57 +#define SZ_ERROR_PARAM 5
pascal@9240 58 +#define SZ_ERROR_INPUT_EOF 6
pascal@9240 59 +#define SZ_ERROR_OUTPUT_EOF 7
pascal@9240 60 +#define SZ_ERROR_READ 8
pascal@9240 61 +#define SZ_ERROR_WRITE 9
pascal@9240 62 +#define SZ_ERROR_PROGRESS 10
pascal@9240 63 +#define SZ_ERROR_FAIL 11
pascal@9240 64 +#define SZ_ERROR_THREAD 12
pascal@9240 65 +
pascal@9240 66 +#define SZ_ERROR_ARCHIVE 16
pascal@9240 67 +#define SZ_ERROR_NO_ARCHIVE 17
pascal@9240 68 +
pascal@9240 69 +typedef int SRes;
pascal@9240 70 +typedef int WRes;
pascal@9240 71 +
pascal@9240 72 +#ifndef RINOK
pascal@9240 73 +#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
pascal@9240 74 +#endif
pascal@9240 75 +
pascal@9240 76 +typedef unsigned char Byte;
pascal@9240 77 +typedef short Int16;
pascal@9240 78 +typedef unsigned short UInt16;
pascal@9240 79 +
pascal@9240 80 +typedef int Int32;
pascal@9240 81 +typedef unsigned int UInt32;
pascal@9240 82 +
pascal@9240 83 +typedef long long int Int64;
pascal@9240 84 +typedef unsigned long long int UInt64;
pascal@9240 85 +
pascal@9240 86 +typedef UInt32 SizeT;
pascal@9240 87 +typedef int ptrdiff_t;
pascal@9240 88 +
pascal@9240 89 +typedef int Bool;
pascal@9240 90 +#define True 1
pascal@9240 91 +#define False 0
pascal@9240 92 +
pascal@9240 93 +#define MY_STD_CALL
pascal@9240 94 +#define MY_CDECL
pascal@9240 95 +#define MY_FAST_CALL
pascal@9240 96 +
pascal@9240 97 +typedef struct
pascal@9240 98 +{
pascal@9240 99 + void *(*Alloc)(void *p, SizeT size);
pascal@9240 100 + void (*Free)(void *p, void *address); /* address can be 0 */
pascal@9240 101 +} ISzAlloc;
pascal@9240 102 +
pascal@9240 103 +#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
pascal@9240 104 +#define IAlloc_Free(p, a) (p)->Free((p), a)
pascal@9240 105 +
pascal@9240 106 +/* -------------------------------------------------------------------------- */
pascal@9240 107 +
pascal@9240 108 +/* LzmaDec.h -- LZMA Decoder
pascal@9240 109 +2009-02-07 : Igor Pavlov : Public domain */
pascal@9240 110 +
pascal@9240 111 +/* #define _LZMA_PROB32 */
pascal@9240 112 +/* _LZMA_PROB32 can increase the speed on some CPUs,
pascal@9240 113 + but memory usage for CLzmaDec::probs will be doubled in that case */
pascal@9240 114 +
pascal@9240 115 +#ifdef _LZMA_PROB32
pascal@9240 116 +#define UIntLzmaProb UInt32
pascal@9240 117 +#else
pascal@9240 118 +#define UIntLzmaProb UInt16
pascal@9240 119 +#endif
pascal@9240 120 +
pascal@9240 121 +
pascal@9240 122 +/* ---------- LZMA Properties ---------- */
pascal@9240 123 +
pascal@9240 124 +#define LZMA_PROPS_SIZE 5
pascal@9240 125 +
pascal@9240 126 +typedef struct _CLzmaProps
pascal@9240 127 +{
pascal@9240 128 + unsigned lc, lp, pb;
pascal@9240 129 + UInt32 dicSize;
pascal@9240 130 +} CLzmaProps;
pascal@9240 131 +
pascal@9240 132 +/* LzmaProps_Decode - decodes properties
pascal@9240 133 +Returns:
pascal@9240 134 + SZ_OK
pascal@9240 135 + SZ_ERROR_UNSUPPORTED - Unsupported properties
pascal@9240 136 +*/
pascal@9240 137 +
pascal@9240 138 +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
pascal@9240 139 +
pascal@9240 140 +
pascal@9240 141 +/* ---------- LZMA Decoder state ---------- */
pascal@9240 142 +
pascal@9240 143 +/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
pascal@9240 144 + Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
pascal@9240 145 +
pascal@9240 146 +#define LZMA_REQUIRED_INPUT_MAX 20
pascal@9240 147 +
pascal@9240 148 +typedef struct
pascal@9240 149 +{
pascal@9240 150 + CLzmaProps prop;
pascal@9240 151 + UIntLzmaProb *probs;
pascal@9240 152 + const Byte *buf;
pascal@9240 153 + UInt32 range, code;
pascal@9240 154 + Byte *dic;
pascal@9240 155 + UInt32 dicPos;
pascal@9240 156 + UInt32 dicBufSize;
pascal@9240 157 + Byte *inp;
pascal@9240 158 + UInt32 inpPos, inpSize;
pascal@9240 159 + UInt32 inpBufSize;
pascal@9240 160 + UInt32 processedPos;
pascal@9240 161 + UInt32 checkDicSize;
pascal@9240 162 + unsigned state;
pascal@9240 163 + UInt32 reps[4];
pascal@9240 164 + unsigned remainLen;
pascal@9240 165 + int needFlush;
pascal@9240 166 + int needInitState;
pascal@9240 167 + UInt32 numProbs;
pascal@9240 168 + unsigned tempBufSize;
pascal@9240 169 + Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
pascal@9240 170 + UInt64 inpFilePos;
pascal@9240 171 + UInt64 dicFilePos;
pascal@9240 172 + struct {
pascal@9240 173 + UInt64 fmax, fpos;
pascal@9240 174 + } filec, fileu;
pascal@9240 175 +} CLzmaDec;
pascal@9240 176 +
pascal@9240 177 +#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
pascal@9240 178 +
pascal@9240 179 +void LzmaDec_Init(CLzmaDec *p);
pascal@9240 180 +
pascal@9240 181 +/* There are two types of LZMA streams:
pascal@9240 182 + 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
pascal@9240 183 + 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
pascal@9240 184 +
pascal@9240 185 +typedef enum
pascal@9240 186 +{
pascal@9240 187 + LZMA_FINISH_ANY, /* finish at any point */
pascal@9240 188 + LZMA_FINISH_END /* block must be finished at the end */
pascal@9240 189 +} ELzmaFinishMode;
pascal@9240 190 +
pascal@9240 191 +/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
pascal@9240 192 +
pascal@9240 193 + You must use LZMA_FINISH_END, when you know that current output buffer
pascal@9240 194 + covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
pascal@9240 195 +
pascal@9240 196 + If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
pascal@9240 197 + and output value of destLen will be less than output buffer size limit.
pascal@9240 198 + You can check status result also.
pascal@9240 199 +
pascal@9240 200 + You can use multiple checks to test data integrity after full decompression:
pascal@9240 201 + 1) Check Result and "status" variable.
pascal@9240 202 + 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
pascal@9240 203 + 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
pascal@9240 204 + You must use correct finish mode in that case. */
pascal@9240 205 +
pascal@9240 206 +typedef enum
pascal@9240 207 +{
pascal@9240 208 + LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
pascal@9240 209 + LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
pascal@9240 210 + LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
pascal@9240 211 + LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
pascal@9240 212 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
pascal@9240 213 +} ELzmaStatus;
pascal@9240 214 +
pascal@9240 215 +/* ELzmaStatus is used only as output value for function call */
pascal@9240 216 +
pascal@9240 217 +
pascal@9240 218 +/* ---------- Interfaces ---------- */
pascal@9240 219 +
pascal@9240 220 +/* There are 3 levels of interfaces:
pascal@9240 221 + 1) Dictionary Interface
pascal@9240 222 + 2) Buffer Interface
pascal@9240 223 + 3) One Call Interface
pascal@9240 224 + You can select any of these interfaces, but don't mix functions from different
pascal@9240 225 + groups for same object. */
pascal@9240 226 +
pascal@9240 227 +
pascal@9240 228 +/* There are two variants to allocate state for Dictionary Interface:
pascal@9240 229 + 1) LzmaDec_Allocate / LzmaDec_Free
pascal@9240 230 + 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
pascal@9240 231 + You can use variant 2, if you set dictionary buffer manually.
pascal@9240 232 + For Buffer Interface you must always use variant 1.
pascal@9240 233 +
pascal@9240 234 +LzmaDec_Allocate* can return:
pascal@9240 235 + SZ_OK
pascal@9240 236 + SZ_ERROR_MEM - Memory allocation error
pascal@9240 237 + SZ_ERROR_UNSUPPORTED - Unsupported properties
pascal@9240 238 +*/
pascal@9240 239 +
pascal@9240 240 +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
pascal@9240 241 +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
pascal@9240 242 +
pascal@9240 243 +SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
pascal@9240 244 +void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
pascal@9240 245 +
pascal@9240 246 +/* ---------- Dictionary Interface ---------- */
pascal@9240 247 +
pascal@9240 248 +/* You can use it, if you want to eliminate the overhead for data copying from
pascal@9240 249 + dictionary to some other external buffer.
pascal@9240 250 + You must work with CLzmaDec variables directly in this interface.
pascal@9240 251 +
pascal@9240 252 + STEPS:
pascal@9240 253 + LzmaDec_Constr()
pascal@9240 254 + LzmaDec_Allocate()
pascal@9240 255 + for (each new stream)
pascal@9240 256 + {
pascal@9240 257 + LzmaDec_Init()
pascal@9240 258 + while (it needs more decompression)
pascal@9240 259 + {
pascal@9240 260 + LzmaDec_DecodeToDic()
pascal@9240 261 + use data from CLzmaDec::dic and update CLzmaDec::dicPos
pascal@9240 262 + }
pascal@9240 263 + }
pascal@9240 264 + LzmaDec_Free()
pascal@9240 265 +*/
pascal@9240 266 +
pascal@9240 267 +/* LzmaDec_DecodeToDic
pascal@9240 268 +
pascal@9240 269 + The decoding to internal dictionary buffer (CLzmaDec::dic).
pascal@9240 270 + You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
pascal@9240 271 +
pascal@9240 272 +finishMode:
pascal@9240 273 + It has meaning only if the decoding reaches output limit (dicLimit).
pascal@9240 274 + LZMA_FINISH_ANY - Decode just dicLimit bytes.
pascal@9240 275 + LZMA_FINISH_END - Stream must be finished after dicLimit.
pascal@9240 276 +
pascal@9240 277 +Returns:
pascal@9240 278 + SZ_OK
pascal@9240 279 + status:
pascal@9240 280 + LZMA_STATUS_FINISHED_WITH_MARK
pascal@9240 281 + LZMA_STATUS_NOT_FINISHED
pascal@9240 282 + LZMA_STATUS_NEEDS_MORE_INPUT
pascal@9240 283 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
pascal@9240 284 + SZ_ERROR_DATA - Data error
pascal@9240 285 +*/
pascal@9240 286 +
pascal@9240 287 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
pascal@9240 288 + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
pascal@9240 289 +
pascal@9240 290 +
pascal@9240 291 +/* ---------- Buffer Interface ---------- */
pascal@9240 292 +
pascal@9240 293 +/* It's zlib-like interface.
pascal@9240 294 + See LzmaDec_DecodeToDic description for information about STEPS and return results,
pascal@9240 295 + but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
pascal@9240 296 + to work with CLzmaDec variables manually.
pascal@9240 297 +
pascal@9240 298 +finishMode:
pascal@9240 299 + It has meaning only if the decoding reaches output limit (*destLen).
pascal@9240 300 + LZMA_FINISH_ANY - Decode just destLen bytes.
pascal@9240 301 + LZMA_FINISH_END - Stream must be finished after (*destLen).
pascal@9240 302 +*/
pascal@9240 303 +
pascal@9240 304 +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
pascal@9240 305 + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
pascal@9240 306 +
pascal@9240 307 +
pascal@9240 308 +/* ---------- One Call Interface ---------- */
pascal@9240 309 +
pascal@9240 310 +/* LzmaDecode
pascal@9240 311 +
pascal@9240 312 +finishMode:
pascal@9240 313 + It has meaning only if the decoding reaches output limit (*destLen).
pascal@9240 314 + LZMA_FINISH_ANY - Decode just destLen bytes.
pascal@9240 315 + LZMA_FINISH_END - Stream must be finished after (*destLen).
pascal@9240 316 +
pascal@9240 317 +Returns:
pascal@9240 318 + SZ_OK
pascal@9240 319 + status:
pascal@9240 320 + LZMA_STATUS_FINISHED_WITH_MARK
pascal@9240 321 + LZMA_STATUS_NOT_FINISHED
pascal@9240 322 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
pascal@9240 323 + SZ_ERROR_DATA - Data error
pascal@9240 324 + SZ_ERROR_MEM - Memory allocation error
pascal@9240 325 + SZ_ERROR_UNSUPPORTED - Unsupported properties
pascal@9240 326 + SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
pascal@9240 327 +*/
pascal@9240 328 +
pascal@9240 329 +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
pascal@9240 330 + const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
pascal@9240 331 + ELzmaStatus *status, ISzAlloc *alloc);
pascal@9240 332 +
pascal@9240 333 +/* -------------------------------------------------------------------------- */
pascal@9240 334 +
pascal@9240 335 +/* LzmaDec.c -- LZMA Decoder
pascal@9240 336 +2009-09-20 : Igor Pavlov : Public domain */
pascal@9240 337 +
pascal@9240 338 +//#include "LzmaDec.h"
pascal@9240 339 +
pascal@9240 340 +//#include <string.h>
pascal@9240 341 +
pascal@9240 342 +#define kNumTopBits 24
pascal@9240 343 +#define kTopValue ((UInt32)1 << kNumTopBits)
pascal@9240 344 +
pascal@9240 345 +#define kNumBitModelTotalBits 11
pascal@9240 346 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
pascal@9240 347 +#define kNumMoveBits 5
pascal@9240 348 +
pascal@9240 349 +#define RC_INIT_SIZE 5
pascal@9240 350 +
pascal@9240 351 +#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
pascal@9240 352 +
pascal@9240 353 +#define TEST_BIT_0(p) ({ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; (code < bound);})
pascal@9240 354 +#define UPDATE_0(p) range = bound; *(p) = (UIntLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
pascal@9240 355 +#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (UIntLzmaProb)(ttt - (ttt >> kNumMoveBits));
pascal@9240 356 +#define GET_BIT2(p, i, A0, A1) if(TEST_BIT_0(p)) \
pascal@9240 357 + { UPDATE_0(p); i = (i + i); A0; } else \
pascal@9240 358 + { UPDATE_1(p); i = (i + i) + 1; A1; }
pascal@9240 359 +#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
pascal@9240 360 +
pascal@9240 361 +#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
pascal@9240 362 +#define TREE_DECODE(probs, limit, i) \
pascal@9240 363 + { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
pascal@9240 364 +
pascal@9240 365 +/* #define _LZMA_SIZE_OPT */
pascal@9240 366 +
pascal@9240 367 +#ifdef _LZMA_SIZE_OPT
pascal@9240 368 +#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
pascal@9240 369 +#else
pascal@9240 370 +#define TREE_6_DECODE(probs, i) \
pascal@9240 371 + { i = 1; \
pascal@9240 372 + TREE_GET_BIT(probs, i); \
pascal@9240 373 + TREE_GET_BIT(probs, i); \
pascal@9240 374 + TREE_GET_BIT(probs, i); \
pascal@9240 375 + TREE_GET_BIT(probs, i); \
pascal@9240 376 + TREE_GET_BIT(probs, i); \
pascal@9240 377 + TREE_GET_BIT(probs, i); \
pascal@9240 378 + i -= 0x40; }
pascal@9240 379 +#endif
pascal@9240 380 +
pascal@9240 381 +#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
pascal@9240 382 +
pascal@9240 383 +#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
pascal@9240 384 +#define UPDATE_0_CHECK range = bound;
pascal@9240 385 +#define UPDATE_1_CHECK range -= bound; code -= bound;
pascal@9240 386 +#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
pascal@9240 387 + { UPDATE_0_CHECK; i = (i + i); A0; } else \
pascal@9240 388 + { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
pascal@9240 389 +#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
pascal@9240 390 +#define TREE_DECODE_CHECK(probs, limit, i) \
pascal@9240 391 + { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
pascal@9240 392 +
pascal@9240 393 +
pascal@9240 394 +#define kNumPosBitsMax 4
pascal@9240 395 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
pascal@9240 396 +
pascal@9240 397 +#define kLenNumLowBits 3
pascal@9240 398 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
pascal@9240 399 +#define kLenNumMidBits 3
pascal@9240 400 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
pascal@9240 401 +#define kLenNumHighBits 8
pascal@9240 402 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
pascal@9240 403 +
pascal@9240 404 +#define LenChoice 0
pascal@9240 405 +#define LenChoice2 (LenChoice + 1)
pascal@9240 406 +#define LenLow (LenChoice2 + 1)
pascal@9240 407 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
pascal@9240 408 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
pascal@9240 409 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
pascal@9240 410 +
pascal@9240 411 +
pascal@9240 412 +#define kNumStates 12
pascal@9240 413 +#define kNumLitStates 7
pascal@9240 414 +
pascal@9240 415 +#define kStartPosModelIndex 4
pascal@9240 416 +#define kEndPosModelIndex 14
pascal@9240 417 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
pascal@9240 418 +
pascal@9240 419 +#define kNumPosSlotBits 6
pascal@9240 420 +#define kNumLenToPosStates 4
pascal@9240 421 +
pascal@9240 422 +#define kNumAlignBits 4
pascal@9240 423 +#define kAlignTableSize (1 << kNumAlignBits)
pascal@9240 424 +
pascal@9240 425 +#define kMatchMinLen 2
pascal@9240 426 +#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
pascal@9240 427 +
pascal@9240 428 +#define IsMatch 0
pascal@9240 429 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
pascal@9240 430 +#define IsRepG0 (IsRep + kNumStates)
pascal@9240 431 +#define IsRepG1 (IsRepG0 + kNumStates)
pascal@9240 432 +#define IsRepG2 (IsRepG1 + kNumStates)
pascal@9240 433 +#define IsRep0Long (IsRepG2 + kNumStates)
pascal@9240 434 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
pascal@9240 435 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
pascal@9240 436 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
pascal@9240 437 +#define LenCoder (Align + kAlignTableSize)
pascal@9240 438 +#define RepLenCoder (LenCoder + kNumLenProbs)
pascal@9240 439 +#define Literal (RepLenCoder + kNumLenProbs)
pascal@9240 440 +
pascal@9240 441 +#define LZMA_BASE_SIZE 1846
pascal@9240 442 +#define LZMA_LIT_SIZE 768
pascal@9240 443 +
pascal@9240 444 +#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
pascal@9240 445 +
pascal@9240 446 +#if Literal != LZMA_BASE_SIZE
pascal@9240 447 +StopCompilingDueBUG
pascal@9240 448 +#endif
pascal@9240 449 +
pascal@9240 450 +#define LZMA_DIC_MIN (1 << 12)
pascal@9240 451 +
pascal@9240 452 +/* First LZMA-symbol is always decoded.
pascal@9240 453 +And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
pascal@9240 454 +Out:
pascal@9240 455 + Result:
pascal@9240 456 + SZ_OK - OK
pascal@9240 457 + SZ_ERROR_DATA - Error
pascal@9240 458 + p->remainLen:
pascal@9240 459 + < kMatchSpecLenStart : normal remain
pascal@9240 460 + = kMatchSpecLenStart : finished
pascal@9240 461 + = kMatchSpecLenStart + 1 : Flush marker
pascal@9240 462 + = kMatchSpecLenStart + 2 : State Init Marker
pascal@9240 463 +*/
pascal@9240 464 +
pascal@9240 465 +static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
pascal@9240 466 +{
pascal@9240 467 + UIntLzmaProb *probs = p->probs;
pascal@9240 468 +
pascal@9240 469 + unsigned state = p->state;
pascal@9240 470 + UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
pascal@9240 471 + unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
pascal@9240 472 + unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
pascal@9240 473 + unsigned lc = p->prop.lc;
pascal@9240 474 +
pascal@9240 475 + Byte *dic = p->dic;
pascal@9240 476 + SizeT dicBufSize = p->dicBufSize;
pascal@9240 477 + SizeT dicPos = p->dicPos;
pascal@9240 478 +
pascal@9240 479 + UInt32 processedPos = p->processedPos;
pascal@9240 480 + UInt32 checkDicSize = p->checkDicSize;
pascal@9240 481 + unsigned len = 0;
pascal@9240 482 +
pascal@9240 483 + const Byte *buf = p->buf;
pascal@9240 484 + UInt32 range = p->range;
pascal@9240 485 + UInt32 code = p->code;
pascal@9240 486 +
pascal@9240 487 + do
pascal@9240 488 + {
pascal@9240 489 + UIntLzmaProb *prob;
pascal@9240 490 + UInt32 bound;
pascal@9240 491 + unsigned ttt;
pascal@9240 492 + unsigned posState = processedPos & pbMask;
pascal@9240 493 +
pascal@9240 494 + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
pascal@9240 495 + if(TEST_BIT_0(prob))
pascal@9240 496 + {
pascal@9240 497 + unsigned symbol;
pascal@9240 498 + UPDATE_0(prob);
pascal@9240 499 + prob = probs + Literal;
pascal@9240 500 + if (checkDicSize != 0 || processedPos != 0)
pascal@9240 501 + prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
pascal@9240 502 + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
pascal@9240 503 +
pascal@9240 504 + if (state < kNumLitStates)
pascal@9240 505 + {
pascal@9240 506 + state -= (state < 4) ? state : 3;
pascal@9240 507 + symbol = 1;
pascal@9240 508 + do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
pascal@9240 509 + }
pascal@9240 510 + else
pascal@9240 511 + {
pascal@9240 512 + unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
pascal@9240 513 + unsigned offs = 0x100;
pascal@9240 514 + state -= (state < 10) ? 3 : 6;
pascal@9240 515 + symbol = 1;
pascal@9240 516 + do
pascal@9240 517 + {
pascal@9240 518 + unsigned bit;
pascal@9240 519 + UIntLzmaProb *probLit;
pascal@9240 520 + matchByte <<= 1;
pascal@9240 521 + bit = (matchByte & offs);
pascal@9240 522 + probLit = prob + offs + bit + symbol;
pascal@9240 523 + GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
pascal@9240 524 + }
pascal@9240 525 + while (symbol < 0x100);
pascal@9240 526 + }
pascal@9240 527 + dic[dicPos++] = (Byte)symbol;
pascal@9240 528 + processedPos++;
pascal@9240 529 + continue;
pascal@9240 530 + }
pascal@9240 531 + else
pascal@9240 532 + {
pascal@9240 533 + UPDATE_1(prob);
pascal@9240 534 + prob = probs + IsRep + state;
pascal@9240 535 + if(TEST_BIT_0(prob))
pascal@9240 536 + {
pascal@9240 537 + UPDATE_0(prob);
pascal@9240 538 + state += kNumStates;
pascal@9240 539 + prob = probs + LenCoder;
pascal@9240 540 + }
pascal@9240 541 + else
pascal@9240 542 + {
pascal@9240 543 + UPDATE_1(prob);
pascal@9240 544 + if (checkDicSize == 0 && processedPos == 0)
pascal@9240 545 + return SZ_ERROR_DATA;
pascal@9240 546 + prob = probs + IsRepG0 + state;
pascal@9240 547 + if(TEST_BIT_0(prob))
pascal@9240 548 + {
pascal@9240 549 + UPDATE_0(prob);
pascal@9240 550 + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
pascal@9240 551 + if(TEST_BIT_0(prob))
pascal@9240 552 + {
pascal@9240 553 + UPDATE_0(prob);
pascal@9240 554 + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
pascal@9240 555 + dicPos++;
pascal@9240 556 + processedPos++;
pascal@9240 557 + state = state < kNumLitStates ? 9 : 11;
pascal@9240 558 + continue;
pascal@9240 559 + }
pascal@9240 560 + UPDATE_1(prob);
pascal@9240 561 + }
pascal@9240 562 + else
pascal@9240 563 + {
pascal@9240 564 + UInt32 distance;
pascal@9240 565 + UPDATE_1(prob);
pascal@9240 566 + prob = probs + IsRepG1 + state;
pascal@9240 567 + if(TEST_BIT_0(prob))
pascal@9240 568 + {
pascal@9240 569 + UPDATE_0(prob);
pascal@9240 570 + distance = rep1;
pascal@9240 571 + }
pascal@9240 572 + else
pascal@9240 573 + {
pascal@9240 574 + UPDATE_1(prob);
pascal@9240 575 + prob = probs + IsRepG2 + state;
pascal@9240 576 + if(TEST_BIT_0(prob))
pascal@9240 577 + {
pascal@9240 578 + UPDATE_0(prob);
pascal@9240 579 + distance = rep2;
pascal@9240 580 + }
pascal@9240 581 + else
pascal@9240 582 + {
pascal@9240 583 + UPDATE_1(prob);
pascal@9240 584 + distance = rep3;
pascal@9240 585 + rep3 = rep2;
pascal@9240 586 + }
pascal@9240 587 + rep2 = rep1;
pascal@9240 588 + }
pascal@9240 589 + rep1 = rep0;
pascal@9240 590 + rep0 = distance;
pascal@9240 591 + }
pascal@9240 592 + state = state < kNumLitStates ? 8 : 11;
pascal@9240 593 + prob = probs + RepLenCoder;
pascal@9240 594 + }
pascal@9240 595 + {
pascal@9240 596 + unsigned limit, offset;
pascal@9240 597 + UIntLzmaProb *probLen = prob + LenChoice;
pascal@9240 598 + if(TEST_BIT_0(probLen))
pascal@9240 599 + {
pascal@9240 600 + UPDATE_0(probLen);
pascal@9240 601 + probLen = prob + LenLow + (posState << kLenNumLowBits);
pascal@9240 602 + offset = 0;
pascal@9240 603 + limit = (1 << kLenNumLowBits);
pascal@9240 604 + }
pascal@9240 605 + else
pascal@9240 606 + {
pascal@9240 607 + UPDATE_1(probLen);
pascal@9240 608 + probLen = prob + LenChoice2;
pascal@9240 609 + if(TEST_BIT_0(probLen))
pascal@9240 610 + {
pascal@9240 611 + UPDATE_0(probLen);
pascal@9240 612 + probLen = prob + LenMid + (posState << kLenNumMidBits);
pascal@9240 613 + offset = kLenNumLowSymbols;
pascal@9240 614 + limit = (1 << kLenNumMidBits);
pascal@9240 615 + }
pascal@9240 616 + else
pascal@9240 617 + {
pascal@9240 618 + UPDATE_1(probLen);
pascal@9240 619 + probLen = prob + LenHigh;
pascal@9240 620 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
pascal@9240 621 + limit = (1 << kLenNumHighBits);
pascal@9240 622 + }
pascal@9240 623 + }
pascal@9240 624 + TREE_DECODE(probLen, limit, len);
pascal@9240 625 + len += offset;
pascal@9240 626 + }
pascal@9240 627 +
pascal@9240 628 + if (state >= kNumStates)
pascal@9240 629 + {
pascal@9240 630 + UInt32 distance;
pascal@9240 631 + prob = probs + PosSlot +
pascal@9240 632 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
pascal@9240 633 + TREE_6_DECODE(prob, distance);
pascal@9240 634 + if (distance >= kStartPosModelIndex)
pascal@9240 635 + {
pascal@9240 636 + unsigned posSlot = (unsigned)distance;
pascal@9240 637 + int numDirectBits = (int)(((distance >> 1) - 1));
pascal@9240 638 + distance = (2 | (distance & 1));
pascal@9240 639 + if (posSlot < kEndPosModelIndex)
pascal@9240 640 + {
pascal@9240 641 + distance <<= numDirectBits;
pascal@9240 642 + prob = probs + SpecPos + distance - posSlot - 1;
pascal@9240 643 + {
pascal@9240 644 + UInt32 mask = 1;
pascal@9240 645 + unsigned i = 1;
pascal@9240 646 + do
pascal@9240 647 + {
pascal@9240 648 + GET_BIT2(prob + i, i, ; , distance |= mask);
pascal@9240 649 + mask <<= 1;
pascal@9240 650 + }
pascal@9240 651 + while (--numDirectBits != 0);
pascal@9240 652 + }
pascal@9240 653 + }
pascal@9240 654 + else
pascal@9240 655 + {
pascal@9240 656 + numDirectBits -= kNumAlignBits;
pascal@9240 657 + do
pascal@9240 658 + {
pascal@9240 659 + NORMALIZE
pascal@9240 660 + range >>= 1;
pascal@9240 661 +
pascal@9240 662 + {
pascal@9240 663 + UInt32 t;
pascal@9240 664 + code -= range;
pascal@9240 665 + t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
pascal@9240 666 + distance = (distance << 1) + (t + 1);
pascal@9240 667 + code += range & t;
pascal@9240 668 + }
pascal@9240 669 + /*
pascal@9240 670 + distance <<= 1;
pascal@9240 671 + if (code >= range)
pascal@9240 672 + {
pascal@9240 673 + code -= range;
pascal@9240 674 + distance |= 1;
pascal@9240 675 + }
pascal@9240 676 + */
pascal@9240 677 + }
pascal@9240 678 + while (--numDirectBits != 0);
pascal@9240 679 + prob = probs + Align;
pascal@9240 680 + distance <<= kNumAlignBits;
pascal@9240 681 + {
pascal@9240 682 + unsigned i = 1;
pascal@9240 683 + GET_BIT2(prob + i, i, ; , distance |= 1);
pascal@9240 684 + GET_BIT2(prob + i, i, ; , distance |= 2);
pascal@9240 685 + GET_BIT2(prob + i, i, ; , distance |= 4);
pascal@9240 686 + GET_BIT2(prob + i, i, ; , distance |= 8);
pascal@9240 687 + }
pascal@9240 688 + if (distance == (UInt32)0xFFFFFFFF)
pascal@9240 689 + {
pascal@9240 690 + len += kMatchSpecLenStart;
pascal@9240 691 + state -= kNumStates;
pascal@9240 692 + break;
pascal@9240 693 + }
pascal@9240 694 + }
pascal@9240 695 + }
pascal@9240 696 + rep3 = rep2;
pascal@9240 697 + rep2 = rep1;
pascal@9240 698 + rep1 = rep0;
pascal@9240 699 + rep0 = distance + 1;
pascal@9240 700 + if (checkDicSize == 0)
pascal@9240 701 + {
pascal@9240 702 + if (distance >= processedPos)
pascal@9240 703 + return SZ_ERROR_DATA;
pascal@9240 704 + }
pascal@9240 705 + else if (distance >= checkDicSize)
pascal@9240 706 + return SZ_ERROR_DATA;
pascal@9240 707 + state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
pascal@9240 708 + }
pascal@9240 709 +
pascal@9240 710 + len += kMatchMinLen;
pascal@9240 711 +
pascal@9240 712 + if (limit == dicPos)
pascal@9240 713 + return SZ_ERROR_DATA;
pascal@9240 714 + {
pascal@9240 715 + SizeT rem = limit - dicPos;
pascal@9240 716 + unsigned curLen = ((rem < len) ? (unsigned)rem : len);
pascal@9240 717 + SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
pascal@9240 718 +
pascal@9240 719 + processedPos += curLen;
pascal@9240 720 +
pascal@9240 721 + len -= curLen;
pascal@9240 722 + if (pos + curLen <= dicBufSize)
pascal@9240 723 + {
pascal@9240 724 + Byte *dest = dic + dicPos;
pascal@9240 725 + ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
pascal@9240 726 + const Byte *lim = dest + curLen;
pascal@9240 727 + dicPos += curLen;
pascal@9240 728 + do
pascal@9240 729 + *(dest) = (Byte)(*(dest + src));
pascal@9240 730 + while (++dest != lim);
pascal@9240 731 + }
pascal@9240 732 + else
pascal@9240 733 + {
pascal@9240 734 + do
pascal@9240 735 + {
pascal@9240 736 + dic[dicPos++] = dic[pos];
pascal@9240 737 + if (++pos == dicBufSize)
pascal@9240 738 + pos = 0;
pascal@9240 739 + }
pascal@9240 740 + while (--curLen != 0);
pascal@9240 741 + }
pascal@9240 742 + }
pascal@9240 743 + }
pascal@9240 744 + }
pascal@9240 745 + while (dicPos < limit && buf < bufLimit);
pascal@9240 746 + NORMALIZE;
pascal@9240 747 + p->buf = buf;
pascal@9240 748 + p->range = range;
pascal@9240 749 + p->code = code;
pascal@9240 750 + p->remainLen = len;
pascal@9240 751 + p->dicPos = dicPos;
pascal@9240 752 + p->processedPos = processedPos;
pascal@9240 753 + p->reps[0] = rep0;
pascal@9240 754 + p->reps[1] = rep1;
pascal@9240 755 + p->reps[2] = rep2;
pascal@9240 756 + p->reps[3] = rep3;
pascal@9240 757 + p->state = state;
pascal@9240 758 +
pascal@9240 759 + return SZ_OK;
pascal@9240 760 +}
pascal@9240 761 +
pascal@9240 762 +static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
pascal@9240 763 +{
pascal@9240 764 + if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
pascal@9240 765 + {
pascal@9240 766 + Byte *dic = p->dic;
pascal@9240 767 + SizeT dicPos = p->dicPos;
pascal@9240 768 + SizeT dicBufSize = p->dicBufSize;
pascal@9240 769 + unsigned len = p->remainLen;
pascal@9240 770 + UInt32 rep0 = p->reps[0];
pascal@9240 771 + if (limit - dicPos < len)
pascal@9240 772 + len = (unsigned)(limit - dicPos);
pascal@9240 773 +
pascal@9240 774 + if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
pascal@9240 775 + p->checkDicSize = p->prop.dicSize;
pascal@9240 776 +
pascal@9240 777 + p->processedPos += len;
pascal@9240 778 + p->remainLen -= len;
pascal@9240 779 + while (len-- != 0)
pascal@9240 780 + {
pascal@9240 781 + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
pascal@9240 782 + dicPos++;
pascal@9240 783 + }
pascal@9240 784 + p->dicPos = dicPos;
pascal@9240 785 + }
pascal@9240 786 +}
pascal@9240 787 +
pascal@9240 788 +static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
pascal@9240 789 +{
pascal@9240 790 + do
pascal@9240 791 + {
pascal@9240 792 + SizeT limit2 = limit;
pascal@9240 793 + if (p->checkDicSize == 0)
pascal@9240 794 + {
pascal@9240 795 + UInt32 rem = p->prop.dicSize - p->processedPos;
pascal@9240 796 + if (limit - p->dicPos > rem)
pascal@9240 797 + limit2 = p->dicPos + rem;
pascal@9240 798 + }
pascal@9240 799 + RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
pascal@9240 800 + if (p->processedPos >= p->prop.dicSize)
pascal@9240 801 + p->checkDicSize = p->prop.dicSize;
pascal@9240 802 + LzmaDec_WriteRem(p, limit);
pascal@9240 803 + }
pascal@9240 804 + while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
pascal@9240 805 +
pascal@9240 806 + if (p->remainLen > kMatchSpecLenStart)
pascal@9240 807 + {
pascal@9240 808 + p->remainLen = kMatchSpecLenStart;
pascal@9240 809 + }
pascal@9240 810 + return 0;
pascal@9240 811 +}
pascal@9240 812 +
pascal@9240 813 +typedef enum
pascal@9240 814 +{
pascal@9240 815 + DUMMY_ERROR, /* unexpected end of input stream */
pascal@9240 816 + DUMMY_LIT,
pascal@9240 817 + DUMMY_MATCH,
pascal@9240 818 + DUMMY_REP
pascal@9240 819 +} ELzmaDummy;
pascal@9240 820 +
pascal@9240 821 +static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
pascal@9240 822 +{
pascal@9240 823 + UInt32 range = p->range;
pascal@9240 824 + UInt32 code = p->code;
pascal@9240 825 + const Byte *bufLimit = buf + inSize;
pascal@9240 826 + UIntLzmaProb *probs = p->probs;
pascal@9240 827 + unsigned state = p->state;
pascal@9240 828 + ELzmaDummy res;
pascal@9240 829 +
pascal@9240 830 + {
pascal@9240 831 + UIntLzmaProb *prob;
pascal@9240 832 + UInt32 bound;
pascal@9240 833 + unsigned ttt;
pascal@9240 834 + unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
pascal@9240 835 +
pascal@9240 836 + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
pascal@9240 837 + IF_BIT_0_CHECK(prob)
pascal@9240 838 + {
pascal@9240 839 + UPDATE_0_CHECK
pascal@9240 840 +
pascal@9240 841 + /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
pascal@9240 842 +
pascal@9240 843 + prob = probs + Literal;
pascal@9240 844 + if (p->checkDicSize != 0 || p->processedPos != 0)
pascal@9240 845 + prob += (LZMA_LIT_SIZE *
pascal@9240 846 + ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
pascal@9240 847 + (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
pascal@9240 848 +
pascal@9240 849 + if (state < kNumLitStates)
pascal@9240 850 + {
pascal@9240 851 + unsigned symbol = 1;
pascal@9240 852 + do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
pascal@9240 853 + }
pascal@9240 854 + else
pascal@9240 855 + {
pascal@9240 856 + unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
pascal@9240 857 + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
pascal@9240 858 + unsigned offs = 0x100;
pascal@9240 859 + unsigned symbol = 1;
pascal@9240 860 + do
pascal@9240 861 + {
pascal@9240 862 + unsigned bit;
pascal@9240 863 + UIntLzmaProb *probLit;
pascal@9240 864 + matchByte <<= 1;
pascal@9240 865 + bit = (matchByte & offs);
pascal@9240 866 + probLit = prob + offs + bit + symbol;
pascal@9240 867 + GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
pascal@9240 868 + }
pascal@9240 869 + while (symbol < 0x100);
pascal@9240 870 + }
pascal@9240 871 + res = DUMMY_LIT;
pascal@9240 872 + }
pascal@9240 873 + else
pascal@9240 874 + {
pascal@9240 875 + unsigned len;
pascal@9240 876 + UPDATE_1_CHECK;
pascal@9240 877 +
pascal@9240 878 + prob = probs + IsRep + state;
pascal@9240 879 + IF_BIT_0_CHECK(prob)
pascal@9240 880 + {
pascal@9240 881 + UPDATE_0_CHECK;
pascal@9240 882 + state = 0;
pascal@9240 883 + prob = probs + LenCoder;
pascal@9240 884 + res = DUMMY_MATCH;
pascal@9240 885 + }
pascal@9240 886 + else
pascal@9240 887 + {
pascal@9240 888 + UPDATE_1_CHECK;
pascal@9240 889 + res = DUMMY_REP;
pascal@9240 890 + prob = probs + IsRepG0 + state;
pascal@9240 891 + IF_BIT_0_CHECK(prob)
pascal@9240 892 + {
pascal@9240 893 + UPDATE_0_CHECK;
pascal@9240 894 + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
pascal@9240 895 + IF_BIT_0_CHECK(prob)
pascal@9240 896 + {
pascal@9240 897 + UPDATE_0_CHECK;
pascal@9240 898 + NORMALIZE_CHECK;
pascal@9240 899 + return DUMMY_REP;
pascal@9240 900 + }
pascal@9240 901 + else
pascal@9240 902 + {
pascal@9240 903 + UPDATE_1_CHECK;
pascal@9240 904 + }
pascal@9240 905 + }
pascal@9240 906 + else
pascal@9240 907 + {
pascal@9240 908 + UPDATE_1_CHECK;
pascal@9240 909 + prob = probs + IsRepG1 + state;
pascal@9240 910 + IF_BIT_0_CHECK(prob)
pascal@9240 911 + {
pascal@9240 912 + UPDATE_0_CHECK;
pascal@9240 913 + }
pascal@9240 914 + else
pascal@9240 915 + {
pascal@9240 916 + UPDATE_1_CHECK;
pascal@9240 917 + prob = probs + IsRepG2 + state;
pascal@9240 918 + IF_BIT_0_CHECK(prob)
pascal@9240 919 + {
pascal@9240 920 + UPDATE_0_CHECK;
pascal@9240 921 + }
pascal@9240 922 + else
pascal@9240 923 + {
pascal@9240 924 + UPDATE_1_CHECK;
pascal@9240 925 + }
pascal@9240 926 + }
pascal@9240 927 + }
pascal@9240 928 + state = kNumStates;
pascal@9240 929 + prob = probs + RepLenCoder;
pascal@9240 930 + }
pascal@9240 931 + {
pascal@9240 932 + unsigned limit, offset;
pascal@9240 933 + UIntLzmaProb *probLen = prob + LenChoice;
pascal@9240 934 + IF_BIT_0_CHECK(probLen)
pascal@9240 935 + {
pascal@9240 936 + UPDATE_0_CHECK;
pascal@9240 937 + probLen = prob + LenLow + (posState << kLenNumLowBits);
pascal@9240 938 + offset = 0;
pascal@9240 939 + limit = 1 << kLenNumLowBits;
pascal@9240 940 + }
pascal@9240 941 + else
pascal@9240 942 + {
pascal@9240 943 + UPDATE_1_CHECK;
pascal@9240 944 + probLen = prob + LenChoice2;
pascal@9240 945 + IF_BIT_0_CHECK(probLen)
pascal@9240 946 + {
pascal@9240 947 + UPDATE_0_CHECK;
pascal@9240 948 + probLen = prob + LenMid + (posState << kLenNumMidBits);
pascal@9240 949 + offset = kLenNumLowSymbols;
pascal@9240 950 + limit = 1 << kLenNumMidBits;
pascal@9240 951 + }
pascal@9240 952 + else
pascal@9240 953 + {
pascal@9240 954 + UPDATE_1_CHECK;
pascal@9240 955 + probLen = prob + LenHigh;
pascal@9240 956 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
pascal@9240 957 + limit = 1 << kLenNumHighBits;
pascal@9240 958 + }
pascal@9240 959 + }
pascal@9240 960 + TREE_DECODE_CHECK(probLen, limit, len);
pascal@9240 961 + len += offset;
pascal@9240 962 + }
pascal@9240 963 +
pascal@9240 964 + if (state < 4)
pascal@9240 965 + {
pascal@9240 966 + unsigned posSlot;
pascal@9240 967 + prob = probs + PosSlot +
pascal@9240 968 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
pascal@9240 969 + kNumPosSlotBits);
pascal@9240 970 + TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
pascal@9240 971 + if (posSlot >= kStartPosModelIndex)
pascal@9240 972 + {
pascal@9240 973 + int numDirectBits = ((posSlot >> 1) - 1);
pascal@9240 974 +
pascal@9240 975 + /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
pascal@9240 976 +
pascal@9240 977 + if (posSlot < kEndPosModelIndex)
pascal@9240 978 + {
pascal@9240 979 + prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
pascal@9240 980 + }
pascal@9240 981 + else
pascal@9240 982 + {
pascal@9240 983 + numDirectBits -= kNumAlignBits;
pascal@9240 984 + do
pascal@9240 985 + {
pascal@9240 986 + NORMALIZE_CHECK
pascal@9240 987 + range >>= 1;
pascal@9240 988 + code -= range & (((code - range) >> 31) - 1);
pascal@9240 989 + /* if (code >= range) code -= range; */
pascal@9240 990 + }
pascal@9240 991 + while (--numDirectBits != 0);
pascal@9240 992 + prob = probs + Align;
pascal@9240 993 + numDirectBits = kNumAlignBits;
pascal@9240 994 + }
pascal@9240 995 + {
pascal@9240 996 + unsigned i = 1;
pascal@9240 997 + do
pascal@9240 998 + {
pascal@9240 999 + GET_BIT_CHECK(prob + i, i);
pascal@9240 1000 + }
pascal@9240 1001 + while (--numDirectBits != 0);
pascal@9240 1002 + }
pascal@9240 1003 + }
pascal@9240 1004 + }
pascal@9240 1005 + }
pascal@9240 1006 + }
pascal@9240 1007 + NORMALIZE_CHECK;
pascal@9240 1008 + return res;
pascal@9240 1009 +}
pascal@9240 1010 +
pascal@9240 1011 +
pascal@9240 1012 +static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
pascal@9240 1013 +{
pascal@9240 1014 + p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
pascal@9240 1015 + p->range = 0xFFFFFFFF;
pascal@9240 1016 + p->needFlush = 0;
pascal@9240 1017 +}
pascal@9240 1018 +
pascal@9240 1019 +void LzmaDec_Init(CLzmaDec *p)
pascal@9240 1020 +{
pascal@9240 1021 + p->dicFilePos = 0;
pascal@9240 1022 + p->dicPos = 0;
pascal@9240 1023 + p->needFlush = 1;
pascal@9240 1024 + p->remainLen = 0;
pascal@9240 1025 + p->tempBufSize = 0;
pascal@9240 1026 + p->processedPos = 0;
pascal@9240 1027 + p->checkDicSize = 0;
pascal@9240 1028 + p->needInitState = 1;
pascal@9240 1029 + p->needInitState = 1;
pascal@9240 1030 +}
pascal@9240 1031 +
pascal@9240 1032 +static void LzmaDec_InitStateReal(CLzmaDec *p)
pascal@9240 1033 +{
pascal@9240 1034 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
pascal@9240 1035 + UInt32 i;
pascal@9240 1036 + UIntLzmaProb *probs = p->probs;
pascal@9240 1037 + for (i = 0; i < numProbs; i++)
pascal@9240 1038 + probs[i] = kBitModelTotal >> 1;
pascal@9240 1039 + p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
pascal@9240 1040 + p->state = 0;
pascal@9240 1041 + p->needInitState = 0;
pascal@9240 1042 +}
pascal@9240 1043 +
pascal@9240 1044 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
pascal@9240 1045 + ELzmaFinishMode finishMode, ELzmaStatus *status)
pascal@9240 1046 +{
pascal@9240 1047 + SizeT inSize = *srcLen;
pascal@9240 1048 + (*srcLen) = 0;
pascal@9240 1049 + LzmaDec_WriteRem(p, dicLimit);
pascal@9240 1050 +
pascal@9240 1051 + *status = LZMA_STATUS_NOT_SPECIFIED;
pascal@9240 1052 +
pascal@9240 1053 + while (p->remainLen != kMatchSpecLenStart)
pascal@9240 1054 + {
pascal@9240 1055 + int checkEndMarkNow;
pascal@9240 1056 +
pascal@9240 1057 + if (p->needFlush != 0)
pascal@9240 1058 + {
pascal@9240 1059 + for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
pascal@9240 1060 + p->tempBuf[p->tempBufSize++] = *src++;
pascal@9240 1061 + if (p->tempBufSize < RC_INIT_SIZE)
pascal@9240 1062 + {
pascal@9240 1063 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
pascal@9240 1064 + return SZ_OK;
pascal@9240 1065 + }
pascal@9240 1066 + if (p->tempBuf[0] != 0)
pascal@9240 1067 + return SZ_ERROR_DATA;
pascal@9240 1068 +
pascal@9240 1069 + LzmaDec_InitRc(p, p->tempBuf);
pascal@9240 1070 + p->tempBufSize = 0;
pascal@9240 1071 + }
pascal@9240 1072 +
pascal@9240 1073 + checkEndMarkNow = 0;
pascal@9240 1074 + if (p->dicPos >= dicLimit)
pascal@9240 1075 + {
pascal@9240 1076 + if (p->remainLen == 0 && p->code == 0)
pascal@9240 1077 + {
pascal@9240 1078 + *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
pascal@9240 1079 + return SZ_OK;
pascal@9240 1080 + }
pascal@9240 1081 + if (finishMode == LZMA_FINISH_ANY)
pascal@9240 1082 + {
pascal@9240 1083 + *status = LZMA_STATUS_NOT_FINISHED;
pascal@9240 1084 + return SZ_OK;
pascal@9240 1085 + }
pascal@9240 1086 + if (p->remainLen != 0)
pascal@9240 1087 + {
pascal@9240 1088 + *status = LZMA_STATUS_NOT_FINISHED;
pascal@9240 1089 + return SZ_ERROR_DATA;
pascal@9240 1090 + }
pascal@9240 1091 + checkEndMarkNow = 1;
pascal@9240 1092 + }
pascal@9240 1093 +
pascal@9240 1094 + if (p->needInitState)
pascal@9240 1095 + LzmaDec_InitStateReal(p);
pascal@9240 1096 +
pascal@9240 1097 + if (p->tempBufSize == 0)
pascal@9240 1098 + {
pascal@9240 1099 + SizeT processed;
pascal@9240 1100 + const Byte *bufLimit;
pascal@9240 1101 + if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
pascal@9240 1102 + {
pascal@9240 1103 + int dummyRes = LzmaDec_TryDummy(p, src, inSize);
pascal@9240 1104 + if (dummyRes == DUMMY_ERROR)
pascal@9240 1105 + {
pascal@9240 1106 + memcpy(p->tempBuf, src, inSize);
pascal@9240 1107 + p->tempBufSize = (unsigned)inSize;
pascal@9240 1108 + (*srcLen) += inSize;
pascal@9240 1109 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
pascal@9240 1110 + return SZ_OK;
pascal@9240 1111 + }
pascal@9240 1112 + if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
pascal@9240 1113 + {
pascal@9240 1114 + *status = LZMA_STATUS_NOT_FINISHED;
pascal@9240 1115 + return SZ_ERROR_DATA;
pascal@9240 1116 + }
pascal@9240 1117 + bufLimit = src;
pascal@9240 1118 + }
pascal@9240 1119 + else
pascal@9240 1120 + bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
pascal@9240 1121 + p->buf = src;
pascal@9240 1122 + if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
pascal@9240 1123 + return SZ_ERROR_DATA;
pascal@9240 1124 + processed = (SizeT)(p->buf - src);
pascal@9240 1125 + (*srcLen) += processed;
pascal@9240 1126 + src += processed;
pascal@9240 1127 + inSize -= processed;
pascal@9240 1128 + }
pascal@9240 1129 + else
pascal@9240 1130 + {
pascal@9240 1131 + unsigned rem = p->tempBufSize, lookAhead = 0;
pascal@9240 1132 + while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
pascal@9240 1133 + p->tempBuf[rem++] = src[lookAhead++];
pascal@9240 1134 + p->tempBufSize = rem;
pascal@9240 1135 + if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
pascal@9240 1136 + {
pascal@9240 1137 + int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
pascal@9240 1138 + if (dummyRes == DUMMY_ERROR)
pascal@9240 1139 + {
pascal@9240 1140 + (*srcLen) += lookAhead;
pascal@9240 1141 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
pascal@9240 1142 + return SZ_OK;
pascal@9240 1143 + }
pascal@9240 1144 + if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
pascal@9240 1145 + {
pascal@9240 1146 + *status = LZMA_STATUS_NOT_FINISHED;
pascal@9240 1147 + return SZ_ERROR_DATA;
pascal@9240 1148 + }
pascal@9240 1149 + }
pascal@9240 1150 + p->buf = p->tempBuf;
pascal@9240 1151 + if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
pascal@9240 1152 + return SZ_ERROR_DATA;
pascal@9240 1153 + lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
pascal@9240 1154 + (*srcLen) += lookAhead;
pascal@9240 1155 + src += lookAhead;
pascal@9240 1156 + inSize -= lookAhead;
pascal@9240 1157 + p->tempBufSize = 0;
pascal@9240 1158 + }
pascal@9240 1159 + }
pascal@9240 1160 + if (p->code == 0)
pascal@9240 1161 + *status = LZMA_STATUS_FINISHED_WITH_MARK;
pascal@9240 1162 + return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
pascal@9240 1163 +}
pascal@9240 1164 +
pascal@9240 1165 +/* -------------------------------------------------------------------------- */
pascal@9240 1166 +
pascal@9240 1167 +#define ReadUnalignedUInt32(p) ((UInt32)((Byte*)(p))[0] | ((UInt32)((Byte*)(p))[1]<<8) | ((UInt32)((Byte*)(p))[2]<<16) | ((UInt32)((Byte*)(p))[3]<<24))
pascal@9240 1168 +#define ReadUnalignedUInt64(p) (ReadUnalignedUInt32(p) | ((UInt64)ReadUnalignedUInt32((Byte*)(p)+4)<<32))
pascal@9240 1169 +
pascal@9240 1170 +CLzmaDec lzmadec;
pascal@9240 1171 +
pascal@9240 1172 +static unsigned long malloc_top = 0;
pascal@9240 1173 +static void *grub_malloc(unsigned long size)
pascal@9240 1174 +{
pascal@9240 1175 + if (!malloc_top)
pascal@9240 1176 + malloc_top = RAW_ADDR ((saved_mem_upper << 10) + 0x100000);
pascal@9240 1177 + malloc_top = (malloc_top - size) & ~3;
pascal@9240 1178 + return (void *) malloc_top;
pascal@9240 1179 +}
pascal@9240 1180 +#define grub_free(x)
pascal@9240 1181 +
pascal@9240 1182 +int
pascal@9240 1183 +dec_lzma_open (void)
pascal@9240 1184 +// return 1=success or 0=failure
pascal@9240 1185 +{
pascal@9240 1186 + unsigned char header[13];
pascal@9240 1187 + unsigned char d;
pascal@9240 1188 +
pascal@9240 1189 + if (no_decompression) return 0;
pascal@9240 1190 +
pascal@9240 1191 + // Now it does not support openning more than 1 file at a time.
pascal@9240 1192 + // Make sure previously allocated memory blocks is freed.
pascal@9240 1193 + // Don't need this line if grub_close is called for every openned file before grub_open is called for next file.
pascal@9240 1194 + dec_lzma_close();
pascal@9240 1195 +
pascal@9240 1196 + filepos = 0;
pascal@9240 1197 + if (grub_read ((char *)header, 13, 0xedde0d90) == 13)
pascal@9240 1198 + {
pascal@9240 1199 + // check header
pascal@9240 1200 + lzmadec.prop.dicSize = ReadUnalignedUInt32(header+1);
pascal@9240 1201 + if (lzmadec.prop.dicSize < LZMA_DIC_MIN)
pascal@9240 1202 + lzmadec.prop.dicSize = LZMA_DIC_MIN;
pascal@9240 1203 + d = header[0];
pascal@9240 1204 + if (d < 9*5*5)
pascal@9240 1205 + {
pascal@9240 1206 + // valid LZMA file
pascal@9240 1207 + lzmadec.prop.lc = d % 9; d /= 9;
pascal@9240 1208 + lzmadec.prop.lp = d % 5;
pascal@9240 1209 + lzmadec.prop.pb = d / 5;
pascal@9240 1210 + lzmadec.fileu.fmax = ReadUnalignedUInt64(header+5);
pascal@9240 1211 + lzmadec.fileu.fpos = 0;
pascal@9240 1212 + lzmadec.dicBufSize = lzmadec.prop.dicSize;
pascal@9240 1213 + lzmadec.dic = (Byte*) grub_malloc(lzmadec.dicBufSize);
pascal@9240 1214 + //grub_printf("LZMA allocate memory\n");
pascal@9240 1215 + if (lzmadec.dic)
pascal@9240 1216 + {
pascal@9240 1217 + lzmadec.numProbs = LzmaProps_GetNumProbs(&lzmadec.prop);
pascal@9240 1218 + lzmadec.probs = (UIntLzmaProb *) grub_malloc(lzmadec.numProbs * sizeof(UIntLzmaProb));
pascal@9240 1219 + if (lzmadec.probs)
pascal@9240 1220 + {
pascal@9240 1221 + lzmadec.inpBufSize = 0x8000;
pascal@9240 1222 + lzmadec.inp = (Byte*) grub_malloc(lzmadec.inpBufSize);
pascal@9240 1223 + if (lzmadec.inp)
pascal@9240 1224 + {
pascal@9240 1225 + lzmadec.inpFilePos = 0;
pascal@9240 1226 + lzmadec.inpPos = 0;
pascal@9240 1227 + lzmadec.inpSize = 0;
pascal@9240 1228 + LzmaDec_Init(&lzmadec);
pascal@9240 1229 + decomp_type = 1;
pascal@9240 1230 + compressed_file = 1;
pascal@9240 1231 + lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax;
pascal@9240 1232 + lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos;
pascal@9240 1233 + // success
pascal@9240 1234 + //grub_printf("LZMA open success\n");
pascal@9240 1235 + errnum = 0;
pascal@9240 1236 + return 1;
pascal@9240 1237 + }
pascal@9240 1238 + else
pascal@9240 1239 + {
pascal@9240 1240 + errnum = ERR_NOT_ENOUGH_MEMORY;
pascal@9240 1241 + }
pascal@9240 1242 + grub_free(lzmadec.probs); lzmadec.probs = 0;
pascal@9240 1243 + }
pascal@9240 1244 + else
pascal@9240 1245 + {
pascal@9240 1246 + errnum = ERR_NOT_ENOUGH_MEMORY;
pascal@9240 1247 + }
pascal@9240 1248 + grub_free(lzmadec.dic); lzmadec.dic = 0;
pascal@9240 1249 + }
pascal@9240 1250 + else
pascal@9240 1251 + {
pascal@9240 1252 + errnum = ERR_NOT_ENOUGH_MEMORY;
pascal@9240 1253 + }
pascal@9240 1254 + }
pascal@9240 1255 + else
pascal@9240 1256 + {
pascal@9240 1257 + //grub_printf("LZMA allocate memory\n");
pascal@9240 1258 + errnum = ERR_BAD_GZIP_HEADER;
pascal@9240 1259 + }
pascal@9240 1260 + }
pascal@9240 1261 + else
pascal@9240 1262 + {
pascal@9240 1263 + //grub_printf("LZMA error reading header\n");
pascal@9240 1264 + errnum = ERR_BAD_GZIP_HEADER;
pascal@9240 1265 + }
pascal@9240 1266 + //grub_printf("LZMA open fail\n");
pascal@9240 1267 + filepos = 0;
pascal@9240 1268 + return 0;
pascal@9240 1269 +}
pascal@9240 1270 +
pascal@9240 1271 +void
pascal@9240 1272 +dec_lzma_close (void)
pascal@9240 1273 +{
pascal@9240 1274 + if (lzmadec.inp ) { grub_free(lzmadec.inp ); lzmadec.inp = 0; }
pascal@9240 1275 + if (lzmadec.dic ) { grub_free(lzmadec.dic ); lzmadec.dic = 0; }
pascal@9240 1276 + if (lzmadec.probs) { grub_free(lzmadec.probs); lzmadec.probs = 0; }
pascal@9240 1277 +}
pascal@9240 1278 +
pascal@9240 1279 +unsigned long
pascal@9240 1280 +dec_lzma_read (char *buf, unsigned long len, unsigned long write)
pascal@9240 1281 +{
pascal@9240 1282 + UInt64 outTx, outSkip;
pascal@9240 1283 + //grub_printf("LZMA read buf=%ld len=%ld dic=%d inp=%d\n",buf,len,lzmadec.dic,lzmadec.inp);
pascal@9240 1284 +
pascal@9240 1285 + compressed_file = 0;
pascal@9240 1286 + lzmadec.fileu.fmax = filemax; filemax = lzmadec.filec.fmax;
pascal@9240 1287 + lzmadec.fileu.fpos = filepos; filepos = lzmadec.filec.fpos;
pascal@9240 1288 + /* Now filepos, filemax is of compressed file
pascal@9240 1289 + * fileu.fpos, fileu.fmax is of uncompressed data
pascal@9240 1290 + * filec is not used
pascal@9240 1291 + */
pascal@9240 1292 +
pascal@9240 1293 + /*
pascal@9240 1294 + * When dicPos>0,
pascal@9240 1295 + * dic[0 ... dicPos-1] contains
pascal@9240 1296 + * uncompressed_data [dicFilePos ... dicFilePos+dicPos-1].
pascal@9240 1297 + * When dicFilePos>0,
pascal@9240 1298 + * dic[dicPos ... dicBufSize-1] contains
pascal@9240 1299 + * uncompressed_data [dicFilePos-dicBufSize+dicFilePos ... dicFilePos-1]
pascal@9240 1300 + */
pascal@9240 1301 + /* do we reset decompression to the beginning of the file? */
pascal@9240 1302 + if (lzmadec.dicFilePos && (lzmadec.fileu.fpos < lzmadec.dicFilePos-lzmadec.dicBufSize+lzmadec.dicFilePos))
pascal@9240 1303 + {
pascal@9240 1304 + LzmaDec_Init(&lzmadec);
pascal@9240 1305 + filepos = 13;
pascal@9240 1306 + lzmadec.inpPos = lzmadec.inpSize = 0;
pascal@9240 1307 + }
pascal@9240 1308 +
pascal@9240 1309 + outTx = 0;
pascal@9240 1310 + outSkip = lzmadec.fileu.fpos - lzmadec.dicFilePos;
pascal@9240 1311 + //grub_printf("fileu.fpos=%ld dicFilePos=%ld\n",lzmadec.fileu.fpos,lzmadec.dicFilePos);
pascal@9240 1312 +
pascal@9240 1313 + /* Copy uncompressed data from upper part of dic. dic[dicPos]...dic[dicBufSize-1] */
pascal@9240 1314 + if (lzmadec.dicFilePos > lzmadec.fileu.fpos)
pascal@9240 1315 + {
pascal@9240 1316 + UInt32 outTxCur = lzmadec.dicFilePos - lzmadec.fileu.fpos;
pascal@9240 1317 + if (outTxCur > len) outTxCur = len;
pascal@9240 1318 + if (buf)
pascal@9240 1319 + {
pascal@9240 1320 + grub_memmove(buf, lzmadec.dic+outSkip+lzmadec.dicBufSize, outTxCur);
pascal@9240 1321 + buf += outTxCur;
pascal@9240 1322 + }
pascal@9240 1323 + outSkip = 0;
pascal@9240 1324 + outTx += outTxCur;
pascal@9240 1325 + lzmadec.fileu.fpos += outTxCur;
pascal@9240 1326 + len -= outTxCur;
pascal@9240 1327 + }
pascal@9240 1328 +
pascal@9240 1329 + while (len!=0)
pascal@9240 1330 + {
pascal@9240 1331 + SizeT inSizeCur, dicLimit;
pascal@9240 1332 + UInt32 dicPos;
pascal@9240 1333 + ELzmaStatus status;
pascal@9240 1334 + SRes res;
pascal@9240 1335 +
pascal@9240 1336 + /* Copy uncompressed data from lower part of dic. dic[0]...dic[dicPos-1] */
pascal@9240 1337 + //grub_printf("Loop len=%ld outSkip=%ld dicPos=%d\n",len,outSkip,lzmadec.dicPos);
pascal@9240 1338 + if (outSkip < lzmadec.dicPos)
pascal@9240 1339 + {
pascal@9240 1340 + UInt32 outTxCur = lzmadec.dicPos - outSkip;
pascal@9240 1341 + //grub_printf("Copy %d byte ",outTxCur);
pascal@9240 1342 + if (buf)
pascal@9240 1343 + {
pascal@9240 1344 + grub_memmove(buf, lzmadec.dic+outSkip, outTxCur);
pascal@9240 1345 + buf += outTxCur;
pascal@9240 1346 + }
pascal@9240 1347 + outSkip = lzmadec.dicPos;
pascal@9240 1348 + outTx += outTxCur;
pascal@9240 1349 + lzmadec.fileu.fpos += outTxCur;
pascal@9240 1350 + len -= outTxCur;
pascal@9240 1351 + //grub_printf(" remaining len=%ld\n",len);
pascal@9240 1352 + if (len==0) break;
pascal@9240 1353 + }
pascal@9240 1354 + /* All existing wanted data from dic have been copied. We will add more data to dic. */
pascal@9240 1355 + /* Read more input if there is no unprocessed input left. */
pascal@9240 1356 + if (lzmadec.inpPos == lzmadec.inpSize)
pascal@9240 1357 + {
pascal@9240 1358 + UInt32 inTxCur = (filemax-filepos<lzmadec.inpBufSize)?filemax-filepos:lzmadec.inpBufSize;
pascal@9240 1359 + lzmadec.inpFilePos = filepos;
pascal@9240 1360 + lzmadec.inpPos = 0;
pascal@9240 1361 + //grub_printf("read inp %d ",inTxCur);
pascal@9240 1362 + lzmadec.inpSize = grub_read(lzmadec.inp, inTxCur, 0xedde0d90);
pascal@9240 1363 + //grub_printf("->%d\n",lzmadec.inpSize);
pascal@9240 1364 + }
pascal@9240 1365 + inSizeCur = lzmadec.inpSize - lzmadec.inpPos;
pascal@9240 1366 +
pascal@9240 1367 + /* Prepare output dicPos, dicLimit. */
pascal@9240 1368 + if (lzmadec.dicPos == lzmadec.dicBufSize)
pascal@9240 1369 + {
pascal@9240 1370 + lzmadec.dicPos = 0;
pascal@9240 1371 + outSkip -= lzmadec.dicBufSize;
pascal@9240 1372 + }
pascal@9240 1373 + dicPos = lzmadec.dicPos;
pascal@9240 1374 + dicLimit = (lzmadec.dicBufSize-dicPos < len)? lzmadec.dicBufSize: dicPos+len;
pascal@9240 1375 +
pascal@9240 1376 + /* Do decompression. */
pascal@9240 1377 + //grub_printf("DecodeToDic dicPos=%d limit=%d inPos=%d inSize=%d ",dicPos,dicLimit,lzmadec.inpPos,inSizeCur);
pascal@9240 1378 + status = LZMA_STATUS_NOT_SPECIFIED;
pascal@9240 1379 + res = LzmaDec_DecodeToDic(&lzmadec, dicLimit, lzmadec.inp+lzmadec.inpPos, &inSizeCur, LZMA_FINISH_ANY, &status);
pascal@9240 1380 + //grub_printf("->%d\n",inSizeCur);
pascal@9240 1381 + lzmadec.inpPos += inSizeCur;
pascal@9240 1382 + if (inSizeCur==0 && lzmadec.dicPos==dicPos)
pascal@9240 1383 + {
pascal@9240 1384 + /* Error */
pascal@9240 1385 + //grub_printf("No more input and output\n");
pascal@9240 1386 + break;
pascal@9240 1387 + }
pascal@9240 1388 + }
pascal@9240 1389 + compressed_file = 1;
pascal@9240 1390 + lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax;
pascal@9240 1391 + lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos;
pascal@9240 1392 + /* Now filepos, file max is of uncompressed data
pascal@9240 1393 + * filec.fpos, filwc.fmax is of compressed file
pascal@9240 1394 + * fileu is not used
pascal@9240 1395 + */
pascal@9240 1396 +
pascal@9240 1397 + //grub_printf("LZMA read end %ld\n",outTx);
pascal@9240 1398 + return outTx;
pascal@9240 1399 +}
pascal@9240 1400 +
pascal@9240 1401 +#endif /* ! NO_DECOMPRESSION */
pascal@9240 1402 diff -Naur ../grub4dos-chenall-r63/stage2/decomp.h ./stage2/decomp.h
pascal@9240 1403 --- grub4dos-chenall-r63/stage2/decomp.h 1970-01-01 07:00:00.000000000 +0700
pascal@9240 1404 +++ grub4dos/stage2/decomp.h 2010-11-28 13:51:54.687217000 +0700
pascal@9240 1405 @@ -0,0 +1,36 @@
pascal@9240 1406 +/* decomp.h - abstract decompression interface */
pascal@9240 1407 +/*
pascal@9240 1408 + * GRUB -- GRand Unified Bootloader
pascal@9240 1409 + * Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
pascal@9240 1410 + *
pascal@9240 1411 + * This program is free software; you can redistribute it and/or modify
pascal@9240 1412 + * it under the terms of the GNU General Public License as published by
pascal@9240 1413 + * the Free Software Foundation; either version 2 of the License, or
pascal@9240 1414 + * (at your option) any later version.
pascal@9240 1415 + *
pascal@9240 1416 + * This program is distributed in the hope that it will be useful,
pascal@9240 1417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
pascal@9240 1418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
pascal@9240 1419 + * GNU General Public License for more details.
pascal@9240 1420 + *
pascal@9240 1421 + * You should have received a copy of the GNU General Public License
pascal@9240 1422 + * along with this program; if not, write to the Free Software
pascal@9240 1423 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
pascal@9240 1424 + */
pascal@9240 1425 +
pascal@9240 1426 +#ifndef ASM_FILE
pascal@9240 1427 +
pascal@9240 1428 +struct decomp_entry
pascal@9240 1429 +{
pascal@9240 1430 + char *name;
pascal@9240 1431 + int (*open_func) (void);
pascal@9240 1432 + void (*close_func) (void);
pascal@9240 1433 + unsigned long (*read_func) (char *buf, unsigned long len, unsigned long write);
pascal@9240 1434 +};
pascal@9240 1435 +
pascal@9240 1436 +#define NUM_DECOM 2
pascal@9240 1437 +
pascal@9240 1438 +extern struct decomp_entry decomp_table[NUM_DECOM];
pascal@9240 1439 +extern int decomp_type;
pascal@9240 1440 +
pascal@9240 1441 +#endif
pascal@9240 1442 \ No newline at end of file
pascal@9240 1443 diff -Naur ../grub4dos-chenall-r63/stage2/disk_io.c ./stage2/disk_io.c
pascal@9240 1444 --- grub4dos-chenall-r63/stage2/disk_io.c 2010-08-12 14:22:47.111207000 +0700
pascal@9240 1445 +++ grub4dos/stage2/disk_io.c 2010-11-28 20:26:39.089887300 +0700
pascal@9240 1446 @@ -21,6 +21,7 @@
pascal@9240 1447
pascal@9240 1448 #include <shared.h>
pascal@9240 1449 #include <filesys.h>
pascal@9240 1450 +#include <decomp.h>
pascal@9240 1451 #include <iso9660.h>
pascal@9240 1452
pascal@9240 1453 #ifdef SUPPORT_NETBOOT
pascal@9240 1454 @@ -1872,7 +1873,16 @@
pascal@9240 1455 #ifdef NO_DECOMPRESSION
pascal@9240 1456 return 1;
pascal@9240 1457 #else
pascal@9240 1458 - return gunzip_test_header ();
pascal@9240 1459 + if (no_decompression)
pascal@9240 1460 + return 1;
pascal@9240 1461 + int i;
pascal@9240 1462 + i = strlen(open_filename);
pascal@9240 1463 + if (i>=5 && strcmp(open_filename+i-5,".lzma")==0)
pascal@9240 1464 + dec_lzma_open ();
pascal@9240 1465 + else
pascal@9240 1466 + gunzip_test_header ();
pascal@9240 1467 + errnum = 0;
pascal@9240 1468 + return 1;
pascal@9240 1469 #endif
pascal@9240 1470 }
pascal@9240 1471
pascal@9240 1472 @@ -1903,7 +1903,7 @@
pascal@9240 1473 {
pascal@9240 1474 if (write == 0x900ddeed)
pascal@9240 1475 return !(errnum = ERR_WRITE_GZIP_FILE);
pascal@9240 1476 - return gunzip_read (buf, len);
pascal@9240 1477 + return decomp_table[decomp_type].read_func (buf, len, write);
pascal@9240 1478 }
pascal@9240 1479 #endif /* NO_DECOMPRESSION */
pascal@9240 1480
pascal@9240 1481 @@ -1978,6 +1982,12 @@
pascal@9240 1482 void
pascal@9240 1483 grub_close (void)
pascal@9240 1484 {
pascal@9240 1485 +#ifndef NO_DECOMPRESSION
pascal@9240 1486 + if (compressed_file)
pascal@9240 1487 + decomp_table[decomp_type].close_func ();
pascal@9240 1488 + compressed_file = 0;
pascal@9240 1489 +#endif /* NO_DECOMPRESSION */
pascal@9240 1490 +
pascal@9240 1491 #ifndef NO_BLOCK_FILES
pascal@9240 1492 if (block_file)
pascal@9240 1493 return;
pascal@9240 1494 diff -Naur ../grub4dos-chenall-r63/stage2/gunzip.c ./stage2/gunzip.c
pascal@9240 1495 --- grub4dos-chenall-r63/stage2/gunzip.c 2010-07-26 19:35:48.440546000 +0700
pascal@9240 1496 +++ grub4dos/stage2/gunzip.c 2010-11-28 14:20:56.983870700 +0700
pascal@9240 1497 @@ -129,6 +129,8 @@
pascal@9240 1498
pascal@9240 1499 #include "filesys.h"
pascal@9240 1500
pascal@9240 1501 +#include "decomp.h"
pascal@9240 1502 +
pascal@9240 1503 /* so we can disable decompression */
pascal@9240 1504 #ifdef GRUB_UTIL
pascal@9240 1505 int no_decompression = 0;
pascal@9240 1506 @@ -137,6 +139,15 @@
pascal@9240 1507 /* used to tell if "read" should be redirected to "gunzip_read" */
pascal@9240 1508 int compressed_file;
pascal@9240 1509
pascal@9240 1510 +/* identify active decompressor */
pascal@9240 1511 +int decomp_type;
pascal@9240 1512 +
pascal@9240 1513 +struct decomp_entry decomp_table[NUM_DECOM] =
pascal@9240 1514 +{
pascal@9240 1515 + {"gz",gunzip_test_header,gunzip_close,gunzip_read},
pascal@9240 1516 + {"lzma",dec_lzma_open,dec_lzma_close,dec_lzma_read}
pascal@9240 1517 +};
pascal@9240 1518 +
pascal@9240 1519 /* internal variables only */
pascal@9240 1520 static unsigned long long gzip_data_offset;
pascal@9240 1521 static unsigned long long gzip_filepos;
pascal@9240 1522 @@ -227,6 +238,7 @@
pascal@9240 1523 /* Little-Endian defines for the 2-byte magic number for gzip files */
pascal@9240 1524 #define GZIP_HDR_LE 0x8B1F
pascal@9240 1525 #define OLD_GZIP_HDR_LE 0x9E1F
pascal@9240 1526 +#define LZMA_HDR_LE 0x005D
pascal@9240 1527
pascal@9240 1528 /* Compression methods (see algorithm.doc) */
pascal@9240 1529 #define STORED 0
pascal@9240 1530 @@ -281,10 +292,18 @@
pascal@9240 1531 if (no_decompression
pascal@9240 1532 || grub_read ((char *)buf, 10, 0xedde0d90) != 10
pascal@9240 1533 || ((*((unsigned short *) buf) != GZIP_HDR_LE)
pascal@9240 1534 - && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE)))
pascal@9240 1535 + && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE)
pascal@9240 1536 + && (*((unsigned short *) buf) != LZMA_HDR_LE)))
pascal@9240 1537 {
pascal@9240 1538 filepos = 0;
pascal@9240 1539 return ! errnum;
pascal@9240 1540 + }
pascal@9240 1541 +
pascal@9240 1542 + if (*((unsigned short *) buf) == LZMA_HDR_LE)
pascal@9240 1543 + {
pascal@9240 1544 + filepos = 0;
pascal@9240 1545 + dec_lzma_open();
pascal@9240 1546 + return 1;
pascal@9240 1547 }
pascal@9240 1548
pascal@9240 1549 /*
pascal@9240 1550 @@ -323,6 +334,7 @@
pascal@9240 1551
pascal@9240 1552 initialize_tables ();
pascal@9240 1553
pascal@9240 1554 + decomp_type = 0;
pascal@9240 1555 compressed_file = 1;
pascal@9240 1556 gunzip_swap_values ();
pascal@9240 1557 /*
pascal@9240 1558 @@ -334,6 +346,11 @@
pascal@9240 1559 return 1;
pascal@9240 1560 }
pascal@9240 1561
pascal@9240 1562 +void
pascal@9240 1563 +gunzip_close (void)
pascal@9240 1564 +{
pascal@9240 1565 +}
pascal@9240 1566 +
pascal@9240 1567
pascal@9240 1568 /* Huffman code lookup table entry--this entry is four bytes for machines
pascal@9240 1569 that have 16-bit pointers (e.g. PC's in the small or medium model).
pascal@9240 1570 @@ -1190,7 +1226,7 @@
pascal@9240 1571
pascal@9240 1572
pascal@9240 1573 unsigned long
pascal@9240 1574 -gunzip_read (char *buf, unsigned long len)
pascal@9240 1575 +gunzip_read (char *buf, unsigned long len, unsigned long write)
pascal@9240 1576 {
pascal@9240 1577 unsigned long ret = 0;
pascal@9240 1578
pascal@9240 1579 diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.am ./stage2/Makefile.am
pascal@9240 1580 --- grub4dos-chenall-r63/stage2/Makefile.am 2010-08-12 14:22:47.111207000 +0700
pascal@9240 1581 +++ grub4dos/stage2/Makefile.am 2010-11-28 16:35:18.724975900 +0700
pascal@9240 1582 @@ -16,6 +16,7 @@
pascal@9240 1583 # The library for /sbin/grub.
pascal@9240 1584 noinst_LIBRARIES = libgrub.a
pascal@9240 1585 libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
pascal@9240 1586 + dec_lzma.c \
pascal@9240 1587 disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \
pascal@9240 1588 fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
pascal@9240 1589 fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \
pascal@9240 1590 @@ -100,7 +101,7 @@
pascal@9240 1591
pascal@9240 1592 # For stage2 target.
pascal@9240 1593 pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
pascal@9240 1594 - cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
pascal@9240 1595 + cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \
pascal@9240 1596 fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
pascal@9240 1597 fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \
pascal@9240 1598 hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c
pascal@9240 1599 diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.in ./stage2/Makefile.in
pascal@9240 1600 --- grub4dos-chenall-r63/stage2/Makefile.in 2010-08-12 14:22:47.111207000 +0700
pascal@9240 1601 +++ grub4dos/stage2/Makefile.in 2010-11-28 16:38:22.871508400 +0700
pascal@9240 1602 @@ -104,10 +104,11 @@
pascal@9240 1603 am_libgrub_a_OBJECTS = libgrub_a-boot.$(OBJEXT) \
pascal@9240 1604 libgrub_a-builtins.$(OBJEXT) libgrub_a-char_io.$(OBJEXT) \
pascal@9240 1605 libgrub_a-cmdline.$(OBJEXT) libgrub_a-common.$(OBJEXT) \
pascal@9240 1606 - libgrub_a-disk_io.$(OBJEXT) libgrub_a-fsys_ext2fs.$(OBJEXT) \
pascal@9240 1607 - libgrub_a-fsys_fat.$(OBJEXT) libgrub_a-fsys_ntfs.$(OBJEXT) \
pascal@9240 1608 - libgrub_a-fsys_ffs.$(OBJEXT) libgrub_a-fsys_iso9660.$(OBJEXT) \
pascal@9240 1609 - libgrub_a-fsys_jfs.$(OBJEXT) libgrub_a-fsys_minix.$(OBJEXT) \
pascal@9240 1610 + libgrub_a-dec_lzma.$(OBJEXT) libgrub_a-disk_io.$(OBJEXT) \
pascal@9240 1611 + libgrub_a-fsys_ext2fs.$(OBJEXT) libgrub_a-fsys_fat.$(OBJEXT) \
pascal@9240 1612 + libgrub_a-fsys_ntfs.$(OBJEXT) libgrub_a-fsys_ffs.$(OBJEXT) \
pascal@9240 1613 + libgrub_a-fsys_iso9660.$(OBJEXT) libgrub_a-fsys_jfs.$(OBJEXT) \
pascal@9240 1614 + libgrub_a-fsys_minix.$(OBJEXT) \
pascal@9240 1615 libgrub_a-fsys_reiserfs.$(OBJEXT) \
pascal@9240 1616 libgrub_a-fsys_ufs2.$(OBJEXT) libgrub_a-fsys_vstafs.$(OBJEXT) \
pascal@9240 1617 libgrub_a-fsys_xfs.$(OBJEXT) libgrub_a-fsys_pxe.$(OBJEXT) \
pascal@9240 1618 @@ -131,6 +132,7 @@
pascal@9240 1619 diskless_exec-char_io.$(OBJEXT) \
pascal@9240 1620 diskless_exec-cmdline.$(OBJEXT) diskless_exec-common.$(OBJEXT) \
pascal@9240 1621 diskless_exec-console.$(OBJEXT) \
pascal@9240 1622 + diskless_exec-dec_lzma.$(OBJEXT) \
pascal@9240 1623 diskless_exec-disk_io.$(OBJEXT) \
pascal@9240 1624 diskless_exec-fsys_ext2fs.$(OBJEXT) \
pascal@9240 1625 diskless_exec-fsys_fat.$(OBJEXT) \
pascal@9240 1626 @@ -247,6 +249,7 @@
pascal@9240 1627 pre_stage2_exec-cmdline.$(OBJEXT) \
pascal@9240 1628 pre_stage2_exec-common.$(OBJEXT) \
pascal@9240 1629 pre_stage2_exec-console.$(OBJEXT) \
pascal@9240 1630 + pre_stage2_exec-dec_lzma.$(OBJEXT) \
pascal@9240 1631 pre_stage2_exec-disk_io.$(OBJEXT) \
pascal@9240 1632 pre_stage2_exec-fsys_ext2fs.$(OBJEXT) \
pascal@9240 1633 pre_stage2_exec-fsys_fat.$(OBJEXT) \
pascal@9240 1634 @@ -512,6 +513,7 @@
pascal@9240 1635 # The library for /sbin/grub.
pascal@9240 1636 noinst_LIBRARIES = libgrub.a
pascal@9240 1637 libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
pascal@9240 1638 + dec_lzma.c \
pascal@9240 1639 disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \
pascal@9240 1640 fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
pascal@9240 1641 fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \
pascal@9240 1642 @@ -559,7 +563,7 @@
pascal@9240 1643
pascal@9240 1644 # For stage2 target.
pascal@9240 1645 pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
pascal@9240 1646 - cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
pascal@9240 1647 + cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \
pascal@9240 1648 fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
pascal@9240 1649 fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \
pascal@9240 1650 hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c
pascal@9240 1651 @@ -878,6 +882,7 @@
pascal@9240 1652 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-cmdline.Po@am__quote@
pascal@9240 1653 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-common.Po@am__quote@
pascal@9240 1654 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-console.Po@am__quote@
pascal@9240 1655 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-dec_lzma.Po@am__quote@
pascal@9240 1656 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-disk_io.Po@am__quote@
pascal@9240 1657 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_ext2fs.Po@am__quote@
pascal@9240 1658 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_fat.Po@am__quote@
pascal@9240 1659 @@ -935,6 +940,7 @@
pascal@9240 1660 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-char_io.Po@am__quote@
pascal@9240 1661 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-cmdline.Po@am__quote@
pascal@9240 1662 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-common.Po@am__quote@
pascal@9240 1663 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-dec_lzma.Po@am__quote@
pascal@9240 1664 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-disk_io.Po@am__quote@
pascal@9240 1665 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_ext2fs.Po@am__quote@
pascal@9240 1666 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_fat.Po@am__quote@
pascal@9240 1667 @@ -974,6 +980,7 @@
pascal@9240 1668 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-cmdline.Po@am__quote@
pascal@9240 1669 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-common.Po@am__quote@
pascal@9240 1670 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-console.Po@am__quote@
pascal@9240 1671 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-dec_lzma.Po@am__quote@
pascal@9240 1672 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-disk_io.Po@am__quote@
pascal@9240 1673 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_ext2fs.Po@am__quote@
pascal@9240 1674 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_fat.Po@am__quote@
pascal@9240 1675 @@ -1315,6 +1322,20 @@
pascal@9240 1676 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1677 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-common.obj `if test -f 'common.c'; then $(CYGPATH_W) 'common.c'; else $(CYGPATH_W) '$(srcdir)/common.c'; fi`
pascal@9240 1678
pascal@9240 1679 +libgrub_a-dec_lzma.o: dec_lzma.c
pascal@9240 1680 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-dec_lzma.o -MD -MP -MF "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" -c -o libgrub_a-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
pascal@9240 1681 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" "$(DEPDIR)/libgrub_a-dec_lzma.Po"; else rm -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1682 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
pascal@9240 1683 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1684 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
pascal@9240 1685 +
pascal@9240 1686 +libgrub_a-dec_lzma.obj: dec_lzma.c
pascal@9240 1687 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" -c -o libgrub_a-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
pascal@9240 1688 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" "$(DEPDIR)/libgrub_a-dec_lzma.Po"; else rm -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1689 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
pascal@9240 1690 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1691 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
pascal@9240 1692 +
pascal@9240 1693 libgrub_a-disk_io.o: disk_io.c
pascal@9240 1694 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-disk_io.o -MD -MP -MF "$(DEPDIR)/libgrub_a-disk_io.Tpo" -c -o libgrub_a-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
pascal@9240 1695 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-disk_io.Tpo" "$(DEPDIR)/libgrub_a-disk_io.Po"; else rm -f "$(DEPDIR)/libgrub_a-disk_io.Tpo"; exit 1; fi
pascal@9240 1696 @@ -1693,6 +1714,20 @@
pascal@9240 1697 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1698 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-console.obj `if test -f 'console.c'; then $(CYGPATH_W) 'console.c'; else $(CYGPATH_W) '$(srcdir)/console.c'; fi`
pascal@9240 1699
pascal@9240 1700 +diskless_exec-dec_lzma.o: dec_lzma.c
pascal@9240 1701 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-dec_lzma.o -MD -MP -MF "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" -c -o diskless_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
pascal@9240 1702 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" "$(DEPDIR)/diskless_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1703 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
pascal@9240 1704 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1705 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
pascal@9240 1706 +
pascal@9240 1707 +diskless_exec-dec_lzma.obj: dec_lzma.c
pascal@9240 1708 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" -c -o diskless_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
pascal@9240 1709 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" "$(DEPDIR)/diskless_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1710 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
pascal@9240 1711 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1712 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
pascal@9240 1713 +
pascal@9240 1714 diskless_exec-disk_io.o: disk_io.c
pascal@9240 1715 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-disk_io.o -MD -MP -MF "$(DEPDIR)/diskless_exec-disk_io.Tpo" -c -o diskless_exec-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
pascal@9240 1716 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-disk_io.Tpo" "$(DEPDIR)/diskless_exec-disk_io.Po"; else rm -f "$(DEPDIR)/diskless_exec-disk_io.Tpo"; exit 1; fi
pascal@9240 1717 @@ -2687,6 +2722,20 @@
pascal@9240 1718 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1719 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-console.obj `if test -f 'console.c'; then $(CYGPATH_W) 'console.c'; else $(CYGPATH_W) '$(srcdir)/console.c'; fi`
pascal@9240 1720
pascal@9240 1721 +pre_stage2_exec-dec_lzma.o: dec_lzma.c
pascal@9240 1722 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-dec_lzma.o -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" -c -o pre_stage2_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
pascal@9240 1723 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" "$(DEPDIR)/pre_stage2_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1724 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
pascal@9240 1725 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1726 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
pascal@9240 1727 +
pascal@9240 1728 +pre_stage2_exec-dec_lzma.obj: dec_lzma.c
pascal@9240 1729 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" -c -o pre_stage2_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
pascal@9240 1730 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" "$(DEPDIR)/pre_stage2_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo"; exit 1; fi
pascal@9240 1731 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
pascal@9240 1732 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
pascal@9240 1733 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
pascal@9240 1734 +
pascal@9240 1735 pre_stage2_exec-disk_io.o: disk_io.c
pascal@9240 1736 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-disk_io.o -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo" -c -o pre_stage2_exec-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
pascal@9240 1737 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo" "$(DEPDIR)/pre_stage2_exec-disk_io.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo"; exit 1; fi
pascal@9240 1738 diff -Naur ../grub4dos-chenall-r63/stage2/shared.h ./stage2/shared.h
pascal@9240 1739 --- grub4dos-chenall-r63/stage2/shared.h 2010-11-17 15:33:51.826683000 +0700
pascal@9240 1740 +++ grub4dos/stage2/shared.h 2010-11-27 01:16:46.996893700 +0700
pascal@9240 1741 @@ -640,6 +640,7 @@
pascal@9240 1742 ERR_WRITE_GZIP_FILE,
pascal@9240 1743 ERR_FUNC_CALL,
pascal@9240 1744 // ERR_WRITE_TO_NON_MEM_DRIVE,
pascal@9240 1745 + ERR_NOT_ENOUGH_MEMORY,
pascal@9240 1746
pascal@9240 1747 MAX_ERR_NUM
pascal@9240 1748 } grub_error_t;
pascal@9240 1749 @@ -1185,7 +1186,11 @@
pascal@9240 1750 #ifndef NO_DECOMPRESSION
pascal@9240 1751 /* Compression support. */
pascal@9240 1752 int gunzip_test_header (void);
pascal@9240 1753 -unsigned long gunzip_read (char *buf, unsigned long len);
pascal@9240 1754 +void gunzip_close (void);
pascal@9240 1755 +unsigned long gunzip_read (char *buf, unsigned long len, unsigned long write);
pascal@9240 1756 +int dec_lzma_open (void);
pascal@9240 1757 +void dec_lzma_close (void);
pascal@9240 1758 +unsigned long dec_lzma_read (char *buf, unsigned long len, unsigned long write);
pascal@9240 1759 #endif /* NO_DECOMPRESSION */
pascal@9240 1760
pascal@9240 1761 int rawread (unsigned long drive, unsigned long sector, unsigned long byte_offset, unsigned long byte_len, char *buf, unsigned long write);