wok rev 25514

Add memtest64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 16 14:18:05 2023 +0000 (14 months ago)
parents 2956e54cc56a
children 8acc87b18a99
files memtest-efi32/receipt memtest-efi64/receipt memtest/receipt memtest64/receipt memtest64/stuff/bootloader.S memtest64/stuff/pack memtest64/stuff/unlz4.S memtest64/stuff/unlzma.S memtest64/stuff/unlzsa1.S memtest64/stuff/unlzsa2.S memtest64/stuff/unpack.S memtest64/stuff/unpackx.S
line diff
     1.1 --- a/memtest-efi32/receipt	Tue Feb 14 15:41:57 2023 +0000
     1.2 +++ b/memtest-efi32/receipt	Thu Feb 16 14:18:05 2023 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  # SliTaz package receipt.
     1.5  
     1.6  PACKAGE="memtest-efi32"
     1.7 -VERSION="6.01"
     1.8 +VERSION="6.10"
     1.9  CATEGORY="base-system"
    1.10  SHORT_DESC="Memory failures detection tool."
    1.11  MAINTAINER="pascal.bellard@slitaz.org"
     2.1 --- a/memtest-efi64/receipt	Tue Feb 14 15:41:57 2023 +0000
     2.2 +++ b/memtest-efi64/receipt	Thu Feb 16 14:18:05 2023 +0000
     2.3 @@ -1,7 +1,7 @@
     2.4  # SliTaz package receipt.
     2.5  
     2.6  PACKAGE="memtest-efi64"
     2.7 -VERSION="6.01"
     2.8 +VERSION="6.10"
     2.9  CATEGORY="base-system"
    2.10  SHORT_DESC="Memory failures detection tool."
    2.11  MAINTAINER="pascal.bellard@slitaz.org"
     3.1 --- a/memtest/receipt	Tue Feb 14 15:41:57 2023 +0000
     3.2 +++ b/memtest/receipt	Thu Feb 16 14:18:05 2023 +0000
     3.3 @@ -66,7 +66,6 @@
     3.4  # Rules to configure and make the package.
     3.5  compile_rules()
     3.6  {
     3.7 -	# Need CPUID instruction (586+ cpu)
     3.8  	sed -i 's|64, MT_VERSION "." GIT_HASH|65, MT_VERSION ".SliTaz"|;s|"\.x32"|".386"|' app/display.c
     3.9  	sed 's|gcc|gcc-83|;s|march=i586|march=i486|' -i build32/Makefile
    3.10  	patch -p0 < $stuff/memtest86\+-6-386.patch
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/memtest64/receipt	Thu Feb 16 14:18:05 2023 +0000
     4.3 @@ -0,0 +1,86 @@
     4.4 +# SliTaz package receipt.
     4.5 +
     4.6 +PACKAGE="memtest64"
     4.7 +VERSION="6.10"
     4.8 +CATEGORY="base-system"
     4.9 +SHORT_DESC="Memory failures detection tool."
    4.10 +MAINTAINER="pascal.bellard@slitaz.org"
    4.11 +LICENSE="GPL2"
    4.12 +TARBALL="$PACKAGE-$VERSION.zip"
    4.13 +WEB_SITE="https://www.memtest.org/"	# https://github.com/memtest86plus/memtest86plus/
    4.14 +WGET_URL="https://memtest.org/download/v$VERSION/mt86plus_${VERSION}.binaries.zip"
    4.15 +
    4.16 +# What is the latest version available today?
    4.17 +current_version()
    4.18 +{
    4.19 +	wget -O - $WEB_SITE 2>/dev/null | \
    4.20 +	sed '/binaries.zip/!d;s|.*mt86plus_||;s|.binaries.zip.*||;q'
    4.21 +}
    4.22 +
    4.23 +asm()
    4.24 +{
    4.25 +	cc -o $1.o -Wa,-a=$1.lst -c $1.S
    4.26 +	objcopy --only-section=.text -O binary $1.o $1.bin
    4.27 +}
    4.28 +
    4.29 +tune_lzma()
    4.30 +{
    4.31 +	file=$1
    4.32 +	shift
    4.33 +	for i in lzma lz4x2 lzsa1x2 lzsa2x2 ; do
    4.34 +		cp $stuff/*.S $stuff/pack .
    4.35 +		sed "s/VERSION/$VERSION/;s|lzma1=|&nice=${1:-64},|" -i pack
    4.36 +		while [ -n "$2" ]; do
    4.37 +			sed "s|^#define PROP_$2 .*|#define PROP_$2 $3|" -i unlzma.S
    4.38 +			shift 2
    4.39 +		done
    4.40 +		sed -i "s|uncompress|un${i%x2}|" unpack.S
    4.41 +		asm bootloader
    4.42 +		asm unpack
    4.43 +		cp pack pack.bak
    4.44 +		./pack --build bootloader.bin unpack.bin
    4.45 +		PACKER=${i%x2} ./pack $file $file.${i%x2}
    4.46 +		if [ $(stat -c %s $file.${i%x2}) -ge $((0x101F0)) ]; then
    4.47 +			rm $file.${i%x2}
    4.48 +			cp pack.bak pack
    4.49 +			sed -e "s|^#define FLAT16.*// lzma case|#define FLAT16			0 // ${i%x2}|" -i unpack.S
    4.50 +			asm unpack
    4.51 +			./pack --build bootloader.bin unpack.bin
    4.52 +			PACKER=${i%x2} ./pack $file $file.${i%x2}
    4.53 +		fi
    4.54 +		mv unpack.lst unpack.lst.${i%x2}
    4.55 +		if [ "${i#*x}" = "2" ]; then
    4.56 +			cp pack.bak pack
    4.57 +			sed -e "s|^#define DOUBLE_PACKED|#define DOUBLE_PACKED	1 // $i|" -i unpack.S
    4.58 +			asm unpack
    4.59 +			./pack --build bootloader.bin unpack.bin
    4.60 +			PACKER=${i%x2} ./pack $file $file.$i
    4.61 +			mv unpack.lst unpack.lst.$i
    4.62 +		fi
    4.63 +	done
    4.64 +}
    4.65 +
    4.66 +# Rules to configure and make the package.
    4.67 +compile_rules()
    4.68 +{
    4.69 +	tune_lzma memtest64.bin 55,mf=bt2 LC 3 PB 2
    4.70 +} 
    4.71 +
    4.72 +# Rules to gen a SliTaz package suitable for Tazpkg.
    4.73 +genpkg_rules()
    4.74 +{
    4.75 +	mkdir -p $fs/boot
    4.76 +	cp $src/memtest64.bin.lzma $fs/boot/memtest64.exe
    4.77 +}
    4.78 +
    4.79 +# Pre and post install commands for Tazpkg.
    4.80 +post_install()
    4.81 +{
    4.82 +	[ -s $1/boot/isolinux/isolinux.cfg ] &&
    4.83 +	! grep -qs 'Check 64bits memory' $1/boot/isolinux/isolinux.cfg && sed -i \
    4.84 +'s|LABEL md5|LABEL memtest64 mem64 ram64\
    4.85 +	MENU LABEL Check 64bits memory\
    4.86 +	KERNEL /boot/memtest64.exe\
    4.87 +\n&|' $1/boot/isolinux/isolinux.cfg
    4.88 +	true
    4.89 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/memtest64/stuff/bootloader.S	Thu Feb 16 14:18:05 2023 +0000
     5.3 @@ -0,0 +1,684 @@
     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 +
    5.23 +/* some extra features */
    5.24 +#define EXE_SUPPORT		real mode dos .exe file support	+208/264
    5.25 +#define  CMDLINE		dos kernel cmdline support	+45
    5.26 +#define  BUGGY_CMDLINE		verify cmdline length		+2
    5.27 +#define  VCPI			VCPI 4.0 support (386+)		+109
    5.28 +#define  SHUTDOWNDOS		shutdown DOS services		+29
    5.29 +#define   CHK_DOS_INT19		do not trace bios		+12/13
    5.30 +
    5.31 +/* some contraints to reduce the code size */
    5.32 +//#define FLOPPY_1440K_ONLY	1.44M floppies support only	-26
    5.33 +//#define FLOPPY_HAS_2_SIDES	hardcoded heads count to 2	-15
    5.34 +//#define NO_CMDLINE_SHRINK	remove heading spaces ?		-6-21
    5.35 +//#define  NO_CMDLINE_FILE	remove @cmdline file support ?	-21
    5.36 +#define NO_DOTS			show progression dots ?		-5
    5.37 +#ifndef BZIMAGE
    5.38 +//#define TINY_ZIMAGE		system < 64Kb ?			-11
    5.39 +//#define NO_MINSETUP		default setup (dos only) ?	-4
    5.40 +//#define NO_CURSOR_DEFINITION					-8
    5.41 +#endif
    5.42 +
    5.43 +#ifdef ELKS
    5.44 +	.arch	i8086
    5.45 +INITSEG		= 0x0100
    5.46 +SETUPSEG	= 0x0120
    5.47 +#define ONLY8086
    5.48 +#undef BZIMAGE
    5.49 +#undef VCPI
    5.50 +#else
    5.51 +INITSEG		= 0x9000
    5.52 +SETUPSEG	= 0x9020
    5.53 +#endif
    5.54 +
    5.55 +.macro	shlclw cnt,obj
    5.56 +#ifdef ONLY8086
    5.57 +	movb	\cnt,%cl
    5.58 +	shlw	%cl,\obj
    5.59 +#else
    5.60 +	shlw	\cnt,\obj
    5.61 +#endif
    5.62 +.endm
    5.63 +
    5.64 +.macro	shrclw cnt,obj
    5.65 +#ifdef ONLY8086
    5.66 +	movb	\cnt,%cl
    5.67 +	shrw	%cl,\obj
    5.68 +#else
    5.69 +	shrw	\cnt,\obj
    5.70 +#endif
    5.71 +.endm
    5.72 +
    5.73 +#ifdef EXE_SUPPORT
    5.74 +#define EXEADRS(x)	(x+0xE0)
    5.75 +#define FLAT20(x)	(x+16*INITSEG)
    5.76 +
    5.77 +.macro	trace_int19
    5.78 +#ifdef ONLY8086
    5.79 +	xorw	%si, %si
    5.80 +	movw	%si, %ds
    5.81 +# ifdef CHK_DOS_INT19
    5.82 +	cmpb	$0xF0, 4*0x19+3(%si)
    5.83 +	jne	stepit
    5.84 +	pushw	%es
    5.85 +	movw	$skip_step19, %si
    5.86 +	pushw	%si
    5.87 +	retf
    5.88 +stepit:
    5.89 +# endif
    5.90 +	pushw	4+2(%si)
    5.91 +	pushw	4(%si)
    5.92 +	movw	$step19, 4(%si)
    5.93 +	movw	$INITSEG, 4+2(%si)
    5.94 +#else
    5.95 +	pushl	$4
    5.96 +	popw	%si
    5.97 +	popw	%ds
    5.98 +# ifdef CHK_DOS_INT19
    5.99 +	cmpb	$0xF0, 4*0x19+3-4(%si)
   5.100 +	jne	stepit
   5.101 +	pushw	%es
   5.102 +	pushw	$skip_step19
   5.103 +	retf
   5.104 +stepit:
   5.105 +# endif
   5.106 +	pushl	(%si)
   5.107 +	movl	$step19+(INITSEG<<16), (%si)
   5.108 +#endif
   5.109 +	pushfw
   5.110 +	popw	%ax
   5.111 +	incb	%ah			# set TF
   5.112 +	pushw	%ax
   5.113 +	popfw
   5.114 +#ifdef ONLY8086
   5.115 +	ljmp	*4*0x19(%si)
   5.116 +#else
   5.117 +	ljmp	*4*0x19-4(%si)
   5.118 +#endif
   5.119 +.endm
   5.120 +
   5.121 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
   5.122 +	decw	%bp			// Magic number: MZ
   5.123 +	popw	%dx
   5.124 +	jmp	start			// Bytes on last page of file
   5.125 +	.word	(CODESZ+511)/512	// Pages in file			INSTALLER
   5.126 +	.word	0			// Relocations
   5.127 +	.word	(end_header-_start)/16	// Size of header in paragraphs
   5.128 +	.word	4096			// Minimum extra paragraphs needed
   5.129 +	.word	-1			// Maximum extra paragraphs needed
   5.130 +	.word	(CODESZ+15)/16		// Initial (relative) SS value		INSTALLER
   5.131 +	.word	stacktop		// Initial SP value
   5.132 +	.word	0			// Checksum				INSTALLER?
   5.133 +	.word	EXEADRS(comstart)	// Initial IP value
   5.134 +	.word	0xFFF0			// Initial (relative) CS value
   5.135 +//	.word	0x001C			// File address of relocation table
   5.136 +//	.word	0,0,0			// Overlay number
   5.137 +#else
   5.138 +#undef VCPI
   5.139 +#endif
   5.140 +start:
   5.141 +	xorw	%ax, %ax		# %ax = 0
   5.142 +zeroed		= 12			# zeroed registers
   5.143 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
   5.144 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000 (+zeroed+12)
   5.145 +#ifdef ONLY8086
   5.146 +	movw	$INITSEG, %bx
   5.147 +#else
   5.148 +	pushw	$INITSEG
   5.149 +#endif
   5.150 +end_header:
   5.151 +	cld				# assume nothing
   5.152 +#if defined(BZIMAGE) && BZIMAGE >= 0x202
   5.153 +	popw	%es			# %es contain INITSEG
   5.154 +	movw	%es, %di
   5.155 +#else
   5.156 +					# cmdline offset at 0x22
   5.157 +	movw	$stacktop, %di		# stacktop is an arbitrary value >=
   5.158 +					# length of bootsect + length of
   5.159 +					# setup + room for stack;
   5.160 +					# 12 is disk parm size.
   5.161 +# ifdef ONLY8086
   5.162 +	pushw	%bx
   5.163 +# endif
   5.164 +	popw	%es			# %es contain INITSEG
   5.165 +#endif
   5.166 +	pushw	%es
   5.167 +	popw	%ss			# %es = %ss = INITSEG
   5.168 +	movw	%di, %sp		# put stack at INITSEG:stacktop-...
   5.169 +#ifdef EXE_SUPPORT
   5.170 +	cwd				# force %dx = 0 (floppy only)
   5.171 +#endif
   5.172 +
   5.173 +# Many BIOS's default disk parameter tables will not recognize
   5.174 +# multi-sector reads beyond the maximum sector number specified
   5.175 +# in the default diskette parameter tables - this may mean 7
   5.176 +# sectors in some cases.
   5.177 +#
   5.178 +# Since single sector reads are slow and out of the question,
   5.179 +# we must take care of this by creating new parameter tables
   5.180 +# (for the first disk) in RAM.  We can set the maximum sector
   5.181 +# count to 36 - the most we will encounter on an ED 2.88.  
   5.182 +#
   5.183 +# High doesn't hurt.  Low does.  Let's use the max: 63
   5.184 +
   5.185 +	rep				# don't worry about cld
   5.186 +	stosw				# already done above
   5.187 +	popw	%bx			# offset = 0
   5.188 +	popw	%ds			# %ds = 0
   5.189 +
   5.190 +	movb	setup_sects+0x7C00, %al	# read bootsector + setup (%ds = 0)
   5.191 +	incw	%ax
   5.192 +
   5.193 +	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   5.194 +	pushw	%es
   5.195 +	pushw	%di
   5.196 +	movb	$6, %cl			# copy 12 bytes
   5.197 +	rep				# don't worry about cld
   5.198 +	movsw				# already done above
   5.199 +	movw	%cx, %ds		# %ds = 0
   5.200 +#ifdef ONLY8086
   5.201 +	popw	0x78(%bx)		# update parameter table address
   5.202 +	popw	0x78+2(%bx)
   5.203 +#else
   5.204 +	popl	0x78(%bx)		# update parameter table address
   5.205 +#endif
   5.206 +	pushw	%ss
   5.207 +	popw	%ds			# now %ds = %es = %ss = INITSEG
   5.208 +	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   5.209 +
   5.210 +	xchg	%ax, %di		# sector count
   5.211 +	popw	%ax			# limits = 0
   5.212 +	incw	%cx			# cylinder 0, sector 1, clear Z
   5.213 +	call	read_first_sectors	# read setup
   5.214 +
   5.215 +# This routine loads the system at address LOADSEG, making sure
   5.216 +# no 64kB boundaries are crossed. We try to load it as fast as
   5.217 +# possible, loading whole tracks whenever we can.
   5.218 +
   5.219 +	movw	syssize, %di
   5.220 +	decw	%di
   5.221 +	shrclw	$9-4, %di
   5.222 +	incw	%di
   5.223 +	movw	$SYSSEG, %cx
   5.224 +#ifdef BZIMAGE
   5.225 +	push	%cx
   5.226 +#endif
   5.227 +	call	read_sectorsCX
   5.228 +
   5.229 +# This procedure turns off the floppy drive motor, so
   5.230 +# that we enter the kernel in a known state, and
   5.231 +# don't have to worry about it later.
   5.232 +
   5.233 +kill_motor:
   5.234 +	xchgw	%ax, %di		# reset FDC (%di < 128)
   5.235 +	int	$0x13
   5.236 +
   5.237 +# After that (everything loaded), we jump to the setup-routine
   5.238 +# loaded directly after the bootblock:
   5.239 +# Segments are as follows: %ds = %ss = INITSEG
   5.240 +
   5.241 +#ifdef BZIMAGE
   5.242 +	popw	%bx
   5.243 +	popw	%si			// SYSSEG:0
   5.244 +movesys:				// %bx = DS, %si
   5.245 +	movw	$16, %ax
   5.246 +	mulw	%bx
   5.247 +	addw	%si, %ax
   5.248 +	adcw	$0x9300, %dx		// %dx:%ax src flat address
   5.249 +	movw	$9, %cx
   5.250 +zero1:
   5.251 +	pushw	$0			// 2E..1E
   5.252 +	loop	zero1
   5.253 +	//pushl	$0x93100000		// 1A: dest
   5.254 +	pushw	$0x9310
   5.255 +	pushw	%cx
   5.256 +	pushw	$-1			// 18
   5.257 +	pushw	%cx			// 16
   5.258 +	pushw	%dx			// src
   5.259 +	pushw	%ax
   5.260 +	pushw	$-1			// 10
   5.261 +	movb	$8, %cl
   5.262 +	movw	%cx, %bx		// will move 8*64 = 512Kb
   5.263 +zero2:
   5.264 +	pushw	$0			// 0E..00
   5.265 +	loop	zero2
   5.266 +	movw	%sp, %si
   5.267 +	pushw	%ss
   5.268 +	popw	%es
   5.269 +	pushw	%es
   5.270 +	popw	%ds
   5.271 +syslp:
   5.272 +	movb	$0x80, %ch	
   5.273 +	movb	$0x87, %ah
   5.274 +	int	$0x15
   5.275 +	incb	0x14(%si)
   5.276 +	incb	0x1C(%si)
   5.277 +	decw	%bx
   5.278 +	jne	syslp
   5.279 +#endif
   5.280 +jmp_setup:
   5.281 +	cli
   5.282 +	ljmp	$SETUPSEG, $0
   5.283 +
   5.284 +#ifdef EXE_SUPPORT
   5.285 +#ifdef SHUTDOWNDOS
   5.286 +doiret:
   5.287 +	iret
   5.288 +step19:
   5.289 +	pushw	%si
   5.290 +	pushw	%ds
   5.291 +	movw	%sp, %si
   5.292 +	ldsw	%ss:4(%si), %si
   5.293 +	cmpw	$0x19CD, (%si)
   5.294 +	popw    %ds
   5.295 +	popw    %si
   5.296 +	jne	doiret
   5.297 +	xorw	%si, %si
   5.298 +	movw	%si, %ds
   5.299 +	pushw	%cs
   5.300 +	popw	%ss
   5.301 +	movw	$stacktop-4-16, %sp
   5.302 +#ifdef ONLY8086
   5.303 +	popw	4(%si)
   5.304 +	popw	4+2(%si)
   5.305 +skip_step19:
   5.306 +	popw	%bp
   5.307 +	popw	%di
   5.308 +	popw	%si
   5.309 +	popw	%dx
   5.310 +	popw	%cx
   5.311 +	popw	%bx
   5.312 +	popw	%ax
   5.313 +#else
   5.314 +	popl	4(%si)
   5.315 +skip_step19:
   5.316 +	popaw
   5.317 +#endif
   5.318 +#ifdef BZIMAGE
   5.319 +	jmp	movesys
   5.320 +#endif
   5.321 +#endif
   5.322 +#ifndef BZIMAGE
   5.323 +movesys:				// %ax = SYSSEG, %bx = DS, %si
   5.324 +	shrclw	$4, %si
   5.325 +	addw	%si, %bx
   5.326 +#ifdef TINY_ZIMAGE
   5.327 +	movw	$0xFFFF, %cx
   5.328 +	xorw	%si, %si
   5.329 +	xorw	%di, %di
   5.330 +	cmpw	%ax, %bx
   5.331 +	jnc	forward
   5.332 +	decw	%si
   5.333 +	decw	%di
   5.334 +	std
   5.335 +forward:
   5.336 +	movw	%ax, %es
   5.337 +	movw	%bx, %ds
   5.338 +	rep
   5.339 +	  movsb
   5.340 +	cld
   5.341 +#else
   5.342 +	subw	%ax, %bx
   5.343 +	jnc	forward
   5.344 +	//movw	$0x8FFF, %ax
   5.345 +	movb	$0x90, %ah
   5.346 +forward:
   5.347 +	movw	%ax, %es
   5.348 +	movw	%ax, %di
   5.349 +	addw	%bx, %di
   5.350 +	movw	%di, %ds
   5.351 +	sbbw	%di, %di		// %di = 0 : -1
   5.352 +	cmc				//  C  = 1 :  0
   5.353 +	adcw	%di, %ax
   5.354 +	xorw	%si, %si
   5.355 +	xorw	%di, %di
   5.356 +	movb	$0x10, %cl
   5.357 +	cmpb	%cl, %ah		// move 512k
   5.358 +	rep
   5.359 +	  movsb
   5.360 +	jns	forward
   5.361 +#endif
   5.362 +#ifndef NO_CURSOR_DEFINITION
   5.363 +	movb	$1, %ah
   5.364 +	movb	$0, %bh
   5.365 +	movb	$0x20, %ch	// 0x2000
   5.366 +	int	$0x10
   5.367 +#endif
   5.368 +	pushw	%ss
   5.369 +	popw	%ds
   5.370 +	jmp	jmp_setup
   5.371 +#endif
   5.372 +comstart:
   5.373 +	cld				# assume nothing
   5.374 +#ifdef ONLY8086
   5.375 +	movw	$INITSEG, %ax
   5.376 +	pushw	%ax
   5.377 +#else
   5.378 +	pushw	$INITSEG
   5.379 +#endif
   5.380 +	popw	%es
   5.381 +#ifdef CMDLINE
   5.382 +	movw	%sp, %di
   5.383 +	movw	$0x80, %si
   5.384 +	lodsb
   5.385 +	cbw
   5.386 +	xchgw	%ax, %cx
   5.387 +#ifdef BUGGY_CMDLINE
   5.388 +	test	%cl, %cl		# C=O=0, set S & Z
   5.389 +	jng	nocmdline		# Z == 1 or O != S ?
   5.390 +#else
   5.391 +	jcxz	nocmdline
   5.392 +#endif
   5.393 +# if defined(BZIMAGE) && BZIMAGE >= 0x202
   5.394 +	movw	$INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1)
   5.395 +# else
   5.396 +	movw	$0xA33F, 0x7F(%si)
   5.397 +# endif
   5.398 +# ifndef NO_CMDLINE_SHRINK
   5.399 +skipspace:
   5.400 +	lodsb
   5.401 +	cmpb	$0x20, %al
   5.402 +	je	skipspace
   5.403 +#  ifndef NO_CMDLINE_FILE
   5.404 +	movw	%si,%dx
   5.405 +	decw	%si
   5.406 +	subb	$'@',%al
   5.407 +	jne	notafile
   5.408 +	movb	$0x3D,%ah
   5.409 +	int	$0x21
   5.410 +	jc	notafile
   5.411 +	xchgw	%ax,%bx
   5.412 +	//movw	%si,%dx		// ~320 bytes max
   5.413 +	movw	$EXEADRS(notafile)-130,%cx
   5.414 +	movb	$0x3F,%ah
   5.415 +	int	$0x21
   5.416 +	xchgw	%ax,%cx
   5.417 +notafile:
   5.418 +#  else
   5.419 +	decw	%si
   5.420 +#  endif
   5.421 +# endif
   5.422 +	rep
   5.423 +	  movsb
   5.424 +nocmdline:
   5.425 +	orb	EXEADRS(setup_sects), %ch
   5.426 +# ifndef NO_MINSETUP
   5.427 +#  ifndef BZIMAGE
   5.428 +	jnz	setupok
   5.429 +	mov	$4, %ch
   5.430 +setupok:
   5.431 +#  endif
   5.432 +# endif
   5.433 +#else
   5.434 +	movb	EXEADRS(setup_sects), %ch
   5.435 +#endif
   5.436 +	movb	$(512-(end_header-_start))/2, %cl
   5.437 +	movw	$0x100, %si
   5.438 +	movw	$end_header, %di
   5.439 +	rep
   5.440 +	  movsw
   5.441 +	movw	$SYSSEG, %ax
   5.442 +	movw	%ds, %bx
   5.443 +	pushw	%es
   5.444 +	popw	%ss
   5.445 +#ifndef SHUTDOWNDOS
   5.446 +	pushw	%es
   5.447 +	pushw	$movesys
   5.448 +#endif
   5.449 +#ifdef VCPI
   5.450 +	pushaw
   5.451 +	smsww	%ax
   5.452 +	andb	$1, %al
   5.453 +	je	isrm
   5.454 +	movw	$EXEADRS(gdt_vcpi),%si
   5.455 +	movw	$pagebuf-0x90000,%di	// %es = 0x9000
   5.456 +	movl	$pagebuf+3,%es:0x1000(%di)
   5.457 +call_vcpi:
   5.458 +	movb	$0xDE,%ah	// DE01, EBX = getiface(DS:SI, ES:DI)
   5.459 +	int	$0x67
   5.460 +	movl	$FLAT20(sw2pm_params),%esi
   5.461 +	movb	$0x0C,%al	// DE0C switchpm(ESI)
   5.462 +	jmp	call_vcpi
   5.463 +pm_code:
   5.464 +	.byte	0x6A, SEL_DATA	// pushw	$SEL_DATA
   5.465 +	popw	%ss
   5.466 +	movl	%cr0,%eax
   5.467 +	andl	$0x7FFFFFFE,%eax
   5.468 +	movl	%eax,%cr0
   5.469 +	movl	%eax,%cr3
   5.470 +isrm:
   5.471 +# ifdef SHUTDOWNDOS
   5.472 +	trace_int19
   5.473 +# else
   5.474 +	popaw
   5.475 +	retf
   5.476 +# endif
   5.477 +#else
   5.478 +# ifdef SHUTDOWNDOS
   5.479 +#  ifdef ONLY8086
   5.480 +	pushw	%ax
   5.481 +	pushw	%bx
   5.482 +	pushw	%cx
   5.483 +	pushw	%dx
   5.484 +	pushw	%si
   5.485 +	pushw	%di
   5.486 +	pushw	%bp
   5.487 +#  else
   5.488 +	pushaw
   5.489 +#  endif
   5.490 +	trace_int19
   5.491 +# endif
   5.492 +	retf
   5.493 +#endif
   5.494 +#endif
   5.495 +
   5.496 +# read_sectors reads %di sectors into %es:0 buffer.
   5.497 +# %es:0 is updated to the next memory location.
   5.498 +# First, sectors are read sector by sector until
   5.499 +# sector per track count is known. Then they are
   5.500 +# read track by track.
   5.501 +# Assume no error on first track.
   5.502 +
   5.503 +#ifdef FLOPPY_1440K_ONLY
   5.504 +#ifndef FLOPPY_HAS_2_SIDES
   5.505 +#define FLOPPY_HAS_2_SIDES	hardcore heads count to 2
   5.506 +#endif
   5.507 +#define FLOPPY_SECTORS		18	/* 18 sectors */
   5.508 +#else
   5.509 +#define FLOPPY_HEADS		2	/* 2 heads minimum */
   5.510 +#endif
   5.511 +
   5.512 +return:
   5.513 +#ifndef NO_DOTS
   5.514 +	movw	$0xE2E,%ax
   5.515 +	int	$0x10
   5.516 +#endif
   5.517 +	ret
   5.518 +
   5.519 +check_limits:
   5.520 +#ifndef FLOPPY_1440K_ONLY
   5.521 +	popw	%dx
   5.522 +        cmpb    %al, %cl		# max sector known ?
   5.523 +        ja	next_head		#   no -> store it
   5.524 +#ifndef FLOPPY_HAS_2_SIDES
   5.525 +#ifdef FLOPPY_HEADS
   5.526 +	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   5.527 +	jb	check_cylinder
   5.528 +#endif
   5.529 +        cmpb    %ah, %dh		# max head known ?
   5.530 +        ja	next_cylinder		#   no -> store it
   5.531 +check_cylinder:
   5.532 +#endif
   5.533 +	pushw	%ax
   5.534 +	cbw				# %ah = 0
   5.535 +#else
   5.536 +	pushw	%dx
   5.537 +#endif
   5.538 +        int     $0x13			# reset controler
   5.539 +#ifndef FLOPPY_1440K_ONLY
   5.540 +	popw	%ax
   5.541 +	movb	$1, %al			# sector by sector...
   5.542 +#else
   5.543 +	movw	$1, %ax
   5.544 +	jmp	more1trk
   5.545 +#endif
   5.546 +read_sectorslp:
   5.547 +	pushw	%dx			# some bios break dx...
   5.548 +#ifndef FLOPPY_1440K_ONLY
   5.549 +        pushw   %ax			# limits
   5.550 +	subb	%cl, %al		# sectors remaining in track
   5.551 +	ja	tolastsect
   5.552 +	movb	$1, %al			# first track sector by sector
   5.553 +tolastsect:
   5.554 +#else
   5.555 +	movb	$FLOPPY_SECTORS+1, %al
   5.556 +	subb	%cl, %al		# sectors remaining in track
   5.557 +#endif
   5.558 +	cbw
   5.559 +	cmpw	%di, %ax
   5.560 +	jb	more1trk
   5.561 +	movw	%di, %ax		# sectors to read
   5.562 +more1trk:
   5.563 +	pushw	%ax			# save context
   5.564 +	movb	$2, %ah			# cmd: read chs
   5.565 +        int     $0x13
   5.566 +#ifndef FLOPPY_1440K_ONLY
   5.567 +	popw	%dx			# save %ax
   5.568 +        popw    %ax			# limits
   5.569 +#else
   5.570 +	popw	%ax			# restore context
   5.571 +	popw	%dx
   5.572 +#endif
   5.573 +	jc	check_limits
   5.574 +#ifndef FLOPPY_1440K_ONLY
   5.575 +	xchgw	%ax, %bp
   5.576 +	addw	%dx,%cx			# next sector
   5.577 +	movw	%cx, %si
   5.578 +	pushw	%dx
   5.579 +	shlclw	$5, %dx
   5.580 +	movw	%es, %cx
   5.581 +	addw	%dx, %cx
   5.582 +	popw	%dx
   5.583 +	subw	%dx,%di			# update sector counter
   5.584 +	popw	%dx
   5.585 +#else
   5.586 +	addw	%ax,%cx			# next sector
   5.587 +	movw	%cx, %si
   5.588 +	pushw	%ax
   5.589 +	shlclw	$5, %ax
   5.590 +	movw	%es, %cx
   5.591 +	addw	%ax, %cx
   5.592 +	popw	%ax
   5.593 +	subw	%ax,%di			# update sector counter
   5.594 +#endif
   5.595 +read_sectorsCX:
   5.596 +	movw	%cx, %es		# next location
   5.597 +	jz	return
   5.598 +read_sectors:
   5.599 +	movw	%si, %cx
   5.600 +#ifndef FLOPPY_1440K_ONLY
   5.601 +#   al is last sector+1
   5.602 +#   ah is last head+1
   5.603 +	xchgw	%ax, %bp
   5.604 +#endif
   5.605 +#ifndef FLOPPY_1440K_ONLY
   5.606 +        cmpb    %al,%cl			# reach sector limit ?
   5.607 +        jne     bdendlp
   5.608 +next_head:
   5.609 +        movb    %cl,%al
   5.610 +#else
   5.611 +        cmpb    $FLOPPY_SECTORS+1,%cl	# reach sector limit ?
   5.612 +        jne     bdendlp
   5.613 +#endif
   5.614 +        movb    $1,%cl			# first sector
   5.615 +#ifndef FLOPPY_HAS_2_SIDES
   5.616 +        incb    %dh			# next head
   5.617 +        cmpb    %ah, %dh		# reach head limit ?
   5.618 +        jne     bdendlp
   5.619 +next_cylinder:
   5.620 +        movb    %dh,%ah
   5.621 +        movb    $0,%dh			# first head
   5.622 +#else
   5.623 +        xorb    %cl,%dh			# next head
   5.624 +        jne	bdendlp			# reach head limit ?
   5.625 +#endif
   5.626 +# NOTE : support 256 cylinders max
   5.627 +        incb    %ch			# next cylinder
   5.628 +read_first_sectors:
   5.629 +bdendlp:
   5.630 +        jmp	read_sectorslp
   5.631 +
   5.632 +#ifdef VCPI
   5.633 +pagebuf		=	0x98000
   5.634 +tss		=	gdt_abs-40
   5.635 +gdt		=	gdt_abs-32
   5.636 +gdt_null	=	gdt_abs-32
   5.637 +gdt_vcpi	=	gdt_abs-24
   5.638 +gdt_vcpi2	=	gdt_abs-16
   5.639 +gdt_vcpi3	=	gdt_abs-8
   5.640 +gdt_abs:
   5.641 +SEL_DATA	= gdt_abs-gdt_null
   5.642 +	.word	0xFFFF
   5.643 +	.long	0x92000000
   5.644 +	.byte	0x8F,0
   5.645 +gdt_code:
   5.646 +	.word	0xFFFF
   5.647 +gdt_code_base:
   5.648 +	.long	0x9A000000+FLAT20(0)
   5.649 +	.byte	0x8F,0
   5.650 +gdt_tss:
   5.651 +	.word	0x00FF
   5.652 +gdt_tss_base:
   5.653 +	.long	0x89000000+FLAT20(tss)
   5.654 +	.byte	0,0
   5.655 +gdtr:
   5.656 +gdt_lim:
   5.657 +	.word	0xFFFF
   5.658 +gdt_base:
   5.659 +	.long	FLAT20(gdt)
   5.660 +sw2pm_params:
   5.661 +sw2pm_cr3:
   5.662 +	.long	pagebuf+0x1000
   5.663 +sw2pm_gdtr_ptr:
   5.664 +	.long	FLAT20(gdtr)
   5.665 +sw2pm_idtr_ptr:
   5.666 +	.long	FLAT20(idtr)
   5.667 +sw2pm_ldtr:
   5.668 +	.word	0
   5.669 +sw2pm_tr:
   5.670 +SEL_TSS		= gdt_tss-gdt_null
   5.671 +	.word	SEL_TSS
   5.672 +sw2pm_jumpaddr:
   5.673 +	.long	pm_code
   5.674 +SEL_CODE	= gdt_code-gdt_null
   5.675 +	.word	SEL_CODE
   5.676 +idtr:
   5.677 +idt_lim:
   5.678 +	.word	0x03FF
   5.679 +idt_base:
   5.680 +	.long	0
   5.681 +#endif
   5.682 +#ifdef ELKS
   5.683 +	.org	0x1E3
   5.684 +	.byte	13,10,7
   5.685 +	.asciz	"ELKS Boot"
   5.686 +#endif
   5.687 +	.org	0x1F1
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/memtest64/stuff/pack	Thu Feb 16 14:18:05 2023 +0000
     6.3 @@ -0,0 +1,101 @@
     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 +	x=$(grep -s setup_keep$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.18 +	if [ -n "$x" ]; then
    6.19 +		sed -i "s/XXXK2 //" $0 
    6.20 +	else
    6.21 +		x=$(grep -s setup_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.22 +		if [ -n "$x" ]; then
    6.23 +			sed -i "s/XXXK2/bs=500 skip=1/" $0
    6.24 +		else
    6.25 +			sed -i "s/XXXK2/bs=512 skip=1/" $0
    6.26 +		fi
    6.27 +	fi
    6.28 +	x=$(grep -s double_packed$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.29 +	[ -n "$x" ] && sed -i "s/| compress /&& 2 /" $0
    6.30 +	x=$(grep -s update_code32_start$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.31 +	[ -n "$x" ] && sed -i '/XXXU2/d; s| XXXU1||' $0 || sed -i '/XXXU1/d; s| XXXU2||' $0
    6.32 +	x=$(grep -s lzsa.block$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.33 +	[ -n "$x" ] && sed -i 's| XXXR||' $0 || sed -i 's| XXXR| -r|;s|tail -c +4|cat|' $0
    6.34 +	helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.35 +	helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    6.36 +	if [ -n "$helpmsg" ]; then
    6.37 +		sed -i "s/YYY/$((0x$helpmsg))/" $0
    6.38 +		sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0
    6.39 +	else
    6.40 +		sed -i '/YYY/d' $0
    6.41 +	fi
    6.42 +	cat >> $0 <<EOM
    6.43 +$(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -)
    6.44 +EOT
    6.45 +EOM
    6.46 +	sed -i '/--build/,/^fi/d' $0
    6.47 +	exit
    6.48 +fi
    6.49 +
    6.50 +store()
    6.51 +{
    6.52 +	n=$1
    6.53 +	for i in $(seq 1 ${4:-2}); do
    6.54 +		printf '\\\\x%02X' $(($n & 255))
    6.55 +		n=$(($n >> 8))
    6.56 +	done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
    6.57 +}
    6.58 +
    6.59 +bits()
    6.60 +{
    6.61 +	sed "/^#define PROP_$1/!d;s|.*PROP_...||" unlzma.S
    6.62 +}
    6.63 +
    6.64 +compress()
    6.65 +{
    6.66 +	case "$PACKER" in
    6.67 +	lz4) lz4 -l --best | tail -c +5 ;;
    6.68 +	lzsa1) cat > /tmp/in$$$1 ; lzsa XXXR -f1 /tmp/in$$$1 /tmp/out$$$1 ; tail -c +4 /tmp/out$$$1 ; rm -f /tmp/in$$$1 /tmp/out$$$1 ;;
    6.69 +	lzsa2) cat > /tmp/in$$$1 ; lzsa XXXR -f2 /tmp/in$$$1 /tmp/out$$$1 ; tail -c +4 /tmp/out$$$1 ; rm -f /tmp/in$$$1 /tmp/out$$$1 ;;
    6.70 +	*) xz -z -e --format=raw --lzma1=lc=$(bits LC),lp=$(bits LP),pb=$(bits PB) --stdout 
    6.71 +	esac
    6.72 +}
    6.73 +
    6.74 +main()
    6.75 +{
    6.76 +	uudecode | gunzip >$2
    6.77 +	dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
    6.78 +	setup="$(echo $(od -j 497 -N 1 -dAn $1))"
    6.79 +	[ $setup -eq 0 ] && setup=4
    6.80 +	store $setup $2 497 1
    6.81 +	setup=$((setup+1))
    6.82 +	store $setup $2 XXXSB 1
    6.83 +	store $setup $2 XXXSW 1
    6.84 +	store $((32*setup+0xF000)) $2 XXXSP
    6.85 +	store $((0x1000 - 32*setup)) $2 XXXSS 
    6.86 +	cp $1 /tmp/un$$ XXXU1
    6.87 +	store 1 /tmp/un$$ 534 1 XXXU1
    6.88 +	dd if=/tmp/un$$ XXXK2 | compress >>$2 XXXU1
    6.89 +	rm -f /tmp/un$$ XXXU1
    6.90 +	dd if=$1 XXXK2 | compress >>$2 XXXU2
    6.91 +	size=$(stat -c %s $2)
    6.92 +	syssize=$(((size-512*setup+15)/16))
    6.93 +	store $((syssize + 0x1000 + 0x1000)) $2 XXXP
    6.94 +	store $syssize $2 500
    6.95 +	store $(((size+511)/512)) $2 4
    6.96 +	store $(((size+15)/16)) $2 14
    6.97 +	echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
    6.98 +}
    6.99 +
   6.100 +HELP="$(unix2dos <<EOT
   6.101 +Memtest86+ VERSION GPLv2
   6.102 +EOT
   6.103 +)"
   6.104 +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/memtest64/stuff/unlz4.S	Thu Feb 16 14:18:05 2023 +0000
     7.3 @@ -0,0 +1,132 @@
     7.4 +// Lz4Decode:
     7.5 +#ifndef FLAT32
     7.6 +//   input   ds:si=inStream, es:di=outStream
     7.7 +//   output  outStream[], ds:si, es:di
     7.8 +	.code16
     7.9 +#define AX	%ax
    7.10 +#define BX	%bx
    7.11 +#define CX	%cx
    7.12 +#define SI	%si
    7.13 +#define DI	%di
    7.14 +#else
    7.15 +//   input   esi=inStream, edi=outStream
    7.16 +//   output  outStream[], ds:esi, es:edi
    7.17 +	.code32
    7.18 +#define AX	%eax
    7.19 +#define BX	%ebx
    7.20 +#define CX	%ecx
    7.21 +#define SI	%esi
    7.22 +#define DI	%edi
    7.23 +#endif
    7.24 + 
    7.25 +#define ARCHIVE_MAGICNUMBER 0x184C2102
    7.26 +
    7.27 +//#define PARANOIA			// cover rare cases, optional
    7.28 +
    7.29 +lz4main:
    7.30 +#ifdef PARANOIA
    7.31 +	cld
    7.32 +# if !defined(FLAT32) && !defined(FLAT16OUT)
    7.33 +	xorl	%cx, %cx
    7.34 +	call	lz4mov
    7.35 +# endif
    7.36 +#endif
    7.37 +	lodsl			// get chunkSize
    7.38 +#ifndef NO_LZ4_HEADER
    7.39 +	cmpl	$ARCHIVE_MAGICNUMBER, %eax
    7.40 +	je	lz4main
    7.41 +#endif
    7.42 +	orl	%eax, %eax	// end of file ?
    7.43 +	je	lz4quit
    7.44 +	xchgl	%eax, %edx
    7.45 +lz4chunk:			// uncompress chunk
    7.46 +	lodsb			// get token
    7.47 +	movb	%al, %bl
    7.48 +	shrb	$4, %al
    7.49 +	call	lz4len		// get literal length
    7.50 +	subl	%ecx, %edx	// count literal
    7.51 +#if !defined(FLAT32) && !defined(FLAT16OUT) && (!defined(FLAT16) || !defined(PARANOIA))
    7.52 +#define NeedLz4mov
    7.53 +	call	lz4mov		// copy literals
    7.54 +#else
    7.55 +	rep movsb
    7.56 +#endif
    7.57 +	subl	$1+2, %edx	// count token & string address
    7.58 +	jle	lz4main
    7.59 +	lodsw			// get string address
    7.60 +	xchg	AX, BX
    7.61 +	call	lz4len		// get string length
    7.62 +	add	$4, CX
    7.63 +#if !defined(FLAT32) && !defined(FLAT16OUT)
    7.64 +	pushw	%ds
    7.65 +	pushw	%si
    7.66 +	movw	%di, %si
    7.67 +	subw	%bx, %si
    7.68 +	movw	%es, %ax
    7.69 +	jnc	axok
    7.70 +	subb	$0x10, %ah
    7.71 +axok:
    7.72 +.macro norm	reg
    7.73 +	movw	%si, \reg
    7.74 +	andw	$0xF, %si
    7.75 +	shrw	$4, \reg
    7.76 +	addw	\reg, %ax
    7.77 +	movw	%ax, %ds
    7.78 +	movw	%di, \reg
    7.79 +	andw	$0xF, %di
    7.80 +	shrw	$4, \reg
    7.81 +	movw	%es, %ax
    7.82 +	addw	\reg, %ax
    7.83 +	movw	%ax, %es
    7.84 +.endm 
    7.85 +# if !defined (NeedLz4mov)
    7.86 +	norm	%bp
    7.87 +	rep movsb
    7.88 +# else
    7.89 +	call	lz4movStr	// copy string
    7.90 +# endif
    7.91 +	popw	%si
    7.92 +	popw	%ds
    7.93 +#else
    7.94 +	xchg	AX, SI
    7.95 +	mov	DI, SI
    7.96 +	sub	BX, SI
    7.97 +	rep movsb %es:(SI), %es:(DI)
    7.98 +	xchg	AX, SI
    7.99 +#endif
   7.100 +	jmp	lz4chunk
   7.101 +
   7.102 +#if defined(NeedLz4mov)
   7.103 +# if defined(PARANOIA)
   7.104 +lz4movlp:
   7.105 +	xchgw	%ax, %cx
   7.106 +	movw	$0x3C00, %cx
   7.107 +	rep movsl
   7.108 +	xchgw	%ax, %cx
   7.109 +	sub	$0xF0, %ch
   7.110 +# endif
   7.111 +lz4mov:
   7.112 +	movw	%ds, %ax
   7.113 +lz4movStr:
   7.114 +	norm	%bp
   7.115 +# if defined(PARANOIA)
   7.116 +	cmp	$0xFF, %ch	// catch FFFX case
   7.117 +	jz	lz4movlp
   7.118 +# endif
   7.119 +	rep movsb
   7.120 +	ret
   7.121 +#endif
   7.122 +
   7.123 +lz4len:				// get length in %ecx
   7.124 +	andl	$0xF, %eax
   7.125 +	movl	%eax, %ecx
   7.126 +	cmpb	$0xF, %al
   7.127 +	jne	lz4quit
   7.128 +lz4len2:
   7.129 +	lodsb
   7.130 +	decl	%edx		// remaining chunk size
   7.131 +	addw	%ax, %cx
   7.132 +	cmpb	$0xFF, %al
   7.133 +	je	lz4len2
   7.134 +lz4quit:
   7.135 +	ret
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/memtest64/stuff/unlzma.S	Thu Feb 16 14:18:05 2023 +0000
     8.3 @@ -0,0 +1,1028 @@
     8.4 +// #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
     8.5 +//
     8.6 +// #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
     8.7 +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
     8.8 +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
     8.9 +//
    8.10 +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
    8.11 +//  { UpdateBit0(p); mi <<= 1; A0; } else \
    8.12 +//  { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
    8.13 +//
    8.14 +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
    8.15 +//
    8.16 +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \
    8.17 +//  { int i = numLevels; res = 1; \
    8.18 +//  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
    8.19 +//  res -= (1 << numLevels); }
    8.20 +/*
    8.21 + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3
    8.22 + */
    8.23 +
    8.24 +#define PROP_PB 2
    8.25 +#define PROP_LP 0
    8.26 +#define PROP_LC 3
    8.27 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45))
    8.28 +
    8.29 +// static const Byte *Buffer;
    8.30 +// static UInt32 bound, Code, Range;
    8.31 +
    8.32 +/*
    8.33 + * Buffer register DS:SI
    8.34 + * all var based ws=ss:bp
    8.35 + */
    8.36 +
    8.37 +rep0		=	-4		// long
    8.38 +rep1		=	rep0-4		// long
    8.39 +rep2		=	rep0-8		// long
    8.40 +rep3		=	rep0-12		// long
    8.41 +state		=	-17		// byte, 0..11
    8.42 +posState 	=	state-1		// byte, 0..15
    8.43 +posState2 	=	posState-1	// byte, 0..15
    8.44 +scratched	=	rep0-16		// byte = 1
    8.45 +Code		=	-24		// long
    8.46 +outStream	=	-28		// long
    8.47 +nowPos		=	outStream	// long
    8.48 +Range		=	Code-8		// long
    8.49 +#define LOCALS		32
    8.50 +
    8.51 +// int LzmaDecode(CLzmaDecoderState *vs,
    8.52 +//     const unsigned char *inStream, 
    8.53 +//     unsigned char *outStream)
    8.54 +// {
    8.55 +//   CProb *p = vs->Probs;
    8.56 +//   SizeT nowPos = 0;
    8.57 +//   #define posStateMask = (1 << (vs->Properties.pb)) - 1;
    8.58 +//   #define literalPosMask = (1 << (vs->Properties.lp)) - 1;
    8.59 +//   int lc = vs->Properties.lc, state = 0, len = 0;
    8.60 +//   UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
    8.61 +// 
    8.62 +//   {
    8.63 +//     UInt32 i, numProbs = Literal /*1846*/
    8.64 +// 	    + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp));
    8.65 +//     for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1;
    8.66 +
    8.67 +#define WS (1846+(768<<(PROP_LC+PROP_LP)))
    8.68 +#if (WS+WS+LOCALS) >= 65000
    8.69 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */
    8.70 +#error invalid (lc,lp,pb) : out of memory
    8.71 +#endif
    8.72 +
    8.73 +ws1	=	WS
    8.74 +ws2	=	ws1*2
    8.75 +ws	=	ws2+LOCALS+15
    8.76 +
    8.77 +#ifndef FLAT32
    8.78 +#define	AX	%ax
    8.79 +#define	BX	%bx
    8.80 +#define	CX	%cx
    8.81 +#define	DX	%dx
    8.82 +#define	SI	%si
    8.83 +#define	DI	%di
    8.84 +#define	BP	%bp
    8.85 +#define	SP	%sp
    8.86 +#define CWD	cwd
    8.87 +#else
    8.88 +#define	AX	%eax
    8.89 +#define	BX	%ebx
    8.90 +#define	CX	%ecx
    8.91 +#define	DX	%edx
    8.92 +#define	SI	%esi
    8.93 +#define	DI	%edi
    8.94 +#define	BP	%ebp
    8.95 +#define	SP	%esp
    8.96 +#define CWD	cdq
    8.97 +#endif
    8.98 +/*
    8.99 + * LzmaDecode:
   8.100 +#ifndef FLAT32
   8.101 + *   input   ds:si=inStream, es:di=outStream
   8.102 + *   output  outStream[], ds:si, es:di
   8.103 + 	.code 16
   8.104 +#else
   8.105 + *   input   esi=inStream, edi=outStream
   8.106 + *   output  outStream[], esi, edi
   8.107 + 	.code 32
   8.108 +#endif
   8.109 + */
   8.110 + 
   8.111 +	mov	$ws1, CX
   8.112 +#ifdef ONLY8086
   8.113 +	.arch	i8086
   8.114 +	movw	$2048/2, %ax
   8.115 +lzd1:
   8.116 +	pushw	%ax
   8.117 +#else
   8.118 +lzd1:
   8.119 +	pushw	$2048/2
   8.120 +#endif
   8.121 +	loop	lzd1
   8.122 +	mov	SP, BP
   8.123 +	movb	$((LOCALS+3)/4)*2, %cl
   8.124 +#ifdef ONLY8086
   8.125 +	movw	$1, %ax
   8.126 +	cwd
   8.127 +initlocals:
   8.128 +	pushw	%dx
   8.129 +	pushw	%ax
   8.130 +#else
   8.131 +initlocals:
   8.132 +	pushl	$1
   8.133 +#endif
   8.134 +	loop	initlocals
   8.135 +
   8.136 +#if !defined(FLAT32) && !defined(FLAT16OUT)
   8.137 +	movb	$4, %cl
   8.138 +	movw	%es, %bx
   8.139 +	shrw	%cl, %bx
   8.140 +	movw	%es, %dx
   8.141 +	shlw	%cl, %dx
   8.142 +	addw	%dx, %di
   8.143 +	movw	%di, outStream(%bp)
   8.144 +	adcb	%bh, outStream+2(%bp)
   8.145 +	incw	%cx
   8.146 +#else
   8.147 +	movb	$5, %cl
   8.148 +	mov	DI, outStream(BP)
   8.149 +#endif
   8.150 +
   8.151 +//   Byte previousByte = 0;
   8.152 +	xor	BX, BX
   8.153 +
   8.154 +// #define RC_INIT(buffer) 
   8.155 +//    Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; 
   8.156 +//    { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }}
   8.157 +//   }
   8.158 +//   RC_INIT(inStream);
   8.159 +
   8.160 +#ifndef NO_LZMA_HEADER
   8.161 +#ifdef CHECK_LZMA_HEADER
   8.162 +	cmp.w	$0x5A4C, (SI)	// lzip header ('LZIP' version:1 dicobits:1)
   8.163 +	je	lzip_header
   8.164 +	cmp.w	$0x5D, (SI)	// lzma header (0x5D dicosz:4 orgsz:8)
   8.165 +	jne	no_header
   8.166 +	add	$13-6, SI	// skip lzma header
   8.167 +lzip_header:
   8.168 +	add	$6, SI		// skip lzip header
   8.169 +no_header:
   8.170 +#else
   8.171 +	add	$13, SI		// skip lzma header (0x5D dicosz:4 orgsz:8)
   8.172 +#endif
   8.173 +#endif
   8.174 +setrep:
   8.175 +	call	RC_LOAD_BYTE
   8.176 +	decb	Range(BP)
   8.177 +	loop	setrep
   8.178 +
   8.179 +lzdmainlp:
   8.180 +//   while(1) {
   8.181 +//     CProb *prob;
   8.182 +//     int posState = (int)((nowPos) & posStateMask);
   8.183 +// 
   8.184 +//     prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState;
   8.185 +//     if (Bit0(prob)) { /* char */
   8.186 +
   8.187 +	xor	DX, DX
   8.188 +	call	Bit1state	// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
   8.189 +	mov	$state, DI
   8.190 +	jc	lzdstring
   8.191 +
   8.192 +//       prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * 
   8.193 +// 	((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc))));
   8.194 +
   8.195 +#if PROP_LC != 0
   8.196 +# ifdef ONLY8086
   8.197 +	movb	$8-PROP_LC, %cl
   8.198 +	shrb	%cl, %bl
   8.199 +# else
   8.200 +	shrb	$8-PROP_LC, %bl
   8.201 +# endif
   8.202 +#else
   8.203 +	xor	%bx,%bx
   8.204 +#endif
   8.205 +
   8.206 +#if PROP_LP != 0
   8.207 +	movb	posState2(BP), %dl
   8.208 +# if PROP_LC != 0
   8.209 +#  ifdef ONLY8086
   8.210 +	movb	$PROP_LC, %cl
   8.211 +	shl	%cl, DX
   8.212 +#  else
   8.213 +	shl	$PROP_LC, DX
   8.214 +#  endif
   8.215 +	movb	$0, %bh
   8.216 +# endif
   8.217 +	add	BX, DX
   8.218 +#endif
   8.219 +
   8.220 +#if PROP_LC == 0 && PROP_LP == 0
   8.221 +	mov	$1846, AX
   8.222 +#else
   8.223 +	movb	$3, %ah
   8.224 +	mul	BX		// dx = 3*bh
   8.225 +	add	$1846, AX
   8.226 +#endif
   8.227 +
   8.228 +//       int symbol = 1;
   8.229 +
   8.230 +	CWD
   8.231 +	inc	DX		// symbol = 1
   8.232 +	xchg	AX, CX		// save prob
   8.233 +
   8.234 +//       if (state >= kNumLitStates /*7*/) { /* previous was string */
   8.235 +//       if (state < 4) state = 0;
   8.236 +
   8.237 +lzd6z:
   8.238 +	subb	$3, (BP, DI)
   8.239 +
   8.240 +//       if (state < 4) state = 0;
   8.241 +
   8.242 +	jnc	lzd6
   8.243 +	movb	%dh, (BP, DI)	// %dh = 0
   8.244 +
   8.245 +lzd6:
   8.246 +//       else if (state < 10) state -= 3;
   8.247 +
   8.248 +	cmpb	$10-3, (BP, DI)
   8.249 +	
   8.250 +//       else state -= 6;
   8.251 +
   8.252 +	jnb	lzd6z
   8.253 +	cmpb	$7-3-1, (BP, DI)
   8.254 +	jbe	lzd3
   8.255 +	
   8.256 +//         int matchByte = outStream[nowPos - rep0];
   8.257 +
   8.258 +	call	DicoRep02ESDI	// %bl = outStream[nowPos - rep0];
   8.259 +	
   8.260 +//         do {
   8.261 +//           int bit;
   8.262 +//           CProb *probLit;
   8.263 +//           matchByte <<= 1; bit = (matchByte & 0x100);
   8.264 +
   8.265 +	movb	$1, %bh
   8.266 +lzd4:
   8.267 +	shlb	$1, %bl			// matchByte <<= 1
   8.268 +	sbb	DI, DI			// save bit=C
   8.269 +
   8.270 +//           probLit = prob + 0x100 + bit + symbol;
   8.271 +
   8.272 +	mov	CX, AX			// restore prob
   8.273 +	adcb	%bh, %ah		// + bit + 0x100
   8.274 +	
   8.275 +//           RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break)
   8.276 +
   8.277 +	call	Bit1axdx		// C,%ax = Bit1(prob+%ax)
   8.278 +	rclb	$1, %dl			// symbol <<= 1; symbol |= C
   8.279 +	jc	lzd5			// if symbol >= 0x100
   8.280 +	cmp	DI, AX
   8.281 +	jz	lzd4			// if bit == Bit1(prob+%ax)
   8.282 +
   8.283 +//         } while (symbol < 0x100);
   8.284 +//       }
   8.285 +lzd3:
   8.286 +//       while (symbol < 0x100) {
   8.287 +//         CProb *probLit = prob + symbol;
   8.288 +//         RC_GET_BIT(probLit, symbol)
   8.289 +//       }
   8.290 +
   8.291 +	xor	BX, BX
   8.292 +	jmp	lzd4
   8.293 +lzd5:
   8.294 +
   8.295 +//       outStream[nowPos++] = previousByte = (Byte)symbol;
   8.296 +
   8.297 +	xchg	AX, DX
   8.298 +	call	outchar		// %bl = outStream[nowPos++] = %al;
   8.299 +	jmp	lzdmainlp
   8.300 +
   8.301 +//     }
   8.302 +
   8.303 +lzdstring:
   8.304 +	mov	$1, CX
   8.305 +
   8.306 +//     else { /* string */
   8.307 +//       prob = p + IsRep /*192*/ + state;
   8.308 +
   8.309 +	movb	$192, %dl
   8.310 +	addb	(BP, DI), %dl
   8.311 +	mov	$rep0, DI
   8.312 +
   8.313 +//       if (Bit0(prob)) {
   8.314 +
   8.315 +	call	Bit1dx		// Bit1(prob)
   8.316 + 	jc	lzd8
   8.317 +
   8.318 +//         rep3 = rep2; rep2 = rep1; rep1 = rep0;
   8.319 +//         state = (state < kNumLitStates /*7*/) ? 0 : 3;
   8.320 +
   8.321 +	stc
   8.322 +
   8.323 +//         prob = p + LenCoder /*818*/;
   8.324 +
   8.325 +	mov	$818, DX
   8.326 +
   8.327 +//       }
   8.328 +
   8.329 +	jmp	lzd11a
   8.330 +
   8.331 +//       else {
   8.332 +lzd8:
   8.333 +//         prob += kNumStates /*12*/;
   8.334 +//         if (Bit0(prob)) {
   8.335 +	call	Bit1dx12	// prob += 12; Bit1(prob)
   8.336 +	jc	lzd11
   8.337 +//           prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) 
   8.338 +// 		   + posState;
   8.339 +	movb	$240, %dl	// dh=0
   8.340 +
   8.341 +//           if (Bit0(prob)) {
   8.342 +
   8.343 +	call	Bit1state	// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
   8.344 +	jc	lzd12
   8.345 +
   8.346 +//             // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR;
   8.347 +//             state = (state < kNumLitStates /*7*/) ? 9 : 11;
   8.348 +
   8.349 +	movb	$9, %dl
   8.350 +
   8.351 +//             len++; goto string;
   8.352 +	jmp	lzd13string	// ax = 0
   8.353 +//           }
   8.354 +//         }
   8.355 +//         else {
   8.356 +lzd11:
   8.357 +//           UInt32 distance = rep1;
   8.358 +//           prob += kNumStates /*12*/;
   8.359 +//           if (!Bit0(prob)) {
   8.360 +
   8.361 +	call	Bit1dx12	// prob += 12; Bit1(prob)
   8.362 +	jnc	lzd11z
   8.363 +
   8.364 +//             prob += kNumStates /*12*/;
   8.365 +//             if (Bit0(prob)) distance = rep2;
   8.366 +
   8.367 +	call	Bit1dx12	// prob += 12; Bit1(prob)
   8.368 +lzd11a:
   8.369 +	adcb	%cl, %cl
   8.370 +	
   8.371 +//             else { distance = rep3; rep3 = rep2; }
   8.372 +//             rep2 = rep1;
   8.373 +//           }
   8.374 +//           rep1 = rep0; rep0 = distance;
   8.375 +
   8.376 +lzd11z:
   8.377 +# ifdef ONLY8086
   8.378 +	shl	$1, CX
   8.379 +	shl	$1, CX		// 8->32 bits
   8.380 +	sub	CX, DI		// &rep[cx]
   8.381 +	movw	(BP, DI), %ax
   8.382 +	pushw	2(BP, DI)
   8.383 +rotreplp:
   8.384 +	movb	4(BP, DI), %bl
   8.385 +	movb	%bl, (BP, DI)
   8.386 +	inc	DI
   8.387 +	loop	rotreplp
   8.388 +	popw	%bx
   8.389 +	testb	%dh, %dh
   8.390 +	jnz	lzd10
   8.391 +	movw	%ax, (BP, DI)
   8.392 +	movw	%bx, 2(BP, DI)
   8.393 +# else
   8.394 +	shl	$2, CX		// 8->32 bits
   8.395 +	sub	CX, DI		// &rep[cx]
   8.396 +	movl	(BP, DI), %eax
   8.397 +rotreplp:
   8.398 +	movb	4(BP, DI), %bl
   8.399 +	movb	%bl, (BP, DI)
   8.400 +	inc	DI
   8.401 +	loop	rotreplp
   8.402 +	testb	%dh, %dh
   8.403 +	jnz	lzd10
   8.404 +	movl	%eax, (BP, DI)
   8.405 +# endif
   8.406 +
   8.407 +//         }
   8.408 +lzd12:
   8.409 +//         state = (state < kNumLitStates /*7*/) ? 8 : 11;
   8.410 +
   8.411 +	movb	$0x08, %cl
   8.412 +
   8.413 +//         prob = p + RepLenCoder /*1332*/;
   8.414 +
   8.415 +	mov	$1332, DX
   8.416 +
   8.417 +//       }
   8.418 +lzd10:
   8.419 +	push	CX		// CX = 0
   8.420 +
   8.421 +//       { /* get len */
   8.422 +//         int numBits, offset;
   8.423 +//         CProb *probLen = prob + LenChoice /*0*/;
   8.424 +//         numBits = kLenNumLowBits /*3*/;
   8.425 +
   8.426 +	movb	$8, %cl		// numBits : 3,3,8
   8.427 +
   8.428 +//         if (Bit0(probLen)) {
   8.429 +
   8.430 +	call	Bit1dx		// Bit1(prob)
   8.431 +	xchg	AX, BX
   8.432 +	inc	DX
   8.433 +	jnc	lzd15		// bx=0
   8.434 +
   8.435 +//           probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/);
   8.436 +//           offset = 0;
   8.437 +//         }
   8.438 +//         else {
   8.439 +//           probLen = prob + LenChoice2 /*1*/;
   8.440 +
   8.441 +	call	Bit1dx		// Bit1(prob)
   8.442 +	add	AX, BX
   8.443 +
   8.444 +#if PROP_PB != 0
   8.445 +	inc	AX		// ah=0
   8.446 +#endif
   8.447 +	jc	lzd16		// %ax=0, %bx=-2 
   8.448 +lzd15:
   8.449 +#if PROP_PB != 0
   8.450 +	movb	$8, %al
   8.451 +	mulb	posState(BP)
   8.452 +#endif
   8.453 +
   8.454 +//           if (Bit0(probLen)) {
   8.455 +//             probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/);
   8.456 +
   8.457 +	movb	$3, %cl		// numBits : 3,3,8
   8.458 +lzd16:
   8.459 +#if PROP_PB != 0
   8.460 +	add	$2-128-1, AX	// probLen : 2,130,258
   8.461 +#else
   8.462 +	mov	$2-128-1, AX	// probLen : 2,130,258
   8.463 +#endif
   8.464 +	add	DX, AX
   8.465 +	mov	$-8+1, DX	// offset  : 0,8,16
   8.466 +lzdargslp:
   8.467 +	add	$8, DX
   8.468 +	add	$128, AX
   8.469 +	inc	BX
   8.470 +	jle	lzdargslp	// leave with bx=1
   8.471 +
   8.472 +//             offset = kLenNumLowSymbols /*8*/;
   8.473 +//             //numBits = kLenNumMidBits /*3*/;
   8.474 +//           }
   8.475 +//           else {
   8.476 +//             probLen = prob + LenHigh /*258*/;
   8.477 +//             offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/;
   8.478 +//             numBits = kLenNumHighBits /*8*/;
   8.479 +//           }
   8.480 +//         }
   8.481 +//         RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset;
   8.482 +
   8.483 +	push	DX
   8.484 +	call	RangeDecoder	// %ax=probs, %cx=numLevels, %ax=res
   8.485 +	pop	DX
   8.486 +	add	DX, AX		// offset
   8.487 +	pop	DX		// 0
   8.488 +lzd13string:
   8.489 +	push	AX
   8.490 +
   8.491 +// state = (state < kNumLitStates /*7*/) ? dl : dl|3;
   8.492 +
   8.493 +	movb	$7, %cl
   8.494 +	cmpb	%cl, state(BP)
   8.495 +	jb	new_state
   8.496 +	orb	$3, %dl
   8.497 +new_state:
   8.498 +	movb	%dl, state(BP)
   8.499 +
   8.500 +//       } /* get len */
   8.501 +//       if (state < 4) {
   8.502 +
   8.503 +	cmpb	$4-1, %dl
   8.504 +	ja	lzd19
   8.505 +
   8.506 +//         int posSlot;
   8.507 +//         state += kNumLitStates /*7*/;
   8.508 +
   8.509 +	addb	%cl, state(BP)
   8.510 +
   8.511 +//         prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? 
   8.512 +// 		len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/);
   8.513 +
   8.514 +	cmp	$4+1, AX
   8.515 +	jb	lzd21
   8.516 +	mov	$3+1, AX
   8.517 +
   8.518 +lzd21:
   8.519 +
   8.520 +	dec	CX		// cx = 6
   8.521 +	shl	%cl, AX
   8.522 +	add	$432-64, AX
   8.523 +
   8.524 +//         RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot);
   8.525 +
   8.526 +	call	RangeDecoder	// %ax=probs, %cx=numLevels, %ax=res
   8.527 +
   8.528 +//         if (posSlot >= kStartPosModelIndex /*4*/) {
   8.529 +//           int numDirectBits = ((posSlot >> 1) - 1);
   8.530 +
   8.531 +#ifndef FLAT32
   8.532 +	movw	%cx, 2(%bp, %di)	// %cx = 0
   8.533 +#endif
   8.534 +	mov	AX, (BP, DI)
   8.535 +	mov	AX, CX
   8.536 +	shrw	$1, CX
   8.537 +	dec	CX
   8.538 +	cmpb	$4, %al
   8.539 +	jb	lzd22
   8.540 +
   8.541 +//           rep0 = (2 | ((UInt32)posSlot & 1));
   8.542 +
   8.543 +	andb	%bl, (BP, DI)		// %bx=1
   8.544 +	orb	$2, (BP, DI)
   8.545 +
   8.546 +//           if (posSlot < kEndPosModelIndex /*14*/) {
   8.547 +
   8.548 +	cmpb	$14, %al
   8.549 +	jnb	lzd23
   8.550 +
   8.551 +//             rep0 <<= numDirectBits;
   8.552 +
   8.553 +	neg	AX
   8.554 +# ifdef ONLY8086
   8.555 +	pushw	%cx
   8.556 +	movb	$0, %ch
   8.557 +shllrep0:
   8.558 +	shlw	$1, (BP, DI)
   8.559 +	rclw	$1, 2(BP, DI)
   8.560 +	loop	shllrep0
   8.561 +	popw	%cx
   8.562 +# else
   8.563 +	shll	%cl, (BP, DI)
   8.564 +# endif
   8.565 +	add	(BP, DI), AX
   8.566 +
   8.567 +//             prob = p + SpecPos /*688*/ + rep0 - posSlot - 1;
   8.568 +
   8.569 +	add	$687, AX
   8.570 +	jmp	lzd24
   8.571 +
   8.572 +//           }
   8.573 +//           else {
   8.574 +lzd23:
   8.575 +//             numDirectBits -= kNumAlignBits /*4*/;
   8.576 +//             do {
   8.577 +//               RC_NORMALIZE; Range >>= 1; rep0 <<= 1;
   8.578 +//               if (Code >= Range) { Code -= Range; rep0 |= 1; }
   8.579 +
   8.580 +lzd23z:
   8.581 +	call	RC_NORMALIZE
   8.582 +# ifdef ONLY8086
   8.583 +	pushw	%dx
   8.584 +	shrw	$1, Range+2(BP)
   8.585 +	rcrw	$1, Range(BP)
   8.586 +	movw	Range(BP), %ax
   8.587 +	movw	Range+2(BP), %dx
   8.588 +	cmpw	Code+2(BP), %dx
   8.589 +	ja	lzd25
   8.590 +	jb	lzd25x
   8.591 +	cmpw	Code(BP), %ax
   8.592 +	ja	lzd25
   8.593 +lzd25x:
   8.594 +	subw	%ax, Code(BP)
   8.595 +	sbbw	%dx, Code+2(BP)
   8.596 +	stc
   8.597 +lzd25:
   8.598 +	popw	%dx
   8.599 +	rclw	$1, (BP, DI)
   8.600 +	rclw	$1, 2(BP, DI)
   8.601 +# else
   8.602 +	shrl	$1, Range(BP)
   8.603 +	movl	Range(BP), %eax
   8.604 +	cmpl	Code(BP), %eax
   8.605 +	ja	lzd25
   8.606 +	subl	%eax, Code(BP)
   8.607 +	stc
   8.608 +lzd25:
   8.609 +	rcll	$1, (BP, DI)
   8.610 +# endif
   8.611 +
   8.612 +//             } while (--numDirectBits != 0);
   8.613 +
   8.614 +	cmpb	$4+1, %cl
   8.615 +	loopne	lzd23z
   8.616 +
   8.617 +//             prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/;
   8.618 +//             rep0 <<= numDirectBits;
   8.619 +
   8.620 +# ifdef ONLY8086
   8.621 +	pushw	%cx
   8.622 +	movb	$0, %ch
   8.623 +shlrep0:
   8.624 +	shlw	$1, (BP, DI)
   8.625 +	rclw	$1, 2(BP, DI)
   8.626 +	loop	shlrep0
   8.627 +	popw	%cx
   8.628 +# else
   8.629 +	shll	%cl, (BP, DI)
   8.630 +# endif
   8.631 +	mov	$802, AX
   8.632 +//           }
   8.633 +
   8.634 +lzd24:
   8.635 +	call	RangeDecoder	// %ax=probs, %cx=numLevels, %ax=res
   8.636 +
   8.637 +//           {
   8.638 +//             int i = 1, mi = 1;
   8.639 +//             do {
   8.640 +//               CProb *prob3 = prob + mi;
   8.641 +//               RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
   8.642 +
   8.643 +	orb	%dh, (BP, DI)	// update rep0 with DirectBits
   8.644 +
   8.645 +//               i <<= 1;
   8.646 +//             } while(--numDirectBits != 0);
   8.647 +//           }
   8.648 +//         } else rep0 = posSlot;
   8.649 +lzd22:
   8.650 +//         if (++rep0 == (UInt32)(0)) break; /* EOF */
   8.651 +
   8.652 +# ifdef ONLY8086
   8.653 +	incw	(BP, DI)
   8.654 +	jnz	lzd19
   8.655 +	incw	2(BP, DI)
   8.656 +# else
   8.657 +	incl	(BP, DI)
   8.658 +# endif
   8.659 +
   8.660 +lzd19:
   8.661 +	pop	CX
   8.662 +	jz	lzdone
   8.663 +
   8.664 +//       }
   8.665 +//       len += kMatchMinLen;/*2*/
   8.666 +
   8.667 +	inc	CX
   8.668 +
   8.669 +//     string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR;
   8.670 +//       do {
   8.671 +lzd13z:
   8.672 +//         previousByte = outStream[nowPos - rep0];
   8.673 +//         outStream[nowPos++] = previousByte;
   8.674 +
   8.675 +	call	outcharDico 	// %bl = outStream[nowPos++] = outStream[nowPos - rep0]
   8.676 +
   8.677 +//       } while(--len != 0);
   8.678 +
   8.679 +	loop	lzd13z
   8.680 +
   8.681 +//     } /* char/string */
   8.682 +//   }
   8.683 +
   8.684 +	jmp	lzdmainlp
   8.685 +
   8.686 +lzdone:
   8.687 +//   //RC_NORMALIZE;
   8.688 +//   //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos;
   8.689 +//   return LZMA_RESULT_OK;
   8.690 +	call	Dico2ESDI	// set es & di (rep0 = 0)
   8.691 +	lea	ws2(BP), SP	// dealloc
   8.692 +	ret	
   8.693 +// }
   8.694 +
   8.695 +// al = outStream[nowPos - rep0];
   8.696 +
   8.697 +/*
   8.698 + * output  es:di, al
   8.699 + * scratch bh, cl, flags
   8.700 + */
   8.701 +
   8.702 +DicoRep02ESDI:
   8.703 +	stc
   8.704 +
   8.705 +// bl = outStream[nowPos];
   8.706 +
   8.707 +/*
   8.708 + * output  es:di, bl
   8.709 + * scratch bh, cl, flags
   8.710 + */
   8.711 + 
   8.712 +Dico2ESDI:
   8.713 +#if !defined(FLAT32) && !defined(FLAT16OUT)
   8.714 +# ifdef ONLY8086
   8.715 +	pushw	%ax
   8.716 +	movw	nowPos(%bp), %bx
   8.717 +	movw	nowPos+2(%bp), %ax
   8.718 +	jnc	Dico2ESDIz
   8.719 +	subw	rep0(%bp), %bx
   8.720 +	sbbw	rep0+2(%bp), %ax
   8.721 +Dico2ESDIz:
   8.722 +	movw	$0xF, %di
   8.723 +	andw	%bx, %di
   8.724 +	pushw	%cx
   8.725 +	movb	$4, %cl
   8.726 +	shrw	%cl, %bx
   8.727 +	shlw	%cl, %ax
   8.728 +	popw	%cx
   8.729 +	addb	%al, %bh
   8.730 +	popw	%ax
   8.731 +# else
   8.732 +	movl	nowPos(%bp), %ebx
   8.733 +	jnc	Dico2ESDIz
   8.734 +	subl	rep0(%bp), %ebx
   8.735 +Dico2ESDIz:
   8.736 +	movw	%bx, %di
   8.737 +	xorw	%bx, %bx
   8.738 +	shrl	$4, %ebx
   8.739 +# endif
   8.740 +	movw	%bx, %es
   8.741 +#else
   8.742 +	mov	nowPos(BP), DI
   8.743 +	jnc	Dico2ESDIz
   8.744 +	sub	rep0(BP), DI
   8.745 +Dico2ESDIz:
   8.746 +#endif
   8.747 +#ifdef FLAT32
   8.748 +	movb	(DI), %bl
   8.749 +#else
   8.750 +	movb	%es:(%di), %bl
   8.751 +#endif
   8.752 +	ret
   8.753 +
   8.754 +outcharDico:
   8.755 +
   8.756 +// bl = outStream[nowPos++] = outStream[nowPos - rep0]
   8.757 +
   8.758 +/*
   8.759 + * output  es:di, bl
   8.760 + * update  nowPos
   8.761 + * scratch ax, dx, bh, cl, flags
   8.762 + */
   8.763 +
   8.764 +	call	DicoRep02ESDI	// %bl = outStream[nowPos - rep0]
   8.765 +	xchg	AX, BX
   8.766 +outchar:
   8.767 +
   8.768 +// bl = outStream[nowPos++] = previousByte = al;
   8.769 +
   8.770 +/*
   8.771 + * output  bl
   8.772 + * update  nowPos
   8.773 + * scratch ax, dx, bh, di, cl, flags
   8.774 + */
   8.775 +
   8.776 +	clc
   8.777 +	call	Dico2ESDI
   8.778 +	stosb
   8.779 +	xchg	AX, BX		// previous byte
   8.780 +
   8.781 +//	int posState = (int)((nowPos) & posStateMask);
   8.782 +
   8.783 +#if PROP_PB != 0 && PROP_LP != 0
   8.784 +	addw	$0x0101, posState2(BP)
   8.785 +	andb	$(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP)
   8.786 +#else
   8.787 +# if PROP_PB != 0
   8.788 +	incb	posState(BP)
   8.789 +	andb	$((1 << PROP_PB) -1), posState(BP)
   8.790 +# endif
   8.791 +# if PROP_LP != 0
   8.792 +	incb	posState2(BP)
   8.793 +	andb	$((1 << PROP_LP) -1), posState2(BP)
   8.794 +# endif
   8.795 +#endif
   8.796 +#ifdef ONLY8086
   8.797 +	incw	nowPos(BP)
   8.798 +	jnz	incnowPosDone
   8.799 +	incw	nowPos+2(BP)
   8.800 +incnowPosDone:
   8.801 +#else
   8.802 +	incl	nowPos(BP)
   8.803 +#endif
   8.804 +	ret
   8.805 +
   8.806 +//  
   8.807 +// #define RC_NORMALIZE if (Range < kTopValue) 
   8.808 +//    { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
   8.809 +
   8.810 +/*
   8.811 + * update  Range, Code, ds:si
   8.812 + * scratch flags
   8.813 + */
   8.814 +
   8.815 +RC_NORMALIZE:
   8.816 +	cmpb	$0, Range+3(BP)
   8.817 +	jne	RC_NORMALIZE_1
   8.818 +RC_LOAD_BYTE:
   8.819 +	push	AX
   8.820 +#ifdef ONLY8086
   8.821 +	movw	Range+1(BP), %ax
   8.822 +	movw	%ax, Range+2(BP)
   8.823 +	movw	Code+1(BP), %ax
   8.824 +	movw	%ax, Code+2(BP)
   8.825 +	xorw	%ax, %ax
   8.826 +	movb	Range(BP), %ah
   8.827 +	movw	%ax, Range(BP)
   8.828 +	movb	Code(BP), %ah
   8.829 +	movw	%ax, Code(BP)
   8.830 +#else
   8.831 +	shll	$8, Range(BP)
   8.832 +	shll	$8, Code(BP)
   8.833 +#endif
   8.834 +#if !defined(FLAT16) && !defined(FLAT32)
   8.835 +	testw	%si, %si
   8.836 +	jns	RC_READ_BYTE
   8.837 +	movw	%ds, %ax
   8.838 +	incw	%ax
   8.839 +	movw	%ax, %ds
   8.840 +	addw	$-16, %si
   8.841 +RC_READ_BYTE:
   8.842 +#endif
   8.843 +	lodsb
   8.844 +	movb	%al, Code(BP)
   8.845 +	pop	AX
   8.846 +RC_NORMALIZE_1:
   8.847 +	ret
   8.848 +
   8.849 +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
   8.850 +
   8.851 +Bit1state:
   8.852 +	movb	$16, %al
   8.853 +	mulb	state(BP)
   8.854 +# if PROP_PB != 0
   8.855 +	addb	posState(BP), %al
   8.856 +# endif
   8.857 +Bit1axdx:
   8.858 +	add	DX, AX
   8.859 +	jmp	Bit1
   8.860 +
   8.861 +// prob += 12; Bit1(prob)
   8.862 +
   8.863 +Bit1dx12:
   8.864 +	add	$12, DX
   8.865 +Bit1dx:
   8.866 +	mov	DX, AX
   8.867 +
   8.868 +// static int Bit1(CProb *p)
   8.869 +
   8.870 +Bit1:
   8.871 +/*
   8.872 + * input   ax=p
   8.873 + * output  C, ax
   8.874 + * update  bound, Range, Code, ds:si
   8.875 + * scratch flags
   8.876 + */
   8.877 + 
   8.878 +// {
   8.879 +// 	RC_NORMALIZE;
   8.880 +
   8.881 +	call  RC_NORMALIZE		// kill %ax, update %si
   8.882 +
   8.883 +#ifdef ONLY8086
   8.884 +	pushw	%ax
   8.885 +	pushw	%cx
   8.886 +	pushw	%dx
   8.887 +	pushw	%di
   8.888 +#else
   8.889 +	pushal
   8.890 +#endif
   8.891 +
   8.892 +	xchg	AX, DI
   8.893 +	add	DI, DI			// short *
   8.894 +	
   8.895 +
   8.896 +// 	bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p);
   8.897 +
   8.898 +#ifdef ONLY8086
   8.899 +	movw	Range(BP), %dx
   8.900 +	movw	Range+2(BP), %ax
   8.901 +	movw	$11, %cx
   8.902 +shr11lp:
   8.903 +	shrw	$1, %ax
   8.904 +	rcrw	$1, %dx
   8.905 +	loop	shr11lp
   8.906 +	movw	%dx, %cx
   8.907 +	mulw	(BP, DI)
   8.908 +	xchgw	%ax, %cx
   8.909 +	mulw	(BP, DI)
   8.910 +	addw	%cx, %dx
   8.911 +#else
   8.912 +	movl	Range(BP), %eax
   8.913 +	shrl	$11, %eax
   8.914 +	movzwl	(BP, DI), %edx
   8.915 +	mull	%edx
   8.916 +#endif
   8.917 +
   8.918 +// 	if (Code < bound) {
   8.919 +
   8.920 +#ifdef ONLY8086
   8.921 +	cmpw	Code+2(BP), %dx
   8.922 +	jb	Bit1_1
   8.923 +	ja	Bit1_1x
   8.924 +	cmpw	Code(BP), %ax
   8.925 +	jbe	Bit1_1
   8.926 +Bit1_1x:
   8.927 +
   8.928 +//    		Range = bound;
   8.929 +
   8.930 +	movw	%ax, Range(BP)
   8.931 +	movw	%dx, Range+2(BP)
   8.932 +#else
   8.933 +	cmpl	Code(BP), %eax
   8.934 +	jbe	Bit1_1
   8.935 +
   8.936 +//    		Range = bound;
   8.937 +
   8.938 +	movl	%eax, Range(BP)
   8.939 +#endif
   8.940 +
   8.941 +// 		*(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/;
   8.942 +
   8.943 +	movw	$2048, %ax
   8.944 +
   8.945 +// 		return 0;
   8.946 +
   8.947 +	jmp	Bit1_2
   8.948 +
   8.949 +//	}
   8.950 +// 	else {
   8.951 +
   8.952 +Bit1_1:
   8.953 +
   8.954 +//    		Range -= bound; Code -= bound;
   8.955 +
   8.956 +#ifdef ONLY8086
   8.957 +	subw	%ax, Range(BP)
   8.958 +	sbbw	%dx, Range+2(BP)
   8.959 +	subw	%ax, Code(BP)
   8.960 +	sbbw	%dx, Code+2(BP)
   8.961 +#else
   8.962 +	subl	%eax, Range(BP)
   8.963 +	subl	%eax, Code(BP)
   8.964 +#endif
   8.965 +
   8.966 +// 		*(p) -= (*(p)) >> kNumMoveBits /*5*/;
   8.967 +
   8.968 +	movw	$31, %ax
   8.969 +
   8.970 +// 		return 1;
   8.971 +
   8.972 +	stc
   8.973 +Bit1_2:
   8.974 +	pushf
   8.975 +	subw	(BP, DI), %ax
   8.976 +#ifdef ONLY8086
   8.977 +	movb	$5, %cl
   8.978 +	sarw	%cl, %ax
   8.979 +#else
   8.980 +	sarw	$5, %ax
   8.981 +#endif
   8.982 +	addw	%ax, (BP, DI)
   8.983 +	popf
   8.984 +#ifdef ONLY8086
   8.985 +	popw	%di
   8.986 +	popw	%dx
   8.987 +	popw	%cx
   8.988 +	popw	%ax
   8.989 +#else
   8.990 +	popal
   8.991 +#endif
   8.992 +	sbb	AX, AX
   8.993 +
   8.994 +// 	}
   8.995 +// }
   8.996 +
   8.997 +	ret
   8.998 +
   8.999 +RangeDecoder:
  8.1000 +
  8.1001 +/*
  8.1002 + * input   ax=probs cx=numLevels (< 8) bx=1
  8.1003 + * output  ax=res (backward), dh (forward)
  8.1004 + * update  bound, Range, Code, ds:si
  8.1005 + * scratch flags, cx=0, dl
  8.1006 + */
  8.1007 + 
  8.1008 +	push	BX
  8.1009 +	
  8.1010 +//   { int i = numLevels; res = 1; 
  8.1011 +	mov	BX, DX		// res = 1
  8.1012 +	
  8.1013 +//   do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); 
  8.1014 +
  8.1015 +RangeDecoder_1:
  8.1016 +	push	AX
  8.1017 +	call	Bit1axdx		// C,%ax = Bit1(prob+%ax)
  8.1018 +	rclb	$1, %dl			// res <<= 1; res |= C
  8.1019 +	andb	%bl, %al		// current bit
  8.1020 +	orb	%al, %bh		// store in bh
  8.1021 +	shlb	$1, %bl			// update max
  8.1022 +	pop	AX
  8.1023 +	loop	RangeDecoder_1
  8.1024 +
  8.1025 +//   res -= (1 << numLevels); }
  8.1026 +
  8.1027 +	xchg	AX, BX			// move bh to dh
  8.1028 +	xchg	AX, DX			// and dl to al
  8.1029 +	sub	%dl, %al		// sub max
  8.1030 +	pop	BX
  8.1031 +	ret
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/memtest64/stuff/unlzsa1.S	Thu Feb 16 14:18:05 2023 +0000
     9.3 @@ -0,0 +1,197 @@
     9.4 +// Lzsa1Decode:
     9.5 +#ifndef FLAT32
     9.6 +//   input   ds:si=inStream, es:di=outStream
     9.7 +//   output  outStream[], ds:si, es:di
     9.8 +	.code16
     9.9 +#define AX	%ax
    9.10 +#define BX	%bx
    9.11 +#define SI	%si
    9.12 +#define DI	%di
    9.13 +#else
    9.14 +//   input   esi=inStream, edi=outStream
    9.15 +//   output  outStream[], ds:esi, es:edi
    9.16 +	.code32
    9.17 +#define AX	%eax
    9.18 +#define BX	%ebx
    9.19 +#define SI	%esi
    9.20 +#define DI	%edi
    9.21 +#endif
    9.22 +
    9.23 +MATCH_RUN_LEN		=	15
    9.24 +LITERALS_RUN_LEN	=	7
    9.25 +MIN_MATCH_SIZE		=	3
    9.26 +MIN_LITERALS_SIZE	=	0
    9.27 +
    9.28 +#define PACKED_ONLY			// assume no copy block, optional
    9.29 +//#define PARANOIA			// cover rare cases, optional
    9.30 + 
    9.31 +lzsa1main:
    9.32 +#ifdef PARANOIA
    9.33 +	cld
    9.34 +#endif
    9.35 +#ifdef FLAT16OUT
    9.36 +#define RAW_FORMAT
    9.37 +#endif
    9.38 +#ifndef RAW_FORMAT
    9.39 +# if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
    9.40 +	xorw	%cx, %cx
    9.41 +	call	normalize
    9.42 +# endif
    9.43 +# ifndef NO_LZSA1_HEADER
    9.44 +	lodsw
    9.45 +	cmpw	$0x9E7B, %ax	// magic
    9.46 +	jne	lzsa1main
    9.47 +	lodsb
    9.48 +	cmpb	$0, %al		// lzsa1
    9.49 +	jne	lzsa1main
    9.50 +# endif
    9.51 +lzsa1block:			// uncompress chunk
    9.52 +	lodsw			// block size
    9.53 +	xchgw	%ax, %cx
    9.54 +	lodsb
    9.55 +# ifndef PACKED_ONLY
    9.56 +	orb	%al, %al
    9.57 +	jns	lzsa1compressed
    9.58 +#  if !defined(FLAT32) && !defined(FLAT16OUT)
    9.59 +	movw	%cx, %dx
    9.60 +	movb	$0, %cl
    9.61 +	movb	$0, %dh
    9.62 +copytail:
    9.63 +	call	lzsa1movStr
    9.64 +	xchg	%dx, %cx
    9.65 +	incw	%cx
    9.66 +	loop	copytail
    9.67 +#  else
    9.68 +	movsb			// copy block
    9.69 +copylp:
    9.70 +	movsb			// copy block
    9.71 +	loop	copylp		// handle 64K case
    9.72 +#  endif
    9.73 +	jmp	lzsa1block	// end of block
    9.74 +lzsa1compressed:
    9.75 +	jne	lzsa1chunk	// 64Kb block
    9.76 +# endif
    9.77 +	jcxz	lzsa1quit	// bail if we hit EOD
    9.78 +	pushw	%cx
    9.79 +# if !defined(FLAT32) && !defined(FLAT16)
    9.80 +	xorw	%cx, %cx
    9.81 +	call	normalize
    9.82 +# define NeedNormalize
    9.83 +# endif
    9.84 +	popw	%dx
    9.85 +	addw	%si, %dx
    9.86 +#endif
    9.87 +lzsa1chunk:			// uncompress chunk
    9.88 +	lodsb			// get token O|LLL|MMMM
    9.89 +	movb	%al, %bl	// keep token in bl
    9.90 +	shrb	$4, %al		// shift literals length into place
    9.91 +	movw	$LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
    9.92 +	call	lzsa1len	// %ch = LITERALS_RUN_LEN
    9.93 +#if defined(NeedNormalize)
    9.94 +	call	lzsa1movLit	// copy %cx literals from %ds:%si to %es:%di
    9.95 +#else
    9.96 +	rep	movsb		// copy %cx literals from %ds:%si to %es:%di
    9.97 +#endif
    9.98 +#ifndef RAW_FORMAT
    9.99 +	cmpw	%dx, %si
   9.100 +	jae	lzsa1block	// bail if we hit EOD
   9.101 +#endif
   9.102 +#ifdef FLAT32
   9.103 +	orl	$-1, %eax
   9.104 +#else
   9.105 +	movb	$-1, %ah
   9.106 +#endif
   9.107 +	testb	%bl, %bl	// check match offset size in token (O bit)
   9.108 +	jns	lzsa1ShortOfs
   9.109 +	lodsw
   9.110 +	.byte	0x3C		// mask lodsb with cmpb $0xAC, %al
   9.111 +lzsa1ShortOfs:
   9.112 +	lodsb
   9.113 +	xchg	AX, BX		// %bx: match offset  %ax: original token
   9.114 +	movw	$MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
   9.115 +	call	lzsa1len
   9.116 +#ifdef RAW_FORMAT
   9.117 +	jcxz	lzsa1quit	// bail if we hit EOD
   9.118 +#endif
   9.119 +#if !defined(FLAT32) && !defined(FLAT16OUT)
   9.120 +	pushw	%ds
   9.121 +	pushw	%si
   9.122 +	movw	%di, %si
   9.123 +	addw	%bx, %si
   9.124 +	movw	%es, %ax
   9.125 +	jc	axok
   9.126 +	subb	$0x10, %ah
   9.127 +axok:
   9.128 +.macro norm	reg
   9.129 +	movw	%si, \reg
   9.130 +	subw	%si, %dx
   9.131 +	andw	$0xF, %si
   9.132 +	addw	%si, %dx
   9.133 +	shrw	$4, \reg
   9.134 +	addw	\reg, %ax
   9.135 +	movw	%ax, %ds
   9.136 +	movw	%di, \reg
   9.137 +	andw	$0xF, %di
   9.138 +	shrw	$4, \reg
   9.139 +	movw	%es, %ax
   9.140 +	addw	\reg, %ax
   9.141 +	movw	%ax, %es
   9.142 +.endm 
   9.143 +	pushw	%dx
   9.144 +# if defined(NeedNormalize) || defined(PARANOIA)
   9.145 +	call	lzsa1movStr	// copy string
   9.146 +# else
   9.147 +	norm	%bp
   9.148 +	rep movsb
   9.149 +# endif
   9.150 +	popw	%dx
   9.151 +	popw	%si
   9.152 +	popw	%ds
   9.153 +#else
   9.154 +	xchg	AX, SI		// save %si	
   9.155 +	lea	(BX,DI), SI
   9.156 +	rep movsb	%es:(SI), %es:(DI)
   9.157 +	xchg	AX, SI		// restore %si	
   9.158 +#endif
   9.159 +	jmp	lzsa1chunk
   9.160 +
   9.161 +lzsa1len:			// get length in %ecx
   9.162 +	andb	%ch, %al
   9.163 +	cbw			// clear %ah
   9.164 +	cmpb	%ch, %al
   9.165 +	jne	lzsa1minNumber	// S=0-6, L=0-14
   9.166 +	lodsb
   9.167 +	addb	%ch, %cl
   9.168 +lzsa1minNumber:
   9.169 +	addb	%cl, %al
   9.170 +	jnc	lzsa1gotNumber  // 0-255
   9.171 +	movb	%al, %ah	// S=256-1791, L=256-3839 or S=256-511, L=256-511
   9.172 +	jne	lzsa1midNumber
   9.173 +	lodsw			// 0-65535
   9.174 +	.byte	0x3C		// mask lodsb with cmpb $0xAC, %al
   9.175 +lzsa1midNumber:
   9.176 +	lodsb
   9.177 +lzsa1gotNumber:
   9.178 +	xchgw	%ax, %cx
   9.179 +lzsa1quit:
   9.180 +	ret
   9.181 +
   9.182 +#if defined(NeedNormalize) || defined(PARANOIA)
   9.183 +# if defined(PARANOIA)
   9.184 +lzsa1movlp:
   9.185 +	decw	%ch
   9.186 +	rep movsb
   9.187 +	incw	%ch
   9.188 +# endif
   9.189 +normalize:
   9.190 +lzsa1movLit:
   9.191 +	movw	%ds, %ax
   9.192 +lzsa1movStr:
   9.193 +	norm	%bp
   9.194 +# if defined(PARANOIA)
   9.195 +	cmpb	$0xFF, %ch	// catch FFFX case
   9.196 +	je	lzsa1movlp
   9.197 +# endif
   9.198 +	rep movsb
   9.199 +	ret
   9.200 +#endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/memtest64/stuff/unlzsa2.S	Thu Feb 16 14:18:05 2023 +0000
    10.3 @@ -0,0 +1,274 @@
    10.4 +// Lzsa2Decode:
    10.5 +#ifndef FLAT32
    10.6 +//   input   ds:si=inStream, es:di=outStream
    10.7 +//   output  outStream[], ds:si, es:di
    10.8 +	.code16
    10.9 +#define AX	%ax
   10.10 +#define BX	%bx
   10.11 +#define BP	%bp
   10.12 +#define SI	%si
   10.13 +#define DI	%di
   10.14 +#else
   10.15 +//   input   esi=inStream, edi=outStream
   10.16 +//   output  outStream[], ds:esi, es:edi
   10.17 +	.code32
   10.18 +#define AX	%eax
   10.19 +#define BX	%ebx
   10.20 +#define BP	%ebp
   10.21 +#define SI	%esi
   10.22 +#define DI	%edi
   10.23 +#endif
   10.24 +
   10.25 +MATCH_RUN_LEN		=	7
   10.26 +LITERALS_RUN_LEN	=	3
   10.27 +MIN_MATCH_SIZE		=	2
   10.28 +MIN_LITERALS_SIZE	=	0
   10.29 +
   10.30 +#define PACKED_ONLY			// assume no copy block, optional
   10.31 +//#define PARANOIA			// cover rare cases, optional
   10.32 + 
   10.33 +lzsa2main:
   10.34 +#ifdef PARANOIA
   10.35 +	cld
   10.36 +#endif
   10.37 +#ifdef FLAT16OUT
   10.38 +#define RAW_FORMAT
   10.39 +#endif
   10.40 +#ifndef RAW_FORMAT
   10.41 +# if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
   10.42 +	xorw	%cx, %cx
   10.43 +	call	normalize
   10.44 +# endif
   10.45 +# ifndef NO_LZSA2_HEADER
   10.46 +	lodsw
   10.47 +	cmpw	$0x9E7B, %ax	// magic
   10.48 +	jne	lzsa2main
   10.49 +	lodsb
   10.50 +	testb	$0x20, %al	// lzsa2
   10.51 +	je	lzsa2main
   10.52 +# endif
   10.53 +lzsa2block:			// uncompress chunk
   10.54 +# if !defined(FLAT32) && !defined(FLAT16)
   10.55 +	xorw	%cx, %cx
   10.56 +	call	normalize
   10.57 +# endif
   10.58 +	lodsw			// block size
   10.59 +	xchgw	%ax, %cx
   10.60 +	lodsb
   10.61 +# ifndef PACKED_ONLY
   10.62 +	orb	%al, %al
   10.63 +	jns	lzsa2compressed
   10.64 +#  if !defined(FLAT32) && !defined(FLAT16OUT)
   10.65 +	movw	%cx, %dx
   10.66 +	movb	$0, %cl
   10.67 +	movb	$0, %dh
   10.68 +copytail:
   10.69 +	call	lzsa1movStr
   10.70 +	xchg	%dx, %cx
   10.71 +	incw	%cx
   10.72 +	loop	copytail
   10.73 +#  else
   10.74 +	movsb			// copy block
   10.75 +copylp:
   10.76 +	movsb			// copy block
   10.77 +	loop	copylp		// handle 64K case
   10.78 +#  endif
   10.79 +	jmp	lzsa2block	// end of block
   10.80 +lzsa2compressed:
   10.81 +	jne	lzsa2chunk	// 64Kb block
   10.82 +# endif
   10.83 +	jcxz	lzsa2quit	// bail if we hit EOD
   10.84 +# if !defined(FLAT16)
   10.85 +	pushw	%cx
   10.86 +	xorw	%cx, %cx
   10.87 +	call	normalize
   10.88 +# define NeedNormalize
   10.89 +	popw	%dx
   10.90 +	addw	%si, %dx
   10.91 +# else
   10.92 +	movw	%si, %dx
   10.93 +	addw	%cx, %dx
   10.94 +# endif
   10.95 +#else
   10.96 +# if !defined(FLAT16)
   10.97 +	xorw	%cx, %cx
   10.98 +	call	normalize
   10.99 +# define NeedNormalize
  10.100 +# endif
  10.101 +#endif
  10.102 +	movb	$0, %bh		// no nibble stored
  10.103 +lzsa2chunk:			// uncompress chunk
  10.104 +	lodsb			// get token XYZ|LL|MMM
  10.105 +	movb	%al, %bl	// keep token in bl
  10.106 +	movw	$LITERALS_RUN_LEN+256*MIN_LITERALS_SIZE, %cx
  10.107 +	shrb	%cl, %al	// shift literals length into place
  10.108 +	call	lzsa2len	// %cl = LITERALS_RUN_LEN
  10.109 +#if defined(NeedNormalize)
  10.110 +	pushw	%bp
  10.111 +	call	lzsa2movLit	// copy %cx literals from %ds:%si to %es:%di
  10.112 +	popw	%bp
  10.113 +#else
  10.114 +	rep	movsb		// copy %cx literals from %ds:%si to %es:%di
  10.115 +#endif
  10.116 +#ifndef RAW_FORMAT
  10.117 +maxsi:
  10.118 +	cmpw	%dx, %si
  10.119 +	jae	lzsa2block	// bail if we hit EOD
  10.120 +#endif
  10.121 +#ifdef FLAT32
  10.122 +	orl	$-1, %eax	// set offset bits 31-8 to 1
  10.123 +#else
  10.124 +	movb	$-1, %ah	// set offset bits 15-8 to 1
  10.125 +#endif
  10.126 +// XYZ
  10.127 +	testb	$0xC0, %bl	// check match offset mode in token (X bit)
  10.128 +	bt	$5, %bx		// move bit 5 to carry
  10.129 +	js	rep_match_or_large_offset
  10.130 +	jne	offset_9_bit
  10.131 +// 00Z 5-bit offset: read a nibble for offset bits 1-4 and use the inverted bit Z of the token as bit 0 of the offset.
  10.132 +//                   set bits 5-15 of the offset to 1.
  10.133 +	call	getByteFromNibbleAndC
  10.134 +	jmp	get_match_length
  10.135 +offset_9_bit:
  10.136 +// 01Z 9-bit offset: read a byte for offset bits 0-7 and use the inverted bit Z for bit 8 of the offset.
  10.137 +//                   set bits 9-15 of the offset to 1.
  10.138 +	sbbb	%cl, %ah	// clear bit 8 if Z bit is clear
  10.139 +	jmp	get_match_length_0
  10.140 +
  10.141 +getNibble:
  10.142 +	xorb	$0xF0, %bh	// toggle nibble stored flags
  10.143 +	movb	%bh, %al
  10.144 +	jns	gotnibble
  10.145 +	lodsb
  10.146 +	movb	$0xF0, %bh
  10.147 +	orb	%al, %bh
  10.148 +	shrb	$4, %al
  10.149 +gotnibble:
  10.150 +lzsa2quit:
  10.151 +	ret
  10.152 +
  10.153 +rep_match_or_large_offset:
  10.154 +	jpe	rep_match_or_16_bit
  10.155 +//10Z 13-bit offset: read a nibble for offset bits 9-12 and use the inverted bit Z for bit 8 of the offset,
  10.156 +//                   then read a byte for offset bits 0-7. set bits 13-15 of the offset to 1.
  10.157 +//                   substract 512 from the offset to get the final value.
  10.158 +	call	getByteFromNibbleAndC
  10.159 +	subb	$2, %al		// substract 512
  10.160 +	jmp	get_match_length_1
  10.161 +rep_match_or_16_bit:
  10.162 +	jc	repeat_match	// rep-match
  10.163 +//110 16-bit offset: read a byte for offset bits 8-15, then another byte for offset bits 0-7.
  10.164 +	lodsb			// Get 2-byte match offset
  10.165 +get_match_length_1:
  10.166 +	xchgb	%al, %ah
  10.167 +get_match_length_0:
  10.168 +	lodsb			// load match offset bits 0-7
  10.169 +get_match_length:
  10.170 +	xchgw	%ax, %bp	// bp: offset
  10.171 +repeat_match:
  10.172 +//111 repeat offset: reuse the offset value of the previous match command.
  10.173 +
  10.174 +	movb	%bl, %al	// %al: original token
  10.175 +	movw	$MATCH_RUN_LEN+256*MIN_MATCH_SIZE, %cx
  10.176 +	call	lzsa2len
  10.177 +#ifdef RAW_FORMAT
  10.178 +	jcxz	lzsa2quit	// bail if we hit EOD
  10.179 +#endif
  10.180 +#if !defined(FLAT32) && !defined(FLAT16OUT)
  10.181 +	pushw	%ds
  10.182 +	pushw	%si
  10.183 +	movw	%di, %si
  10.184 +	addw	%bp, %si
  10.185 +	movw	%es, %ax
  10.186 +	jc	axok
  10.187 +	subb	$0x10, %ah
  10.188 +axok:
  10.189 +.macro norm	reg
  10.190 +	movw	%si, \reg
  10.191 +	subw	%si, %dx
  10.192 +	andw	$0xF, %si
  10.193 +	addw	%si, %dx
  10.194 +	shrw	$4, \reg
  10.195 +	addw	\reg, %ax
  10.196 +	movw	%ax, %ds
  10.197 +	movw	%di, \reg
  10.198 +	andw	$0xF, %di
  10.199 +	shrw	$4, \reg
  10.200 +	movw	%es, %ax
  10.201 +	addw	\reg, %ax
  10.202 +	movw	%ax, %es
  10.203 +.endm 
  10.204 +	pushw	%bp
  10.205 +	pushw	%dx
  10.206 +# if defined(NeedNormalize) || defined(PARANOIA)
  10.207 +	call	lzsa2movStr	// copy string
  10.208 +# else
  10.209 +	norm	%bp
  10.210 +	rep movsb
  10.211 +# endif
  10.212 +	popw	%dx
  10.213 +	popw	%bp
  10.214 +	popw	%si
  10.215 +	popw	%ds
  10.216 +#else
  10.217 +	xchg	AX, SI		// save %si	
  10.218 +	lea	(BP,DI), SI
  10.219 +	rep movsb	%es:(SI), %es:(DI)
  10.220 +	xchg	AX, SI		// restore %si	
  10.221 +#endif
  10.222 +	jmp	lzsa2chunk
  10.223 +
  10.224 +getByteFromNibbleAndC:
  10.225 +	pushfw
  10.226 +	call	getNibble	// get nibble for offset bits 0-3
  10.227 +	popfw
  10.228 +	rclb	$1, %al
  10.229 +	xorb	$0xE1, %al	// set offset bits 7-5 to 1
  10.230 +	ret
  10.231 +
  10.232 +lzsa2len:			// get length in %cx
  10.233 +	andb	%cl, %al
  10.234 +	cbw			// clear %ah
  10.235 +	cmpb	%al, %cl
  10.236 +	jne	lzsa2minNumber	// S=0-2, L=0-6
  10.237 +	call	getNibble
  10.238 +	cmp	$0xF, %al
  10.239 +	jne	lzsa2noExtraByte
  10.240 +	addb	%al, %ch
  10.241 +	lodsb
  10.242 +lzsa2noExtraByte:
  10.243 +	addb	%cl, %ch
  10.244 +lzsa2minNumber:
  10.245 +	addb	%ch, %al
  10.246 +	jnc	lzsa2gotNumber  // 0-255
  10.247 +#if 0
  10.248 +	je	lzsa2BigNumber
  10.249 +	movb	%al, %ah	// S=256-767, L=256-1791
  10.250 +	lodsb	
  10.251 +	.byte	0xB1		// mask lodsw with movb $0xAD, %cl
  10.252 +lzsa2BigNumber:
  10.253 +#endif
  10.254 +	lodsw			// 0-65535
  10.255 +lzsa2gotNumber:
  10.256 +	xchgw	%ax, %cx
  10.257 +	ret
  10.258 +
  10.259 +#if defined(NeedNormalize) || defined(PARANOIA)
  10.260 +# if defined(PARANOIA)
  10.261 +lzsa2movlp:
  10.262 +	decw	%ch
  10.263 +	rep movsb
  10.264 +	incw	%ch
  10.265 +# endif
  10.266 +normalize:
  10.267 +lzsa2movLit:
  10.268 +	movw	%ds, %ax
  10.269 +lzsa2movStr:
  10.270 +	norm	%bp
  10.271 +# if defined(PARANOIA)
  10.272 +	cmpb	$0xFF, %ch	// catch FFFX case
  10.273 +	je	lzsa2movlp
  10.274 +# endif
  10.275 +	rep movsb
  10.276 +	ret
  10.277 +#endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/memtest64/stuff/unpack.S	Thu Feb 16 14:18:05 2023 +0000
    11.3 @@ -0,0 +1,323 @@
    11.4 +#define SYSTEM		0x10000
    11.5 +#define SETUP		14
    11.6 +#define SYSSIZE		0x1F4
    11.7 +#define SETUPSIZE	0x1F1
    11.8 +
    11.9 +#define KEEP_BOOTSECTOR		0
   11.10 +#define LINUX_HEADER		0
   11.11 +#define UPDATE_SYSSIZE		0
   11.12 +#define FLAT16			1	// lzma case
   11.13 +#define FLAT16OUT		0
   11.14 +#define COPYTOHIGHMEM		0
   11.15 +#define UPDATE_CODE32_START	1
   11.16 +#define DOUBLE_PACKED		0
   11.17 +#define SAVEREGS		0 
   11.18 +#define ELKS			0
   11.19 +
   11.20 +	.text
   11.21 +	.code16
   11.22 +	.org	0
   11.23 +
   11.24 +#if KEEP_BOOTSECTOR
   11.25 +#undef UPDATE_SYSSIZE
   11.26 +#define UPDATE_SYSSIZE		0
   11.27 +#endif
   11.28 +#if ELKS
   11.29 +	.arch	i8086
   11.30 +#define FLAT16			1
   11.31 +#define KEEP_BOOTSECTOR		1
   11.32 +#define LINUX_HEADER		0
   11.33 +#define SAVEREGS		0 
   11.34 +#define TOPSEG		0x2000
   11.35 +#else
   11.36 +#define TOPSEG		0x8000
   11.37 +#endif
   11.38 +
   11.39 +.macro	pusham
   11.40 +#if ELKS
   11.41 +	pushw	%ax
   11.42 +//	movw	%sp, %ax
   11.43 +//	incw	%ax		// emulate popa behaviour
   11.44 +//	incw	%ax
   11.45 +	pushw	%cx
   11.46 +	pushw	%dx
   11.47 +	pushw	%bx
   11.48 +//	pushw	%ax		// %sp
   11.49 +	pushw	%bp
   11.50 +	pushw	%si
   11.51 +	pushw	%di
   11.52 +#else
   11.53 +	pushaw
   11.54 +#endif
   11.55 +.endm 
   11.56 +
   11.57 +.macro	popam
   11.58 +#if ELKS
   11.59 +	popw	%di
   11.60 +	popw	%si
   11.61 +	popw	%bp
   11.62 +//	popw	%ax
   11.63 +	popw	%bx
   11.64 +	popw	%dx
   11.65 +	popw	%cx
   11.66 +	popw	%ax
   11.67 +#else
   11.68 +	popaw
   11.69 +#endif
   11.70 +.endm 
   11.71 +
   11.72 +.macro	pushm	val
   11.73 +#if ELKS
   11.74 +	movw	\val, %ax
   11.75 +	pushw	%ax
   11.76 +#else
   11.77 +	pushw	\val
   11.78 +#endif
   11.79 +.endm 
   11.80 +
   11.81 +.macro	shrwm	cnt, reg
   11.82 +#if ELKS
   11.83 +	.rept	\cnt
   11.84 +	shrw	$1, \reg
   11.85 +	.endr
   11.86 +#else
   11.87 +	shrw	$\cnt, \reg
   11.88 +#endif
   11.89 +.endm
   11.90 +
   11.91 +	.globl	_start
   11.92 +_start:
   11.93 +#if LINUX_HEADER
   11.94 +	jmp	start2
   11.95 +	.ascii	"HdrS"		// 202 magic
   11.96 +	.word	0x200		// 206 version 2.00
   11.97 +	.long	0		// 208 realmode_swtch
   11.98 +	.word	SYSTEM/16	// 20C start_sys_seg
   11.99 +	.word	0		// 20E kernel_version
  11.100 +	.byte	0		// 210 type_of_loader
  11.101 +	.byte	0		// 211 loadflags
  11.102 +	.word	0		// 212 setup_move_size
  11.103 +	.long	SYSTEM		// 214 code32_start
  11.104 +	.long	0		// 218 ramdisk_image
  11.105 +	.long	0		// 21C ramdisk_size
  11.106 +	.long	0		// 220 bootsect_kludge
  11.107 +start2:
  11.108 +#endif
  11.109 +#if SAVEREGS
  11.110 +	pushfw
  11.111 +	pushw	%cs
  11.112 +	pushw	$0
  11.113 +	pusham
  11.114 +	xorw	%si, %si
  11.115 +	pushw	%ds
  11.116 +	pushw	%es
  11.117 +	cld
  11.118 +#else
  11.119 +	pushw	%cs			// return adress is %cs:0
  11.120 +	xorw	%si, %si
  11.121 +	pushw	%si
  11.122 +#endif	// SAVEREGS
  11.123 +	pushw	%ds			// <A> bootsector+setup segment
  11.124 +#if FLAT16
  11.125 +# 1- move 9000..9020+stp -> TOPSEG
  11.126 +	pushm	$TOPSEG
  11.127 +	popw	%es
  11.128 +# if SAVEREGS
  11.129 +setup_word:
  11.130 +	movw	$SETUP*256+256, %cx
  11.131 +	pushw	%cx			// <B> bootsector+setup words
  11.132 +# endif
  11.133 +	pushw	%es			// <C> TOPSEG
  11.134 +	pushw	%es
  11.135 +# if SAVEREGS
  11.136 +	xorw	%di, %di		// %ds:%si = 9000:0000		%es:%di = TOPSEG:0
  11.137 +	pushm	$0x200+cont
  11.138 +	rep
  11.139 +	  movsw
  11.140 +	lret
  11.141 +cont:
  11.142 +# else
  11.143 +	movw	$-0x200, %di
  11.144 +	call	jumpinto
  11.145 +# endif
  11.146 +# 2- move 1000..1000+sys -> TOPSEG+stp
  11.147 +	pushm	$0x1000
  11.148 +	popw	%ds
  11.149 +	xorw	%si, %si		// %ds:%si = 1000:0
  11.150 +	subw	%di, %cx		// %cx = 64K - setupsz
  11.151 +	rep
  11.152 +	  movsb
  11.153 +# 3- unlz(TOPSEG+stp:end, 1000-stp:0)
  11.154 +setup_seg:
  11.155 +	pushm	$0x1000-(SETUP*32)-32
  11.156 +	popw	%es
  11.157 +#else		// FLAT16
  11.158 +# 1- move 9020..9020+unpack -> 0700 and jump into
  11.159 +	movw	$0x700, %cx		// Up to 3.5KB for unpacker (unlzma is << 1KB)
  11.160 +	movw	%cx, %es		// Use 7000 .. 7E00, keep up to 23 elks setup sectors
  11.161 +	pushw	%es
  11.162 +	xorw	%di, %di		// %ds:%si = 9000:0000	%es:%di = 0700:0000
  11.163 +	pushm	$0x200+cont
  11.164 +# if SAVEREGS
  11.165 +	rep
  11.166 +	  movsw
  11.167 +	lret
  11.168 +# else
  11.169 +	jmp	jumpinto
  11.170 +# endif
  11.171 +cont:
  11.172 +# 2- move 9020..9020+stp -> 9000-sys-stp
  11.173 +	movw	%ds, %dx
  11.174 +setup_byte:
  11.175 +	movb	$SETUP+1, %ch
  11.176 +setup_para:
  11.177 +	subw	$SETUP*32+32+0xF000, %dx
  11.178 +packed_syssize:
  11.179 +	movw	$0+0x1000, %ax
  11.180 +	pushw	%cx			// <B> bootsector+setup words
  11.181 +	subw	%ax, %dx
  11.182 +	movw	%dx, %es
  11.183 +	pushw	%es			// <C> 9000-sys-stp
  11.184 +	xorw	%si, %si
  11.185 +	xorw	%di, %di		// %ds:%si = 9000:0	%es:%di = 9000-sys-stp:0
  11.186 +	rep
  11.187 +	  movsw
  11.188 +# 3- move 1000..1000+sys -> 9000-sys
  11.189 +	movw	%ds, %dx
  11.190 +mvsys:
  11.191 +	decw	%ax
  11.192 +	decw	%dx
  11.193 +	movw	%ax, %ds
  11.194 +	movw	%dx, %es
  11.195 +	xorw	%si, %si
  11.196 +	xorw	%di, %di
  11.197 +	movw	$8, %cx
  11.198 +	rep
  11.199 +	  movsw
  11.200 +	cmpw	$0x1000, %ax
  11.201 +	jne	mvsys
  11.202 +# 4- unlz(9000-sys-stp:end, 1000-stp:0)
  11.203 +setup_seg:
  11.204 +	pushm	$0x1000-(SETUP*32)-32
  11.205 +	popw	%es
  11.206 +#endif		// FLAT16
  11.207 +	popw	%ds			// <C>
  11.208 +#if FLAT16 && SAVEREGS == 0
  11.209 +	movw	$end-_start, %si	// %ds:%si = TOPSSEG:compressed
  11.210 +#else
  11.211 +	movw	$0x200+end-_start, %si	// %ds:%si = 9000-sys-stp:compressed
  11.212 +#endif
  11.213 +#if KEEP_BOOTSECTOR
  11.214 +setup_keep:
  11.215 +	xorw	%di, %di
  11.216 +#else
  11.217 +# if UPDATE_SYSSIZE
  11.218 +setup_syssize:
  11.219 +	movw	$0x1F4, %di		// %es:%di = 1000-setup-bootsector:SYSSIZE
  11.220 +# else
  11.221 +	movw	$0x200, %di
  11.222 +# endif
  11.223 +#endif
  11.224 +	pushw	%di
  11.225 +	pushw	%es
  11.226 +#if DOUBLE_PACKED
  11.227 +double_packed:
  11.228 +	pushm	$0x4000
  11.229 +	popw	%es
  11.230 +	pushw	%di
  11.231 +	pushw	%es
  11.232 +	call	unpack
  11.233 +	popw	%ds
  11.234 +	popw	%si
  11.235 +	popw	%es
  11.236 +	popw	%di
  11.237 +	pushw	%di
  11.238 +	pushw	%es
  11.239 +#endif
  11.240 +	call	unpack
  11.241 +#if COPYTOHIGHMEM
  11.242 +# if FLAT16OUT
  11.243 +	movw	$0x9310+1, %ax		// from 1000:FFFF
  11.244 +# else
  11.245 +#  if 0
  11.246 +	movw	%es, %ax
  11.247 +	shrw	$12, %ax
  11.248 +	orw	$0x9310, %ax
  11.249 +#  else
  11.250 +	movw	$0x9310+7, %ax		// from 7000:FFFF
  11.251 +#  endif
  11.252 +# endif
  11.253 +	pushw	%ss
  11.254 +	popw	%es
  11.255 +	movw	$8, %cx
  11.256 +zero1:
  11.257 +	pushw	$0			// 2E..20
  11.258 +	loop	zero1
  11.259 +src:		
  11.260 +	pushw	%cx			// 1E, 16
  11.261 +	pushw	%ax			// 1A: dst %ax:%cx, 12: src %ax:%cx
  11.262 +	pushw	%cx
  11.263 +	pushw	$-1			// 18, 10: full 64K segment
  11.264 +	subb	$0x10, %al
  11.265 +	jnc	src
  11.266 +	movb	$8, %cl
  11.267 +zero2:
  11.268 +	pushw	$0			// 0E..00
  11.269 +	loop	zero2
  11.270 +	movw	%sp, %si
  11.271 +syslp:
  11.272 +	movb	$0x80, %ch	
  11.273 +	movb	$0x87, %ah
  11.274 +	int	$0x15
  11.275 +# if FLAT16OUT == 0
  11.276 +	decb	%es:0x1C(%si)
  11.277 +	decb	%es:0x14(%si)
  11.278 +	jne	syslp			// down to 1000:0000
  11.279 +# endif
  11.280 +	addw	$0x30, %sp
  11.281 +#endif	// COPYTOHIGHMEM
  11.282 +	popw	%ds
  11.283 +	popw	%si			// %ds:%si = 1000-setup-bootsector:SYSSIZE / 0
  11.284 +#if UPDATE_CODE32_START
  11.285 +update_code32_start:
  11.286 +//	movb	$1, 0x216
  11.287 +#endif
  11.288 +#if FLAT16 == 0 || SAVEREGS
  11.289 +	popw	%cx			// <B> bootsector+setup words
  11.290 +#endif
  11.291 +	popw	%es			// <A> bootsector+setup segment
  11.292 +	movw	%si, %di
  11.293 +jumpinto:
  11.294 +#if FLAT16 && SAVEREGS == 0
  11.295 +setup_word:
  11.296 +	movw	$SETUP*256+256, %cx
  11.297 +#endif
  11.298 +# 5- move 1000-stp..1000 -> 9000
  11.299 +	rep
  11.300 +	  movsw
  11.301 +#if SAVEREGS
  11.302 +	popw	%es
  11.303 +	popw	%ds
  11.304 +	popam
  11.305 +	iret
  11.306 +#else
  11.307 +	lret
  11.308 +#endif
  11.309 +
  11.310 +unpack:
  11.311 +#define NO_LZMA_HEADER
  11.312 +#define NO_LZSA2_HEADER
  11.313 +#define NO_LZSA1_HEADER
  11.314 +#define NO_LZ4_HEADER
  11.315 +#if ELKS
  11.316 +#define ONLY8086	1
  11.317 +#endif
  11.318 +#if defined(FLAT16OUT) && FLAT16OUT == 0
  11.319 +#undef FLAT16OUT
  11.320 +#endif
  11.321 +#if defined(FLAT16) && FLAT16 == 0
  11.322 +#undef FLAT16
  11.323 +#endif
  11.324 +#include "uncompress.S"
  11.325 +
  11.326 +end:
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/memtest64/stuff/unpackx.S	Thu Feb 16 14:18:05 2023 +0000
    12.3 @@ -0,0 +1,323 @@
    12.4 +#define SYSTEM		0x10000
    12.5 +#define SETUP		14
    12.6 +#define SYSSIZE		0x1F4
    12.7 +#define SETUPSIZE	0x1F1
    12.8 +
    12.9 +#define KEEP_BOOTSECTOR		0
   12.10 +#define LINUX_HEADER		0
   12.11 +#define UPDATE_SYSSIZE		1
   12.12 +#define FLAT16			1	// lzma case
   12.13 +#define FLAT16OUT		0
   12.14 +#define COPYTOHIGHMEM		0
   12.15 +#define UPDATE_CODE32_START	0
   12.16 +#define DOUBLE_PACKED		0
   12.17 +#define SAVEREGS		0 
   12.18 +#define ELKS			0
   12.19 +
   12.20 +	.text
   12.21 +	.code16
   12.22 +	.org	0
   12.23 +
   12.24 +#if KEEP_BOOTSECTOR
   12.25 +#undef UPDATE_SYSSIZE
   12.26 +#define UPDATE_SYSSIZE		0
   12.27 +#endif
   12.28 +#if ELKS
   12.29 +	.arch	i8086
   12.30 +#define FLAT16			1
   12.31 +#define KEEP_BOOTSECTOR		1
   12.32 +#define LINUX_HEADER		0
   12.33 +#define SAVEREGS		0 
   12.34 +#define TOPSEG		0x2000
   12.35 +#else
   12.36 +#define TOPSEG		0x8000
   12.37 +#endif
   12.38 +
   12.39 +.macro	pusham
   12.40 +#if ELKS
   12.41 +	pushw	%ax
   12.42 +//	movw	%sp, %ax
   12.43 +//	incw	%ax		// emulate popa behaviour
   12.44 +//	incw	%ax
   12.45 +	pushw	%cx
   12.46 +	pushw	%dx
   12.47 +	pushw	%bx
   12.48 +//	pushw	%ax		// %sp
   12.49 +	pushw	%bp
   12.50 +	pushw	%si
   12.51 +	pushw	%di
   12.52 +#else
   12.53 +	pushaw
   12.54 +#endif
   12.55 +.endm 
   12.56 +
   12.57 +.macro	popam
   12.58 +#if ELKS
   12.59 +	popw	%di
   12.60 +	popw	%si
   12.61 +	popw	%bp
   12.62 +//	popw	%ax
   12.63 +	popw	%bx
   12.64 +	popw	%dx
   12.65 +	popw	%cx
   12.66 +	popw	%ax
   12.67 +#else
   12.68 +	popaw
   12.69 +#endif
   12.70 +.endm 
   12.71 +
   12.72 +.macro	pushm	val
   12.73 +#if ELKS
   12.74 +	movw	\val, %ax
   12.75 +	pushw	%ax
   12.76 +#else
   12.77 +	pushw	\val
   12.78 +#endif
   12.79 +.endm 
   12.80 +
   12.81 +.macro	shrwm	cnt, reg
   12.82 +#if ELKS
   12.83 +	.rept	\cnt
   12.84 +	shrw	$1, \reg
   12.85 +	.endr
   12.86 +#else
   12.87 +	shrw	$\cnt, \reg
   12.88 +#endif
   12.89 +.endm
   12.90 +
   12.91 +	.globl	_start
   12.92 +_start:
   12.93 +#if LINUX_HEADER
   12.94 +	jmp	start2
   12.95 +	.ascii	"HdrS"		// 202 magic
   12.96 +	.word	0x200		// 206 version 2.00
   12.97 +	.long	0		// 208 realmode_swtch
   12.98 +	.word	SYSTEM/16	// 20C start_sys_seg
   12.99 +	.word	0		// 20E kernel_version
  12.100 +	.byte	0		// 210 type_of_loader
  12.101 +	.byte	0		// 211 loadflags
  12.102 +	.word	0		// 212 setup_move_size
  12.103 +	.long	SYSTEM		// 214 code32_start
  12.104 +	.long	0		// 218 ramdisk_image
  12.105 +	.long	0		// 21C ramdisk_size
  12.106 +	.long	0		// 220 bootsect_kludge
  12.107 +start2:
  12.108 +#endif
  12.109 +#if SAVEREGS
  12.110 +	pushfw
  12.111 +	pushw	%cs
  12.112 +	pushw	$0
  12.113 +	pusham
  12.114 +	xorw	%si, %si
  12.115 +	pushw	%ds
  12.116 +	pushw	%es
  12.117 +	cld
  12.118 +#else
  12.119 +	pushw	%cs			// return adress is %cs:0
  12.120 +	xorw	%si, %si
  12.121 +	pushw	%si
  12.122 +#endif	// SAVEREGS
  12.123 +	pushw	%ds			// <A> bootsector+setup segment
  12.124 +#if FLAT16
  12.125 +# 1- move 9000..9020+stp -> TOPSEG
  12.126 +	pushm	$TOPSEG
  12.127 +	popw	%es
  12.128 +# if SAVEREGS
  12.129 +setup_word:
  12.130 +	movw	$SETUP*256+256, %cx
  12.131 +	pushw	%cx			// <B> bootsector+setup words
  12.132 +# endif
  12.133 +	pushw	%es			// <C> TOPSEG
  12.134 +	pushw	%es
  12.135 +# if SAVEREGS
  12.136 +	xorw	%di, %di		// %ds:%si = 9000:0000		%es:%di = TOPSEG:0
  12.137 +	pushm	$0x200+cont
  12.138 +	rep
  12.139 +	  movsw
  12.140 +	lret
  12.141 +cont:
  12.142 +# else
  12.143 +	movw	$-0x200, %di
  12.144 +	call	jumpinto
  12.145 +# endif
  12.146 +# 2- move 1000..1000+sys -> TOPSEG+stp
  12.147 +	pushm	$0x1000
  12.148 +	popw	%ds
  12.149 +	xorw	%si, %si		// %ds:%si = 1000:0
  12.150 +	subw	%di, %cx		// %cx = 64K - setupsz
  12.151 +	rep
  12.152 +	  movsb
  12.153 +# 3- unlz(TOPSEG+stp:end, 1000-stp:0)
  12.154 +setup_seg:
  12.155 +	pushm	$0x1000-(SETUP*32)-32
  12.156 +	popw	%es
  12.157 +#else		// FLAT16
  12.158 +# 1- move 9020..9020+unpack -> 0700 and jump into
  12.159 +	movw	$0x700, %cx		// Up to 3.5KB for unpacker (unlzma is << 1KB)
  12.160 +	movw	%cx, %es		// Use 7000 .. 7E00, keep up to 23 elks setup sectors
  12.161 +	pushw	%es
  12.162 +	xorw	%di, %di		// %ds:%si = 9000:0000	%es:%di = 0700:0000
  12.163 +	pushm	$0x200+cont
  12.164 +# if SAVEREGS
  12.165 +	rep
  12.166 +	  movsw
  12.167 +	lret
  12.168 +# else
  12.169 +	jmp	jumpinto
  12.170 +# endif
  12.171 +cont:
  12.172 +# 2- move 9020..9020+stp -> 9000-sys-stp
  12.173 +	movw	%ds, %dx
  12.174 +setup_byte:
  12.175 +	movb	$SETUP+1, %ch
  12.176 +setup_para:
  12.177 +	subw	$SETUP*32+32+0xF000, %dx
  12.178 +packed_syssize:
  12.179 +	movw	$0+0x1000, %ax
  12.180 +	pushw	%cx			// <B> bootsector+setup words
  12.181 +	subw	%ax, %dx
  12.182 +	movw	%dx, %es
  12.183 +	pushw	%es			// <C> 9000-sys-stp
  12.184 +	xorw	%si, %si
  12.185 +	xorw	%di, %di		// %ds:%si = 9000:0	%es:%di = 9000-sys-stp:0
  12.186 +	rep
  12.187 +	  movsw
  12.188 +# 3- move 1000..1000+sys -> 9000-sys
  12.189 +	movw	%ds, %dx
  12.190 +mvsys:
  12.191 +	decw	%ax
  12.192 +	decw	%dx
  12.193 +	movw	%ax, %ds
  12.194 +	movw	%dx, %es
  12.195 +	xorw	%si, %si
  12.196 +	xorw	%di, %di
  12.197 +	movw	$8, %cx
  12.198 +	rep
  12.199 +	  movsw
  12.200 +	cmpw	$0x1000, %ax
  12.201 +	jne	mvsys
  12.202 +# 4- unlz(9000-sys-stp:end, 1000-stp:0)
  12.203 +setup_seg:
  12.204 +	pushm	$0x1000-(SETUP*32)-32
  12.205 +	popw	%es
  12.206 +#endif		// FLAT16
  12.207 +	popw	%ds			// <C>
  12.208 +#if FLAT16 && SAVEREGS == 0
  12.209 +	movw	$end-_start, %si	// %ds:%si = TOPSSEG:compressed
  12.210 +#else
  12.211 +	movw	$0x200+end-_start, %si	// %ds:%si = 9000-sys-stp:compressed
  12.212 +#endif
  12.213 +#if KEEP_BOOTSECTOR
  12.214 +setup_keep:
  12.215 +	xorw	%di, %di
  12.216 +#else
  12.217 +# if UPDATE_SYSSIZE
  12.218 +setup_syssize:
  12.219 +	movw	$0x1F4, %di		// %es:%di = 1000-setup-bootsector:SYSSIZE
  12.220 +# else
  12.221 +	movw	$0x200, %di
  12.222 +# endif
  12.223 +#endif
  12.224 +	pushw	%di
  12.225 +	pushw	%es
  12.226 +#if DOUBLE_PACKED
  12.227 +double_packed:
  12.228 +	pushm	$0x4000
  12.229 +	popw	%es
  12.230 +	pushw	%di
  12.231 +	pushw	%es
  12.232 +	call	unpack
  12.233 +	popw	%ds
  12.234 +	popw	%si
  12.235 +	popw	%es
  12.236 +	popw	%di
  12.237 +	pushw	%di
  12.238 +	pushw	%es
  12.239 +#endif
  12.240 +	call	unpack
  12.241 +#if COPYTOHIGHMEM
  12.242 +# if FLAT16OUT
  12.243 +	movw	$0x9310+1, %ax		// from 1000:FFFF
  12.244 +# else
  12.245 +#  if 0
  12.246 +	movw	%es, %ax
  12.247 +	shrw	$12, %ax
  12.248 +	orw	$0x9310, %ax
  12.249 +#  else
  12.250 +	movw	$0x9310+7, %ax		// from 7000:FFFF
  12.251 +#  endif
  12.252 +# endif
  12.253 +	pushw	%ss
  12.254 +	popw	%es
  12.255 +	movw	$8, %cx
  12.256 +zero1:
  12.257 +	pushw	$0			// 2E..20
  12.258 +	loop	zero1
  12.259 +src:		
  12.260 +	pushw	%cx			// 1E, 16
  12.261 +	pushw	%ax			// 1A: dst %ax:%cx, 12: src %ax:%cx
  12.262 +	pushw	%cx
  12.263 +	pushw	$-1			// 18, 10: full 64K segment
  12.264 +	subb	$0x10, %al
  12.265 +	jnc	src
  12.266 +	movb	$8, %cl
  12.267 +zero2:
  12.268 +	pushw	$0			// 0E..00
  12.269 +	loop	zero2
  12.270 +	movw	%sp, %si
  12.271 +syslp:
  12.272 +	movb	$0x80, %ch	
  12.273 +	movb	$0x87, %ah
  12.274 +	int	$0x15
  12.275 +# if FLAT16OUT == 0
  12.276 +	decb	%es:0x1C(%si)
  12.277 +	decb	%es:0x14(%si)
  12.278 +	jne	syslp			// down to 1000:0000
  12.279 +# endif
  12.280 +	addw	$0x30, %sp
  12.281 +#endif	// COPYTOHIGHMEM
  12.282 +	popw	%ds
  12.283 +	popw	%si			// %ds:%si = 1000-setup-bootsector:SYSSIZE / 0
  12.284 +#if UPDATE_CODE32_START
  12.285 +update_code32_start:
  12.286 +//	movb	$1, 0x216
  12.287 +#endif
  12.288 +#if FLAT16 == 0 || SAVEREGS
  12.289 +	popw	%cx			// <B> bootsector+setup words
  12.290 +#endif
  12.291 +	popw	%es			// <A> bootsector+setup segment
  12.292 +	movw	%si, %di
  12.293 +jumpinto:
  12.294 +#if FLAT16 && SAVEREGS == 0
  12.295 +setup_word:
  12.296 +	movw	$SETUP*256+256, %cx
  12.297 +#endif
  12.298 +# 5- move 1000-stp..1000 -> 9000
  12.299 +	rep
  12.300 +	  movsw
  12.301 +#if SAVEREGS
  12.302 +	popw	%es
  12.303 +	popw	%ds
  12.304 +	popam
  12.305 +	iret
  12.306 +#else
  12.307 +	lret
  12.308 +#endif
  12.309 +
  12.310 +unpack:
  12.311 +#define NO_LZMA_HEADER
  12.312 +#define NO_LZSA2_HEADER
  12.313 +#define NO_LZSA1_HEADER
  12.314 +#define NO_LZ4_HEADER
  12.315 +#if ELKS
  12.316 +#define ONLY8086	1
  12.317 +#endif
  12.318 +#if defined(FLAT16OUT) && FLAT16OUT == 0
  12.319 +#undef FLAT16OUT
  12.320 +#endif
  12.321 +#if defined(FLAT16) && FLAT16 == 0
  12.322 +#undef FLAT16
  12.323 +#endif
  12.324 +#include "uncompress.S"
  12.325 +
  12.326 +end: