# HG changeset patch # User Pascal Bellard # Date 1620494599 0 # Node ID 8da769e5f6c39861c7d08eaa82430aa41b92af14 # Parent da3ed5ef7be833500618eda29071cff26ea66c3b Add x86test & tfttest diff -r da3ed5ef7be8 -r 8da769e5f6c3 tfttest/receipt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tfttest/receipt Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,39 @@ +# SliTaz package receipt. + +PACKAGE="tfttest" +VERSION="1.01" +CATEGORY="base-system" +SHORT_DESC="CHZ Monitor-Test is a dead pixel detection tool." +MAINTAINER="pascal.bellard@slitaz.org" +LICENSE="GPL2" +WEB_SITE="http://www.slitaz.org/" +TARGET="i486" + +# Rules to configure and make the package. +compile_rules() +{ + mkdir -p $src/mnt && cd $src + mount -o ro,loop $stuff/tfttest.img mnt + cp mnt/* . + cp $stuff/bootloader.S . + for i in bootloader ; do + cc -o $i.o -Wa,-a=$i.lst -c $i.S + objcopy -O binary $i.o $i.bin + done + dd if=TFTTEST.COM of=bootloader.bin bs=16 seek=6 conv=notrunc 2> /dev/null + umount mnt +} + +# Rules to gen a SliTaz package suitable for Tazpkg. +genpkg_rules() +{ + mkdir -p $fs/boot + cp $src/bootloader.bin $fs/boot/$PACKAGE +} + +# Post install/remove commands for Tazpkg. +post_install() +{ + grep -qs ^tfttest $1/boot/bootmenu || + echo "tfttest Tfttest,pixel,tft Check dead pixels (may run under DOS if renamed to tfttest.com)" >> $1/boot/bootmenu +} diff -r da3ed5ef7be8 -r 8da769e5f6c3 tfttest/stuff/bootloader.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tfttest/stuff/bootloader.S Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,59 @@ + .text + .code16 + .arch i8086 + .org 0 + .globl _start +_start: + call start2 +start2: + popw %bx + cmpb $0x1, %bh + je dotcom + xorw %ax, %ax # %ax = 0 + movw %ax, %ds + leaw int21-start2(%bx), %ax + movw %ax,0x21*4 + movw %cs,0x21*4+2 + movw $0x7C0-0x10, %ax + movw %ax, %ds +dotcom: + movw %ds, %ax + addw $6, %ax # addw $code/16, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %ss + movw $0xFFFE, %sp + pushw %ds + movw $0x100, %ax + pushw %ax + cbw + xorw %bx, %bx + retf + +int21: + cmpb $7, %ah + jne not_input + movb $0, %ah + int $0x16 +do_iret: + iret +not_input: + cmpb $9, %ah + jne abort + movw %dx, %si +puts: + lodsb + cmpb $'$', %al + je do_iret + movb $0xe, %ah + movw $0xf, %bx + int $0x10 + jmp puts +abort: + ljmp $0xffff,$0 + + .org 0x60 +code: + .org 510 + + .word 0xaa55 diff -r da3ed5ef7be8 -r 8da769e5f6c3 tfttest/stuff/tfttest.img Binary file tfttest/stuff/tfttest.img has changed diff -r da3ed5ef7be8 -r 8da769e5f6c3 x86test/receipt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x86test/receipt Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,42 @@ +# SliTaz package receipt. + +PACKAGE="x86test" +VERSION="0.10a" +CATEGORY="base-system" +SHORT_DESC="CPU failures detection tool." +MAINTAINER="pascal.bellard@slitaz.org" +LICENSE="GPL2" +WEB_SITE="http://www.slitaz.org/" +TARGET="i486" + +BUILD_DEPENDS="xz" + +# Rules to configure and make the package. +compile_rules() +{ + mkdir -p $src && cd $src + cp $stuff/x86test $stuff/*.S $stuff/pack . + sed -i '/#define ONLY8086/d' unpack.S + for i in bootloader unpack ; do + cc -o $i.o -Wa,-a=$i.lst -c $i.S + objcopy -O binary $i.o $i.bin + done + sed -i "s/VERSION/$VERSION/" pack + ./pack --build bootloader.bin unpack.bin + ./pack x86test x86test.packed + dd if=bootloader.bin of=x86test conv=notrunc 2> /dev/null +} + +# Rules to gen a SliTaz package suitable for Tazpkg. +genpkg_rules() +{ + mkdir -p $fs/boot + cp $src/x86test.packed $fs/boot/$PACKAGE +} + +# Post install/remove commands for Tazpkg. +post_install() +{ + grep -qs ^x86test $1/boot/bootmenu || + echo "x86test X86test,cpu,x86 Check X86 CPU (may run under DOS if renamed to x86test.exe)" >> $1/boot/bootmenu +} diff -r da3ed5ef7be8 -r 8da769e5f6c3 x86test/stuff/bootloader.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x86test/stuff/bootloader.S Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,659 @@ +// 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 */ +#define ONLY8086 + +/* some extra features */ +#define EXE_SUPPORT real mode dos .exe file support +208/264 +#define CMDLINE dos kernel cmdline support +45 +//#define VCPI VCPI 4.0 support (386+) +109 +#define SHUTDOWNDOS shutdown DOS services +29 + +/* 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 +INITSEG = 0x0100 +SETUPSEG = 0x0120 +#define ONLY8086 +#undef BZIMAGE +#undef VCPI +#else +INITSEG = 0x9000 +SETUPSEG = 0x9020 +#endif + +#ifdef ONLY8086 + .arch i8086 +#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 + pushw 4+2(%si) + pushw 4(%si) + movw $step19, 4(%si) + movw $INITSEG, 4+2(%si) +#else + pushl $4 + popw %si + popw %ds + pushl (%si) + movl $step19+(INITSEG<<16), (%si) +#endif + pushfw + popw %ax + incb %ah # set TF + pushw %ax + popfw + ljmp *4*0x19-4(%si) +.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) + popw %bp + popw %di + popw %si + popw %dx + popw %cx + popw %bx + popw %ax +#else + popl 4(%si) + 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 + jcxz nocmdline +# 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: + movl %cr0,%eax + andl $0x7FFFFFFE,%eax + movl %eax,%cr0 + movl %eax,%cr3 +isrm: +# ifdef SHUTDOWNDOS + trace_int19 +# else + lssw %cs:EXEADRS(saved_ss_sp),%sp + 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: + .word 0xFFFF + .long 0x92000000 + .byte 0xCF,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 +# ifndef SHUTDOWNDOS +saved_ss_sp: + .word stacktop-4-16-4,INITSEG +# endif +#endif +#ifdef ELKS + .org 0x1E3 + .byte 13,10,7 + .asciz "ELKS Boot" +#endif diff -r da3ed5ef7be8 -r 8da769e5f6c3 x86test/stuff/pack --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x86test/stuff/pack Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,76 @@ +#!/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 + grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0 + grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $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|.*_$1.||" unlzma.S +} + +compress() +{ + xz -z -e --format=raw --lzma1=mf=bt2,lc=$(bits LC),lp=$(bits LP),pb=$(bits PB),nice=36 --stdout +} + +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 XXXSB 1 + store $setup $2 XXXSW 1 + store $((32 * $setup)) $2 XXXSP + store $((0x1000 - 32*$setup)) $2 XXXSS + dd if=$1 bs=512 skip=1 | compress >>$2 + size=$(stat -c %s $2) + syssize=$((($size-512*($setup+1)+15)/16)) + store $(($syssize + 0x1000)) $2 XXXP + store $syssize $2 500 + store 4 $2 497 1 + 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 0 +#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 + 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 + + movb $3, %ah + mul BX // dx = 3*bh + add $1846, AX + +// 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 da3ed5ef7be8 -r 8da769e5f6c3 x86test/stuff/unpack.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x86test/stuff/unpack.S Sat May 08 17:23:19 2021 +0000 @@ -0,0 +1,286 @@ +#define SYSTEM 0x10000 +#define SETUP 14 +#define SYSSIZE 0x1F4 +#define SETUPSIZE 0x1F1 + +#define LINUX_HEADER 0 +#define UPDATE_SYSSIZE 1 +#define HARDCODED_SYSSIZE 1 +#define HARDCODED_SETUPSIZE 1 +#define FLAT16 1 +#define FLAT16OUT 1 +#define SAVEREGS 0 +#define ELKS 0 + +#define ONLY8086 1 + + .text + .code16 + .org 0 + +#if ELKS + .arch i8086 +#define FLAT16 1 +#define LINUX_HEADER 0 +#define SAVEREGS 0 +#define TOPSEG 0x2000 +#else +#define TOPSEG 0x8000 +#endif + + .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 + pushal + pushw %ds + cld +#else + pushw %cs +# if FLAT16 + xorw %di, %di + pushw %di +# else + pushw $0 +# endif +#endif +#if ELKS + movw $0x100, %ax + pushw %ax +#else +#if UPDATE_SYSSIZE + pushw %ds // +#else + pushw %cs // +#endif +#endif +#if FLAT16 +# 1- move 9020..9020+stp -> TOPSEG +#if ELKS + movb $TOPSEG/256, %ah + movw %ax, %es +#else + pushw $TOPSEG + popw %es +#endif + movw $0x200, %si +#if SAVEREGS == 0 + pushw %es +#if ELKS + movw $cont, %ax + pushw %ax +#else + // pushw $cont + .byte 0x6A, cont +#endif + jmp jumpinto +#else +# if HARDCODED_SETUPSIZE +setup_word: + movw $SETUP*256, %cx +# else + xorw %cx, %cx + movb SETUPSIZE, %ch + movw %cx, %dx +# endif + pushw %cx // + pushw %es + pushw %di + rep + movsw + lret +#endif +cont: +# 2- move 1000..1000+sys -> TOPSEG+stp +#if ELKS + movw $0x1000, %ax + movw %ax, %ds +#else + pushw $0x1000 + popw %ds +#endif + xorw %si, %si + subw %di, %cx + rep + movsb +# 3- unlz(TOPSEG+stp:end, 1000-stp:0) + pushw %es // +# if HARDCODED_SETUPSIZE +setup_seg: +#if ELKS +# if UPDATE_SYSSIZE + movw $0x1000-(SETUP*32)-32, %ax +# else + movw $0x1000-(SETUP*32), %ax +# endif + movw %ax, %es +#else +# if UPDATE_SYSSIZE + pushw $0x1000-(SETUP*32)-32 +# else + pushw $0x1000-(SETUP*32) +# endif + popw %es +#endif +# else +# if UPDATE_SYSSIZE + incb %dh +# endif +#if ELKS + shrw $1, %dx + shrw $1, %dx + shrw $1, %dx +#else + shrw $3, %dx +#endif + movw %ds, %ax + subw %dx, %ax + movw %ax, %es +# endif +#else // FLAT16 +# 1- move 1000..1000+sys -> 9000-sys +# if HARDCODED_SYSSIZE +packed_syssize: + movw $0x1000+0, %ax +# else + movw SYSSIZE, %ax + addw $0x1000, %ax +# endif + 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 +# 2- move 9020..9020+stp -> 9000-sys-stp + +# if HARDCODED_SETUPSIZE +setup_byte: + movb $SETUP, %ch +setup_para: + subw $SETUP*32, %dx +# else + movb %ss:SETUPSIZE, %ch + movw %cx, %ax +#if ELKS + shrw $1, %ax + shrw $1, %ax + shrw $1, %ax +#else + shrw $3, %ax +#endif + subw %ax, %dx +# endif + pushw %cx // + movw %dx, %es + xorw %si, %si + xorw %di, %di + rep + movsw %cs:(%si),%es:(%di) + pushw %es +# 3- reloc itself in 0x7C00 + pushw $0x07C0 + popw %es + movw $cont, %si + movw %si, %di + movw $end-_start, %cx + pushw %es + pushw %di + rep + movsb %cs:(%si),%es:(%di) + lret +cont: +# 4- unlz(9000-sys-stp:end, 1000-stp:0) +# if HARDCODED_SETUPSIZE +setup_seg: +# if UPDATE_SYSSIZE + pushw $0x1000-(SETUP*32)-32 +# else + pushw $0x1000-(SETUP*32) +# endif + popw %es +# else + negw %ax +# if UPDATE_SYSSIZE + addw $0x1000-32, %ax +# else + addw $0x1000, %ax +# endif + movw %ax, %es +# endif +#endif // FLAT16 + popw %ds // + movw $end-_start, %si +#if UPDATE_SYSSIZE + movw $SYSSIZE, %di +#else + xorw %di, %di +#endif + pushw %di + pushw %es + call unpack + popw %ds + popw %si + movw %si, %di +# if SAVEREGS != 0 + popw %cx // +#if UPDATE_SYSSIZE +// not need with memtest movb $(512-SYSSIZE)/2, %cl +#endif + popw %es // +# 5- move 1000-stp..1000 -> 9020 +# else + popw %es // +jumpinto: +# if HARDCODED_SETUPSIZE +setup_word: + movw $SETUP*256, %cx +# else + xorw %cx, %cx + movb %ss:SETUPSIZE, %ch + movw %cx, %dx +# endif +# endif + rep + movsw +#if SAVEREGS + popw %ds + popal + iret +#else + lret +#endif + +unpack: +#define NO_LZMA_HEADER +#if ELKS +#define ONLY8086 1 +#endif +#include "unlzma.S" + +end: diff -r da3ed5ef7be8 -r 8da769e5f6c3 x86test/stuff/x86test Binary file x86test/stuff/x86test has changed