wok view memtest/stuff/unlzsa2.S @ rev 25504

Update some web_site / wget_url
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 05 09:28:51 2023 +0000 (15 months ago)
parents 48dff2952881
children 20c2ee666646
line source
1 // Lzsa2Decode:
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 BP %bp
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 BP %ebp
18 #define SI %esi
19 #define DI %edi
20 #endif
22 MATCH_RUN_LEN = 7
23 LITERALS_RUN_LEN = 3
24 MIN_MATCH_SIZE = 2
25 MIN_LITERALS_SIZE = 0
27 #define PACKED_ONLY // assume no copy block, optional
28 //#define PARANOIA // cover rare cases, optional
30 lzsa2main:
31 #ifdef PARANOIA
32 cld
33 #endif
34 #ifndef RAW_FORMAT
35 # if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
36 xorw %cx, %cx
37 call normalize
38 # endif
39 # ifndef NO_LZSA2_HEADER
40 lodsw
41 cmpw $0x9E7B, %ax // magic
42 jne lzsa2main
43 lodsb
44 testb $0x20, %al // lzsa2
45 je lzsa2main
46 # endif
47 lzsa2block: // uncompress chunk
48 # if !defined(FLAT32) && !defined(FLAT16)
49 xorw %cx, %cx
50 call normalize
51 # endif
52 lodsw // block size
53 xchgw %ax, %cx
54 lodsb
55 # ifndef PACKED_ONLY
56 orb %al, %al
57 jns lzsa2compressed
58 # if !defined(FLAT32) && !defined(FLAT16OUT)
59 movw %cx, %dx
60 movb $0, %cl
61 movb $0, %dh
62 copytail:
63 call lzsa1movStr
64 xchg %dx, %cx
65 incw %cx
66 loop copytail
67 # else
68 movsb // copy block
69 copylp:
70 movsb // copy block
71 loop copylp // handle 64K case
72 # endif
73 jmp lzsa2block
74 lzsa2compressed:
75 jne lzsa2chunk // 64Kb block
76 # endif
77 jcxz lzsa2quit // bail if we hit EOD
78 # if !defined(FLAT16)
79 pushw %cx
80 xorw %cx, %cx
81 call normalize
82 # define NeedNormalize
83 popw %dx
84 addw %si, %dx
85 # else
86 movw %si, %dx
87 addw %cx, %dx
88 # endif
89 #else
90 # if !defined(FLAT16)
91 xorw %cx, %cx
92 call normalize
93 # define NeedNormalize
94 # endif
95 #endif
96 movb $0, %bh // no nibble stored
97 lzsa2chunk: // uncompress chunk
98 lodsb // get token XYZ|LL|MMM
99 movb %al, %bl // keep token in bl
100 movw $LITERALS_RUN_LEN+256*MIN_LITERALS_SIZE, %cx
101 shrb %cl, %al // shift literals length into place
102 call lzsa2len // %cl = LITERALS_RUN_LEN
103 #if defined(NeedNormalize)
104 pushw %bp
105 call lzsa2movLit // copy %cx literals from %ds:%si to %es:%di
106 popw %bp
107 #else
108 rep movsb // copy %cx literals from %ds:%si to %es:%di
109 #endif
110 #ifndef RAW_FORMAT
111 maxsi:
112 cmpw %dx, %si
113 jae lzsa2block // bail if we hit EOD
114 #endif
115 #ifdef FLAT32
116 orl $-1, %eax // set offset bits 31-8 to 1
117 #else
118 movb $-1, %ah // set offset bits 15-8 to 1
119 #endif
120 // XYZ
121 testb $0xC0, %bl // check match offset mode in token (X bit)
122 bt $5, %bx // move bit 5 to carry
123 js rep_match_or_large_offset
124 jne offset_9_bit
125 // 00Z 5-bit offset: read a nibble for offset bits 1-4 and use the inverted bit Z of the token as bit 0 of the offset.
126 // set bits 5-15 of the offset to 1.
127 call getByteFromNibbleAndC
128 jmp get_match_length
129 offset_9_bit:
130 // 01Z 9-bit offset: read a byte for offset bits 0-7 and use the inverted bit Z for bit 8 of the offset.
131 // set bits 9-15 of the offset to 1.
132 sbbb %cl, %ah // clear bit 8 if Z bit is clear
133 jmp get_match_length_0
135 getNibble:
136 xorb $0xF0, %bh // toggle nibble stored flags
137 movb %bh, %al
138 jns gotnibble
139 lodsb
140 movb $0xF0, %bh
141 orb %al, %bh
142 shrb $4, %al
143 gotnibble:
144 lzsa2quit:
145 ret
147 rep_match_or_large_offset:
148 jpe rep_match_or_16_bit
149 //10Z 13-bit offset: read a nibble for offset bits 9-12 and use the inverted bit Z for bit 8 of the offset,
150 // then read a byte for offset bits 0-7. set bits 13-15 of the offset to 1.
151 // substract 512 from the offset to get the final value.
152 call getByteFromNibbleAndC
153 subb $2, %al // substract 512
154 jmp get_match_length_1
155 rep_match_or_16_bit:
156 jc repeat_match // rep-match
157 //110 16-bit offset: read a byte for offset bits 8-15, then another byte for offset bits 0-7.
158 lodsb // Get 2-byte match offset
159 get_match_length_1:
160 xchgb %al, %ah
161 get_match_length_0:
162 lodsb // load match offset bits 0-7
163 get_match_length:
164 xchgw %ax, %bp // bp: offset
165 repeat_match:
166 //111 repeat offset: reuse the offset value of the previous match command.
168 movb %bl, %al // %al: original token
169 movw $MATCH_RUN_LEN+256*MIN_MATCH_SIZE, %cx
170 call lzsa2len
171 #ifdef RAW_FORMAT
172 jz lzsa2quit // bail if we hit EOD
173 #endif
174 #if !defined(FLAT32) && !defined(FLAT16OUT)
175 pushw %ds
176 pushw %si
177 movw %di, %si
178 addw %bp, %si
179 movw %es, %ax
180 jc axok
181 subb $0x10, %ah
182 axok:
183 .macro norm reg
184 movw %si, \reg
185 subw %si, %dx
186 andw $0xF, %si
187 addw %si, %dx
188 shrw $4, \reg
189 addw \reg, %ax
190 movw %ax, %ds
191 movw %di, \reg
192 andw $0xF, %di
193 shrw $4, \reg
194 movw %es, %ax
195 addw \reg, %ax
196 movw %ax, %es
197 .endm
198 pushw %bp
199 pushw %dx
200 # if defined(NeedNormalize) || defined(PARANOIA)
201 call lzsa2movStr // copy string
202 # else
203 norm %bp
204 rep movsb
205 # endif
206 popw %dx
207 popw %bp
208 popw %si
209 popw %ds
210 #else
211 xchg AX, SI // save %si
212 lea (BP,DI), SI
213 rep movsb %es:(SI), %es:(DI)
214 xchg AX, SI // restore %si
215 #endif
216 jmp lzsa2chunk
218 getByteFromNibbleAndC:
219 pushfw
220 call getNibble // get nibble for offset bits 0-3
221 popfw
222 rclb $1, %al
223 xorb $0xE1, %al // set offset bits 7-5 to 1
224 ret
226 lzsa2len: // get length in %cx
227 andb %cl, %al
228 cbw // clear %ah
229 cmpb %al, %cl
230 jne lzsa2minNumber // S=0-2, L=0-6
231 call getNibble
232 cmp $0xF, %al
233 jne lzsa2noExtraByte
234 addb %al, %ch
235 lodsb
236 lzsa2noExtraByte:
237 addb %cl, %ch
238 lzsa2minNumber:
239 addb %ch, %al
240 jnc lzsa2gotNumber // 0-255
241 #if 0
242 je lzsa2BigNumber
243 movb %al, %ah // S=256-767, L=256-1791
244 lodsb
245 .byte 0xB1 // mask lodsw with movb $0xAD, %cl
246 lzsa2BigNumber:
247 #endif
248 lodsw // 0-65535
249 lzsa2gotNumber:
250 xchgw %ax, %cx
251 ret
253 #if defined(NeedNormalize) || defined(PARANOIA)
254 # if defined(PARANOIA)
255 lzsa2movlp:
256 decw %ch
257 rep movsb
258 incw %ch
259 # endif
260 normalize:
261 lzsa2movLit:
262 movw %ds, %ax
263 lzsa2movStr:
264 norm %bp
265 # if defined(PARANOIA)
266 cmpb $0xFF, %ch // catch FFFX case
267 je lzsa2movlp
268 # endif
269 rep movsb
270 ret
271 #endif