Index: src/superio/ite/it8716f/superio.c
===================================================================
--- src/superio/ite/it8716f/superio.c	(revision 3118)
+++ src/superio/ite/it8716f/superio.c	(working copy)
@@ -113,6 +122,12 @@
 		res1 = find_resource(dev, PNP_IDX_IO1);
 		init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
 		break;
+#if CONFIG_PIOROM_PAYLOAD
+	case IT8716F_GPIO:
+		res0 = find_resource(dev, PNP_IDX_IO2);
+		init_gpio(res0->base);
+		break;
+#endif
 	}
 }
 
Index: src/stream/Config.lb
===================================================================
--- src/stream/Config.lb	(revision 3118)
+++ src/stream/Config.lb	(working copy)
@@ -1,9 +1,18 @@
 uses CONFIG_ROM_PAYLOAD
+uses CONFIG_PIOROM_PAYLOAD
 uses CONFIG_IDE_PAYLOAD
 uses CONFIG_FS_PAYLOAD
 uses CONFIG_IDE
 uses CONFIG_SERIAL_PAYLOAD
 
+if CONFIG_PIOROM_PAYLOAD
+#  if (ROM_SIZE > 512*1024)
+    object piorom_stream.o
+#  else
+#    object rom_stream.o
+#  end
+end
+
 if CONFIG_ROM_PAYLOAD
   object rom_stream.o
 end
Index: src/stream/piorom_stream.c
===================================================================
--- src/stream/piorom_stream.c	(revision 0)
+++ src/stream/piorom_stream.c	(revision 0)
@@ -0,0 +1,199 @@
+#if ROM_SIZE <= 512*1024
+#include "rom_stream.c"
+#else
+#include <console/console.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stream/read_bytes.h>
+#include <string.h>
+
+/* if they set the precompressed rom stream, they better have set a type */
+#if CONFIG_PRECOMPRESSED_PAYLOAD && ((!CONFIG_COMPRESSED_PAYLOAD_NRV2B) && (!CONFIG_COMPRESSED_PAYLOAD_LZMA))
+#error "You set CONFIG_PRECOMPRESSED_PAYLOAD but need to set CONFIG_COMPRESSED_PAYLOAD_NRV2B or CONFIG_COMPRESSED_PAYLOAD_LZMA"
+#endif
+
+/* If they set ANY of these, then we're compressed */
+#if ((CONFIG_COMPRESSED_PAYLOAD_NRV2B) || (CONFIG_COMPRESSED_PAYLOAD_LZMA))
+#define UNCOMPRESSER 1
+extern unsigned char _heap, _eheap;
+
+/* this here is it8716 specific */
+#include <arch/io.h>
+
+extern unsigned it8716f_spi_flash_base;
+static uint32_t address;
+
+#define IN_CHUNK_SIZE 3
+#define JEDEC_READ	0x03
+
+static void init_pioread(void *src)
+{
+	uint8_t busy, writeenc;
+	int size;
+
+	address=(uint32_t)src;
+	do {
+		busy = inb(it8716f_spi_flash_base) & 0x80;
+	} while (busy);
+
+	outb(JEDEC_READ, it8716f_spi_flash_base + 1);
+	outb((address >> 0) & 0xff, it8716f_spi_flash_base + 2);
+	outb((address >> 8) & 0xff, it8716f_spi_flash_base + 3);
+	outb((address >> 16) & 0xff, it8716f_spi_flash_base + 4);
+	size=3;
+	writeenc = 0x2;
+	outb(((0x4) << 4) | (size << 2) | (writeenc), it8716f_spi_flash_base);
+}
+
+static void get_chunk(uint8_t *dest, int size)
+{
+	uint8_t busy, writeenc;
+	int i;
+
+	size&=3;
+	do {
+		busy = inb(it8716f_spi_flash_base) & 0x80;
+	} while (busy);
+
+	for (i = 0; i < size; i++) {
+		dest[i] = inb(it8716f_spi_flash_base + 5 + i);
+	}
+	address+=size;
+
+	outb(JEDEC_READ, it8716f_spi_flash_base + 1);
+	outb((address >> 0) & 0xff, it8716f_spi_flash_base + 2);
+	outb((address >> 8) & 0xff, it8716f_spi_flash_base + 3);
+	outb((address >> 16) & 0xff, it8716f_spi_flash_base + 4);
+	size=3;
+	writeenc = 0x2;
+	outb(((0x4) << 4) | (size << 2) | (writeenc), it8716f_spi_flash_base);
+}
+#endif
+
+#if (CONFIG_COMPRESSED_PAYLOAD_NRV2B) 
+#define HAVE_UNCOMPRESSER 1
+// include generic nrv2b
+#error "nrv2b is not supported for piorom (yet...?)"
+#include "../lib/nrv2b.c"
+#endif
+
+#if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
+#if HAVE_UNCOMPRESSER
+#error "You're defining more than one compression type, which is not allowed (of course)"
+#endif
+#define HAVE_UNCOMPRESSER 1
+// include generic lzma with callback
+#include "../lib/lzma_cb.c"
+#endif
+
+#ifndef CONFIG_ROM_PAYLOAD_START
+#define CONFIG_ROM_PAYLOAD_START 0xffff0000UL
+#endif
+
+/* well, this is a mess, and it will get fixed, but not right away.
+ * until we stop using 'ld' for building the rom image, that is.
+ * problem is, that on the sc520, ROM_PAYLOAD_START has to be at 0x2000000.
+ * but if you set CONFIG_ROM_PAYLOAD_START to that, then ld will try to
+ * build a giant image: 0x0-0x2000000, i.e. almost 4 GB.
+ * so make this non-static, non-const for now.
+ */
+
+/*XXXXXXXXXXXXXX */
+/*static const */unsigned char *rom_start = (unsigned char *)CONFIG_ROM_PAYLOAD_START;
+/*static const */unsigned char *rom_end   = (unsigned char *)(CONFIG_ROM_PAYLOAD_START + PAYLOAD_SIZE - 1);
+/*XXXXXXXXXXXXXX */
+
+static const unsigned char *rom;
+
+#if UNCOMPRESSER
+static inline unsigned long 
+uncompress(uint8_t * rom_start, uint8_t *dest )
+{
+	init_pioread(rom_start);
+#if (CONFIG_COMPRESSED_PAYLOAD_NRV2B) 
+	unsigned long ilen; // used compressed stream length
+	return unrv2b(rom_start, dest, &ilen);
+#endif
+#if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
+	return ulzma(dest);
+#endif
+}
+#endif
+int stream_init(void)
+{
+#if (UNCOMPRESSER)
+        unsigned char *dest;
+        unsigned long olen;
+#endif
+
+	printk_debug("rom_stream: 0x%08lx - 0x%08lx\n",
+		(unsigned long)rom_start,
+		(unsigned long)rom_end);
+
+#if (UNCOMPRESSER) 
+#if 0
+        dest = &_eheap; /* need a good address on RAM */
+
+#if _RAMBASE<0x00100000
+	olen = *(unsigned int *)dest;
+#if (CONFIG_CONSOLE_VGA==1) || (CONFIG_PCI_ROM_RUN == 1)
+	if((dest < 0xa0000) && ((dest+olen)>0xa0000)) {
+		dest = (CONFIG_LB_MEM_TOPK<<10);
+	}
+#endif
+        if((dest < (unsigned char *) 0xf0000) && ((dest+olen)> (unsigned char *)0xf0000)) { // coreboot tables etc
+	  dest = (unsigned char *) (CONFIG_LB_MEM_TOPK<<10);
+        }
+#endif
+#else
+	/* ALL of those settings are too smart and also unsafe. Set the dest to 16 MB: 
+	 * known to be safe for LB for now, and mostly safe for all elf images we have tried. 
+	 * long term, this has got to be fixed. 
+	 */
+	dest  = (unsigned char *) (16 * 1024 * 1024);
+#endif
+        printk_debug("Uncompressing to RAM 0x%08lx ", dest);
+        olen = uncompress((uint8_t *) rom_start, (uint8_t *)dest );
+	printk_debug(" olen = 0x%08lx done.\n", olen);
+	rom_end = dest + olen - 1;
+	rom = dest;
+#else
+        rom = rom_start;
+#endif
+
+	return 0;
+}
+
+
+void stream_fini(void)
+{
+	return;
+}
+
+byte_offset_t stream_skip(byte_offset_t count)
+{
+	byte_offset_t bytes;
+	bytes = count;
+	if ((rom + bytes - 1) > rom_end) {
+		printk_warning("%6d:%s() - overflowed source buffer\n",
+			__LINE__, __FUNCTION__);
+		bytes = 0;
+		if (rom <= rom_end) {
+			bytes = (rom_end - rom) + 1;
+		}
+	}
+	rom += bytes;
+	return bytes;
+}
+
+byte_offset_t stream_read(void *vdest, byte_offset_t count)
+{
+	unsigned char *dest = vdest;
+	const unsigned char *src = rom;
+	byte_offset_t bytes;
+
+	bytes = stream_skip(count);
+	memcpy(dest, src, bytes);
+	return bytes;
+}
+#endif
Index: src/mainboard/gigabyte/m57sli/Options.lb
===================================================================
--- src/mainboard/gigabyte/m57sli/Options.lb	(revision 3118)
+++ src/mainboard/gigabyte/m57sli/Options.lb	(working copy)
@@ -42,7 +42,7 @@
 uses ROM_IMAGE_SIZE
 uses ROM_SECTION_SIZE
 uses ROM_SECTION_OFFSET
-uses CONFIG_ROM_PAYLOAD
+uses CONFIG_PIOROM_PAYLOAD
 uses CONFIG_ROM_PAYLOAD_START
 uses CONFIG_COMPRESSED_PAYLOAD_NRV2B
 uses CONFIG_COMPRESSED_PAYLOAD_LZMA
@@ -80,6 +80,7 @@
 uses OBJCOPY
 uses CONFIG_CHIP_NAME
 uses CONFIG_CONSOLE_VGA
+uses CONFIG_VGA_ROM_RUN
 uses CONFIG_USBDEBUG_DIRECT
 uses CONFIG_PCI_ROM_RUN
 uses HW_MEM_HOLE_SIZEK
@@ -217,7 +218,8 @@
 
 #VGA Console
 default CONFIG_CONSOLE_VGA=1
-default CONFIG_PCI_ROM_RUN=1
+default CONFIG_VGA_ROM_RUN=1
+default CONFIG_PCI_ROM_RUN=0
 
 #default CONFIG_USBDEBUG_DIRECT=1
 
@@ -290,9 +292,9 @@
 default _RAMBASE=0x00100000
 
 ##
-## Load the payload from the ROM
+## Load the payload from the ROM using PIO if needed
 ##
-default CONFIG_ROM_PAYLOAD = 1
+default CONFIG_PIOROM_PAYLOAD = 1
 
 #default CONFIG_COMPRESSED_PAYLOAD_NRV2B = 1
 
Index: src/config/Options.lb
===================================================================
--- src/config/Options.lb	(revision 3118)
+++ src/config/Options.lb	(working copy)
@@ -613,6 +613,11 @@
 	export always
 	comment "Boot image is located in ROM" 
 end
+define CONFIG_PIOROM_PAYLOAD
+	default 0
+	export always
+	comment "Boot image is located in ROM, use PIO method for reading it" 
+end
 define CONFIG_ROM_PAYLOAD_START
 	default {0xffffffff - ROM_SIZE + ROM_SECTION_OFFSET + 1}
 	format "0x%x"
Index: src/lib/lzma_cb.c
===================================================================
--- src/lib/lzma_cb.c	(revision 0)
+++ src/lib/lzma_cb.c	(revision 0)
@@ -0,0 +1,49 @@
+/* 
+
+Coreboot interface to memory-saving variant of LZMA decoder
+(C)opyright 2006 Carl-Daniel Hailfinger
+(c)2008 Reworked to chunk mode by Ronald Hoogenboom
+Released under the GNU GPL
+
+*/
+
+#define _LZMA_IN_CB
+
+#include "lzmadecode.c"
+
+static unsigned char scratchpad[15980];
+static CLzmaDecoderState state;
+static UInt32 outSize;
+unsigned char src[IN_CHUNK_SIZE];
+
+static unsigned long ulzma(unsigned char *dst)
+{
+	unsigned char properties[LZMA_PROPERTIES_SIZE+8];
+	SizeT mallocneeds;
+	SizeT outProcessed=0;
+	int res;
+	int i;
+
+	for (i = 0; i < sizeof properties; i+=IN_CHUNK_SIZE) {
+		int toread=IN_CHUNK_SIZE;
+		if (sizeof properties < toread+i) toread=sizeof properties-i;
+		get_chunk(properties+i, toread);
+	}
+	outSize = *(UInt32 *)(properties + LZMA_PROPERTIES_SIZE);
+	if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
+		printk_warning("Incorrect stream properties\n");
+	}
+	mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
+	if (mallocneeds > sizeof scratchpad) {
+		printk_warning("Decoder scratchpad too small! needs %u, has %u\n",mallocneeds, sizeof scratchpad);
+	}
+	state.Probs = (CProb *)scratchpad;
+	state.BufferLim=state.Buffer=src+IN_CHUNK_SIZE;
+
+	res = LzmaDecode(&state, get_chunk,
+			dst, outSize, &outProcessed);
+	if (res != 0) {
+		printk_warning("Decoding error = %d\n", res);
+	}
+	return outProcessed;
+}
Index: src/lib/lzmadecode.c
===================================================================
--- src/lib/lzmadecode.c	(revision 3118)
+++ src/lib/lzmadecode.c	(working copy)
@@ -33,11 +33,37 @@
 #define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
   { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
 
+#ifdef _LZMA_OUT_READ
 
-#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
+#define RC_PUT_BYTE(x) outStream[nowPos++] = dictionary[dictionaryPos] = (x); \
+  { if (++dictionaryPos == dictionarySize) dictionaryPos = 0; }
 
+#define GET_DICT(x) dictionary[({ UInt32 pos=dictionaryPos - (x); \
+  if (pos >= dictionarySize) pos+=dictionarySize; pos; })]
+
+#else
+
+#define RC_PUT_BYTE(x) outStream[nowPos++] = (x)
+
+#define GET_DICT(x) outStream[nowPos - (x)]
+
+#endif
+
+#ifdef _LZMA_IN_CB
+
+#define RC_TEST { if (Buffer == BufferLim) \
+  { Buffer = BufferLim - IN_CHUNK_SIZE; \
+	  InCallback((Byte *)Buffer, IN_CHUNK_SIZE); }}
+
+#define RC_INIT RC_INIT2
+
+#else
+
+#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR+3; }
+
 #define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
  
+#endif
 
 #define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
 
