wok-tiny rev 139
linux: pack setup
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jul 01 10:56:29 2018 +0200 (2018-07-01) |
parents | c0783b759e56 |
children | d71bd8881bcd |
files | linux/receipt linux/stuff/pack linux/stuff/unlzma.S linux/stuff/unpacklz4.S |
line diff
1.1 --- a/linux/receipt Mon Mar 05 22:31:30 2018 +0100 1.2 +++ b/linux/receipt Sun Jul 01 10:56:29 2018 +0200 1.3 @@ -16,12 +16,18 @@ 1.4 1.5 DEPENDS="" 1.6 BUILD_DEPENDS="slitaz-toolchain perl git lzma wget gcc2" 1.7 -BUILD_SUGGESTED="advancecomp zopfli" 1.8 +BUILD_SUGGESTED="advancecomp zopfli lz4 grep" 1.9 1.10 case "$TARGET" in 1.11 i486) SUGGESTED="memtest ipxe";; # bundle may install a boot menu 1.12 esac 1.13 1.14 +S2bin() 1.15 +{ 1.16 + cc -o $1.o -Wa,-algms=$1.lst -c $stuff/$1.S 1.17 + objcopy -O binary $1.o $1.bin 1.18 +} 1.19 + 1.20 # Rules to configure and make the package. 1.21 compile_rules() 1.22 { 1.23 @@ -47,23 +53,22 @@ 1.24 cp $WOK/busybox/source/busybox*/.config $src/config-busybox 1.25 mkdir $src/slitaz 1.26 cp $stuff/list_modules.sh $src/slitaz 1.27 - cc -o bootloader.o -Wa,-algms=bootloader.lst -c $stuff/bootloader.S 1.28 - objcopy -O binary bootloader.o bootloader.bin 1.29 + S2bin bootloader 1.30 + S2bin unpacklz4 1.31 1.32 sed -i '/config %config:/{NNNps/config %config:/%config:/}' Makefile 1.33 sed -i 's/^config %config:/config:/' Makefile 1.34 cp $stuff/linux-$VERSION-slitaz.config .config 1.35 yes '' | make ARCH=i386 HOSTCC=gcc-2 config 1.36 make ARCH=i386 CC=gcc-2 HOSTCC=gcc-2 -j 4 bzImage 1.37 + $stuff/pack bzImage 1.38 grep -q "CONFIG_MODULES=y" .config && 1.39 make ARCH=i386 CC=gcc-2 HOSTCC=gcc-2 -j 4 modules && 1.40 make ARCH=i386 INSTALL_MOD_PATH=$DESTDIR -j 1 modules_install || true 1.41 - cc -o bundle.o -Wa,-algms=bundle.lst -c $stuff/bundle.S 1.42 - objcopy -O binary bundle.o bundle.bin 1.43 + S2bin bundle 1.44 cp $stuff/bundle . 1.45 ./bundle 1.46 - cc -o cmdline.o -Wa,-algms=cmdline.lst -c $stuff/cmdline.S 1.47 - objcopy -O binary cmdline.o cmdline.bin 1.48 + S2bin cmdline 1.49 } 1.50 1.51 # Rules to gen a SliTaz package suitable for Tazpkg.
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/linux/stuff/pack Sun Jul 01 10:56:29 2018 +0200 2.3 @@ -0,0 +1,69 @@ 2.4 +#!/bin/sh 2.5 + 2.6 +ddq() 2.7 +{ 2.8 + dd "$@" 2> /dev/null 2.9 +} 2.10 + 2.11 +word() 2.12 +{ 2.13 + n=$1; for i in $(seq 1 1 ${2:-2}); do 2.14 + printf '\\\\x%02X' $(($n & 255)) 2.15 + n=$(($n >> 8)) 2.16 + done | xargs echo -en 2.17 +} 2.18 + 2.19 +store() 2.20 +{ 2.21 + word $2 "$4" | ddq bs=1 conv=notrunc of="$3" seek=$(($1)) 2.22 +} 2.23 + 2.24 +get() 2.25 +{ 2.26 + echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An "$2") 2.27 +} 2.28 + 2.29 +if which lz4 > /dev/null ; then 2.30 + 2.31 +# boot + head param 2.32 +param=$((514+$(get 0x201 $1 1))) 2.33 +ddq if=$1 bs=1 count=$param > /tmp/setup$$ 2.34 + 2.35 +# unlz4 + data 2.36 +ddq if=unpacklz4.bin >> /tmp/setup$$ 2.37 +setupsz=$(get 0x1F1 $1 1) 2.38 +ddq if=$1 bs=1 skip=$param count=$(($setupsz*512-$param+512)) | \ 2.39 + lz4 -l -12 | ddq bs=4 skip=1 >> /tmp/setup$$ 2.40 + 2.41 +# version string 2.42 +word $(get 0x20E $1) >> /tmp/setup$$ 2.43 +word $setupsz 1 >> /tmp/setup$$ 2.44 +versionofs= 2.45 +version="$(ddq if=$1 bs=1 skip=$((0x200+$(get 0x20E $1))) | strings | sed q)" 2.46 +if grep --help 2>&1 | grep -q byte-offset; then 2.47 + versionofs=$(grep -obaF "$version" /tmp/setup$$ | sed 's/:.*//') 2.48 +fi 2.49 +if [ -z "$versionofs" ]; then 2.50 + versionofs=$(stat -c %s /tmp/setup$$) 2.51 + echo -en "$version\0" >> /tmp/setup$$ 2.52 +fi 2.53 +store 0x20E $(($versionofs-512)) /tmp/setup$$ 2.54 + 2.55 +helpersz=0 2.56 +[ -n "$2" ] && helpersz=$(stat -Lc %s "$2") 2.57 +newsetupsz=$((($(stat -c %s /tmp/setup$$)+$helpersz-1)/512)) 2.58 +[ $newsetupsz -lt 4 ] && newsetupsz=4 2.59 +store 0x1F1 $newsetupsz /tmp/setup$$ 1 2.60 + 2.61 +if [ $newsetupsz -lt $setupsz ]; then 2.62 + ddq of=/tmp/setup$$ bs=512 seek=$(($newsetupsz+1)) count=0 2.63 + [ -n "$2" ] && ddq if="$2" bs=1 of=/tmp/setup$$ \ 2.64 + seek=$((512 + 512*$newsetupsz - $helpersz)) 2.65 + [ -n "$3" ] && [ $(stat -Lc %s "$3") -eq 497 ] && 2.66 + ddq if="$3" conv=notrunc of=/tmp/setup$$ 2.67 + ddq if=$1 bs=512 skip=$((1+$setupsz)) >> /tmp/setup$$ 2.68 + cp /tmp/setup$$ $1 2.69 +fi 2.70 +rm -f /tmp/setup$$ 2.71 + 2.72 +fi
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/linux/stuff/unlzma.S Sun Jul 01 10:56:29 2018 +0200 3.3 @@ -0,0 +1,1019 @@ 3.4 +// #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 3.5 +// 3.6 +// #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) 3.7 +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; 3.8 +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; 3.9 +// 3.10 +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ 3.11 +// { UpdateBit0(p); mi <<= 1; A0; } else \ 3.12 +// { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 3.13 +// 3.14 +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) 3.15 +// 3.16 +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \ 3.17 +// { int i = numLevels; res = 1; \ 3.18 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ 3.19 +// res -= (1 << numLevels); } 3.20 +/* 3.21 + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3 3.22 + */ 3.23 + 3.24 +#define PROP_PB 2 3.25 +#define PROP_LP 0 3.26 +#define PROP_LC 3 3.27 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45)) 3.28 + 3.29 +// static const Byte *Buffer; 3.30 +// static UInt32 bound, Code, Range; 3.31 + 3.32 +/* 3.33 + * Buffer register DS:SI 3.34 + * all var based ws=ss:bp 3.35 + */ 3.36 + 3.37 +rep0 = -4 // long 3.38 +rep1 = rep0-4 // long 3.39 +rep2 = rep0-8 // long 3.40 +rep3 = rep0-12 // long 3.41 +state = -17 // byte, 0..11 3.42 +posState = state-1 // byte, 0..15 3.43 +posState2 = posState-1 // byte, 0..15 3.44 +scratched = rep0-16 // byte = 1 3.45 +Code = -24 // long 3.46 +outStream = -28 // long 3.47 +nowPos = outStream // long 3.48 +Range = Code-8 // long 3.49 +#define LOCALS 32 3.50 + 3.51 +// int LzmaDecode(CLzmaDecoderState *vs, 3.52 +// const unsigned char *inStream, 3.53 +// unsigned char *outStream) 3.54 +// { 3.55 +// CProb *p = vs->Probs; 3.56 +// SizeT nowPos = 0; 3.57 +// #define posStateMask = (1 << (vs->Properties.pb)) - 1; 3.58 +// #define literalPosMask = (1 << (vs->Properties.lp)) - 1; 3.59 +// int lc = vs->Properties.lc, state = 0, len = 0; 3.60 +// UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 3.61 +// 3.62 +// { 3.63 +// UInt32 i, numProbs = Literal /*1846*/ 3.64 +// + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp)); 3.65 +// for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1; 3.66 + 3.67 +#define WS (1846+(768<<(PROP_LC+PROP_LP))) 3.68 +#if (WS+WS+LOCALS) >= 65000 3.69 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */ 3.70 +#error invalid (lc,lp,pb) : out of memory 3.71 +#endif 3.72 + 3.73 +ws1 = WS 3.74 +ws2 = ws1*2 3.75 +ws = ws2+LOCALS+15 3.76 + 3.77 +#ifndef FLAT32 3.78 +#define AX %ax 3.79 +#define BX %bx 3.80 +#define CX %cx 3.81 +#define DX %dx 3.82 +#define SI %si 3.83 +#define DI %di 3.84 +#define BP %bp 3.85 +#define SP %sp 3.86 +#define CWD cwd 3.87 +#else 3.88 +#define AX %eax 3.89 +#define BX %ebx 3.90 +#define CX %ecx 3.91 +#define DX %edx 3.92 +#define SI %esi 3.93 +#define DI %edi 3.94 +#define BP %ebp 3.95 +#define SP %esp 3.96 +#define CWD cdq 3.97 +#endif 3.98 +/* 3.99 + * LzmaDecode: 3.100 +#ifndef FLAT32 3.101 + * input ds:si=inStream, es:di=outStream 3.102 + * output outStream[], ds:si, es:di 3.103 + .code 16 3.104 +#else 3.105 + * input esi=inStream, edi=outStream 3.106 + * output outStream[], esi, edi 3.107 + .code 32 3.108 +#endif 3.109 + */ 3.110 + 3.111 + mov $ws1, CX 3.112 +#ifdef ONLY8086 3.113 + movw $2048/2, %ax 3.114 +lzd1: 3.115 + pushw %ax 3.116 +#else 3.117 +lzd1: 3.118 + pushw $2048/2 3.119 +#endif 3.120 + loop lzd1 3.121 + mov SP, BP 3.122 + movb $((LOCALS+3)/4)*2, %cl 3.123 +#ifdef ONLY8086 3.124 + movw $1, %ax 3.125 + cwd 3.126 +initlocals: 3.127 + pushw %dx 3.128 + pushw %ax 3.129 +#else 3.130 +initlocals: 3.131 + pushl $1 3.132 +#endif 3.133 + loop initlocals 3.134 + 3.135 +#if !defined(FLAT32) && !defined(FLAT16OUT) 3.136 + movb $4, %cl 3.137 + movw %es, %bx 3.138 + shrw %cl, %bx 3.139 + movw %es, %dx 3.140 + shlw %cl, %dx 3.141 + addw %dx, %di 3.142 + movw %di, outStream(%bp) 3.143 + adcb %bh, outStream+2(%bp) 3.144 + incw %cx 3.145 +#else 3.146 + movb $5, %cl 3.147 + mov DI, outStream(BP) 3.148 +#endif 3.149 + 3.150 +// Byte previousByte = 0; 3.151 + xor BX, BX 3.152 + 3.153 +// #define RC_INIT(buffer) 3.154 +// Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; 3.155 +// { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }} 3.156 +// } 3.157 +// RC_INIT(inStream); 3.158 + 3.159 +#ifndef NO_LZMA_HEADER 3.160 +#ifdef CHECK_LZMA_HEADER 3.161 + cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1) 3.162 + je lzip_header 3.163 + cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8) 3.164 + jne no_header 3.165 + add $13-6, SI // skip lzma header 3.166 +lzip_header: 3.167 + add $6, SI // skip lzip header 3.168 +no_header: 3.169 +#else 3.170 + add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8) 3.171 +#endif 3.172 +#endif 3.173 +setrep: 3.174 + call RC_LOAD_BYTE 3.175 + decb Range(BP) 3.176 + loop setrep 3.177 + 3.178 +lzdmainlp: 3.179 +// while(1) { 3.180 +// CProb *prob; 3.181 +// int posState = (int)((nowPos) & posStateMask); 3.182 +// 3.183 +// prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState; 3.184 +// if (Bit0(prob)) { /* char */ 3.185 + 3.186 + xor DX, DX 3.187 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 3.188 + mov $state, DI 3.189 + jc lzdstring 3.190 + 3.191 +// prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * 3.192 +// ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc)))); 3.193 + 3.194 +#if PROP_LC != 0 3.195 +# ifdef ONLY8086 3.196 + movb $8-PROP_LC, %cl 3.197 + shrb %cl, %bl 3.198 +# else 3.199 + shrb $8-PROP_LC, %bl 3.200 +# endif 3.201 +#endif 3.202 + 3.203 +#if PROP_LP != 0 3.204 + movb posState2(BP), %dl 3.205 +# ifdef ONLY8086 3.206 + movb $PROP_LC, %cl 3.207 + shl %cl, DX 3.208 +# else 3.209 + shl $PROP_LC, DX 3.210 +# endif 3.211 + movb $0, %bh 3.212 + add BX, DX 3.213 +#endif 3.214 + 3.215 + movb $3, %ah 3.216 + mul BX // dx = 3*bh 3.217 + add $1846, AX 3.218 + 3.219 +// int symbol = 1; 3.220 + 3.221 + CWD 3.222 + inc DX // symbol = 1 3.223 + xchg AX, CX // save prob 3.224 + 3.225 +// if (state >= kNumLitStates /*7*/) { /* previous was string */ 3.226 +// if (state < 4) state = 0; 3.227 + 3.228 +lzd6z: 3.229 + subb $3, (BP, DI) 3.230 + 3.231 +// if (state < 4) state = 0; 3.232 + 3.233 + jnc lzd6 3.234 + movb %dh, (BP, DI) // %dh = 0 3.235 + 3.236 +lzd6: 3.237 +// else if (state < 10) state -= 3; 3.238 + 3.239 + cmpb $10-3, (BP, DI) 3.240 + 3.241 +// else state -= 6; 3.242 + 3.243 + jnb lzd6z 3.244 + cmpb $7-3-1, (BP, DI) 3.245 + jbe lzd3 3.246 + 3.247 +// int matchByte = outStream[nowPos - rep0]; 3.248 + 3.249 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0]; 3.250 + 3.251 +// do { 3.252 +// int bit; 3.253 +// CProb *probLit; 3.254 +// matchByte <<= 1; bit = (matchByte & 0x100); 3.255 + 3.256 + movb $1, %bh 3.257 +lzd4: 3.258 + shlb $1, %bl // matchByte <<= 1 3.259 + sbb DI, DI // save bit=C 3.260 + 3.261 +// probLit = prob + 0x100 + bit + symbol; 3.262 + 3.263 + mov CX, AX // restore prob 3.264 + adcb %bh, %ah // + bit + 0x100 3.265 + 3.266 +// RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break) 3.267 + 3.268 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 3.269 + rclb $1, %dl // symbol <<= 1; symbol |= C 3.270 + jc lzd5 // if symbol >= 0x100 3.271 + cmp DI, AX 3.272 + jz lzd4 // if bit == Bit1(prob+%ax) 3.273 + 3.274 +// } while (symbol < 0x100); 3.275 +// } 3.276 +lzd3: 3.277 +// while (symbol < 0x100) { 3.278 +// CProb *probLit = prob + symbol; 3.279 +// RC_GET_BIT(probLit, symbol) 3.280 +// } 3.281 + 3.282 + xor BX, BX 3.283 + jmp lzd4 3.284 +lzd5: 3.285 + 3.286 +// outStream[nowPos++] = previousByte = (Byte)symbol; 3.287 + 3.288 + xchg AX, DX 3.289 + call outchar // %bl = outStream[nowPos++] = %al; 3.290 + jmp lzdmainlp 3.291 + 3.292 +// } 3.293 + 3.294 +lzdstring: 3.295 + mov $1, CX 3.296 + 3.297 +// else { /* string */ 3.298 +// prob = p + IsRep /*192*/ + state; 3.299 + 3.300 + movb $192, %dl 3.301 + addb (BP, DI), %dl 3.302 + mov $rep0, DI 3.303 + 3.304 +// if (Bit0(prob)) { 3.305 + 3.306 + call Bit1dx // Bit1(prob) 3.307 + jc lzd8 3.308 + 3.309 +// rep3 = rep2; rep2 = rep1; rep1 = rep0; 3.310 +// state = (state < kNumLitStates /*7*/) ? 0 : 3; 3.311 + 3.312 + stc 3.313 + 3.314 +// prob = p + LenCoder /*818*/; 3.315 + 3.316 + mov $818, DX 3.317 + 3.318 +// } 3.319 + 3.320 + jmp lzd11a 3.321 + 3.322 +// else { 3.323 +lzd8: 3.324 +// prob += kNumStates /*12*/; 3.325 +// if (Bit0(prob)) { 3.326 + call Bit1dx12 // prob += 12; Bit1(prob) 3.327 + jc lzd11 3.328 +// prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) 3.329 +// + posState; 3.330 + movb $240, %dl // dh=0 3.331 + 3.332 +// if (Bit0(prob)) { 3.333 + 3.334 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 3.335 + jc lzd12 3.336 + 3.337 +// // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR; 3.338 +// state = (state < kNumLitStates /*7*/) ? 9 : 11; 3.339 + 3.340 + movb $9, %dl 3.341 + 3.342 +// len++; goto string; 3.343 + jmp lzd13string // ax = 0 3.344 +// } 3.345 +// } 3.346 +// else { 3.347 +lzd11: 3.348 +// UInt32 distance = rep1; 3.349 +// prob += kNumStates /*12*/; 3.350 +// if (!Bit0(prob)) { 3.351 + 3.352 + call Bit1dx12 // prob += 12; Bit1(prob) 3.353 + jnc lzd11z 3.354 + 3.355 +// prob += kNumStates /*12*/; 3.356 +// if (Bit0(prob)) distance = rep2; 3.357 + 3.358 + call Bit1dx12 // prob += 12; Bit1(prob) 3.359 +lzd11a: 3.360 + adcb %cl, %cl 3.361 + 3.362 +// else { distance = rep3; rep3 = rep2; } 3.363 +// rep2 = rep1; 3.364 +// } 3.365 +// rep1 = rep0; rep0 = distance; 3.366 + 3.367 +lzd11z: 3.368 +# ifdef ONLY8086 3.369 + shl $1, CX 3.370 + shl $1, CX // 8->32 bits 3.371 + sub CX, DI // &rep[cx] 3.372 + movw (BP, DI), %ax 3.373 + pushw 2(BP, DI) 3.374 +rotreplp: 3.375 + movb 4(BP, DI), %bl 3.376 + movb %bl, (BP, DI) 3.377 + inc DI 3.378 + loop rotreplp 3.379 + popw %bx 3.380 + testb %dh, %dh 3.381 + jnz lzd10 3.382 + movw %ax, (BP, DI) 3.383 + movw %bx, 2(BP, DI) 3.384 +# else 3.385 + shl $2, CX // 8->32 bits 3.386 + sub CX, DI // &rep[cx] 3.387 + movl (BP, DI), %eax 3.388 +rotreplp: 3.389 + movb 4(BP, DI), %bl 3.390 + movb %bl, (BP, DI) 3.391 + inc DI 3.392 + loop rotreplp 3.393 + testb %dh, %dh 3.394 + jnz lzd10 3.395 + movl %eax, (BP, DI) 3.396 +# endif 3.397 + 3.398 +// } 3.399 +lzd12: 3.400 +// state = (state < kNumLitStates /*7*/) ? 8 : 11; 3.401 + 3.402 + movb $0x08, %cl 3.403 + 3.404 +// prob = p + RepLenCoder /*1332*/; 3.405 + 3.406 + mov $1332, DX 3.407 + 3.408 +// } 3.409 +lzd10: 3.410 + push CX // CX = 0 3.411 + 3.412 +// { /* get len */ 3.413 +// int numBits, offset; 3.414 +// CProb *probLen = prob + LenChoice /*0*/; 3.415 +// numBits = kLenNumLowBits /*3*/; 3.416 + 3.417 + movb $8, %cl // numBits : 3,3,8 3.418 + 3.419 +// if (Bit0(probLen)) { 3.420 + 3.421 + call Bit1dx // Bit1(prob) 3.422 + xchg AX, BX 3.423 + inc DX 3.424 + jnc lzd15 // bx=0 3.425 + 3.426 +// probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/); 3.427 +// offset = 0; 3.428 +// } 3.429 +// else { 3.430 +// probLen = prob + LenChoice2 /*1*/; 3.431 + 3.432 + call Bit1dx // Bit1(prob) 3.433 + add AX, BX 3.434 + 3.435 +#if PROP_PB != 0 3.436 + inc AX // ah=0 3.437 +#endif 3.438 + jc lzd16 // %ax=0, %bx=-2 3.439 +lzd15: 3.440 +#if PROP_PB != 0 3.441 + movb $8, %al 3.442 + mulb posState(BP) 3.443 +#endif 3.444 + 3.445 +// if (Bit0(probLen)) { 3.446 +// probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/); 3.447 + 3.448 + movb $3, %cl // numBits : 3,3,8 3.449 +lzd16: 3.450 +#if PROP_PB != 0 3.451 + add $2-128-1, AX // probLen : 2,130,258 3.452 +#else 3.453 + mov $2-128-1, AX // probLen : 2,130,258 3.454 +#endif 3.455 + add DX, AX 3.456 + mov $-8+1, DX // offset : 0,8,16 3.457 +lzdargslp: 3.458 + add $8, DX 3.459 + add $128, AX 3.460 + inc BX 3.461 + jle lzdargslp // leave with bx=1 3.462 + 3.463 +// offset = kLenNumLowSymbols /*8*/; 3.464 +// //numBits = kLenNumMidBits /*3*/; 3.465 +// } 3.466 +// else { 3.467 +// probLen = prob + LenHigh /*258*/; 3.468 +// offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/; 3.469 +// numBits = kLenNumHighBits /*8*/; 3.470 +// } 3.471 +// } 3.472 +// RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset; 3.473 + 3.474 + push DX 3.475 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 3.476 + pop DX 3.477 + add DX, AX // offset 3.478 + pop DX // 0 3.479 +lzd13string: 3.480 + push AX 3.481 + 3.482 +// state = (state < kNumLitStates /*7*/) ? dl : dl|3; 3.483 + 3.484 + movb $7, %cl 3.485 + cmpb %cl, state(BP) 3.486 + jb new_state 3.487 + orb $3, %dl 3.488 +new_state: 3.489 + movb %dl, state(BP) 3.490 + 3.491 +// } /* get len */ 3.492 +// if (state < 4) { 3.493 + 3.494 + cmpb $4-1, %dl 3.495 + ja lzd19 3.496 + 3.497 +// int posSlot; 3.498 +// state += kNumLitStates /*7*/; 3.499 + 3.500 + addb %cl, state(BP) 3.501 + 3.502 +// prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? 3.503 +// len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/); 3.504 + 3.505 + cmp $4+1, AX 3.506 + jb lzd21 3.507 + mov $3+1, AX 3.508 + 3.509 +lzd21: 3.510 + 3.511 + dec CX // cx = 6 3.512 + shl %cl, AX 3.513 + add $432-64, AX 3.514 + 3.515 +// RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot); 3.516 + 3.517 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 3.518 + 3.519 +// if (posSlot >= kStartPosModelIndex /*4*/) { 3.520 +// int numDirectBits = ((posSlot >> 1) - 1); 3.521 + 3.522 +#ifndef FLAT32 3.523 + movw %cx, 2(%bp, %di) // %cx = 0 3.524 +#endif 3.525 + mov AX, (BP, DI) 3.526 + mov AX, CX 3.527 + shrw $1, CX 3.528 + dec CX 3.529 + cmpb $4, %al 3.530 + jb lzd22 3.531 + 3.532 +// rep0 = (2 | ((UInt32)posSlot & 1)); 3.533 + 3.534 + andb %bl, (BP, DI) // %bx=1 3.535 + orb $2, (BP, DI) 3.536 + 3.537 +// if (posSlot < kEndPosModelIndex /*14*/) { 3.538 + 3.539 + cmpb $14, %al 3.540 + jnb lzd23 3.541 + 3.542 +// rep0 <<= numDirectBits; 3.543 + 3.544 + neg AX 3.545 +# ifdef ONLY8086 3.546 + pushw %cx 3.547 + movb $0, %ch 3.548 +shllrep0: 3.549 + shlw $1, (BP, DI) 3.550 + rclw $1, 2(BP, DI) 3.551 + loop shllrep0 3.552 + popw %cx 3.553 +# else 3.554 + shll %cl, (BP, DI) 3.555 +# endif 3.556 + add (BP, DI), AX 3.557 + 3.558 +// prob = p + SpecPos /*688*/ + rep0 - posSlot - 1; 3.559 + 3.560 + add $687, AX 3.561 + jmp lzd24 3.562 + 3.563 +// } 3.564 +// else { 3.565 +lzd23: 3.566 +// numDirectBits -= kNumAlignBits /*4*/; 3.567 +// do { 3.568 +// RC_NORMALIZE; Range >>= 1; rep0 <<= 1; 3.569 +// if (Code >= Range) { Code -= Range; rep0 |= 1; } 3.570 + 3.571 +lzd23z: 3.572 + call RC_NORMALIZE 3.573 +# ifdef ONLY8086 3.574 + pushw %dx 3.575 + shrw $1, Range+2(BP) 3.576 + rcrw $1, Range(BP) 3.577 + movw Range(BP), %ax 3.578 + movw Range+2(BP), %dx 3.579 + cmpw Code+2(BP), %dx 3.580 + ja lzd25 3.581 + jb lzd25x 3.582 + cmpw Code(BP), %ax 3.583 + ja lzd25 3.584 +lzd25x: 3.585 + subw %ax, Code(BP) 3.586 + sbbw %dx, Code+2(BP) 3.587 + stc 3.588 +lzd25: 3.589 + popw %dx 3.590 + rclw $1, (BP, DI) 3.591 + rclw $1, 2(BP, DI) 3.592 +# else 3.593 + shrl $1, Range(BP) 3.594 + movl Range(BP), %eax 3.595 + cmpl Code(BP), %eax 3.596 + ja lzd25 3.597 + subl %eax, Code(BP) 3.598 + stc 3.599 +lzd25: 3.600 + rcll $1, (BP, DI) 3.601 +# endif 3.602 + 3.603 +// } while (--numDirectBits != 0); 3.604 + 3.605 + cmpb $4+1, %cl 3.606 + loopne lzd23z 3.607 + 3.608 +// prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/; 3.609 +// rep0 <<= numDirectBits; 3.610 + 3.611 +# ifdef ONLY8086 3.612 + pushw %cx 3.613 + movb $0, %ch 3.614 +shlrep0: 3.615 + shlw $1, (BP, DI) 3.616 + rclw $1, 2(BP, DI) 3.617 + loop shlrep0 3.618 + popw %cx 3.619 +# else 3.620 + shll %cl, (BP, DI) 3.621 +# endif 3.622 + mov $802, AX 3.623 +// } 3.624 + 3.625 +lzd24: 3.626 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 3.627 + 3.628 +// { 3.629 +// int i = 1, mi = 1; 3.630 +// do { 3.631 +// CProb *prob3 = prob + mi; 3.632 +// RC_GET_BIT2(prob3, mi, ; , rep0 |= i); 3.633 + 3.634 + orb %dh, (BP, DI) // update rep0 with DirectBits 3.635 + 3.636 +// i <<= 1; 3.637 +// } while(--numDirectBits != 0); 3.638 +// } 3.639 +// } else rep0 = posSlot; 3.640 +lzd22: 3.641 +// if (++rep0 == (UInt32)(0)) break; /* EOF */ 3.642 + 3.643 +# ifdef ONLY8086 3.644 + incw (BP, DI) 3.645 + jnz lzd19 3.646 + incw 2(BP, DI) 3.647 +# else 3.648 + incl (BP, DI) 3.649 +# endif 3.650 + 3.651 +lzd19: 3.652 + pop CX 3.653 + jz lzdone 3.654 + 3.655 +// } 3.656 +// len += kMatchMinLen;/*2*/ 3.657 + 3.658 + inc CX 3.659 + 3.660 +// string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR; 3.661 +// do { 3.662 +lzd13z: 3.663 +// previousByte = outStream[nowPos - rep0]; 3.664 +// outStream[nowPos++] = previousByte; 3.665 + 3.666 + call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0] 3.667 + 3.668 +// } while(--len != 0); 3.669 + 3.670 + loop lzd13z 3.671 + 3.672 +// } /* char/string */ 3.673 +// } 3.674 + 3.675 + jmp lzdmainlp 3.676 + 3.677 +lzdone: 3.678 +// //RC_NORMALIZE; 3.679 +// //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos; 3.680 +// return LZMA_RESULT_OK; 3.681 + call Dico2ESDI // set es & di (rep0 = 0) 3.682 + lea ws2(BP), SP // dealloc 3.683 + ret 3.684 +// } 3.685 + 3.686 +// al = outStream[nowPos - rep0]; 3.687 + 3.688 +/* 3.689 + * output es:di, al 3.690 + * scratch bh, cl, flags 3.691 + */ 3.692 + 3.693 +DicoRep02ESDI: 3.694 + stc 3.695 + 3.696 +// bl = outStream[nowPos]; 3.697 + 3.698 +/* 3.699 + * output es:di, bl 3.700 + * scratch bh, cl, flags 3.701 + */ 3.702 + 3.703 +Dico2ESDI: 3.704 +#if !defined(FLAT32) && !defined(FLAT16OUT) 3.705 +# ifdef ONLY8086 3.706 + pushw %ax 3.707 + movw nowPos(%bp), %bx 3.708 + movw nowPos+2(%bp), %ax 3.709 + jnc Dico2ESDIz 3.710 + subw rep0(%bp), %bx 3.711 + sbbw rep0+2(%bp), %ax 3.712 +Dico2ESDIz: 3.713 + movw $0xF, %di 3.714 + andw %bx, %di 3.715 + pushw %cx 3.716 + movb $4, %cl 3.717 + shrw %cl, %bx 3.718 + shlw %cl, %ax 3.719 + popw %cx 3.720 + addb %al, %bh 3.721 + popw %ax 3.722 +# else 3.723 + movl nowPos(%bp), %ebx 3.724 + jnc Dico2ESDIz 3.725 + subl rep0(%bp), %ebx 3.726 +Dico2ESDIz: 3.727 + movw %bx, %di 3.728 + xorw %bx, %bx 3.729 + shrl $4, %ebx 3.730 +# endif 3.731 + movw %bx, %es 3.732 +#else 3.733 + mov nowPos(BP), DI 3.734 + jnc Dico2ESDIz 3.735 + sub rep0(BP), DI 3.736 +Dico2ESDIz: 3.737 +#endif 3.738 +#ifdef FLAT32 3.739 + movb (DI), %bl 3.740 +#else 3.741 + movb %es:(%di), %bl 3.742 +#endif 3.743 + ret 3.744 + 3.745 +outcharDico: 3.746 + 3.747 +// bl = outStream[nowPos++] = outStream[nowPos - rep0] 3.748 + 3.749 +/* 3.750 + * output es:di, bl 3.751 + * update nowPos 3.752 + * scratch ax, dx, bh, cl, flags 3.753 + */ 3.754 + 3.755 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0] 3.756 + xchg AX, BX 3.757 +outchar: 3.758 + 3.759 +// bl = outStream[nowPos++] = previousByte = al; 3.760 + 3.761 +/* 3.762 + * output bl 3.763 + * update nowPos 3.764 + * scratch ax, dx, bh, di, cl, flags 3.765 + */ 3.766 + 3.767 + clc 3.768 + call Dico2ESDI 3.769 + stosb 3.770 + xchg AX, BX // previous byte 3.771 + 3.772 +// int posState = (int)((nowPos) & posStateMask); 3.773 + 3.774 +#if PROP_PB != 0 && PROP_LP != 0 3.775 + addw $0x0101, posState2(BP) 3.776 + andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP) 3.777 +#else 3.778 +# if PROP_PB != 0 3.779 + incb posState(BP) 3.780 + andb $((1 << PROP_PB) -1), posState(BP) 3.781 +# endif 3.782 +# if PROP_LP != 0 3.783 + incb posState2(BP) 3.784 + andb $((1 << PROP_LP) -1), posState2(BP) 3.785 +# endif 3.786 +#endif 3.787 +#ifdef ONLY8086 3.788 + incw nowPos(BP) 3.789 + jnz incnowPosDone 3.790 + incw nowPos+2(BP) 3.791 +incnowPosDone: 3.792 +#else 3.793 + incl nowPos(BP) 3.794 +#endif 3.795 + ret 3.796 + 3.797 +// 3.798 +// #define RC_NORMALIZE if (Range < kTopValue) 3.799 +// { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 3.800 + 3.801 +/* 3.802 + * update Range, Code, ds:si 3.803 + * scratch flags 3.804 + */ 3.805 + 3.806 +RC_NORMALIZE: 3.807 + cmpb $0, Range+3(BP) 3.808 + jne RC_NORMALIZE_1 3.809 +RC_LOAD_BYTE: 3.810 + push AX 3.811 +#ifdef ONLY8086 3.812 + movw Range+1(BP), %ax 3.813 + movw %ax, Range+2(BP) 3.814 + movw Code+1(BP), %ax 3.815 + movw %ax, Code+2(BP) 3.816 + xorw %ax, %ax 3.817 + movb Range(BP), %ah 3.818 + movw %ax, Range(BP) 3.819 + movb Code(BP), %ah 3.820 + movw %ax, Code(BP) 3.821 +#else 3.822 + shll $8, Range(BP) 3.823 + shll $8, Code(BP) 3.824 +#endif 3.825 +#if !defined(FLAT16) && !defined(FLAT32) 3.826 + testw %si, %si 3.827 + jns RC_READ_BYTE 3.828 + movw %ds, %ax 3.829 + incw %ax 3.830 + movw %ax, %ds 3.831 + addw $-16, %si 3.832 +RC_READ_BYTE: 3.833 +#endif 3.834 + lodsb 3.835 + movb %al, Code(BP) 3.836 + pop AX 3.837 +RC_NORMALIZE_1: 3.838 + ret 3.839 + 3.840 +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 3.841 + 3.842 +Bit1state: 3.843 + movb $16, %al 3.844 + mulb state(BP) 3.845 +# if PROP_PB != 0 3.846 + addb posState(BP), %al 3.847 +# endif 3.848 +Bit1axdx: 3.849 + add DX, AX 3.850 + jmp Bit1 3.851 + 3.852 +// prob += 12; Bit1(prob) 3.853 + 3.854 +Bit1dx12: 3.855 + add $12, DX 3.856 +Bit1dx: 3.857 + mov DX, AX 3.858 + 3.859 +// static int Bit1(CProb *p) 3.860 + 3.861 +Bit1: 3.862 +/* 3.863 + * input ax=p 3.864 + * output C, ax 3.865 + * update bound, Range, Code, ds:si 3.866 + * scratch flags 3.867 + */ 3.868 + 3.869 +// { 3.870 +// RC_NORMALIZE; 3.871 + 3.872 + call RC_NORMALIZE // kill %ax, update %si 3.873 + 3.874 +#ifdef ONLY8086 3.875 + pushw %ax 3.876 + pushw %cx 3.877 + pushw %dx 3.878 + pushw %di 3.879 +#else 3.880 + pushal 3.881 +#endif 3.882 + 3.883 + xchg AX, DI 3.884 + add DI, DI // short * 3.885 + 3.886 + 3.887 +// bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p); 3.888 + 3.889 +#ifdef ONLY8086 3.890 + movw Range(BP), %dx 3.891 + movw Range+2(BP), %ax 3.892 + movw $11, %cx 3.893 +shr11lp: 3.894 + shrw $1, %ax 3.895 + rcrw $1, %dx 3.896 + loop shr11lp 3.897 + movw %dx, %cx 3.898 + mulw (BP, DI) 3.899 + xchgw %ax, %cx 3.900 + mulw (BP, DI) 3.901 + addw %cx, %dx 3.902 +#else 3.903 + movl Range(BP), %eax 3.904 + shrl $11, %eax 3.905 + movzwl (BP, DI), %edx 3.906 + mull %edx 3.907 +#endif 3.908 + 3.909 +// if (Code < bound) { 3.910 + 3.911 +#ifdef ONLY8086 3.912 + cmpw Code+2(BP), %dx 3.913 + jb Bit1_1 3.914 + ja Bit1_1x 3.915 + cmpw Code(BP), %ax 3.916 + jbe Bit1_1 3.917 +Bit1_1x: 3.918 + 3.919 +// Range = bound; 3.920 + 3.921 + movw %ax, Range(BP) 3.922 + movw %dx, Range+2(BP) 3.923 +#else 3.924 + cmpl Code(BP), %eax 3.925 + jbe Bit1_1 3.926 + 3.927 +// Range = bound; 3.928 + 3.929 + movl %eax, Range(BP) 3.930 +#endif 3.931 + 3.932 +// *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/; 3.933 + 3.934 + movw $2048, %ax 3.935 + 3.936 +// return 0; 3.937 + 3.938 + jmp Bit1_2 3.939 + 3.940 +// } 3.941 +// else { 3.942 + 3.943 +Bit1_1: 3.944 + 3.945 +// Range -= bound; Code -= bound; 3.946 + 3.947 +#ifdef ONLY8086 3.948 + subw %ax, Range(BP) 3.949 + sbbw %dx, Range+2(BP) 3.950 + subw %ax, Code(BP) 3.951 + sbbw %dx, Code+2(BP) 3.952 +#else 3.953 + subl %eax, Range(BP) 3.954 + subl %eax, Code(BP) 3.955 +#endif 3.956 + 3.957 +// *(p) -= (*(p)) >> kNumMoveBits /*5*/; 3.958 + 3.959 + movw $31, %ax 3.960 + 3.961 +// return 1; 3.962 + 3.963 + stc 3.964 +Bit1_2: 3.965 + pushf 3.966 + subw (BP, DI), %ax 3.967 +#ifdef ONLY8086 3.968 + movb $5, %cl 3.969 + sarw %cl, %ax 3.970 +#else 3.971 + sarw $5, %ax 3.972 +#endif 3.973 + addw %ax, (BP, DI) 3.974 + popf 3.975 +#ifdef ONLY8086 3.976 + popw %di 3.977 + popw %dx 3.978 + popw %cx 3.979 + popw %ax 3.980 +#else 3.981 + popal 3.982 +#endif 3.983 + sbb AX, AX 3.984 + 3.985 +// } 3.986 +// } 3.987 + 3.988 + ret 3.989 + 3.990 +RangeDecoder: 3.991 + 3.992 +/* 3.993 + * input ax=probs cx=numLevels (< 8) bx=1 3.994 + * output ax=res (backward), dh (forward) 3.995 + * update bound, Range, Code, ds:si 3.996 + * scratch flags, cx=0, dl 3.997 + */ 3.998 + 3.999 + push BX 3.1000 + 3.1001 +// { int i = numLevels; res = 1; 3.1002 + mov BX, DX // res = 1 3.1003 + 3.1004 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); 3.1005 + 3.1006 +RangeDecoder_1: 3.1007 + push AX 3.1008 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 3.1009 + rclb $1, %dl // res <<= 1; res |= C 3.1010 + andb %bl, %al // current bit 3.1011 + orb %al, %bh // store in bh 3.1012 + shlb $1, %bl // update max 3.1013 + pop AX 3.1014 + loop RangeDecoder_1 3.1015 + 3.1016 +// res -= (1 << numLevels); } 3.1017 + 3.1018 + xchg AX, BX // move bh to dh 3.1019 + xchg AX, DX // and dl to al 3.1020 + sub %dl, %al // sub max 3.1021 + pop BX 3.1022 + ret
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/linux/stuff/unpacklz4.S Sun Jul 01 10:56:29 2018 +0200 4.3 @@ -0,0 +1,118 @@ 4.4 +// objdump -D -b binary -mi386 -Maddr16,data16 mbr 4.5 + 4.6 + .code16 4.7 + .org 0 4.8 + 4.9 +#define LZMA 0 4.10 +#define HOLE 0x4000 4.11 + 4.12 +start: 4.13 + cld 4.14 +#define packed_moved HOLE+0x200+packed 4.15 + movw $packed_moved-next, %di 4.16 + xorw %si, %si 4.17 + movw %di, %cx 4.18 + pushw %ds 4.19 + popw %es 4.20 + rep movsb %ds:(%si), %es:(%di) // move setup 4.21 + pushw %cs // CS 4.22 + pushw %cx // IP = 0 4.23 + call packed_moved 4.24 +next: 4.25 + popw %di 4.26 + addw %di, %si 4.27 + addw $0x200+start-next, %di 4.28 +#if LZMA 4.29 + call unlzma 4.30 +#else 4.31 + 4.32 +#define ARCHIVE_MAGICNUMBER 0x184C2102 4.33 +#define NEGATIVE_OFFSETS 0 // non standard hack 4.34 +#define LENGTH_16BITS 0 // non standard hack 4.35 +#define BYTE_RLE 0 4.36 + 4.37 +lz4main: 4.38 + lodsl // get chunkSize 4.39 + //cmpl $ARCHIVE_MAGICNUMBER, %eax 4.40 + //je lz4main 4.41 + addw %si, %ax 4.42 + xchgw %ax, %dx 4.43 + jmp lz4chunk // %cx = 0 4.44 + 4.45 +lz4len: // get length in %cx 4.46 + andw $0xF, %ax 4.47 + cmpb $0xF, %al 4.48 + xchgw %ax, %cx 4.49 + jne lz4quit 4.50 +lz4len2: 4.51 + lodsb 4.52 + addw %ax, %cx 4.53 + cmpb $0xFF, %al 4.54 +#if LENGTH_16BITS 4.55 + jne lz4quit 4.56 + lodsw 4.57 + addw %ax, %cx 4.58 +#else 4.59 + je lz4len2 4.60 +#endif 4.61 +lz4quit: 4.62 + ret 4.63 + 4.64 +#if BYTE_RLE 4.65 + movb -1(%di), %al 4.66 + rep stosb %es:(%di) // fill string 4.67 + jmp lz4chunk 4.68 +#endif 4.69 + 4.70 +lz4string: 4.71 + lodsw // get string offset 4.72 + xchgw %ax, %bx 4.73 + call lz4len // get string length 4.74 +#if BYTE_RLE 4.75 + add $4, %cx // minimum match is 4 4.76 + decw %bx 4.77 + jz lz4rle 4.78 +# if NEGATIVE_OFFSETS 4.79 + incw %bx 4.80 +# else 4.81 + notw %bx 4.82 +# endif 4.83 +#endif 4.84 + xchgw %ax, %si 4.85 +#if NEGATIVE_OFFSETS || BYTE_RLE 4.86 + leaw (%bx,%di), %si 4.87 +#else 4.88 + movw %di, %si 4.89 + subw %bx, %si 4.90 +#endif 4.91 + rep movsb %ds:(%si), %es:(%di) // copy string 4.92 +#if !BYTE_RLE 4.93 + movsl %ds:(%si), %es:(%di) // minimum match is 4 4.94 +#endif 4.95 + xchgw %ax, %si 4.96 + 4.97 +lz4chunk: // uncompress chunk 4.98 + lodsb // get token 4.99 + movb %al, %bl 4.100 + shrb $4, %al 4.101 + call lz4len // get literal length 4.102 + rep movsb %ds:(%si), %es:(%di) // copy literals 4.103 + cmpw %dx, %si 4.104 + jb lz4string 4.105 +#endif 4.106 +done: 4.107 + movw $0x20E, %di 4.108 + movsw // version string 4.109 + movw $0x1F1, %di 4.110 + movsb // setup size 4.111 + retf 4.112 + 4.113 +#if LZMA 4.114 +#define FLAT16 1 4.115 +#define FLAT16OUT 1 4.116 +#define NO_LZMA_HEADER 1 4.117 +unlzma: 4.118 +#include "unlzma.S" 4.119 +#endif 4.120 + 4.121 +packed: