include $(TOPDIR)/rules.mk
+LOADADDR = 0x81000000 # RAM start + 16M
+KERNEL_ENTRY = 0x80100000
+RAMSIZE = 0x00100000 # 1MB
+
+LOADER_MAKEOPTS= \
+ KDIR=$(KDIR) \
+ LOADADDR=$(LOADADDR) \
+ KERNEL_ENTRY=$(KERNEL_ENTRY) \
+ RAMSIZE=$(RAMSIZE)
+
KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
lzma-loader-clean:
- $(MAKE) -C lzma-loader clean
+ $(MAKE) -C ../generic/lzma-loader $(LOADER_MAKEOPTS) clean
lzma-loader-prepare:
- $(MAKE) -C lzma-loader prepare
+ $(MAKE) -C ../generic/lzma-loader $(LOADER_MAKEOPTS) prepare
lzma-loader-compile: $(KDIR)/vmlinux.lzma lzma-loader-prepare
- $(MAKE) -C lzma-loader compile KDIR=$(KDIR)
+ $(MAKE) -C ../generic/lzma-loader $(LOADER_MAKEOPTS) compile
ifeq ($(IB),)
$(KDIR)/vmlinux.lzma: $(KDIR)/vmlinux
+++ /dev/null
-# $Id: Makefile 1823 2005-09-01 20:07:42Z nbd $
-
-include $(TOPDIR)/rules.mk
-
-PKG_NAME := loader
-PKG_VERSION := 0.05
-
-PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
-
-$(PKG_BUILD_DIR)/.prepared:
- mkdir $(PKG_BUILD_DIR)
- cp -fpR ./src/* $(PKG_BUILD_DIR)/
- touch $@
-
-$(PKG_BUILD_DIR)/lzma.elf: $(PKG_BUILD_DIR)/.prepared $(PKG_BUILD_DIR)/vmlinux.lzma
- $(MAKE) -C $(PKG_BUILD_DIR) CC=$(TARGET_CC) \
- LD=$(TARGET_CROSS)ld CROSS_COMPILE=$(TARGET_CROSS)
-
-$(PKG_BUILD_DIR)/vmlinux.lzma: $(KDIR)/vmlinux.lzma
- cp $< $@
-
-$(KDIR)/loader.elf: $(PKG_BUILD_DIR)/lzma.elf
- cp $< $@
-
-source:
-prepare: $(PKG_BUILD_DIR)/.prepared
-compile: $(KDIR)/loader.elf
-install:
-
-clean:
- rm -rf $(PKG_BUILD_DIR)
- rm -f $(KDIR)/loader.elf
+++ /dev/null
-/*\r
- LzmaDecode.c\r
- LZMA Decoder (optimized for Speed version)\r
- \r
- LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)\r
- http://www.7-zip.org/\r
-\r
- LZMA SDK is licensed under two licenses:\r
- 1) GNU Lesser General Public License (GNU LGPL)\r
- 2) Common Public License (CPL)\r
- It means that you can select one of these two licenses and \r
- follow rules of that license.\r
-\r
- SPECIAL EXCEPTION:\r
- Igor Pavlov, as the author of this Code, expressly permits you to \r
- statically or dynamically link your Code (or bind by name) to the \r
- interfaces of this file without subjecting your linked Code to the \r
- terms of the CPL or GNU LGPL. Any modifications or additions \r
- to this file, however, are subject to the LGPL or CPL terms.\r
-*/\r
-\r
-#include "LzmaDecode.h"\r
-\r
-#ifndef Byte\r
-#define Byte unsigned char\r
-#endif\r
-\r
-#define kNumTopBits 24\r
-#define kTopValue ((UInt32)1 << kNumTopBits)\r
-\r
-#define kNumBitModelTotalBits 11\r
-#define kBitModelTotal (1 << kNumBitModelTotalBits)\r
-#define kNumMoveBits 5\r
-\r
-#define RC_READ_BYTE (*Buffer++)\r
-\r
-#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\r
- { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r
-\r
-#ifdef _LZMA_IN_CB\r
-\r
-#define RC_TEST { if (Buffer == BufferLim) \\r
- { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\r
- BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r
-\r
-#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r
-\r
-#else\r
-\r
-#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r
-\r
-#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r
- \r
-#endif\r
-\r
-#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r
-\r
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r
-\r
-#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\r
- { UpdateBit0(p); mi <<= 1; A0; } else \\r
- { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r
- \r
-#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) \r
-\r
-#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\r
- { int i = numLevels; res = 1; \\r
- do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\r
- res -= (1 << numLevels); }\r
-\r
-\r
-#define kNumPosBitsMax 4\r
-#define kNumPosStatesMax (1 << kNumPosBitsMax)\r
-\r
-#define kLenNumLowBits 3\r
-#define kLenNumLowSymbols (1 << kLenNumLowBits)\r
-#define kLenNumMidBits 3\r
-#define kLenNumMidSymbols (1 << kLenNumMidBits)\r
-#define kLenNumHighBits 8\r
-#define kLenNumHighSymbols (1 << kLenNumHighBits)\r
-\r
-#define LenChoice 0\r
-#define LenChoice2 (LenChoice + 1)\r
-#define LenLow (LenChoice2 + 1)\r
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r
-\r
-\r
-#define kNumStates 12\r
-#define kNumLitStates 7\r
-\r
-#define kStartPosModelIndex 4\r
-#define kEndPosModelIndex 14\r
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
-\r
-#define kNumPosSlotBits 6\r
-#define kNumLenToPosStates 4\r
-\r
-#define kNumAlignBits 4\r
-#define kAlignTableSize (1 << kNumAlignBits)\r
-\r
-#define kMatchMinLen 2\r
-\r
-#define IsMatch 0\r
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r
-#define IsRepG0 (IsRep + kNumStates)\r
-#define IsRepG1 (IsRepG0 + kNumStates)\r
-#define IsRepG2 (IsRepG1 + kNumStates)\r
-#define IsRep0Long (IsRepG2 + kNumStates)\r
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r
-#define LenCoder (Align + kAlignTableSize)\r
-#define RepLenCoder (LenCoder + kNumLenProbs)\r
-#define Literal (RepLenCoder + kNumLenProbs)\r
-\r
-#if Literal != LZMA_BASE_SIZE\r
-StopCompilingDueBUG\r
-#endif\r
-\r
-#if 0\r
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r
-{\r
- unsigned char prop0;\r
- if (size < LZMA_PROPERTIES_SIZE)\r
- return LZMA_RESULT_DATA_ERROR;\r
- prop0 = propsData[0];\r
- if (prop0 >= (9 * 5 * 5))\r
- return LZMA_RESULT_DATA_ERROR;\r
- {\r
- for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r
- for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r
- propsRes->lc = prop0;\r
- /*\r
- unsigned char remainder = (unsigned char)(prop0 / 9);\r
- propsRes->lc = prop0 % 9;\r
- propsRes->pb = remainder / 5;\r
- propsRes->lp = remainder % 5;\r
- */\r
- }\r
-\r
- #ifdef _LZMA_OUT_READ\r
- {\r
- int i;\r
- propsRes->DictionarySize = 0;\r
- for (i = 0; i < 4; i++)\r
- propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r
- if (propsRes->DictionarySize == 0)\r
- propsRes->DictionarySize = 1;\r
- }\r
- #endif\r
- return LZMA_RESULT_OK;\r
-}\r
-#endif\r
-\r
-#define kLzmaStreamWasFinishedId (-1)\r
-\r
-int LzmaDecode(CLzmaDecoderState *vs,\r
- #ifdef _LZMA_IN_CB\r
- ILzmaInCallback *InCallback,\r
- #else\r
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r
- #endif\r
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r
-{\r
- CProb *p = vs->Probs;\r
- SizeT nowPos = 0;\r
- Byte previousByte = 0;\r
- UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r
- UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r
- int lc = vs->Properties.lc;\r
-\r
- #ifdef _LZMA_OUT_READ\r
- \r
- UInt32 Range = vs->Range;\r
- UInt32 Code = vs->Code;\r
- #ifdef _LZMA_IN_CB\r
- const Byte *Buffer = vs->Buffer;\r
- const Byte *BufferLim = vs->BufferLim;\r
- #else\r
- const Byte *Buffer = inStream;\r
- const Byte *BufferLim = inStream + inSize;\r
- #endif\r
- int state = vs->State;\r
- UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r
- int len = vs->RemainLen;\r
- UInt32 globalPos = vs->GlobalPos;\r
- UInt32 distanceLimit = vs->DistanceLimit;\r
-\r
- Byte *dictionary = vs->Dictionary;\r
- UInt32 dictionarySize = vs->Properties.DictionarySize;\r
- UInt32 dictionaryPos = vs->DictionaryPos;\r
-\r
- Byte tempDictionary[4];\r
-\r
- #ifndef _LZMA_IN_CB\r
- *inSizeProcessed = 0;\r
- #endif\r
- *outSizeProcessed = 0;\r
- if (len == kLzmaStreamWasFinishedId)\r
- return LZMA_RESULT_OK;\r
-\r
- if (dictionarySize == 0)\r
- {\r
- dictionary = tempDictionary;\r
- dictionarySize = 1;\r
- tempDictionary[0] = vs->TempDictionary[0];\r
- }\r
-\r
- if (len == kLzmaNeedInitId)\r
- {\r
- {\r
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r
- UInt32 i;\r
- for (i = 0; i < numProbs; i++)\r
- p[i] = kBitModelTotal >> 1; \r
- rep0 = rep1 = rep2 = rep3 = 1;\r
- state = 0;\r
- globalPos = 0;\r
- distanceLimit = 0;\r
- dictionaryPos = 0;\r
- dictionary[dictionarySize - 1] = 0;\r
- #ifdef _LZMA_IN_CB\r
- RC_INIT;\r
- #else\r
- RC_INIT(inStream, inSize);\r
- #endif\r
- }\r
- len = 0;\r
- }\r
- while(len != 0 && nowPos < outSize)\r
- {\r
- UInt32 pos = dictionaryPos - rep0;\r
- if (pos >= dictionarySize)\r
- pos += dictionarySize;\r
- outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r
- if (++dictionaryPos == dictionarySize)\r
- dictionaryPos = 0;\r
- len--;\r
- }\r
- if (dictionaryPos == 0)\r
- previousByte = dictionary[dictionarySize - 1];\r
- else\r
- previousByte = dictionary[dictionaryPos - 1];\r
-\r
- #else /* if !_LZMA_OUT_READ */\r
-\r
- int state = 0;\r
- UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r
- int len = 0;\r
- const Byte *Buffer;\r
- const Byte *BufferLim;\r
- UInt32 Range;\r
- UInt32 Code;\r
-\r
- #ifndef _LZMA_IN_CB\r
- *inSizeProcessed = 0;\r
- #endif\r
- *outSizeProcessed = 0;\r
-\r
- {\r
- UInt32 i;\r
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r
- for (i = 0; i < numProbs; i++)\r
- p[i] = kBitModelTotal >> 1;\r
- }\r
- \r
- #ifdef _LZMA_IN_CB\r
- RC_INIT;\r
- #else\r
- RC_INIT(inStream, inSize);\r
- #endif\r
-\r
- #endif /* _LZMA_OUT_READ */\r
-\r
- while(nowPos < outSize)\r
- {\r
- CProb *prob;\r
- UInt32 bound;\r
- int posState = (int)(\r
- (nowPos \r
- #ifdef _LZMA_OUT_READ\r
- + globalPos\r
- #endif\r
- )\r
- & posStateMask);\r
-\r
- prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r
- IfBit0(prob)\r
- {\r
- int symbol = 1;\r
- UpdateBit0(prob)\r
- prob = p + Literal + (LZMA_LIT_SIZE * \r
- (((\r
- (nowPos \r
- #ifdef _LZMA_OUT_READ\r
- + globalPos\r
- #endif\r
- )\r
- & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r
-\r
- if (state >= kNumLitStates)\r
- {\r
- int matchByte;\r
- #ifdef _LZMA_OUT_READ\r
- UInt32 pos = dictionaryPos - rep0;\r
- if (pos >= dictionarySize)\r
- pos += dictionarySize;\r
- matchByte = dictionary[pos];\r
- #else\r
- matchByte = outStream[nowPos - rep0];\r
- #endif\r
- do\r
- {\r
- int bit;\r
- CProb *probLit;\r
- matchByte <<= 1;\r
- bit = (matchByte & 0x100);\r
- probLit = prob + 0x100 + bit + symbol;\r
- RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r
- }\r
- while (symbol < 0x100);\r
- }\r
- while (symbol < 0x100)\r
- {\r
- CProb *probLit = prob + symbol;\r
- RC_GET_BIT(probLit, symbol)\r
- }\r
- previousByte = (Byte)symbol;\r
-\r
- outStream[nowPos++] = previousByte;\r
- #ifdef _LZMA_OUT_READ\r
- if (distanceLimit < dictionarySize)\r
- distanceLimit++;\r
-\r
- dictionary[dictionaryPos] = previousByte;\r
- if (++dictionaryPos == dictionarySize)\r
- dictionaryPos = 0;\r
- #endif\r
- if (state < 4) state = 0;\r
- else if (state < 10) state -= 3;\r
- else state -= 6;\r
- }\r
- else \r
- {\r
- UpdateBit1(prob);\r
- prob = p + IsRep + state;\r
- IfBit0(prob)\r
- {\r
- UpdateBit0(prob);\r
- rep3 = rep2;\r
- rep2 = rep1;\r
- rep1 = rep0;\r
- state = state < kNumLitStates ? 0 : 3;\r
- prob = p + LenCoder;\r
- }\r
- else\r
- {\r
- UpdateBit1(prob);\r
- prob = p + IsRepG0 + state;\r
- IfBit0(prob)\r
- {\r
- UpdateBit0(prob);\r
- prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
- IfBit0(prob)\r
- {\r
- #ifdef _LZMA_OUT_READ\r
- UInt32 pos;\r
- #endif\r
- UpdateBit0(prob);\r
- \r
- #ifdef _LZMA_OUT_READ\r
- if (distanceLimit == 0)\r
- #else\r
- if (nowPos == 0)\r
- #endif\r
- return LZMA_RESULT_DATA_ERROR;\r
- \r
- state = state < kNumLitStates ? 9 : 11;\r
- #ifdef _LZMA_OUT_READ\r
- pos = dictionaryPos - rep0;\r
- if (pos >= dictionarySize)\r
- pos += dictionarySize;\r
- previousByte = dictionary[pos];\r
- dictionary[dictionaryPos] = previousByte;\r
- if (++dictionaryPos == dictionarySize)\r
- dictionaryPos = 0;\r
- #else\r
- previousByte = outStream[nowPos - rep0];\r
- #endif\r
- outStream[nowPos++] = previousByte;\r
- #ifdef _LZMA_OUT_READ\r
- if (distanceLimit < dictionarySize)\r
- distanceLimit++;\r
- #endif\r
-\r
- continue;\r
- }\r
- else\r
- {\r
- UpdateBit1(prob);\r
- }\r
- }\r
- else\r
- {\r
- UInt32 distance;\r
- UpdateBit1(prob);\r
- prob = p + IsRepG1 + state;\r
- IfBit0(prob)\r
- {\r
- UpdateBit0(prob);\r
- distance = rep1;\r
- }\r
- else \r
- {\r
- UpdateBit1(prob);\r
- prob = p + IsRepG2 + state;\r
- IfBit0(prob)\r
- {\r
- UpdateBit0(prob);\r
- distance = rep2;\r
- }\r
- else\r
- {\r
- UpdateBit1(prob);\r
- distance = rep3;\r
- rep3 = rep2;\r
- }\r
- rep2 = rep1;\r
- }\r
- rep1 = rep0;\r
- rep0 = distance;\r
- }\r
- state = state < kNumLitStates ? 8 : 11;\r
- prob = p + RepLenCoder;\r
- }\r
- {\r
- int numBits, offset;\r
- CProb *probLen = prob + LenChoice;\r
- IfBit0(probLen)\r
- {\r
- UpdateBit0(probLen);\r
- probLen = prob + LenLow + (posState << kLenNumLowBits);\r
- offset = 0;\r
- numBits = kLenNumLowBits;\r
- }\r
- else\r
- {\r
- UpdateBit1(probLen);\r
- probLen = prob + LenChoice2;\r
- IfBit0(probLen)\r
- {\r
- UpdateBit0(probLen);\r
- probLen = prob + LenMid + (posState << kLenNumMidBits);\r
- offset = kLenNumLowSymbols;\r
- numBits = kLenNumMidBits;\r
- }\r
- else\r
- {\r
- UpdateBit1(probLen);\r
- probLen = prob + LenHigh;\r
- offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
- numBits = kLenNumHighBits;\r
- }\r
- }\r
- RangeDecoderBitTreeDecode(probLen, numBits, len);\r
- len += offset;\r
- }\r
-\r
- if (state < 4)\r
- {\r
- int posSlot;\r
- state += kNumLitStates;\r
- prob = p + PosSlot +\r
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r
- kNumPosSlotBits);\r
- RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r
- if (posSlot >= kStartPosModelIndex)\r
- {\r
- int numDirectBits = ((posSlot >> 1) - 1);\r
- rep0 = (2 | ((UInt32)posSlot & 1));\r
- if (posSlot < kEndPosModelIndex)\r
- {\r
- rep0 <<= numDirectBits;\r
- prob = p + SpecPos + rep0 - posSlot - 1;\r
- }\r
- else\r
- {\r
- numDirectBits -= kNumAlignBits;\r
- do\r
- {\r
- RC_NORMALIZE\r
- Range >>= 1;\r
- rep0 <<= 1;\r
- if (Code >= Range)\r
- {\r
- Code -= Range;\r
- rep0 |= 1;\r
- }\r
- }\r
- while (--numDirectBits != 0);\r
- prob = p + Align;\r
- rep0 <<= kNumAlignBits;\r
- numDirectBits = kNumAlignBits;\r
- }\r
- {\r
- int i = 1;\r
- int mi = 1;\r
- do\r
- {\r
- CProb *prob3 = prob + mi;\r
- RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r
- i <<= 1;\r
- }\r
- while(--numDirectBits != 0);\r
- }\r
- }\r
- else\r
- rep0 = posSlot;\r
- if (++rep0 == (UInt32)(0))\r
- {\r
- /* it's for stream version */\r
- len = kLzmaStreamWasFinishedId;\r
- break;\r
- }\r
- }\r
-\r
- len += kMatchMinLen;\r
- #ifdef _LZMA_OUT_READ\r
- if (rep0 > distanceLimit) \r
- #else\r
- if (rep0 > nowPos)\r
- #endif\r
- return LZMA_RESULT_DATA_ERROR;\r
-\r
- #ifdef _LZMA_OUT_READ\r
- if (dictionarySize - distanceLimit > (UInt32)len)\r
- distanceLimit += len;\r
- else\r
- distanceLimit = dictionarySize;\r
- #endif\r
-\r
- do\r
- {\r
- #ifdef _LZMA_OUT_READ\r
- UInt32 pos = dictionaryPos - rep0;\r
- if (pos >= dictionarySize)\r
- pos += dictionarySize;\r
- previousByte = dictionary[pos];\r
- dictionary[dictionaryPos] = previousByte;\r
- if (++dictionaryPos == dictionarySize)\r
- dictionaryPos = 0;\r
- #else\r
- previousByte = outStream[nowPos - rep0];\r
- #endif\r
- len--;\r
- outStream[nowPos++] = previousByte;\r
- }\r
- while(len != 0 && nowPos < outSize);\r
- }\r
- }\r
- RC_NORMALIZE;\r
-\r
- #ifdef _LZMA_OUT_READ\r
- vs->Range = Range;\r
- vs->Code = Code;\r
- vs->DictionaryPos = dictionaryPos;\r
- vs->GlobalPos = globalPos + (UInt32)nowPos;\r
- vs->DistanceLimit = distanceLimit;\r
- vs->Reps[0] = rep0;\r
- vs->Reps[1] = rep1;\r
- vs->Reps[2] = rep2;\r
- vs->Reps[3] = rep3;\r
- vs->State = state;\r
- vs->RemainLen = len;\r
- vs->TempDictionary[0] = tempDictionary[0];\r
- #endif\r
-\r
- #ifdef _LZMA_IN_CB\r
- vs->Buffer = Buffer;\r
- vs->BufferLim = BufferLim;\r
- #else\r
- *inSizeProcessed = (SizeT)(Buffer - inStream);\r
- #endif\r
- *outSizeProcessed = nowPos;\r
- return LZMA_RESULT_OK;\r
-}\r
+++ /dev/null
-/* \r
- LzmaDecode.h\r
- LZMA Decoder interface\r
-\r
- LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r
- http://www.7-zip.org/\r
-\r
- LZMA SDK is licensed under two licenses:\r
- 1) GNU Lesser General Public License (GNU LGPL)\r
- 2) Common Public License (CPL)\r
- It means that you can select one of these two licenses and \r
- follow rules of that license.\r
-\r
- SPECIAL EXCEPTION:\r
- Igor Pavlov, as the author of this code, expressly permits you to \r
- statically or dynamically link your code (or bind by name) to the \r
- interfaces of this file without subjecting your linked code to the \r
- terms of the CPL or GNU LGPL. Any modifications or additions \r
- to this file, however, are subject to the LGPL or CPL terms.\r
-*/\r
-\r
-#ifndef __LZMADECODE_H\r
-#define __LZMADECODE_H\r
-\r
-/* #define _LZMA_IN_CB */\r
-/* Use callback for input data */\r
-\r
-/* #define _LZMA_OUT_READ */\r
-/* Use read function for output data */\r
-\r
-/* #define _LZMA_PROB32 */\r
-/* It can increase speed on some 32-bit CPUs, \r
- but memory usage will be doubled in that case */\r
-\r
-/* #define _LZMA_LOC_OPT */\r
-/* Enable local speed optimizations inside code */\r
-\r
-/* #define _LZMA_SYSTEM_SIZE_T */\r
-/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r
-\r
-#ifndef UInt32\r
-#ifdef _LZMA_UINT32_IS_ULONG\r
-#define UInt32 unsigned long\r
-#else\r
-#define UInt32 unsigned int\r
-#endif\r
-#endif\r
-\r
-#ifndef SizeT\r
-#ifdef _LZMA_SYSTEM_SIZE_T\r
-#include <stddef.h>\r
-#define SizeT size_t\r
-#else\r
-#define SizeT UInt32\r
-#endif\r
-#endif\r
-\r
-#ifdef _LZMA_PROB32\r
-#define CProb UInt32\r
-#else\r
-#define CProb unsigned short\r
-#endif\r
-\r
-#define LZMA_RESULT_OK 0\r
-#define LZMA_RESULT_DATA_ERROR 1\r
-\r
-#ifdef _LZMA_IN_CB\r
-typedef struct _ILzmaInCallback\r
-{\r
- int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r
-} ILzmaInCallback;\r
-#endif\r
-\r
-#define LZMA_BASE_SIZE 1846\r
-#define LZMA_LIT_SIZE 768\r
-\r
-#define LZMA_PROPERTIES_SIZE 5\r
-\r
-typedef struct _CLzmaProperties\r
-{\r
- int lc;\r
- int lp;\r
- int pb;\r
- #ifdef _LZMA_OUT_READ\r
- UInt32 DictionarySize;\r
- #endif\r
-}CLzmaProperties;\r
-\r
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r
-\r
-#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r
-\r
-#define kLzmaNeedInitId (-2)\r
-\r
-typedef struct _CLzmaDecoderState\r
-{\r
- CLzmaProperties Properties;\r
- CProb *Probs;\r
-\r
- #ifdef _LZMA_IN_CB\r
- const unsigned char *Buffer;\r
- const unsigned char *BufferLim;\r
- #endif\r
-\r
- #ifdef _LZMA_OUT_READ\r
- unsigned char *Dictionary;\r
- UInt32 Range;\r
- UInt32 Code;\r
- UInt32 DictionaryPos;\r
- UInt32 GlobalPos;\r
- UInt32 DistanceLimit;\r
- UInt32 Reps[4];\r
- int State;\r
- int RemainLen;\r
- unsigned char TempDictionary[4];\r
- #endif\r
-} CLzmaDecoderState;\r
-\r
-#ifdef _LZMA_OUT_READ\r
-#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r
-#endif\r
-\r
-int LzmaDecode(CLzmaDecoderState *vs,\r
- #ifdef _LZMA_IN_CB\r
- ILzmaInCallback *inCallback,\r
- #else\r
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r
- #endif\r
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r
-\r
-#endif\r
+++ /dev/null
-LOADADDR = 0x81000000
-RAMSIZE = 0x00100000 # 1MB
-
-CROSS_COMPILE = mips-linux-
-
-.S.s:
- $(CPP) $(CFLAGS) $< -o $*.s
-.S.o:
- $(CC) $(CFLAGS) -c $< -o $*.o
-.c.o:
- $(CC) $(CFLAGS) -c $< -o $*.o
-
-CC = $(CROSS_COMPILE)gcc
-LD = $(CROSS_COMPILE)ld
-OBJCOPY = $(CROSS_COMPILE)objcopy
-OBJDUMP = $(CROSS_COMPILE)objdump
-
-CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE} -D_LZMA_IN_CB
-# CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE}
-
-O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
-
-# Drop some uninteresting sections in the kernel.
-# This is only relevant for ELF kernels but doesn't hurt a.out
-drop-sections = .reginfo .mdebug .comment
-strip-flags = $(addprefix --remove-section=,$(drop-sections))
-
-
-all : lzma.elf
-
-kernel.o: vmlinux.lzma
- $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
-
-lzma.elf: start.o decompress.o LzmaDecode.o kernel.o
- $(LD) -s -Tlzma.lds -o $@ $^
-
-clean:
- rm -f *.o lzma.elf
+++ /dev/null
-/*
- * LZMA compressed kernel decompressor for bcm947xx boards
- *
- * Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *
- * Please note, this was code based on the bunzip2 decompressor code
- * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left
- * is an idea and part of original vendor code
- *
- *
- * 12-Mar-2005 Mineharu Takahara <mtakahar@yahoo.com>
- * pass actual output size to decoder (stream mode
- * compressed input is not a requirement anymore)
- *
- * 24-Apr-2005 Oleg I. Vdovikin
- * reordered functions using lds script, removed forward decl
- *
- * ??-Nov-2005 Mike Baker
- * reorder the script as an lzma wrapper; do not depend on flash access
- */
-
-#include "LzmaDecode.h"
-#define LOADADDR 0x80100000
-
-#define KSEG0 0x80000000
-#define KSEG1 0xa0000000
-
-#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1)
-
-#define Index_Invalidate_I 0x00
-#define Index_Writeback_Inv_D 0x01
-
-#define cache_unroll(base,op) \
- __asm__ __volatile__( \
- ".set noreorder;\n" \
- ".set mips3;\n" \
- "cache %1, (%0);\n" \
- ".set mips0;\n" \
- ".set reorder\n" \
- : \
- : "r" (base), \
- "i" (op));
-
-
-static __inline__ void blast_icache(unsigned long size, unsigned long lsize)
-{
- unsigned long start = KSEG0;
- unsigned long end = (start + size);
-
- while(start < end) {
- cache_unroll(start,Index_Invalidate_I);
- start += lsize;
- }
-}
-
-static __inline__ void blast_dcache(unsigned long size, unsigned long lsize)
-{
- unsigned long start = KSEG0;
- unsigned long end = (start + size);
-
- while(start < end) {
- cache_unroll(start,Index_Writeback_Inv_D);
- start += lsize;
- }
-}
-
-unsigned char *data;
-
-static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize)
-{
- *bufferSize = 1;
- *buffer = data;
- ++data;
- return LZMA_RESULT_OK;
-}
-
-static __inline__ unsigned char get_byte(void)
-{
- unsigned char *buffer;
- UInt32 fake;
-
- return read_byte(0, &buffer, &fake), *buffer;
-}
-
-static char *buffer = (char *)0x80C00000;
-extern char lzma_start[];
-extern char lzma_end[];
-
-/* should be the first function */
-void entry(unsigned long icache_size, unsigned long icache_lsize,
- unsigned long dcache_size, unsigned long dcache_lsize)
-{
- unsigned int i; /* temp value */
- unsigned int osize; /* uncompressed size */
-
- ILzmaInCallback callback;
- CLzmaDecoderState vs;
- callback.Read = read_byte;
-
- data = lzma_start;
-
- /* lzma args */
- i = get_byte();
- vs.Properties.lc = i % 9, i = i / 9;
- vs.Properties.lp = i % 5, vs.Properties.pb = i / 5;
-
- vs.Probs = (CProb *)buffer;
-
- /* skip rest of the LZMA coder property */
- for (i = 0; i < 4; i++)
- get_byte();
-
- /* read the lower half of uncompressed size in the header */
- osize = ((unsigned int)get_byte()) +
- ((unsigned int)get_byte() << 8) +
- ((unsigned int)get_byte() << 16) +
- ((unsigned int)get_byte() << 24);
-
- /* skip rest of the header (upper half of uncompressed size) */
- for (i = 0; i < 4; i++)
- get_byte();
-
- /* decompress kernel */
- if ((i = LzmaDecode(&vs, &callback,
- (unsigned char*)LOADADDR, osize, &osize)) == LZMA_RESULT_OK)
- {
- blast_dcache(dcache_size, dcache_lsize);
- blast_icache(icache_size, icache_lsize);
-
- /* Jump to load address */
- ((void (*)(void)) LOADADDR)();
- }
-}
+++ /dev/null
-OUTPUT_ARCH(mips)
-ENTRY(_start)
-SECTIONS
-{
- /* Read-only sections, merged into text segment: */
- . = 0x81000000;
- .text :
- {
- _ftext = . ;
- *(.text)
- *(.rodata)
- lzma_start = .;
- kernel.o
- lzma_end = .;
- } =0
-
- .reginfo : { *(.reginfo) }
-
- .bss :
- {
- *(.bss)
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-#include "print.h"
-
-/* macros */
-#define IsDigit(x) ( ((x) >= '0') && ((x) <= '9') )
-#define Ctod(x) ( (x) - '0')
-
-/* forward declaration */
-extern int PrintChar(char *, char, int, int);
-extern int PrintString(char *, char *, int, int);
-extern int PrintNum(char *, unsigned long, int, int, int, int, char, int);
-
-/* private variable */
-static const char theFatalMsg[] = "fatal error in lp_Print!";
-
-/* -*-
- * A low level printf() function.
- */
-void
-lp_Print(void (*output)(void *, char *, int),
- void * arg,
- char *fmt,
- va_list ap)
-{
-
-#define OUTPUT(arg, s, l) \
- { if (((l) < 0) || ((l) > LP_MAX_BUF)) { \
- (*output)(arg, (char*)theFatalMsg, sizeof(theFatalMsg)-1); for(;;); \
- } else { \
- (*output)(arg, s, l); \
- } \
- }
-
- char buf[LP_MAX_BUF];
-
- char c;
- char *s;
- long int num;
-
- int longFlag;
- int negFlag;
- int width;
- int prec;
- int ladjust;
- char padc;
-
- int length;
-
- for(;;) {
- {
- /* scan for the next '%' */
- char *fmtStart = fmt;
- while ( (*fmt != '\0') && (*fmt != '%')) {
- fmt ++;
- }
-
- /* flush the string found so far */
- OUTPUT(arg, fmtStart, fmt-fmtStart);
-
- /* are we hitting the end? */
- if (*fmt == '\0') break;
- }
-
- /* we found a '%' */
- fmt ++;
-
- /* check for long */
- if (*fmt == 'l') {
- longFlag = 1;
- fmt ++;
- } else {
- longFlag = 0;
- }
-
- /* check for other prefixes */
- width = 0;
- prec = -1;
- ladjust = 0;
- padc = ' ';
-
- if (*fmt == '-') {
- ladjust = 1;
- fmt ++;
- }
-
- if (*fmt == '0') {
- padc = '0';
- fmt++;
- }
-
- if (IsDigit(*fmt)) {
- while (IsDigit(*fmt)) {
- width = 10 * width + Ctod(*fmt++);
- }
- }
-
- if (*fmt == '.') {
- fmt ++;
- if (IsDigit(*fmt)) {
- prec = 0;
- while (IsDigit(*fmt)) {
- prec = prec*10 + Ctod(*fmt++);
- }
- }
- }
-
-
- /* check format flag */
- negFlag = 0;
- switch (*fmt) {
- case 'b':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- length = PrintNum(buf, num, 2, 0, width, ladjust, padc, 0);
- OUTPUT(arg, buf, length);
- break;
-
- case 'd':
- case 'D':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- if (num < 0) {
- num = - num;
- negFlag = 1;
- }
- length = PrintNum(buf, num, 10, negFlag, width, ladjust, padc, 0);
- OUTPUT(arg, buf, length);
- break;
-
- case 'o':
- case 'O':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- length = PrintNum(buf, num, 8, 0, width, ladjust, padc, 0);
- OUTPUT(arg, buf, length);
- break;
-
- case 'u':
- case 'U':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- length = PrintNum(buf, num, 10, 0, width, ladjust, padc, 0);
- OUTPUT(arg, buf, length);
- break;
-
- case 'x':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 0);
- OUTPUT(arg, buf, length);
- break;
-
- case 'X':
- if (longFlag) {
- num = va_arg(ap, long int);
- } else {
- num = va_arg(ap, int);
- }
- length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 1);
- OUTPUT(arg, buf, length);
- break;
-
- case 'c':
- c = (char)va_arg(ap, int);
- length = PrintChar(buf, c, width, ladjust);
- OUTPUT(arg, buf, length);
- break;
-
- case 's':
- s = (char*)va_arg(ap, char *);
- length = PrintString(buf, s, width, ladjust);
- OUTPUT(arg, buf, length);
- break;
-
- case '\0':
- fmt --;
- break;
-
- default:
- /* output this char as it is */
- OUTPUT(arg, fmt, 1);
- } /* switch (*fmt) */
-
- fmt ++;
- } /* for(;;) */
-
- /* special termination call */
- OUTPUT(arg, "\0", 1);
-}
-
-
-/* --------------- local help functions --------------------- */
-int
-PrintChar(char * buf, char c, int length, int ladjust)
-{
- int i;
-
- if (length < 1) length = 1;
- if (ladjust) {
- *buf = c;
- for (i=1; i< length; i++) buf[i] = ' ';
- } else {
- for (i=0; i< length-1; i++) buf[i] = ' ';
- buf[length - 1] = c;
- }
- return length;
-}
-
-int
-PrintString(char * buf, char* s, int length, int ladjust)
-{
- int i;
- int len=0;
- char* s1 = s;
- while (*s1++) len++;
- if (length < len) length = len;
-
- if (ladjust) {
- for (i=0; i< len; i++) buf[i] = s[i];
- for (i=len; i< length; i++) buf[i] = ' ';
- } else {
- for (i=0; i< length-len; i++) buf[i] = ' ';
- for (i=length-len; i < length; i++) buf[i] = s[i-length+len];
- }
- return length;
-}
-
-int
-PrintNum(char * buf, unsigned long u, int base, int negFlag,
- int length, int ladjust, char padc, int upcase)
-{
- /* algorithm :
- * 1. prints the number from left to right in reverse form.
- * 2. fill the remaining spaces with padc if length is longer than
- * the actual length
- * TRICKY : if left adjusted, no "0" padding.
- * if negtive, insert "0" padding between "0" and number.
- * 3. if (!ladjust) we reverse the whole string including paddings
- * 4. otherwise we only reverse the actual string representing the num.
- */
-
- int actualLength =0;
- char *p = buf;
- int i;
-
- do {
- int tmp = u %base;
- if (tmp <= 9) {
- *p++ = '0' + tmp;
- } else if (upcase) {
- *p++ = 'A' + tmp - 10;
- } else {
- *p++ = 'a' + tmp - 10;
- }
- u /= base;
- } while (u != 0);
-
- if (negFlag) {
- *p++ = '-';
- }
-
- /* figure out actual length and adjust the maximum length */
- actualLength = p - buf;
- if (length < actualLength) length = actualLength;
-
- /* add padding */
- if (ladjust) {
- padc = ' ';
- }
- if (negFlag && !ladjust && (padc == '0')) {
- for (i = actualLength-1; i< length-1; i++) buf[i] = padc;
- buf[length -1] = '-';
- } else {
- for (i = actualLength; i< length; i++) buf[i] = padc;
- }
-
-
- /* prepare to reverse the string */
- {
- int begin = 0;
- int end;
- if (ladjust) {
- end = actualLength - 1;
- } else {
- end = length -1;
- }
-
- while (end > begin) {
- char tmp = buf[begin];
- buf[begin] = buf[end];
- buf[end] = tmp;
- begin ++;
- end --;
- }
- }
-
- /* adjust the string pointer */
- return length;
-}
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-#ifndef _print_h_
-#define _print_h_
-
-#include <stdarg.h>
-
-/* this is the maximum width for a variable */
-#define LP_MAX_BUF 80
-
-/* -*-
- * output function takes an void pointer which is passed in as the
- * second argument in lp_Print(). This black-box argument gives output
- * function a way to track state.
- *
- * The second argument in output function is a pointer to char buffer.
- * The third argument specifies the number of chars to outputed.
- *
- * output function cannot assume the buffer is null-terminated after
- * l number of chars.
- */
-void lp_Print(void (*output)(void *, char *, int),
- void * arg,
- char *fmt,
- va_list ap);
-
-#endif
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-#include "printf.h"
-#include "print.h"
-#include "uart16550.h"
-
-static void myoutput(void *arg, char *s, int l)
-{
- int i;
-
- // special termination call
- if ((l==1) && (s[0] == '\0')) return;
-
- for (i=0; i< l; i++) {
- Uart16550Put(s[i]);
- if (s[i] == '\n') Uart16550Put('\r');
- }
-}
-
-void printf(char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- lp_Print(myoutput, 0, fmt, ap);
- va_end(ap);
-}
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-#ifndef _printf_h_
-#define _printf_h_
-
-#include <stdarg.h>
-void printf(char *fmt, ...);
-
-#endif /* _printf_h_ */
+++ /dev/null
-#include <asm/asm.h>
-#include <asm/regdef.h>
-
-#define KSEG0 0x80000000
-
-#define C0_CONFIG $16
-#define C0_TAGLO $28
-#define C0_TAGHI $29
-
-#define CONF1_DA_SHIFT 7 /* D$ associativity */
-#define CONF1_DA_MASK 0x00000380
-#define CONF1_DA_BASE 1
-#define CONF1_DL_SHIFT 10 /* D$ line size */
-#define CONF1_DL_MASK 0x00001c00
-#define CONF1_DL_BASE 2
-#define CONF1_DS_SHIFT 13 /* D$ sets/way */
-#define CONF1_DS_MASK 0x0000e000
-#define CONF1_DS_BASE 64
-#define CONF1_IA_SHIFT 16 /* I$ associativity */
-#define CONF1_IA_MASK 0x00070000
-#define CONF1_IA_BASE 1
-#define CONF1_IL_SHIFT 19 /* I$ line size */
-#define CONF1_IL_MASK 0x00380000
-#define CONF1_IL_BASE 2
-#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
-#define CONF1_IS_MASK 0x01c00000
-#define CONF1_IS_BASE 64
-
-#define Index_Invalidate_I 0x00
-#define Index_Writeback_Inv_D 0x01
-
-LEAF(_start)
-
- .set mips32
- .set noreorder
-
- /* set up stack */
- li sp, 0xa0000000 + RAMSIZE - 16
-
-
- /* At this point we need to invalidate dcache and */
- /* icache before jumping to new code */
-
-1: /* Get cache sizes */
- mfc0 s0,C0_CONFIG,1
-
- li s1,CONF1_DL_MASK
- and s1,s0
- beq s1,zero,nodc
- nop
-
- srl s1,CONF1_DL_SHIFT
- li t0,CONF1_DL_BASE
- sll s1,t0,s1 /* s1 has D$ cache line size */
-
- li s2,CONF1_DA_MASK
- and s2,s0
- srl s2,CONF1_DA_SHIFT
- addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */
-
- li t0,CONF1_DS_MASK
- and t0,s0
- srl t0,CONF1_DS_SHIFT
- li s3,CONF1_DS_BASE
- sll s3,s3,t0 /* s3 has D$ sets per way */
-
- multu s2,s3 /* sets/way * associativity */
- mflo t0 /* total cache lines */
-
- multu s1,t0 /* D$ linesize * lines */
- mflo s2 /* s2 is now D$ size in bytes */
-
- /* Initilize the D$: */
- mtc0 zero,C0_TAGLO
- mtc0 zero,C0_TAGHI
-
- li t0,KSEG0 /* Just an address for the first $ line */
- addu t1,t0,s2 /* + size of cache == end */
-
-1: cache Index_Writeback_Inv_D,0(t0)
- bne t0,t1,1b
- addu t0,s1
-
-nodc:
- /* Now we get to do it all again for the I$ */
-
- move s3,zero /* just in case there is no icache */
- move s4,zero
-
- li t0,CONF1_IL_MASK
- and t0,s0
- beq t0,zero,noic
- nop
-
- srl t0,CONF1_IL_SHIFT
- li s3,CONF1_IL_BASE
- sll s3,t0 /* s3 has I$ cache line size */
-
- li t0,CONF1_IA_MASK
- and t0,s0
- srl t0,CONF1_IA_SHIFT
- addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */
-
- li t0,CONF1_IS_MASK
- and t0,s0
- srl t0,CONF1_IS_SHIFT
- li s5,CONF1_IS_BASE
- sll s5,t0 /* s5 has I$ sets per way */
-
- multu s4,s5 /* sets/way * associativity */
- mflo t0 /* s4 is now total cache lines */
-
- multu s3,t0 /* I$ linesize * lines */
- mflo s4 /* s4 is cache size in bytes */
-
- /* Initilize the I$: */
- mtc0 zero,C0_TAGLO
- mtc0 zero,C0_TAGHI
-
- li t0,KSEG0 /* Just an address for the first $ line */
- addu t1,t0,s4 /* + size of cache == end */
-
-1: cache Index_Invalidate_I,0(t0)
- bne t0,t1,1b
- addu t0,s3
-noic:
- /* jump to main */
- move a0,s3 /* icache line size */
- move a1,s4 /* icache size */
- move a2,s1 /* dcache line size */
- jal entry
- move a3,s2 /* dcache size */
-
- .set reorder
-END(_start)
-
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-
-#include "uart16550.h"
-
-/* === CONFIG === */
-
-#define BASE 0xb8058000
-#define MAX_BAUD 1152000
-#define REG_OFFSET 4
-
-/* === END OF CONFIG === */
-
-/* register offset */
-#define OFS_RCV_BUFFER (0*REG_OFFSET)
-#define OFS_TRANS_HOLD (0*REG_OFFSET)
-#define OFS_SEND_BUFFER (0*REG_OFFSET)
-#define OFS_INTR_ENABLE (1*REG_OFFSET)
-#define OFS_INTR_ID (2*REG_OFFSET)
-#define OFS_DATA_FORMAT (3*REG_OFFSET)
-#define OFS_LINE_CONTROL (3*REG_OFFSET)
-#define OFS_MODEM_CONTROL (4*REG_OFFSET)
-#define OFS_RS232_OUTPUT (4*REG_OFFSET)
-#define OFS_LINE_STATUS (5*REG_OFFSET)
-#define OFS_MODEM_STATUS (6*REG_OFFSET)
-#define OFS_RS232_INPUT (6*REG_OFFSET)
-#define OFS_SCRATCH_PAD (7*REG_OFFSET)
-
-#define OFS_DIVISOR_LSB (0*REG_OFFSET)
-#define OFS_DIVISOR_MSB (1*REG_OFFSET)
-
-
-/* memory-mapped read/write of the port */
-#define UART16550_READ(y) (*((volatile uint32*)(BASE + y)))
-#define UART16550_WRITE(y, z) ((*((volatile uint32*)(BASE + y))) = z)
-
-#define DEBUG_LED (*(unsigned short*)0xb7ffffc0)
-#define OutputLED(x) (DEBUG_LED = x)
-
-void Uart16550Init(uint32 baud, uint8 data, uint8 parity, uint8 stop)
-{
- /* disable interrupts */
- UART16550_WRITE(OFS_INTR_ENABLE, 0);
-
- /* set up buad rate */
- {
- uint32 divisor;
-
- /* set DIAB bit */
- UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
-
- /* set divisor */
- divisor = MAX_BAUD / baud;
- UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
- UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00)>>8);
-
- /* clear DIAB bit */
- UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
- }
-
- /* set data format */
- UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
-}
-
-uint8 Uart16550GetPoll()
-{
- while((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
- return UART16550_READ(OFS_RCV_BUFFER);
-}
-
-
-void Uart16550Put(uint8 byte)
-{
- while ((UART16550_READ(OFS_LINE_STATUS) &0x20) == 0);
- UART16550_WRITE(OFS_SEND_BUFFER, byte);
-}
-
+++ /dev/null
-/*
- * Copyright (C) 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- */
-
-#ifndef _uart16550_h_
-#define _uart16550_h_
-
-typedef unsigned char uint8;
-typedef unsigned int uint32;
-
-#define UART16550_BAUD_2400 2400
-#define UART16550_BAUD_4800 4800
-#define UART16550_BAUD_9600 9600
-#define UART16550_BAUD_19200 19200
-#define UART16550_BAUD_38400 38400
-#define UART16550_BAUD_57600 57600
-#define UART16550_BAUD_115200 115200
-
-#define UART16550_PARITY_NONE 0
-#define UART16550_PARITY_ODD 0x08
-#define UART16550_PARITY_EVEN 0x18
-#define UART16550_PARITY_MARK 0x28
-#define UART16550_PARITY_SPACE 0x38
-
-#define UART16550_DATA_5BIT 0x0
-#define UART16550_DATA_6BIT 0x1
-#define UART16550_DATA_7BIT 0x2
-#define UART16550_DATA_8BIT 0x3
-
-#define UART16550_STOP_1BIT 0x0
-#define UART16550_STOP_2BIT 0x4
-
-void Uart16550Init(uint32 baud, uint8 data, uint8 parity, uint8 stop);
-
-/* blocking call */
-uint8 Uart16550GetPoll();
-
-void Uart16550Put(uint8 byte);
-
-#endif
--- /dev/null
+# $Id: Makefile 1823 2005-09-01 20:07:42Z nbd $
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME := loader
+PKG_VERSION := 0.05
+
+PKG_BUILD_DIR := $(KDIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+$(PKG_BUILD_DIR)/.prepared:
+ mkdir $(PKG_BUILD_DIR)
+ cp -fpR ./src/* $(PKG_BUILD_DIR)/
+ touch $@
+
+$(PKG_BUILD_DIR)/lzma.elf: $(PKG_BUILD_DIR)/.prepared $(PKG_BUILD_DIR)/vmlinux.lzma
+ $(MAKE) -C $(PKG_BUILD_DIR) CC=$(TARGET_CC) \
+ LD=$(TARGET_CROSS)ld CROSS_COMPILE=$(TARGET_CROSS) \
+ RAMSIZE=$(RAMSIZE) \
+ LOADADDR=$(LOADADDR) \
+ KERNEL_ENTRY=$(KERNEL_ENTRY)
+
+
+$(PKG_BUILD_DIR)/vmlinux.lzma: $(KDIR)/vmlinux.lzma
+ cp $< $@
+
+$(KDIR)/loader.elf: $(PKG_BUILD_DIR)/lzma.elf
+ cp $< $@
+
+source:
+prepare: $(PKG_BUILD_DIR)/.prepared
+compile: $(KDIR)/loader.elf
+install:
+
+clean:
+ rm -rf $(PKG_BUILD_DIR)
+ rm -f $(KDIR)/loader.elf
--- /dev/null
+/*\r
+ LzmaDecode.c\r
+ LZMA Decoder (optimized for Speed version)\r
+ \r
+ LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)\r
+ http://www.7-zip.org/\r
+\r
+ LZMA SDK is licensed under two licenses:\r
+ 1) GNU Lesser General Public License (GNU LGPL)\r
+ 2) Common Public License (CPL)\r
+ It means that you can select one of these two licenses and \r
+ follow rules of that license.\r
+\r
+ SPECIAL EXCEPTION:\r
+ Igor Pavlov, as the author of this Code, expressly permits you to \r
+ statically or dynamically link your Code (or bind by name) to the \r
+ interfaces of this file without subjecting your linked Code to the \r
+ terms of the CPL or GNU LGPL. Any modifications or additions \r
+ to this file, however, are subject to the LGPL or CPL terms.\r
+*/\r
+\r
+#include "LzmaDecode.h"\r
+\r
+#ifndef Byte\r
+#define Byte unsigned char\r
+#endif\r
+\r
+#define kNumTopBits 24\r
+#define kTopValue ((UInt32)1 << kNumTopBits)\r
+\r
+#define kNumBitModelTotalBits 11\r
+#define kBitModelTotal (1 << kNumBitModelTotalBits)\r
+#define kNumMoveBits 5\r
+\r
+#define RC_READ_BYTE (*Buffer++)\r
+\r
+#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\r
+ { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r
+\r
+#ifdef _LZMA_IN_CB\r
+\r
+#define RC_TEST { if (Buffer == BufferLim) \\r
+ { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\r
+ BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r
+\r
+#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r
+\r
+#else\r
+\r
+#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r
+\r
+#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r
+ \r
+#endif\r
+\r
+#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r
+\r
+#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r
+#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r
+#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r
+\r
+#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\r
+ { UpdateBit0(p); mi <<= 1; A0; } else \\r
+ { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r
+ \r
+#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) \r
+\r
+#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\r
+ { int i = numLevels; res = 1; \\r
+ do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\r
+ res -= (1 << numLevels); }\r
+\r
+\r
+#define kNumPosBitsMax 4\r
+#define kNumPosStatesMax (1 << kNumPosBitsMax)\r
+\r
+#define kLenNumLowBits 3\r
+#define kLenNumLowSymbols (1 << kLenNumLowBits)\r
+#define kLenNumMidBits 3\r
+#define kLenNumMidSymbols (1 << kLenNumMidBits)\r
+#define kLenNumHighBits 8\r
+#define kLenNumHighSymbols (1 << kLenNumHighBits)\r
+\r
+#define LenChoice 0\r
+#define LenChoice2 (LenChoice + 1)\r
+#define LenLow (LenChoice2 + 1)\r
+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r
+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r
+\r
+\r
+#define kNumStates 12\r
+#define kNumLitStates 7\r
+\r
+#define kStartPosModelIndex 4\r
+#define kEndPosModelIndex 14\r
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
+\r
+#define kNumPosSlotBits 6\r
+#define kNumLenToPosStates 4\r
+\r
+#define kNumAlignBits 4\r
+#define kAlignTableSize (1 << kNumAlignBits)\r
+\r
+#define kMatchMinLen 2\r
+\r
+#define IsMatch 0\r
+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r
+#define IsRepG0 (IsRep + kNumStates)\r
+#define IsRepG1 (IsRepG0 + kNumStates)\r
+#define IsRepG2 (IsRepG1 + kNumStates)\r
+#define IsRep0Long (IsRepG2 + kNumStates)\r
+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r
+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r
+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r
+#define LenCoder (Align + kAlignTableSize)\r
+#define RepLenCoder (LenCoder + kNumLenProbs)\r
+#define Literal (RepLenCoder + kNumLenProbs)\r
+\r
+#if Literal != LZMA_BASE_SIZE\r
+StopCompilingDueBUG\r
+#endif\r
+\r
+#if 0\r
+int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r
+{\r
+ unsigned char prop0;\r
+ if (size < LZMA_PROPERTIES_SIZE)\r
+ return LZMA_RESULT_DATA_ERROR;\r
+ prop0 = propsData[0];\r
+ if (prop0 >= (9 * 5 * 5))\r
+ return LZMA_RESULT_DATA_ERROR;\r
+ {\r
+ for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r
+ for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r
+ propsRes->lc = prop0;\r
+ /*\r
+ unsigned char remainder = (unsigned char)(prop0 / 9);\r
+ propsRes->lc = prop0 % 9;\r
+ propsRes->pb = remainder / 5;\r
+ propsRes->lp = remainder % 5;\r
+ */\r
+ }\r
+\r
+ #ifdef _LZMA_OUT_READ\r
+ {\r
+ int i;\r
+ propsRes->DictionarySize = 0;\r
+ for (i = 0; i < 4; i++)\r
+ propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r
+ if (propsRes->DictionarySize == 0)\r
+ propsRes->DictionarySize = 1;\r
+ }\r
+ #endif\r
+ return LZMA_RESULT_OK;\r
+}\r
+#endif\r
+\r
+#define kLzmaStreamWasFinishedId (-1)\r
+\r
+int LzmaDecode(CLzmaDecoderState *vs,\r
+ #ifdef _LZMA_IN_CB\r
+ ILzmaInCallback *InCallback,\r
+ #else\r
+ const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r
+ #endif\r
+ unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r
+{\r
+ CProb *p = vs->Probs;\r
+ SizeT nowPos = 0;\r
+ Byte previousByte = 0;\r
+ UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r
+ UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r
+ int lc = vs->Properties.lc;\r
+\r
+ #ifdef _LZMA_OUT_READ\r
+ \r
+ UInt32 Range = vs->Range;\r
+ UInt32 Code = vs->Code;\r
+ #ifdef _LZMA_IN_CB\r
+ const Byte *Buffer = vs->Buffer;\r
+ const Byte *BufferLim = vs->BufferLim;\r
+ #else\r
+ const Byte *Buffer = inStream;\r
+ const Byte *BufferLim = inStream + inSize;\r
+ #endif\r
+ int state = vs->State;\r
+ UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r
+ int len = vs->RemainLen;\r
+ UInt32 globalPos = vs->GlobalPos;\r
+ UInt32 distanceLimit = vs->DistanceLimit;\r
+\r
+ Byte *dictionary = vs->Dictionary;\r
+ UInt32 dictionarySize = vs->Properties.DictionarySize;\r
+ UInt32 dictionaryPos = vs->DictionaryPos;\r
+\r
+ Byte tempDictionary[4];\r
+\r
+ #ifndef _LZMA_IN_CB\r
+ *inSizeProcessed = 0;\r
+ #endif\r
+ *outSizeProcessed = 0;\r
+ if (len == kLzmaStreamWasFinishedId)\r
+ return LZMA_RESULT_OK;\r
+\r
+ if (dictionarySize == 0)\r
+ {\r
+ dictionary = tempDictionary;\r
+ dictionarySize = 1;\r
+ tempDictionary[0] = vs->TempDictionary[0];\r
+ }\r
+\r
+ if (len == kLzmaNeedInitId)\r
+ {\r
+ {\r
+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r
+ UInt32 i;\r
+ for (i = 0; i < numProbs; i++)\r
+ p[i] = kBitModelTotal >> 1; \r
+ rep0 = rep1 = rep2 = rep3 = 1;\r
+ state = 0;\r
+ globalPos = 0;\r
+ distanceLimit = 0;\r
+ dictionaryPos = 0;\r
+ dictionary[dictionarySize - 1] = 0;\r
+ #ifdef _LZMA_IN_CB\r
+ RC_INIT;\r
+ #else\r
+ RC_INIT(inStream, inSize);\r
+ #endif\r
+ }\r
+ len = 0;\r
+ }\r
+ while(len != 0 && nowPos < outSize)\r
+ {\r
+ UInt32 pos = dictionaryPos - rep0;\r
+ if (pos >= dictionarySize)\r
+ pos += dictionarySize;\r
+ outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r
+ if (++dictionaryPos == dictionarySize)\r
+ dictionaryPos = 0;\r
+ len--;\r
+ }\r
+ if (dictionaryPos == 0)\r
+ previousByte = dictionary[dictionarySize - 1];\r
+ else\r
+ previousByte = dictionary[dictionaryPos - 1];\r
+\r
+ #else /* if !_LZMA_OUT_READ */\r
+\r
+ int state = 0;\r
+ UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r
+ int len = 0;\r
+ const Byte *Buffer;\r
+ const Byte *BufferLim;\r
+ UInt32 Range;\r
+ UInt32 Code;\r
+\r
+ #ifndef _LZMA_IN_CB\r
+ *inSizeProcessed = 0;\r
+ #endif\r
+ *outSizeProcessed = 0;\r
+\r
+ {\r
+ UInt32 i;\r
+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r
+ for (i = 0; i < numProbs; i++)\r
+ p[i] = kBitModelTotal >> 1;\r
+ }\r
+ \r
+ #ifdef _LZMA_IN_CB\r
+ RC_INIT;\r
+ #else\r
+ RC_INIT(inStream, inSize);\r
+ #endif\r
+\r
+ #endif /* _LZMA_OUT_READ */\r
+\r
+ while(nowPos < outSize)\r
+ {\r
+ CProb *prob;\r
+ UInt32 bound;\r
+ int posState = (int)(\r
+ (nowPos \r
+ #ifdef _LZMA_OUT_READ\r
+ + globalPos\r
+ #endif\r
+ )\r
+ & posStateMask);\r
+\r
+ prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r
+ IfBit0(prob)\r
+ {\r
+ int symbol = 1;\r
+ UpdateBit0(prob)\r
+ prob = p + Literal + (LZMA_LIT_SIZE * \r
+ (((\r
+ (nowPos \r
+ #ifdef _LZMA_OUT_READ\r
+ + globalPos\r
+ #endif\r
+ )\r
+ & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r
+\r
+ if (state >= kNumLitStates)\r
+ {\r
+ int matchByte;\r
+ #ifdef _LZMA_OUT_READ\r
+ UInt32 pos = dictionaryPos - rep0;\r
+ if (pos >= dictionarySize)\r
+ pos += dictionarySize;\r
+ matchByte = dictionary[pos];\r
+ #else\r
+ matchByte = outStream[nowPos - rep0];\r
+ #endif\r
+ do\r
+ {\r
+ int bit;\r
+ CProb *probLit;\r
+ matchByte <<= 1;\r
+ bit = (matchByte & 0x100);\r
+ probLit = prob + 0x100 + bit + symbol;\r
+ RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r
+ }\r
+ while (symbol < 0x100);\r
+ }\r
+ while (symbol < 0x100)\r
+ {\r
+ CProb *probLit = prob + symbol;\r
+ RC_GET_BIT(probLit, symbol)\r
+ }\r
+ previousByte = (Byte)symbol;\r
+\r
+ outStream[nowPos++] = previousByte;\r
+ #ifdef _LZMA_OUT_READ\r
+ if (distanceLimit < dictionarySize)\r
+ distanceLimit++;\r
+\r
+ dictionary[dictionaryPos] = previousByte;\r
+ if (++dictionaryPos == dictionarySize)\r
+ dictionaryPos = 0;\r
+ #endif\r
+ if (state < 4) state = 0;\r
+ else if (state < 10) state -= 3;\r
+ else state -= 6;\r
+ }\r
+ else \r
+ {\r
+ UpdateBit1(prob);\r
+ prob = p + IsRep + state;\r
+ IfBit0(prob)\r
+ {\r
+ UpdateBit0(prob);\r
+ rep3 = rep2;\r
+ rep2 = rep1;\r
+ rep1 = rep0;\r
+ state = state < kNumLitStates ? 0 : 3;\r
+ prob = p + LenCoder;\r
+ }\r
+ else\r
+ {\r
+ UpdateBit1(prob);\r
+ prob = p + IsRepG0 + state;\r
+ IfBit0(prob)\r
+ {\r
+ UpdateBit0(prob);\r
+ prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
+ IfBit0(prob)\r
+ {\r
+ #ifdef _LZMA_OUT_READ\r
+ UInt32 pos;\r
+ #endif\r
+ UpdateBit0(prob);\r
+ \r
+ #ifdef _LZMA_OUT_READ\r
+ if (distanceLimit == 0)\r
+ #else\r
+ if (nowPos == 0)\r
+ #endif\r
+ return LZMA_RESULT_DATA_ERROR;\r
+ \r
+ state = state < kNumLitStates ? 9 : 11;\r
+ #ifdef _LZMA_OUT_READ\r
+ pos = dictionaryPos - rep0;\r
+ if (pos >= dictionarySize)\r
+ pos += dictionarySize;\r
+ previousByte = dictionary[pos];\r
+ dictionary[dictionaryPos] = previousByte;\r
+ if (++dictionaryPos == dictionarySize)\r
+ dictionaryPos = 0;\r
+ #else\r
+ previousByte = outStream[nowPos - rep0];\r
+ #endif\r
+ outStream[nowPos++] = previousByte;\r
+ #ifdef _LZMA_OUT_READ\r
+ if (distanceLimit < dictionarySize)\r
+ distanceLimit++;\r
+ #endif\r
+\r
+ continue;\r
+ }\r
+ else\r
+ {\r
+ UpdateBit1(prob);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ UInt32 distance;\r
+ UpdateBit1(prob);\r
+ prob = p + IsRepG1 + state;\r
+ IfBit0(prob)\r
+ {\r
+ UpdateBit0(prob);\r
+ distance = rep1;\r
+ }\r
+ else \r
+ {\r
+ UpdateBit1(prob);\r
+ prob = p + IsRepG2 + state;\r
+ IfBit0(prob)\r
+ {\r
+ UpdateBit0(prob);\r
+ distance = rep2;\r
+ }\r
+ else\r
+ {\r
+ UpdateBit1(prob);\r
+ distance = rep3;\r
+ rep3 = rep2;\r
+ }\r
+ rep2 = rep1;\r
+ }\r
+ rep1 = rep0;\r
+ rep0 = distance;\r
+ }\r
+ state = state < kNumLitStates ? 8 : 11;\r
+ prob = p + RepLenCoder;\r
+ }\r
+ {\r
+ int numBits, offset;\r
+ CProb *probLen = prob + LenChoice;\r
+ IfBit0(probLen)\r
+ {\r
+ UpdateBit0(probLen);\r
+ probLen = prob + LenLow + (posState << kLenNumLowBits);\r
+ offset = 0;\r
+ numBits = kLenNumLowBits;\r
+ }\r
+ else\r
+ {\r
+ UpdateBit1(probLen);\r
+ probLen = prob + LenChoice2;\r
+ IfBit0(probLen)\r
+ {\r
+ UpdateBit0(probLen);\r
+ probLen = prob + LenMid + (posState << kLenNumMidBits);\r
+ offset = kLenNumLowSymbols;\r
+ numBits = kLenNumMidBits;\r
+ }\r
+ else\r
+ {\r
+ UpdateBit1(probLen);\r
+ probLen = prob + LenHigh;\r
+ offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
+ numBits = kLenNumHighBits;\r
+ }\r
+ }\r
+ RangeDecoderBitTreeDecode(probLen, numBits, len);\r
+ len += offset;\r
+ }\r
+\r
+ if (state < 4)\r
+ {\r
+ int posSlot;\r
+ state += kNumLitStates;\r
+ prob = p + PosSlot +\r
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r
+ kNumPosSlotBits);\r
+ RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r
+ if (posSlot >= kStartPosModelIndex)\r
+ {\r
+ int numDirectBits = ((posSlot >> 1) - 1);\r
+ rep0 = (2 | ((UInt32)posSlot & 1));\r
+ if (posSlot < kEndPosModelIndex)\r
+ {\r
+ rep0 <<= numDirectBits;\r
+ prob = p + SpecPos + rep0 - posSlot - 1;\r
+ }\r
+ else\r
+ {\r
+ numDirectBits -= kNumAlignBits;\r
+ do\r
+ {\r
+ RC_NORMALIZE\r
+ Range >>= 1;\r
+ rep0 <<= 1;\r
+ if (Code >= Range)\r
+ {\r
+ Code -= Range;\r
+ rep0 |= 1;\r
+ }\r
+ }\r
+ while (--numDirectBits != 0);\r
+ prob = p + Align;\r
+ rep0 <<= kNumAlignBits;\r
+ numDirectBits = kNumAlignBits;\r
+ }\r
+ {\r
+ int i = 1;\r
+ int mi = 1;\r
+ do\r
+ {\r
+ CProb *prob3 = prob + mi;\r
+ RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r
+ i <<= 1;\r
+ }\r
+ while(--numDirectBits != 0);\r
+ }\r
+ }\r
+ else\r
+ rep0 = posSlot;\r
+ if (++rep0 == (UInt32)(0))\r
+ {\r
+ /* it's for stream version */\r
+ len = kLzmaStreamWasFinishedId;\r
+ break;\r
+ }\r
+ }\r
+\r
+ len += kMatchMinLen;\r
+ #ifdef _LZMA_OUT_READ\r
+ if (rep0 > distanceLimit) \r
+ #else\r
+ if (rep0 > nowPos)\r
+ #endif\r
+ return LZMA_RESULT_DATA_ERROR;\r
+\r
+ #ifdef _LZMA_OUT_READ\r
+ if (dictionarySize - distanceLimit > (UInt32)len)\r
+ distanceLimit += len;\r
+ else\r
+ distanceLimit = dictionarySize;\r
+ #endif\r
+\r
+ do\r
+ {\r
+ #ifdef _LZMA_OUT_READ\r
+ UInt32 pos = dictionaryPos - rep0;\r
+ if (pos >= dictionarySize)\r
+ pos += dictionarySize;\r
+ previousByte = dictionary[pos];\r
+ dictionary[dictionaryPos] = previousByte;\r
+ if (++dictionaryPos == dictionarySize)\r
+ dictionaryPos = 0;\r
+ #else\r
+ previousByte = outStream[nowPos - rep0];\r
+ #endif\r
+ len--;\r
+ outStream[nowPos++] = previousByte;\r
+ }\r
+ while(len != 0 && nowPos < outSize);\r
+ }\r
+ }\r
+ RC_NORMALIZE;\r
+\r
+ #ifdef _LZMA_OUT_READ\r
+ vs->Range = Range;\r
+ vs->Code = Code;\r
+ vs->DictionaryPos = dictionaryPos;\r
+ vs->GlobalPos = globalPos + (UInt32)nowPos;\r
+ vs->DistanceLimit = distanceLimit;\r
+ vs->Reps[0] = rep0;\r
+ vs->Reps[1] = rep1;\r
+ vs->Reps[2] = rep2;\r
+ vs->Reps[3] = rep3;\r
+ vs->State = state;\r
+ vs->RemainLen = len;\r
+ vs->TempDictionary[0] = tempDictionary[0];\r
+ #endif\r
+\r
+ #ifdef _LZMA_IN_CB\r
+ vs->Buffer = Buffer;\r
+ vs->BufferLim = BufferLim;\r
+ #else\r
+ *inSizeProcessed = (SizeT)(Buffer - inStream);\r
+ #endif\r
+ *outSizeProcessed = nowPos;\r
+ return LZMA_RESULT_OK;\r
+}\r
--- /dev/null
+/* \r
+ LzmaDecode.h\r
+ LZMA Decoder interface\r
+\r
+ LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r
+ http://www.7-zip.org/\r
+\r
+ LZMA SDK is licensed under two licenses:\r
+ 1) GNU Lesser General Public License (GNU LGPL)\r
+ 2) Common Public License (CPL)\r
+ It means that you can select one of these two licenses and \r
+ follow rules of that license.\r
+\r
+ SPECIAL EXCEPTION:\r
+ Igor Pavlov, as the author of this code, expressly permits you to \r
+ statically or dynamically link your code (or bind by name) to the \r
+ interfaces of this file without subjecting your linked code to the \r
+ terms of the CPL or GNU LGPL. Any modifications or additions \r
+ to this file, however, are subject to the LGPL or CPL terms.\r
+*/\r
+\r
+#ifndef __LZMADECODE_H\r
+#define __LZMADECODE_H\r
+\r
+/* #define _LZMA_IN_CB */\r
+/* Use callback for input data */\r
+\r
+/* #define _LZMA_OUT_READ */\r
+/* Use read function for output data */\r
+\r
+/* #define _LZMA_PROB32 */\r
+/* It can increase speed on some 32-bit CPUs, \r
+ but memory usage will be doubled in that case */\r
+\r
+/* #define _LZMA_LOC_OPT */\r
+/* Enable local speed optimizations inside code */\r
+\r
+/* #define _LZMA_SYSTEM_SIZE_T */\r
+/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r
+\r
+#ifndef UInt32\r
+#ifdef _LZMA_UINT32_IS_ULONG\r
+#define UInt32 unsigned long\r
+#else\r
+#define UInt32 unsigned int\r
+#endif\r
+#endif\r
+\r
+#ifndef SizeT\r
+#ifdef _LZMA_SYSTEM_SIZE_T\r
+#include <stddef.h>\r
+#define SizeT size_t\r
+#else\r
+#define SizeT UInt32\r
+#endif\r
+#endif\r
+\r
+#ifdef _LZMA_PROB32\r
+#define CProb UInt32\r
+#else\r
+#define CProb unsigned short\r
+#endif\r
+\r
+#define LZMA_RESULT_OK 0\r
+#define LZMA_RESULT_DATA_ERROR 1\r
+\r
+#ifdef _LZMA_IN_CB\r
+typedef struct _ILzmaInCallback\r
+{\r
+ int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r
+} ILzmaInCallback;\r
+#endif\r
+\r
+#define LZMA_BASE_SIZE 1846\r
+#define LZMA_LIT_SIZE 768\r
+\r
+#define LZMA_PROPERTIES_SIZE 5\r
+\r
+typedef struct _CLzmaProperties\r
+{\r
+ int lc;\r
+ int lp;\r
+ int pb;\r
+ #ifdef _LZMA_OUT_READ\r
+ UInt32 DictionarySize;\r
+ #endif\r
+}CLzmaProperties;\r
+\r
+int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r
+\r
+#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r
+\r
+#define kLzmaNeedInitId (-2)\r
+\r
+typedef struct _CLzmaDecoderState\r
+{\r
+ CLzmaProperties Properties;\r
+ CProb *Probs;\r
+\r
+ #ifdef _LZMA_IN_CB\r
+ const unsigned char *Buffer;\r
+ const unsigned char *BufferLim;\r
+ #endif\r
+\r
+ #ifdef _LZMA_OUT_READ\r
+ unsigned char *Dictionary;\r
+ UInt32 Range;\r
+ UInt32 Code;\r
+ UInt32 DictionaryPos;\r
+ UInt32 GlobalPos;\r
+ UInt32 DistanceLimit;\r
+ UInt32 Reps[4];\r
+ int State;\r
+ int RemainLen;\r
+ unsigned char TempDictionary[4];\r
+ #endif\r
+} CLzmaDecoderState;\r
+\r
+#ifdef _LZMA_OUT_READ\r
+#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r
+#endif\r
+\r
+int LzmaDecode(CLzmaDecoderState *vs,\r
+ #ifdef _LZMA_IN_CB\r
+ ILzmaInCallback *inCallback,\r
+ #else\r
+ const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r
+ #endif\r
+ unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r
+\r
+#endif\r
--- /dev/null
+LOADADDR = 0x80400000 # RAM start + 4M
+KERNEL_ENTRY = 0x80001000
+RAMSIZE = 0x00100000 # 1MB
+
+CROSS_COMPILE = mips-linux-
+
+.S.s:
+ $(CPP) $(CFLAGS) $< -o $*.s
+.S.o:
+ $(CC) $(CFLAGS) -c $< -o $*.o
+.c.o:
+ $(CC) $(CFLAGS) -c $< -o $*.o
+
+CC = $(CROSS_COMPILE)gcc
+LD = $(CROSS_COMPILE)ld
+OBJCOPY = $(CROSS_COMPILE)objcopy
+OBJDUMP = $(CROSS_COMPILE)objdump
+
+CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE} -DKERNEL_ENTRY=${KERNEL_ENTRY} -D_LZMA_IN_CB
+# CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE}
+
+O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
+
+# Drop some uninteresting sections in the kernel.
+# This is only relevant for ELF kernels but doesn't hurt a.out
+drop-sections = .reginfo .mdebug .comment
+strip-flags = $(addprefix --remove-section=,$(drop-sections))
+
+
+all : lzma.elf
+
+lzma.lds: lzma.lds.in
+ sed -e 's,@LOADADDR@,$(LOADADDR),g' $< >$@
+
+kernel.o: vmlinux.lzma lzma.lds
+ $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
+
+lzma.elf: start.o decompress.o LzmaDecode.o kernel.o
+ $(LD) -s -Tlzma.lds -o $@ $^
+
+clean:
+ rm -f *.o lzma.elf
--- /dev/null
+/*
+ * LZMA compressed kernel decompressor for bcm947xx boards
+ *
+ * Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * Please note, this was code based on the bunzip2 decompressor code
+ * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left
+ * is an idea and part of original vendor code
+ *
+ *
+ * 12-Mar-2005 Mineharu Takahara <mtakahar@yahoo.com>
+ * pass actual output size to decoder (stream mode
+ * compressed input is not a requirement anymore)
+ *
+ * 24-Apr-2005 Oleg I. Vdovikin
+ * reordered functions using lds script, removed forward decl
+ *
+ * ??-Nov-2005 Mike Baker
+ * reorder the script as an lzma wrapper; do not depend on flash access
+ */
+
+#include "LzmaDecode.h"
+
+#define KSEG0 0x80000000
+#define KSEG1 0xa0000000
+
+#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1)
+
+#define Index_Invalidate_I 0x00
+#define Index_Writeback_Inv_D 0x01
+
+#define cache_unroll(base,op) \
+ __asm__ __volatile__( \
+ ".set noreorder;\n" \
+ ".set mips3;\n" \
+ "cache %1, (%0);\n" \
+ ".set mips0;\n" \
+ ".set reorder\n" \
+ : \
+ : "r" (base), \
+ "i" (op));
+
+
+static __inline__ void blast_icache(unsigned long size, unsigned long lsize)
+{
+ unsigned long start = KSEG0;
+ unsigned long end = (start + size);
+
+ while(start < end) {
+ cache_unroll(start,Index_Invalidate_I);
+ start += lsize;
+ }
+}
+
+static __inline__ void blast_dcache(unsigned long size, unsigned long lsize)
+{
+ unsigned long start = KSEG0;
+ unsigned long end = (start + size);
+
+ while(start < end) {
+ cache_unroll(start,Index_Writeback_Inv_D);
+ start += lsize;
+ }
+}
+
+unsigned char *data;
+
+static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize)
+{
+ *bufferSize = 1;
+ *buffer = data;
+ ++data;
+ return LZMA_RESULT_OK;
+}
+
+static __inline__ unsigned char get_byte(void)
+{
+ unsigned char *buffer;
+ UInt32 fake;
+
+ return read_byte(0, &buffer, &fake), *buffer;
+}
+
+static char *buffer = (char *)0x80C00000;
+extern char lzma_start[];
+extern char lzma_end[];
+
+/* should be the first function */
+void entry(unsigned long icache_size, unsigned long icache_lsize,
+ unsigned long dcache_size, unsigned long dcache_lsize)
+{
+ unsigned int i; /* temp value */
+ unsigned int osize; /* uncompressed size */
+
+ ILzmaInCallback callback;
+ CLzmaDecoderState vs;
+ callback.Read = read_byte;
+
+ data = lzma_start;
+
+ /* lzma args */
+ i = get_byte();
+ vs.Properties.lc = i % 9, i = i / 9;
+ vs.Properties.lp = i % 5, vs.Properties.pb = i / 5;
+
+ vs.Probs = (CProb *)buffer;
+
+ /* skip rest of the LZMA coder property */
+ for (i = 0; i < 4; i++)
+ get_byte();
+
+ /* read the lower half of uncompressed size in the header */
+ osize = ((unsigned int)get_byte()) +
+ ((unsigned int)get_byte() << 8) +
+ ((unsigned int)get_byte() << 16) +
+ ((unsigned int)get_byte() << 24);
+
+ /* skip rest of the header (upper half of uncompressed size) */
+ for (i = 0; i < 4; i++)
+ get_byte();
+
+ /* decompress kernel */
+ if ((i = LzmaDecode(&vs, &callback,
+ (unsigned char*)KERNEL_ENTRY, osize, &osize)) == LZMA_RESULT_OK)
+ {
+ blast_dcache(dcache_size, dcache_lsize);
+ blast_icache(icache_size, icache_lsize);
+
+ /* Jump to load address */
+ ((void (*)(void)) KERNEL_ENTRY)();
+ }
+}
--- /dev/null
+OUTPUT_ARCH(mips)
+ENTRY(_start)
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ . = @LOADADDR@;
+ .text :
+ {
+ _ftext = . ;
+ *(.text)
+ *(.rodata)
+ lzma_start = .;
+ kernel.o
+ lzma_end = .;
+ } =0
+
+ .reginfo : { *(.reginfo) }
+
+ .bss :
+ {
+ *(.bss)
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include "print.h"
+
+/* macros */
+#define IsDigit(x) ( ((x) >= '0') && ((x) <= '9') )
+#define Ctod(x) ( (x) - '0')
+
+/* forward declaration */
+extern int PrintChar(char *, char, int, int);
+extern int PrintString(char *, char *, int, int);
+extern int PrintNum(char *, unsigned long, int, int, int, int, char, int);
+
+/* private variable */
+static const char theFatalMsg[] = "fatal error in lp_Print!";
+
+/* -*-
+ * A low level printf() function.
+ */
+void
+lp_Print(void (*output)(void *, char *, int),
+ void * arg,
+ char *fmt,
+ va_list ap)
+{
+
+#define OUTPUT(arg, s, l) \
+ { if (((l) < 0) || ((l) > LP_MAX_BUF)) { \
+ (*output)(arg, (char*)theFatalMsg, sizeof(theFatalMsg)-1); for(;;); \
+ } else { \
+ (*output)(arg, s, l); \
+ } \
+ }
+
+ char buf[LP_MAX_BUF];
+
+ char c;
+ char *s;
+ long int num;
+
+ int longFlag;
+ int negFlag;
+ int width;
+ int prec;
+ int ladjust;
+ char padc;
+
+ int length;
+
+ for(;;) {
+ {
+ /* scan for the next '%' */
+ char *fmtStart = fmt;
+ while ( (*fmt != '\0') && (*fmt != '%')) {
+ fmt ++;
+ }
+
+ /* flush the string found so far */
+ OUTPUT(arg, fmtStart, fmt-fmtStart);
+
+ /* are we hitting the end? */
+ if (*fmt == '\0') break;
+ }
+
+ /* we found a '%' */
+ fmt ++;
+
+ /* check for long */
+ if (*fmt == 'l') {
+ longFlag = 1;
+ fmt ++;
+ } else {
+ longFlag = 0;
+ }
+
+ /* check for other prefixes */
+ width = 0;
+ prec = -1;
+ ladjust = 0;
+ padc = ' ';
+
+ if (*fmt == '-') {
+ ladjust = 1;
+ fmt ++;
+ }
+
+ if (*fmt == '0') {
+ padc = '0';
+ fmt++;
+ }
+
+ if (IsDigit(*fmt)) {
+ while (IsDigit(*fmt)) {
+ width = 10 * width + Ctod(*fmt++);
+ }
+ }
+
+ if (*fmt == '.') {
+ fmt ++;
+ if (IsDigit(*fmt)) {
+ prec = 0;
+ while (IsDigit(*fmt)) {
+ prec = prec*10 + Ctod(*fmt++);
+ }
+ }
+ }
+
+
+ /* check format flag */
+ negFlag = 0;
+ switch (*fmt) {
+ case 'b':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ length = PrintNum(buf, num, 2, 0, width, ladjust, padc, 0);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'd':
+ case 'D':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ if (num < 0) {
+ num = - num;
+ negFlag = 1;
+ }
+ length = PrintNum(buf, num, 10, negFlag, width, ladjust, padc, 0);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'o':
+ case 'O':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ length = PrintNum(buf, num, 8, 0, width, ladjust, padc, 0);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'u':
+ case 'U':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ length = PrintNum(buf, num, 10, 0, width, ladjust, padc, 0);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'x':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 0);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'X':
+ if (longFlag) {
+ num = va_arg(ap, long int);
+ } else {
+ num = va_arg(ap, int);
+ }
+ length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 1);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 'c':
+ c = (char)va_arg(ap, int);
+ length = PrintChar(buf, c, width, ladjust);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case 's':
+ s = (char*)va_arg(ap, char *);
+ length = PrintString(buf, s, width, ladjust);
+ OUTPUT(arg, buf, length);
+ break;
+
+ case '\0':
+ fmt --;
+ break;
+
+ default:
+ /* output this char as it is */
+ OUTPUT(arg, fmt, 1);
+ } /* switch (*fmt) */
+
+ fmt ++;
+ } /* for(;;) */
+
+ /* special termination call */
+ OUTPUT(arg, "\0", 1);
+}
+
+
+/* --------------- local help functions --------------------- */
+int
+PrintChar(char * buf, char c, int length, int ladjust)
+{
+ int i;
+
+ if (length < 1) length = 1;
+ if (ladjust) {
+ *buf = c;
+ for (i=1; i< length; i++) buf[i] = ' ';
+ } else {
+ for (i=0; i< length-1; i++) buf[i] = ' ';
+ buf[length - 1] = c;
+ }
+ return length;
+}
+
+int
+PrintString(char * buf, char* s, int length, int ladjust)
+{
+ int i;
+ int len=0;
+ char* s1 = s;
+ while (*s1++) len++;
+ if (length < len) length = len;
+
+ if (ladjust) {
+ for (i=0; i< len; i++) buf[i] = s[i];
+ for (i=len; i< length; i++) buf[i] = ' ';
+ } else {
+ for (i=0; i< length-len; i++) buf[i] = ' ';
+ for (i=length-len; i < length; i++) buf[i] = s[i-length+len];
+ }
+ return length;
+}
+
+int
+PrintNum(char * buf, unsigned long u, int base, int negFlag,
+ int length, int ladjust, char padc, int upcase)
+{
+ /* algorithm :
+ * 1. prints the number from left to right in reverse form.
+ * 2. fill the remaining spaces with padc if length is longer than
+ * the actual length
+ * TRICKY : if left adjusted, no "0" padding.
+ * if negtive, insert "0" padding between "0" and number.
+ * 3. if (!ladjust) we reverse the whole string including paddings
+ * 4. otherwise we only reverse the actual string representing the num.
+ */
+
+ int actualLength =0;
+ char *p = buf;
+ int i;
+
+ do {
+ int tmp = u %base;
+ if (tmp <= 9) {
+ *p++ = '0' + tmp;
+ } else if (upcase) {
+ *p++ = 'A' + tmp - 10;
+ } else {
+ *p++ = 'a' + tmp - 10;
+ }
+ u /= base;
+ } while (u != 0);
+
+ if (negFlag) {
+ *p++ = '-';
+ }
+
+ /* figure out actual length and adjust the maximum length */
+ actualLength = p - buf;
+ if (length < actualLength) length = actualLength;
+
+ /* add padding */
+ if (ladjust) {
+ padc = ' ';
+ }
+ if (negFlag && !ladjust && (padc == '0')) {
+ for (i = actualLength-1; i< length-1; i++) buf[i] = padc;
+ buf[length -1] = '-';
+ } else {
+ for (i = actualLength; i< length; i++) buf[i] = padc;
+ }
+
+
+ /* prepare to reverse the string */
+ {
+ int begin = 0;
+ int end;
+ if (ladjust) {
+ end = actualLength - 1;
+ } else {
+ end = length -1;
+ }
+
+ while (end > begin) {
+ char tmp = buf[begin];
+ buf[begin] = buf[end];
+ buf[end] = tmp;
+ begin ++;
+ end --;
+ }
+ }
+
+ /* adjust the string pointer */
+ return length;
+}
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _print_h_
+#define _print_h_
+
+#include <stdarg.h>
+
+/* this is the maximum width for a variable */
+#define LP_MAX_BUF 80
+
+/* -*-
+ * output function takes an void pointer which is passed in as the
+ * second argument in lp_Print(). This black-box argument gives output
+ * function a way to track state.
+ *
+ * The second argument in output function is a pointer to char buffer.
+ * The third argument specifies the number of chars to outputed.
+ *
+ * output function cannot assume the buffer is null-terminated after
+ * l number of chars.
+ */
+void lp_Print(void (*output)(void *, char *, int),
+ void * arg,
+ char *fmt,
+ va_list ap);
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include "printf.h"
+#include "print.h"
+#include "uart16550.h"
+
+static void myoutput(void *arg, char *s, int l)
+{
+ int i;
+
+ // special termination call
+ if ((l==1) && (s[0] == '\0')) return;
+
+ for (i=0; i< l; i++) {
+ Uart16550Put(s[i]);
+ if (s[i] == '\n') Uart16550Put('\r');
+ }
+}
+
+void printf(char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ lp_Print(myoutput, 0, fmt, ap);
+ va_end(ap);
+}
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _printf_h_
+#define _printf_h_
+
+#include <stdarg.h>
+void printf(char *fmt, ...);
+
+#endif /* _printf_h_ */
--- /dev/null
+#include <asm/asm.h>
+#include <asm/regdef.h>
+
+#define KSEG0 0x80000000
+
+#define C0_CONFIG $16
+#define C0_TAGLO $28
+#define C0_TAGHI $29
+
+#define CONF1_DA_SHIFT 7 /* D$ associativity */
+#define CONF1_DA_MASK 0x00000380
+#define CONF1_DA_BASE 1
+#define CONF1_DL_SHIFT 10 /* D$ line size */
+#define CONF1_DL_MASK 0x00001c00
+#define CONF1_DL_BASE 2
+#define CONF1_DS_SHIFT 13 /* D$ sets/way */
+#define CONF1_DS_MASK 0x0000e000
+#define CONF1_DS_BASE 64
+#define CONF1_IA_SHIFT 16 /* I$ associativity */
+#define CONF1_IA_MASK 0x00070000
+#define CONF1_IA_BASE 1
+#define CONF1_IL_SHIFT 19 /* I$ line size */
+#define CONF1_IL_MASK 0x00380000
+#define CONF1_IL_BASE 2
+#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
+#define CONF1_IS_MASK 0x01c00000
+#define CONF1_IS_BASE 64
+
+#define Index_Invalidate_I 0x00
+#define Index_Writeback_Inv_D 0x01
+
+LEAF(_start)
+
+ .set mips32
+ .set noreorder
+
+ /* set up stack */
+ li sp, 0xa0000000 + RAMSIZE - 16
+
+
+ /* At this point we need to invalidate dcache and */
+ /* icache before jumping to new code */
+
+1: /* Get cache sizes */
+ mfc0 s0,C0_CONFIG,1
+
+ li s1,CONF1_DL_MASK
+ and s1,s0
+ beq s1,zero,nodc
+ nop
+
+ srl s1,CONF1_DL_SHIFT
+ li t0,CONF1_DL_BASE
+ sll s1,t0,s1 /* s1 has D$ cache line size */
+
+ li s2,CONF1_DA_MASK
+ and s2,s0
+ srl s2,CONF1_DA_SHIFT
+ addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */
+
+ li t0,CONF1_DS_MASK
+ and t0,s0
+ srl t0,CONF1_DS_SHIFT
+ li s3,CONF1_DS_BASE
+ sll s3,s3,t0 /* s3 has D$ sets per way */
+
+ multu s2,s3 /* sets/way * associativity */
+ mflo t0 /* total cache lines */
+
+ multu s1,t0 /* D$ linesize * lines */
+ mflo s2 /* s2 is now D$ size in bytes */
+
+ /* Initilize the D$: */
+ mtc0 zero,C0_TAGLO
+ mtc0 zero,C0_TAGHI
+
+ li t0,KSEG0 /* Just an address for the first $ line */
+ addu t1,t0,s2 /* + size of cache == end */
+
+1: cache Index_Writeback_Inv_D,0(t0)
+ bne t0,t1,1b
+ addu t0,s1
+
+nodc:
+ /* Now we get to do it all again for the I$ */
+
+ move s3,zero /* just in case there is no icache */
+ move s4,zero
+
+ li t0,CONF1_IL_MASK
+ and t0,s0
+ beq t0,zero,noic
+ nop
+
+ srl t0,CONF1_IL_SHIFT
+ li s3,CONF1_IL_BASE
+ sll s3,t0 /* s3 has I$ cache line size */
+
+ li t0,CONF1_IA_MASK
+ and t0,s0
+ srl t0,CONF1_IA_SHIFT
+ addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */
+
+ li t0,CONF1_IS_MASK
+ and t0,s0
+ srl t0,CONF1_IS_SHIFT
+ li s5,CONF1_IS_BASE
+ sll s5,t0 /* s5 has I$ sets per way */
+
+ multu s4,s5 /* sets/way * associativity */
+ mflo t0 /* s4 is now total cache lines */
+
+ multu s3,t0 /* I$ linesize * lines */
+ mflo s4 /* s4 is cache size in bytes */
+
+ /* Initilize the I$: */
+ mtc0 zero,C0_TAGLO
+ mtc0 zero,C0_TAGHI
+
+ li t0,KSEG0 /* Just an address for the first $ line */
+ addu t1,t0,s4 /* + size of cache == end */
+
+1: cache Index_Invalidate_I,0(t0)
+ bne t0,t1,1b
+ addu t0,s3
+noic:
+ /* jump to main */
+ move a0,s3 /* icache line size */
+ move a1,s4 /* icache size */
+ move a2,s1 /* dcache line size */
+ jal entry
+ move a3,s2 /* dcache size */
+
+ .set reorder
+END(_start)
+
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+
+#include "uart16550.h"
+
+/* === CONFIG === */
+
+#define BASE 0xb8058000
+#define MAX_BAUD 1152000
+#define REG_OFFSET 4
+
+/* === END OF CONFIG === */
+
+/* register offset */
+#define OFS_RCV_BUFFER (0*REG_OFFSET)
+#define OFS_TRANS_HOLD (0*REG_OFFSET)
+#define OFS_SEND_BUFFER (0*REG_OFFSET)
+#define OFS_INTR_ENABLE (1*REG_OFFSET)
+#define OFS_INTR_ID (2*REG_OFFSET)
+#define OFS_DATA_FORMAT (3*REG_OFFSET)
+#define OFS_LINE_CONTROL (3*REG_OFFSET)
+#define OFS_MODEM_CONTROL (4*REG_OFFSET)
+#define OFS_RS232_OUTPUT (4*REG_OFFSET)
+#define OFS_LINE_STATUS (5*REG_OFFSET)
+#define OFS_MODEM_STATUS (6*REG_OFFSET)
+#define OFS_RS232_INPUT (6*REG_OFFSET)
+#define OFS_SCRATCH_PAD (7*REG_OFFSET)
+
+#define OFS_DIVISOR_LSB (0*REG_OFFSET)
+#define OFS_DIVISOR_MSB (1*REG_OFFSET)
+
+
+/* memory-mapped read/write of the port */
+#define UART16550_READ(y) (*((volatile uint32*)(BASE + y)))
+#define UART16550_WRITE(y, z) ((*((volatile uint32*)(BASE + y))) = z)
+
+#define DEBUG_LED (*(unsigned short*)0xb7ffffc0)
+#define OutputLED(x) (DEBUG_LED = x)
+
+void Uart16550Init(uint32 baud, uint8 data, uint8 parity, uint8 stop)
+{
+ /* disable interrupts */
+ UART16550_WRITE(OFS_INTR_ENABLE, 0);
+
+ /* set up buad rate */
+ {
+ uint32 divisor;
+
+ /* set DIAB bit */
+ UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
+
+ /* set divisor */
+ divisor = MAX_BAUD / baud;
+ UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
+ UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00)>>8);
+
+ /* clear DIAB bit */
+ UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
+ }
+
+ /* set data format */
+ UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
+}
+
+uint8 Uart16550GetPoll()
+{
+ while((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
+ return UART16550_READ(OFS_RCV_BUFFER);
+}
+
+
+void Uart16550Put(uint8 byte)
+{
+ while ((UART16550_READ(OFS_LINE_STATUS) &0x20) == 0);
+ UART16550_WRITE(OFS_SEND_BUFFER, byte);
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _uart16550_h_
+#define _uart16550_h_
+
+typedef unsigned char uint8;
+typedef unsigned int uint32;
+
+#define UART16550_BAUD_2400 2400
+#define UART16550_BAUD_4800 4800
+#define UART16550_BAUD_9600 9600
+#define UART16550_BAUD_19200 19200
+#define UART16550_BAUD_38400 38400
+#define UART16550_BAUD_57600 57600
+#define UART16550_BAUD_115200 115200
+
+#define UART16550_PARITY_NONE 0
+#define UART16550_PARITY_ODD 0x08
+#define UART16550_PARITY_EVEN 0x18
+#define UART16550_PARITY_MARK 0x28
+#define UART16550_PARITY_SPACE 0x38
+
+#define UART16550_DATA_5BIT 0x0
+#define UART16550_DATA_6BIT 0x1
+#define UART16550_DATA_7BIT 0x2
+#define UART16550_DATA_8BIT 0x3
+
+#define UART16550_STOP_1BIT 0x0
+#define UART16550_STOP_2BIT 0x4
+
+void Uart16550Init(uint32 baud, uint8 data, uint8 parity, uint8 stop);
+
+/* blocking call */
+uint8 Uart16550GetPoll();
+
+void Uart16550Put(uint8 byte);
+
+#endif