@@ -49,7 +75,7 @@
   { UpdateBit0(p); mi <<= 1; A0; } else \
   { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 
   
-#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               
+#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
 
 #define RangeDecoderBitTreeDecode(probs, numLevels, res) \
   { int i = numLevels; res = 1; \
@@ -127,13 +153,28 @@
     */
   }
 
+  #ifdef _LZMA_OUT_READ
+  {
+    int i;
+    propsRes->DictionarySize = 0;
+    for (i = 0; i < 4; i++)
+      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
+    if (propsRes->DictionarySize == 0)
+      propsRes->DictionarySize = 1;
+	printf("dictionarySize=%u\n",propsRes->DictionarySize);
+  }
+  #endif
   return LZMA_RESULT_OK;
 }
 
 #define kLzmaStreamWasFinishedId (-1)
 
 int LzmaDecode(CLzmaDecoderState *vs,
+    #ifdef _LZMA_IN_CB
+    ILzmaInCallback *InCallback,
+    #else
     const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
+    #endif
     unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
 {
   CProb *p = vs->Probs;
@@ -143,16 +184,85 @@
   UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
   int lc = vs->Properties.lc;
 
+  #ifdef _LZMA_IN_CB
+  const Byte *Buffer = vs->Buffer;
+  const Byte *BufferLim = vs->BufferLim;
+  #else
+  const Byte *Buffer = inStream;
+  const Byte *BufferLim = inStream + inSize;
+  #endif
+  #ifdef _LZMA_OUT_READ
 
+  UInt32 Range = vs->Range;
+  UInt32 Code = vs->Code;
+  int state = vs->State;
+  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
+  int len = vs->RemainLen;
+  UInt32 globalPos = vs->GlobalPos;
+  UInt32 distanceLimit = vs->DistanceLimit;
+
+  Byte *dictionary = vs->Dictionary;
+  UInt32 dictionarySize = vs->Properties.DictionarySize;
+  UInt32 dictionaryPos = vs->DictionaryPos;
+
+  Byte tempDictionary[4];
+
+  #ifndef _LZMA_IN_CB
+  *inSizeProcessed = 0;
+  #endif
+  *outSizeProcessed = 0;
+  if (len == kLzmaStreamWasFinishedId)
+    return LZMA_RESULT_OK;
+
+  if (dictionarySize == 0)
+  {
+    dictionary = tempDictionary;
+    dictionarySize = 1;
+    tempDictionary[0] = vs->TempDictionary[0];
+  }
+
+  if (len == kLzmaNeedInitId)
+  {
+    {
+      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
+      UInt32 i;
+      for (i = 0; i < numProbs; i++)
+        p[i] = kBitModelTotal >> 1; 
+      rep0 = rep1 = rep2 = rep3 = 1;
+      state = 0;
+      globalPos = 0;
+      distanceLimit = 0;
+      dictionaryPos = 0;
+      dictionary[dictionarySize - 1] = 0;
+      #ifdef _LZMA_IN_CB
+      RC_INIT;
+      #else
+      RC_INIT(inStream, inSize);
+      #endif
+    }
+    len = 0;
+  }
+  while(len != 0 && nowPos < outSize)
+  {
+	RC_PUT_BYTE(GET_DICT(rep0));
+    len--;
+  }
+  if (dictionaryPos == 0)
+    previousByte = dictionary[dictionarySize - 1];
+  else
+    previousByte = dictionary[dictionaryPos - 1];
+
+  #else /* if !_LZMA_OUT_READ */
+
   int state = 0;
   UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
   int len = 0;
-  const Byte *Buffer;
-  const Byte *BufferLim;
   UInt32 Range;
   UInt32 Code;
 
+  #ifndef _LZMA_IN_CB
   *inSizeProcessed = 0;
+  #endif
   *outSizeProcessed = 0;
 
   {
@@ -162,8 +272,13 @@
       p[i] = kBitModelTotal >> 1;
   }
   
+  #ifdef _LZMA_IN_CB
+  RC_INIT;
+  #else
   RC_INIT(inStream, inSize);
+  #endif
 
+  #endif /* _LZMA_OUT_READ */
 
   while(nowPos < outSize)
   {
@@ -171,6 +286,9 @@
     UInt32 bound;
     int posState = (int)(
         (nowPos 
+        #ifdef _LZMA_OUT_READ
+        + globalPos
+        #endif
         )
         & posStateMask);
 
@@ -182,13 +300,16 @@
       prob = p + Literal + (LZMA_LIT_SIZE * 
         (((
         (nowPos 
+        #ifdef _LZMA_OUT_READ
+        + globalPos
+        #endif
         )
         & literalPosMask) << lc) + (previousByte >> (8 - lc))));
 
       if (state >= kNumLitStates)
       {
         int matchByte;
-        matchByte = outStream[nowPos - rep0];
+        matchByte = GET_DICT(rep0);
         do
         {
           int bit;
@@ -207,12 +328,16 @@
       }
       previousByte = (Byte)symbol;
 
-      outStream[nowPos++] = previousByte;
+	  RC_PUT_BYTE(previousByte);
+      #ifdef _LZMA_OUT_READ
+      if (distanceLimit < dictionarySize)
+        distanceLimit++;
+      #endif
       if (state < 4) state = 0;
       else if (state < 10) state -= 3;
       else state -= 6;
     }
-    else             
+    else
     {
       UpdateBit1(prob);
       prob = p + IsRep + state;
@@ -236,13 +361,21 @@
           IfBit0(prob)
           {
             UpdateBit0(prob);
-            
+
+            #ifdef _LZMA_OUT_READ
+            if (distanceLimit == 0)
+            #else
             if (nowPos == 0)
-              return LZMA_RESULT_DATA_ERROR;
-            
+            #endif
+              return LZMA_RESULT_DATA_ERROR+1;
+
             state = state < kNumLitStates ? 9 : 11;
-            previousByte = outStream[nowPos - rep0];
-            outStream[nowPos++] = previousByte;
+			previousByte=GET_DICT(rep0);
+			RC_PUT_BYTE(previousByte);
+            #ifdef _LZMA_OUT_READ
+            if (distanceLimit < dictionarySize)
+              distanceLimit++;
+            #endif
 
             continue;
           }
@@ -376,23 +509,52 @@
       }
 
       len += kMatchMinLen;
+      #ifdef _LZMA_OUT_READ
+      if (rep0 > distanceLimit) 
+      #else
       if (rep0 > nowPos)
-        return LZMA_RESULT_DATA_ERROR;
+      #endif
+        return LZMA_RESULT_DATA_ERROR+2;
 
+      #ifdef _LZMA_OUT_READ
+      if (dictionarySize - distanceLimit > (UInt32)len)
+        distanceLimit += len;
+      else
+        distanceLimit = dictionarySize;
+      #endif
 
       do
       {
-        previousByte = outStream[nowPos - rep0];
+		previousByte=GET_DICT(rep0);
+		RC_PUT_BYTE(previousByte);
         len--;
-        outStream[nowPos++] = previousByte;
       }
       while(len != 0 && nowPos < outSize);
     }
   }
   RC_NORMALIZE;
 
+  #ifdef _LZMA_OUT_READ
+  vs->Range = Range;
+  vs->Code = Code;
+  vs->DictionaryPos = dictionaryPos;
+  vs->GlobalPos = globalPos + (UInt32)nowPos;
+  vs->DistanceLimit = distanceLimit;
+  vs->Reps[0] = rep0;
+  vs->Reps[1] = rep1;
+  vs->Reps[2] = rep2;
+  vs->Reps[3] = rep3;
+  vs->State = state;
+  vs->RemainLen = len;
+  vs->TempDictionary[0] = tempDictionary[0];
+  #endif
 
+  #ifdef _LZMA_IN_CB
+  vs->Buffer = Buffer;
+  vs->BufferLim = BufferLim;
+  #else
   *inSizeProcessed = (SizeT)(Buffer - inStream);
+  #endif
   *outSizeProcessed = nowPos;
   return LZMA_RESULT_OK;
 }
Index: src/lib/lzmadecode.h
===================================================================
--- src/lib/lzmadecode.h	(revision 3118)
+++ src/lib/lzmadecode.h	(working copy)
@@ -32,6 +32,9 @@
 #define LZMA_RESULT_OK 0
 #define LZMA_RESULT_DATA_ERROR 1
 
+#ifdef _LZMA_IN_CB
+typedef void (ILzmaInCallback)(unsigned char *buffer, int bufferSize);
+#endif
 
 #define LZMA_BASE_SIZE 1846
 #define LZMA_LIT_SIZE 768
@@ -43,6 +46,9 @@
   int lc;
   int lp;
   int pb;
+  #ifdef _LZMA_OUT_READ
+  UInt32 DictionarySize;
+  #endif
 }CLzmaProperties;
 
 int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
@@ -56,12 +62,35 @@
   CLzmaProperties Properties;
   CProb *Probs;
 
+  #ifdef _LZMA_IN_CB
+  const unsigned char *Buffer;
+  const unsigned char *BufferLim;
+  #endif
 
+  #ifdef _LZMA_OUT_READ
+  unsigned char *Dictionary;
+  UInt32 Range;
+  UInt32 Code;
+  UInt32 DictionaryPos;
+  UInt32 GlobalPos;
+  UInt32 DistanceLimit;
+  UInt32 Reps[4];
+  int State;
+  int RemainLen;
+  unsigned char TempDictionary[4];
+  #endif
 } CLzmaDecoderState;
 
+#ifdef _LZMA_OUT_READ
+#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
+#endif
 
 int LzmaDecode(CLzmaDecoderState *vs,
+    #ifdef _LZMA_IN_CB
+    ILzmaInCallback *inCallback,
+    #else
     const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
+    #endif
     unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
 
 #endif
