wok-tiny view linux/stuff/unpacklz4.S @ rev 174

Up linux 2.6.20 (avoid 386 & 486 problems)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 14 14:20:00 2021 +0000 (2021-07-14)
parents d22f6fcf51da
children
line source
1 // objdump -D -b binary -mi386 -Maddr16,data16 mbr
3 .code16
4 .org 0
6 // LZ4 LZSA1 LZSA2 or LZMA
7 #define COMPRESSION_LZ4
8 #define HOLE 0x4000
9 #define DS_OFS 0x0200
11 start:
12 cld
13 #define packed_moved HOLE+0x200+packed
14 movw $packed_moved-next, %di
15 xorw %si, %si
16 movw %di, %cx
17 pushw %ds
18 popw %es
19 rep movsb %ds:(%si), %es:(%di) // move setup
20 pushw %cs // CS
21 pushw %cx // IP = 0
22 //pushaw
23 call packed_moved
24 next:
25 popw %bx
26 leaw DS_OFS+start-next(%bx), %di
27 leaw DS_OFS+packed-next(%bx,%si), %si
28 #if defined(COMPRESSION_LZMA)
29 call unlzma
30 #elif defined(COMPRESSION_LZSA2)
31 call unlzsa2
32 #elif defined(COMPRESSION_LZSA1)
33 call unlzsa1
34 #else
36 #define ARCHIVE_MAGICNUMBER 0x184C2102
37 #define NEGATIVE_OFFSETS 0 // non standard hack
38 #define LENGTH_16BITS 0 // non standard hack
39 #define BYTE_RLE 0
41 lz4main:
42 lodsl // get chunkSize
43 //cmpl $ARCHIVE_MAGICNUMBER, %eax
44 //je lz4main
45 //lodsw
46 addw %si, %ax
47 xchgw %ax, %dx
48 //lodsw
49 jmp lz4chunk // %cx = 0
51 lz4len: // get length in %cx
52 andw $0xF, %ax
53 cmpb $0xF, %al
54 xchgw %ax, %cx
55 jne lz4quit
56 lz4len2:
57 lodsb
58 addw %ax, %cx
59 cmpb $0xFF, %al
60 #if LENGTH_16BITS
61 jne lz4quit
62 lodsw
63 addw %ax, %cx
64 #else
65 je lz4len2
66 #endif
67 lz4quit:
68 ret
70 #if BYTE_RLE
71 movb -1(%di), %al
72 rep stosb %es:(%di) // fill string
73 jmp lz4chunk
74 #endif
76 lz4string:
77 lodsw // get string offset
78 xchgw %ax, %bx
79 call lz4len // get string length
80 add $4, %cx // minimum match is 4
81 #if BYTE_RLE
82 decw %bx
83 jz lz4rle
84 # if NEGATIVE_OFFSETS
85 incw %bx
86 # else
87 notw %bx
88 # endif
89 #endif
90 pushw %si
91 #if NEGATIVE_OFFSETS || BYTE_RLE
92 leaw (%bx,%di), %si
93 #else
94 movw %di, %si
95 subw %bx, %si
96 #endif
97 #ifdef USE_MOVSW
98 # if NEGATIVE_OFFSETS || BYTE_RLE
99 cmpw $-2, %bx
100 jb lzs4_move_words
101 # else
102 cmpw $2, %bx
103 ja lzs4_move_words
104 # endif
105 lodsw %es:(%si)
106 je lzs4_store_word
107 movb %al, %ah
108 lzs4_store_word:
109 shrw $1, %cx
110 rep stosw %es:(%di)
111 adcw %cx, %cx
112 rep stosb %es:(%di)
113 lzs4_move_words:
114 shrw $1, %cx
115 rep movsw %es:(%si), %es:(%di)
116 adcw %cx, %cx
117 #endif
118 rep movsb %es:(%si), %es:(%di) // copy string
119 popw %si
121 lz4chunk: // uncompress chunk
122 lodsb // get token
123 movb %al, %bl
124 shrb $4, %al
125 call lz4len // get literal length
126 #ifdef USE_MOVSW
127 shrw $1, %cx
128 rep movsw %ds:(%si), %es:(%di)
129 adcw %cx, %cx
130 #endif
131 rep movsb %ds:(%si), %es:(%di) // copy literals
132 cmpw %dx, %si
133 jb lz4string
134 #endif
135 done:
136 movw $0x020E, %di
137 movsw // version string
138 movw $0x01F1, %di
139 movsb // setup size
140 //popaw
141 retf
143 #if defined(COMPRESSION_LZMA)
144 #define FLAT16 1
145 #define FLAT16OUT 1
146 #define NO_LZMA_HEADER 1
147 unlzma:
148 #include "unlzma.S"
149 #elif defined(COMPRESSION_LZSA2)
150 unlzsa2:
151 #include "unlzsa2.S"
152 #elif defined(COMPRESSION_LZSA1)
153 unlzsa1:
154 #include "unlzsa1.S"
155 #endif
157 packed: