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

linux: pack setup (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jul 07 11:56:18 2018 +0200 (2018-07-07)
parents d71bd8881bcd
children 2c80994c5e30
line source
1 // objdump -D -b binary -mi386 -Maddr16,data16 mbr
3 .code16
4 .org 0
6 #define LZMA 0
7 #define HOLE 0x4000
8 #define DS_OFS 0x0200
10 start:
11 cld
12 #define packed_moved HOLE+0x200+packed
13 movw $packed_moved-next, %di
14 xorw %si, %si
15 movw %di, %cx
16 pushw %ds
17 popw %es
18 rep movsb %ds:(%si), %es:(%di) // move setup
19 pushw %cs // CS
20 pushw %cx // IP = 0
21 //pushaw
22 call packed_moved
23 next:
24 popw %bx
25 leaw DS_OFS+start-next(%bx), %di
26 leaw DS_OFS+packed-next(%bx,%si), %si
27 #if LZMA
28 call unlzma
29 #else
31 #define ARCHIVE_MAGICNUMBER 0x184C2102
32 #define NEGATIVE_OFFSETS 0 // non standard hack
33 #define LENGTH_16BITS 0 // non standard hack
34 #define BYTE_RLE 0
36 lz4main:
37 lodsl // get chunkSize
38 //cmpl $ARCHIVE_MAGICNUMBER, %eax
39 //je lz4main
40 //lodsw
41 addw %si, %ax
42 xchgw %ax, %dx
43 //lodsw
44 jmp lz4chunk // %cx = 0
46 lz4len: // get length in %cx
47 andw $0xF, %ax
48 cmpb $0xF, %al
49 xchgw %ax, %cx
50 jne lz4quit
51 lz4len2:
52 lodsb
53 addw %ax, %cx
54 cmpb $0xFF, %al
55 #if LENGTH_16BITS
56 jne lz4quit
57 lodsw
58 addw %ax, %cx
59 #else
60 je lz4len2
61 #endif
62 lz4quit:
63 ret
65 #if BYTE_RLE
66 movb -1(%di), %al
67 rep stosb %es:(%di) // fill string
68 jmp lz4chunk
69 #endif
71 lz4string:
72 lodsw // get string offset
73 xchgw %ax, %bx
74 call lz4len // get string length
75 add $4, %cx // minimum match is 4
76 #if BYTE_RLE
77 decw %bx
78 jz lz4rle
79 # if NEGATIVE_OFFSETS
80 incw %bx
81 # else
82 notw %bx
83 # endif
84 #endif
85 xchgw %ax, %si
86 #if NEGATIVE_OFFSETS || BYTE_RLE
87 leaw (%bx,%di), %si
88 #else
89 movw %di, %si
90 subw %bx, %si
91 #endif
92 rep movsb %ds:(%si), %es:(%di) // copy string
93 xchgw %ax, %si
95 lz4chunk: // uncompress chunk
96 lodsb // get token
97 movb %al, %bl
98 shrb $4, %al
99 call lz4len // get literal length
100 rep movsb %ds:(%si), %es:(%di) // copy literals
101 cmpw %dx, %si
102 jb lz4string
103 #endif
104 done:
105 movw $0x020E, %di
106 movsw // version string
107 movw $0x01F1, %di
108 movsb // setup size
109 //popaw
110 retf
112 #if LZMA
113 #define FLAT16 1
114 #define FLAT16OUT 1
115 #define NO_LZMA_HEADER 1
116 unlzma:
117 #include "unlzma.S"
118 #endif
120 packed: