wok view memtest/stuff/unlz4.S @ rev 25487

Up exiftool (12.50), foomatic-db (4.0-20221111), lzsa (1.4.0), zlib (1.2.13)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 15 16:20:54 2022 +0000 (17 months ago)
parents 18d1dc85701e
children 2ccf00d9c1cd
line source
1 // Lz4Decode:
2 #ifndef FLAT32
3 // input ds:si=inStream, es:di=outStream
4 // output outStream[], ds:si, es:di
5 .code16
6 #define AX %ax
7 #define BX %bx
8 #define CX %cx
9 #define SI %si
10 #define DI %di
11 #else
12 // input esi=inStream, edi=outStream
13 // output outStream[], ds:esi, es:edi
14 .code32
15 #define AX %eax
16 #define BX %ebx
17 #define CX %ecx
18 #define SI %esi
19 #define DI %edi
20 #endif
22 #define ARCHIVE_MAGICNUMBER 0x184C2102
24 //#define PARANOIA // cover rare cases, optional
26 lz4main:
27 #ifdef PARANOIA
28 cld
29 # if !defined(FLAT32) && !defined(FLAT16OUT)
30 xorl %cx, %cx
31 call lz4mov
32 # endif
33 #endif
34 lodsl // get chunkSize
35 cmpl $ARCHIVE_MAGICNUMBER, %eax
36 je lz4main
37 orl %eax, %eax // end of file ?
38 je lz4quit
39 xchgl %eax, %edx
40 lz4chunk: // uncompress chunk
41 lodsb // get token
42 movb %al, %bl
43 shrb $4, %al
44 call lz4len // get literal length, %eax < 255
45 subl %ecx, %edx // count literal
46 subl $1+2, %edx // count token & string address
47 #if !defined(FLAT32) && !defined(FLAT16OUT)
48 pushf
49 call lz4mov // copy literals
50 popf
51 #else
52 rep movsb
53 #endif
54 jle lz4main
55 lodsw // get string address
56 xchgw %ax, %bx
57 call lz4len // get string length
58 add $4, CX
59 #if !defined(FLAT32) && !defined(FLAT16OUT)
60 pushw %ds
61 pushw %si
62 movw %di, %si
63 subw %bx, %si
64 movw %es, %ax
65 jnc axok
66 subb $0x10, %ah
67 axok:
68 movw %ax, %ds
69 call lz4mov // copy string
70 popw %si
71 popw %ds
72 #else
73 xchg AX, SI
74 mov DI, SI
75 sub BX, SI
76 rep movsb %es(SI), %es(DI)
77 xchg AX, SI
78 #endif
79 jmp lz4chunk
81 #if !defined(FLAT32) && !defined(FLAT16OUT)
82 # if defined(PARANOIA)
83 lz4movlp:
84 xchgw %ax, %cx
85 movw $0x3C00, %cx
86 rep movsl
87 xchgw %ax, %cx
88 sub $0xF0, %ch
89 # endif
90 lz4mov:
91 movw %di, %ax
92 andw $0xF, %di
93 shrw $4, %ax
94 movw %es, %bp
95 addw %ax, %bp
96 movw %bp, %es
97 movw %si, %ax
98 andw $0xF, %si
99 shrw $4, %ax
100 movw %ds, %bp
101 addw %ax, %bp
102 movw %bp, %ds
103 # if defined(PARANOIA)
104 cmp $0xFF, %ch // catch FFFX case
105 jz lz4movlp
106 # endif
107 rep movsb
108 ret
109 #endif
111 lz4len: // get length in %ecx
112 andl $0xF, %eax
113 movl %eax, %ecx
114 cmpb $0xF, %al
115 jne lz4quit
116 lz4len2:
117 lodsb
118 decl %edx // remaining chunk size
119 addw %ax, %cx
120 cmpb $0xFF, %al
121 je lz4len2
122 lz4quit:
123 ret