wok view memtest/stuff/unlz4.S @ rev 25807
dstat: added dependency python-six
author | Hans-G?nter Theisgen |
---|---|
date | Fri Dec 13 16:28:59 2024 +0100 (6 months ago) |
parents | 54dc5622a785 |
children |
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 #if defined(FLAT16OUT) || defined(ONLY8086)
23 #define cAX %ax
24 #define cCX %cx
25 #define cDX %dx
26 #else
27 #define cAX %eax
28 #define cCX %ecx
29 #define cDX %edx
30 #endif
32 #define ARCHIVE_MAGICNUMBER 0x184C2102
34 //#define PARANOIA // cover rare cases, optional
36 .macro norm1 reg, seg, ptr, loadax=1
37 .if \loadax
38 movw \seg, %ax
39 .endif
40 movw \ptr, \reg
41 #ifdef ONLY8086
42 shrw %cl, \reg
43 #else
44 shrw $4, \reg
45 #endif
46 #ifdef BACKWARD
47 subw $0xFFF, %ax
48 orw $0xFFF0, \ptr
49 #else
50 andw $0xF, \ptr
51 #endif
52 addw \reg, %ax
53 movw %ax, \seg
54 .endm
56 .macro norm reg, loadax=1
57 #ifdef ONLY8086
58 pushw %cx
59 movb $4, %cl
60 #endif
61 #ifndef FLAT16
62 norm1 \reg, %ds, %si, \loadax
63 #endif
64 norm1 \reg, %es, %di
65 #ifdef ONLY8086
66 popw %cx
67 #endif
68 .endm
70 lz4main:
71 #ifdef PARANOIA
72 cld
73 # if !defined(FLAT32) && !defined(FLAT16OUT)
74 xorl %cx, %cx
75 call lz4mov
76 # endif
77 #endif
78 #if defined(FLAT16OUT) || defined(ONLY8086)
79 lodsw // get chunkSize
80 # ifndef NO_LZ4_HEADER
81 cmpw $ARCHIVE_MAGICNUMBER&0xFFFF, %ax
82 # endif
83 xchg %ax, %dx
84 lodsw
85 # ifndef NO_LZ4_HEADER
86 jne chkeof
87 cmpw $ARCHIVE_MAGICNUMBER>>16, %ax
88 je lz4main
89 chkeof:
90 # endif
91 # ifdef PARANOIA
92 orw %ax, %dx // end of file ?
93 je lz4quit
94 # endif
95 # ifndef FLAT16OUT
96 xchgw %ax, %bp
97 subw $1, %dx
98 sbbw $0, %bp
99 # endif
100 #else
101 lodsl // get chunkSize
102 # ifndef NO_LZ4_HEADER
103 cmpl $ARCHIVE_MAGICNUMBER, %eax
104 je lz4main
105 # endif
106 # ifdef PARANOIA
107 orl %eax, %eax // end of file ?
108 je lz4quit
109 # endif
110 xchgl %eax, %edx
111 #endif
112 lz4chunk: // uncompress chunk
113 lodsb // get token
114 pushw %ax
115 #ifdef ONLY8086
116 movb $4, %cl
117 shrb %cl, %al
118 #else
119 shrb $4, %al
120 #endif
121 call lz4len // get literal length
122 #if !defined(FLAT16OUT) && defined(ONLY8086)
123 subw %cx, %dx // count literal
124 sbbw $0, %bp
125 #else
126 sub cCX, cDX // count literal
127 #endif
128 #if !defined(FLAT32) && !defined(FLAT16OUT) && (!defined(FLAT16) || !defined(PARANOIA))
129 #define NeedLz4mov
130 call lz4mov // copy literals
131 #else
132 rep movsb
133 #endif
134 popw %bx
135 #if !defined(FLAT16OUT) && defined(ONLY8086)
136 subw $1+2, %dx // count token & string address
137 sbbw $0, %bp
138 jb lz4quit
139 lz4cont:
140 #else
141 sub $1+2, cDX // count token & string address
142 jbe lz4quit
143 #endif
144 lodsw // get string address
145 xchg AX, BX
146 call lz4len // get string length
147 add $4, CX
148 #if !defined(FLAT32) && !defined(FLAT16OUT)
149 pushw %ds
150 pushw %si
151 movw %di, %si
152 movw %es, %ax
153 # ifdef BACKWARD
154 addw %bx, %si
155 jnc axok
156 addb $0x10, %ah
157 # else
158 subw %bx, %si
159 jnc axok
160 subb $0x10, %ah
161 # endif
162 axok:
163 # if !defined (NeedLz4mov)
164 norm %bx, 0
165 rep movsb
166 # else
167 call lz4movStr // copy string
168 # endif
169 popw %si
170 popw %ds
171 #else
172 # ifdef FASTFILL
173 cmp $FASTFILL,BX
174 jbe lz4fast
175 # endif
176 lz4notfast:
177 xchg AX, SI
178 # ifdef BACKWARD
179 lea (DI,BX), SI
180 # else
181 mov DI, SI
182 sub BX, SI
183 # endif
184 # ifdef ONLY8086
185 # jcxz 1f
186 2:
187 movsb %es:(SI), %es:(DI) // NMOS 8088/8086 workaround.
188 loop 2b
189 1:
190 # else
191 rep movsb %es:(SI), %es:(DI)
192 # endif
193 xchg AX, SI
194 # ifdef FASTFILL
195 lz4fast:
196 # if FASTFILL == 1
197 movb %es:-1(DI), %al
198 rep stosb
199 # endif
200 # if FASTFILL >= 2
201 movw %es:-2(DI), %ax
202 je lz4fastword
203 movb %al, %ah
204 lz4fastword:
205 shr $1, CX
206 rep stosw
207 jnc lz4chunk
208 stosb
209 # endif
210 # endif
211 #endif
212 jmp lz4chunk
214 #if defined(NeedLz4mov)
215 # if defined(PARANOIA)
216 lz4movlp:
217 xchgw %ax, %cx
218 movw $0x7800, %cx
219 rep movsw
220 xchgw %ax, %cx
221 sub $0xF0, %ch
222 # endif
223 lz4mov:
224 movw %ds, %ax
225 lz4movStr:
226 norm %bx, 0
227 # if defined(PARANOIA)
228 cmp $0xFF, %ch // catch FFFX case
229 jz lz4movlp
230 # endif
231 rep movsb
232 ret
233 #endif
235 lz4len: // get length in %ecx
236 and $0xF, cAX
237 mov cAX, cCX
238 cmpb $0xF, %al
239 jne lz4quit
240 lz4len2:
241 lodsb
242 #if !defined(FLAT16OUT) && defined(ONLY8086)
243 subw $1, %dx // remaining chunk size
244 sbbw $0, %bp
245 #else
246 dec cDX // remaining chunk size
247 #endif
248 add AX, CX
249 cmpb $0xFF, %al
250 je lz4len2
251 lz4quit:
252 ret