wok view memtest/stuff/unlzsa1.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 // Lzsa1Decode:
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 SI %si
9 #define DI %di
10 #else
11 // input esi=inStream, edi=outStream
12 // output outStream[], ds:esi, es:edi
13 .code32
14 #define AX %eax
15 #define BX %ebx
16 #define SI %esi
17 #define DI %edi
18 #endif
20 MATCH_RUN_LEN = 15
21 LITERALS_RUN_LEN = 7
22 MIN_MATCH_SIZE = 3
23 MIN_LITERALS_SIZE = 0
25 #define PACKED_ONLY // assume no copy block, optional
26 //#define PARANOIA // cover rare cases, optional
28 lzsa1main:
29 #ifdef PARANOIA
30 cld
31 #endif
32 #ifndef RAW_FORMAT
33 # if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
34 xorw %cx, %cx
35 call normalize
36 # endif
37 # ifndef NO_LZSA1_HEADER
38 lodsw
39 cmpw $0x9E7B, %ax // magic
40 jne lzsa1main
41 lodsb
42 cmpb $0, %al // lzsa1
43 jne lzsa1main
44 # endif
45 lzsa1block: // uncompress chunk
46 lodsw // block size
47 xchgw %ax, %cx
48 lodsb
49 # ifndef PACKED_ONLY
50 orb %al, %al
51 jns lzsa1compressed
52 # if !defined(FLAT32) && !defined(FLAT16OUT)
53 movw %cx, %dx
54 andb $0x7F, %ch
55 andw $0x8000, %dx
56 copy32k:
57 call lzsa1movStr
58 xchg %dx, %cx
59 incw %cx
60 loop copy32k
61 # else
62 movsb // copy block
63 copylp:
64 movsb // copy block
65 loop copylp // handle 64K case
66 # endif
67 jmp lzsa1block
68 lzsa1compressed:
69 jne lzsa1chunk // 64Kb block
70 # endif
71 jcxz lzsa1quit // bail if we hit EOD
72 movw %cx, %dx
73 # if !defined(FLAT32) && !defined(FLAT16)
74 xorw %cx, %cx
75 call normalize
76 # endif
77 addw %si, %dx
78 #endif
79 lzsa1chunk: // uncompress chunk
80 lodsb // get token O|LLL|MMMM
81 movb %al, %bl // keep token in bl
82 shrb $4, %al // shift literals length into place
83 movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
84 call lzsa1len // %ch = LITERALS_RUN_LEN
85 #if !defined(FLAT32) && !defined(FLAT16OUT)
86 call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di
87 #else
88 rep movsb // copy %cx literals from %ds:%si to %es:%di
89 #endif
90 #ifndef RAW_FORMAT
91 cmpw %dx, %si
92 jae lzsa1block // bail if we hit EOD
93 #endif
94 #ifdef FLAT32
95 orl $-1, %eax
96 #else
97 movb $-1, %ah
98 #endif
99 testb %bl, %bl // check match offset size in token (O bit)
100 jns lzsa1ShortOfs
101 lodsw
102 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
103 lzsa1ShortOfs:
104 lodsb
105 #ifdef RAW_FORMAT
106 orw %ax, %ax
107 jz lzsa1quit // bail if we hit EOD
108 #endif
109 xchg AX, BX // %bx: match offset %ax: original token
110 movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
111 call lzsa1len
112 #if !defined(FLAT32) && !defined(FLAT16OUT)
113 pushw %ds
114 pushw %si
115 movw %di, %si
116 addw %bx, %si
117 movw %es, %ax
118 jc dxok
119 subb $0x10, %ah
120 dxok:
121 movw %ax, %ds
122 call lzsa1movStr // copy string
123 popw %si
124 popw %ds
125 #else
126 xchg AX, SI // save %si
127 lea (BX,DI), SI
128 rep movsb %es:(SI), %es:(DI)
129 xchg AX, SI // restore %si
130 #endif
131 jmp lzsa1chunk
133 lzsa1len: // get length in %ecx
134 andb %ch, %al
135 cbw // clear %ah
136 cmpb %al, %ch
137 jne lzsa1minNumber // S=0-6, L=0-14
138 lodsb
139 addb %cl, %ch
140 addb %ch, %al
141 jnc lzsa1gotNumber // 0-255
142 movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511
143 jne lzsa1midNumber
144 lodsw // 0-65535
145 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
146 lzsa1midNumber:
147 lodsb
148 lzsa1gotNumber:
149 xchgw %ax, %cx
150 lzsa1quit:
151 ret
152 lzsa1minNumber:
153 addb %cl, %al
154 xchgw %ax, %cx
155 ret
157 #if !defined(FLAT32) && !defined(FLAT16OUT)
158 # if defined(PARANOIA)
159 lzsa1movlp:
160 decw %ch
161 rep movsb
162 incw %ch
163 # endif
164 normalize:
165 lzsa1movStr:
166 movw %si, %ax
167 andw $0xF, %si
168 shrw $4, %ax
169 movw %ds, %bp
170 addw %ax, %bp
171 movw %bp, %ds
172 lzsa1movLit:
173 movw %di, %ax
174 andw $0xF, %di
175 shrw $4, %ax
176 movw %es, %bp
177 addw %ax, %bp
178 movw %bp, %es
179 # if defined(PARANOIA)
180 cmpb $0xFF, %ch // catch FFFX case
181 je lzsa1movlp
182 # endif
183 rep movsb
184 ret
185 #endif