# HG changeset patch # User Pascal Bellard # Date 1676557085 0 # Node ID a7a39e042b62908ac970abf194d4759b626281f9 # Parent 2956e54cc56ad84937a1d18be9051129c5949612 Add memtest64 diff -r 2956e54cc56a -r a7a39e042b62 memtest-efi32/receipt --- a/memtest-efi32/receipt Tue Feb 14 15:41:57 2023 +0000 +++ b/memtest-efi32/receipt Thu Feb 16 14:18:05 2023 +0000 @@ -1,7 +1,7 @@ # SliTaz package receipt. PACKAGE="memtest-efi32" -VERSION="6.01" +VERSION="6.10" CATEGORY="base-system" SHORT_DESC="Memory failures detection tool." MAINTAINER="pascal.bellard@slitaz.org" diff -r 2956e54cc56a -r a7a39e042b62 memtest-efi64/receipt --- a/memtest-efi64/receipt Tue Feb 14 15:41:57 2023 +0000 +++ b/memtest-efi64/receipt Thu Feb 16 14:18:05 2023 +0000 @@ -1,7 +1,7 @@ # SliTaz package receipt. PACKAGE="memtest-efi64" -VERSION="6.01" +VERSION="6.10" CATEGORY="base-system" SHORT_DESC="Memory failures detection tool." MAINTAINER="pascal.bellard@slitaz.org" diff -r 2956e54cc56a -r a7a39e042b62 memtest/receipt --- a/memtest/receipt Tue Feb 14 15:41:57 2023 +0000 +++ b/memtest/receipt Thu Feb 16 14:18:05 2023 +0000 @@ -66,7 +66,6 @@ # Rules to configure and make the package. compile_rules() { - # Need CPUID instruction (586+ cpu) sed -i 's|64, MT_VERSION "." GIT_HASH|65, MT_VERSION ".SliTaz"|;s|"\.x32"|".386"|' app/display.c sed 's|gcc|gcc-83|;s|march=i586|march=i486|' -i build32/Makefile patch -p0 < $stuff/memtest86\+-6-386.patch diff -r 2956e54cc56a -r a7a39e042b62 memtest64/receipt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/receipt Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,86 @@ +# SliTaz package receipt. + +PACKAGE="memtest64" +VERSION="6.10" +CATEGORY="base-system" +SHORT_DESC="Memory failures detection tool." +MAINTAINER="pascal.bellard@slitaz.org" +LICENSE="GPL2" +TARBALL="$PACKAGE-$VERSION.zip" +WEB_SITE="https://www.memtest.org/" # https://github.com/memtest86plus/memtest86plus/ +WGET_URL="https://memtest.org/download/v$VERSION/mt86plus_${VERSION}.binaries.zip" + +# What is the latest version available today? +current_version() +{ + wget -O - $WEB_SITE 2>/dev/null | \ + sed '/binaries.zip/!d;s|.*mt86plus_||;s|.binaries.zip.*||;q' +} + +asm() +{ + cc -o $1.o -Wa,-a=$1.lst -c $1.S + objcopy --only-section=.text -O binary $1.o $1.bin +} + +tune_lzma() +{ + file=$1 + shift + for i in lzma lz4x2 lzsa1x2 lzsa2x2 ; do + cp $stuff/*.S $stuff/pack . + sed "s/VERSION/$VERSION/;s|lzma1=|&nice=${1:-64},|" -i pack + while [ -n "$2" ]; do + sed "s|^#define PROP_$2 .*|#define PROP_$2 $3|" -i unlzma.S + shift 2 + done + sed -i "s|uncompress|un${i%x2}|" unpack.S + asm bootloader + asm unpack + cp pack pack.bak + ./pack --build bootloader.bin unpack.bin + PACKER=${i%x2} ./pack $file $file.${i%x2} + if [ $(stat -c %s $file.${i%x2}) -ge $((0x101F0)) ]; then + rm $file.${i%x2} + cp pack.bak pack + sed -e "s|^#define FLAT16.*// lzma case|#define FLAT16 0 // ${i%x2}|" -i unpack.S + asm unpack + ./pack --build bootloader.bin unpack.bin + PACKER=${i%x2} ./pack $file $file.${i%x2} + fi + mv unpack.lst unpack.lst.${i%x2} + if [ "${i#*x}" = "2" ]; then + cp pack.bak pack + sed -e "s|^#define DOUBLE_PACKED|#define DOUBLE_PACKED 1 // $i|" -i unpack.S + asm unpack + ./pack --build bootloader.bin unpack.bin + PACKER=${i%x2} ./pack $file $file.$i + mv unpack.lst unpack.lst.$i + fi + done +} + +# Rules to configure and make the package. +compile_rules() +{ + tune_lzma memtest64.bin 55,mf=bt2 LC 3 PB 2 +} + +# Rules to gen a SliTaz package suitable for Tazpkg. +genpkg_rules() +{ + mkdir -p $fs/boot + cp $src/memtest64.bin.lzma $fs/boot/memtest64.exe +} + +# Pre and post install commands for Tazpkg. +post_install() +{ + [ -s $1/boot/isolinux/isolinux.cfg ] && + ! grep -qs 'Check 64bits memory' $1/boot/isolinux/isolinux.cfg && sed -i \ +'s|LABEL md5|LABEL memtest64 mem64 ram64\ + MENU LABEL Check 64bits memory\ + KERNEL /boot/memtest64.exe\ +\n&|' $1/boot/isolinux/isolinux.cfg + true +} diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/bootloader.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/bootloader.S Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,684 @@ +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2. + +SYSSEG = 0x1000 +setup_sects = 497 +syssize = 500 +cmd_line_ptr = 0x228 + + .text + .code16 + .org 0 + .globl _start +_start: + +#define CODESZ 512 /* patched by installer */ + +// Default kernel format is 386 Image/zImage +//#define BZIMAGE 0x207 /* setup version ; for bzImage < 512 Kb only */ +//#define ELKS /* 8086/286 linux port */ + +/* some extra features */ +#define EXE_SUPPORT real mode dos .exe file support +208/264 +#define CMDLINE dos kernel cmdline support +45 +#define BUGGY_CMDLINE verify cmdline length +2 +#define VCPI VCPI 4.0 support (386+) +109 +#define SHUTDOWNDOS shutdown DOS services +29 +#define CHK_DOS_INT19 do not trace bios +12/13 + +/* some contraints to reduce the code size */ +//#define FLOPPY_1440K_ONLY 1.44M floppies support only -26 +//#define FLOPPY_HAS_2_SIDES hardcoded heads count to 2 -15 +//#define NO_CMDLINE_SHRINK remove heading spaces ? -6-21 +//#define NO_CMDLINE_FILE remove @cmdline file support ? -21 +#define NO_DOTS show progression dots ? -5 +#ifndef BZIMAGE +//#define TINY_ZIMAGE system < 64Kb ? -11 +//#define NO_MINSETUP default setup (dos only) ? -4 +//#define NO_CURSOR_DEFINITION -8 +#endif + +#ifdef ELKS + .arch i8086 +INITSEG = 0x0100 +SETUPSEG = 0x0120 +#define ONLY8086 +#undef BZIMAGE +#undef VCPI +#else +INITSEG = 0x9000 +SETUPSEG = 0x9020 +#endif + +.macro shlclw cnt,obj +#ifdef ONLY8086 + movb \cnt,%cl + shlw %cl,\obj +#else + shlw \cnt,\obj +#endif +.endm + +.macro shrclw cnt,obj +#ifdef ONLY8086 + movb \cnt,%cl + shrw %cl,\obj +#else + shrw \cnt,\obj +#endif +.endm + +#ifdef EXE_SUPPORT +#define EXEADRS(x) (x+0xE0) +#define FLAT20(x) (x+16*INITSEG) + +.macro trace_int19 +#ifdef ONLY8086 + xorw %si, %si + movw %si, %ds +# ifdef CHK_DOS_INT19 + cmpb $0xF0, 4*0x19+3(%si) + jne stepit + pushw %es + movw $skip_step19, %si + pushw %si + retf +stepit: +# endif + pushw 4+2(%si) + pushw 4(%si) + movw $step19, 4(%si) + movw $INITSEG, 4+2(%si) +#else + pushl $4 + popw %si + popw %ds +# ifdef CHK_DOS_INT19 + cmpb $0xF0, 4*0x19+3-4(%si) + jne stepit + pushw %es + pushw $skip_step19 + retf +stepit: +# endif + pushl (%si) + movl $step19+(INITSEG<<16), (%si) +#endif + pushfw + popw %ax + incb %ah # set TF + pushw %ax + popfw +#ifdef ONLY8086 + ljmp *4*0x19(%si) +#else + ljmp *4*0x19-4(%si) +#endif +.endm + +stacktop = 0x9E00 # in 0x8000 .. 0xA000 + decw %bp // Magic number: MZ + popw %dx + jmp start // Bytes on last page of file + .word (CODESZ+511)/512 // Pages in file INSTALLER + .word 0 // Relocations + .word (end_header-_start)/16 // Size of header in paragraphs + .word 4096 // Minimum extra paragraphs needed + .word -1 // Maximum extra paragraphs needed + .word (CODESZ+15)/16 // Initial (relative) SS value INSTALLER + .word stacktop // Initial SP value + .word 0 // Checksum INSTALLER? + .word EXEADRS(comstart) // Initial IP value + .word 0xFFF0 // Initial (relative) CS value +// .word 0x001C // File address of relocation table +// .word 0,0,0 // Overlay number +#else +#undef VCPI +#endif +start: + xorw %ax, %ax # %ax = 0 +zeroed = 12 # zeroed registers + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits +stacktop = 0x9E00 # in 0x8000 .. 0xA000 (+zeroed+12) +#ifdef ONLY8086 + movw $INITSEG, %bx +#else + pushw $INITSEG +#endif +end_header: + cld # assume nothing +#if defined(BZIMAGE) && BZIMAGE >= 0x202 + popw %es # %es contain INITSEG + movw %es, %di +#else + # cmdline offset at 0x22 + movw $stacktop, %di # stacktop is an arbitrary value >= + # length of bootsect + length of + # setup + room for stack; + # 12 is disk parm size. +# ifdef ONLY8086 + pushw %bx +# endif + popw %es # %es contain INITSEG +#endif + pushw %es + popw %ss # %es = %ss = INITSEG + movw %di, %sp # put stack at INITSEG:stacktop-... +#ifdef EXE_SUPPORT + cwd # force %dx = 0 (floppy only) +#endif + +# Many BIOS's default disk parameter tables will not recognize +# multi-sector reads beyond the maximum sector number specified +# in the default diskette parameter tables - this may mean 7 +# sectors in some cases. +# +# Since single sector reads are slow and out of the question, +# we must take care of this by creating new parameter tables +# (for the first disk) in RAM. We can set the maximum sector +# count to 36 - the most we will encounter on an ED 2.88. +# +# High doesn't hurt. Low does. Let's use the max: 63 + + rep # don't worry about cld + stosw # already done above + popw %bx # offset = 0 + popw %ds # %ds = 0 + + movb setup_sects+0x7C00, %al # read bootsector + setup (%ds = 0) + incw %ax + + ldsw 0x78(%bx), %si # %ds:%bx+0x78 is parameter table address + pushw %es + pushw %di + movb $6, %cl # copy 12 bytes + rep # don't worry about cld + movsw # already done above + movw %cx, %ds # %ds = 0 +#ifdef ONLY8086 + popw 0x78(%bx) # update parameter table address + popw 0x78+2(%bx) +#else + popl 0x78(%bx) # update parameter table address +#endif + pushw %ss + popw %ds # now %ds = %es = %ss = INITSEG + movb $63, 0x4-12(%di) # patch sector count, %di = stacktop + + xchg %ax, %di # sector count + popw %ax # limits = 0 + incw %cx # cylinder 0, sector 1, clear Z + call read_first_sectors # read setup + +# This routine loads the system at address LOADSEG, making sure +# no 64kB boundaries are crossed. We try to load it as fast as +# possible, loading whole tracks whenever we can. + + movw syssize, %di + decw %di + shrclw $9-4, %di + incw %di + movw $SYSSEG, %cx +#ifdef BZIMAGE + push %cx +#endif + call read_sectorsCX + +# This procedure turns off the floppy drive motor, so +# that we enter the kernel in a known state, and +# don't have to worry about it later. + +kill_motor: + xchgw %ax, %di # reset FDC (%di < 128) + int $0x13 + +# After that (everything loaded), we jump to the setup-routine +# loaded directly after the bootblock: +# Segments are as follows: %ds = %ss = INITSEG + +#ifdef BZIMAGE + popw %bx + popw %si // SYSSEG:0 +movesys: // %bx = DS, %si + movw $16, %ax + mulw %bx + addw %si, %ax + adcw $0x9300, %dx // %dx:%ax src flat address + movw $9, %cx +zero1: + pushw $0 // 2E..1E + loop zero1 + //pushl $0x93100000 // 1A: dest + pushw $0x9310 + pushw %cx + pushw $-1 // 18 + pushw %cx // 16 + pushw %dx // src + pushw %ax + pushw $-1 // 10 + movb $8, %cl + movw %cx, %bx // will move 8*64 = 512Kb +zero2: + pushw $0 // 0E..00 + loop zero2 + movw %sp, %si + pushw %ss + popw %es + pushw %es + popw %ds +syslp: + movb $0x80, %ch + movb $0x87, %ah + int $0x15 + incb 0x14(%si) + incb 0x1C(%si) + decw %bx + jne syslp +#endif +jmp_setup: + cli + ljmp $SETUPSEG, $0 + +#ifdef EXE_SUPPORT +#ifdef SHUTDOWNDOS +doiret: + iret +step19: + pushw %si + pushw %ds + movw %sp, %si + ldsw %ss:4(%si), %si + cmpw $0x19CD, (%si) + popw %ds + popw %si + jne doiret + xorw %si, %si + movw %si, %ds + pushw %cs + popw %ss + movw $stacktop-4-16, %sp +#ifdef ONLY8086 + popw 4(%si) + popw 4+2(%si) +skip_step19: + popw %bp + popw %di + popw %si + popw %dx + popw %cx + popw %bx + popw %ax +#else + popl 4(%si) +skip_step19: + popaw +#endif +#ifdef BZIMAGE + jmp movesys +#endif +#endif +#ifndef BZIMAGE +movesys: // %ax = SYSSEG, %bx = DS, %si + shrclw $4, %si + addw %si, %bx +#ifdef TINY_ZIMAGE + movw $0xFFFF, %cx + xorw %si, %si + xorw %di, %di + cmpw %ax, %bx + jnc forward + decw %si + decw %di + std +forward: + movw %ax, %es + movw %bx, %ds + rep + movsb + cld +#else + subw %ax, %bx + jnc forward + //movw $0x8FFF, %ax + movb $0x90, %ah +forward: + movw %ax, %es + movw %ax, %di + addw %bx, %di + movw %di, %ds + sbbw %di, %di // %di = 0 : -1 + cmc // C = 1 : 0 + adcw %di, %ax + xorw %si, %si + xorw %di, %di + movb $0x10, %cl + cmpb %cl, %ah // move 512k + rep + movsb + jns forward +#endif +#ifndef NO_CURSOR_DEFINITION + movb $1, %ah + movb $0, %bh + movb $0x20, %ch // 0x2000 + int $0x10 +#endif + pushw %ss + popw %ds + jmp jmp_setup +#endif +comstart: + cld # assume nothing +#ifdef ONLY8086 + movw $INITSEG, %ax + pushw %ax +#else + pushw $INITSEG +#endif + popw %es +#ifdef CMDLINE + movw %sp, %di + movw $0x80, %si + lodsb + cbw + xchgw %ax, %cx +#ifdef BUGGY_CMDLINE + test %cl, %cl # C=O=0, set S & Z + jng nocmdline # Z == 1 or O != S ? +#else + jcxz nocmdline +#endif +# if defined(BZIMAGE) && BZIMAGE >= 0x202 + movw $INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1) +# else + movw $0xA33F, 0x7F(%si) +# endif +# ifndef NO_CMDLINE_SHRINK +skipspace: + lodsb + cmpb $0x20, %al + je skipspace +# ifndef NO_CMDLINE_FILE + movw %si,%dx + decw %si + subb $'@',%al + jne notafile + movb $0x3D,%ah + int $0x21 + jc notafile + xchgw %ax,%bx + //movw %si,%dx // ~320 bytes max + movw $EXEADRS(notafile)-130,%cx + movb $0x3F,%ah + int $0x21 + xchgw %ax,%cx +notafile: +# else + decw %si +# endif +# endif + rep + movsb +nocmdline: + orb EXEADRS(setup_sects), %ch +# ifndef NO_MINSETUP +# ifndef BZIMAGE + jnz setupok + mov $4, %ch +setupok: +# endif +# endif +#else + movb EXEADRS(setup_sects), %ch +#endif + movb $(512-(end_header-_start))/2, %cl + movw $0x100, %si + movw $end_header, %di + rep + movsw + movw $SYSSEG, %ax + movw %ds, %bx + pushw %es + popw %ss +#ifndef SHUTDOWNDOS + pushw %es + pushw $movesys +#endif +#ifdef VCPI + pushaw + smsww %ax + andb $1, %al + je isrm + movw $EXEADRS(gdt_vcpi),%si + movw $pagebuf-0x90000,%di // %es = 0x9000 + movl $pagebuf+3,%es:0x1000(%di) +call_vcpi: + movb $0xDE,%ah // DE01, EBX = getiface(DS:SI, ES:DI) + int $0x67 + movl $FLAT20(sw2pm_params),%esi + movb $0x0C,%al // DE0C switchpm(ESI) + jmp call_vcpi +pm_code: + .byte 0x6A, SEL_DATA // pushw $SEL_DATA + popw %ss + movl %cr0,%eax + andl $0x7FFFFFFE,%eax + movl %eax,%cr0 + movl %eax,%cr3 +isrm: +# ifdef SHUTDOWNDOS + trace_int19 +# else + popaw + retf +# endif +#else +# ifdef SHUTDOWNDOS +# ifdef ONLY8086 + pushw %ax + pushw %bx + pushw %cx + pushw %dx + pushw %si + pushw %di + pushw %bp +# else + pushaw +# endif + trace_int19 +# endif + retf +#endif +#endif + +# read_sectors reads %di sectors into %es:0 buffer. +# %es:0 is updated to the next memory location. +# First, sectors are read sector by sector until +# sector per track count is known. Then they are +# read track by track. +# Assume no error on first track. + +#ifdef FLOPPY_1440K_ONLY +#ifndef FLOPPY_HAS_2_SIDES +#define FLOPPY_HAS_2_SIDES hardcore heads count to 2 +#endif +#define FLOPPY_SECTORS 18 /* 18 sectors */ +#else +#define FLOPPY_HEADS 2 /* 2 heads minimum */ +#endif + +return: +#ifndef NO_DOTS + movw $0xE2E,%ax + int $0x10 +#endif + ret + +check_limits: +#ifndef FLOPPY_1440K_ONLY + popw %dx + cmpb %al, %cl # max sector known ? + ja next_head # no -> store it +#ifndef FLOPPY_HAS_2_SIDES +#ifdef FLOPPY_HEADS + cmpb $FLOPPY_HEADS, %dh # 2 heads minimum + jb check_cylinder +#endif + cmpb %ah, %dh # max head known ? + ja next_cylinder # no -> store it +check_cylinder: +#endif + pushw %ax + cbw # %ah = 0 +#else + pushw %dx +#endif + int $0x13 # reset controler +#ifndef FLOPPY_1440K_ONLY + popw %ax + movb $1, %al # sector by sector... +#else + movw $1, %ax + jmp more1trk +#endif +read_sectorslp: + pushw %dx # some bios break dx... +#ifndef FLOPPY_1440K_ONLY + pushw %ax # limits + subb %cl, %al # sectors remaining in track + ja tolastsect + movb $1, %al # first track sector by sector +tolastsect: +#else + movb $FLOPPY_SECTORS+1, %al + subb %cl, %al # sectors remaining in track +#endif + cbw + cmpw %di, %ax + jb more1trk + movw %di, %ax # sectors to read +more1trk: + pushw %ax # save context + movb $2, %ah # cmd: read chs + int $0x13 +#ifndef FLOPPY_1440K_ONLY + popw %dx # save %ax + popw %ax # limits +#else + popw %ax # restore context + popw %dx +#endif + jc check_limits +#ifndef FLOPPY_1440K_ONLY + xchgw %ax, %bp + addw %dx,%cx # next sector + movw %cx, %si + pushw %dx + shlclw $5, %dx + movw %es, %cx + addw %dx, %cx + popw %dx + subw %dx,%di # update sector counter + popw %dx +#else + addw %ax,%cx # next sector + movw %cx, %si + pushw %ax + shlclw $5, %ax + movw %es, %cx + addw %ax, %cx + popw %ax + subw %ax,%di # update sector counter +#endif +read_sectorsCX: + movw %cx, %es # next location + jz return +read_sectors: + movw %si, %cx +#ifndef FLOPPY_1440K_ONLY +# al is last sector+1 +# ah is last head+1 + xchgw %ax, %bp +#endif +#ifndef FLOPPY_1440K_ONLY + cmpb %al,%cl # reach sector limit ? + jne bdendlp +next_head: + movb %cl,%al +#else + cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ? + jne bdendlp +#endif + movb $1,%cl # first sector +#ifndef FLOPPY_HAS_2_SIDES + incb %dh # next head + cmpb %ah, %dh # reach head limit ? + jne bdendlp +next_cylinder: + movb %dh,%ah + movb $0,%dh # first head +#else + xorb %cl,%dh # next head + jne bdendlp # reach head limit ? +#endif +# NOTE : support 256 cylinders max + incb %ch # next cylinder +read_first_sectors: +bdendlp: + jmp read_sectorslp + +#ifdef VCPI +pagebuf = 0x98000 +tss = gdt_abs-40 +gdt = gdt_abs-32 +gdt_null = gdt_abs-32 +gdt_vcpi = gdt_abs-24 +gdt_vcpi2 = gdt_abs-16 +gdt_vcpi3 = gdt_abs-8 +gdt_abs: +SEL_DATA = gdt_abs-gdt_null + .word 0xFFFF + .long 0x92000000 + .byte 0x8F,0 +gdt_code: + .word 0xFFFF +gdt_code_base: + .long 0x9A000000+FLAT20(0) + .byte 0x8F,0 +gdt_tss: + .word 0x00FF +gdt_tss_base: + .long 0x89000000+FLAT20(tss) + .byte 0,0 +gdtr: +gdt_lim: + .word 0xFFFF +gdt_base: + .long FLAT20(gdt) +sw2pm_params: +sw2pm_cr3: + .long pagebuf+0x1000 +sw2pm_gdtr_ptr: + .long FLAT20(gdtr) +sw2pm_idtr_ptr: + .long FLAT20(idtr) +sw2pm_ldtr: + .word 0 +sw2pm_tr: +SEL_TSS = gdt_tss-gdt_null + .word SEL_TSS +sw2pm_jumpaddr: + .long pm_code +SEL_CODE = gdt_code-gdt_null + .word SEL_CODE +idtr: +idt_lim: + .word 0x03FF +idt_base: + .long 0 +#endif +#ifdef ELKS + .org 0x1E3 + .byte 13,10,7 + .asciz "ELKS Boot" +#endif + .org 0x1F1 diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/pack --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/pack Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,101 @@ +#!/bin/sh +if [ "$1" == "--build" ]; then + set -- ${2:-bootloader.bin} ${3:-unpack.bin} + x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0 + x=$(grep -s setup_byte$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/XXXSB/$((513+0x$x))/" $0 || sed -i "/XXXSB/d" $0 + x=$(grep -s setup_word$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/XXXSW/$((514+0x$x))/" $0 || sed -i "/XXXSW/d" $0 + x=$(grep -s setup_para$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/XXXSP/$((514+0x$x))/" $0 || sed -i "/XXXSP/d" $0 + x=$(grep -s setup_seg$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0 + x=$(grep -s setup_keep$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + if [ -n "$x" ]; then + sed -i "s/XXXK2 //" $0 + else + x=$(grep -s setup_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + if [ -n "$x" ]; then + sed -i "s/XXXK2/bs=500 skip=1/" $0 + else + sed -i "s/XXXK2/bs=512 skip=1/" $0 + fi + fi + x=$(grep -s double_packed$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i "s/| compress /&& 2 /" $0 + x=$(grep -s update_code32_start$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i '/XXXU2/d; s| XXXU1||' $0 || sed -i '/XXXU1/d; s| XXXU2||' $0 + x=$(grep -s lzsa.block$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + [ -n "$x" ] && sed -i 's| XXXR||' $0 || sed -i 's| XXXR| -r|;s|tail -c +4|cat|' $0 + helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') + if [ -n "$helpmsg" ]; then + sed -i "s/YYY/$((0x$helpmsg))/" $0 + sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0 + else + sed -i '/YYY/d' $0 + fi + cat >> $0 < /dev/null | cat - $2 | gzip -9 | uuencode -m -) +EOT +EOM + sed -i '/--build/,/^fi/d' $0 + exit +fi + +store() +{ + n=$1 + for i in $(seq 1 ${4:-2}); do + printf '\\\\x%02X' $(($n & 255)) + n=$(($n >> 8)) + done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 +} + +bits() +{ + sed "/^#define PROP_$1/!d;s|.*PROP_...||" unlzma.S +} + +compress() +{ + case "$PACKER" in + lz4) lz4 -l --best | tail -c +5 ;; + 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 ;; + 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 ;; + *) xz -z -e --format=raw --lzma1=lc=$(bits LC),lp=$(bits LP),pb=$(bits PB) --stdout + esac +} + +main() +{ + uudecode | gunzip >$2 + dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc + setup="$(echo $(od -j 497 -N 1 -dAn $1))" + [ $setup -eq 0 ] && setup=4 + store $setup $2 497 1 + setup=$((setup+1)) + store $setup $2 XXXSB 1 + store $setup $2 XXXSW 1 + store $((32*setup+0xF000)) $2 XXXSP + store $((0x1000 - 32*setup)) $2 XXXSS + cp $1 /tmp/un$$ XXXU1 + store 1 /tmp/un$$ 534 1 XXXU1 + dd if=/tmp/un$$ XXXK2 | compress >>$2 XXXU1 + rm -f /tmp/un$$ XXXU1 + dd if=$1 XXXK2 | compress >>$2 XXXU2 + size=$(stat -c %s $2) + syssize=$(((size-512*setup+15)/16)) + store $((syssize + 0x1000 + 0x1000)) $2 XXXP + store $syssize $2 500 + store $(((size+511)/512)) $2 4 + store $(((size+15)/16)) $2 14 + echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ +} + +HELP="$(unix2dos </dev/null <> kNumBitModelTotalBits) * *(p); if (Code < bound) +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; +// +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ +// { UpdateBit0(p); mi <<= 1; A0; } else \ +// { UpdateBit1(p); mi = (mi + mi) + 1; A1; } +// +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) +// +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \ +// { int i = numLevels; res = 1; \ +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ +// res -= (1 << numLevels); } +/* + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3 + */ + +#define PROP_PB 2 +#define PROP_LP 0 +#define PROP_LC 3 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45)) + +// static const Byte *Buffer; +// static UInt32 bound, Code, Range; + +/* + * Buffer register DS:SI + * all var based ws=ss:bp + */ + +rep0 = -4 // long +rep1 = rep0-4 // long +rep2 = rep0-8 // long +rep3 = rep0-12 // long +state = -17 // byte, 0..11 +posState = state-1 // byte, 0..15 +posState2 = posState-1 // byte, 0..15 +scratched = rep0-16 // byte = 1 +Code = -24 // long +outStream = -28 // long +nowPos = outStream // long +Range = Code-8 // long +#define LOCALS 32 + +// int LzmaDecode(CLzmaDecoderState *vs, +// const unsigned char *inStream, +// unsigned char *outStream) +// { +// CProb *p = vs->Probs; +// SizeT nowPos = 0; +// #define posStateMask = (1 << (vs->Properties.pb)) - 1; +// #define literalPosMask = (1 << (vs->Properties.lp)) - 1; +// int lc = vs->Properties.lc, state = 0, len = 0; +// UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; +// +// { +// UInt32 i, numProbs = Literal /*1846*/ +// + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp)); +// for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1; + +#define WS (1846+(768<<(PROP_LC+PROP_LP))) +#if (WS+WS+LOCALS) >= 65000 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */ +#error invalid (lc,lp,pb) : out of memory +#endif + +ws1 = WS +ws2 = ws1*2 +ws = ws2+LOCALS+15 + +#ifndef FLAT32 +#define AX %ax +#define BX %bx +#define CX %cx +#define DX %dx +#define SI %si +#define DI %di +#define BP %bp +#define SP %sp +#define CWD cwd +#else +#define AX %eax +#define BX %ebx +#define CX %ecx +#define DX %edx +#define SI %esi +#define DI %edi +#define BP %ebp +#define SP %esp +#define CWD cdq +#endif +/* + * LzmaDecode: +#ifndef FLAT32 + * input ds:si=inStream, es:di=outStream + * output outStream[], ds:si, es:di + .code 16 +#else + * input esi=inStream, edi=outStream + * output outStream[], esi, edi + .code 32 +#endif + */ + + mov $ws1, CX +#ifdef ONLY8086 + .arch i8086 + movw $2048/2, %ax +lzd1: + pushw %ax +#else +lzd1: + pushw $2048/2 +#endif + loop lzd1 + mov SP, BP + movb $((LOCALS+3)/4)*2, %cl +#ifdef ONLY8086 + movw $1, %ax + cwd +initlocals: + pushw %dx + pushw %ax +#else +initlocals: + pushl $1 +#endif + loop initlocals + +#if !defined(FLAT32) && !defined(FLAT16OUT) + movb $4, %cl + movw %es, %bx + shrw %cl, %bx + movw %es, %dx + shlw %cl, %dx + addw %dx, %di + movw %di, outStream(%bp) + adcb %bh, outStream+2(%bp) + incw %cx +#else + movb $5, %cl + mov DI, outStream(BP) +#endif + +// Byte previousByte = 0; + xor BX, BX + +// #define RC_INIT(buffer) +// Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; +// { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }} +// } +// RC_INIT(inStream); + +#ifndef NO_LZMA_HEADER +#ifdef CHECK_LZMA_HEADER + cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1) + je lzip_header + cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8) + jne no_header + add $13-6, SI // skip lzma header +lzip_header: + add $6, SI // skip lzip header +no_header: +#else + add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8) +#endif +#endif +setrep: + call RC_LOAD_BYTE + decb Range(BP) + loop setrep + +lzdmainlp: +// while(1) { +// CProb *prob; +// int posState = (int)((nowPos) & posStateMask); +// +// prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState; +// if (Bit0(prob)) { /* char */ + + xor DX, DX + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) + mov $state, DI + jc lzdstring + +// prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * +// ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc)))); + +#if PROP_LC != 0 +# ifdef ONLY8086 + movb $8-PROP_LC, %cl + shrb %cl, %bl +# else + shrb $8-PROP_LC, %bl +# endif +#else + xor %bx,%bx +#endif + +#if PROP_LP != 0 + movb posState2(BP), %dl +# if PROP_LC != 0 +# ifdef ONLY8086 + movb $PROP_LC, %cl + shl %cl, DX +# else + shl $PROP_LC, DX +# endif + movb $0, %bh +# endif + add BX, DX +#endif + +#if PROP_LC == 0 && PROP_LP == 0 + mov $1846, AX +#else + movb $3, %ah + mul BX // dx = 3*bh + add $1846, AX +#endif + +// int symbol = 1; + + CWD + inc DX // symbol = 1 + xchg AX, CX // save prob + +// if (state >= kNumLitStates /*7*/) { /* previous was string */ +// if (state < 4) state = 0; + +lzd6z: + subb $3, (BP, DI) + +// if (state < 4) state = 0; + + jnc lzd6 + movb %dh, (BP, DI) // %dh = 0 + +lzd6: +// else if (state < 10) state -= 3; + + cmpb $10-3, (BP, DI) + +// else state -= 6; + + jnb lzd6z + cmpb $7-3-1, (BP, DI) + jbe lzd3 + +// int matchByte = outStream[nowPos - rep0]; + + call DicoRep02ESDI // %bl = outStream[nowPos - rep0]; + +// do { +// int bit; +// CProb *probLit; +// matchByte <<= 1; bit = (matchByte & 0x100); + + movb $1, %bh +lzd4: + shlb $1, %bl // matchByte <<= 1 + sbb DI, DI // save bit=C + +// probLit = prob + 0x100 + bit + symbol; + + mov CX, AX // restore prob + adcb %bh, %ah // + bit + 0x100 + +// RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break) + + call Bit1axdx // C,%ax = Bit1(prob+%ax) + rclb $1, %dl // symbol <<= 1; symbol |= C + jc lzd5 // if symbol >= 0x100 + cmp DI, AX + jz lzd4 // if bit == Bit1(prob+%ax) + +// } while (symbol < 0x100); +// } +lzd3: +// while (symbol < 0x100) { +// CProb *probLit = prob + symbol; +// RC_GET_BIT(probLit, symbol) +// } + + xor BX, BX + jmp lzd4 +lzd5: + +// outStream[nowPos++] = previousByte = (Byte)symbol; + + xchg AX, DX + call outchar // %bl = outStream[nowPos++] = %al; + jmp lzdmainlp + +// } + +lzdstring: + mov $1, CX + +// else { /* string */ +// prob = p + IsRep /*192*/ + state; + + movb $192, %dl + addb (BP, DI), %dl + mov $rep0, DI + +// if (Bit0(prob)) { + + call Bit1dx // Bit1(prob) + jc lzd8 + +// rep3 = rep2; rep2 = rep1; rep1 = rep0; +// state = (state < kNumLitStates /*7*/) ? 0 : 3; + + stc + +// prob = p + LenCoder /*818*/; + + mov $818, DX + +// } + + jmp lzd11a + +// else { +lzd8: +// prob += kNumStates /*12*/; +// if (Bit0(prob)) { + call Bit1dx12 // prob += 12; Bit1(prob) + jc lzd11 +// prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) +// + posState; + movb $240, %dl // dh=0 + +// if (Bit0(prob)) { + + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) + jc lzd12 + +// // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR; +// state = (state < kNumLitStates /*7*/) ? 9 : 11; + + movb $9, %dl + +// len++; goto string; + jmp lzd13string // ax = 0 +// } +// } +// else { +lzd11: +// UInt32 distance = rep1; +// prob += kNumStates /*12*/; +// if (!Bit0(prob)) { + + call Bit1dx12 // prob += 12; Bit1(prob) + jnc lzd11z + +// prob += kNumStates /*12*/; +// if (Bit0(prob)) distance = rep2; + + call Bit1dx12 // prob += 12; Bit1(prob) +lzd11a: + adcb %cl, %cl + +// else { distance = rep3; rep3 = rep2; } +// rep2 = rep1; +// } +// rep1 = rep0; rep0 = distance; + +lzd11z: +# ifdef ONLY8086 + shl $1, CX + shl $1, CX // 8->32 bits + sub CX, DI // &rep[cx] + movw (BP, DI), %ax + pushw 2(BP, DI) +rotreplp: + movb 4(BP, DI), %bl + movb %bl, (BP, DI) + inc DI + loop rotreplp + popw %bx + testb %dh, %dh + jnz lzd10 + movw %ax, (BP, DI) + movw %bx, 2(BP, DI) +# else + shl $2, CX // 8->32 bits + sub CX, DI // &rep[cx] + movl (BP, DI), %eax +rotreplp: + movb 4(BP, DI), %bl + movb %bl, (BP, DI) + inc DI + loop rotreplp + testb %dh, %dh + jnz lzd10 + movl %eax, (BP, DI) +# endif + +// } +lzd12: +// state = (state < kNumLitStates /*7*/) ? 8 : 11; + + movb $0x08, %cl + +// prob = p + RepLenCoder /*1332*/; + + mov $1332, DX + +// } +lzd10: + push CX // CX = 0 + +// { /* get len */ +// int numBits, offset; +// CProb *probLen = prob + LenChoice /*0*/; +// numBits = kLenNumLowBits /*3*/; + + movb $8, %cl // numBits : 3,3,8 + +// if (Bit0(probLen)) { + + call Bit1dx // Bit1(prob) + xchg AX, BX + inc DX + jnc lzd15 // bx=0 + +// probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/); +// offset = 0; +// } +// else { +// probLen = prob + LenChoice2 /*1*/; + + call Bit1dx // Bit1(prob) + add AX, BX + +#if PROP_PB != 0 + inc AX // ah=0 +#endif + jc lzd16 // %ax=0, %bx=-2 +lzd15: +#if PROP_PB != 0 + movb $8, %al + mulb posState(BP) +#endif + +// if (Bit0(probLen)) { +// probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/); + + movb $3, %cl // numBits : 3,3,8 +lzd16: +#if PROP_PB != 0 + add $2-128-1, AX // probLen : 2,130,258 +#else + mov $2-128-1, AX // probLen : 2,130,258 +#endif + add DX, AX + mov $-8+1, DX // offset : 0,8,16 +lzdargslp: + add $8, DX + add $128, AX + inc BX + jle lzdargslp // leave with bx=1 + +// offset = kLenNumLowSymbols /*8*/; +// //numBits = kLenNumMidBits /*3*/; +// } +// else { +// probLen = prob + LenHigh /*258*/; +// offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/; +// numBits = kLenNumHighBits /*8*/; +// } +// } +// RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset; + + push DX + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res + pop DX + add DX, AX // offset + pop DX // 0 +lzd13string: + push AX + +// state = (state < kNumLitStates /*7*/) ? dl : dl|3; + + movb $7, %cl + cmpb %cl, state(BP) + jb new_state + orb $3, %dl +new_state: + movb %dl, state(BP) + +// } /* get len */ +// if (state < 4) { + + cmpb $4-1, %dl + ja lzd19 + +// int posSlot; +// state += kNumLitStates /*7*/; + + addb %cl, state(BP) + +// prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? +// len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/); + + cmp $4+1, AX + jb lzd21 + mov $3+1, AX + +lzd21: + + dec CX // cx = 6 + shl %cl, AX + add $432-64, AX + +// RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot); + + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res + +// if (posSlot >= kStartPosModelIndex /*4*/) { +// int numDirectBits = ((posSlot >> 1) - 1); + +#ifndef FLAT32 + movw %cx, 2(%bp, %di) // %cx = 0 +#endif + mov AX, (BP, DI) + mov AX, CX + shrw $1, CX + dec CX + cmpb $4, %al + jb lzd22 + +// rep0 = (2 | ((UInt32)posSlot & 1)); + + andb %bl, (BP, DI) // %bx=1 + orb $2, (BP, DI) + +// if (posSlot < kEndPosModelIndex /*14*/) { + + cmpb $14, %al + jnb lzd23 + +// rep0 <<= numDirectBits; + + neg AX +# ifdef ONLY8086 + pushw %cx + movb $0, %ch +shllrep0: + shlw $1, (BP, DI) + rclw $1, 2(BP, DI) + loop shllrep0 + popw %cx +# else + shll %cl, (BP, DI) +# endif + add (BP, DI), AX + +// prob = p + SpecPos /*688*/ + rep0 - posSlot - 1; + + add $687, AX + jmp lzd24 + +// } +// else { +lzd23: +// numDirectBits -= kNumAlignBits /*4*/; +// do { +// RC_NORMALIZE; Range >>= 1; rep0 <<= 1; +// if (Code >= Range) { Code -= Range; rep0 |= 1; } + +lzd23z: + call RC_NORMALIZE +# ifdef ONLY8086 + pushw %dx + shrw $1, Range+2(BP) + rcrw $1, Range(BP) + movw Range(BP), %ax + movw Range+2(BP), %dx + cmpw Code+2(BP), %dx + ja lzd25 + jb lzd25x + cmpw Code(BP), %ax + ja lzd25 +lzd25x: + subw %ax, Code(BP) + sbbw %dx, Code+2(BP) + stc +lzd25: + popw %dx + rclw $1, (BP, DI) + rclw $1, 2(BP, DI) +# else + shrl $1, Range(BP) + movl Range(BP), %eax + cmpl Code(BP), %eax + ja lzd25 + subl %eax, Code(BP) + stc +lzd25: + rcll $1, (BP, DI) +# endif + +// } while (--numDirectBits != 0); + + cmpb $4+1, %cl + loopne lzd23z + +// prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/; +// rep0 <<= numDirectBits; + +# ifdef ONLY8086 + pushw %cx + movb $0, %ch +shlrep0: + shlw $1, (BP, DI) + rclw $1, 2(BP, DI) + loop shlrep0 + popw %cx +# else + shll %cl, (BP, DI) +# endif + mov $802, AX +// } + +lzd24: + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res + +// { +// int i = 1, mi = 1; +// do { +// CProb *prob3 = prob + mi; +// RC_GET_BIT2(prob3, mi, ; , rep0 |= i); + + orb %dh, (BP, DI) // update rep0 with DirectBits + +// i <<= 1; +// } while(--numDirectBits != 0); +// } +// } else rep0 = posSlot; +lzd22: +// if (++rep0 == (UInt32)(0)) break; /* EOF */ + +# ifdef ONLY8086 + incw (BP, DI) + jnz lzd19 + incw 2(BP, DI) +# else + incl (BP, DI) +# endif + +lzd19: + pop CX + jz lzdone + +// } +// len += kMatchMinLen;/*2*/ + + inc CX + +// string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR; +// do { +lzd13z: +// previousByte = outStream[nowPos - rep0]; +// outStream[nowPos++] = previousByte; + + call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0] + +// } while(--len != 0); + + loop lzd13z + +// } /* char/string */ +// } + + jmp lzdmainlp + +lzdone: +// //RC_NORMALIZE; +// //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos; +// return LZMA_RESULT_OK; + call Dico2ESDI // set es & di (rep0 = 0) + lea ws2(BP), SP // dealloc + ret +// } + +// al = outStream[nowPos - rep0]; + +/* + * output es:di, al + * scratch bh, cl, flags + */ + +DicoRep02ESDI: + stc + +// bl = outStream[nowPos]; + +/* + * output es:di, bl + * scratch bh, cl, flags + */ + +Dico2ESDI: +#if !defined(FLAT32) && !defined(FLAT16OUT) +# ifdef ONLY8086 + pushw %ax + movw nowPos(%bp), %bx + movw nowPos+2(%bp), %ax + jnc Dico2ESDIz + subw rep0(%bp), %bx + sbbw rep0+2(%bp), %ax +Dico2ESDIz: + movw $0xF, %di + andw %bx, %di + pushw %cx + movb $4, %cl + shrw %cl, %bx + shlw %cl, %ax + popw %cx + addb %al, %bh + popw %ax +# else + movl nowPos(%bp), %ebx + jnc Dico2ESDIz + subl rep0(%bp), %ebx +Dico2ESDIz: + movw %bx, %di + xorw %bx, %bx + shrl $4, %ebx +# endif + movw %bx, %es +#else + mov nowPos(BP), DI + jnc Dico2ESDIz + sub rep0(BP), DI +Dico2ESDIz: +#endif +#ifdef FLAT32 + movb (DI), %bl +#else + movb %es:(%di), %bl +#endif + ret + +outcharDico: + +// bl = outStream[nowPos++] = outStream[nowPos - rep0] + +/* + * output es:di, bl + * update nowPos + * scratch ax, dx, bh, cl, flags + */ + + call DicoRep02ESDI // %bl = outStream[nowPos - rep0] + xchg AX, BX +outchar: + +// bl = outStream[nowPos++] = previousByte = al; + +/* + * output bl + * update nowPos + * scratch ax, dx, bh, di, cl, flags + */ + + clc + call Dico2ESDI + stosb + xchg AX, BX // previous byte + +// int posState = (int)((nowPos) & posStateMask); + +#if PROP_PB != 0 && PROP_LP != 0 + addw $0x0101, posState2(BP) + andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP) +#else +# if PROP_PB != 0 + incb posState(BP) + andb $((1 << PROP_PB) -1), posState(BP) +# endif +# if PROP_LP != 0 + incb posState2(BP) + andb $((1 << PROP_LP) -1), posState2(BP) +# endif +#endif +#ifdef ONLY8086 + incw nowPos(BP) + jnz incnowPosDone + incw nowPos+2(BP) +incnowPosDone: +#else + incl nowPos(BP) +#endif + ret + +// +// #define RC_NORMALIZE if (Range < kTopValue) +// { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } + +/* + * update Range, Code, ds:si + * scratch flags + */ + +RC_NORMALIZE: + cmpb $0, Range+3(BP) + jne RC_NORMALIZE_1 +RC_LOAD_BYTE: + push AX +#ifdef ONLY8086 + movw Range+1(BP), %ax + movw %ax, Range+2(BP) + movw Code+1(BP), %ax + movw %ax, Code+2(BP) + xorw %ax, %ax + movb Range(BP), %ah + movw %ax, Range(BP) + movb Code(BP), %ah + movw %ax, Code(BP) +#else + shll $8, Range(BP) + shll $8, Code(BP) +#endif +#if !defined(FLAT16) && !defined(FLAT32) + testw %si, %si + jns RC_READ_BYTE + movw %ds, %ax + incw %ax + movw %ax, %ds + addw $-16, %si +RC_READ_BYTE: +#endif + lodsb + movb %al, Code(BP) + pop AX +RC_NORMALIZE_1: + ret + +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) + +Bit1state: + movb $16, %al + mulb state(BP) +# if PROP_PB != 0 + addb posState(BP), %al +# endif +Bit1axdx: + add DX, AX + jmp Bit1 + +// prob += 12; Bit1(prob) + +Bit1dx12: + add $12, DX +Bit1dx: + mov DX, AX + +// static int Bit1(CProb *p) + +Bit1: +/* + * input ax=p + * output C, ax + * update bound, Range, Code, ds:si + * scratch flags + */ + +// { +// RC_NORMALIZE; + + call RC_NORMALIZE // kill %ax, update %si + +#ifdef ONLY8086 + pushw %ax + pushw %cx + pushw %dx + pushw %di +#else + pushal +#endif + + xchg AX, DI + add DI, DI // short * + + +// bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p); + +#ifdef ONLY8086 + movw Range(BP), %dx + movw Range+2(BP), %ax + movw $11, %cx +shr11lp: + shrw $1, %ax + rcrw $1, %dx + loop shr11lp + movw %dx, %cx + mulw (BP, DI) + xchgw %ax, %cx + mulw (BP, DI) + addw %cx, %dx +#else + movl Range(BP), %eax + shrl $11, %eax + movzwl (BP, DI), %edx + mull %edx +#endif + +// if (Code < bound) { + +#ifdef ONLY8086 + cmpw Code+2(BP), %dx + jb Bit1_1 + ja Bit1_1x + cmpw Code(BP), %ax + jbe Bit1_1 +Bit1_1x: + +// Range = bound; + + movw %ax, Range(BP) + movw %dx, Range+2(BP) +#else + cmpl Code(BP), %eax + jbe Bit1_1 + +// Range = bound; + + movl %eax, Range(BP) +#endif + +// *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/; + + movw $2048, %ax + +// return 0; + + jmp Bit1_2 + +// } +// else { + +Bit1_1: + +// Range -= bound; Code -= bound; + +#ifdef ONLY8086 + subw %ax, Range(BP) + sbbw %dx, Range+2(BP) + subw %ax, Code(BP) + sbbw %dx, Code+2(BP) +#else + subl %eax, Range(BP) + subl %eax, Code(BP) +#endif + +// *(p) -= (*(p)) >> kNumMoveBits /*5*/; + + movw $31, %ax + +// return 1; + + stc +Bit1_2: + pushf + subw (BP, DI), %ax +#ifdef ONLY8086 + movb $5, %cl + sarw %cl, %ax +#else + sarw $5, %ax +#endif + addw %ax, (BP, DI) + popf +#ifdef ONLY8086 + popw %di + popw %dx + popw %cx + popw %ax +#else + popal +#endif + sbb AX, AX + +// } +// } + + ret + +RangeDecoder: + +/* + * input ax=probs cx=numLevels (< 8) bx=1 + * output ax=res (backward), dh (forward) + * update bound, Range, Code, ds:si + * scratch flags, cx=0, dl + */ + + push BX + +// { int i = numLevels; res = 1; + mov BX, DX // res = 1 + +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); + +RangeDecoder_1: + push AX + call Bit1axdx // C,%ax = Bit1(prob+%ax) + rclb $1, %dl // res <<= 1; res |= C + andb %bl, %al // current bit + orb %al, %bh // store in bh + shlb $1, %bl // update max + pop AX + loop RangeDecoder_1 + +// res -= (1 << numLevels); } + + xchg AX, BX // move bh to dh + xchg AX, DX // and dl to al + sub %dl, %al // sub max + pop BX + ret diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/unlzsa1.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/unlzsa1.S Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,197 @@ +// Lzsa1Decode: +#ifndef FLAT32 +// input ds:si=inStream, es:di=outStream +// output outStream[], ds:si, es:di + .code16 +#define AX %ax +#define BX %bx +#define SI %si +#define DI %di +#else +// input esi=inStream, edi=outStream +// output outStream[], ds:esi, es:edi + .code32 +#define AX %eax +#define BX %ebx +#define SI %esi +#define DI %edi +#endif + +MATCH_RUN_LEN = 15 +LITERALS_RUN_LEN = 7 +MIN_MATCH_SIZE = 3 +MIN_LITERALS_SIZE = 0 + +#define PACKED_ONLY // assume no copy block, optional +//#define PARANOIA // cover rare cases, optional + +lzsa1main: +#ifdef PARANOIA + cld +#endif +#ifdef FLAT16OUT +#define RAW_FORMAT +#endif +#ifndef RAW_FORMAT +# if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16) + xorw %cx, %cx + call normalize +# endif +# ifndef NO_LZSA1_HEADER + lodsw + cmpw $0x9E7B, %ax // magic + jne lzsa1main + lodsb + cmpb $0, %al // lzsa1 + jne lzsa1main +# endif +lzsa1block: // uncompress chunk + lodsw // block size + xchgw %ax, %cx + lodsb +# ifndef PACKED_ONLY + orb %al, %al + jns lzsa1compressed +# if !defined(FLAT32) && !defined(FLAT16OUT) + movw %cx, %dx + movb $0, %cl + movb $0, %dh +copytail: + call lzsa1movStr + xchg %dx, %cx + incw %cx + loop copytail +# else + movsb // copy block +copylp: + movsb // copy block + loop copylp // handle 64K case +# endif + jmp lzsa1block // end of block +lzsa1compressed: + jne lzsa1chunk // 64Kb block +# endif + jcxz lzsa1quit // bail if we hit EOD + pushw %cx +# if !defined(FLAT32) && !defined(FLAT16) + xorw %cx, %cx + call normalize +# define NeedNormalize +# endif + popw %dx + addw %si, %dx +#endif +lzsa1chunk: // uncompress chunk + lodsb // get token O|LLL|MMMM + movb %al, %bl // keep token in bl + shrb $4, %al // shift literals length into place + movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx + call lzsa1len // %ch = LITERALS_RUN_LEN +#if defined(NeedNormalize) + call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di +#else + rep movsb // copy %cx literals from %ds:%si to %es:%di +#endif +#ifndef RAW_FORMAT + cmpw %dx, %si + jae lzsa1block // bail if we hit EOD +#endif +#ifdef FLAT32 + orl $-1, %eax +#else + movb $-1, %ah +#endif + testb %bl, %bl // check match offset size in token (O bit) + jns lzsa1ShortOfs + lodsw + .byte 0x3C // mask lodsb with cmpb $0xAC, %al +lzsa1ShortOfs: + lodsb + xchg AX, BX // %bx: match offset %ax: original token + movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx + call lzsa1len +#ifdef RAW_FORMAT + jcxz lzsa1quit // bail if we hit EOD +#endif +#if !defined(FLAT32) && !defined(FLAT16OUT) + pushw %ds + pushw %si + movw %di, %si + addw %bx, %si + movw %es, %ax + jc axok + subb $0x10, %ah +axok: +.macro norm reg + movw %si, \reg + subw %si, %dx + andw $0xF, %si + addw %si, %dx + shrw $4, \reg + addw \reg, %ax + movw %ax, %ds + movw %di, \reg + andw $0xF, %di + shrw $4, \reg + movw %es, %ax + addw \reg, %ax + movw %ax, %es +.endm + pushw %dx +# if defined(NeedNormalize) || defined(PARANOIA) + call lzsa1movStr // copy string +# else + norm %bp + rep movsb +# endif + popw %dx + popw %si + popw %ds +#else + xchg AX, SI // save %si + lea (BX,DI), SI + rep movsb %es:(SI), %es:(DI) + xchg AX, SI // restore %si +#endif + jmp lzsa1chunk + +lzsa1len: // get length in %ecx + andb %ch, %al + cbw // clear %ah + cmpb %ch, %al + jne lzsa1minNumber // S=0-6, L=0-14 + lodsb + addb %ch, %cl +lzsa1minNumber: + addb %cl, %al + jnc lzsa1gotNumber // 0-255 + movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511 + jne lzsa1midNumber + lodsw // 0-65535 + .byte 0x3C // mask lodsb with cmpb $0xAC, %al +lzsa1midNumber: + lodsb +lzsa1gotNumber: + xchgw %ax, %cx +lzsa1quit: + ret + +#if defined(NeedNormalize) || defined(PARANOIA) +# if defined(PARANOIA) +lzsa1movlp: + decw %ch + rep movsb + incw %ch +# endif +normalize: +lzsa1movLit: + movw %ds, %ax +lzsa1movStr: + norm %bp +# if defined(PARANOIA) + cmpb $0xFF, %ch // catch FFFX case + je lzsa1movlp +# endif + rep movsb + ret +#endif diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/unlzsa2.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/unlzsa2.S Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,274 @@ +// Lzsa2Decode: +#ifndef FLAT32 +// input ds:si=inStream, es:di=outStream +// output outStream[], ds:si, es:di + .code16 +#define AX %ax +#define BX %bx +#define BP %bp +#define SI %si +#define DI %di +#else +// input esi=inStream, edi=outStream +// output outStream[], ds:esi, es:edi + .code32 +#define AX %eax +#define BX %ebx +#define BP %ebp +#define SI %esi +#define DI %edi +#endif + +MATCH_RUN_LEN = 7 +LITERALS_RUN_LEN = 3 +MIN_MATCH_SIZE = 2 +MIN_LITERALS_SIZE = 0 + +#define PACKED_ONLY // assume no copy block, optional +//#define PARANOIA // cover rare cases, optional + +lzsa2main: +#ifdef PARANOIA + cld +#endif +#ifdef FLAT16OUT +#define RAW_FORMAT +#endif +#ifndef RAW_FORMAT +# if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16) + xorw %cx, %cx + call normalize +# endif +# ifndef NO_LZSA2_HEADER + lodsw + cmpw $0x9E7B, %ax // magic + jne lzsa2main + lodsb + testb $0x20, %al // lzsa2 + je lzsa2main +# endif +lzsa2block: // uncompress chunk +# if !defined(FLAT32) && !defined(FLAT16) + xorw %cx, %cx + call normalize +# endif + lodsw // block size + xchgw %ax, %cx + lodsb +# ifndef PACKED_ONLY + orb %al, %al + jns lzsa2compressed +# if !defined(FLAT32) && !defined(FLAT16OUT) + movw %cx, %dx + movb $0, %cl + movb $0, %dh +copytail: + call lzsa1movStr + xchg %dx, %cx + incw %cx + loop copytail +# else + movsb // copy block +copylp: + movsb // copy block + loop copylp // handle 64K case +# endif + jmp lzsa2block // end of block +lzsa2compressed: + jne lzsa2chunk // 64Kb block +# endif + jcxz lzsa2quit // bail if we hit EOD +# if !defined(FLAT16) + pushw %cx + xorw %cx, %cx + call normalize +# define NeedNormalize + popw %dx + addw %si, %dx +# else + movw %si, %dx + addw %cx, %dx +# endif +#else +# if !defined(FLAT16) + xorw %cx, %cx + call normalize +# define NeedNormalize +# endif +#endif + movb $0, %bh // no nibble stored +lzsa2chunk: // uncompress chunk + lodsb // get token XYZ|LL|MMM + movb %al, %bl // keep token in bl + movw $LITERALS_RUN_LEN+256*MIN_LITERALS_SIZE, %cx + shrb %cl, %al // shift literals length into place + call lzsa2len // %cl = LITERALS_RUN_LEN +#if defined(NeedNormalize) + pushw %bp + call lzsa2movLit // copy %cx literals from %ds:%si to %es:%di + popw %bp +#else + rep movsb // copy %cx literals from %ds:%si to %es:%di +#endif +#ifndef RAW_FORMAT +maxsi: + cmpw %dx, %si + jae lzsa2block // bail if we hit EOD +#endif +#ifdef FLAT32 + orl $-1, %eax // set offset bits 31-8 to 1 +#else + movb $-1, %ah // set offset bits 15-8 to 1 +#endif +// XYZ + testb $0xC0, %bl // check match offset mode in token (X bit) + bt $5, %bx // move bit 5 to carry + js rep_match_or_large_offset + jne offset_9_bit +// 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. +// set bits 5-15 of the offset to 1. + call getByteFromNibbleAndC + jmp get_match_length +offset_9_bit: +// 01Z 9-bit offset: read a byte for offset bits 0-7 and use the inverted bit Z for bit 8 of the offset. +// set bits 9-15 of the offset to 1. + sbbb %cl, %ah // clear bit 8 if Z bit is clear + jmp get_match_length_0 + +getNibble: + xorb $0xF0, %bh // toggle nibble stored flags + movb %bh, %al + jns gotnibble + lodsb + movb $0xF0, %bh + orb %al, %bh + shrb $4, %al +gotnibble: +lzsa2quit: + ret + +rep_match_or_large_offset: + jpe rep_match_or_16_bit +//10Z 13-bit offset: read a nibble for offset bits 9-12 and use the inverted bit Z for bit 8 of the offset, +// then read a byte for offset bits 0-7. set bits 13-15 of the offset to 1. +// substract 512 from the offset to get the final value. + call getByteFromNibbleAndC + subb $2, %al // substract 512 + jmp get_match_length_1 +rep_match_or_16_bit: + jc repeat_match // rep-match +//110 16-bit offset: read a byte for offset bits 8-15, then another byte for offset bits 0-7. + lodsb // Get 2-byte match offset +get_match_length_1: + xchgb %al, %ah +get_match_length_0: + lodsb // load match offset bits 0-7 +get_match_length: + xchgw %ax, %bp // bp: offset +repeat_match: +//111 repeat offset: reuse the offset value of the previous match command. + + movb %bl, %al // %al: original token + movw $MATCH_RUN_LEN+256*MIN_MATCH_SIZE, %cx + call lzsa2len +#ifdef RAW_FORMAT + jcxz lzsa2quit // bail if we hit EOD +#endif +#if !defined(FLAT32) && !defined(FLAT16OUT) + pushw %ds + pushw %si + movw %di, %si + addw %bp, %si + movw %es, %ax + jc axok + subb $0x10, %ah +axok: +.macro norm reg + movw %si, \reg + subw %si, %dx + andw $0xF, %si + addw %si, %dx + shrw $4, \reg + addw \reg, %ax + movw %ax, %ds + movw %di, \reg + andw $0xF, %di + shrw $4, \reg + movw %es, %ax + addw \reg, %ax + movw %ax, %es +.endm + pushw %bp + pushw %dx +# if defined(NeedNormalize) || defined(PARANOIA) + call lzsa2movStr // copy string +# else + norm %bp + rep movsb +# endif + popw %dx + popw %bp + popw %si + popw %ds +#else + xchg AX, SI // save %si + lea (BP,DI), SI + rep movsb %es:(SI), %es:(DI) + xchg AX, SI // restore %si +#endif + jmp lzsa2chunk + +getByteFromNibbleAndC: + pushfw + call getNibble // get nibble for offset bits 0-3 + popfw + rclb $1, %al + xorb $0xE1, %al // set offset bits 7-5 to 1 + ret + +lzsa2len: // get length in %cx + andb %cl, %al + cbw // clear %ah + cmpb %al, %cl + jne lzsa2minNumber // S=0-2, L=0-6 + call getNibble + cmp $0xF, %al + jne lzsa2noExtraByte + addb %al, %ch + lodsb +lzsa2noExtraByte: + addb %cl, %ch +lzsa2minNumber: + addb %ch, %al + jnc lzsa2gotNumber // 0-255 +#if 0 + je lzsa2BigNumber + movb %al, %ah // S=256-767, L=256-1791 + lodsb + .byte 0xB1 // mask lodsw with movb $0xAD, %cl +lzsa2BigNumber: +#endif + lodsw // 0-65535 +lzsa2gotNumber: + xchgw %ax, %cx + ret + +#if defined(NeedNormalize) || defined(PARANOIA) +# if defined(PARANOIA) +lzsa2movlp: + decw %ch + rep movsb + incw %ch +# endif +normalize: +lzsa2movLit: + movw %ds, %ax +lzsa2movStr: + norm %bp +# if defined(PARANOIA) + cmpb $0xFF, %ch // catch FFFX case + je lzsa2movlp +# endif + rep movsb + ret +#endif diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/unpack.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/unpack.S Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,323 @@ +#define SYSTEM 0x10000 +#define SETUP 14 +#define SYSSIZE 0x1F4 +#define SETUPSIZE 0x1F1 + +#define KEEP_BOOTSECTOR 0 +#define LINUX_HEADER 0 +#define UPDATE_SYSSIZE 0 +#define FLAT16 1 // lzma case +#define FLAT16OUT 0 +#define COPYTOHIGHMEM 0 +#define UPDATE_CODE32_START 1 +#define DOUBLE_PACKED 0 +#define SAVEREGS 0 +#define ELKS 0 + + .text + .code16 + .org 0 + +#if KEEP_BOOTSECTOR +#undef UPDATE_SYSSIZE +#define UPDATE_SYSSIZE 0 +#endif +#if ELKS + .arch i8086 +#define FLAT16 1 +#define KEEP_BOOTSECTOR 1 +#define LINUX_HEADER 0 +#define SAVEREGS 0 +#define TOPSEG 0x2000 +#else +#define TOPSEG 0x8000 +#endif + +.macro pusham +#if ELKS + pushw %ax +// movw %sp, %ax +// incw %ax // emulate popa behaviour +// incw %ax + pushw %cx + pushw %dx + pushw %bx +// pushw %ax // %sp + pushw %bp + pushw %si + pushw %di +#else + pushaw +#endif +.endm + +.macro popam +#if ELKS + popw %di + popw %si + popw %bp +// popw %ax + popw %bx + popw %dx + popw %cx + popw %ax +#else + popaw +#endif +.endm + +.macro pushm val +#if ELKS + movw \val, %ax + pushw %ax +#else + pushw \val +#endif +.endm + +.macro shrwm cnt, reg +#if ELKS + .rept \cnt + shrw $1, \reg + .endr +#else + shrw $\cnt, \reg +#endif +.endm + + .globl _start +_start: +#if LINUX_HEADER + jmp start2 + .ascii "HdrS" // 202 magic + .word 0x200 // 206 version 2.00 + .long 0 // 208 realmode_swtch + .word SYSTEM/16 // 20C start_sys_seg + .word 0 // 20E kernel_version + .byte 0 // 210 type_of_loader + .byte 0 // 211 loadflags + .word 0 // 212 setup_move_size + .long SYSTEM // 214 code32_start + .long 0 // 218 ramdisk_image + .long 0 // 21C ramdisk_size + .long 0 // 220 bootsect_kludge +start2: +#endif +#if SAVEREGS + pushfw + pushw %cs + pushw $0 + pusham + xorw %si, %si + pushw %ds + pushw %es + cld +#else + pushw %cs // return adress is %cs:0 + xorw %si, %si + pushw %si +#endif // SAVEREGS + pushw %ds // bootsector+setup segment +#if FLAT16 +# 1- move 9000..9020+stp -> TOPSEG + pushm $TOPSEG + popw %es +# if SAVEREGS +setup_word: + movw $SETUP*256+256, %cx + pushw %cx // bootsector+setup words +# endif + pushw %es // TOPSEG + pushw %es +# if SAVEREGS + xorw %di, %di // %ds:%si = 9000:0000 %es:%di = TOPSEG:0 + pushm $0x200+cont + rep + movsw + lret +cont: +# else + movw $-0x200, %di + call jumpinto +# endif +# 2- move 1000..1000+sys -> TOPSEG+stp + pushm $0x1000 + popw %ds + xorw %si, %si // %ds:%si = 1000:0 + subw %di, %cx // %cx = 64K - setupsz + rep + movsb +# 3- unlz(TOPSEG+stp:end, 1000-stp:0) +setup_seg: + pushm $0x1000-(SETUP*32)-32 + popw %es +#else // FLAT16 +# 1- move 9020..9020+unpack -> 0700 and jump into + movw $0x700, %cx // Up to 3.5KB for unpacker (unlzma is << 1KB) + movw %cx, %es // Use 7000 .. 7E00, keep up to 23 elks setup sectors + pushw %es + xorw %di, %di // %ds:%si = 9000:0000 %es:%di = 0700:0000 + pushm $0x200+cont +# if SAVEREGS + rep + movsw + lret +# else + jmp jumpinto +# endif +cont: +# 2- move 9020..9020+stp -> 9000-sys-stp + movw %ds, %dx +setup_byte: + movb $SETUP+1, %ch +setup_para: + subw $SETUP*32+32+0xF000, %dx +packed_syssize: + movw $0+0x1000, %ax + pushw %cx // bootsector+setup words + subw %ax, %dx + movw %dx, %es + pushw %es // 9000-sys-stp + xorw %si, %si + xorw %di, %di // %ds:%si = 9000:0 %es:%di = 9000-sys-stp:0 + rep + movsw +# 3- move 1000..1000+sys -> 9000-sys + movw %ds, %dx +mvsys: + decw %ax + decw %dx + movw %ax, %ds + movw %dx, %es + xorw %si, %si + xorw %di, %di + movw $8, %cx + rep + movsw + cmpw $0x1000, %ax + jne mvsys +# 4- unlz(9000-sys-stp:end, 1000-stp:0) +setup_seg: + pushm $0x1000-(SETUP*32)-32 + popw %es +#endif // FLAT16 + popw %ds // +#if FLAT16 && SAVEREGS == 0 + movw $end-_start, %si // %ds:%si = TOPSSEG:compressed +#else + movw $0x200+end-_start, %si // %ds:%si = 9000-sys-stp:compressed +#endif +#if KEEP_BOOTSECTOR +setup_keep: + xorw %di, %di +#else +# if UPDATE_SYSSIZE +setup_syssize: + movw $0x1F4, %di // %es:%di = 1000-setup-bootsector:SYSSIZE +# else + movw $0x200, %di +# endif +#endif + pushw %di + pushw %es +#if DOUBLE_PACKED +double_packed: + pushm $0x4000 + popw %es + pushw %di + pushw %es + call unpack + popw %ds + popw %si + popw %es + popw %di + pushw %di + pushw %es +#endif + call unpack +#if COPYTOHIGHMEM +# if FLAT16OUT + movw $0x9310+1, %ax // from 1000:FFFF +# else +# if 0 + movw %es, %ax + shrw $12, %ax + orw $0x9310, %ax +# else + movw $0x9310+7, %ax // from 7000:FFFF +# endif +# endif + pushw %ss + popw %es + movw $8, %cx +zero1: + pushw $0 // 2E..20 + loop zero1 +src: + pushw %cx // 1E, 16 + pushw %ax // 1A: dst %ax:%cx, 12: src %ax:%cx + pushw %cx + pushw $-1 // 18, 10: full 64K segment + subb $0x10, %al + jnc src + movb $8, %cl +zero2: + pushw $0 // 0E..00 + loop zero2 + movw %sp, %si +syslp: + movb $0x80, %ch + movb $0x87, %ah + int $0x15 +# if FLAT16OUT == 0 + decb %es:0x1C(%si) + decb %es:0x14(%si) + jne syslp // down to 1000:0000 +# endif + addw $0x30, %sp +#endif // COPYTOHIGHMEM + popw %ds + popw %si // %ds:%si = 1000-setup-bootsector:SYSSIZE / 0 +#if UPDATE_CODE32_START +update_code32_start: +// movb $1, 0x216 +#endif +#if FLAT16 == 0 || SAVEREGS + popw %cx // bootsector+setup words +#endif + popw %es // bootsector+setup segment + movw %si, %di +jumpinto: +#if FLAT16 && SAVEREGS == 0 +setup_word: + movw $SETUP*256+256, %cx +#endif +# 5- move 1000-stp..1000 -> 9000 + rep + movsw +#if SAVEREGS + popw %es + popw %ds + popam + iret +#else + lret +#endif + +unpack: +#define NO_LZMA_HEADER +#define NO_LZSA2_HEADER +#define NO_LZSA1_HEADER +#define NO_LZ4_HEADER +#if ELKS +#define ONLY8086 1 +#endif +#if defined(FLAT16OUT) && FLAT16OUT == 0 +#undef FLAT16OUT +#endif +#if defined(FLAT16) && FLAT16 == 0 +#undef FLAT16 +#endif +#include "uncompress.S" + +end: diff -r 2956e54cc56a -r a7a39e042b62 memtest64/stuff/unpackx.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest64/stuff/unpackx.S Thu Feb 16 14:18:05 2023 +0000 @@ -0,0 +1,323 @@ +#define SYSTEM 0x10000 +#define SETUP 14 +#define SYSSIZE 0x1F4 +#define SETUPSIZE 0x1F1 + +#define KEEP_BOOTSECTOR 0 +#define LINUX_HEADER 0 +#define UPDATE_SYSSIZE 1 +#define FLAT16 1 // lzma case +#define FLAT16OUT 0 +#define COPYTOHIGHMEM 0 +#define UPDATE_CODE32_START 0 +#define DOUBLE_PACKED 0 +#define SAVEREGS 0 +#define ELKS 0 + + .text + .code16 + .org 0 + +#if KEEP_BOOTSECTOR +#undef UPDATE_SYSSIZE +#define UPDATE_SYSSIZE 0 +#endif +#if ELKS + .arch i8086 +#define FLAT16 1 +#define KEEP_BOOTSECTOR 1 +#define LINUX_HEADER 0 +#define SAVEREGS 0 +#define TOPSEG 0x2000 +#else +#define TOPSEG 0x8000 +#endif + +.macro pusham +#if ELKS + pushw %ax +// movw %sp, %ax +// incw %ax // emulate popa behaviour +// incw %ax + pushw %cx + pushw %dx + pushw %bx +// pushw %ax // %sp + pushw %bp + pushw %si + pushw %di +#else + pushaw +#endif +.endm + +.macro popam +#if ELKS + popw %di + popw %si + popw %bp +// popw %ax + popw %bx + popw %dx + popw %cx + popw %ax +#else + popaw +#endif +.endm + +.macro pushm val +#if ELKS + movw \val, %ax + pushw %ax +#else + pushw \val +#endif +.endm + +.macro shrwm cnt, reg +#if ELKS + .rept \cnt + shrw $1, \reg + .endr +#else + shrw $\cnt, \reg +#endif +.endm + + .globl _start +_start: +#if LINUX_HEADER + jmp start2 + .ascii "HdrS" // 202 magic + .word 0x200 // 206 version 2.00 + .long 0 // 208 realmode_swtch + .word SYSTEM/16 // 20C start_sys_seg + .word 0 // 20E kernel_version + .byte 0 // 210 type_of_loader + .byte 0 // 211 loadflags + .word 0 // 212 setup_move_size + .long SYSTEM // 214 code32_start + .long 0 // 218 ramdisk_image + .long 0 // 21C ramdisk_size + .long 0 // 220 bootsect_kludge +start2: +#endif +#if SAVEREGS + pushfw + pushw %cs + pushw $0 + pusham + xorw %si, %si + pushw %ds + pushw %es + cld +#else + pushw %cs // return adress is %cs:0 + xorw %si, %si + pushw %si +#endif // SAVEREGS + pushw %ds // bootsector+setup segment +#if FLAT16 +# 1- move 9000..9020+stp -> TOPSEG + pushm $TOPSEG + popw %es +# if SAVEREGS +setup_word: + movw $SETUP*256+256, %cx + pushw %cx // bootsector+setup words +# endif + pushw %es // TOPSEG + pushw %es +# if SAVEREGS + xorw %di, %di // %ds:%si = 9000:0000 %es:%di = TOPSEG:0 + pushm $0x200+cont + rep + movsw + lret +cont: +# else + movw $-0x200, %di + call jumpinto +# endif +# 2- move 1000..1000+sys -> TOPSEG+stp + pushm $0x1000 + popw %ds + xorw %si, %si // %ds:%si = 1000:0 + subw %di, %cx // %cx = 64K - setupsz + rep + movsb +# 3- unlz(TOPSEG+stp:end, 1000-stp:0) +setup_seg: + pushm $0x1000-(SETUP*32)-32 + popw %es +#else // FLAT16 +# 1- move 9020..9020+unpack -> 0700 and jump into + movw $0x700, %cx // Up to 3.5KB for unpacker (unlzma is << 1KB) + movw %cx, %es // Use 7000 .. 7E00, keep up to 23 elks setup sectors + pushw %es + xorw %di, %di // %ds:%si = 9000:0000 %es:%di = 0700:0000 + pushm $0x200+cont +# if SAVEREGS + rep + movsw + lret +# else + jmp jumpinto +# endif +cont: +# 2- move 9020..9020+stp -> 9000-sys-stp + movw %ds, %dx +setup_byte: + movb $SETUP+1, %ch +setup_para: + subw $SETUP*32+32+0xF000, %dx +packed_syssize: + movw $0+0x1000, %ax + pushw %cx // bootsector+setup words + subw %ax, %dx + movw %dx, %es + pushw %es // 9000-sys-stp + xorw %si, %si + xorw %di, %di // %ds:%si = 9000:0 %es:%di = 9000-sys-stp:0 + rep + movsw +# 3- move 1000..1000+sys -> 9000-sys + movw %ds, %dx +mvsys: + decw %ax + decw %dx + movw %ax, %ds + movw %dx, %es + xorw %si, %si + xorw %di, %di + movw $8, %cx + rep + movsw + cmpw $0x1000, %ax + jne mvsys +# 4- unlz(9000-sys-stp:end, 1000-stp:0) +setup_seg: + pushm $0x1000-(SETUP*32)-32 + popw %es +#endif // FLAT16 + popw %ds // +#if FLAT16 && SAVEREGS == 0 + movw $end-_start, %si // %ds:%si = TOPSSEG:compressed +#else + movw $0x200+end-_start, %si // %ds:%si = 9000-sys-stp:compressed +#endif +#if KEEP_BOOTSECTOR +setup_keep: + xorw %di, %di +#else +# if UPDATE_SYSSIZE +setup_syssize: + movw $0x1F4, %di // %es:%di = 1000-setup-bootsector:SYSSIZE +# else + movw $0x200, %di +# endif +#endif + pushw %di + pushw %es +#if DOUBLE_PACKED +double_packed: + pushm $0x4000 + popw %es + pushw %di + pushw %es + call unpack + popw %ds + popw %si + popw %es + popw %di + pushw %di + pushw %es +#endif + call unpack +#if COPYTOHIGHMEM +# if FLAT16OUT + movw $0x9310+1, %ax // from 1000:FFFF +# else +# if 0 + movw %es, %ax + shrw $12, %ax + orw $0x9310, %ax +# else + movw $0x9310+7, %ax // from 7000:FFFF +# endif +# endif + pushw %ss + popw %es + movw $8, %cx +zero1: + pushw $0 // 2E..20 + loop zero1 +src: + pushw %cx // 1E, 16 + pushw %ax // 1A: dst %ax:%cx, 12: src %ax:%cx + pushw %cx + pushw $-1 // 18, 10: full 64K segment + subb $0x10, %al + jnc src + movb $8, %cl +zero2: + pushw $0 // 0E..00 + loop zero2 + movw %sp, %si +syslp: + movb $0x80, %ch + movb $0x87, %ah + int $0x15 +# if FLAT16OUT == 0 + decb %es:0x1C(%si) + decb %es:0x14(%si) + jne syslp // down to 1000:0000 +# endif + addw $0x30, %sp +#endif // COPYTOHIGHMEM + popw %ds + popw %si // %ds:%si = 1000-setup-bootsector:SYSSIZE / 0 +#if UPDATE_CODE32_START +update_code32_start: +// movb $1, 0x216 +#endif +#if FLAT16 == 0 || SAVEREGS + popw %cx // bootsector+setup words +#endif + popw %es // bootsector+setup segment + movw %si, %di +jumpinto: +#if FLAT16 && SAVEREGS == 0 +setup_word: + movw $SETUP*256+256, %cx +#endif +# 5- move 1000-stp..1000 -> 9000 + rep + movsw +#if SAVEREGS + popw %es + popw %ds + popam + iret +#else + lret +#endif + +unpack: +#define NO_LZMA_HEADER +#define NO_LZSA2_HEADER +#define NO_LZSA1_HEADER +#define NO_LZ4_HEADER +#if ELKS +#define ONLY8086 1 +#endif +#if defined(FLAT16OUT) && FLAT16OUT == 0 +#undef FLAT16OUT +#endif +#if defined(FLAT16) && FLAT16 == 0 +#undef FLAT16 +#endif +#include "uncompress.S" + +end: