wok-tiny rev 168
memtest: 386 support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Apr 30 16:35:54 2021 +0000 (2021-04-30) |
parents | c1bce725480a |
children | aacd5b54d010 |
files | memtest/receipt memtest/stuff/bootloader.S memtest/stuff/memtest86+-5.01-386.patch memtest/stuff/memtest86+-5.01-O0.patch memtest/stuff/memtest86+-5.01-array-size.patch memtest/stuff/memtest86+-5.01-io.patch memtest/stuff/memtest86+-5.01-scp.patch memtest/stuff/memtest86+-5.01-setup.patch memtest/stuff/pack memtest/stuff/unlzma.S memtest/stuff/unpack.S |
line diff
1.1 --- a/memtest/receipt Thu Feb 18 11:46:30 2021 +0000 1.2 +++ b/memtest/receipt Fri Apr 30 16:35:54 2021 +0000 1.3 @@ -7,15 +7,35 @@ 1.4 MAINTAINER="pascal.bellard@slitaz.org" 1.5 LICENSE="GPL2" 1.6 WEB_SITE="http://www.memtest.org/" 1.7 -TARBALL="$PACKAGE-$VERSION" 1.8 -WGET_URL="http://cook.slitaz.org/cooker.cgi?download=../wok/memtest/taz/memtest-$VERSION/fs/boot/memtest" 1.9 +TARBALL="memtest86+-$VERSION.tar.gz" 1.10 +WGET_URL="http://www.memtest.org/download/$VERSION/$TARBALL" 1.11 TARGET="i486" 1.12 1.13 +BUILD_DEPENDS="xz" 1.14 + 1.15 +# Rules to configure and make the package. 1.16 +compile_rules() 1.17 +{ 1.18 + ls $stuff/memtest*-$VERSION-*.patch && 1.19 + for i in $stuff/memtest*-$VERSION-*.patch ; do 1.20 + patch -p1 < $i 1.21 + done 1.22 + make 1.23 + cp $stuff/*.S $stuff/pack . 1.24 + for i in bootloader unpack ; do 1.25 + cc -o $i.o -Wa,-a=$i.lst -c $i.S 1.26 + objcopy -O binary $i.o $i.bin 1.27 + done 1.28 + sed -i "s/VERSION/$VERSION/" pack 1.29 + ./pack --build bootloader.bin unpack.bin 1.30 + ./pack memtest.bin memtest.packed 1.31 +} 1.32 + 1.33 # Rules to gen a SliTaz package suitable for Tazpkg. 1.34 genpkg_rules() 1.35 { 1.36 mkdir -p $fs/boot 1.37 - cp $SOURCES_REPOSITORY/$TARBALL $fs/boot/$PACKAGE 1.38 + cp $src/memtest.packed $fs/boot/$PACKAGE 1.39 } 1.40 1.41 # Post install/remove commands for Tazpkg.
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/memtest/stuff/bootloader.S Fri Apr 30 16:35:54 2021 +0000 2.3 @@ -0,0 +1,655 @@ 2.4 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2. 2.5 + 2.6 +SYSSEG = 0x1000 2.7 +setup_sects = 497 2.8 +syssize = 500 2.9 +cmd_line_ptr = 0x228 2.10 + 2.11 + .text 2.12 + .code16 2.13 + .org 0 2.14 + .globl _start 2.15 +_start: 2.16 + 2.17 +#define CODESZ 512 /* patched by installer */ 2.18 + 2.19 +// Default kernel format is 386 Image/zImage 2.20 +//#define BZIMAGE 0x207 /* setup version ; for bzImage < 512 Kb only */ 2.21 +//#define ELKS /* 8086/286 linux port */ 2.22 + 2.23 +/* some extra features */ 2.24 +#define EXE_SUPPORT real mode dos .exe file support +208/264 2.25 +#define CMDLINE dos kernel cmdline support +45 2.26 +#define VCPI VCPI 4.0 support (386+) +109 2.27 +#define SHUTDOWNDOS shutdown DOS services +29 2.28 + 2.29 +/* some contraints to reduce the code size */ 2.30 +//#define FLOPPY_1440K_ONLY 1.44M floppies support only -26 2.31 +//#define FLOPPY_HAS_2_SIDES hardcoded heads count to 2 -15 2.32 +//#define NO_CMDLINE_SHRINK remove heading spaces ? -6-21 2.33 +//#define NO_CMDLINE_FILE remove @cmdline file support ? -21 2.34 +//#define NO_DOTS show progression dots ? -5 2.35 +#ifndef BZIMAGE 2.36 +//#define TINY_ZIMAGE system < 64Kb ? -11 2.37 +//#define NO_MINSETUP default setup (dos only) ? -4 2.38 +//#define NO_CURSOR_DEFINITION -8 2.39 +#endif 2.40 + 2.41 +#ifdef ELKS 2.42 + .arch i8086 2.43 +INITSEG = 0x0100 2.44 +SETUPSEG = 0x0120 2.45 +#define ONLY8086 2.46 +#undef BZIMAGE 2.47 +#undef VCPI 2.48 +#else 2.49 +INITSEG = 0x9000 2.50 +SETUPSEG = 0x9020 2.51 +#endif 2.52 + 2.53 +.macro shlclw cnt,obj 2.54 +#ifdef ONLY8086 2.55 + movb \cnt,%cl 2.56 + shlw %cl,\obj 2.57 +#else 2.58 + shlw \cnt,\obj 2.59 +#endif 2.60 +.endm 2.61 + 2.62 +.macro shrclw cnt,obj 2.63 +#ifdef ONLY8086 2.64 + movb \cnt,%cl 2.65 + shrw %cl,\obj 2.66 +#else 2.67 + shrw \cnt,\obj 2.68 +#endif 2.69 +.endm 2.70 + 2.71 +#ifdef EXE_SUPPORT 2.72 +#define EXEADRS(x) (x+0xE0) 2.73 +#define FLAT20(x) (x+16*INITSEG) 2.74 + 2.75 +.macro trace_int19 2.76 +#ifdef ONLY8086 2.77 + xorw %si, %si 2.78 + movw %si, %ds 2.79 + pushw 4+2(%si) 2.80 + pushw 4(%si) 2.81 + movw $step19, 4(%si) 2.82 + movw $INITSEG, 4+2(%si) 2.83 +#else 2.84 + pushl $4 2.85 + popw %si 2.86 + popw %ds 2.87 + pushl (%si) 2.88 + movl $step19+(INITSEG<<16), (%si) 2.89 +#endif 2.90 + pushfw 2.91 + popw %ax 2.92 + incb %ah # set TF 2.93 + pushw %ax 2.94 + popfw 2.95 + ljmp *4*0x19-4(%si) 2.96 +.endm 2.97 + 2.98 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 2.99 + decw %bp // Magic number: MZ 2.100 + popw %dx 2.101 + jmp start // Bytes on last page of file 2.102 + .word (CODESZ+511)/512 // Pages in file INSTALLER 2.103 + .word 0 // Relocations 2.104 + .word (end_header-_start)/16 // Size of header in paragraphs 2.105 + .word 4096 // Minimum extra paragraphs needed 2.106 + .word -1 // Maximum extra paragraphs needed 2.107 + .word (CODESZ+15)/16 // Initial (relative) SS value INSTALLER 2.108 + .word stacktop // Initial SP value 2.109 + .word 0 // Checksum INSTALLER? 2.110 + .word EXEADRS(comstart) // Initial IP value 2.111 + .word 0xFFF0 // Initial (relative) CS value 2.112 +// .word 0x001C // File address of relocation table 2.113 +// .word 0,0,0 // Overlay number 2.114 +#else 2.115 +#undef VCPI 2.116 +#endif 2.117 +start: 2.118 + xorw %ax, %ax # %ax = 0 2.119 +zeroed = 12 # zeroed registers 2.120 + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits 2.121 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 (+zeroed+12) 2.122 +#ifdef ONLY8086 2.123 + movw $INITSEG, %bx 2.124 +#else 2.125 + pushw $INITSEG 2.126 +#endif 2.127 +end_header: 2.128 + cld # assume nothing 2.129 +#if defined(BZIMAGE) && BZIMAGE >= 0x202 2.130 + popw %es # %es contain INITSEG 2.131 + movw %es, %di 2.132 +#else 2.133 + # cmdline offset at 0x22 2.134 + movw $stacktop, %di # stacktop is an arbitrary value >= 2.135 + # length of bootsect + length of 2.136 + # setup + room for stack; 2.137 + # 12 is disk parm size. 2.138 +# ifdef ONLY8086 2.139 + pushw %bx 2.140 +# endif 2.141 + popw %es # %es contain INITSEG 2.142 +#endif 2.143 + pushw %es 2.144 + popw %ss # %es = %ss = INITSEG 2.145 + movw %di, %sp # put stack at INITSEG:stacktop-... 2.146 +#ifdef EXE_SUPPORT 2.147 + cwd # force %dx = 0 (floppy only) 2.148 +#endif 2.149 + 2.150 +# Many BIOS's default disk parameter tables will not recognize 2.151 +# multi-sector reads beyond the maximum sector number specified 2.152 +# in the default diskette parameter tables - this may mean 7 2.153 +# sectors in some cases. 2.154 +# 2.155 +# Since single sector reads are slow and out of the question, 2.156 +# we must take care of this by creating new parameter tables 2.157 +# (for the first disk) in RAM. We can set the maximum sector 2.158 +# count to 36 - the most we will encounter on an ED 2.88. 2.159 +# 2.160 +# High doesn't hurt. Low does. Let's use the max: 63 2.161 + 2.162 + rep # don't worry about cld 2.163 + stosw # already done above 2.164 + popw %bx # offset = 0 2.165 + popw %ds # %ds = 0 2.166 + 2.167 + movb setup_sects+0x7C00, %al # read bootsector + setup (%ds = 0) 2.168 + incw %ax 2.169 + 2.170 + ldsw 0x78(%bx), %si # %ds:%bx+0x78 is parameter table address 2.171 + pushw %es 2.172 + pushw %di 2.173 + movb $6, %cl # copy 12 bytes 2.174 + rep # don't worry about cld 2.175 + movsw # already done above 2.176 + movw %cx, %ds # %ds = 0 2.177 +#ifdef ONLY8086 2.178 + popw 0x78(%bx) # update parameter table address 2.179 + popw 0x78+2(%bx) 2.180 +#else 2.181 + popl 0x78(%bx) # update parameter table address 2.182 +#endif 2.183 + pushw %ss 2.184 + popw %ds # now %ds = %es = %ss = INITSEG 2.185 + movb $63, 0x4-12(%di) # patch sector count, %di = stacktop 2.186 + 2.187 + xchg %ax, %di # sector count 2.188 + popw %ax # limits = 0 2.189 + incw %cx # cylinder 0, sector 1, clear Z 2.190 + call read_first_sectors # read setup 2.191 + 2.192 +# This routine loads the system at address LOADSEG, making sure 2.193 +# no 64kB boundaries are crossed. We try to load it as fast as 2.194 +# possible, loading whole tracks whenever we can. 2.195 + 2.196 + movw syssize, %di 2.197 + decw %di 2.198 + shrclw $9-4, %di 2.199 + incw %di 2.200 + movw $SYSSEG, %cx 2.201 +#ifdef BZIMAGE 2.202 + push %cx 2.203 +#endif 2.204 + call read_sectorsCX 2.205 + 2.206 +# This procedure turns off the floppy drive motor, so 2.207 +# that we enter the kernel in a known state, and 2.208 +# don't have to worry about it later. 2.209 + 2.210 +kill_motor: 2.211 + xchgw %ax, %di # reset FDC (%di < 128) 2.212 + int $0x13 2.213 + 2.214 +# After that (everything loaded), we jump to the setup-routine 2.215 +# loaded directly after the bootblock: 2.216 +# Segments are as follows: %ds = %ss = INITSEG 2.217 + 2.218 +#ifdef BZIMAGE 2.219 + popw %bx 2.220 + popw %si // SYSSEG:0 2.221 +movesys: // %bx = DS, %si 2.222 + movw $16, %ax 2.223 + mulw %bx 2.224 + addw %si, %ax 2.225 + adcw $0x9300, %dx // %dx:%ax src flat address 2.226 + movw $9, %cx 2.227 +zero1: 2.228 + pushw $0 // 2E..1E 2.229 + loop zero1 2.230 + //pushl $0x93100000 // 1A: dest 2.231 + pushw $0x9310 2.232 + pushw %cx 2.233 + pushw $-1 // 18 2.234 + pushw %cx // 16 2.235 + pushw %dx // src 2.236 + pushw %ax 2.237 + pushw $-1 // 10 2.238 + movb $8, %cl 2.239 + movw %cx, %bx // will move 8*64 = 512Kb 2.240 +zero2: 2.241 + pushw $0 // 0E..00 2.242 + loop zero2 2.243 + movw %sp, %si 2.244 + pushw %ss 2.245 + popw %es 2.246 + pushw %es 2.247 + popw %ds 2.248 +syslp: 2.249 + movb $0x80, %ch 2.250 + movb $0x87, %ah 2.251 + int $0x15 2.252 + incb 0x14(%si) 2.253 + incb 0x1C(%si) 2.254 + decw %bx 2.255 + jne syslp 2.256 +#endif 2.257 +jmp_setup: 2.258 + cli 2.259 + ljmp $SETUPSEG, $0 2.260 + 2.261 +#ifdef EXE_SUPPORT 2.262 +#ifdef SHUTDOWNDOS 2.263 +doiret: 2.264 + iret 2.265 +step19: 2.266 + pushw %si 2.267 + pushw %ds 2.268 + movw %sp, %si 2.269 + ldsw %ss:4(%si), %si 2.270 + cmpw $0x19CD, (%si) 2.271 + popw %ds 2.272 + popw %si 2.273 + jne doiret 2.274 + xorw %si, %si 2.275 + movw %si, %ds 2.276 + pushw %cs 2.277 + popw %ss 2.278 + movw $stacktop-4-16, %sp 2.279 +#ifdef ONLY8086 2.280 + popw 4(%si) 2.281 + popw 4+2(%si) 2.282 + popw %bp 2.283 + popw %di 2.284 + popw %si 2.285 + popw %dx 2.286 + popw %cx 2.287 + popw %bx 2.288 + popw %ax 2.289 +#else 2.290 + popl 4(%si) 2.291 + popaw 2.292 +#endif 2.293 +#ifdef BZIMAGE 2.294 + jmp movesys 2.295 +#endif 2.296 +#endif 2.297 +#ifndef BZIMAGE 2.298 +movesys: // %ax = SYSSEG, %bx = DS, %si 2.299 + shrclw $4, %si 2.300 + addw %si, %bx 2.301 +#ifdef TINY_ZIMAGE 2.302 + movw $0xFFFF, %cx 2.303 + xorw %si, %si 2.304 + xorw %di, %di 2.305 + cmpw %ax, %bx 2.306 + jnc forward 2.307 + decw %si 2.308 + decw %di 2.309 + std 2.310 +forward: 2.311 + movw %ax, %es 2.312 + movw %bx, %ds 2.313 + rep 2.314 + movsb 2.315 + cld 2.316 +#else 2.317 + subw %ax, %bx 2.318 + jnc forward 2.319 + movb $0x90, %ah 2.320 + ;decw %ax 2.321 +forward: 2.322 + movw %ax, %es 2.323 + movw %ax, %di 2.324 + addw %bx, %di 2.325 + movw %di, %ds 2.326 + sbbw %di, %di // %di = 0 : -1 2.327 + cmc // C = 1 : 0 2.328 + adcw %di, %ax 2.329 + xorw %si, %si 2.330 + xorw %di, %di 2.331 + movb $0x10, %cl 2.332 + cmpb %cl, %ah // move 512k 2.333 + rep 2.334 + movsb 2.335 + jns forward 2.336 +#endif 2.337 +#ifndef NO_CURSOR_DEFINITION 2.338 + movb $1, %ah 2.339 + movb $0, %bh 2.340 + movb $0x20, %ch // 0x2000 2.341 + int $0x10 2.342 +#endif 2.343 + pushw %ss 2.344 + popw %ds 2.345 + jmp jmp_setup 2.346 +#endif 2.347 +comstart: 2.348 + cld # assume nothing 2.349 +#ifdef ONLY8086 2.350 + movw $INITSEG, %ax 2.351 + pushw %ax 2.352 +#else 2.353 + pushw $INITSEG 2.354 +#endif 2.355 + popw %es 2.356 +#ifdef CMDLINE 2.357 + movw %sp, %di 2.358 + movw $0x80, %si 2.359 + lodsb 2.360 + cbw 2.361 + xchgw %ax, %cx 2.362 + jcxz nocmdline 2.363 +# if defined(BZIMAGE) && BZIMAGE >= 0x202 2.364 + movw $INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1) 2.365 +# else 2.366 + movw $0xA33F, 0x7F(%si) 2.367 +# endif 2.368 +# ifndef NO_CMDLINE_SHRINK 2.369 +skipspace: 2.370 + lodsb 2.371 + cmpb $0x20, %al 2.372 + je skipspace 2.373 +# ifndef NO_CMDLINE_FILE 2.374 + movw %si,%dx 2.375 + decw %si 2.376 + subb $'@',%al 2.377 + jne notafile 2.378 + movb $0x3D,%ah 2.379 + int $0x21 2.380 + jc notafile 2.381 + xchgw %ax,%bx 2.382 + //movw %si,%dx // ~320 bytes max 2.383 + movw $EXEADRS(notafile)-130,%cx 2.384 + movb $0x3F,%ah 2.385 + int $0x21 2.386 + xchgw %ax,%cx 2.387 +notafile: 2.388 +# else 2.389 + decw %si 2.390 +# endif 2.391 +# endif 2.392 + rep 2.393 + movsb 2.394 +nocmdline: 2.395 + orb EXEADRS(setup_sects), %ch 2.396 +# ifndef NO_MINSETUP 2.397 +# ifndef BZIMAGE 2.398 + jnz setupok 2.399 + mov $4, %ch 2.400 +setupok: 2.401 +# endif 2.402 +# endif 2.403 +#else 2.404 + movb EXEADRS(setup_sects), %ch 2.405 +#endif 2.406 + movb $(512-(end_header-_start))/2, %cl 2.407 + movw $0x100, %si 2.408 + movw $end_header, %di 2.409 + rep 2.410 + movsw 2.411 + movw $SYSSEG, %ax 2.412 + movw %ds, %bx 2.413 + pushw %es 2.414 + popw %ss 2.415 +#ifndef SHUTDOWNDOS 2.416 + pushw %es 2.417 + pushw $movesys 2.418 +#endif 2.419 +#ifdef VCPI 2.420 + pushaw 2.421 + smsww %ax 2.422 + andb $1, %al 2.423 + je isrm 2.424 + movw $EXEADRS(gdt_vcpi),%si 2.425 + movw $pagebuf-0x90000,%di // %es = 0x9000 2.426 + movl $pagebuf+3,%es:0x1000(%di) 2.427 +call_vcpi: 2.428 + movb $0xDE,%ah // DE01, EBX = getiface(DS:SI, ES:DI) 2.429 + int $0x67 2.430 + movl $FLAT20(sw2pm_params),%esi 2.431 + movb $0x0C,%al // DE0C switchpm(ESI) 2.432 + jmp call_vcpi 2.433 +pm_code: 2.434 + movl %cr0,%eax 2.435 + andl $0x7FFFFFFE,%eax 2.436 + movl %eax,%cr0 2.437 + movl %eax,%cr3 2.438 +isrm: 2.439 +# ifdef SHUTDOWNDOS 2.440 + trace_int19 2.441 +# else 2.442 + lssw %cs:EXEADRS(saved_ss_sp),%sp 2.443 + popaw 2.444 + retf 2.445 +# endif 2.446 +#else 2.447 +# ifdef SHUTDOWNDOS 2.448 +# ifdef ONLY8086 2.449 + pushw %ax 2.450 + pushw %bx 2.451 + pushw %cx 2.452 + pushw %dx 2.453 + pushw %si 2.454 + pushw %di 2.455 + pushw %bp 2.456 +# else 2.457 + pushaw 2.458 +# endif 2.459 + trace_int19 2.460 +# endif 2.461 + retf 2.462 +#endif 2.463 +#endif 2.464 + 2.465 +# read_sectors reads %di sectors into %es:0 buffer. 2.466 +# %es:0 is updated to the next memory location. 2.467 +# First, sectors are read sector by sector until 2.468 +# sector per track count is known. Then they are 2.469 +# read track by track. 2.470 +# Assume no error on first track. 2.471 + 2.472 +#ifdef FLOPPY_1440K_ONLY 2.473 +#ifndef FLOPPY_HAS_2_SIDES 2.474 +#define FLOPPY_HAS_2_SIDES hardcore heads count to 2 2.475 +#endif 2.476 +#define FLOPPY_SECTORS 18 /* 18 sectors */ 2.477 +#else 2.478 +#define FLOPPY_HEADS 2 /* 2 heads minimum */ 2.479 +#endif 2.480 + 2.481 +return: 2.482 +#ifndef NO_DOTS 2.483 + movw $0xE2E,%ax 2.484 + int $0x10 2.485 +#endif 2.486 + ret 2.487 + 2.488 +check_limits: 2.489 +#ifndef FLOPPY_1440K_ONLY 2.490 + popw %dx 2.491 + cmpb %al, %cl # max sector known ? 2.492 + ja next_head # no -> store it 2.493 +#ifndef FLOPPY_HAS_2_SIDES 2.494 +#ifdef FLOPPY_HEADS 2.495 + cmpb $FLOPPY_HEADS, %dh # 2 heads minimum 2.496 + jb check_cylinder 2.497 +#endif 2.498 + cmpb %ah, %dh # max head known ? 2.499 + ja next_cylinder # no -> store it 2.500 +check_cylinder: 2.501 +#endif 2.502 + pushw %ax 2.503 + cbw # %ah = 0 2.504 +#else 2.505 + pushw %dx 2.506 +#endif 2.507 + int $0x13 # reset controler 2.508 +#ifndef FLOPPY_1440K_ONLY 2.509 + popw %ax 2.510 + movb $1, %al # sector by sector... 2.511 +#else 2.512 + movw $1, %ax 2.513 + jmp more1trk 2.514 +#endif 2.515 +read_sectorslp: 2.516 + pushw %dx # some bios break dx... 2.517 +#ifndef FLOPPY_1440K_ONLY 2.518 + pushw %ax # limits 2.519 + subb %cl, %al # sectors remaining in track 2.520 + ja tolastsect 2.521 + movb $1, %al # first track sector by sector 2.522 +tolastsect: 2.523 +#else 2.524 + movb $FLOPPY_SECTORS+1, %al 2.525 + subb %cl, %al # sectors remaining in track 2.526 +#endif 2.527 + cbw 2.528 + cmpw %di, %ax 2.529 + jb more1trk 2.530 + movw %di, %ax # sectors to read 2.531 +more1trk: 2.532 + pushw %ax # save context 2.533 + movb $2, %ah # cmd: read chs 2.534 + int $0x13 2.535 +#ifndef FLOPPY_1440K_ONLY 2.536 + popw %dx # save %ax 2.537 + popw %ax # limits 2.538 +#else 2.539 + popw %ax # restore context 2.540 + popw %dx 2.541 +#endif 2.542 + jc check_limits 2.543 +#ifndef FLOPPY_1440K_ONLY 2.544 + xchgw %ax, %bp 2.545 + addw %dx,%cx # next sector 2.546 + movw %cx, %si 2.547 + pushw %dx 2.548 + shlclw $5, %dx 2.549 + movw %es, %cx 2.550 + addw %dx, %cx 2.551 + popw %dx 2.552 + subw %dx,%di # update sector counter 2.553 + popw %dx 2.554 +#else 2.555 + addw %ax,%cx # next sector 2.556 + movw %cx, %si 2.557 + pushw %ax 2.558 + shlclw $5, %ax 2.559 + movw %es, %cx 2.560 + addw %ax, %cx 2.561 + popw %ax 2.562 + subw %ax,%di # update sector counter 2.563 +#endif 2.564 +read_sectorsCX: 2.565 + movw %cx, %es # next location 2.566 + jz return 2.567 +read_sectors: 2.568 + movw %si, %cx 2.569 +#ifndef FLOPPY_1440K_ONLY 2.570 +# al is last sector+1 2.571 +# ah is last head+1 2.572 + xchgw %ax, %bp 2.573 +#endif 2.574 +#ifndef FLOPPY_1440K_ONLY 2.575 + cmpb %al,%cl # reach sector limit ? 2.576 + jne bdendlp 2.577 +next_head: 2.578 + movb %cl,%al 2.579 +#else 2.580 + cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ? 2.581 + jne bdendlp 2.582 +#endif 2.583 + movb $1,%cl # first sector 2.584 +#ifndef FLOPPY_HAS_2_SIDES 2.585 + incb %dh # next head 2.586 + cmpb %ah, %dh # reach head limit ? 2.587 + jne bdendlp 2.588 +next_cylinder: 2.589 + movb %dh,%ah 2.590 + movb $0,%dh # first head 2.591 +#else 2.592 + xorb %cl,%dh # next head 2.593 + jne bdendlp # reach head limit ? 2.594 +#endif 2.595 +# NOTE : support 256 cylinders max 2.596 + incb %ch # next cylinder 2.597 +read_first_sectors: 2.598 +bdendlp: 2.599 + jmp read_sectorslp 2.600 + 2.601 +#ifdef VCPI 2.602 +pagebuf = 0x98000 2.603 +tss = gdt_abs-40 2.604 +gdt = gdt_abs-32 2.605 +gdt_null = gdt_abs-32 2.606 +gdt_vcpi = gdt_abs-24 2.607 +gdt_vcpi2 = gdt_abs-16 2.608 +gdt_vcpi3 = gdt_abs-8 2.609 +gdt_abs: 2.610 + .word 0xFFFF 2.611 + .long 0x92000000 2.612 + .byte 0xCF,0 2.613 +gdt_code: 2.614 + .word 0xFFFF 2.615 +gdt_code_base: 2.616 + .long 0x9A000000+FLAT20(0) 2.617 + .byte 0x8F,0 2.618 +gdt_tss: 2.619 + .word 0x00FF 2.620 +gdt_tss_base: 2.621 + .long 0x89000000+FLAT20(tss) 2.622 + .byte 0,0 2.623 +gdtr: 2.624 +gdt_lim: 2.625 + .word 0xFFFF 2.626 +gdt_base: 2.627 + .long FLAT20(gdt) 2.628 +sw2pm_params: 2.629 +sw2pm_cr3: 2.630 + .long pagebuf+0x1000 2.631 +sw2pm_gdtr_ptr: 2.632 + .long FLAT20(gdtr) 2.633 +sw2pm_idtr_ptr: 2.634 + .long FLAT20(idtr) 2.635 +sw2pm_ldtr: 2.636 + .word 0 2.637 +sw2pm_tr: 2.638 +SEL_TSS = gdt_tss-gdt_null 2.639 + .word SEL_TSS 2.640 +sw2pm_jumpaddr: 2.641 + .long pm_code 2.642 +SEL_CODE = gdt_code-gdt_null 2.643 + .word SEL_CODE 2.644 +idtr: 2.645 +idt_lim: 2.646 + .word 0x03FF 2.647 +idt_base: 2.648 + .long 0 2.649 +# ifndef SHUTDOWNDOS 2.650 +saved_ss_sp: 2.651 + .word stacktop-4-16-4,INITSEG 2.652 +# endif 2.653 +#endif 2.654 +#ifdef ELKS 2.655 + .org 0x1E3 2.656 + .byte 13,10,7 2.657 + .asciz "ELKS Boot" 2.658 +#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/memtest/stuff/memtest86+-5.01-386.patch Fri Apr 30 16:35:54 2021 +0000 3.3 @@ -0,0 +1,105 @@ 3.4 +--- memtest86+-5.01/cpuid.c 3.5 ++++ memtest86+-5.01/cpuid.c 3.6 +@@ -14,6 +14,15 @@ 3.7 + unsigned int *v, dummy[3]; 3.8 + char *p, *q; 3.9 + 3.10 ++ switch (has_cpuid(AC_BIT|CPUID_BIT)) { 3.11 ++ case 0: 3.12 ++ cpu_id.vers.bits.family = 3; 3.13 ++ return; 3.14 ++ case AC_BIT: 3.15 ++ cpu_id.vers.bits.family = 4; 3.16 ++ return; 3.17 ++ } 3.18 ++ 3.19 + /* Get max std cpuid & vendor ID */ 3.20 + cpuid(0x0, &cpu_id.max_cpuid, &cpu_id.vend_id.uint32_array[0], 3.21 + &cpu_id.vend_id.uint32_array[2], &cpu_id.vend_id.uint32_array[1]); 3.22 +--- memtest86+-5.01/cpuid.h 3.23 ++++ memtest86+-5.01/cpuid.h 3.24 +@@ -11,6 +11,26 @@ 3.25 + 3.26 + extern struct cpu_ident cpu_id; 3.27 + 3.28 ++#define AC_BIT (1<<18) 3.29 ++#define CPUID_BIT (1<<21) 3.30 ++static inline int has_cpuid(int bits) 3.31 ++{ 3.32 ++ int eax, edx; 3.33 ++ asm __volatile__( 3.34 ++ "pushfl\n\t" 3.35 ++ "popl %0\n\t" 3.36 ++ "movl %0,%1\n\t" 3.37 ++ "xorl %2,%0\n\t" 3.38 ++ "pushl %0\n\t" 3.39 ++ "popfl\n\t" 3.40 ++ "pushfl\n\t" 3.41 ++ "popl %0\n\t" 3.42 ++ "pushl %1\n\t" 3.43 ++ "popfl\n\t" 3.44 ++ "xorl %1,%0":"=a" (eax),"=d" (edx):"c" (bits)); 3.45 ++ return eax; 3.46 ++} 3.47 ++ 3.48 + static inline void __cpuid(unsigned int *eax, unsigned int *ebx, 3.49 + unsigned int *ecx, unsigned int *edx) 3.50 + { 3.51 +--- memtest86+-5.01/init.c 3.52 ++++ memtest86+-5.01/init.c 3.53 +@@ -77,6 +77,7 @@ 3.54 + cprint(19, 15, "==> Press F2 to force Multi-Threading (SMP) <=="); 3.55 + } 3.56 + 3.57 ++ if (cpu_id.fid.bits.rdtsc) { 3.58 + /* save the starting time */ 3.59 + asm __volatile__( 3.60 + "rdtsc":"=a" (sl),"=d" (sh)); 3.61 +@@ -122,6 +123,7 @@ 3.62 + } 3.63 + 3.64 + } 3.65 ++ } 3.66 + 3.67 + cprint(18, 18, " "); 3.68 + cprint(19, 15, " "); 3.69 +@@ -321,7 +323,9 @@ 3.70 + beep(1000); 3.71 + 3.72 + /* Record the start time */ 3.73 ++ if (cpu_id.fid.bits.rdtsc) { 3.74 + asm __volatile__ ("rdtsc":"=a" (v->startl),"=d" (v->starth)); 3.75 ++ } 3.76 + v->snapl = v->startl; 3.77 + v->snaph = v->starth; 3.78 + if (l1_cache == 0) { l1_cache = 64; } 3.79 +@@ -998,10 +1002,18 @@ 3.80 + default: 3.81 + /* Make a guess at the family */ 3.82 + switch(cpu_id.vers.bits.family) { 3.83 ++ case 3: 3.84 ++ cprint(0, COL_MID, "386"); 3.85 ++ break; 3.86 ++ case 4: 3.87 ++ cprint(0, COL_MID, "486"); 3.88 ++ break; 3.89 + case 5: 3.90 + cprint(0, COL_MID, "586"); 3.91 ++ break; 3.92 + case 6: 3.93 + cprint(0, COL_MID, "686"); 3.94 ++ break; 3.95 + default: 3.96 + cprint(0, COL_MID, "Unidentified Processor"); 3.97 + } 3.98 +--- memtest86+-5.01/test.c 3.99 ++++ memtest86+-5.01/test.c 3.100 +@@ -1501,6 +1501,8 @@ 3.101 + { 3.102 + ulong sh, sl, l, h, t, ip=0; 3.103 + 3.104 ++ if (cpu_id.fid.bits.rdtsc == 0) return; 3.105 ++ 3.106 + /* save the starting time */ 3.107 + asm __volatile__( 3.108 + "rdtsc":"=a" (sl),"=d" (sh));
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/memtest/stuff/memtest86+-5.01-O0.patch Fri Apr 30 16:35:54 2021 +0000 4.3 @@ -0,0 +1,11 @@ 4.4 +--- memtest86+-5.01/Makefile 2014-01-08 01:30:11.355900076 +0000 4.5 ++++ memtest86+-5.01/Makefile 2014-01-08 01:31:19.387555469 +0000 4.6 +@@ -12,7 +12,7 @@ 4.7 + AS=as -32 4.8 + CC=gcc 4.9 + 4.10 +-CFLAGS= -Wall -march=i486 -m32 -O1 -fomit-frame-pointer -fno-builtin \ 4.11 ++CFLAGS= -Wall -march=i486 -m32 -O0 -fomit-frame-pointer -fno-builtin \ 4.12 + -ffreestanding -fPIC $(SMP_FL) -fno-stack-protector 4.13 + 4.14 + OBJS= head.o reloc.o main.o test.o init.o lib.o patn.o screen_buffer.o \
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/memtest/stuff/memtest86+-5.01-array-size.patch Fri Apr 30 16:35:54 2021 +0000 5.3 @@ -0,0 +1,20 @@ 5.4 +--- memtest86+-5.01/controller.c 2013-08-10 02:01:58.000000000 +0000 5.5 ++++ memtest86+-5.01/controller.c 2013-12-12 20:58:12.873555378 +0000 5.6 +@@ -292,7 +292,7 @@ 5.7 + 5.8 + /* First, locate the PCI bus where the MCH is located */ 5.9 + 5.10 +- for(i = 0; i < sizeof(possible_nhm_bus); i++) { 5.11 ++ for(i = 0; i < sizeof(possible_nhm_bus) / sizeof(possible_nhm_bus[0]); i++) { 5.12 + pci_conf_read( possible_nhm_bus[i], 3, 4, 0x00, 2, &vid); 5.13 + pci_conf_read( possible_nhm_bus[i], 3, 4, 0x02, 2, &did); 5.14 + vid &= 0xFFFF; 5.15 +@@ -327,7 +327,7 @@ 5.16 + ctrl.mode = ECC_NONE; 5.17 + 5.18 + /* First, locate the PCI bus where the MCH is located */ 5.19 +- for(i = 0; i < sizeof(possible_nhm_bus); i++) { 5.20 ++ for(i = 0; i < sizeof(possible_nhm_bus) / sizeof(possible_nhm_bus[0]); i++) { 5.21 + pci_conf_read( possible_nhm_bus[i], 3, 4, 0x00, 2, &vid); 5.22 + pci_conf_read( possible_nhm_bus[i], 3, 4, 0x02, 2, &did); 5.23 + vid &= 0xFFFF;
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/memtest/stuff/memtest86+-5.01-io.patch Fri Apr 30 16:35:54 2021 +0000 6.3 @@ -0,0 +1,20 @@ 6.4 +--- memtest86+-5.01/io.h 2013-08-10 02:01:58.000000000 +0000 6.5 ++++ memtest86+-5.01/io.h 2014-01-08 01:29:12.404465515 +0000 6.6 +@@ -31,7 +31,7 @@ 6.7 + */ 6.8 + 6.9 + #define __OUT1(s,x) \ 6.10 +-extern inline void __out##s(unsigned x value, unsigned short port) { 6.11 ++static inline void __out##s(unsigned x value, unsigned short port) { 6.12 + 6.13 + #define __OUT2(s,s1,s2) \ 6.14 + __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1" 6.15 +@@ -43,7 +43,7 @@ 6.16 + __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; } 6.17 + 6.18 + #define __IN1(s) \ 6.19 +-extern inline RETURN_TYPE __in##s(unsigned short port) { RETURN_TYPE _v; 6.20 ++static inline RETURN_TYPE __in##s(unsigned short port) { RETURN_TYPE _v; 6.21 + 6.22 + #define __IN2(s,s1,s2) \ 6.23 + __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/memtest/stuff/memtest86+-5.01-scp.patch Fri Apr 30 16:35:54 2021 +0000 7.3 @@ -0,0 +1,10 @@ 7.4 +--- memtest86+-5.01/Makefile 7.5 ++++ memtest86+-5.01/Makefile 7.6 +@@ -21,7 +21,6 @@ 7.7 + 7.8 + 7.9 + all: clean memtest.bin memtest 7.10 +- scp memtest.bin root@192.168.0.12:/srv/tftp/mt86plus 7.11 + 7.12 + # Link it statically once so I know I don't have undefined 7.13 + # symbols and then link it dynamically so I have full
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/memtest/stuff/memtest86+-5.01-setup.patch Fri Apr 30 16:35:54 2021 +0000 8.3 @@ -0,0 +1,69 @@ 8.4 +--- memtest86+-5.01/setup.S 8.5 ++++ memtest86+-5.01/setup.S 8.6 +@@ -27,11 +27,11 @@ 8.7 + #ljmp $INITSEG, $(reload - start + 0x200) 8.8 + reload: 8.9 + movw $INITSEG, %ax 8.10 +- movw %ax, %ds 8.11 + movw %ax, %es 8.12 + movw %ax, %fs 8.13 ++ movw %ax, %gs 8.14 + movw %ax, %ss # reset the stack to INITSEG:0x4000-12. 8.15 +- movw %dx, %sp 8.16 ++ movw $0x4000-12, %sp 8.17 + push %cs 8.18 + pop %ds 8.19 + lidt idt_48 - start # load idt with 0,0 8.20 +@@ -50,13 +50,13 @@ 8.21 + jz alt_a20_done 8.22 + 8.23 + /* set or clear bit1, the ALT_A20_GATE bit */ 8.24 +- movb 4(%esp), %ah 8.25 +- testb %ah, %ah 8.26 +- jz alt_a20_cont1 8.27 ++ //movb 4(%esp), %ah 8.28 ++ //testb %ah, %ah 8.29 ++ //jz alt_a20_cont1 8.30 + orb $2, %al 8.31 +- jmp alt_a20_cont2 8.32 ++ //jmp alt_a20_cont2 8.33 + alt_a20_cont1: 8.34 +- and $0xfd, %al 8.35 ++ //and $0xfd, %al 8.36 + 8.37 + /* clear the INIT_NOW bit; don't accidently reset the machine */ 8.38 + alt_a20_cont2: 8.39 +@@ -87,9 +87,9 @@ 8.40 + movw $KERNEL_DS, %ax 8.41 + movw %ax, %ds 8.42 + movw %ax, %es 8.43 +- movw %ax, %ss 8.44 + movw %ax, %fs 8.45 + movw %ax, %gs 8.46 ++ movw %ax, %ss 8.47 + 8.48 + data32 ljmp $KERNEL_CS, $(TSTLOAD <<4) # jmp offset 2000 of segment 0x10 (cs) 8.49 + 8.50 +@@ -100,18 +100,16 @@ 8.51 + * No timeout is used - if this hangs there is something wrong with 8.52 + * the machine, and we probably couldn't proceed anyway. 8.53 + */ 8.54 ++has_output: 8.55 ++ call delay 8.56 ++ inb $0x60, %al # read it 8.57 + empty_8042: 8.58 + call delay 8.59 + inb $0x64, %al # 8042 status port 8.60 + cmpb $0xff, %al # from grub-a20-patch, skip if not impl 8.61 + jz empty_8042_ret 8.62 + testb $1, %al # output buffer? 8.63 +- jz no_output 8.64 +- call delay 8.65 +- inb $0x60, %al # read it 8.66 +- jmp empty_8042 8.67 +- 8.68 +-no_output: 8.69 ++ jnz has_output 8.70 + testb $2, %al # is input buffer full? 8.71 + jnz empty_8042 # yes - loop 8.72 + empty_8042_ret:
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/memtest/stuff/pack Fri Apr 30 16:35:54 2021 +0000 9.3 @@ -0,0 +1,71 @@ 9.4 +#!/bin/sh 9.5 +if [ "$1" == "--build" ]; then 9.6 + set -- ${2:-bootloader.bin} ${3:-unpack.bin} 9.7 + x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.8 + [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0 9.9 + x=$(grep -s setup_byte$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.10 + [ -n "$x" ] && sed -i "s/XXXSB/$((513+0x$x))/" $0 || sed -i "/XXXSB/d" $0 9.11 + x=$(grep -s setup_word$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.12 + [ -n "$x" ] && sed -i "s/XXXSW/$((514+0x$x))/" $0 || sed -i "/XXXSW/d" $0 9.13 + x=$(grep -s setup_para$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.14 + [ -n "$x" ] && sed -i "s/XXXSP/$((514+0x$x))/" $0 || sed -i "/XXXSP/d" $0 9.15 + x=$(grep -s setup_seg$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.16 + [ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0 9.17 + grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0 9.18 + grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0 9.19 + helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.20 + helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') 9.21 + if [ -n "$helpmsg" ]; then 9.22 + sed -i "s/YYY/$((0x$helpmsg))/" $0 9.23 + sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0 9.24 + else 9.25 + sed -i '/YYY/d' $0 9.26 + fi 9.27 + cat >> $0 <<EOM 9.28 +$(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -) 9.29 +EOT 9.30 +EOM 9.31 + sed -i '/--build/,/^fi/d' $0 9.32 + exit 9.33 +fi 9.34 + 9.35 +store() 9.36 +{ 9.37 + n=$1 9.38 + for i in $(seq 1 ${4:-2}); do 9.39 + printf '\\\\x%02X' $(($n & 255)) 9.40 + n=$(($n >> 8)) 9.41 + done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 9.42 +} 9.43 + 9.44 +compress() 9.45 +{ 9.46 + xz -z -e --format=lzma --lzma1=mf=bt2 --stdout | dd bs=1 skip=13 9.47 +} 9.48 + 9.49 +main() 9.50 +{ 9.51 + uudecode | gunzip >$2 9.52 + dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc 9.53 + setup="$(echo $(od -j 497 -N 1 -dAn $1))" 9.54 + [ $setup -eq 0 ] && setup=4 9.55 + store $setup $2 XXXSB 1 9.56 + store $setup $2 XXXSW 1 9.57 + store $((32 * $setup)) $2 XXXSP 9.58 + store $((0x1000 - 32*$setup)) $2 XXXSS 9.59 + dd if=$1 bs=512 skip=1 | compress >>$2 9.60 + size=$(stat -c %s $2) 9.61 + syssize=$((($size-512*($setup+1)+15)/16)) 9.62 + store $(($syssize + 0x1000)) $2 XXXP 9.63 + store $syssize $2 500 9.64 + store 4 $2 497 1 9.65 + store $((($size+511)/512)) $2 4 9.66 + store $((($size+15)/16)) $2 14 9.67 + echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ 9.68 +} 9.69 + 9.70 +HELP="$(unix2dos <<EOT 9.71 +Memtest86+ VERSION GPLv2 9.72 +EOT 9.73 +)" 9.74 +main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/memtest/stuff/unlzma.S Fri Apr 30 16:35:54 2021 +0000 10.3 @@ -0,0 +1,1019 @@ 10.4 +// #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 10.5 +// 10.6 +// #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) 10.7 +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; 10.8 +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; 10.9 +// 10.10 +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ 10.11 +// { UpdateBit0(p); mi <<= 1; A0; } else \ 10.12 +// { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 10.13 +// 10.14 +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) 10.15 +// 10.16 +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \ 10.17 +// { int i = numLevels; res = 1; \ 10.18 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ 10.19 +// res -= (1 << numLevels); } 10.20 +/* 10.21 + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3 10.22 + */ 10.23 + 10.24 +#define PROP_PB 2 10.25 +#define PROP_LP 0 10.26 +#define PROP_LC 3 10.27 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45)) 10.28 + 10.29 +// static const Byte *Buffer; 10.30 +// static UInt32 bound, Code, Range; 10.31 + 10.32 +/* 10.33 + * Buffer register DS:SI 10.34 + * all var based ws=ss:bp 10.35 + */ 10.36 + 10.37 +rep0 = -4 // long 10.38 +rep1 = rep0-4 // long 10.39 +rep2 = rep0-8 // long 10.40 +rep3 = rep0-12 // long 10.41 +state = -17 // byte, 0..11 10.42 +posState = state-1 // byte, 0..15 10.43 +posState2 = posState-1 // byte, 0..15 10.44 +scratched = rep0-16 // byte = 1 10.45 +Code = -24 // long 10.46 +outStream = -28 // long 10.47 +nowPos = outStream // long 10.48 +Range = Code-8 // long 10.49 +#define LOCALS 32 10.50 + 10.51 +// int LzmaDecode(CLzmaDecoderState *vs, 10.52 +// const unsigned char *inStream, 10.53 +// unsigned char *outStream) 10.54 +// { 10.55 +// CProb *p = vs->Probs; 10.56 +// SizeT nowPos = 0; 10.57 +// #define posStateMask = (1 << (vs->Properties.pb)) - 1; 10.58 +// #define literalPosMask = (1 << (vs->Properties.lp)) - 1; 10.59 +// int lc = vs->Properties.lc, state = 0, len = 0; 10.60 +// UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 10.61 +// 10.62 +// { 10.63 +// UInt32 i, numProbs = Literal /*1846*/ 10.64 +// + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp)); 10.65 +// for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1; 10.66 + 10.67 +#define WS (1846+(768<<(PROP_LC+PROP_LP))) 10.68 +#if (WS+WS+LOCALS) >= 65000 10.69 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */ 10.70 +#error invalid (lc,lp,pb) : out of memory 10.71 +#endif 10.72 + 10.73 +ws1 = WS 10.74 +ws2 = ws1*2 10.75 +ws = ws2+LOCALS+15 10.76 + 10.77 +#ifndef FLAT32 10.78 +#define AX %ax 10.79 +#define BX %bx 10.80 +#define CX %cx 10.81 +#define DX %dx 10.82 +#define SI %si 10.83 +#define DI %di 10.84 +#define BP %bp 10.85 +#define SP %sp 10.86 +#define CWD cwd 10.87 +#else 10.88 +#define AX %eax 10.89 +#define BX %ebx 10.90 +#define CX %ecx 10.91 +#define DX %edx 10.92 +#define SI %esi 10.93 +#define DI %edi 10.94 +#define BP %ebp 10.95 +#define SP %esp 10.96 +#define CWD cdq 10.97 +#endif 10.98 +/* 10.99 + * LzmaDecode: 10.100 +#ifndef FLAT32 10.101 + * input ds:si=inStream, es:di=outStream 10.102 + * output outStream[], ds:si, es:di 10.103 + .code 16 10.104 +#else 10.105 + * input esi=inStream, edi=outStream 10.106 + * output outStream[], esi, edi 10.107 + .code 32 10.108 +#endif 10.109 + */ 10.110 + 10.111 + mov $ws1, CX 10.112 +#ifdef ONLY8086 10.113 + movw $2048/2, %ax 10.114 +lzd1: 10.115 + pushw %ax 10.116 +#else 10.117 +lzd1: 10.118 + pushw $2048/2 10.119 +#endif 10.120 + loop lzd1 10.121 + mov SP, BP 10.122 + movb $((LOCALS+3)/4)*2, %cl 10.123 +#ifdef ONLY8086 10.124 + movw $1, %ax 10.125 + cwd 10.126 +initlocals: 10.127 + pushw %dx 10.128 + pushw %ax 10.129 +#else 10.130 +initlocals: 10.131 + pushl $1 10.132 +#endif 10.133 + loop initlocals 10.134 + 10.135 +#if !defined(FLAT32) && !defined(FLAT16OUT) 10.136 + movb $4, %cl 10.137 + movw %es, %bx 10.138 + shrw %cl, %bx 10.139 + movw %es, %dx 10.140 + shlw %cl, %dx 10.141 + addw %dx, %di 10.142 + movw %di, outStream(%bp) 10.143 + adcb %bh, outStream+2(%bp) 10.144 + incw %cx 10.145 +#else 10.146 + movb $5, %cl 10.147 + mov DI, outStream(BP) 10.148 +#endif 10.149 + 10.150 +// Byte previousByte = 0; 10.151 + xor BX, BX 10.152 + 10.153 +// #define RC_INIT(buffer) 10.154 +// Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; 10.155 +// { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }} 10.156 +// } 10.157 +// RC_INIT(inStream); 10.158 + 10.159 +#ifndef NO_LZMA_HEADER 10.160 +#ifdef CHECK_LZMA_HEADER 10.161 + cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1) 10.162 + je lzip_header 10.163 + cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8) 10.164 + jne no_header 10.165 + add $13-6, SI // skip lzma header 10.166 +lzip_header: 10.167 + add $6, SI // skip lzip header 10.168 +no_header: 10.169 +#else 10.170 + add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8) 10.171 +#endif 10.172 +#endif 10.173 +setrep: 10.174 + call RC_LOAD_BYTE 10.175 + decb Range(BP) 10.176 + loop setrep 10.177 + 10.178 +lzdmainlp: 10.179 +// while(1) { 10.180 +// CProb *prob; 10.181 +// int posState = (int)((nowPos) & posStateMask); 10.182 +// 10.183 +// prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState; 10.184 +// if (Bit0(prob)) { /* char */ 10.185 + 10.186 + xor DX, DX 10.187 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 10.188 + mov $state, DI 10.189 + jc lzdstring 10.190 + 10.191 +// prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * 10.192 +// ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc)))); 10.193 + 10.194 +#if PROP_LC != 0 10.195 +# ifdef ONLY8086 10.196 + movb $8-PROP_LC, %cl 10.197 + shrb %cl, %bl 10.198 +# else 10.199 + shrb $8-PROP_LC, %bl 10.200 +# endif 10.201 +#endif 10.202 + 10.203 +#if PROP_LP != 0 10.204 + movb posState2(BP), %dl 10.205 +# ifdef ONLY8086 10.206 + movb $PROP_LC, %cl 10.207 + shl %cl, DX 10.208 +# else 10.209 + shl $PROP_LC, DX 10.210 +# endif 10.211 + movb $0, %bh 10.212 + add BX, DX 10.213 +#endif 10.214 + 10.215 + movb $3, %ah 10.216 + mul BX // dx = 3*bh 10.217 + add $1846, AX 10.218 + 10.219 +// int symbol = 1; 10.220 + 10.221 + CWD 10.222 + inc DX // symbol = 1 10.223 + xchg AX, CX // save prob 10.224 + 10.225 +// if (state >= kNumLitStates /*7*/) { /* previous was string */ 10.226 +// if (state < 4) state = 0; 10.227 + 10.228 +lzd6z: 10.229 + subb $3, (BP, DI) 10.230 + 10.231 +// if (state < 4) state = 0; 10.232 + 10.233 + jnc lzd6 10.234 + movb %dh, (BP, DI) // %dh = 0 10.235 + 10.236 +lzd6: 10.237 +// else if (state < 10) state -= 3; 10.238 + 10.239 + cmpb $10-3, (BP, DI) 10.240 + 10.241 +// else state -= 6; 10.242 + 10.243 + jnb lzd6z 10.244 + cmpb $7-3-1, (BP, DI) 10.245 + jbe lzd3 10.246 + 10.247 +// int matchByte = outStream[nowPos - rep0]; 10.248 + 10.249 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0]; 10.250 + 10.251 +// do { 10.252 +// int bit; 10.253 +// CProb *probLit; 10.254 +// matchByte <<= 1; bit = (matchByte & 0x100); 10.255 + 10.256 + movb $1, %bh 10.257 +lzd4: 10.258 + shlb $1, %bl // matchByte <<= 1 10.259 + sbb DI, DI // save bit=C 10.260 + 10.261 +// probLit = prob + 0x100 + bit + symbol; 10.262 + 10.263 + mov CX, AX // restore prob 10.264 + adcb %bh, %ah // + bit + 0x100 10.265 + 10.266 +// RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break) 10.267 + 10.268 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 10.269 + rclb $1, %dl // symbol <<= 1; symbol |= C 10.270 + jc lzd5 // if symbol >= 0x100 10.271 + cmp DI, AX 10.272 + jz lzd4 // if bit == Bit1(prob+%ax) 10.273 + 10.274 +// } while (symbol < 0x100); 10.275 +// } 10.276 +lzd3: 10.277 +// while (symbol < 0x100) { 10.278 +// CProb *probLit = prob + symbol; 10.279 +// RC_GET_BIT(probLit, symbol) 10.280 +// } 10.281 + 10.282 + xor BX, BX 10.283 + jmp lzd4 10.284 +lzd5: 10.285 + 10.286 +// outStream[nowPos++] = previousByte = (Byte)symbol; 10.287 + 10.288 + xchg AX, DX 10.289 + call outchar // %bl = outStream[nowPos++] = %al; 10.290 + jmp lzdmainlp 10.291 + 10.292 +// } 10.293 + 10.294 +lzdstring: 10.295 + mov $1, CX 10.296 + 10.297 +// else { /* string */ 10.298 +// prob = p + IsRep /*192*/ + state; 10.299 + 10.300 + movb $192, %dl 10.301 + addb (BP, DI), %dl 10.302 + mov $rep0, DI 10.303 + 10.304 +// if (Bit0(prob)) { 10.305 + 10.306 + call Bit1dx // Bit1(prob) 10.307 + jc lzd8 10.308 + 10.309 +// rep3 = rep2; rep2 = rep1; rep1 = rep0; 10.310 +// state = (state < kNumLitStates /*7*/) ? 0 : 3; 10.311 + 10.312 + stc 10.313 + 10.314 +// prob = p + LenCoder /*818*/; 10.315 + 10.316 + mov $818, DX 10.317 + 10.318 +// } 10.319 + 10.320 + jmp lzd11a 10.321 + 10.322 +// else { 10.323 +lzd8: 10.324 +// prob += kNumStates /*12*/; 10.325 +// if (Bit0(prob)) { 10.326 + call Bit1dx12 // prob += 12; Bit1(prob) 10.327 + jc lzd11 10.328 +// prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) 10.329 +// + posState; 10.330 + movb $240, %dl // dh=0 10.331 + 10.332 +// if (Bit0(prob)) { 10.333 + 10.334 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 10.335 + jc lzd12 10.336 + 10.337 +// // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR; 10.338 +// state = (state < kNumLitStates /*7*/) ? 9 : 11; 10.339 + 10.340 + movb $9, %dl 10.341 + 10.342 +// len++; goto string; 10.343 + jmp lzd13string // ax = 0 10.344 +// } 10.345 +// } 10.346 +// else { 10.347 +lzd11: 10.348 +// UInt32 distance = rep1; 10.349 +// prob += kNumStates /*12*/; 10.350 +// if (!Bit0(prob)) { 10.351 + 10.352 + call Bit1dx12 // prob += 12; Bit1(prob) 10.353 + jnc lzd11z 10.354 + 10.355 +// prob += kNumStates /*12*/; 10.356 +// if (Bit0(prob)) distance = rep2; 10.357 + 10.358 + call Bit1dx12 // prob += 12; Bit1(prob) 10.359 +lzd11a: 10.360 + adcb %cl, %cl 10.361 + 10.362 +// else { distance = rep3; rep3 = rep2; } 10.363 +// rep2 = rep1; 10.364 +// } 10.365 +// rep1 = rep0; rep0 = distance; 10.366 + 10.367 +lzd11z: 10.368 +# ifdef ONLY8086 10.369 + shl $1, CX 10.370 + shl $1, CX // 8->32 bits 10.371 + sub CX, DI // &rep[cx] 10.372 + movw (BP, DI), %ax 10.373 + pushw 2(BP, DI) 10.374 +rotreplp: 10.375 + movb 4(BP, DI), %bl 10.376 + movb %bl, (BP, DI) 10.377 + inc DI 10.378 + loop rotreplp 10.379 + popw %bx 10.380 + testb %dh, %dh 10.381 + jnz lzd10 10.382 + movw %ax, (BP, DI) 10.383 + movw %bx, 2(BP, DI) 10.384 +# else 10.385 + shl $2, CX // 8->32 bits 10.386 + sub CX, DI // &rep[cx] 10.387 + movl (BP, DI), %eax 10.388 +rotreplp: 10.389 + movb 4(BP, DI), %bl 10.390 + movb %bl, (BP, DI) 10.391 + inc DI 10.392 + loop rotreplp 10.393 + testb %dh, %dh 10.394 + jnz lzd10 10.395 + movl %eax, (BP, DI) 10.396 +# endif 10.397 + 10.398 +// } 10.399 +lzd12: 10.400 +// state = (state < kNumLitStates /*7*/) ? 8 : 11; 10.401 + 10.402 + movb $0x08, %cl 10.403 + 10.404 +// prob = p + RepLenCoder /*1332*/; 10.405 + 10.406 + mov $1332, DX 10.407 + 10.408 +// } 10.409 +lzd10: 10.410 + push CX // CX = 0 10.411 + 10.412 +// { /* get len */ 10.413 +// int numBits, offset; 10.414 +// CProb *probLen = prob + LenChoice /*0*/; 10.415 +// numBits = kLenNumLowBits /*3*/; 10.416 + 10.417 + movb $8, %cl // numBits : 3,3,8 10.418 + 10.419 +// if (Bit0(probLen)) { 10.420 + 10.421 + call Bit1dx // Bit1(prob) 10.422 + xchg AX, BX 10.423 + inc DX 10.424 + jnc lzd15 // bx=0 10.425 + 10.426 +// probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/); 10.427 +// offset = 0; 10.428 +// } 10.429 +// else { 10.430 +// probLen = prob + LenChoice2 /*1*/; 10.431 + 10.432 + call Bit1dx // Bit1(prob) 10.433 + add AX, BX 10.434 + 10.435 +#if PROP_PB != 0 10.436 + inc AX // ah=0 10.437 +#endif 10.438 + jc lzd16 // %ax=0, %bx=-2 10.439 +lzd15: 10.440 +#if PROP_PB != 0 10.441 + movb $8, %al 10.442 + mulb posState(BP) 10.443 +#endif 10.444 + 10.445 +// if (Bit0(probLen)) { 10.446 +// probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/); 10.447 + 10.448 + movb $3, %cl // numBits : 3,3,8 10.449 +lzd16: 10.450 +#if PROP_PB != 0 10.451 + add $2-128-1, AX // probLen : 2,130,258 10.452 +#else 10.453 + mov $2-128-1, AX // probLen : 2,130,258 10.454 +#endif 10.455 + add DX, AX 10.456 + mov $-8+1, DX // offset : 0,8,16 10.457 +lzdargslp: 10.458 + add $8, DX 10.459 + add $128, AX 10.460 + inc BX 10.461 + jle lzdargslp // leave with bx=1 10.462 + 10.463 +// offset = kLenNumLowSymbols /*8*/; 10.464 +// //numBits = kLenNumMidBits /*3*/; 10.465 +// } 10.466 +// else { 10.467 +// probLen = prob + LenHigh /*258*/; 10.468 +// offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/; 10.469 +// numBits = kLenNumHighBits /*8*/; 10.470 +// } 10.471 +// } 10.472 +// RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset; 10.473 + 10.474 + push DX 10.475 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 10.476 + pop DX 10.477 + add DX, AX // offset 10.478 + pop DX // 0 10.479 +lzd13string: 10.480 + push AX 10.481 + 10.482 +// state = (state < kNumLitStates /*7*/) ? dl : dl|3; 10.483 + 10.484 + movb $7, %cl 10.485 + cmpb %cl, state(BP) 10.486 + jb new_state 10.487 + orb $3, %dl 10.488 +new_state: 10.489 + movb %dl, state(BP) 10.490 + 10.491 +// } /* get len */ 10.492 +// if (state < 4) { 10.493 + 10.494 + cmpb $4-1, %dl 10.495 + ja lzd19 10.496 + 10.497 +// int posSlot; 10.498 +// state += kNumLitStates /*7*/; 10.499 + 10.500 + addb %cl, state(BP) 10.501 + 10.502 +// prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? 10.503 +// len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/); 10.504 + 10.505 + cmp $4+1, AX 10.506 + jb lzd21 10.507 + mov $3+1, AX 10.508 + 10.509 +lzd21: 10.510 + 10.511 + dec CX // cx = 6 10.512 + shl %cl, AX 10.513 + add $432-64, AX 10.514 + 10.515 +// RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot); 10.516 + 10.517 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 10.518 + 10.519 +// if (posSlot >= kStartPosModelIndex /*4*/) { 10.520 +// int numDirectBits = ((posSlot >> 1) - 1); 10.521 + 10.522 +#ifndef FLAT32 10.523 + movw %cx, 2(%bp, %di) // %cx = 0 10.524 +#endif 10.525 + mov AX, (BP, DI) 10.526 + mov AX, CX 10.527 + shrw $1, CX 10.528 + dec CX 10.529 + cmpb $4, %al 10.530 + jb lzd22 10.531 + 10.532 +// rep0 = (2 | ((UInt32)posSlot & 1)); 10.533 + 10.534 + andb %bl, (BP, DI) // %bx=1 10.535 + orb $2, (BP, DI) 10.536 + 10.537 +// if (posSlot < kEndPosModelIndex /*14*/) { 10.538 + 10.539 + cmpb $14, %al 10.540 + jnb lzd23 10.541 + 10.542 +// rep0 <<= numDirectBits; 10.543 + 10.544 + neg AX 10.545 +# ifdef ONLY8086 10.546 + pushw %cx 10.547 + movb $0, %ch 10.548 +shllrep0: 10.549 + shlw $1, (BP, DI) 10.550 + rclw $1, 2(BP, DI) 10.551 + loop shllrep0 10.552 + popw %cx 10.553 +# else 10.554 + shll %cl, (BP, DI) 10.555 +# endif 10.556 + add (BP, DI), AX 10.557 + 10.558 +// prob = p + SpecPos /*688*/ + rep0 - posSlot - 1; 10.559 + 10.560 + add $687, AX 10.561 + jmp lzd24 10.562 + 10.563 +// } 10.564 +// else { 10.565 +lzd23: 10.566 +// numDirectBits -= kNumAlignBits /*4*/; 10.567 +// do { 10.568 +// RC_NORMALIZE; Range >>= 1; rep0 <<= 1; 10.569 +// if (Code >= Range) { Code -= Range; rep0 |= 1; } 10.570 + 10.571 +lzd23z: 10.572 + call RC_NORMALIZE 10.573 +# ifdef ONLY8086 10.574 + pushw %dx 10.575 + shrw $1, Range+2(BP) 10.576 + rcrw $1, Range(BP) 10.577 + movw Range(BP), %ax 10.578 + movw Range+2(BP), %dx 10.579 + cmpw Code+2(BP), %dx 10.580 + ja lzd25 10.581 + jb lzd25x 10.582 + cmpw Code(BP), %ax 10.583 + ja lzd25 10.584 +lzd25x: 10.585 + subw %ax, Code(BP) 10.586 + sbbw %dx, Code+2(BP) 10.587 + stc 10.588 +lzd25: 10.589 + popw %dx 10.590 + rclw $1, (BP, DI) 10.591 + rclw $1, 2(BP, DI) 10.592 +# else 10.593 + shrl $1, Range(BP) 10.594 + movl Range(BP), %eax 10.595 + cmpl Code(BP), %eax 10.596 + ja lzd25 10.597 + subl %eax, Code(BP) 10.598 + stc 10.599 +lzd25: 10.600 + rcll $1, (BP, DI) 10.601 +# endif 10.602 + 10.603 +// } while (--numDirectBits != 0); 10.604 + 10.605 + cmpb $4+1, %cl 10.606 + loopne lzd23z 10.607 + 10.608 +// prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/; 10.609 +// rep0 <<= numDirectBits; 10.610 + 10.611 +# ifdef ONLY8086 10.612 + pushw %cx 10.613 + movb $0, %ch 10.614 +shlrep0: 10.615 + shlw $1, (BP, DI) 10.616 + rclw $1, 2(BP, DI) 10.617 + loop shlrep0 10.618 + popw %cx 10.619 +# else 10.620 + shll %cl, (BP, DI) 10.621 +# endif 10.622 + mov $802, AX 10.623 +// } 10.624 + 10.625 +lzd24: 10.626 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 10.627 + 10.628 +// { 10.629 +// int i = 1, mi = 1; 10.630 +// do { 10.631 +// CProb *prob3 = prob + mi; 10.632 +// RC_GET_BIT2(prob3, mi, ; , rep0 |= i); 10.633 + 10.634 + orb %dh, (BP, DI) // update rep0 with DirectBits 10.635 + 10.636 +// i <<= 1; 10.637 +// } while(--numDirectBits != 0); 10.638 +// } 10.639 +// } else rep0 = posSlot; 10.640 +lzd22: 10.641 +// if (++rep0 == (UInt32)(0)) break; /* EOF */ 10.642 + 10.643 +# ifdef ONLY8086 10.644 + incw (BP, DI) 10.645 + jnz lzd19 10.646 + incw 2(BP, DI) 10.647 +# else 10.648 + incl (BP, DI) 10.649 +# endif 10.650 + 10.651 +lzd19: 10.652 + pop CX 10.653 + jz lzdone 10.654 + 10.655 +// } 10.656 +// len += kMatchMinLen;/*2*/ 10.657 + 10.658 + inc CX 10.659 + 10.660 +// string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR; 10.661 +// do { 10.662 +lzd13z: 10.663 +// previousByte = outStream[nowPos - rep0]; 10.664 +// outStream[nowPos++] = previousByte; 10.665 + 10.666 + call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0] 10.667 + 10.668 +// } while(--len != 0); 10.669 + 10.670 + loop lzd13z 10.671 + 10.672 +// } /* char/string */ 10.673 +// } 10.674 + 10.675 + jmp lzdmainlp 10.676 + 10.677 +lzdone: 10.678 +// //RC_NORMALIZE; 10.679 +// //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos; 10.680 +// return LZMA_RESULT_OK; 10.681 + call Dico2ESDI // set es & di (rep0 = 0) 10.682 + lea ws2(BP), SP // dealloc 10.683 + ret 10.684 +// } 10.685 + 10.686 +// al = outStream[nowPos - rep0]; 10.687 + 10.688 +/* 10.689 + * output es:di, al 10.690 + * scratch bh, cl, flags 10.691 + */ 10.692 + 10.693 +DicoRep02ESDI: 10.694 + stc 10.695 + 10.696 +// bl = outStream[nowPos]; 10.697 + 10.698 +/* 10.699 + * output es:di, bl 10.700 + * scratch bh, cl, flags 10.701 + */ 10.702 + 10.703 +Dico2ESDI: 10.704 +#if !defined(FLAT32) && !defined(FLAT16OUT) 10.705 +# ifdef ONLY8086 10.706 + pushw %ax 10.707 + movw nowPos(%bp), %bx 10.708 + movw nowPos+2(%bp), %ax 10.709 + jnc Dico2ESDIz 10.710 + subw rep0(%bp), %bx 10.711 + sbbw rep0+2(%bp), %ax 10.712 +Dico2ESDIz: 10.713 + movw $0xF, %di 10.714 + andw %bx, %di 10.715 + pushw %cx 10.716 + movb $4, %cl 10.717 + shrw %cl, %bx 10.718 + shlw %cl, %ax 10.719 + popw %cx 10.720 + addb %al, %bh 10.721 + popw %ax 10.722 +# else 10.723 + movl nowPos(%bp), %ebx 10.724 + jnc Dico2ESDIz 10.725 + subl rep0(%bp), %ebx 10.726 +Dico2ESDIz: 10.727 + movw %bx, %di 10.728 + xorw %bx, %bx 10.729 + shrl $4, %ebx 10.730 +# endif 10.731 + movw %bx, %es 10.732 +#else 10.733 + mov nowPos(BP), DI 10.734 + jnc Dico2ESDIz 10.735 + sub rep0(BP), DI 10.736 +Dico2ESDIz: 10.737 +#endif 10.738 +#ifdef FLAT32 10.739 + movb (DI), %bl 10.740 +#else 10.741 + movb %es:(%di), %bl 10.742 +#endif 10.743 + ret 10.744 + 10.745 +outcharDico: 10.746 + 10.747 +// bl = outStream[nowPos++] = outStream[nowPos - rep0] 10.748 + 10.749 +/* 10.750 + * output es:di, bl 10.751 + * update nowPos 10.752 + * scratch ax, dx, bh, cl, flags 10.753 + */ 10.754 + 10.755 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0] 10.756 + xchg AX, BX 10.757 +outchar: 10.758 + 10.759 +// bl = outStream[nowPos++] = previousByte = al; 10.760 + 10.761 +/* 10.762 + * output bl 10.763 + * update nowPos 10.764 + * scratch ax, dx, bh, di, cl, flags 10.765 + */ 10.766 + 10.767 + clc 10.768 + call Dico2ESDI 10.769 + stosb 10.770 + xchg AX, BX // previous byte 10.771 + 10.772 +// int posState = (int)((nowPos) & posStateMask); 10.773 + 10.774 +#if PROP_PB != 0 && PROP_LP != 0 10.775 + addw $0x0101, posState2(BP) 10.776 + andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP) 10.777 +#else 10.778 +# if PROP_PB != 0 10.779 + incb posState(BP) 10.780 + andb $((1 << PROP_PB) -1), posState(BP) 10.781 +# endif 10.782 +# if PROP_LP != 0 10.783 + incb posState2(BP) 10.784 + andb $((1 << PROP_LP) -1), posState2(BP) 10.785 +# endif 10.786 +#endif 10.787 +#ifdef ONLY8086 10.788 + incw nowPos(BP) 10.789 + jnz incnowPosDone 10.790 + incw nowPos+2(BP) 10.791 +incnowPosDone: 10.792 +#else 10.793 + incl nowPos(BP) 10.794 +#endif 10.795 + ret 10.796 + 10.797 +// 10.798 +// #define RC_NORMALIZE if (Range < kTopValue) 10.799 +// { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 10.800 + 10.801 +/* 10.802 + * update Range, Code, ds:si 10.803 + * scratch flags 10.804 + */ 10.805 + 10.806 +RC_NORMALIZE: 10.807 + cmpb $0, Range+3(BP) 10.808 + jne RC_NORMALIZE_1 10.809 +RC_LOAD_BYTE: 10.810 + push AX 10.811 +#ifdef ONLY8086 10.812 + movw Range+1(BP), %ax 10.813 + movw %ax, Range+2(BP) 10.814 + movw Code+1(BP), %ax 10.815 + movw %ax, Code+2(BP) 10.816 + xorw %ax, %ax 10.817 + movb Range(BP), %ah 10.818 + movw %ax, Range(BP) 10.819 + movb Code(BP), %ah 10.820 + movw %ax, Code(BP) 10.821 +#else 10.822 + shll $8, Range(BP) 10.823 + shll $8, Code(BP) 10.824 +#endif 10.825 +#if !defined(FLAT16) && !defined(FLAT32) 10.826 + testw %si, %si 10.827 + jns RC_READ_BYTE 10.828 + movw %ds, %ax 10.829 + incw %ax 10.830 + movw %ax, %ds 10.831 + addw $-16, %si 10.832 +RC_READ_BYTE: 10.833 +#endif 10.834 + lodsb 10.835 + movb %al, Code(BP) 10.836 + pop AX 10.837 +RC_NORMALIZE_1: 10.838 + ret 10.839 + 10.840 +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 10.841 + 10.842 +Bit1state: 10.843 + movb $16, %al 10.844 + mulb state(BP) 10.845 +# if PROP_PB != 0 10.846 + addb posState(BP), %al 10.847 +# endif 10.848 +Bit1axdx: 10.849 + add DX, AX 10.850 + jmp Bit1 10.851 + 10.852 +// prob += 12; Bit1(prob) 10.853 + 10.854 +Bit1dx12: 10.855 + add $12, DX 10.856 +Bit1dx: 10.857 + mov DX, AX 10.858 + 10.859 +// static int Bit1(CProb *p) 10.860 + 10.861 +Bit1: 10.862 +/* 10.863 + * input ax=p 10.864 + * output C, ax 10.865 + * update bound, Range, Code, ds:si 10.866 + * scratch flags 10.867 + */ 10.868 + 10.869 +// { 10.870 +// RC_NORMALIZE; 10.871 + 10.872 + call RC_NORMALIZE // kill %ax, update %si 10.873 + 10.874 +#ifdef ONLY8086 10.875 + pushw %ax 10.876 + pushw %cx 10.877 + pushw %dx 10.878 + pushw %di 10.879 +#else 10.880 + pushal 10.881 +#endif 10.882 + 10.883 + xchg AX, DI 10.884 + add DI, DI // short * 10.885 + 10.886 + 10.887 +// bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p); 10.888 + 10.889 +#ifdef ONLY8086 10.890 + movw Range(BP), %dx 10.891 + movw Range+2(BP), %ax 10.892 + movw $11, %cx 10.893 +shr11lp: 10.894 + shrw $1, %ax 10.895 + rcrw $1, %dx 10.896 + loop shr11lp 10.897 + movw %dx, %cx 10.898 + mulw (BP, DI) 10.899 + xchgw %ax, %cx 10.900 + mulw (BP, DI) 10.901 + addw %cx, %dx 10.902 +#else 10.903 + movl Range(BP), %eax 10.904 + shrl $11, %eax 10.905 + movzwl (BP, DI), %edx 10.906 + mull %edx 10.907 +#endif 10.908 + 10.909 +// if (Code < bound) { 10.910 + 10.911 +#ifdef ONLY8086 10.912 + cmpw Code+2(BP), %dx 10.913 + jb Bit1_1 10.914 + ja Bit1_1x 10.915 + cmpw Code(BP), %ax 10.916 + jbe Bit1_1 10.917 +Bit1_1x: 10.918 + 10.919 +// Range = bound; 10.920 + 10.921 + movw %ax, Range(BP) 10.922 + movw %dx, Range+2(BP) 10.923 +#else 10.924 + cmpl Code(BP), %eax 10.925 + jbe Bit1_1 10.926 + 10.927 +// Range = bound; 10.928 + 10.929 + movl %eax, Range(BP) 10.930 +#endif 10.931 + 10.932 +// *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/; 10.933 + 10.934 + movw $2048, %ax 10.935 + 10.936 +// return 0; 10.937 + 10.938 + jmp Bit1_2 10.939 + 10.940 +// } 10.941 +// else { 10.942 + 10.943 +Bit1_1: 10.944 + 10.945 +// Range -= bound; Code -= bound; 10.946 + 10.947 +#ifdef ONLY8086 10.948 + subw %ax, Range(BP) 10.949 + sbbw %dx, Range+2(BP) 10.950 + subw %ax, Code(BP) 10.951 + sbbw %dx, Code+2(BP) 10.952 +#else 10.953 + subl %eax, Range(BP) 10.954 + subl %eax, Code(BP) 10.955 +#endif 10.956 + 10.957 +// *(p) -= (*(p)) >> kNumMoveBits /*5*/; 10.958 + 10.959 + movw $31, %ax 10.960 + 10.961 +// return 1; 10.962 + 10.963 + stc 10.964 +Bit1_2: 10.965 + pushf 10.966 + subw (BP, DI), %ax 10.967 +#ifdef ONLY8086 10.968 + movb $5, %cl 10.969 + sarw %cl, %ax 10.970 +#else 10.971 + sarw $5, %ax 10.972 +#endif 10.973 + addw %ax, (BP, DI) 10.974 + popf 10.975 +#ifdef ONLY8086 10.976 + popw %di 10.977 + popw %dx 10.978 + popw %cx 10.979 + popw %ax 10.980 +#else 10.981 + popal 10.982 +#endif 10.983 + sbb AX, AX 10.984 + 10.985 +// } 10.986 +// } 10.987 + 10.988 + ret 10.989 + 10.990 +RangeDecoder: 10.991 + 10.992 +/* 10.993 + * input ax=probs cx=numLevels (< 8) bx=1 10.994 + * output ax=res (backward), dh (forward) 10.995 + * update bound, Range, Code, ds:si 10.996 + * scratch flags, cx=0, dl 10.997 + */ 10.998 + 10.999 + push BX 10.1000 + 10.1001 +// { int i = numLevels; res = 1; 10.1002 + mov BX, DX // res = 1 10.1003 + 10.1004 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); 10.1005 + 10.1006 +RangeDecoder_1: 10.1007 + push AX 10.1008 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 10.1009 + rclb $1, %dl // res <<= 1; res |= C 10.1010 + andb %bl, %al // current bit 10.1011 + orb %al, %bh // store in bh 10.1012 + shlb $1, %bl // update max 10.1013 + pop AX 10.1014 + loop RangeDecoder_1 10.1015 + 10.1016 +// res -= (1 << numLevels); } 10.1017 + 10.1018 + xchg AX, BX // move bh to dh 10.1019 + xchg AX, DX // and dl to al 10.1020 + sub %dl, %al // sub max 10.1021 + pop BX 10.1022 + ret
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/memtest/stuff/unpack.S Fri Apr 30 16:35:54 2021 +0000 11.3 @@ -0,0 +1,284 @@ 11.4 +#define SYSTEM 0x10000 11.5 +#define SETUP 14 11.6 +#define SYSSIZE 0x1F4 11.7 +#define SETUPSIZE 0x1F1 11.8 + 11.9 +#define LINUX_HEADER 0 11.10 +#define UPDATE_SYSSIZE 1 11.11 +#define HARDCODED_SYSSIZE 1 11.12 +#define HARDCODED_SETUPSIZE 1 11.13 +#define FLAT16 1 11.14 +//#define FLAT16OUT 0 11.15 +#define SAVEREGS 0 11.16 +#define ELKS 0 11.17 + 11.18 + .text 11.19 + .code16 11.20 + .org 0 11.21 + 11.22 +#if ELKS 11.23 + .arch i8086 11.24 +#define FLAT16 1 11.25 +#define LINUX_HEADER 0 11.26 +#define SAVEREGS 0 11.27 +#define TOPSEG 0x2000 11.28 +#else 11.29 +#define TOPSEG 0x8000 11.30 +#endif 11.31 + 11.32 + .globl _start 11.33 +_start: 11.34 +#if LINUX_HEADER 11.35 + jmp start2 11.36 + .ascii "HdrS" // 202 magic 11.37 + .word 0x200 // 206 version 2.00 11.38 + .long 0 // 208 realmode_swtch 11.39 + .word SYSTEM/16 // 20C start_sys_seg 11.40 + .word 0 // 20E kernel_version 11.41 + .byte 0 // 210 type_of_loader 11.42 + .byte 0 // 211 loadflags 11.43 + .word 0 // 212 setup_move_size 11.44 + .long SYSTEM // 214 code32_start 11.45 + .long 0 // 218 ramdisk_image 11.46 + .long 0 // 21C ramdisk_size 11.47 + .long 0 // 220 bootsect_kludge 11.48 +start2: 11.49 +#endif 11.50 +#if SAVEREGS 11.51 + pushfw 11.52 + pushw %cs 11.53 + pushw $0 11.54 + pushal 11.55 + pushw %ds 11.56 + cld 11.57 +#else 11.58 + pushw %cs 11.59 +# if FLAT16 11.60 + xorw %di, %di 11.61 + pushw %di 11.62 +# else 11.63 + pushw $0 11.64 +# endif 11.65 +#endif 11.66 +#if ELKS 11.67 + movw $0x100, %ax 11.68 + pushw %ax 11.69 +#else 11.70 +#if UPDATE_SYSSIZE 11.71 + pushw %ds // <A> 11.72 +#else 11.73 + pushw %cs // <A> 11.74 +#endif 11.75 +#endif 11.76 +#if FLAT16 11.77 +# 1- move 9020..9020+stp -> TOPSEG 11.78 +#if ELKS 11.79 + movb $TOPSEG/256, %ah 11.80 + movw %ax, %es 11.81 +#else 11.82 + pushw $TOPSEG 11.83 + popw %es 11.84 +#endif 11.85 + movw $0x200, %si 11.86 +#if SAVEREGS == 0 11.87 + pushw %es 11.88 +#if ELKS 11.89 + movw $cont, %ax 11.90 + pushw %ax 11.91 +#else 11.92 + // pushw $cont 11.93 + .byte 0x6A, cont 11.94 +#endif 11.95 + jmp jumpinto 11.96 +#else 11.97 +# if HARDCODED_SETUPSIZE 11.98 +setup_word: 11.99 + movw $SETUP*256, %cx 11.100 +# else 11.101 + xorw %cx, %cx 11.102 + movb SETUPSIZE, %ch 11.103 + movw %cx, %dx 11.104 +# endif 11.105 + pushw %cx // <B> 11.106 + pushw %es 11.107 + pushw %di 11.108 + rep 11.109 + movsw 11.110 + lret 11.111 +#endif 11.112 +cont: 11.113 +# 2- move 1000..1000+sys -> TOPSEG+stp 11.114 +#if ELKS 11.115 + movw $0x1000, %ax 11.116 + movw %ax, %ds 11.117 +#else 11.118 + pushw $0x1000 11.119 + popw %ds 11.120 +#endif 11.121 + xorw %si, %si 11.122 + subw %di, %cx 11.123 + rep 11.124 + movsb 11.125 +# 3- unlz(TOPSEG+stp:end, 1000-stp:0) 11.126 + pushw %es // <C> 11.127 +# if HARDCODED_SETUPSIZE 11.128 +setup_seg: 11.129 +#if ELKS 11.130 +# if UPDATE_SYSSIZE 11.131 + movw $0x1000-(SETUP*32)-32, %ax 11.132 +# else 11.133 + movw $0x1000-(SETUP*32), %ax 11.134 +# endif 11.135 + movw %ax, %es 11.136 +#else 11.137 +# if UPDATE_SYSSIZE 11.138 + pushw $0x1000-(SETUP*32)-32 11.139 +# else 11.140 + pushw $0x1000-(SETUP*32) 11.141 +# endif 11.142 + popw %es 11.143 +#endif 11.144 +# else 11.145 +# if UPDATE_SYSSIZE 11.146 + incb %dh 11.147 +# endif 11.148 +#if ELKS 11.149 + shrw $1, %dx 11.150 + shrw $1, %dx 11.151 + shrw $1, %dx 11.152 +#else 11.153 + shrw $3, %dx 11.154 +#endif 11.155 + movw %ds, %ax 11.156 + subw %dx, %ax 11.157 + movw %ax, %es 11.158 +# endif 11.159 +#else // FLAT16 11.160 +# 1- move 1000..1000+sys -> 9000-sys 11.161 +# if HARDCODED_SYSSIZE 11.162 +packed_syssize: 11.163 + movw $0x1000+0, %ax 11.164 +# else 11.165 + movw SYSSIZE, %ax 11.166 + addw $0x1000, %ax 11.167 +# endif 11.168 + movw %ds, %dx 11.169 +mvsys: 11.170 + decw %ax 11.171 + decw %dx 11.172 + movw %ax, %ds 11.173 + movw %dx, %es 11.174 + xorw %si, %si 11.175 + xorw %di, %di 11.176 + movw $8, %cx 11.177 + rep 11.178 + movsw 11.179 + cmpw $0x1000, %ax 11.180 + jne mvsys 11.181 +# 2- move 9020..9020+stp -> 9000-sys-stp 11.182 + 11.183 +# if HARDCODED_SETUPSIZE 11.184 +setup_byte: 11.185 + movb $SETUP, %ch 11.186 +setup_para: 11.187 + subw $SETUP*32, %dx 11.188 +# else 11.189 + movb %ss:SETUPSIZE, %ch 11.190 + movw %cx, %ax 11.191 +#if ELKS 11.192 + shrw $1, %ax 11.193 + shrw $1, %ax 11.194 + shrw $1, %ax 11.195 +#else 11.196 + shrw $3, %ax 11.197 +#endif 11.198 + subw %ax, %dx 11.199 +# endif 11.200 + pushw %cx // <B> 11.201 + movw %dx, %es 11.202 + xorw %si, %si 11.203 + xorw %di, %di 11.204 + rep 11.205 + movsw %cs:(%si),%es:(%di) 11.206 + pushw %es 11.207 +# 3- reloc itself in 0x7C00 11.208 + pushw $0x07C0 11.209 + popw %es 11.210 + movw $cont, %si 11.211 + movw %si, %di 11.212 + movw $end-_start, %cx 11.213 + pushw %es 11.214 + pushw %di 11.215 + rep 11.216 + movsb %cs:(%si),%es:(%di) 11.217 + lret 11.218 +cont: 11.219 +# 4- unlz(9000-sys-stp:end, 1000-stp:0) 11.220 +# if HARDCODED_SETUPSIZE 11.221 +setup_seg: 11.222 +# if UPDATE_SYSSIZE 11.223 + pushw $0x1000-(SETUP*32)-32 11.224 +# else 11.225 + pushw $0x1000-(SETUP*32) 11.226 +# endif 11.227 + popw %es 11.228 +# else 11.229 + negw %ax 11.230 +# if UPDATE_SYSSIZE 11.231 + addw $0x1000-32, %ax 11.232 +# else 11.233 + addw $0x1000, %ax 11.234 +# endif 11.235 + movw %ax, %es 11.236 +# endif 11.237 +#endif // FLAT16 11.238 + popw %ds // <C> 11.239 + movw $end-_start, %si 11.240 +#if UPDATE_SYSSIZE 11.241 + movw $SYSSIZE, %di 11.242 +#else 11.243 + xorw %di, %di 11.244 +#endif 11.245 + pushw %di 11.246 + pushw %es 11.247 + call unpack 11.248 + popw %ds 11.249 + popw %si 11.250 + movw %si, %di 11.251 +# if SAVEREGS != 0 11.252 + popw %cx // <B> 11.253 +#if UPDATE_SYSSIZE 11.254 +// not need with memtest movb $(512-SYSSIZE)/2, %cl 11.255 +#endif 11.256 + popw %es // <A> 11.257 +# 5- move 1000-stp..1000 -> 9020 11.258 +# else 11.259 + popw %es // <A> 11.260 +jumpinto: 11.261 +# if HARDCODED_SETUPSIZE 11.262 +setup_word: 11.263 + movw $SETUP*256, %cx 11.264 +# else 11.265 + xorw %cx, %cx 11.266 + movb %ss:SETUPSIZE, %ch 11.267 + movw %cx, %dx 11.268 +# endif 11.269 +# endif 11.270 + rep 11.271 + movsw 11.272 +#if SAVEREGS 11.273 + popw %ds 11.274 + popal 11.275 + iret 11.276 +#else 11.277 + lret 11.278 +#endif 11.279 + 11.280 +unpack: 11.281 +#define NO_LZMA_HEADER 11.282 +#if ELKS 11.283 +#define ONLY8086 1 11.284 +#endif 11.285 +#include "unlzma.S" 11.286 + 11.287 +end: