wok-tiny rev 172
Add x86test & tfttest
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat May 08 17:23:19 2021 +0000 (2021-05-08) |
parents | da3ed5ef7be8 |
children | eb617e43dc08 |
files | tfttest/receipt tfttest/stuff/bootloader.S tfttest/stuff/tfttest.img x86test/receipt x86test/stuff/bootloader.S x86test/stuff/pack x86test/stuff/unlzma.S x86test/stuff/unpack.S x86test/stuff/x86test |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tfttest/receipt Sat May 08 17:23:19 2021 +0000 1.3 @@ -0,0 +1,39 @@ 1.4 +# SliTaz package receipt. 1.5 + 1.6 +PACKAGE="tfttest" 1.7 +VERSION="1.01" 1.8 +CATEGORY="base-system" 1.9 +SHORT_DESC="CHZ Monitor-Test is a dead pixel detection tool." 1.10 +MAINTAINER="pascal.bellard@slitaz.org" 1.11 +LICENSE="GPL2" 1.12 +WEB_SITE="http://www.slitaz.org/" 1.13 +TARGET="i486" 1.14 + 1.15 +# Rules to configure and make the package. 1.16 +compile_rules() 1.17 +{ 1.18 + mkdir -p $src/mnt && cd $src 1.19 + mount -o ro,loop $stuff/tfttest.img mnt 1.20 + cp mnt/* . 1.21 + cp $stuff/bootloader.S . 1.22 + for i in bootloader ; do 1.23 + cc -o $i.o -Wa,-a=$i.lst -c $i.S 1.24 + objcopy -O binary $i.o $i.bin 1.25 + done 1.26 + dd if=TFTTEST.COM of=bootloader.bin bs=16 seek=6 conv=notrunc 2> /dev/null 1.27 + umount mnt 1.28 +} 1.29 + 1.30 +# Rules to gen a SliTaz package suitable for Tazpkg. 1.31 +genpkg_rules() 1.32 +{ 1.33 + mkdir -p $fs/boot 1.34 + cp $src/bootloader.bin $fs/boot/$PACKAGE 1.35 +} 1.36 + 1.37 +# Post install/remove commands for Tazpkg. 1.38 +post_install() 1.39 +{ 1.40 + grep -qs ^tfttest $1/boot/bootmenu || 1.41 + echo "tfttest Tfttest,pixel,tft Check dead pixels (may run under DOS if renamed to tfttest.com)" >> $1/boot/bootmenu 1.42 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tfttest/stuff/bootloader.S Sat May 08 17:23:19 2021 +0000 2.3 @@ -0,0 +1,59 @@ 2.4 + .text 2.5 + .code16 2.6 + .arch i8086 2.7 + .org 0 2.8 + .globl _start 2.9 +_start: 2.10 + call start2 2.11 +start2: 2.12 + popw %bx 2.13 + cmpb $0x1, %bh 2.14 + je dotcom 2.15 + xorw %ax, %ax # %ax = 0 2.16 + movw %ax, %ds 2.17 + leaw int21-start2(%bx), %ax 2.18 + movw %ax,0x21*4 2.19 + movw %cs,0x21*4+2 2.20 + movw $0x7C0-0x10, %ax 2.21 + movw %ax, %ds 2.22 +dotcom: 2.23 + movw %ds, %ax 2.24 + addw $6, %ax # addw $code/16, %ax 2.25 + movw %ax, %ds 2.26 + movw %ax, %es 2.27 + movw %ax, %ss 2.28 + movw $0xFFFE, %sp 2.29 + pushw %ds 2.30 + movw $0x100, %ax 2.31 + pushw %ax 2.32 + cbw 2.33 + xorw %bx, %bx 2.34 + retf 2.35 + 2.36 +int21: 2.37 + cmpb $7, %ah 2.38 + jne not_input 2.39 + movb $0, %ah 2.40 + int $0x16 2.41 +do_iret: 2.42 + iret 2.43 +not_input: 2.44 + cmpb $9, %ah 2.45 + jne abort 2.46 + movw %dx, %si 2.47 +puts: 2.48 + lodsb 2.49 + cmpb $'$', %al 2.50 + je do_iret 2.51 + movb $0xe, %ah 2.52 + movw $0xf, %bx 2.53 + int $0x10 2.54 + jmp puts 2.55 +abort: 2.56 + ljmp $0xffff,$0 2.57 + 2.58 + .org 0x60 2.59 +code: 2.60 + .org 510 2.61 + 2.62 + .word 0xaa55
3.1 Binary file tfttest/stuff/tfttest.img has changed
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/x86test/receipt Sat May 08 17:23:19 2021 +0000 4.3 @@ -0,0 +1,42 @@ 4.4 +# SliTaz package receipt. 4.5 + 4.6 +PACKAGE="x86test" 4.7 +VERSION="0.10a" 4.8 +CATEGORY="base-system" 4.9 +SHORT_DESC="CPU failures detection tool." 4.10 +MAINTAINER="pascal.bellard@slitaz.org" 4.11 +LICENSE="GPL2" 4.12 +WEB_SITE="http://www.slitaz.org/" 4.13 +TARGET="i486" 4.14 + 4.15 +BUILD_DEPENDS="xz" 4.16 + 4.17 +# Rules to configure and make the package. 4.18 +compile_rules() 4.19 +{ 4.20 + mkdir -p $src && cd $src 4.21 + cp $stuff/x86test $stuff/*.S $stuff/pack . 4.22 + sed -i '/#define ONLY8086/d' unpack.S 4.23 + for i in bootloader unpack ; do 4.24 + cc -o $i.o -Wa,-a=$i.lst -c $i.S 4.25 + objcopy -O binary $i.o $i.bin 4.26 + done 4.27 + sed -i "s/VERSION/$VERSION/" pack 4.28 + ./pack --build bootloader.bin unpack.bin 4.29 + ./pack x86test x86test.packed 4.30 + dd if=bootloader.bin of=x86test conv=notrunc 2> /dev/null 4.31 +} 4.32 + 4.33 +# Rules to gen a SliTaz package suitable for Tazpkg. 4.34 +genpkg_rules() 4.35 +{ 4.36 + mkdir -p $fs/boot 4.37 + cp $src/x86test.packed $fs/boot/$PACKAGE 4.38 +} 4.39 + 4.40 +# Post install/remove commands for Tazpkg. 4.41 +post_install() 4.42 +{ 4.43 + grep -qs ^x86test $1/boot/bootmenu || 4.44 + echo "x86test X86test,cpu,x86 Check X86 CPU (may run under DOS if renamed to x86test.exe)" >> $1/boot/bootmenu 4.45 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/x86test/stuff/bootloader.S Sat May 08 17:23:19 2021 +0000 5.3 @@ -0,0 +1,659 @@ 5.4 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2. 5.5 + 5.6 +SYSSEG = 0x1000 5.7 +setup_sects = 497 5.8 +syssize = 500 5.9 +cmd_line_ptr = 0x228 5.10 + 5.11 + .text 5.12 + .code16 5.13 + .org 0 5.14 + .globl _start 5.15 +_start: 5.16 + 5.17 +#define CODESZ 512 /* patched by installer */ 5.18 + 5.19 +// Default kernel format is 386 Image/zImage 5.20 +//#define BZIMAGE 0x207 /* setup version ; for bzImage < 512 Kb only */ 5.21 +//#define ELKS /* 8086/286 linux port */ 5.22 +#define ONLY8086 5.23 + 5.24 +/* some extra features */ 5.25 +#define EXE_SUPPORT real mode dos .exe file support +208/264 5.26 +#define CMDLINE dos kernel cmdline support +45 5.27 +//#define VCPI VCPI 4.0 support (386+) +109 5.28 +#define SHUTDOWNDOS shutdown DOS services +29 5.29 + 5.30 +/* some contraints to reduce the code size */ 5.31 +//#define FLOPPY_1440K_ONLY 1.44M floppies support only -26 5.32 +//#define FLOPPY_HAS_2_SIDES hardcoded heads count to 2 -15 5.33 +//#define NO_CMDLINE_SHRINK remove heading spaces ? -6-21 5.34 +//#define NO_CMDLINE_FILE remove @cmdline file support ? -21 5.35 +//#define NO_DOTS show progression dots ? -5 5.36 +#ifndef BZIMAGE 5.37 +//#define TINY_ZIMAGE system < 64Kb ? -11 5.38 +#define NO_MINSETUP default setup (dos only) ? -4 5.39 +//#define NO_CURSOR_DEFINITION -8 5.40 +#endif 5.41 + 5.42 +#ifdef ELKS 5.43 +INITSEG = 0x0100 5.44 +SETUPSEG = 0x0120 5.45 +#define ONLY8086 5.46 +#undef BZIMAGE 5.47 +#undef VCPI 5.48 +#else 5.49 +INITSEG = 0x9000 5.50 +SETUPSEG = 0x9020 5.51 +#endif 5.52 + 5.53 +#ifdef ONLY8086 5.54 + .arch i8086 5.55 +#endif 5.56 + 5.57 +.macro shlclw cnt,obj 5.58 +#ifdef ONLY8086 5.59 + movb \cnt,%cl 5.60 + shlw %cl,\obj 5.61 +#else 5.62 + shlw \cnt,\obj 5.63 +#endif 5.64 +.endm 5.65 + 5.66 +.macro shrclw cnt,obj 5.67 +#ifdef ONLY8086 5.68 + movb \cnt,%cl 5.69 + shrw %cl,\obj 5.70 +#else 5.71 + shrw \cnt,\obj 5.72 +#endif 5.73 +.endm 5.74 + 5.75 +#ifdef EXE_SUPPORT 5.76 +#define EXEADRS(x) (x+0xE0) 5.77 +#define FLAT20(x) (x+16*INITSEG) 5.78 + 5.79 +.macro trace_int19 5.80 +#ifdef ONLY8086 5.81 + xorw %si, %si 5.82 + movw %si, %ds 5.83 + pushw 4+2(%si) 5.84 + pushw 4(%si) 5.85 + movw $step19, 4(%si) 5.86 + movw $INITSEG, 4+2(%si) 5.87 +#else 5.88 + pushl $4 5.89 + popw %si 5.90 + popw %ds 5.91 + pushl (%si) 5.92 + movl $step19+(INITSEG<<16), (%si) 5.93 +#endif 5.94 + pushfw 5.95 + popw %ax 5.96 + incb %ah # set TF 5.97 + pushw %ax 5.98 + popfw 5.99 + ljmp *4*0x19-4(%si) 5.100 +.endm 5.101 + 5.102 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 5.103 + decw %bp // Magic number: MZ 5.104 + popw %dx 5.105 + jmp start // Bytes on last page of file 5.106 + .word (CODESZ+511)/512 // Pages in file INSTALLER 5.107 + .word 0 // Relocations 5.108 + .word (end_header-_start)/16 // Size of header in paragraphs 5.109 + .word 4096 // Minimum extra paragraphs needed 5.110 + .word -1 // Maximum extra paragraphs needed 5.111 + .word (CODESZ+15)/16 // Initial (relative) SS value INSTALLER 5.112 + .word stacktop // Initial SP value 5.113 + .word 0 // Checksum INSTALLER? 5.114 + .word EXEADRS(comstart) // Initial IP value 5.115 + .word 0xFFF0 // Initial (relative) CS value 5.116 +// .word 0x001C // File address of relocation table 5.117 +// .word 0,0,0 // Overlay number 5.118 +#else 5.119 +#undef VCPI 5.120 +#endif 5.121 +start: 5.122 + xorw %ax, %ax # %ax = 0 5.123 +zeroed = 12 # zeroed registers 5.124 + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits 5.125 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 (+zeroed+12) 5.126 +#ifdef ONLY8086 5.127 + movw $INITSEG, %bx 5.128 +#else 5.129 + pushw $INITSEG 5.130 +#endif 5.131 +end_header: 5.132 + cld # assume nothing 5.133 +#if defined(BZIMAGE) && BZIMAGE >= 0x202 5.134 + popw %es # %es contain INITSEG 5.135 + movw %es, %di 5.136 +#else 5.137 + # cmdline offset at 0x22 5.138 + movw $stacktop, %di # stacktop is an arbitrary value >= 5.139 + # length of bootsect + length of 5.140 + # setup + room for stack; 5.141 + # 12 is disk parm size. 5.142 +# ifdef ONLY8086 5.143 + pushw %bx 5.144 +# endif 5.145 + popw %es # %es contain INITSEG 5.146 +#endif 5.147 + pushw %es 5.148 + popw %ss # %es = %ss = INITSEG 5.149 + movw %di, %sp # put stack at INITSEG:stacktop-... 5.150 +#ifdef EXE_SUPPORT 5.151 + cwd # force %dx = 0 (floppy only) 5.152 +#endif 5.153 + 5.154 +# Many BIOS's default disk parameter tables will not recognize 5.155 +# multi-sector reads beyond the maximum sector number specified 5.156 +# in the default diskette parameter tables - this may mean 7 5.157 +# sectors in some cases. 5.158 +# 5.159 +# Since single sector reads are slow and out of the question, 5.160 +# we must take care of this by creating new parameter tables 5.161 +# (for the first disk) in RAM. We can set the maximum sector 5.162 +# count to 36 - the most we will encounter on an ED 2.88. 5.163 +# 5.164 +# High doesn't hurt. Low does. Let's use the max: 63 5.165 + 5.166 + rep # don't worry about cld 5.167 + stosw # already done above 5.168 + popw %bx # offset = 0 5.169 + popw %ds # %ds = 0 5.170 + 5.171 + movb setup_sects+0x7C00, %al # read bootsector + setup (%ds = 0) 5.172 + incw %ax 5.173 + 5.174 + ldsw 0x78(%bx), %si # %ds:%bx+0x78 is parameter table address 5.175 + pushw %es 5.176 + pushw %di 5.177 + movb $6, %cl # copy 12 bytes 5.178 + rep # don't worry about cld 5.179 + movsw # already done above 5.180 + movw %cx, %ds # %ds = 0 5.181 +#ifdef ONLY8086 5.182 + popw 0x78(%bx) # update parameter table address 5.183 + popw 0x78+2(%bx) 5.184 +#else 5.185 + popl 0x78(%bx) # update parameter table address 5.186 +#endif 5.187 + pushw %ss 5.188 + popw %ds # now %ds = %es = %ss = INITSEG 5.189 + movb $63, 0x4-12(%di) # patch sector count, %di = stacktop 5.190 + 5.191 + xchg %ax, %di # sector count 5.192 + popw %ax # limits = 0 5.193 + incw %cx # cylinder 0, sector 1, clear Z 5.194 + call read_first_sectors # read setup 5.195 + 5.196 +# This routine loads the system at address LOADSEG, making sure 5.197 +# no 64kB boundaries are crossed. We try to load it as fast as 5.198 +# possible, loading whole tracks whenever we can. 5.199 + 5.200 + movw syssize, %di 5.201 + decw %di 5.202 + shrclw $9-4, %di 5.203 + incw %di 5.204 + movw $SYSSEG, %cx 5.205 +#ifdef BZIMAGE 5.206 + push %cx 5.207 +#endif 5.208 + call read_sectorsCX 5.209 + 5.210 +# This procedure turns off the floppy drive motor, so 5.211 +# that we enter the kernel in a known state, and 5.212 +# don't have to worry about it later. 5.213 + 5.214 +kill_motor: 5.215 + xchgw %ax, %di # reset FDC (%di < 128) 5.216 + int $0x13 5.217 + 5.218 +# After that (everything loaded), we jump to the setup-routine 5.219 +# loaded directly after the bootblock: 5.220 +# Segments are as follows: %ds = %ss = INITSEG 5.221 + 5.222 +#ifdef BZIMAGE 5.223 + popw %bx 5.224 + popw %si // SYSSEG:0 5.225 +movesys: // %bx = DS, %si 5.226 + movw $16, %ax 5.227 + mulw %bx 5.228 + addw %si, %ax 5.229 + adcw $0x9300, %dx // %dx:%ax src flat address 5.230 + movw $9, %cx 5.231 +zero1: 5.232 + pushw $0 // 2E..1E 5.233 + loop zero1 5.234 + //pushl $0x93100000 // 1A: dest 5.235 + pushw $0x9310 5.236 + pushw %cx 5.237 + pushw $-1 // 18 5.238 + pushw %cx // 16 5.239 + pushw %dx // src 5.240 + pushw %ax 5.241 + pushw $-1 // 10 5.242 + movb $8, %cl 5.243 + movw %cx, %bx // will move 8*64 = 512Kb 5.244 +zero2: 5.245 + pushw $0 // 0E..00 5.246 + loop zero2 5.247 + movw %sp, %si 5.248 + pushw %ss 5.249 + popw %es 5.250 + pushw %es 5.251 + popw %ds 5.252 +syslp: 5.253 + movb $0x80, %ch 5.254 + movb $0x87, %ah 5.255 + int $0x15 5.256 + incb 0x14(%si) 5.257 + incb 0x1C(%si) 5.258 + decw %bx 5.259 + jne syslp 5.260 +#endif 5.261 +jmp_setup: 5.262 + cli 5.263 + ljmp $SETUPSEG, $0 5.264 + 5.265 +#ifdef EXE_SUPPORT 5.266 +#ifdef SHUTDOWNDOS 5.267 +doiret: 5.268 + iret 5.269 +step19: 5.270 + pushw %si 5.271 + pushw %ds 5.272 + movw %sp, %si 5.273 + ldsw %ss:4(%si), %si 5.274 + cmpw $0x19CD, (%si) 5.275 + popw %ds 5.276 + popw %si 5.277 + jne doiret 5.278 + xorw %si, %si 5.279 + movw %si, %ds 5.280 + pushw %cs 5.281 + popw %ss 5.282 + movw $stacktop-4-16, %sp 5.283 +#ifdef ONLY8086 5.284 + popw 4(%si) 5.285 + popw 4+2(%si) 5.286 + popw %bp 5.287 + popw %di 5.288 + popw %si 5.289 + popw %dx 5.290 + popw %cx 5.291 + popw %bx 5.292 + popw %ax 5.293 +#else 5.294 + popl 4(%si) 5.295 + popaw 5.296 +#endif 5.297 +#ifdef BZIMAGE 5.298 + jmp movesys 5.299 +#endif 5.300 +#endif 5.301 +#ifndef BZIMAGE 5.302 +movesys: // %ax = SYSSEG, %bx = DS, %si 5.303 + shrclw $4, %si 5.304 + addw %si, %bx 5.305 +#ifdef TINY_ZIMAGE 5.306 + movw $0xFFFF, %cx 5.307 + xorw %si, %si 5.308 + xorw %di, %di 5.309 + cmpw %ax, %bx 5.310 + jnc forward 5.311 + decw %si 5.312 + decw %di 5.313 + std 5.314 +forward: 5.315 + movw %ax, %es 5.316 + movw %bx, %ds 5.317 + rep 5.318 + movsb 5.319 + cld 5.320 +#else 5.321 + subw %ax, %bx 5.322 + jnc forward 5.323 + //movw $0x8FFF, %ax 5.324 + movb $0x90, %ah 5.325 +forward: 5.326 + movw %ax, %es 5.327 + movw %ax, %di 5.328 + addw %bx, %di 5.329 + movw %di, %ds 5.330 + sbbw %di, %di // %di = 0 : -1 5.331 + cmc // C = 1 : 0 5.332 + adcw %di, %ax 5.333 + xorw %si, %si 5.334 + xorw %di, %di 5.335 + movb $0x10, %cl 5.336 + cmpb %cl, %ah // move 512k 5.337 + rep 5.338 + movsb 5.339 + jns forward 5.340 +#endif 5.341 +#ifndef NO_CURSOR_DEFINITION 5.342 + movb $1, %ah 5.343 + movb $0, %bh 5.344 + movb $0x20, %ch // 0x2000 5.345 + int $0x10 5.346 +#endif 5.347 + pushw %ss 5.348 + popw %ds 5.349 + jmp jmp_setup 5.350 +#endif 5.351 +comstart: 5.352 + cld # assume nothing 5.353 +#ifdef ONLY8086 5.354 + movw $INITSEG, %ax 5.355 + pushw %ax 5.356 +#else 5.357 + pushw $INITSEG 5.358 +#endif 5.359 + popw %es 5.360 +#ifdef CMDLINE 5.361 + movw %sp, %di 5.362 + movw $0x80, %si 5.363 + lodsb 5.364 + cbw 5.365 + xchgw %ax, %cx 5.366 + jcxz nocmdline 5.367 +# if defined(BZIMAGE) && BZIMAGE >= 0x202 5.368 + movw $INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1) 5.369 +# else 5.370 + movw $0xA33F, 0x7F(%si) 5.371 +# endif 5.372 +# ifndef NO_CMDLINE_SHRINK 5.373 +skipspace: 5.374 + lodsb 5.375 + cmpb $0x20, %al 5.376 + je skipspace 5.377 +# ifndef NO_CMDLINE_FILE 5.378 + movw %si,%dx 5.379 + decw %si 5.380 + subb $'@',%al 5.381 + jne notafile 5.382 + movb $0x3D,%ah 5.383 + int $0x21 5.384 + jc notafile 5.385 + xchgw %ax,%bx 5.386 + //movw %si,%dx // ~320 bytes max 5.387 + movw $EXEADRS(notafile)-130,%cx 5.388 + movb $0x3F,%ah 5.389 + int $0x21 5.390 + xchgw %ax,%cx 5.391 +notafile: 5.392 +# else 5.393 + decw %si 5.394 +# endif 5.395 +# endif 5.396 + rep 5.397 + movsb 5.398 +nocmdline: 5.399 + orb EXEADRS(setup_sects), %ch 5.400 +# ifndef NO_MINSETUP 5.401 +# ifndef BZIMAGE 5.402 + jnz setupok 5.403 + mov $4, %ch 5.404 +setupok: 5.405 +# endif 5.406 +# endif 5.407 +#else 5.408 + movb EXEADRS(setup_sects), %ch 5.409 +#endif 5.410 + movb $(512-(end_header-_start))/2, %cl 5.411 + movw $0x100, %si 5.412 + movw $end_header, %di 5.413 + rep 5.414 + movsw 5.415 + movw $SYSSEG, %ax 5.416 + movw %ds, %bx 5.417 + pushw %es 5.418 + popw %ss 5.419 +#ifndef SHUTDOWNDOS 5.420 + pushw %es 5.421 + pushw $movesys 5.422 +#endif 5.423 +#ifdef VCPI 5.424 + pushaw 5.425 + smsww %ax 5.426 + andb $1, %al 5.427 + je isrm 5.428 + movw $EXEADRS(gdt_vcpi),%si 5.429 + movw $pagebuf-0x90000,%di // %es = 0x9000 5.430 + movl $pagebuf+3,%es:0x1000(%di) 5.431 +call_vcpi: 5.432 + movb $0xDE,%ah // DE01, EBX = getiface(DS:SI, ES:DI) 5.433 + int $0x67 5.434 + movl $FLAT20(sw2pm_params),%esi 5.435 + movb $0x0C,%al // DE0C switchpm(ESI) 5.436 + jmp call_vcpi 5.437 +pm_code: 5.438 + movl %cr0,%eax 5.439 + andl $0x7FFFFFFE,%eax 5.440 + movl %eax,%cr0 5.441 + movl %eax,%cr3 5.442 +isrm: 5.443 +# ifdef SHUTDOWNDOS 5.444 + trace_int19 5.445 +# else 5.446 + lssw %cs:EXEADRS(saved_ss_sp),%sp 5.447 + popaw 5.448 + retf 5.449 +# endif 5.450 +#else 5.451 +# ifdef SHUTDOWNDOS 5.452 +# ifdef ONLY8086 5.453 + pushw %ax 5.454 + pushw %bx 5.455 + pushw %cx 5.456 + pushw %dx 5.457 + pushw %si 5.458 + pushw %di 5.459 + pushw %bp 5.460 +# else 5.461 + pushaw 5.462 +# endif 5.463 + trace_int19 5.464 +# endif 5.465 + retf 5.466 +#endif 5.467 +#endif 5.468 + 5.469 +# read_sectors reads %di sectors into %es:0 buffer. 5.470 +# %es:0 is updated to the next memory location. 5.471 +# First, sectors are read sector by sector until 5.472 +# sector per track count is known. Then they are 5.473 +# read track by track. 5.474 +# Assume no error on first track. 5.475 + 5.476 +#ifdef FLOPPY_1440K_ONLY 5.477 +#ifndef FLOPPY_HAS_2_SIDES 5.478 +#define FLOPPY_HAS_2_SIDES hardcore heads count to 2 5.479 +#endif 5.480 +#define FLOPPY_SECTORS 18 /* 18 sectors */ 5.481 +#else 5.482 +#define FLOPPY_HEADS 2 /* 2 heads minimum */ 5.483 +#endif 5.484 + 5.485 +return: 5.486 +#ifndef NO_DOTS 5.487 + movw $0xE2E,%ax 5.488 + int $0x10 5.489 +#endif 5.490 + ret 5.491 + 5.492 +check_limits: 5.493 +#ifndef FLOPPY_1440K_ONLY 5.494 + popw %dx 5.495 + cmpb %al, %cl # max sector known ? 5.496 + ja next_head # no -> store it 5.497 +#ifndef FLOPPY_HAS_2_SIDES 5.498 +#ifdef FLOPPY_HEADS 5.499 + cmpb $FLOPPY_HEADS, %dh # 2 heads minimum 5.500 + jb check_cylinder 5.501 +#endif 5.502 + cmpb %ah, %dh # max head known ? 5.503 + ja next_cylinder # no -> store it 5.504 +check_cylinder: 5.505 +#endif 5.506 + pushw %ax 5.507 + cbw # %ah = 0 5.508 +#else 5.509 + pushw %dx 5.510 +#endif 5.511 + int $0x13 # reset controler 5.512 +#ifndef FLOPPY_1440K_ONLY 5.513 + popw %ax 5.514 + movb $1, %al # sector by sector... 5.515 +#else 5.516 + movw $1, %ax 5.517 + jmp more1trk 5.518 +#endif 5.519 +read_sectorslp: 5.520 + pushw %dx # some bios break dx... 5.521 +#ifndef FLOPPY_1440K_ONLY 5.522 + pushw %ax # limits 5.523 + subb %cl, %al # sectors remaining in track 5.524 + ja tolastsect 5.525 + movb $1, %al # first track sector by sector 5.526 +tolastsect: 5.527 +#else 5.528 + movb $FLOPPY_SECTORS+1, %al 5.529 + subb %cl, %al # sectors remaining in track 5.530 +#endif 5.531 + cbw 5.532 + cmpw %di, %ax 5.533 + jb more1trk 5.534 + movw %di, %ax # sectors to read 5.535 +more1trk: 5.536 + pushw %ax # save context 5.537 + movb $2, %ah # cmd: read chs 5.538 + int $0x13 5.539 +#ifndef FLOPPY_1440K_ONLY 5.540 + popw %dx # save %ax 5.541 + popw %ax # limits 5.542 +#else 5.543 + popw %ax # restore context 5.544 + popw %dx 5.545 +#endif 5.546 + jc check_limits 5.547 +#ifndef FLOPPY_1440K_ONLY 5.548 + xchgw %ax, %bp 5.549 + addw %dx,%cx # next sector 5.550 + movw %cx, %si 5.551 + pushw %dx 5.552 + shlclw $5, %dx 5.553 + movw %es, %cx 5.554 + addw %dx, %cx 5.555 + popw %dx 5.556 + subw %dx,%di # update sector counter 5.557 + popw %dx 5.558 +#else 5.559 + addw %ax,%cx # next sector 5.560 + movw %cx, %si 5.561 + pushw %ax 5.562 + shlclw $5, %ax 5.563 + movw %es, %cx 5.564 + addw %ax, %cx 5.565 + popw %ax 5.566 + subw %ax,%di # update sector counter 5.567 +#endif 5.568 +read_sectorsCX: 5.569 + movw %cx, %es # next location 5.570 + jz return 5.571 +read_sectors: 5.572 + movw %si, %cx 5.573 +#ifndef FLOPPY_1440K_ONLY 5.574 +# al is last sector+1 5.575 +# ah is last head+1 5.576 + xchgw %ax, %bp 5.577 +#endif 5.578 +#ifndef FLOPPY_1440K_ONLY 5.579 + cmpb %al,%cl # reach sector limit ? 5.580 + jne bdendlp 5.581 +next_head: 5.582 + movb %cl,%al 5.583 +#else 5.584 + cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ? 5.585 + jne bdendlp 5.586 +#endif 5.587 + movb $1,%cl # first sector 5.588 +#ifndef FLOPPY_HAS_2_SIDES 5.589 + incb %dh # next head 5.590 + cmpb %ah, %dh # reach head limit ? 5.591 + jne bdendlp 5.592 +next_cylinder: 5.593 + movb %dh,%ah 5.594 + movb $0,%dh # first head 5.595 +#else 5.596 + xorb %cl,%dh # next head 5.597 + jne bdendlp # reach head limit ? 5.598 +#endif 5.599 +# NOTE : support 256 cylinders max 5.600 + incb %ch # next cylinder 5.601 +read_first_sectors: 5.602 +bdendlp: 5.603 + jmp read_sectorslp 5.604 + 5.605 +#ifdef VCPI 5.606 +pagebuf = 0x98000 5.607 +tss = gdt_abs-40 5.608 +gdt = gdt_abs-32 5.609 +gdt_null = gdt_abs-32 5.610 +gdt_vcpi = gdt_abs-24 5.611 +gdt_vcpi2 = gdt_abs-16 5.612 +gdt_vcpi3 = gdt_abs-8 5.613 +gdt_abs: 5.614 + .word 0xFFFF 5.615 + .long 0x92000000 5.616 + .byte 0xCF,0 5.617 +gdt_code: 5.618 + .word 0xFFFF 5.619 +gdt_code_base: 5.620 + .long 0x9A000000+FLAT20(0) 5.621 + .byte 0x8F,0 5.622 +gdt_tss: 5.623 + .word 0x00FF 5.624 +gdt_tss_base: 5.625 + .long 0x89000000+FLAT20(tss) 5.626 + .byte 0,0 5.627 +gdtr: 5.628 +gdt_lim: 5.629 + .word 0xFFFF 5.630 +gdt_base: 5.631 + .long FLAT20(gdt) 5.632 +sw2pm_params: 5.633 +sw2pm_cr3: 5.634 + .long pagebuf+0x1000 5.635 +sw2pm_gdtr_ptr: 5.636 + .long FLAT20(gdtr) 5.637 +sw2pm_idtr_ptr: 5.638 + .long FLAT20(idtr) 5.639 +sw2pm_ldtr: 5.640 + .word 0 5.641 +sw2pm_tr: 5.642 +SEL_TSS = gdt_tss-gdt_null 5.643 + .word SEL_TSS 5.644 +sw2pm_jumpaddr: 5.645 + .long pm_code 5.646 +SEL_CODE = gdt_code-gdt_null 5.647 + .word SEL_CODE 5.648 +idtr: 5.649 +idt_lim: 5.650 + .word 0x03FF 5.651 +idt_base: 5.652 + .long 0 5.653 +# ifndef SHUTDOWNDOS 5.654 +saved_ss_sp: 5.655 + .word stacktop-4-16-4,INITSEG 5.656 +# endif 5.657 +#endif 5.658 +#ifdef ELKS 5.659 + .org 0x1E3 5.660 + .byte 13,10,7 5.661 + .asciz "ELKS Boot" 5.662 +#endif
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/x86test/stuff/pack Sat May 08 17:23:19 2021 +0000 6.3 @@ -0,0 +1,76 @@ 6.4 +#!/bin/sh 6.5 +if [ "$1" == "--build" ]; then 6.6 + set -- ${2:-bootloader.bin} ${3:-unpack.bin} 6.7 + x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.8 + [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0 6.9 + x=$(grep -s setup_byte$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.10 + [ -n "$x" ] && sed -i "s/XXXSB/$((513+0x$x))/" $0 || sed -i "/XXXSB/d" $0 6.11 + x=$(grep -s setup_word$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.12 + [ -n "$x" ] && sed -i "s/XXXSW/$((514+0x$x))/" $0 || sed -i "/XXXSW/d" $0 6.13 + x=$(grep -s setup_para$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.14 + [ -n "$x" ] && sed -i "s/XXXSP/$((514+0x$x))/" $0 || sed -i "/XXXSP/d" $0 6.15 + x=$(grep -s setup_seg$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.16 + [ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0 6.17 + grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0 6.18 + grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0 6.19 + helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.20 + helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 6.21 + if [ -n "$helpmsg" ]; then 6.22 + sed -i "s/YYY/$((0x$helpmsg))/" $0 6.23 + sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0 6.24 + else 6.25 + sed -i '/YYY/d' $0 6.26 + fi 6.27 + cat >> $0 <<EOM 6.28 +$(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -) 6.29 +EOT 6.30 +EOM 6.31 + sed -i '/--build/,/^fi/d' $0 6.32 + exit 6.33 +fi 6.34 + 6.35 +store() 6.36 +{ 6.37 + n=$1 6.38 + for i in $(seq 1 ${4:-2}); do 6.39 + printf '\\\\x%02X' $(($n & 255)) 6.40 + n=$(($n >> 8)) 6.41 + done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 6.42 +} 6.43 + 6.44 +bits() 6.45 +{ 6.46 + sed "/^.define PROP_$1/"'!'"d;s|.*_$1.||" unlzma.S 6.47 +} 6.48 + 6.49 +compress() 6.50 +{ 6.51 + xz -z -e --format=raw --lzma1=mf=bt2,lc=$(bits LC),lp=$(bits LP),pb=$(bits PB),nice=36 --stdout 6.52 +} 6.53 + 6.54 +main() 6.55 +{ 6.56 + uudecode | gunzip >$2 6.57 + dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc 6.58 + setup="$(echo $(od -j 497 -N 1 -dAn $1))" 6.59 + [ $setup -eq 0 ] && setup=4 6.60 + store $setup $2 XXXSB 1 6.61 + store $setup $2 XXXSW 1 6.62 + store $((32 * $setup)) $2 XXXSP 6.63 + store $((0x1000 - 32*$setup)) $2 XXXSS 6.64 + dd if=$1 bs=512 skip=1 | compress >>$2 6.65 + size=$(stat -c %s $2) 6.66 + syssize=$((($size-512*($setup+1)+15)/16)) 6.67 + store $(($syssize + 0x1000)) $2 XXXP 6.68 + store $syssize $2 500 6.69 + store 4 $2 497 1 6.70 + store $((($size+511)/512)) $2 4 6.71 + store $((($size+15)/16)) $2 14 6.72 + echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ 6.73 +} 6.74 + 6.75 +HELP="$(unix2dos <<EOT 6.76 +x86test VERSION GPLv2 6.77 +EOT 6.78 +)" 6.79 +main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/x86test/stuff/unlzma.S Sat May 08 17:23:19 2021 +0000 7.3 @@ -0,0 +1,1023 @@ 7.4 +// #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 7.5 +// 7.6 +// #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) 7.7 +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; 7.8 +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; 7.9 +// 7.10 +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ 7.11 +// { UpdateBit0(p); mi <<= 1; A0; } else \ 7.12 +// { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 7.13 +// 7.14 +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) 7.15 +// 7.16 +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \ 7.17 +// { int i = numLevels; res = 1; \ 7.18 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ 7.19 +// res -= (1 << numLevels); } 7.20 +/* 7.21 + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3 7.22 + */ 7.23 + 7.24 +#define PROP_PB 0 7.25 +#define PROP_LP 0 7.26 +#define PROP_LC 3 7.27 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45)) 7.28 + 7.29 +// static const Byte *Buffer; 7.30 +// static UInt32 bound, Code, Range; 7.31 + 7.32 +/* 7.33 + * Buffer register DS:SI 7.34 + * all var based ws=ss:bp 7.35 + */ 7.36 + 7.37 +rep0 = -4 // long 7.38 +rep1 = rep0-4 // long 7.39 +rep2 = rep0-8 // long 7.40 +rep3 = rep0-12 // long 7.41 +state = -17 // byte, 0..11 7.42 +posState = state-1 // byte, 0..15 7.43 +posState2 = posState-1 // byte, 0..15 7.44 +scratched = rep0-16 // byte = 1 7.45 +Code = -24 // long 7.46 +outStream = -28 // long 7.47 +nowPos = outStream // long 7.48 +Range = Code-8 // long 7.49 +#define LOCALS 32 7.50 + 7.51 +// int LzmaDecode(CLzmaDecoderState *vs, 7.52 +// const unsigned char *inStream, 7.53 +// unsigned char *outStream) 7.54 +// { 7.55 +// CProb *p = vs->Probs; 7.56 +// SizeT nowPos = 0; 7.57 +// #define posStateMask = (1 << (vs->Properties.pb)) - 1; 7.58 +// #define literalPosMask = (1 << (vs->Properties.lp)) - 1; 7.59 +// int lc = vs->Properties.lc, state = 0, len = 0; 7.60 +// UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 7.61 +// 7.62 +// { 7.63 +// UInt32 i, numProbs = Literal /*1846*/ 7.64 +// + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp)); 7.65 +// for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1; 7.66 + 7.67 +#define WS (1846+(768<<(PROP_LC+PROP_LP))) 7.68 +#if (WS+WS+LOCALS) >= 65000 7.69 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */ 7.70 +#error invalid (lc,lp,pb) : out of memory 7.71 +#endif 7.72 + 7.73 +ws1 = WS 7.74 +ws2 = ws1*2 7.75 +ws = ws2+LOCALS+15 7.76 + 7.77 +#ifndef FLAT32 7.78 +#define AX %ax 7.79 +#define BX %bx 7.80 +#define CX %cx 7.81 +#define DX %dx 7.82 +#define SI %si 7.83 +#define DI %di 7.84 +#define BP %bp 7.85 +#define SP %sp 7.86 +#define CWD cwd 7.87 +#else 7.88 +#define AX %eax 7.89 +#define BX %ebx 7.90 +#define CX %ecx 7.91 +#define DX %edx 7.92 +#define SI %esi 7.93 +#define DI %edi 7.94 +#define BP %ebp 7.95 +#define SP %esp 7.96 +#define CWD cdq 7.97 +#endif 7.98 +/* 7.99 + * LzmaDecode: 7.100 +#ifndef FLAT32 7.101 + * input ds:si=inStream, es:di=outStream 7.102 + * output outStream[], ds:si, es:di 7.103 + .code 16 7.104 +#else 7.105 + * input esi=inStream, edi=outStream 7.106 + * output outStream[], esi, edi 7.107 + .code 32 7.108 +#endif 7.109 + */ 7.110 + 7.111 + mov $ws1, CX 7.112 +#ifdef ONLY8086 7.113 + movw $2048/2, %ax 7.114 +lzd1: 7.115 + pushw %ax 7.116 +#else 7.117 +lzd1: 7.118 + pushw $2048/2 7.119 +#endif 7.120 + loop lzd1 7.121 + mov SP, BP 7.122 + movb $((LOCALS+3)/4)*2, %cl 7.123 +#ifdef ONLY8086 7.124 + movw $1, %ax 7.125 + cwd 7.126 +initlocals: 7.127 + pushw %dx 7.128 + pushw %ax 7.129 +#else 7.130 +initlocals: 7.131 + pushl $1 7.132 +#endif 7.133 + loop initlocals 7.134 + 7.135 +#if !defined(FLAT32) && !defined(FLAT16OUT) 7.136 + movb $4, %cl 7.137 + movw %es, %bx 7.138 + shrw %cl, %bx 7.139 + movw %es, %dx 7.140 + shlw %cl, %dx 7.141 + addw %dx, %di 7.142 + movw %di, outStream(%bp) 7.143 + adcb %bh, outStream+2(%bp) 7.144 + incw %cx 7.145 +#else 7.146 + movb $5, %cl 7.147 + mov DI, outStream(BP) 7.148 +#endif 7.149 + 7.150 +// Byte previousByte = 0; 7.151 + xor BX, BX 7.152 + 7.153 +// #define RC_INIT(buffer) 7.154 +// Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; 7.155 +// { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }} 7.156 +// } 7.157 +// RC_INIT(inStream); 7.158 + 7.159 +#ifndef NO_LZMA_HEADER 7.160 +#ifdef CHECK_LZMA_HEADER 7.161 + cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1) 7.162 + je lzip_header 7.163 + cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8) 7.164 + jne no_header 7.165 + add $13-6, SI // skip lzma header 7.166 +lzip_header: 7.167 + add $6, SI // skip lzip header 7.168 +no_header: 7.169 +#else 7.170 + add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8) 7.171 +#endif 7.172 +#endif 7.173 +setrep: 7.174 + call RC_LOAD_BYTE 7.175 + decb Range(BP) 7.176 + loop setrep 7.177 + 7.178 +lzdmainlp: 7.179 +// while(1) { 7.180 +// CProb *prob; 7.181 +// int posState = (int)((nowPos) & posStateMask); 7.182 +// 7.183 +// prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState; 7.184 +// if (Bit0(prob)) { /* char */ 7.185 + 7.186 + xor DX, DX 7.187 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 7.188 + mov $state, DI 7.189 + jc lzdstring 7.190 + 7.191 +// prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * 7.192 +// ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc)))); 7.193 + 7.194 +#if PROP_LC != 0 7.195 +# ifdef ONLY8086 7.196 + movb $8-PROP_LC, %cl 7.197 + shrb %cl, %bl 7.198 +# else 7.199 + shrb $8-PROP_LC, %bl 7.200 +# endif 7.201 +#else 7.202 + xor %bx,%bx 7.203 +#endif 7.204 + 7.205 +#if PROP_LP != 0 7.206 + movb posState2(BP), %dl 7.207 +# if PROP_LC != 0 7.208 +# ifdef ONLY8086 7.209 + movb $PROP_LC, %cl 7.210 + shl %cl, DX 7.211 +# else 7.212 + shl $PROP_LC, DX 7.213 +# endif 7.214 + movb $0, %bh 7.215 +# endif 7.216 + add BX, DX 7.217 +#endif 7.218 + 7.219 + movb $3, %ah 7.220 + mul BX // dx = 3*bh 7.221 + add $1846, AX 7.222 + 7.223 +// int symbol = 1; 7.224 + 7.225 + CWD 7.226 + inc DX // symbol = 1 7.227 + xchg AX, CX // save prob 7.228 + 7.229 +// if (state >= kNumLitStates /*7*/) { /* previous was string */ 7.230 +// if (state < 4) state = 0; 7.231 + 7.232 +lzd6z: 7.233 + subb $3, (BP, DI) 7.234 + 7.235 +// if (state < 4) state = 0; 7.236 + 7.237 + jnc lzd6 7.238 + movb %dh, (BP, DI) // %dh = 0 7.239 + 7.240 +lzd6: 7.241 +// else if (state < 10) state -= 3; 7.242 + 7.243 + cmpb $10-3, (BP, DI) 7.244 + 7.245 +// else state -= 6; 7.246 + 7.247 + jnb lzd6z 7.248 + cmpb $7-3-1, (BP, DI) 7.249 + jbe lzd3 7.250 + 7.251 +// int matchByte = outStream[nowPos - rep0]; 7.252 + 7.253 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0]; 7.254 + 7.255 +// do { 7.256 +// int bit; 7.257 +// CProb *probLit; 7.258 +// matchByte <<= 1; bit = (matchByte & 0x100); 7.259 + 7.260 + movb $1, %bh 7.261 +lzd4: 7.262 + shlb $1, %bl // matchByte <<= 1 7.263 + sbb DI, DI // save bit=C 7.264 + 7.265 +// probLit = prob + 0x100 + bit + symbol; 7.266 + 7.267 + mov CX, AX // restore prob 7.268 + adcb %bh, %ah // + bit + 0x100 7.269 + 7.270 +// RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break) 7.271 + 7.272 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 7.273 + rclb $1, %dl // symbol <<= 1; symbol |= C 7.274 + jc lzd5 // if symbol >= 0x100 7.275 + cmp DI, AX 7.276 + jz lzd4 // if bit == Bit1(prob+%ax) 7.277 + 7.278 +// } while (symbol < 0x100); 7.279 +// } 7.280 +lzd3: 7.281 +// while (symbol < 0x100) { 7.282 +// CProb *probLit = prob + symbol; 7.283 +// RC_GET_BIT(probLit, symbol) 7.284 +// } 7.285 + 7.286 + xor BX, BX 7.287 + jmp lzd4 7.288 +lzd5: 7.289 + 7.290 +// outStream[nowPos++] = previousByte = (Byte)symbol; 7.291 + 7.292 + xchg AX, DX 7.293 + call outchar // %bl = outStream[nowPos++] = %al; 7.294 + jmp lzdmainlp 7.295 + 7.296 +// } 7.297 + 7.298 +lzdstring: 7.299 + mov $1, CX 7.300 + 7.301 +// else { /* string */ 7.302 +// prob = p + IsRep /*192*/ + state; 7.303 + 7.304 + movb $192, %dl 7.305 + addb (BP, DI), %dl 7.306 + mov $rep0, DI 7.307 + 7.308 +// if (Bit0(prob)) { 7.309 + 7.310 + call Bit1dx // Bit1(prob) 7.311 + jc lzd8 7.312 + 7.313 +// rep3 = rep2; rep2 = rep1; rep1 = rep0; 7.314 +// state = (state < kNumLitStates /*7*/) ? 0 : 3; 7.315 + 7.316 + stc 7.317 + 7.318 +// prob = p + LenCoder /*818*/; 7.319 + 7.320 + mov $818, DX 7.321 + 7.322 +// } 7.323 + 7.324 + jmp lzd11a 7.325 + 7.326 +// else { 7.327 +lzd8: 7.328 +// prob += kNumStates /*12*/; 7.329 +// if (Bit0(prob)) { 7.330 + call Bit1dx12 // prob += 12; Bit1(prob) 7.331 + jc lzd11 7.332 +// prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) 7.333 +// + posState; 7.334 + movb $240, %dl // dh=0 7.335 + 7.336 +// if (Bit0(prob)) { 7.337 + 7.338 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 7.339 + jc lzd12 7.340 + 7.341 +// // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR; 7.342 +// state = (state < kNumLitStates /*7*/) ? 9 : 11; 7.343 + 7.344 + movb $9, %dl 7.345 + 7.346 +// len++; goto string; 7.347 + jmp lzd13string // ax = 0 7.348 +// } 7.349 +// } 7.350 +// else { 7.351 +lzd11: 7.352 +// UInt32 distance = rep1; 7.353 +// prob += kNumStates /*12*/; 7.354 +// if (!Bit0(prob)) { 7.355 + 7.356 + call Bit1dx12 // prob += 12; Bit1(prob) 7.357 + jnc lzd11z 7.358 + 7.359 +// prob += kNumStates /*12*/; 7.360 +// if (Bit0(prob)) distance = rep2; 7.361 + 7.362 + call Bit1dx12 // prob += 12; Bit1(prob) 7.363 +lzd11a: 7.364 + adcb %cl, %cl 7.365 + 7.366 +// else { distance = rep3; rep3 = rep2; } 7.367 +// rep2 = rep1; 7.368 +// } 7.369 +// rep1 = rep0; rep0 = distance; 7.370 + 7.371 +lzd11z: 7.372 +# ifdef ONLY8086 7.373 + shl $1, CX 7.374 + shl $1, CX // 8->32 bits 7.375 + sub CX, DI // &rep[cx] 7.376 + movw (BP, DI), %ax 7.377 + pushw 2(BP, DI) 7.378 +rotreplp: 7.379 + movb 4(BP, DI), %bl 7.380 + movb %bl, (BP, DI) 7.381 + inc DI 7.382 + loop rotreplp 7.383 + popw %bx 7.384 + testb %dh, %dh 7.385 + jnz lzd10 7.386 + movw %ax, (BP, DI) 7.387 + movw %bx, 2(BP, DI) 7.388 +# else 7.389 + shl $2, CX // 8->32 bits 7.390 + sub CX, DI // &rep[cx] 7.391 + movl (BP, DI), %eax 7.392 +rotreplp: 7.393 + movb 4(BP, DI), %bl 7.394 + movb %bl, (BP, DI) 7.395 + inc DI 7.396 + loop rotreplp 7.397 + testb %dh, %dh 7.398 + jnz lzd10 7.399 + movl %eax, (BP, DI) 7.400 +# endif 7.401 + 7.402 +// } 7.403 +lzd12: 7.404 +// state = (state < kNumLitStates /*7*/) ? 8 : 11; 7.405 + 7.406 + movb $0x08, %cl 7.407 + 7.408 +// prob = p + RepLenCoder /*1332*/; 7.409 + 7.410 + mov $1332, DX 7.411 + 7.412 +// } 7.413 +lzd10: 7.414 + push CX // CX = 0 7.415 + 7.416 +// { /* get len */ 7.417 +// int numBits, offset; 7.418 +// CProb *probLen = prob + LenChoice /*0*/; 7.419 +// numBits = kLenNumLowBits /*3*/; 7.420 + 7.421 + movb $8, %cl // numBits : 3,3,8 7.422 + 7.423 +// if (Bit0(probLen)) { 7.424 + 7.425 + call Bit1dx // Bit1(prob) 7.426 + xchg AX, BX 7.427 + inc DX 7.428 + jnc lzd15 // bx=0 7.429 + 7.430 +// probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/); 7.431 +// offset = 0; 7.432 +// } 7.433 +// else { 7.434 +// probLen = prob + LenChoice2 /*1*/; 7.435 + 7.436 + call Bit1dx // Bit1(prob) 7.437 + add AX, BX 7.438 + 7.439 +#if PROP_PB != 0 7.440 + inc AX // ah=0 7.441 +#endif 7.442 + jc lzd16 // %ax=0, %bx=-2 7.443 +lzd15: 7.444 +#if PROP_PB != 0 7.445 + movb $8, %al 7.446 + mulb posState(BP) 7.447 +#endif 7.448 + 7.449 +// if (Bit0(probLen)) { 7.450 +// probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/); 7.451 + 7.452 + movb $3, %cl // numBits : 3,3,8 7.453 +lzd16: 7.454 +#if PROP_PB != 0 7.455 + add $2-128-1, AX // probLen : 2,130,258 7.456 +#else 7.457 + mov $2-128-1, AX // probLen : 2,130,258 7.458 +#endif 7.459 + add DX, AX 7.460 + mov $-8+1, DX // offset : 0,8,16 7.461 +lzdargslp: 7.462 + add $8, DX 7.463 + add $128, AX 7.464 + inc BX 7.465 + jle lzdargslp // leave with bx=1 7.466 + 7.467 +// offset = kLenNumLowSymbols /*8*/; 7.468 +// //numBits = kLenNumMidBits /*3*/; 7.469 +// } 7.470 +// else { 7.471 +// probLen = prob + LenHigh /*258*/; 7.472 +// offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/; 7.473 +// numBits = kLenNumHighBits /*8*/; 7.474 +// } 7.475 +// } 7.476 +// RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset; 7.477 + 7.478 + push DX 7.479 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 7.480 + pop DX 7.481 + add DX, AX // offset 7.482 + pop DX // 0 7.483 +lzd13string: 7.484 + push AX 7.485 + 7.486 +// state = (state < kNumLitStates /*7*/) ? dl : dl|3; 7.487 + 7.488 + movb $7, %cl 7.489 + cmpb %cl, state(BP) 7.490 + jb new_state 7.491 + orb $3, %dl 7.492 +new_state: 7.493 + movb %dl, state(BP) 7.494 + 7.495 +// } /* get len */ 7.496 +// if (state < 4) { 7.497 + 7.498 + cmpb $4-1, %dl 7.499 + ja lzd19 7.500 + 7.501 +// int posSlot; 7.502 +// state += kNumLitStates /*7*/; 7.503 + 7.504 + addb %cl, state(BP) 7.505 + 7.506 +// prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? 7.507 +// len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/); 7.508 + 7.509 + cmp $4+1, AX 7.510 + jb lzd21 7.511 + mov $3+1, AX 7.512 + 7.513 +lzd21: 7.514 + 7.515 + dec CX // cx = 6 7.516 + shl %cl, AX 7.517 + add $432-64, AX 7.518 + 7.519 +// RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot); 7.520 + 7.521 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 7.522 + 7.523 +// if (posSlot >= kStartPosModelIndex /*4*/) { 7.524 +// int numDirectBits = ((posSlot >> 1) - 1); 7.525 + 7.526 +#ifndef FLAT32 7.527 + movw %cx, 2(%bp, %di) // %cx = 0 7.528 +#endif 7.529 + mov AX, (BP, DI) 7.530 + mov AX, CX 7.531 + shrw $1, CX 7.532 + dec CX 7.533 + cmpb $4, %al 7.534 + jb lzd22 7.535 + 7.536 +// rep0 = (2 | ((UInt32)posSlot & 1)); 7.537 + 7.538 + andb %bl, (BP, DI) // %bx=1 7.539 + orb $2, (BP, DI) 7.540 + 7.541 +// if (posSlot < kEndPosModelIndex /*14*/) { 7.542 + 7.543 + cmpb $14, %al 7.544 + jnb lzd23 7.545 + 7.546 +// rep0 <<= numDirectBits; 7.547 + 7.548 + neg AX 7.549 +# ifdef ONLY8086 7.550 + pushw %cx 7.551 + movb $0, %ch 7.552 +shllrep0: 7.553 + shlw $1, (BP, DI) 7.554 + rclw $1, 2(BP, DI) 7.555 + loop shllrep0 7.556 + popw %cx 7.557 +# else 7.558 + shll %cl, (BP, DI) 7.559 +# endif 7.560 + add (BP, DI), AX 7.561 + 7.562 +// prob = p + SpecPos /*688*/ + rep0 - posSlot - 1; 7.563 + 7.564 + add $687, AX 7.565 + jmp lzd24 7.566 + 7.567 +// } 7.568 +// else { 7.569 +lzd23: 7.570 +// numDirectBits -= kNumAlignBits /*4*/; 7.571 +// do { 7.572 +// RC_NORMALIZE; Range >>= 1; rep0 <<= 1; 7.573 +// if (Code >= Range) { Code -= Range; rep0 |= 1; } 7.574 + 7.575 +lzd23z: 7.576 + call RC_NORMALIZE 7.577 +# ifdef ONLY8086 7.578 + pushw %dx 7.579 + shrw $1, Range+2(BP) 7.580 + rcrw $1, Range(BP) 7.581 + movw Range(BP), %ax 7.582 + movw Range+2(BP), %dx 7.583 + cmpw Code+2(BP), %dx 7.584 + ja lzd25 7.585 + jb lzd25x 7.586 + cmpw Code(BP), %ax 7.587 + ja lzd25 7.588 +lzd25x: 7.589 + subw %ax, Code(BP) 7.590 + sbbw %dx, Code+2(BP) 7.591 + stc 7.592 +lzd25: 7.593 + popw %dx 7.594 + rclw $1, (BP, DI) 7.595 + rclw $1, 2(BP, DI) 7.596 +# else 7.597 + shrl $1, Range(BP) 7.598 + movl Range(BP), %eax 7.599 + cmpl Code(BP), %eax 7.600 + ja lzd25 7.601 + subl %eax, Code(BP) 7.602 + stc 7.603 +lzd25: 7.604 + rcll $1, (BP, DI) 7.605 +# endif 7.606 + 7.607 +// } while (--numDirectBits != 0); 7.608 + 7.609 + cmpb $4+1, %cl 7.610 + loopne lzd23z 7.611 + 7.612 +// prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/; 7.613 +// rep0 <<= numDirectBits; 7.614 + 7.615 +# ifdef ONLY8086 7.616 + pushw %cx 7.617 + movb $0, %ch 7.618 +shlrep0: 7.619 + shlw $1, (BP, DI) 7.620 + rclw $1, 2(BP, DI) 7.621 + loop shlrep0 7.622 + popw %cx 7.623 +# else 7.624 + shll %cl, (BP, DI) 7.625 +# endif 7.626 + mov $802, AX 7.627 +// } 7.628 + 7.629 +lzd24: 7.630 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 7.631 + 7.632 +// { 7.633 +// int i = 1, mi = 1; 7.634 +// do { 7.635 +// CProb *prob3 = prob + mi; 7.636 +// RC_GET_BIT2(prob3, mi, ; , rep0 |= i); 7.637 + 7.638 + orb %dh, (BP, DI) // update rep0 with DirectBits 7.639 + 7.640 +// i <<= 1; 7.641 +// } while(--numDirectBits != 0); 7.642 +// } 7.643 +// } else rep0 = posSlot; 7.644 +lzd22: 7.645 +// if (++rep0 == (UInt32)(0)) break; /* EOF */ 7.646 + 7.647 +# ifdef ONLY8086 7.648 + incw (BP, DI) 7.649 + jnz lzd19 7.650 + incw 2(BP, DI) 7.651 +# else 7.652 + incl (BP, DI) 7.653 +# endif 7.654 + 7.655 +lzd19: 7.656 + pop CX 7.657 + jz lzdone 7.658 + 7.659 +// } 7.660 +// len += kMatchMinLen;/*2*/ 7.661 + 7.662 + inc CX 7.663 + 7.664 +// string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR; 7.665 +// do { 7.666 +lzd13z: 7.667 +// previousByte = outStream[nowPos - rep0]; 7.668 +// outStream[nowPos++] = previousByte; 7.669 + 7.670 + call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0] 7.671 + 7.672 +// } while(--len != 0); 7.673 + 7.674 + loop lzd13z 7.675 + 7.676 +// } /* char/string */ 7.677 +// } 7.678 + 7.679 + jmp lzdmainlp 7.680 + 7.681 +lzdone: 7.682 +// //RC_NORMALIZE; 7.683 +// //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos; 7.684 +// return LZMA_RESULT_OK; 7.685 + call Dico2ESDI // set es & di (rep0 = 0) 7.686 + lea ws2(BP), SP // dealloc 7.687 + ret 7.688 +// } 7.689 + 7.690 +// al = outStream[nowPos - rep0]; 7.691 + 7.692 +/* 7.693 + * output es:di, al 7.694 + * scratch bh, cl, flags 7.695 + */ 7.696 + 7.697 +DicoRep02ESDI: 7.698 + stc 7.699 + 7.700 +// bl = outStream[nowPos]; 7.701 + 7.702 +/* 7.703 + * output es:di, bl 7.704 + * scratch bh, cl, flags 7.705 + */ 7.706 + 7.707 +Dico2ESDI: 7.708 +#if !defined(FLAT32) && !defined(FLAT16OUT) 7.709 +# ifdef ONLY8086 7.710 + pushw %ax 7.711 + movw nowPos(%bp), %bx 7.712 + movw nowPos+2(%bp), %ax 7.713 + jnc Dico2ESDIz 7.714 + subw rep0(%bp), %bx 7.715 + sbbw rep0+2(%bp), %ax 7.716 +Dico2ESDIz: 7.717 + movw $0xF, %di 7.718 + andw %bx, %di 7.719 + pushw %cx 7.720 + movb $4, %cl 7.721 + shrw %cl, %bx 7.722 + shlw %cl, %ax 7.723 + popw %cx 7.724 + addb %al, %bh 7.725 + popw %ax 7.726 +# else 7.727 + movl nowPos(%bp), %ebx 7.728 + jnc Dico2ESDIz 7.729 + subl rep0(%bp), %ebx 7.730 +Dico2ESDIz: 7.731 + movw %bx, %di 7.732 + xorw %bx, %bx 7.733 + shrl $4, %ebx 7.734 +# endif 7.735 + movw %bx, %es 7.736 +#else 7.737 + mov nowPos(BP), DI 7.738 + jnc Dico2ESDIz 7.739 + sub rep0(BP), DI 7.740 +Dico2ESDIz: 7.741 +#endif 7.742 +#ifdef FLAT32 7.743 + movb (DI), %bl 7.744 +#else 7.745 + movb %es:(%di), %bl 7.746 +#endif 7.747 + ret 7.748 + 7.749 +outcharDico: 7.750 + 7.751 +// bl = outStream[nowPos++] = outStream[nowPos - rep0] 7.752 + 7.753 +/* 7.754 + * output es:di, bl 7.755 + * update nowPos 7.756 + * scratch ax, dx, bh, cl, flags 7.757 + */ 7.758 + 7.759 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0] 7.760 + xchg AX, BX 7.761 +outchar: 7.762 + 7.763 +// bl = outStream[nowPos++] = previousByte = al; 7.764 + 7.765 +/* 7.766 + * output bl 7.767 + * update nowPos 7.768 + * scratch ax, dx, bh, di, cl, flags 7.769 + */ 7.770 + 7.771 + clc 7.772 + call Dico2ESDI 7.773 + stosb 7.774 + xchg AX, BX // previous byte 7.775 + 7.776 +// int posState = (int)((nowPos) & posStateMask); 7.777 + 7.778 +#if PROP_PB != 0 && PROP_LP != 0 7.779 + addw $0x0101, posState2(BP) 7.780 + andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP) 7.781 +#else 7.782 +# if PROP_PB != 0 7.783 + incb posState(BP) 7.784 + andb $((1 << PROP_PB) -1), posState(BP) 7.785 +# endif 7.786 +# if PROP_LP != 0 7.787 + incb posState2(BP) 7.788 + andb $((1 << PROP_LP) -1), posState2(BP) 7.789 +# endif 7.790 +#endif 7.791 +#ifdef ONLY8086 7.792 + incw nowPos(BP) 7.793 + jnz incnowPosDone 7.794 + incw nowPos+2(BP) 7.795 +incnowPosDone: 7.796 +#else 7.797 + incl nowPos(BP) 7.798 +#endif 7.799 + ret 7.800 + 7.801 +// 7.802 +// #define RC_NORMALIZE if (Range < kTopValue) 7.803 +// { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 7.804 + 7.805 +/* 7.806 + * update Range, Code, ds:si 7.807 + * scratch flags 7.808 + */ 7.809 + 7.810 +RC_NORMALIZE: 7.811 + cmpb $0, Range+3(BP) 7.812 + jne RC_NORMALIZE_1 7.813 +RC_LOAD_BYTE: 7.814 + push AX 7.815 +#ifdef ONLY8086 7.816 + movw Range+1(BP), %ax 7.817 + movw %ax, Range+2(BP) 7.818 + movw Code+1(BP), %ax 7.819 + movw %ax, Code+2(BP) 7.820 + xorw %ax, %ax 7.821 + movb Range(BP), %ah 7.822 + movw %ax, Range(BP) 7.823 + movb Code(BP), %ah 7.824 + movw %ax, Code(BP) 7.825 +#else 7.826 + shll $8, Range(BP) 7.827 + shll $8, Code(BP) 7.828 +#endif 7.829 +#if !defined(FLAT16) && !defined(FLAT32) 7.830 + testw %si, %si 7.831 + jns RC_READ_BYTE 7.832 + movw %ds, %ax 7.833 + incw %ax 7.834 + movw %ax, %ds 7.835 + addw $-16, %si 7.836 +RC_READ_BYTE: 7.837 +#endif 7.838 + lodsb 7.839 + movb %al, Code(BP) 7.840 + pop AX 7.841 +RC_NORMALIZE_1: 7.842 + ret 7.843 + 7.844 +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 7.845 + 7.846 +Bit1state: 7.847 + movb $16, %al 7.848 + mulb state(BP) 7.849 +# if PROP_PB != 0 7.850 + addb posState(BP), %al 7.851 +# endif 7.852 +Bit1axdx: 7.853 + add DX, AX 7.854 + jmp Bit1 7.855 + 7.856 +// prob += 12; Bit1(prob) 7.857 + 7.858 +Bit1dx12: 7.859 + add $12, DX 7.860 +Bit1dx: 7.861 + mov DX, AX 7.862 + 7.863 +// static int Bit1(CProb *p) 7.864 + 7.865 +Bit1: 7.866 +/* 7.867 + * input ax=p 7.868 + * output C, ax 7.869 + * update bound, Range, Code, ds:si 7.870 + * scratch flags 7.871 + */ 7.872 + 7.873 +// { 7.874 +// RC_NORMALIZE; 7.875 + 7.876 + call RC_NORMALIZE // kill %ax, update %si 7.877 + 7.878 +#ifdef ONLY8086 7.879 + pushw %ax 7.880 + pushw %cx 7.881 + pushw %dx 7.882 + pushw %di 7.883 +#else 7.884 + pushal 7.885 +#endif 7.886 + 7.887 + xchg AX, DI 7.888 + add DI, DI // short * 7.889 + 7.890 + 7.891 +// bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p); 7.892 + 7.893 +#ifdef ONLY8086 7.894 + movw Range(BP), %dx 7.895 + movw Range+2(BP), %ax 7.896 + movw $11, %cx 7.897 +shr11lp: 7.898 + shrw $1, %ax 7.899 + rcrw $1, %dx 7.900 + loop shr11lp 7.901 + movw %dx, %cx 7.902 + mulw (BP, DI) 7.903 + xchgw %ax, %cx 7.904 + mulw (BP, DI) 7.905 + addw %cx, %dx 7.906 +#else 7.907 + movl Range(BP), %eax 7.908 + shrl $11, %eax 7.909 + movzwl (BP, DI), %edx 7.910 + mull %edx 7.911 +#endif 7.912 + 7.913 +// if (Code < bound) { 7.914 + 7.915 +#ifdef ONLY8086 7.916 + cmpw Code+2(BP), %dx 7.917 + jb Bit1_1 7.918 + ja Bit1_1x 7.919 + cmpw Code(BP), %ax 7.920 + jbe Bit1_1 7.921 +Bit1_1x: 7.922 + 7.923 +// Range = bound; 7.924 + 7.925 + movw %ax, Range(BP) 7.926 + movw %dx, Range+2(BP) 7.927 +#else 7.928 + cmpl Code(BP), %eax 7.929 + jbe Bit1_1 7.930 + 7.931 +// Range = bound; 7.932 + 7.933 + movl %eax, Range(BP) 7.934 +#endif 7.935 + 7.936 +// *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/; 7.937 + 7.938 + movw $2048, %ax 7.939 + 7.940 +// return 0; 7.941 + 7.942 + jmp Bit1_2 7.943 + 7.944 +// } 7.945 +// else { 7.946 + 7.947 +Bit1_1: 7.948 + 7.949 +// Range -= bound; Code -= bound; 7.950 + 7.951 +#ifdef ONLY8086 7.952 + subw %ax, Range(BP) 7.953 + sbbw %dx, Range+2(BP) 7.954 + subw %ax, Code(BP) 7.955 + sbbw %dx, Code+2(BP) 7.956 +#else 7.957 + subl %eax, Range(BP) 7.958 + subl %eax, Code(BP) 7.959 +#endif 7.960 + 7.961 +// *(p) -= (*(p)) >> kNumMoveBits /*5*/; 7.962 + 7.963 + movw $31, %ax 7.964 + 7.965 +// return 1; 7.966 + 7.967 + stc 7.968 +Bit1_2: 7.969 + pushf 7.970 + subw (BP, DI), %ax 7.971 +#ifdef ONLY8086 7.972 + movb $5, %cl 7.973 + sarw %cl, %ax 7.974 +#else 7.975 + sarw $5, %ax 7.976 +#endif 7.977 + addw %ax, (BP, DI) 7.978 + popf 7.979 +#ifdef ONLY8086 7.980 + popw %di 7.981 + popw %dx 7.982 + popw %cx 7.983 + popw %ax 7.984 +#else 7.985 + popal 7.986 +#endif 7.987 + sbb AX, AX 7.988 + 7.989 +// } 7.990 +// } 7.991 + 7.992 + ret 7.993 + 7.994 +RangeDecoder: 7.995 + 7.996 +/* 7.997 + * input ax=probs cx=numLevels (< 8) bx=1 7.998 + * output ax=res (backward), dh (forward) 7.999 + * update bound, Range, Code, ds:si 7.1000 + * scratch flags, cx=0, dl 7.1001 + */ 7.1002 + 7.1003 + push BX 7.1004 + 7.1005 +// { int i = numLevels; res = 1; 7.1006 + mov BX, DX // res = 1 7.1007 + 7.1008 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); 7.1009 + 7.1010 +RangeDecoder_1: 7.1011 + push AX 7.1012 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 7.1013 + rclb $1, %dl // res <<= 1; res |= C 7.1014 + andb %bl, %al // current bit 7.1015 + orb %al, %bh // store in bh 7.1016 + shlb $1, %bl // update max 7.1017 + pop AX 7.1018 + loop RangeDecoder_1 7.1019 + 7.1020 +// res -= (1 << numLevels); } 7.1021 + 7.1022 + xchg AX, BX // move bh to dh 7.1023 + xchg AX, DX // and dl to al 7.1024 + sub %dl, %al // sub max 7.1025 + pop BX 7.1026 + ret
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/x86test/stuff/unpack.S Sat May 08 17:23:19 2021 +0000 8.3 @@ -0,0 +1,286 @@ 8.4 +#define SYSTEM 0x10000 8.5 +#define SETUP 14 8.6 +#define SYSSIZE 0x1F4 8.7 +#define SETUPSIZE 0x1F1 8.8 + 8.9 +#define LINUX_HEADER 0 8.10 +#define UPDATE_SYSSIZE 1 8.11 +#define HARDCODED_SYSSIZE 1 8.12 +#define HARDCODED_SETUPSIZE 1 8.13 +#define FLAT16 1 8.14 +#define FLAT16OUT 1 8.15 +#define SAVEREGS 0 8.16 +#define ELKS 0 8.17 + 8.18 +#define ONLY8086 1 8.19 + 8.20 + .text 8.21 + .code16 8.22 + .org 0 8.23 + 8.24 +#if ELKS 8.25 + .arch i8086 8.26 +#define FLAT16 1 8.27 +#define LINUX_HEADER 0 8.28 +#define SAVEREGS 0 8.29 +#define TOPSEG 0x2000 8.30 +#else 8.31 +#define TOPSEG 0x8000 8.32 +#endif 8.33 + 8.34 + .globl _start 8.35 +_start: 8.36 +#if LINUX_HEADER 8.37 + jmp start2 8.38 + .ascii "HdrS" // 202 magic 8.39 + .word 0x200 // 206 version 2.00 8.40 + .long 0 // 208 realmode_swtch 8.41 + .word SYSTEM/16 // 20C start_sys_seg 8.42 + .word 0 // 20E kernel_version 8.43 + .byte 0 // 210 type_of_loader 8.44 + .byte 0 // 211 loadflags 8.45 + .word 0 // 212 setup_move_size 8.46 + .long SYSTEM // 214 code32_start 8.47 + .long 0 // 218 ramdisk_image 8.48 + .long 0 // 21C ramdisk_size 8.49 + .long 0 // 220 bootsect_kludge 8.50 +start2: 8.51 +#endif 8.52 +#if SAVEREGS 8.53 + pushfw 8.54 + pushw %cs 8.55 + pushw $0 8.56 + pushal 8.57 + pushw %ds 8.58 + cld 8.59 +#else 8.60 + pushw %cs 8.61 +# if FLAT16 8.62 + xorw %di, %di 8.63 + pushw %di 8.64 +# else 8.65 + pushw $0 8.66 +# endif 8.67 +#endif 8.68 +#if ELKS 8.69 + movw $0x100, %ax 8.70 + pushw %ax 8.71 +#else 8.72 +#if UPDATE_SYSSIZE 8.73 + pushw %ds // <A> 8.74 +#else 8.75 + pushw %cs // <A> 8.76 +#endif 8.77 +#endif 8.78 +#if FLAT16 8.79 +# 1- move 9020..9020+stp -> TOPSEG 8.80 +#if ELKS 8.81 + movb $TOPSEG/256, %ah 8.82 + movw %ax, %es 8.83 +#else 8.84 + pushw $TOPSEG 8.85 + popw %es 8.86 +#endif 8.87 + movw $0x200, %si 8.88 +#if SAVEREGS == 0 8.89 + pushw %es 8.90 +#if ELKS 8.91 + movw $cont, %ax 8.92 + pushw %ax 8.93 +#else 8.94 + // pushw $cont 8.95 + .byte 0x6A, cont 8.96 +#endif 8.97 + jmp jumpinto 8.98 +#else 8.99 +# if HARDCODED_SETUPSIZE 8.100 +setup_word: 8.101 + movw $SETUP*256, %cx 8.102 +# else 8.103 + xorw %cx, %cx 8.104 + movb SETUPSIZE, %ch 8.105 + movw %cx, %dx 8.106 +# endif 8.107 + pushw %cx // <B> 8.108 + pushw %es 8.109 + pushw %di 8.110 + rep 8.111 + movsw 8.112 + lret 8.113 +#endif 8.114 +cont: 8.115 +# 2- move 1000..1000+sys -> TOPSEG+stp 8.116 +#if ELKS 8.117 + movw $0x1000, %ax 8.118 + movw %ax, %ds 8.119 +#else 8.120 + pushw $0x1000 8.121 + popw %ds 8.122 +#endif 8.123 + xorw %si, %si 8.124 + subw %di, %cx 8.125 + rep 8.126 + movsb 8.127 +# 3- unlz(TOPSEG+stp:end, 1000-stp:0) 8.128 + pushw %es // <C> 8.129 +# if HARDCODED_SETUPSIZE 8.130 +setup_seg: 8.131 +#if ELKS 8.132 +# if UPDATE_SYSSIZE 8.133 + movw $0x1000-(SETUP*32)-32, %ax 8.134 +# else 8.135 + movw $0x1000-(SETUP*32), %ax 8.136 +# endif 8.137 + movw %ax, %es 8.138 +#else 8.139 +# if UPDATE_SYSSIZE 8.140 + pushw $0x1000-(SETUP*32)-32 8.141 +# else 8.142 + pushw $0x1000-(SETUP*32) 8.143 +# endif 8.144 + popw %es 8.145 +#endif 8.146 +# else 8.147 +# if UPDATE_SYSSIZE 8.148 + incb %dh 8.149 +# endif 8.150 +#if ELKS 8.151 + shrw $1, %dx 8.152 + shrw $1, %dx 8.153 + shrw $1, %dx 8.154 +#else 8.155 + shrw $3, %dx 8.156 +#endif 8.157 + movw %ds, %ax 8.158 + subw %dx, %ax 8.159 + movw %ax, %es 8.160 +# endif 8.161 +#else // FLAT16 8.162 +# 1- move 1000..1000+sys -> 9000-sys 8.163 +# if HARDCODED_SYSSIZE 8.164 +packed_syssize: 8.165 + movw $0x1000+0, %ax 8.166 +# else 8.167 + movw SYSSIZE, %ax 8.168 + addw $0x1000, %ax 8.169 +# endif 8.170 + movw %ds, %dx 8.171 +mvsys: 8.172 + decw %ax 8.173 + decw %dx 8.174 + movw %ax, %ds 8.175 + movw %dx, %es 8.176 + xorw %si, %si 8.177 + xorw %di, %di 8.178 + movw $8, %cx 8.179 + rep 8.180 + movsw 8.181 + cmpw $0x1000, %ax 8.182 + jne mvsys 8.183 +# 2- move 9020..9020+stp -> 9000-sys-stp 8.184 + 8.185 +# if HARDCODED_SETUPSIZE 8.186 +setup_byte: 8.187 + movb $SETUP, %ch 8.188 +setup_para: 8.189 + subw $SETUP*32, %dx 8.190 +# else 8.191 + movb %ss:SETUPSIZE, %ch 8.192 + movw %cx, %ax 8.193 +#if ELKS 8.194 + shrw $1, %ax 8.195 + shrw $1, %ax 8.196 + shrw $1, %ax 8.197 +#else 8.198 + shrw $3, %ax 8.199 +#endif 8.200 + subw %ax, %dx 8.201 +# endif 8.202 + pushw %cx // <B> 8.203 + movw %dx, %es 8.204 + xorw %si, %si 8.205 + xorw %di, %di 8.206 + rep 8.207 + movsw %cs:(%si),%es:(%di) 8.208 + pushw %es 8.209 +# 3- reloc itself in 0x7C00 8.210 + pushw $0x07C0 8.211 + popw %es 8.212 + movw $cont, %si 8.213 + movw %si, %di 8.214 + movw $end-_start, %cx 8.215 + pushw %es 8.216 + pushw %di 8.217 + rep 8.218 + movsb %cs:(%si),%es:(%di) 8.219 + lret 8.220 +cont: 8.221 +# 4- unlz(9000-sys-stp:end, 1000-stp:0) 8.222 +# if HARDCODED_SETUPSIZE 8.223 +setup_seg: 8.224 +# if UPDATE_SYSSIZE 8.225 + pushw $0x1000-(SETUP*32)-32 8.226 +# else 8.227 + pushw $0x1000-(SETUP*32) 8.228 +# endif 8.229 + popw %es 8.230 +# else 8.231 + negw %ax 8.232 +# if UPDATE_SYSSIZE 8.233 + addw $0x1000-32, %ax 8.234 +# else 8.235 + addw $0x1000, %ax 8.236 +# endif 8.237 + movw %ax, %es 8.238 +# endif 8.239 +#endif // FLAT16 8.240 + popw %ds // <C> 8.241 + movw $end-_start, %si 8.242 +#if UPDATE_SYSSIZE 8.243 + movw $SYSSIZE, %di 8.244 +#else 8.245 + xorw %di, %di 8.246 +#endif 8.247 + pushw %di 8.248 + pushw %es 8.249 + call unpack 8.250 + popw %ds 8.251 + popw %si 8.252 + movw %si, %di 8.253 +# if SAVEREGS != 0 8.254 + popw %cx // <B> 8.255 +#if UPDATE_SYSSIZE 8.256 +// not need with memtest movb $(512-SYSSIZE)/2, %cl 8.257 +#endif 8.258 + popw %es // <A> 8.259 +# 5- move 1000-stp..1000 -> 9020 8.260 +# else 8.261 + popw %es // <A> 8.262 +jumpinto: 8.263 +# if HARDCODED_SETUPSIZE 8.264 +setup_word: 8.265 + movw $SETUP*256, %cx 8.266 +# else 8.267 + xorw %cx, %cx 8.268 + movb %ss:SETUPSIZE, %ch 8.269 + movw %cx, %dx 8.270 +# endif 8.271 +# endif 8.272 + rep 8.273 + movsw 8.274 +#if SAVEREGS 8.275 + popw %ds 8.276 + popal 8.277 + iret 8.278 +#else 8.279 + lret 8.280 +#endif 8.281 + 8.282 +unpack: 8.283 +#define NO_LZMA_HEADER 8.284 +#if ELKS 8.285 +#define ONLY8086 1 8.286 +#endif 8.287 +#include "unlzma.S" 8.288 + 8.289 +end:
9.1 Binary file x86test/stuff/x86test has changed