wok-next diff grub4dos/stuff/lzma.diff @ rev 15732
Up: cookutils (3.1.8)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Dec 28 15:39:34 2013 +0000 (2013-12-28) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/grub4dos/stuff/lzma.diff Sat Dec 28 15:39:34 2013 +0000 1.3 @@ -0,0 +1,1761 @@ 1.4 +From http://code.google.com/p/grub4dos-chenall/issues/detail?id=6 1.5 + 1.6 +diff -Naur ../grub4dos-chenall-r63/stage2/common.c ./stage2/common.c 1.7 +--- grub4dos-chenall-r63/stage2/common.c 2010-11-19 12:41:03.196955000 +0700 1.8 ++++ grub4dos/stage2/common.c 2010-11-23 21:28:26.509102100 +0700 1.9 +@@ -143,6 +143,7 @@ 1.10 + [ERR_WRITE_GZIP_FILE] = "Attempt to write a gzip file", 1.11 + [ERR_FUNC_CALL] = "Invalid function call", 1.12 + // [ERR_WRITE_TO_NON_MEM_DRIVE] = "Only RAM drives can be written when running in a script", 1.13 ++ [ERR_NOT_ENOUGH_MEMORY] = "Not enough memory", 1.14 + 1.15 + }; 1.16 + 1.17 +diff -Naur ../grub4dos-chenall-r63/stage2/dec_lzma.c ./stage2/dec_lzma.c 1.18 +--- grub4dos-chenall-r63/stage2/dec_lzma.c 1970-01-01 07:00:00.000000000 +0700 1.19 ++++ grub4dos/stage2/dec_lzma.c 2010-11-28 22:12:06.452791800 +0700 1.20 +@@ -0,0 +1,1384 @@ 1.21 ++/* 1.22 ++ * GRUB4DOS -- GRand Unified Bootloader 1.23 ++ * Copyright (C) 1999 Free Software Foundation, Inc. 1.24 ++ * 1.25 ++ * This program is free software; you can redistribute it and/or modify 1.26 ++ * it under the terms of the GNU General Public License as published by 1.27 ++ * the Free Software Foundation; either version 2 of the License, or 1.28 ++ * (at your option) any later version. 1.29 ++ * 1.30 ++ * This program is distributed in the hope that it will be useful, 1.31 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.32 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.33 ++ * GNU General Public License for more details. 1.34 ++ * 1.35 ++ * You should have received a copy of the GNU General Public License 1.36 ++ * along with this program; if not, write to the Free Software 1.37 ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1.38 ++ */ 1.39 ++ 1.40 ++/* 1.41 ++ * Most of this file is derives from LZMA SDK 9.12 beta 1.42 ++ * files Types.h, LzmaDec.h, LzmaDec.c by Igor Pavlov 1.43 ++ * It has been modified for used in GRUB4DOS. 1.44 ++ */ 1.45 ++ 1.46 ++#ifndef NO_DECOMPRESSION 1.47 ++ 1.48 ++#include "shared.h" 1.49 ++#include "decomp.h" 1.50 ++ 1.51 ++/* Types.h -- Basic types 1.52 ++2010-03-11 : Igor Pavlov : Public domain */ 1.53 ++ 1.54 ++#define SZ_OK 0 1.55 ++ 1.56 ++#define SZ_ERROR_DATA 1 1.57 ++#define SZ_ERROR_MEM 2 1.58 ++#define SZ_ERROR_CRC 3 1.59 ++#define SZ_ERROR_UNSUPPORTED 4 1.60 ++#define SZ_ERROR_PARAM 5 1.61 ++#define SZ_ERROR_INPUT_EOF 6 1.62 ++#define SZ_ERROR_OUTPUT_EOF 7 1.63 ++#define SZ_ERROR_READ 8 1.64 ++#define SZ_ERROR_WRITE 9 1.65 ++#define SZ_ERROR_PROGRESS 10 1.66 ++#define SZ_ERROR_FAIL 11 1.67 ++#define SZ_ERROR_THREAD 12 1.68 ++ 1.69 ++#define SZ_ERROR_ARCHIVE 16 1.70 ++#define SZ_ERROR_NO_ARCHIVE 17 1.71 ++ 1.72 ++typedef int SRes; 1.73 ++typedef int WRes; 1.74 ++ 1.75 ++#ifndef RINOK 1.76 ++#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } 1.77 ++#endif 1.78 ++ 1.79 ++typedef unsigned char Byte; 1.80 ++typedef short Int16; 1.81 ++typedef unsigned short UInt16; 1.82 ++ 1.83 ++typedef int Int32; 1.84 ++typedef unsigned int UInt32; 1.85 ++ 1.86 ++typedef long long int Int64; 1.87 ++typedef unsigned long long int UInt64; 1.88 ++ 1.89 ++typedef UInt32 SizeT; 1.90 ++typedef int ptrdiff_t; 1.91 ++ 1.92 ++typedef int Bool; 1.93 ++#define True 1 1.94 ++#define False 0 1.95 ++ 1.96 ++#define MY_STD_CALL 1.97 ++#define MY_CDECL 1.98 ++#define MY_FAST_CALL 1.99 ++ 1.100 ++typedef struct 1.101 ++{ 1.102 ++ void *(*Alloc)(void *p, SizeT size); 1.103 ++ void (*Free)(void *p, void *address); /* address can be 0 */ 1.104 ++} ISzAlloc; 1.105 ++ 1.106 ++#define IAlloc_Alloc(p, size) (p)->Alloc((p), size) 1.107 ++#define IAlloc_Free(p, a) (p)->Free((p), a) 1.108 ++ 1.109 ++/* -------------------------------------------------------------------------- */ 1.110 ++ 1.111 ++/* LzmaDec.h -- LZMA Decoder 1.112 ++2009-02-07 : Igor Pavlov : Public domain */ 1.113 ++ 1.114 ++/* #define _LZMA_PROB32 */ 1.115 ++/* _LZMA_PROB32 can increase the speed on some CPUs, 1.116 ++ but memory usage for CLzmaDec::probs will be doubled in that case */ 1.117 ++ 1.118 ++#ifdef _LZMA_PROB32 1.119 ++#define UIntLzmaProb UInt32 1.120 ++#else 1.121 ++#define UIntLzmaProb UInt16 1.122 ++#endif 1.123 ++ 1.124 ++ 1.125 ++/* ---------- LZMA Properties ---------- */ 1.126 ++ 1.127 ++#define LZMA_PROPS_SIZE 5 1.128 ++ 1.129 ++typedef struct _CLzmaProps 1.130 ++{ 1.131 ++ unsigned lc, lp, pb; 1.132 ++ UInt32 dicSize; 1.133 ++} CLzmaProps; 1.134 ++ 1.135 ++/* LzmaProps_Decode - decodes properties 1.136 ++Returns: 1.137 ++ SZ_OK 1.138 ++ SZ_ERROR_UNSUPPORTED - Unsupported properties 1.139 ++*/ 1.140 ++ 1.141 ++SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); 1.142 ++ 1.143 ++ 1.144 ++/* ---------- LZMA Decoder state ---------- */ 1.145 ++ 1.146 ++/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. 1.147 ++ Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ 1.148 ++ 1.149 ++#define LZMA_REQUIRED_INPUT_MAX 20 1.150 ++ 1.151 ++typedef struct 1.152 ++{ 1.153 ++ CLzmaProps prop; 1.154 ++ UIntLzmaProb *probs; 1.155 ++ const Byte *buf; 1.156 ++ UInt32 range, code; 1.157 ++ Byte *dic; 1.158 ++ UInt32 dicPos; 1.159 ++ UInt32 dicBufSize; 1.160 ++ Byte *inp; 1.161 ++ UInt32 inpPos, inpSize; 1.162 ++ UInt32 inpBufSize; 1.163 ++ UInt32 processedPos; 1.164 ++ UInt32 checkDicSize; 1.165 ++ unsigned state; 1.166 ++ UInt32 reps[4]; 1.167 ++ unsigned remainLen; 1.168 ++ int needFlush; 1.169 ++ int needInitState; 1.170 ++ UInt32 numProbs; 1.171 ++ unsigned tempBufSize; 1.172 ++ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; 1.173 ++ UInt64 inpFilePos; 1.174 ++ UInt64 dicFilePos; 1.175 ++ struct { 1.176 ++ UInt64 fmax, fpos; 1.177 ++ } filec, fileu; 1.178 ++} CLzmaDec; 1.179 ++ 1.180 ++#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } 1.181 ++ 1.182 ++void LzmaDec_Init(CLzmaDec *p); 1.183 ++ 1.184 ++/* There are two types of LZMA streams: 1.185 ++ 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 1.186 ++ 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ 1.187 ++ 1.188 ++typedef enum 1.189 ++{ 1.190 ++ LZMA_FINISH_ANY, /* finish at any point */ 1.191 ++ LZMA_FINISH_END /* block must be finished at the end */ 1.192 ++} ELzmaFinishMode; 1.193 ++ 1.194 ++/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! 1.195 ++ 1.196 ++ You must use LZMA_FINISH_END, when you know that current output buffer 1.197 ++ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. 1.198 ++ 1.199 ++ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, 1.200 ++ and output value of destLen will be less than output buffer size limit. 1.201 ++ You can check status result also. 1.202 ++ 1.203 ++ You can use multiple checks to test data integrity after full decompression: 1.204 ++ 1) Check Result and "status" variable. 1.205 ++ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 1.206 ++ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. 1.207 ++ You must use correct finish mode in that case. */ 1.208 ++ 1.209 ++typedef enum 1.210 ++{ 1.211 ++ LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ 1.212 ++ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ 1.213 ++ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ 1.214 ++ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ 1.215 ++ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ 1.216 ++} ELzmaStatus; 1.217 ++ 1.218 ++/* ELzmaStatus is used only as output value for function call */ 1.219 ++ 1.220 ++ 1.221 ++/* ---------- Interfaces ---------- */ 1.222 ++ 1.223 ++/* There are 3 levels of interfaces: 1.224 ++ 1) Dictionary Interface 1.225 ++ 2) Buffer Interface 1.226 ++ 3) One Call Interface 1.227 ++ You can select any of these interfaces, but don't mix functions from different 1.228 ++ groups for same object. */ 1.229 ++ 1.230 ++ 1.231 ++/* There are two variants to allocate state for Dictionary Interface: 1.232 ++ 1) LzmaDec_Allocate / LzmaDec_Free 1.233 ++ 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs 1.234 ++ You can use variant 2, if you set dictionary buffer manually. 1.235 ++ For Buffer Interface you must always use variant 1. 1.236 ++ 1.237 ++LzmaDec_Allocate* can return: 1.238 ++ SZ_OK 1.239 ++ SZ_ERROR_MEM - Memory allocation error 1.240 ++ SZ_ERROR_UNSUPPORTED - Unsupported properties 1.241 ++*/ 1.242 ++ 1.243 ++SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); 1.244 ++void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); 1.245 ++ 1.246 ++SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); 1.247 ++void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); 1.248 ++ 1.249 ++/* ---------- Dictionary Interface ---------- */ 1.250 ++ 1.251 ++/* You can use it, if you want to eliminate the overhead for data copying from 1.252 ++ dictionary to some other external buffer. 1.253 ++ You must work with CLzmaDec variables directly in this interface. 1.254 ++ 1.255 ++ STEPS: 1.256 ++ LzmaDec_Constr() 1.257 ++ LzmaDec_Allocate() 1.258 ++ for (each new stream) 1.259 ++ { 1.260 ++ LzmaDec_Init() 1.261 ++ while (it needs more decompression) 1.262 ++ { 1.263 ++ LzmaDec_DecodeToDic() 1.264 ++ use data from CLzmaDec::dic and update CLzmaDec::dicPos 1.265 ++ } 1.266 ++ } 1.267 ++ LzmaDec_Free() 1.268 ++*/ 1.269 ++ 1.270 ++/* LzmaDec_DecodeToDic 1.271 ++ 1.272 ++ The decoding to internal dictionary buffer (CLzmaDec::dic). 1.273 ++ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! 1.274 ++ 1.275 ++finishMode: 1.276 ++ It has meaning only if the decoding reaches output limit (dicLimit). 1.277 ++ LZMA_FINISH_ANY - Decode just dicLimit bytes. 1.278 ++ LZMA_FINISH_END - Stream must be finished after dicLimit. 1.279 ++ 1.280 ++Returns: 1.281 ++ SZ_OK 1.282 ++ status: 1.283 ++ LZMA_STATUS_FINISHED_WITH_MARK 1.284 ++ LZMA_STATUS_NOT_FINISHED 1.285 ++ LZMA_STATUS_NEEDS_MORE_INPUT 1.286 ++ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 1.287 ++ SZ_ERROR_DATA - Data error 1.288 ++*/ 1.289 ++ 1.290 ++SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, 1.291 ++ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 1.292 ++ 1.293 ++ 1.294 ++/* ---------- Buffer Interface ---------- */ 1.295 ++ 1.296 ++/* It's zlib-like interface. 1.297 ++ See LzmaDec_DecodeToDic description for information about STEPS and return results, 1.298 ++ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need 1.299 ++ to work with CLzmaDec variables manually. 1.300 ++ 1.301 ++finishMode: 1.302 ++ It has meaning only if the decoding reaches output limit (*destLen). 1.303 ++ LZMA_FINISH_ANY - Decode just destLen bytes. 1.304 ++ LZMA_FINISH_END - Stream must be finished after (*destLen). 1.305 ++*/ 1.306 ++ 1.307 ++SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, 1.308 ++ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 1.309 ++ 1.310 ++ 1.311 ++/* ---------- One Call Interface ---------- */ 1.312 ++ 1.313 ++/* LzmaDecode 1.314 ++ 1.315 ++finishMode: 1.316 ++ It has meaning only if the decoding reaches output limit (*destLen). 1.317 ++ LZMA_FINISH_ANY - Decode just destLen bytes. 1.318 ++ LZMA_FINISH_END - Stream must be finished after (*destLen). 1.319 ++ 1.320 ++Returns: 1.321 ++ SZ_OK 1.322 ++ status: 1.323 ++ LZMA_STATUS_FINISHED_WITH_MARK 1.324 ++ LZMA_STATUS_NOT_FINISHED 1.325 ++ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 1.326 ++ SZ_ERROR_DATA - Data error 1.327 ++ SZ_ERROR_MEM - Memory allocation error 1.328 ++ SZ_ERROR_UNSUPPORTED - Unsupported properties 1.329 ++ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 1.330 ++*/ 1.331 ++ 1.332 ++SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 1.333 ++ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, 1.334 ++ ELzmaStatus *status, ISzAlloc *alloc); 1.335 ++ 1.336 ++/* -------------------------------------------------------------------------- */ 1.337 ++ 1.338 ++/* LzmaDec.c -- LZMA Decoder 1.339 ++2009-09-20 : Igor Pavlov : Public domain */ 1.340 ++ 1.341 ++//#include "LzmaDec.h" 1.342 ++ 1.343 ++//#include <string.h> 1.344 ++ 1.345 ++#define kNumTopBits 24 1.346 ++#define kTopValue ((UInt32)1 << kNumTopBits) 1.347 ++ 1.348 ++#define kNumBitModelTotalBits 11 1.349 ++#define kBitModelTotal (1 << kNumBitModelTotalBits) 1.350 ++#define kNumMoveBits 5 1.351 ++ 1.352 ++#define RC_INIT_SIZE 5 1.353 ++ 1.354 ++#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } 1.355 ++ 1.356 ++#define TEST_BIT_0(p) ({ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; (code < bound);}) 1.357 ++#define UPDATE_0(p) range = bound; *(p) = (UIntLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); 1.358 ++#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (UIntLzmaProb)(ttt - (ttt >> kNumMoveBits)); 1.359 ++#define GET_BIT2(p, i, A0, A1) if(TEST_BIT_0(p)) \ 1.360 ++ { UPDATE_0(p); i = (i + i); A0; } else \ 1.361 ++ { UPDATE_1(p); i = (i + i) + 1; A1; } 1.362 ++#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;) 1.363 ++ 1.364 ++#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); } 1.365 ++#define TREE_DECODE(probs, limit, i) \ 1.366 ++ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; } 1.367 ++ 1.368 ++/* #define _LZMA_SIZE_OPT */ 1.369 ++ 1.370 ++#ifdef _LZMA_SIZE_OPT 1.371 ++#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i) 1.372 ++#else 1.373 ++#define TREE_6_DECODE(probs, i) \ 1.374 ++ { i = 1; \ 1.375 ++ TREE_GET_BIT(probs, i); \ 1.376 ++ TREE_GET_BIT(probs, i); \ 1.377 ++ TREE_GET_BIT(probs, i); \ 1.378 ++ TREE_GET_BIT(probs, i); \ 1.379 ++ TREE_GET_BIT(probs, i); \ 1.380 ++ TREE_GET_BIT(probs, i); \ 1.381 ++ i -= 0x40; } 1.382 ++#endif 1.383 ++ 1.384 ++#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); } 1.385 ++ 1.386 ++#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) 1.387 ++#define UPDATE_0_CHECK range = bound; 1.388 ++#define UPDATE_1_CHECK range -= bound; code -= bound; 1.389 ++#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ 1.390 ++ { UPDATE_0_CHECK; i = (i + i); A0; } else \ 1.391 ++ { UPDATE_1_CHECK; i = (i + i) + 1; A1; } 1.392 ++#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;) 1.393 ++#define TREE_DECODE_CHECK(probs, limit, i) \ 1.394 ++ { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; } 1.395 ++ 1.396 ++ 1.397 ++#define kNumPosBitsMax 4 1.398 ++#define kNumPosStatesMax (1 << kNumPosBitsMax) 1.399 ++ 1.400 ++#define kLenNumLowBits 3 1.401 ++#define kLenNumLowSymbols (1 << kLenNumLowBits) 1.402 ++#define kLenNumMidBits 3 1.403 ++#define kLenNumMidSymbols (1 << kLenNumMidBits) 1.404 ++#define kLenNumHighBits 8 1.405 ++#define kLenNumHighSymbols (1 << kLenNumHighBits) 1.406 ++ 1.407 ++#define LenChoice 0 1.408 ++#define LenChoice2 (LenChoice + 1) 1.409 ++#define LenLow (LenChoice2 + 1) 1.410 ++#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) 1.411 ++#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) 1.412 ++#define kNumLenProbs (LenHigh + kLenNumHighSymbols) 1.413 ++ 1.414 ++ 1.415 ++#define kNumStates 12 1.416 ++#define kNumLitStates 7 1.417 ++ 1.418 ++#define kStartPosModelIndex 4 1.419 ++#define kEndPosModelIndex 14 1.420 ++#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) 1.421 ++ 1.422 ++#define kNumPosSlotBits 6 1.423 ++#define kNumLenToPosStates 4 1.424 ++ 1.425 ++#define kNumAlignBits 4 1.426 ++#define kAlignTableSize (1 << kNumAlignBits) 1.427 ++ 1.428 ++#define kMatchMinLen 2 1.429 ++#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols) 1.430 ++ 1.431 ++#define IsMatch 0 1.432 ++#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) 1.433 ++#define IsRepG0 (IsRep + kNumStates) 1.434 ++#define IsRepG1 (IsRepG0 + kNumStates) 1.435 ++#define IsRepG2 (IsRepG1 + kNumStates) 1.436 ++#define IsRep0Long (IsRepG2 + kNumStates) 1.437 ++#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) 1.438 ++#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) 1.439 ++#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) 1.440 ++#define LenCoder (Align + kAlignTableSize) 1.441 ++#define RepLenCoder (LenCoder + kNumLenProbs) 1.442 ++#define Literal (RepLenCoder + kNumLenProbs) 1.443 ++ 1.444 ++#define LZMA_BASE_SIZE 1846 1.445 ++#define LZMA_LIT_SIZE 768 1.446 ++ 1.447 ++#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp))) 1.448 ++ 1.449 ++#if Literal != LZMA_BASE_SIZE 1.450 ++StopCompilingDueBUG 1.451 ++#endif 1.452 ++ 1.453 ++#define LZMA_DIC_MIN (1 << 12) 1.454 ++ 1.455 ++/* First LZMA-symbol is always decoded. 1.456 ++And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization 1.457 ++Out: 1.458 ++ Result: 1.459 ++ SZ_OK - OK 1.460 ++ SZ_ERROR_DATA - Error 1.461 ++ p->remainLen: 1.462 ++ < kMatchSpecLenStart : normal remain 1.463 ++ = kMatchSpecLenStart : finished 1.464 ++ = kMatchSpecLenStart + 1 : Flush marker 1.465 ++ = kMatchSpecLenStart + 2 : State Init Marker 1.466 ++*/ 1.467 ++ 1.468 ++static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit) 1.469 ++{ 1.470 ++ UIntLzmaProb *probs = p->probs; 1.471 ++ 1.472 ++ unsigned state = p->state; 1.473 ++ UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; 1.474 ++ unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1; 1.475 ++ unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; 1.476 ++ unsigned lc = p->prop.lc; 1.477 ++ 1.478 ++ Byte *dic = p->dic; 1.479 ++ SizeT dicBufSize = p->dicBufSize; 1.480 ++ SizeT dicPos = p->dicPos; 1.481 ++ 1.482 ++ UInt32 processedPos = p->processedPos; 1.483 ++ UInt32 checkDicSize = p->checkDicSize; 1.484 ++ unsigned len = 0; 1.485 ++ 1.486 ++ const Byte *buf = p->buf; 1.487 ++ UInt32 range = p->range; 1.488 ++ UInt32 code = p->code; 1.489 ++ 1.490 ++ do 1.491 ++ { 1.492 ++ UIntLzmaProb *prob; 1.493 ++ UInt32 bound; 1.494 ++ unsigned ttt; 1.495 ++ unsigned posState = processedPos & pbMask; 1.496 ++ 1.497 ++ prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; 1.498 ++ if(TEST_BIT_0(prob)) 1.499 ++ { 1.500 ++ unsigned symbol; 1.501 ++ UPDATE_0(prob); 1.502 ++ prob = probs + Literal; 1.503 ++ if (checkDicSize != 0 || processedPos != 0) 1.504 ++ prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) + 1.505 ++ (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc)))); 1.506 ++ 1.507 ++ if (state < kNumLitStates) 1.508 ++ { 1.509 ++ state -= (state < 4) ? state : 3; 1.510 ++ symbol = 1; 1.511 ++ do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100); 1.512 ++ } 1.513 ++ else 1.514 ++ { 1.515 ++ unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; 1.516 ++ unsigned offs = 0x100; 1.517 ++ state -= (state < 10) ? 3 : 6; 1.518 ++ symbol = 1; 1.519 ++ do 1.520 ++ { 1.521 ++ unsigned bit; 1.522 ++ UIntLzmaProb *probLit; 1.523 ++ matchByte <<= 1; 1.524 ++ bit = (matchByte & offs); 1.525 ++ probLit = prob + offs + bit + symbol; 1.526 ++ GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit) 1.527 ++ } 1.528 ++ while (symbol < 0x100); 1.529 ++ } 1.530 ++ dic[dicPos++] = (Byte)symbol; 1.531 ++ processedPos++; 1.532 ++ continue; 1.533 ++ } 1.534 ++ else 1.535 ++ { 1.536 ++ UPDATE_1(prob); 1.537 ++ prob = probs + IsRep + state; 1.538 ++ if(TEST_BIT_0(prob)) 1.539 ++ { 1.540 ++ UPDATE_0(prob); 1.541 ++ state += kNumStates; 1.542 ++ prob = probs + LenCoder; 1.543 ++ } 1.544 ++ else 1.545 ++ { 1.546 ++ UPDATE_1(prob); 1.547 ++ if (checkDicSize == 0 && processedPos == 0) 1.548 ++ return SZ_ERROR_DATA; 1.549 ++ prob = probs + IsRepG0 + state; 1.550 ++ if(TEST_BIT_0(prob)) 1.551 ++ { 1.552 ++ UPDATE_0(prob); 1.553 ++ prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; 1.554 ++ if(TEST_BIT_0(prob)) 1.555 ++ { 1.556 ++ UPDATE_0(prob); 1.557 ++ dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; 1.558 ++ dicPos++; 1.559 ++ processedPos++; 1.560 ++ state = state < kNumLitStates ? 9 : 11; 1.561 ++ continue; 1.562 ++ } 1.563 ++ UPDATE_1(prob); 1.564 ++ } 1.565 ++ else 1.566 ++ { 1.567 ++ UInt32 distance; 1.568 ++ UPDATE_1(prob); 1.569 ++ prob = probs + IsRepG1 + state; 1.570 ++ if(TEST_BIT_0(prob)) 1.571 ++ { 1.572 ++ UPDATE_0(prob); 1.573 ++ distance = rep1; 1.574 ++ } 1.575 ++ else 1.576 ++ { 1.577 ++ UPDATE_1(prob); 1.578 ++ prob = probs + IsRepG2 + state; 1.579 ++ if(TEST_BIT_0(prob)) 1.580 ++ { 1.581 ++ UPDATE_0(prob); 1.582 ++ distance = rep2; 1.583 ++ } 1.584 ++ else 1.585 ++ { 1.586 ++ UPDATE_1(prob); 1.587 ++ distance = rep3; 1.588 ++ rep3 = rep2; 1.589 ++ } 1.590 ++ rep2 = rep1; 1.591 ++ } 1.592 ++ rep1 = rep0; 1.593 ++ rep0 = distance; 1.594 ++ } 1.595 ++ state = state < kNumLitStates ? 8 : 11; 1.596 ++ prob = probs + RepLenCoder; 1.597 ++ } 1.598 ++ { 1.599 ++ unsigned limit, offset; 1.600 ++ UIntLzmaProb *probLen = prob + LenChoice; 1.601 ++ if(TEST_BIT_0(probLen)) 1.602 ++ { 1.603 ++ UPDATE_0(probLen); 1.604 ++ probLen = prob + LenLow + (posState << kLenNumLowBits); 1.605 ++ offset = 0; 1.606 ++ limit = (1 << kLenNumLowBits); 1.607 ++ } 1.608 ++ else 1.609 ++ { 1.610 ++ UPDATE_1(probLen); 1.611 ++ probLen = prob + LenChoice2; 1.612 ++ if(TEST_BIT_0(probLen)) 1.613 ++ { 1.614 ++ UPDATE_0(probLen); 1.615 ++ probLen = prob + LenMid + (posState << kLenNumMidBits); 1.616 ++ offset = kLenNumLowSymbols; 1.617 ++ limit = (1 << kLenNumMidBits); 1.618 ++ } 1.619 ++ else 1.620 ++ { 1.621 ++ UPDATE_1(probLen); 1.622 ++ probLen = prob + LenHigh; 1.623 ++ offset = kLenNumLowSymbols + kLenNumMidSymbols; 1.624 ++ limit = (1 << kLenNumHighBits); 1.625 ++ } 1.626 ++ } 1.627 ++ TREE_DECODE(probLen, limit, len); 1.628 ++ len += offset; 1.629 ++ } 1.630 ++ 1.631 ++ if (state >= kNumStates) 1.632 ++ { 1.633 ++ UInt32 distance; 1.634 ++ prob = probs + PosSlot + 1.635 ++ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); 1.636 ++ TREE_6_DECODE(prob, distance); 1.637 ++ if (distance >= kStartPosModelIndex) 1.638 ++ { 1.639 ++ unsigned posSlot = (unsigned)distance; 1.640 ++ int numDirectBits = (int)(((distance >> 1) - 1)); 1.641 ++ distance = (2 | (distance & 1)); 1.642 ++ if (posSlot < kEndPosModelIndex) 1.643 ++ { 1.644 ++ distance <<= numDirectBits; 1.645 ++ prob = probs + SpecPos + distance - posSlot - 1; 1.646 ++ { 1.647 ++ UInt32 mask = 1; 1.648 ++ unsigned i = 1; 1.649 ++ do 1.650 ++ { 1.651 ++ GET_BIT2(prob + i, i, ; , distance |= mask); 1.652 ++ mask <<= 1; 1.653 ++ } 1.654 ++ while (--numDirectBits != 0); 1.655 ++ } 1.656 ++ } 1.657 ++ else 1.658 ++ { 1.659 ++ numDirectBits -= kNumAlignBits; 1.660 ++ do 1.661 ++ { 1.662 ++ NORMALIZE 1.663 ++ range >>= 1; 1.664 ++ 1.665 ++ { 1.666 ++ UInt32 t; 1.667 ++ code -= range; 1.668 ++ t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */ 1.669 ++ distance = (distance << 1) + (t + 1); 1.670 ++ code += range & t; 1.671 ++ } 1.672 ++ /* 1.673 ++ distance <<= 1; 1.674 ++ if (code >= range) 1.675 ++ { 1.676 ++ code -= range; 1.677 ++ distance |= 1; 1.678 ++ } 1.679 ++ */ 1.680 ++ } 1.681 ++ while (--numDirectBits != 0); 1.682 ++ prob = probs + Align; 1.683 ++ distance <<= kNumAlignBits; 1.684 ++ { 1.685 ++ unsigned i = 1; 1.686 ++ GET_BIT2(prob + i, i, ; , distance |= 1); 1.687 ++ GET_BIT2(prob + i, i, ; , distance |= 2); 1.688 ++ GET_BIT2(prob + i, i, ; , distance |= 4); 1.689 ++ GET_BIT2(prob + i, i, ; , distance |= 8); 1.690 ++ } 1.691 ++ if (distance == (UInt32)0xFFFFFFFF) 1.692 ++ { 1.693 ++ len += kMatchSpecLenStart; 1.694 ++ state -= kNumStates; 1.695 ++ break; 1.696 ++ } 1.697 ++ } 1.698 ++ } 1.699 ++ rep3 = rep2; 1.700 ++ rep2 = rep1; 1.701 ++ rep1 = rep0; 1.702 ++ rep0 = distance + 1; 1.703 ++ if (checkDicSize == 0) 1.704 ++ { 1.705 ++ if (distance >= processedPos) 1.706 ++ return SZ_ERROR_DATA; 1.707 ++ } 1.708 ++ else if (distance >= checkDicSize) 1.709 ++ return SZ_ERROR_DATA; 1.710 ++ state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3; 1.711 ++ } 1.712 ++ 1.713 ++ len += kMatchMinLen; 1.714 ++ 1.715 ++ if (limit == dicPos) 1.716 ++ return SZ_ERROR_DATA; 1.717 ++ { 1.718 ++ SizeT rem = limit - dicPos; 1.719 ++ unsigned curLen = ((rem < len) ? (unsigned)rem : len); 1.720 ++ SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0); 1.721 ++ 1.722 ++ processedPos += curLen; 1.723 ++ 1.724 ++ len -= curLen; 1.725 ++ if (pos + curLen <= dicBufSize) 1.726 ++ { 1.727 ++ Byte *dest = dic + dicPos; 1.728 ++ ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; 1.729 ++ const Byte *lim = dest + curLen; 1.730 ++ dicPos += curLen; 1.731 ++ do 1.732 ++ *(dest) = (Byte)(*(dest + src)); 1.733 ++ while (++dest != lim); 1.734 ++ } 1.735 ++ else 1.736 ++ { 1.737 ++ do 1.738 ++ { 1.739 ++ dic[dicPos++] = dic[pos]; 1.740 ++ if (++pos == dicBufSize) 1.741 ++ pos = 0; 1.742 ++ } 1.743 ++ while (--curLen != 0); 1.744 ++ } 1.745 ++ } 1.746 ++ } 1.747 ++ } 1.748 ++ while (dicPos < limit && buf < bufLimit); 1.749 ++ NORMALIZE; 1.750 ++ p->buf = buf; 1.751 ++ p->range = range; 1.752 ++ p->code = code; 1.753 ++ p->remainLen = len; 1.754 ++ p->dicPos = dicPos; 1.755 ++ p->processedPos = processedPos; 1.756 ++ p->reps[0] = rep0; 1.757 ++ p->reps[1] = rep1; 1.758 ++ p->reps[2] = rep2; 1.759 ++ p->reps[3] = rep3; 1.760 ++ p->state = state; 1.761 ++ 1.762 ++ return SZ_OK; 1.763 ++} 1.764 ++ 1.765 ++static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) 1.766 ++{ 1.767 ++ if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) 1.768 ++ { 1.769 ++ Byte *dic = p->dic; 1.770 ++ SizeT dicPos = p->dicPos; 1.771 ++ SizeT dicBufSize = p->dicBufSize; 1.772 ++ unsigned len = p->remainLen; 1.773 ++ UInt32 rep0 = p->reps[0]; 1.774 ++ if (limit - dicPos < len) 1.775 ++ len = (unsigned)(limit - dicPos); 1.776 ++ 1.777 ++ if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len) 1.778 ++ p->checkDicSize = p->prop.dicSize; 1.779 ++ 1.780 ++ p->processedPos += len; 1.781 ++ p->remainLen -= len; 1.782 ++ while (len-- != 0) 1.783 ++ { 1.784 ++ dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; 1.785 ++ dicPos++; 1.786 ++ } 1.787 ++ p->dicPos = dicPos; 1.788 ++ } 1.789 ++} 1.790 ++ 1.791 ++static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) 1.792 ++{ 1.793 ++ do 1.794 ++ { 1.795 ++ SizeT limit2 = limit; 1.796 ++ if (p->checkDicSize == 0) 1.797 ++ { 1.798 ++ UInt32 rem = p->prop.dicSize - p->processedPos; 1.799 ++ if (limit - p->dicPos > rem) 1.800 ++ limit2 = p->dicPos + rem; 1.801 ++ } 1.802 ++ RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit)); 1.803 ++ if (p->processedPos >= p->prop.dicSize) 1.804 ++ p->checkDicSize = p->prop.dicSize; 1.805 ++ LzmaDec_WriteRem(p, limit); 1.806 ++ } 1.807 ++ while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart); 1.808 ++ 1.809 ++ if (p->remainLen > kMatchSpecLenStart) 1.810 ++ { 1.811 ++ p->remainLen = kMatchSpecLenStart; 1.812 ++ } 1.813 ++ return 0; 1.814 ++} 1.815 ++ 1.816 ++typedef enum 1.817 ++{ 1.818 ++ DUMMY_ERROR, /* unexpected end of input stream */ 1.819 ++ DUMMY_LIT, 1.820 ++ DUMMY_MATCH, 1.821 ++ DUMMY_REP 1.822 ++} ELzmaDummy; 1.823 ++ 1.824 ++static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) 1.825 ++{ 1.826 ++ UInt32 range = p->range; 1.827 ++ UInt32 code = p->code; 1.828 ++ const Byte *bufLimit = buf + inSize; 1.829 ++ UIntLzmaProb *probs = p->probs; 1.830 ++ unsigned state = p->state; 1.831 ++ ELzmaDummy res; 1.832 ++ 1.833 ++ { 1.834 ++ UIntLzmaProb *prob; 1.835 ++ UInt32 bound; 1.836 ++ unsigned ttt; 1.837 ++ unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); 1.838 ++ 1.839 ++ prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; 1.840 ++ IF_BIT_0_CHECK(prob) 1.841 ++ { 1.842 ++ UPDATE_0_CHECK 1.843 ++ 1.844 ++ /* if (bufLimit - buf >= 7) return DUMMY_LIT; */ 1.845 ++ 1.846 ++ prob = probs + Literal; 1.847 ++ if (p->checkDicSize != 0 || p->processedPos != 0) 1.848 ++ prob += (LZMA_LIT_SIZE * 1.849 ++ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) + 1.850 ++ (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc)))); 1.851 ++ 1.852 ++ if (state < kNumLitStates) 1.853 ++ { 1.854 ++ unsigned symbol = 1; 1.855 ++ do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100); 1.856 ++ } 1.857 ++ else 1.858 ++ { 1.859 ++ unsigned matchByte = p->dic[p->dicPos - p->reps[0] + 1.860 ++ ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)]; 1.861 ++ unsigned offs = 0x100; 1.862 ++ unsigned symbol = 1; 1.863 ++ do 1.864 ++ { 1.865 ++ unsigned bit; 1.866 ++ UIntLzmaProb *probLit; 1.867 ++ matchByte <<= 1; 1.868 ++ bit = (matchByte & offs); 1.869 ++ probLit = prob + offs + bit + symbol; 1.870 ++ GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit) 1.871 ++ } 1.872 ++ while (symbol < 0x100); 1.873 ++ } 1.874 ++ res = DUMMY_LIT; 1.875 ++ } 1.876 ++ else 1.877 ++ { 1.878 ++ unsigned len; 1.879 ++ UPDATE_1_CHECK; 1.880 ++ 1.881 ++ prob = probs + IsRep + state; 1.882 ++ IF_BIT_0_CHECK(prob) 1.883 ++ { 1.884 ++ UPDATE_0_CHECK; 1.885 ++ state = 0; 1.886 ++ prob = probs + LenCoder; 1.887 ++ res = DUMMY_MATCH; 1.888 ++ } 1.889 ++ else 1.890 ++ { 1.891 ++ UPDATE_1_CHECK; 1.892 ++ res = DUMMY_REP; 1.893 ++ prob = probs + IsRepG0 + state; 1.894 ++ IF_BIT_0_CHECK(prob) 1.895 ++ { 1.896 ++ UPDATE_0_CHECK; 1.897 ++ prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; 1.898 ++ IF_BIT_0_CHECK(prob) 1.899 ++ { 1.900 ++ UPDATE_0_CHECK; 1.901 ++ NORMALIZE_CHECK; 1.902 ++ return DUMMY_REP; 1.903 ++ } 1.904 ++ else 1.905 ++ { 1.906 ++ UPDATE_1_CHECK; 1.907 ++ } 1.908 ++ } 1.909 ++ else 1.910 ++ { 1.911 ++ UPDATE_1_CHECK; 1.912 ++ prob = probs + IsRepG1 + state; 1.913 ++ IF_BIT_0_CHECK(prob) 1.914 ++ { 1.915 ++ UPDATE_0_CHECK; 1.916 ++ } 1.917 ++ else 1.918 ++ { 1.919 ++ UPDATE_1_CHECK; 1.920 ++ prob = probs + IsRepG2 + state; 1.921 ++ IF_BIT_0_CHECK(prob) 1.922 ++ { 1.923 ++ UPDATE_0_CHECK; 1.924 ++ } 1.925 ++ else 1.926 ++ { 1.927 ++ UPDATE_1_CHECK; 1.928 ++ } 1.929 ++ } 1.930 ++ } 1.931 ++ state = kNumStates; 1.932 ++ prob = probs + RepLenCoder; 1.933 ++ } 1.934 ++ { 1.935 ++ unsigned limit, offset; 1.936 ++ UIntLzmaProb *probLen = prob + LenChoice; 1.937 ++ IF_BIT_0_CHECK(probLen) 1.938 ++ { 1.939 ++ UPDATE_0_CHECK; 1.940 ++ probLen = prob + LenLow + (posState << kLenNumLowBits); 1.941 ++ offset = 0; 1.942 ++ limit = 1 << kLenNumLowBits; 1.943 ++ } 1.944 ++ else 1.945 ++ { 1.946 ++ UPDATE_1_CHECK; 1.947 ++ probLen = prob + LenChoice2; 1.948 ++ IF_BIT_0_CHECK(probLen) 1.949 ++ { 1.950 ++ UPDATE_0_CHECK; 1.951 ++ probLen = prob + LenMid + (posState << kLenNumMidBits); 1.952 ++ offset = kLenNumLowSymbols; 1.953 ++ limit = 1 << kLenNumMidBits; 1.954 ++ } 1.955 ++ else 1.956 ++ { 1.957 ++ UPDATE_1_CHECK; 1.958 ++ probLen = prob + LenHigh; 1.959 ++ offset = kLenNumLowSymbols + kLenNumMidSymbols; 1.960 ++ limit = 1 << kLenNumHighBits; 1.961 ++ } 1.962 ++ } 1.963 ++ TREE_DECODE_CHECK(probLen, limit, len); 1.964 ++ len += offset; 1.965 ++ } 1.966 ++ 1.967 ++ if (state < 4) 1.968 ++ { 1.969 ++ unsigned posSlot; 1.970 ++ prob = probs + PosSlot + 1.971 ++ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << 1.972 ++ kNumPosSlotBits); 1.973 ++ TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot); 1.974 ++ if (posSlot >= kStartPosModelIndex) 1.975 ++ { 1.976 ++ int numDirectBits = ((posSlot >> 1) - 1); 1.977 ++ 1.978 ++ /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */ 1.979 ++ 1.980 ++ if (posSlot < kEndPosModelIndex) 1.981 ++ { 1.982 ++ prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1; 1.983 ++ } 1.984 ++ else 1.985 ++ { 1.986 ++ numDirectBits -= kNumAlignBits; 1.987 ++ do 1.988 ++ { 1.989 ++ NORMALIZE_CHECK 1.990 ++ range >>= 1; 1.991 ++ code -= range & (((code - range) >> 31) - 1); 1.992 ++ /* if (code >= range) code -= range; */ 1.993 ++ } 1.994 ++ while (--numDirectBits != 0); 1.995 ++ prob = probs + Align; 1.996 ++ numDirectBits = kNumAlignBits; 1.997 ++ } 1.998 ++ { 1.999 ++ unsigned i = 1; 1.1000 ++ do 1.1001 ++ { 1.1002 ++ GET_BIT_CHECK(prob + i, i); 1.1003 ++ } 1.1004 ++ while (--numDirectBits != 0); 1.1005 ++ } 1.1006 ++ } 1.1007 ++ } 1.1008 ++ } 1.1009 ++ } 1.1010 ++ NORMALIZE_CHECK; 1.1011 ++ return res; 1.1012 ++} 1.1013 ++ 1.1014 ++ 1.1015 ++static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) 1.1016 ++{ 1.1017 ++ p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]); 1.1018 ++ p->range = 0xFFFFFFFF; 1.1019 ++ p->needFlush = 0; 1.1020 ++} 1.1021 ++ 1.1022 ++void LzmaDec_Init(CLzmaDec *p) 1.1023 ++{ 1.1024 ++ p->dicFilePos = 0; 1.1025 ++ p->dicPos = 0; 1.1026 ++ p->needFlush = 1; 1.1027 ++ p->remainLen = 0; 1.1028 ++ p->tempBufSize = 0; 1.1029 ++ p->processedPos = 0; 1.1030 ++ p->checkDicSize = 0; 1.1031 ++ p->needInitState = 1; 1.1032 ++ p->needInitState = 1; 1.1033 ++} 1.1034 ++ 1.1035 ++static void LzmaDec_InitStateReal(CLzmaDec *p) 1.1036 ++{ 1.1037 ++ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp)); 1.1038 ++ UInt32 i; 1.1039 ++ UIntLzmaProb *probs = p->probs; 1.1040 ++ for (i = 0; i < numProbs; i++) 1.1041 ++ probs[i] = kBitModelTotal >> 1; 1.1042 ++ p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1; 1.1043 ++ p->state = 0; 1.1044 ++ p->needInitState = 0; 1.1045 ++} 1.1046 ++ 1.1047 ++SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, 1.1048 ++ ELzmaFinishMode finishMode, ELzmaStatus *status) 1.1049 ++{ 1.1050 ++ SizeT inSize = *srcLen; 1.1051 ++ (*srcLen) = 0; 1.1052 ++ LzmaDec_WriteRem(p, dicLimit); 1.1053 ++ 1.1054 ++ *status = LZMA_STATUS_NOT_SPECIFIED; 1.1055 ++ 1.1056 ++ while (p->remainLen != kMatchSpecLenStart) 1.1057 ++ { 1.1058 ++ int checkEndMarkNow; 1.1059 ++ 1.1060 ++ if (p->needFlush != 0) 1.1061 ++ { 1.1062 ++ for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--) 1.1063 ++ p->tempBuf[p->tempBufSize++] = *src++; 1.1064 ++ if (p->tempBufSize < RC_INIT_SIZE) 1.1065 ++ { 1.1066 ++ *status = LZMA_STATUS_NEEDS_MORE_INPUT; 1.1067 ++ return SZ_OK; 1.1068 ++ } 1.1069 ++ if (p->tempBuf[0] != 0) 1.1070 ++ return SZ_ERROR_DATA; 1.1071 ++ 1.1072 ++ LzmaDec_InitRc(p, p->tempBuf); 1.1073 ++ p->tempBufSize = 0; 1.1074 ++ } 1.1075 ++ 1.1076 ++ checkEndMarkNow = 0; 1.1077 ++ if (p->dicPos >= dicLimit) 1.1078 ++ { 1.1079 ++ if (p->remainLen == 0 && p->code == 0) 1.1080 ++ { 1.1081 ++ *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK; 1.1082 ++ return SZ_OK; 1.1083 ++ } 1.1084 ++ if (finishMode == LZMA_FINISH_ANY) 1.1085 ++ { 1.1086 ++ *status = LZMA_STATUS_NOT_FINISHED; 1.1087 ++ return SZ_OK; 1.1088 ++ } 1.1089 ++ if (p->remainLen != 0) 1.1090 ++ { 1.1091 ++ *status = LZMA_STATUS_NOT_FINISHED; 1.1092 ++ return SZ_ERROR_DATA; 1.1093 ++ } 1.1094 ++ checkEndMarkNow = 1; 1.1095 ++ } 1.1096 ++ 1.1097 ++ if (p->needInitState) 1.1098 ++ LzmaDec_InitStateReal(p); 1.1099 ++ 1.1100 ++ if (p->tempBufSize == 0) 1.1101 ++ { 1.1102 ++ SizeT processed; 1.1103 ++ const Byte *bufLimit; 1.1104 ++ if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) 1.1105 ++ { 1.1106 ++ int dummyRes = LzmaDec_TryDummy(p, src, inSize); 1.1107 ++ if (dummyRes == DUMMY_ERROR) 1.1108 ++ { 1.1109 ++ memcpy(p->tempBuf, src, inSize); 1.1110 ++ p->tempBufSize = (unsigned)inSize; 1.1111 ++ (*srcLen) += inSize; 1.1112 ++ *status = LZMA_STATUS_NEEDS_MORE_INPUT; 1.1113 ++ return SZ_OK; 1.1114 ++ } 1.1115 ++ if (checkEndMarkNow && dummyRes != DUMMY_MATCH) 1.1116 ++ { 1.1117 ++ *status = LZMA_STATUS_NOT_FINISHED; 1.1118 ++ return SZ_ERROR_DATA; 1.1119 ++ } 1.1120 ++ bufLimit = src; 1.1121 ++ } 1.1122 ++ else 1.1123 ++ bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX; 1.1124 ++ p->buf = src; 1.1125 ++ if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0) 1.1126 ++ return SZ_ERROR_DATA; 1.1127 ++ processed = (SizeT)(p->buf - src); 1.1128 ++ (*srcLen) += processed; 1.1129 ++ src += processed; 1.1130 ++ inSize -= processed; 1.1131 ++ } 1.1132 ++ else 1.1133 ++ { 1.1134 ++ unsigned rem = p->tempBufSize, lookAhead = 0; 1.1135 ++ while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize) 1.1136 ++ p->tempBuf[rem++] = src[lookAhead++]; 1.1137 ++ p->tempBufSize = rem; 1.1138 ++ if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) 1.1139 ++ { 1.1140 ++ int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem); 1.1141 ++ if (dummyRes == DUMMY_ERROR) 1.1142 ++ { 1.1143 ++ (*srcLen) += lookAhead; 1.1144 ++ *status = LZMA_STATUS_NEEDS_MORE_INPUT; 1.1145 ++ return SZ_OK; 1.1146 ++ } 1.1147 ++ if (checkEndMarkNow && dummyRes != DUMMY_MATCH) 1.1148 ++ { 1.1149 ++ *status = LZMA_STATUS_NOT_FINISHED; 1.1150 ++ return SZ_ERROR_DATA; 1.1151 ++ } 1.1152 ++ } 1.1153 ++ p->buf = p->tempBuf; 1.1154 ++ if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0) 1.1155 ++ return SZ_ERROR_DATA; 1.1156 ++ lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf)); 1.1157 ++ (*srcLen) += lookAhead; 1.1158 ++ src += lookAhead; 1.1159 ++ inSize -= lookAhead; 1.1160 ++ p->tempBufSize = 0; 1.1161 ++ } 1.1162 ++ } 1.1163 ++ if (p->code == 0) 1.1164 ++ *status = LZMA_STATUS_FINISHED_WITH_MARK; 1.1165 ++ return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; 1.1166 ++} 1.1167 ++ 1.1168 ++/* -------------------------------------------------------------------------- */ 1.1169 ++ 1.1170 ++#define ReadUnalignedUInt32(p) ((UInt32)((Byte*)(p))[0] | ((UInt32)((Byte*)(p))[1]<<8) | ((UInt32)((Byte*)(p))[2]<<16) | ((UInt32)((Byte*)(p))[3]<<24)) 1.1171 ++#define ReadUnalignedUInt64(p) (ReadUnalignedUInt32(p) | ((UInt64)ReadUnalignedUInt32((Byte*)(p)+4)<<32)) 1.1172 ++ 1.1173 ++CLzmaDec lzmadec; 1.1174 ++ 1.1175 ++static unsigned long malloc_top = 0; 1.1176 ++static void *grub_malloc(unsigned long size) 1.1177 ++{ 1.1178 ++ if (!malloc_top) 1.1179 ++ malloc_top = RAW_ADDR ((saved_mem_upper << 10) + 0x100000); 1.1180 ++ malloc_top = (malloc_top - size) & ~3; 1.1181 ++ return (void *) malloc_top; 1.1182 ++} 1.1183 ++#define grub_free(x) 1.1184 ++ 1.1185 ++int 1.1186 ++dec_lzma_open (void) 1.1187 ++// return 1=success or 0=failure 1.1188 ++{ 1.1189 ++ unsigned char header[13]; 1.1190 ++ unsigned char d; 1.1191 ++ 1.1192 ++ if (no_decompression) return 0; 1.1193 ++ 1.1194 ++ // Now it does not support openning more than 1 file at a time. 1.1195 ++ // Make sure previously allocated memory blocks is freed. 1.1196 ++ // Don't need this line if grub_close is called for every openned file before grub_open is called for next file. 1.1197 ++ dec_lzma_close(); 1.1198 ++ 1.1199 ++ filepos = 0; 1.1200 ++ if (grub_read ((char *)header, 13, 0xedde0d90) == 13) 1.1201 ++ { 1.1202 ++ // check header 1.1203 ++ lzmadec.prop.dicSize = ReadUnalignedUInt32(header+1); 1.1204 ++ if (lzmadec.prop.dicSize < LZMA_DIC_MIN) 1.1205 ++ lzmadec.prop.dicSize = LZMA_DIC_MIN; 1.1206 ++ d = header[0]; 1.1207 ++ if (d < 9*5*5) 1.1208 ++ { 1.1209 ++ // valid LZMA file 1.1210 ++ lzmadec.prop.lc = d % 9; d /= 9; 1.1211 ++ lzmadec.prop.lp = d % 5; 1.1212 ++ lzmadec.prop.pb = d / 5; 1.1213 ++ lzmadec.fileu.fmax = ReadUnalignedUInt64(header+5); 1.1214 ++ lzmadec.fileu.fpos = 0; 1.1215 ++ lzmadec.dicBufSize = lzmadec.prop.dicSize; 1.1216 ++ lzmadec.dic = (Byte*) grub_malloc(lzmadec.dicBufSize); 1.1217 ++ //grub_printf("LZMA allocate memory\n"); 1.1218 ++ if (lzmadec.dic) 1.1219 ++ { 1.1220 ++ lzmadec.numProbs = LzmaProps_GetNumProbs(&lzmadec.prop); 1.1221 ++ lzmadec.probs = (UIntLzmaProb *) grub_malloc(lzmadec.numProbs * sizeof(UIntLzmaProb)); 1.1222 ++ if (lzmadec.probs) 1.1223 ++ { 1.1224 ++ lzmadec.inpBufSize = 0x8000; 1.1225 ++ lzmadec.inp = (Byte*) grub_malloc(lzmadec.inpBufSize); 1.1226 ++ if (lzmadec.inp) 1.1227 ++ { 1.1228 ++ lzmadec.inpFilePos = 0; 1.1229 ++ lzmadec.inpPos = 0; 1.1230 ++ lzmadec.inpSize = 0; 1.1231 ++ LzmaDec_Init(&lzmadec); 1.1232 ++ decomp_type = 1; 1.1233 ++ compressed_file = 1; 1.1234 ++ lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax; 1.1235 ++ lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos; 1.1236 ++ // success 1.1237 ++ //grub_printf("LZMA open success\n"); 1.1238 ++ errnum = 0; 1.1239 ++ return 1; 1.1240 ++ } 1.1241 ++ else 1.1242 ++ { 1.1243 ++ errnum = ERR_NOT_ENOUGH_MEMORY; 1.1244 ++ } 1.1245 ++ grub_free(lzmadec.probs); lzmadec.probs = 0; 1.1246 ++ } 1.1247 ++ else 1.1248 ++ { 1.1249 ++ errnum = ERR_NOT_ENOUGH_MEMORY; 1.1250 ++ } 1.1251 ++ grub_free(lzmadec.dic); lzmadec.dic = 0; 1.1252 ++ } 1.1253 ++ else 1.1254 ++ { 1.1255 ++ errnum = ERR_NOT_ENOUGH_MEMORY; 1.1256 ++ } 1.1257 ++ } 1.1258 ++ else 1.1259 ++ { 1.1260 ++ //grub_printf("LZMA allocate memory\n"); 1.1261 ++ errnum = ERR_BAD_GZIP_HEADER; 1.1262 ++ } 1.1263 ++ } 1.1264 ++ else 1.1265 ++ { 1.1266 ++ //grub_printf("LZMA error reading header\n"); 1.1267 ++ errnum = ERR_BAD_GZIP_HEADER; 1.1268 ++ } 1.1269 ++ //grub_printf("LZMA open fail\n"); 1.1270 ++ filepos = 0; 1.1271 ++ return 0; 1.1272 ++} 1.1273 ++ 1.1274 ++void 1.1275 ++dec_lzma_close (void) 1.1276 ++{ 1.1277 ++ if (lzmadec.inp ) { grub_free(lzmadec.inp ); lzmadec.inp = 0; } 1.1278 ++ if (lzmadec.dic ) { grub_free(lzmadec.dic ); lzmadec.dic = 0; } 1.1279 ++ if (lzmadec.probs) { grub_free(lzmadec.probs); lzmadec.probs = 0; } 1.1280 ++} 1.1281 ++ 1.1282 ++unsigned long 1.1283 ++dec_lzma_read (char *buf, unsigned long len, unsigned long write) 1.1284 ++{ 1.1285 ++ UInt64 outTx, outSkip; 1.1286 ++ //grub_printf("LZMA read buf=%ld len=%ld dic=%d inp=%d\n",buf,len,lzmadec.dic,lzmadec.inp); 1.1287 ++ 1.1288 ++ compressed_file = 0; 1.1289 ++ lzmadec.fileu.fmax = filemax; filemax = lzmadec.filec.fmax; 1.1290 ++ lzmadec.fileu.fpos = filepos; filepos = lzmadec.filec.fpos; 1.1291 ++ /* Now filepos, filemax is of compressed file 1.1292 ++ * fileu.fpos, fileu.fmax is of uncompressed data 1.1293 ++ * filec is not used 1.1294 ++ */ 1.1295 ++ 1.1296 ++ /* 1.1297 ++ * When dicPos>0, 1.1298 ++ * dic[0 ... dicPos-1] contains 1.1299 ++ * uncompressed_data [dicFilePos ... dicFilePos+dicPos-1]. 1.1300 ++ * When dicFilePos>0, 1.1301 ++ * dic[dicPos ... dicBufSize-1] contains 1.1302 ++ * uncompressed_data [dicFilePos-dicBufSize+dicFilePos ... dicFilePos-1] 1.1303 ++ */ 1.1304 ++ /* do we reset decompression to the beginning of the file? */ 1.1305 ++ if (lzmadec.dicFilePos && (lzmadec.fileu.fpos < lzmadec.dicFilePos-lzmadec.dicBufSize+lzmadec.dicFilePos)) 1.1306 ++ { 1.1307 ++ LzmaDec_Init(&lzmadec); 1.1308 ++ filepos = 13; 1.1309 ++ lzmadec.inpPos = lzmadec.inpSize = 0; 1.1310 ++ } 1.1311 ++ 1.1312 ++ outTx = 0; 1.1313 ++ outSkip = lzmadec.fileu.fpos - lzmadec.dicFilePos; 1.1314 ++ //grub_printf("fileu.fpos=%ld dicFilePos=%ld\n",lzmadec.fileu.fpos,lzmadec.dicFilePos); 1.1315 ++ 1.1316 ++ /* Copy uncompressed data from upper part of dic. dic[dicPos]...dic[dicBufSize-1] */ 1.1317 ++ if (lzmadec.dicFilePos > lzmadec.fileu.fpos) 1.1318 ++ { 1.1319 ++ UInt32 outTxCur = lzmadec.dicFilePos - lzmadec.fileu.fpos; 1.1320 ++ if (outTxCur > len) outTxCur = len; 1.1321 ++ if (buf) 1.1322 ++ { 1.1323 ++ grub_memmove(buf, lzmadec.dic+outSkip+lzmadec.dicBufSize, outTxCur); 1.1324 ++ buf += outTxCur; 1.1325 ++ } 1.1326 ++ outSkip = 0; 1.1327 ++ outTx += outTxCur; 1.1328 ++ lzmadec.fileu.fpos += outTxCur; 1.1329 ++ len -= outTxCur; 1.1330 ++ } 1.1331 ++ 1.1332 ++ while (len!=0) 1.1333 ++ { 1.1334 ++ SizeT inSizeCur, dicLimit; 1.1335 ++ UInt32 dicPos; 1.1336 ++ ELzmaStatus status; 1.1337 ++ SRes res; 1.1338 ++ 1.1339 ++ /* Copy uncompressed data from lower part of dic. dic[0]...dic[dicPos-1] */ 1.1340 ++ //grub_printf("Loop len=%ld outSkip=%ld dicPos=%d\n",len,outSkip,lzmadec.dicPos); 1.1341 ++ if (outSkip < lzmadec.dicPos) 1.1342 ++ { 1.1343 ++ UInt32 outTxCur = lzmadec.dicPos - outSkip; 1.1344 ++ //grub_printf("Copy %d byte ",outTxCur); 1.1345 ++ if (buf) 1.1346 ++ { 1.1347 ++ grub_memmove(buf, lzmadec.dic+outSkip, outTxCur); 1.1348 ++ buf += outTxCur; 1.1349 ++ } 1.1350 ++ outSkip = lzmadec.dicPos; 1.1351 ++ outTx += outTxCur; 1.1352 ++ lzmadec.fileu.fpos += outTxCur; 1.1353 ++ len -= outTxCur; 1.1354 ++ //grub_printf(" remaining len=%ld\n",len); 1.1355 ++ if (len==0) break; 1.1356 ++ } 1.1357 ++ /* All existing wanted data from dic have been copied. We will add more data to dic. */ 1.1358 ++ /* Read more input if there is no unprocessed input left. */ 1.1359 ++ if (lzmadec.inpPos == lzmadec.inpSize) 1.1360 ++ { 1.1361 ++ UInt32 inTxCur = (filemax-filepos<lzmadec.inpBufSize)?filemax-filepos:lzmadec.inpBufSize; 1.1362 ++ lzmadec.inpFilePos = filepos; 1.1363 ++ lzmadec.inpPos = 0; 1.1364 ++ //grub_printf("read inp %d ",inTxCur); 1.1365 ++ lzmadec.inpSize = grub_read(lzmadec.inp, inTxCur, 0xedde0d90); 1.1366 ++ //grub_printf("->%d\n",lzmadec.inpSize); 1.1367 ++ } 1.1368 ++ inSizeCur = lzmadec.inpSize - lzmadec.inpPos; 1.1369 ++ 1.1370 ++ /* Prepare output dicPos, dicLimit. */ 1.1371 ++ if (lzmadec.dicPos == lzmadec.dicBufSize) 1.1372 ++ { 1.1373 ++ lzmadec.dicPos = 0; 1.1374 ++ outSkip -= lzmadec.dicBufSize; 1.1375 ++ } 1.1376 ++ dicPos = lzmadec.dicPos; 1.1377 ++ dicLimit = (lzmadec.dicBufSize-dicPos < len)? lzmadec.dicBufSize: dicPos+len; 1.1378 ++ 1.1379 ++ /* Do decompression. */ 1.1380 ++ //grub_printf("DecodeToDic dicPos=%d limit=%d inPos=%d inSize=%d ",dicPos,dicLimit,lzmadec.inpPos,inSizeCur); 1.1381 ++ status = LZMA_STATUS_NOT_SPECIFIED; 1.1382 ++ res = LzmaDec_DecodeToDic(&lzmadec, dicLimit, lzmadec.inp+lzmadec.inpPos, &inSizeCur, LZMA_FINISH_ANY, &status); 1.1383 ++ //grub_printf("->%d\n",inSizeCur); 1.1384 ++ lzmadec.inpPos += inSizeCur; 1.1385 ++ if (inSizeCur==0 && lzmadec.dicPos==dicPos) 1.1386 ++ { 1.1387 ++ /* Error */ 1.1388 ++ //grub_printf("No more input and output\n"); 1.1389 ++ break; 1.1390 ++ } 1.1391 ++ } 1.1392 ++ compressed_file = 1; 1.1393 ++ lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax; 1.1394 ++ lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos; 1.1395 ++ /* Now filepos, file max is of uncompressed data 1.1396 ++ * filec.fpos, filwc.fmax is of compressed file 1.1397 ++ * fileu is not used 1.1398 ++ */ 1.1399 ++ 1.1400 ++ //grub_printf("LZMA read end %ld\n",outTx); 1.1401 ++ return outTx; 1.1402 ++} 1.1403 ++ 1.1404 ++#endif /* ! NO_DECOMPRESSION */ 1.1405 +diff -Naur ../grub4dos-chenall-r63/stage2/decomp.h ./stage2/decomp.h 1.1406 +--- grub4dos-chenall-r63/stage2/decomp.h 1970-01-01 07:00:00.000000000 +0700 1.1407 ++++ grub4dos/stage2/decomp.h 2010-11-28 13:51:54.687217000 +0700 1.1408 +@@ -0,0 +1,36 @@ 1.1409 ++/* decomp.h - abstract decompression interface */ 1.1410 ++/* 1.1411 ++ * GRUB -- GRand Unified Bootloader 1.1412 ++ * Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. 1.1413 ++ * 1.1414 ++ * This program is free software; you can redistribute it and/or modify 1.1415 ++ * it under the terms of the GNU General Public License as published by 1.1416 ++ * the Free Software Foundation; either version 2 of the License, or 1.1417 ++ * (at your option) any later version. 1.1418 ++ * 1.1419 ++ * This program is distributed in the hope that it will be useful, 1.1420 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.1421 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.1422 ++ * GNU General Public License for more details. 1.1423 ++ * 1.1424 ++ * You should have received a copy of the GNU General Public License 1.1425 ++ * along with this program; if not, write to the Free Software 1.1426 ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1.1427 ++ */ 1.1428 ++ 1.1429 ++#ifndef ASM_FILE 1.1430 ++ 1.1431 ++struct decomp_entry 1.1432 ++{ 1.1433 ++ char *name; 1.1434 ++ int (*open_func) (void); 1.1435 ++ void (*close_func) (void); 1.1436 ++ unsigned long (*read_func) (char *buf, unsigned long len, unsigned long write); 1.1437 ++}; 1.1438 ++ 1.1439 ++#define NUM_DECOM 2 1.1440 ++ 1.1441 ++extern struct decomp_entry decomp_table[NUM_DECOM]; 1.1442 ++extern int decomp_type; 1.1443 ++ 1.1444 ++#endif 1.1445 +\ No newline at end of file 1.1446 +diff -Naur ../grub4dos-chenall-r63/stage2/disk_io.c ./stage2/disk_io.c 1.1447 +--- grub4dos-chenall-r63/stage2/disk_io.c 2010-08-12 14:22:47.111207000 +0700 1.1448 ++++ grub4dos/stage2/disk_io.c 2010-11-28 20:26:39.089887300 +0700 1.1449 +@@ -21,6 +21,7 @@ 1.1450 + 1.1451 + #include <shared.h> 1.1452 + #include <filesys.h> 1.1453 ++#include <decomp.h> 1.1454 + #include <iso9660.h> 1.1455 + 1.1456 + #ifdef SUPPORT_NETBOOT 1.1457 +@@ -1872,7 +1873,16 @@ 1.1458 + #ifdef NO_DECOMPRESSION 1.1459 + return 1; 1.1460 + #else 1.1461 +- return gunzip_test_header (); 1.1462 ++ if (no_decompression) 1.1463 ++ return 1; 1.1464 ++ int i; 1.1465 ++ i = strlen(open_filename); 1.1466 ++ if (i>=5 && strcmp(open_filename+i-5,".lzma")==0) 1.1467 ++ dec_lzma_open (); 1.1468 ++ else 1.1469 ++ gunzip_test_header (); 1.1470 ++ errnum = 0; 1.1471 ++ return 1; 1.1472 + #endif 1.1473 + } 1.1474 + 1.1475 +@@ -1903,7 +1903,7 @@ 1.1476 + { 1.1477 + if (write == 0x900ddeed) 1.1478 + return !(errnum = ERR_WRITE_GZIP_FILE); 1.1479 +- return gunzip_read (buf, len); 1.1480 ++ return decomp_table[decomp_type].read_func (buf, len, write); 1.1481 + } 1.1482 + #endif /* NO_DECOMPRESSION */ 1.1483 + 1.1484 +@@ -1978,6 +1982,12 @@ 1.1485 + void 1.1486 + grub_close (void) 1.1487 + { 1.1488 ++#ifndef NO_DECOMPRESSION 1.1489 ++ if (compressed_file) 1.1490 ++ decomp_table[decomp_type].close_func (); 1.1491 ++ compressed_file = 0; 1.1492 ++#endif /* NO_DECOMPRESSION */ 1.1493 ++ 1.1494 + #ifndef NO_BLOCK_FILES 1.1495 + if (block_file) 1.1496 + return; 1.1497 +diff -Naur ../grub4dos-chenall-r63/stage2/gunzip.c ./stage2/gunzip.c 1.1498 +--- grub4dos-chenall-r63/stage2/gunzip.c 2010-07-26 19:35:48.440546000 +0700 1.1499 ++++ grub4dos/stage2/gunzip.c 2010-11-28 14:20:56.983870700 +0700 1.1500 +@@ -129,6 +129,8 @@ 1.1501 + 1.1502 + #include "filesys.h" 1.1503 + 1.1504 ++#include "decomp.h" 1.1505 ++ 1.1506 + /* so we can disable decompression */ 1.1507 + #ifdef GRUB_UTIL 1.1508 + int no_decompression = 0; 1.1509 +@@ -137,6 +139,15 @@ 1.1510 + /* used to tell if "read" should be redirected to "gunzip_read" */ 1.1511 + int compressed_file; 1.1512 + 1.1513 ++/* identify active decompressor */ 1.1514 ++int decomp_type; 1.1515 ++ 1.1516 ++struct decomp_entry decomp_table[NUM_DECOM] = 1.1517 ++{ 1.1518 ++ {"gz",gunzip_test_header,gunzip_close,gunzip_read}, 1.1519 ++ {"lzma",dec_lzma_open,dec_lzma_close,dec_lzma_read} 1.1520 ++}; 1.1521 ++ 1.1522 + /* internal variables only */ 1.1523 + static unsigned long long gzip_data_offset; 1.1524 + static unsigned long long gzip_filepos; 1.1525 +@@ -227,6 +238,7 @@ 1.1526 + /* Little-Endian defines for the 2-byte magic number for gzip files */ 1.1527 + #define GZIP_HDR_LE 0x8B1F 1.1528 + #define OLD_GZIP_HDR_LE 0x9E1F 1.1529 ++#define LZMA_HDR_LE 0x005D 1.1530 + 1.1531 + /* Compression methods (see algorithm.doc) */ 1.1532 + #define STORED 0 1.1533 +@@ -281,10 +292,18 @@ 1.1534 + if (no_decompression 1.1535 + || grub_read ((char *)buf, 10, 0xedde0d90) != 10 1.1536 + || ((*((unsigned short *) buf) != GZIP_HDR_LE) 1.1537 +- && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE))) 1.1538 ++ && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE) 1.1539 ++ && (*((unsigned short *) buf) != LZMA_HDR_LE))) 1.1540 + { 1.1541 + filepos = 0; 1.1542 + return ! errnum; 1.1543 ++ } 1.1544 ++ 1.1545 ++ if (*((unsigned short *) buf) == LZMA_HDR_LE) 1.1546 ++ { 1.1547 ++ filepos = 0; 1.1548 ++ dec_lzma_open(); 1.1549 ++ return 1; 1.1550 + } 1.1551 + 1.1552 + /* 1.1553 +@@ -323,6 +334,7 @@ 1.1554 + 1.1555 + initialize_tables (); 1.1556 + 1.1557 ++ decomp_type = 0; 1.1558 + compressed_file = 1; 1.1559 + gunzip_swap_values (); 1.1560 + /* 1.1561 +@@ -334,6 +346,11 @@ 1.1562 + return 1; 1.1563 + } 1.1564 + 1.1565 ++void 1.1566 ++gunzip_close (void) 1.1567 ++{ 1.1568 ++} 1.1569 ++ 1.1570 + 1.1571 + /* Huffman code lookup table entry--this entry is four bytes for machines 1.1572 + that have 16-bit pointers (e.g. PC's in the small or medium model). 1.1573 +@@ -1190,7 +1226,7 @@ 1.1574 + 1.1575 + 1.1576 + unsigned long 1.1577 +-gunzip_read (char *buf, unsigned long len) 1.1578 ++gunzip_read (char *buf, unsigned long len, unsigned long write) 1.1579 + { 1.1580 + unsigned long ret = 0; 1.1581 + 1.1582 +diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.am ./stage2/Makefile.am 1.1583 +--- grub4dos-chenall-r63/stage2/Makefile.am 2010-08-12 14:22:47.111207000 +0700 1.1584 ++++ grub4dos/stage2/Makefile.am 2010-11-28 16:35:18.724975900 +0700 1.1585 +@@ -16,6 +16,7 @@ 1.1586 + # The library for /sbin/grub. 1.1587 + noinst_LIBRARIES = libgrub.a 1.1588 + libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \ 1.1589 ++ dec_lzma.c \ 1.1590 + disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \ 1.1591 + fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \ 1.1592 + fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \ 1.1593 +@@ -100,7 +101,7 @@ 1.1594 + 1.1595 + # For stage2 target. 1.1596 + pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \ 1.1597 +- cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \ 1.1598 ++ cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \ 1.1599 + fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \ 1.1600 + fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \ 1.1601 + hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c 1.1602 +diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.in ./stage2/Makefile.in 1.1603 +--- grub4dos-chenall-r63/stage2/Makefile.in 2010-08-12 14:22:47.111207000 +0700 1.1604 ++++ grub4dos/stage2/Makefile.in 2010-11-28 16:38:22.871508400 +0700 1.1605 +@@ -104,10 +104,11 @@ 1.1606 + am_libgrub_a_OBJECTS = libgrub_a-boot.$(OBJEXT) \ 1.1607 + libgrub_a-builtins.$(OBJEXT) libgrub_a-char_io.$(OBJEXT) \ 1.1608 + libgrub_a-cmdline.$(OBJEXT) libgrub_a-common.$(OBJEXT) \ 1.1609 +- libgrub_a-disk_io.$(OBJEXT) libgrub_a-fsys_ext2fs.$(OBJEXT) \ 1.1610 +- libgrub_a-fsys_fat.$(OBJEXT) libgrub_a-fsys_ntfs.$(OBJEXT) \ 1.1611 +- libgrub_a-fsys_ffs.$(OBJEXT) libgrub_a-fsys_iso9660.$(OBJEXT) \ 1.1612 +- libgrub_a-fsys_jfs.$(OBJEXT) libgrub_a-fsys_minix.$(OBJEXT) \ 1.1613 ++ libgrub_a-dec_lzma.$(OBJEXT) libgrub_a-disk_io.$(OBJEXT) \ 1.1614 ++ libgrub_a-fsys_ext2fs.$(OBJEXT) libgrub_a-fsys_fat.$(OBJEXT) \ 1.1615 ++ libgrub_a-fsys_ntfs.$(OBJEXT) libgrub_a-fsys_ffs.$(OBJEXT) \ 1.1616 ++ libgrub_a-fsys_iso9660.$(OBJEXT) libgrub_a-fsys_jfs.$(OBJEXT) \ 1.1617 ++ libgrub_a-fsys_minix.$(OBJEXT) \ 1.1618 + libgrub_a-fsys_reiserfs.$(OBJEXT) \ 1.1619 + libgrub_a-fsys_ufs2.$(OBJEXT) libgrub_a-fsys_vstafs.$(OBJEXT) \ 1.1620 + libgrub_a-fsys_xfs.$(OBJEXT) libgrub_a-fsys_pxe.$(OBJEXT) \ 1.1621 +@@ -131,6 +132,7 @@ 1.1622 + diskless_exec-char_io.$(OBJEXT) \ 1.1623 + diskless_exec-cmdline.$(OBJEXT) diskless_exec-common.$(OBJEXT) \ 1.1624 + diskless_exec-console.$(OBJEXT) \ 1.1625 ++ diskless_exec-dec_lzma.$(OBJEXT) \ 1.1626 + diskless_exec-disk_io.$(OBJEXT) \ 1.1627 + diskless_exec-fsys_ext2fs.$(OBJEXT) \ 1.1628 + diskless_exec-fsys_fat.$(OBJEXT) \ 1.1629 +@@ -247,6 +249,7 @@ 1.1630 + pre_stage2_exec-cmdline.$(OBJEXT) \ 1.1631 + pre_stage2_exec-common.$(OBJEXT) \ 1.1632 + pre_stage2_exec-console.$(OBJEXT) \ 1.1633 ++ pre_stage2_exec-dec_lzma.$(OBJEXT) \ 1.1634 + pre_stage2_exec-disk_io.$(OBJEXT) \ 1.1635 + pre_stage2_exec-fsys_ext2fs.$(OBJEXT) \ 1.1636 + pre_stage2_exec-fsys_fat.$(OBJEXT) \ 1.1637 +@@ -512,6 +513,7 @@ 1.1638 + # The library for /sbin/grub. 1.1639 + noinst_LIBRARIES = libgrub.a 1.1640 + libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \ 1.1641 ++ dec_lzma.c \ 1.1642 + disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \ 1.1643 + fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \ 1.1644 + fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \ 1.1645 +@@ -559,7 +563,7 @@ 1.1646 + 1.1647 + # For stage2 target. 1.1648 + pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \ 1.1649 +- cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \ 1.1650 ++ cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \ 1.1651 + fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \ 1.1652 + fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \ 1.1653 + hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c 1.1654 +@@ -878,6 +882,7 @@ 1.1655 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-cmdline.Po@am__quote@ 1.1656 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-common.Po@am__quote@ 1.1657 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-console.Po@am__quote@ 1.1658 ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-dec_lzma.Po@am__quote@ 1.1659 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-disk_io.Po@am__quote@ 1.1660 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_ext2fs.Po@am__quote@ 1.1661 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_fat.Po@am__quote@ 1.1662 +@@ -935,6 +940,7 @@ 1.1663 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-char_io.Po@am__quote@ 1.1664 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-cmdline.Po@am__quote@ 1.1665 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-common.Po@am__quote@ 1.1666 ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-dec_lzma.Po@am__quote@ 1.1667 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-disk_io.Po@am__quote@ 1.1668 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_ext2fs.Po@am__quote@ 1.1669 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_fat.Po@am__quote@ 1.1670 +@@ -974,6 +980,7 @@ 1.1671 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-cmdline.Po@am__quote@ 1.1672 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-common.Po@am__quote@ 1.1673 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-console.Po@am__quote@ 1.1674 ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-dec_lzma.Po@am__quote@ 1.1675 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-disk_io.Po@am__quote@ 1.1676 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_ext2fs.Po@am__quote@ 1.1677 + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_fat.Po@am__quote@ 1.1678 +@@ -1315,6 +1322,20 @@ 1.1679 + @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1680 + @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` 1.1681 + 1.1682 ++libgrub_a-dec_lzma.o: dec_lzma.c 1.1683 ++@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; \ 1.1684 ++@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 1.1685 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.o' libtool=no @AMDEPBACKSLASH@ 1.1686 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1687 ++@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 1.1688 ++ 1.1689 ++libgrub_a-dec_lzma.obj: dec_lzma.c 1.1690 ++@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`; \ 1.1691 ++@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 1.1692 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@ 1.1693 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1694 ++@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` 1.1695 ++ 1.1696 + libgrub_a-disk_io.o: disk_io.c 1.1697 + @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; \ 1.1698 + @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 1.1699 +@@ -1693,6 +1714,20 @@ 1.1700 + @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1701 + @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` 1.1702 + 1.1703 ++diskless_exec-dec_lzma.o: dec_lzma.c 1.1704 ++@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; \ 1.1705 ++@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 1.1706 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@ 1.1707 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1708 ++@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 1.1709 ++ 1.1710 ++diskless_exec-dec_lzma.obj: dec_lzma.c 1.1711 ++@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`; \ 1.1712 ++@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 1.1713 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@ 1.1714 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1715 ++@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` 1.1716 ++ 1.1717 + diskless_exec-disk_io.o: disk_io.c 1.1718 + @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; \ 1.1719 + @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 1.1720 +@@ -2687,6 +2722,20 @@ 1.1721 + @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1722 + @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` 1.1723 + 1.1724 ++pre_stage2_exec-dec_lzma.o: dec_lzma.c 1.1725 ++@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; \ 1.1726 ++@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 1.1727 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@ 1.1728 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1729 ++@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 1.1730 ++ 1.1731 ++pre_stage2_exec-dec_lzma.obj: dec_lzma.c 1.1732 ++@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`; \ 1.1733 ++@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 1.1734 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@ 1.1735 ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1.1736 ++@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` 1.1737 ++ 1.1738 + pre_stage2_exec-disk_io.o: disk_io.c 1.1739 + @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; \ 1.1740 + @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 1.1741 +diff -Naur ../grub4dos-chenall-r63/stage2/shared.h ./stage2/shared.h 1.1742 +--- grub4dos-chenall-r63/stage2/shared.h 2010-11-17 15:33:51.826683000 +0700 1.1743 ++++ grub4dos/stage2/shared.h 2010-11-27 01:16:46.996893700 +0700 1.1744 +@@ -640,6 +640,7 @@ 1.1745 + ERR_WRITE_GZIP_FILE, 1.1746 + ERR_FUNC_CALL, 1.1747 + // ERR_WRITE_TO_NON_MEM_DRIVE, 1.1748 ++ ERR_NOT_ENOUGH_MEMORY, 1.1749 + 1.1750 + MAX_ERR_NUM 1.1751 + } grub_error_t; 1.1752 +@@ -1185,7 +1186,11 @@ 1.1753 + #ifndef NO_DECOMPRESSION 1.1754 + /* Compression support. */ 1.1755 + int gunzip_test_header (void); 1.1756 +-unsigned long gunzip_read (char *buf, unsigned long len); 1.1757 ++void gunzip_close (void); 1.1758 ++unsigned long gunzip_read (char *buf, unsigned long len, unsigned long write); 1.1759 ++int dec_lzma_open (void); 1.1760 ++void dec_lzma_close (void); 1.1761 ++unsigned long dec_lzma_read (char *buf, unsigned long len, unsigned long write); 1.1762 + #endif /* NO_DECOMPRESSION */ 1.1763 + 1.1764 + int rawread (unsigned long drive, unsigned long sector, unsigned long byte_offset, unsigned long byte_len, char *buf, unsigned long write);