wok-next diff memtest/stuff/unlz4.S @ rev 14118

nmap: add patch for nolua support
author Samuel Trassare <samuel_trassare@yahoo.com>
date Mon Feb 25 08:44:23 2013 -0800 (2013-02-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memtest/stuff/unlz4.S	Mon Feb 25 08:44:23 2013 -0800
     1.3 @@ -0,0 +1,105 @@
     1.4 +/*
     1.5 + * Lz4Decode:
     1.6 +#ifndef FLAT32
     1.7 + *   input   ds:si=inStream, es:di=outStream
     1.8 + *   output  outStream[], ds:si, es:di
     1.9 +	.code16
    1.10 +#else
    1.11 + *   input   esi=inStream, edi=outStream
    1.12 + *   output  outStream[], esi, edi
    1.13 +	.code32
    1.14 +#endif
    1.15 + */
    1.16 + 
    1.17 +#define ARCHIVE_MAGICNUMBER 0x184C2102
    1.18 +
    1.19 +lz4main:
    1.20 +	cld
    1.21 +	lodsl			// get chunkSize
    1.22 +	cmpl	$ARCHIVE_MAGICNUMBER, %eax
    1.23 +	je	lz4main
    1.24 +	orl	%eax, %eax	// end of file ?
    1.25 +	je	lz4quit
    1.26 +	xchgl	%eax, %edx
    1.27 +lz4chunk:			// uncompress chunk
    1.28 +	lodsb			// get token
    1.29 +	decl	%edx
    1.30 +	movzbl	%al, %ebx
    1.31 +	shrb	$4, %al
    1.32 +	call	lz4len		// get literal length, %eax < 255
    1.33 +	incl	%ecx
    1.34 +	stc
    1.35 +	sbbl	%ecx, %edx
    1.36 +	pushf	
    1.37 +	call	lz4mov		// copy literals
    1.38 +	popf
    1.39 +	js	lz4main
    1.40 +	lodsw			// get string address
    1.41 +#ifndef FLAT32
    1.42 +	pushw	%bx
    1.43 +	movw	%di, %bx
    1.44 +	subl	%eax, %ebx
    1.45 +	popw	%ax
    1.46 +	call	lz4len		// get string length
    1.47 +	pushw	%ds
    1.48 +	pushw	%si
    1.49 +	pushw	%es
    1.50 +	popw	%ds
    1.51 +	movw	$0xF, %si
    1.52 +	andw	%bx, %si
    1.53 +	shrl	$4, %ebx
    1.54 +	addl	$4+1, %ecx
    1.55 +	movw	%bx, %bp
    1.56 +	call	lz4mov2		// copy string
    1.57 +	popw	%si
    1.58 +	popw	%ds
    1.59 +#else
    1.60 +	negl	%eax
    1.61 +	xchgl	%eax, %ebx
    1.62 +	addl	%edi, %ebx
    1.63 +	call	lz4len		// get string length
    1.64 +	pushl	%esi
    1.65 +	xchgl	%ebx, %esi
    1.66 +	call	lz4mov		// copy string
    1.67 +	popl	%esi
    1.68 +#endif
    1.69 +	jmp	lz4chunk
    1.70 +
    1.71 +lz4len:				// get length in %ecx
    1.72 +	andl	$0xF, %eax
    1.73 +	movl	%eax, %ecx
    1.74 +	cmpb	$0xF, %al
    1.75 +	jne	lz4quit
    1.76 +lz4len2:
    1.77 +	lodsb
    1.78 +	decl	%edx		// remaining chunk size
    1.79 +	addl	%eax, %ecx
    1.80 +	cmpb	$0xFF, %al
    1.81 +	je	lz4len2
    1.82 +lz4quit:
    1.83 +	ret
    1.84 +
    1.85 +lz4movlp:
    1.86 +	movsb
    1.87 +#ifndef FLAT32
    1.88 +	movw	$0x800, %bp
    1.89 +	orw	%di, %di
    1.90 +	jns	lz4di
    1.91 +	subw	$0x8000, %di
    1.92 +	movw	%es, %ax
    1.93 +	addw	%bp, %ax
    1.94 +	movw	%ax, %es
    1.95 +lz4di:
    1.96 +	orw	%si, %si
    1.97 +	jns	lz4si
    1.98 +	subw	$0x8000, %si
    1.99 +lz4mov2:
   1.100 +	movw	%ds, %ax
   1.101 +	addw	%bp, %ax
   1.102 +	movw	%ax, %ds
   1.103 +lz4si:
   1.104 +#endif
   1.105 +lz4mov:
   1.106 +	decl	%ecx
   1.107 +	jnz	lz4movlp
   1.108 +	ret