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

Up foomatic-db (4.0-20221117)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 18 09:54:27 2022 +0000 (17 months ago)
parents ed5f25d05ff6
children e9e2e1c1770c
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 #ifndef NO_LZ4_HEADER
36 cmpl $ARCHIVE_MAGICNUMBER, %eax
37 je lz4main
38 #endif
39 orl %eax, %eax // end of file ?
40 je lz4quit
41 xchgl %eax, %edx
42 lz4chunk: // uncompress chunk
43 lodsb // get token
44 movb %al, %bl
45 shrb $4, %al
46 call lz4len // get literal length, %eax < 255
47 subl %ecx, %edx // count literal
48 subl $1+2, %edx // count token & string address
49 #if !defined(FLAT32) && !defined(FLAT16OUT)
50 pushf
51 call lz4mov // copy literals
52 popf
53 #else
54 rep movsb
55 #endif
56 jle lz4main
57 lodsw // get string address
58 xchgw %ax, %bx
59 call lz4len // get string length
60 add $4, CX
61 #if !defined(FLAT32) && !defined(FLAT16OUT)
62 pushw %ds
63 pushw %si
64 movw %di, %si
65 subw %bx, %si
66 movw %es, %ax
67 jnc axok
68 subb $0x10, %ah
69 axok:
70 movw %ax, %ds
71 call lz4mov // copy string
72 popw %si
73 popw %ds
74 #else
75 xchg AX, SI
76 mov DI, SI
77 sub BX, SI
78 rep movsb %es(SI), %es(DI)
79 xchg AX, SI
80 #endif
81 jmp lz4chunk
83 #if !defined(FLAT32) && !defined(FLAT16OUT)
84 # if defined(PARANOIA)
85 lz4movlp:
86 xchgw %ax, %cx
87 movw $0x3C00, %cx
88 rep movsl
89 xchgw %ax, %cx
90 sub $0xF0, %ch
91 # endif
92 lz4mov:
93 movw %di, %ax
94 andw $0xF, %di
95 shrw $4, %ax
96 movw %es, %bp
97 addw %ax, %bp
98 movw %bp, %es
99 movw %si, %ax
100 andw $0xF, %si
101 shrw $4, %ax
102 movw %ds, %bp
103 addw %ax, %bp
104 movw %bp, %ds
105 # if defined(PARANOIA)
106 cmp $0xFF, %ch // catch FFFX case
107 jz lz4movlp
108 # endif
109 rep movsb
110 ret
111 #endif
113 lz4len: // get length in %ecx
114 andl $0xF, %eax
115 movl %eax, %ecx
116 cmpb $0xF, %al
117 jne lz4quit
118 lz4len2:
119 lodsb
120 decl %edx // remaining chunk size
121 addw %ax, %cx
122 cmpb $0xFF, %al
123 je lz4len2
124 lz4quit:
125 ret