Skip to content

Commit

Permalink
Fix decompression stub for arm64 --lzma
Browse files Browse the repository at this point in the history
#181
	modified:   stub/src/arch/arm64/v8/lzma_d.S
  • Loading branch information
jreiser committed Feb 24, 2018
1 parent 0ef00e9 commit d698eb6
Show file tree
Hide file tree
Showing 7 changed files with 1,443 additions and 1,457 deletions.
888 changes: 443 additions & 445 deletions src/stub/arm64-darwin.macho-entry.h

Large diffs are not rendered by default.

911 changes: 455 additions & 456 deletions src/stub/arm64-linux.elf-entry.h

Large diffs are not rendered by default.

982 changes: 490 additions & 492 deletions src/stub/arm64-linux.shlib-init.h

Large diffs are not rendered by default.

77 changes: 34 additions & 43 deletions src/stub/src/arch/arm64/v8/lzma_d.S
Expand Up @@ -43,82 +43,73 @@ dst .req x2
#define M_LZMA 14
cmp meth,#M_LZMA; bne not_lzma

add x1,src,len,uxtw // x1= eof_src;
mov x4,#0
PUSH4(x1,x2,x3, lr)

PUSH2(x4,x4) // clear CLzmaDecoderState, inSizeProcessed, outSizeProcessed
State= 0
#define a0 x0 /* &CLzmaDecoderState */
add a0,sp,#State
#define a1 x1 /* inp */
#define a2 w2 /* inSize */
#define a3 x3 /* &inSizeProcessed */
add a3,sp,#8
#define a4 x4 /* outp */
#define a5 w5 /* outSize */
#define a6 x6 /* &outSizeProcessed */
add a6,sp,#12

#define t0 w7
#define t1 w8
#define t1x x8

#define fp x29
fp .req x29
PUSH4(x2,x3, fp,lr) // dst,ldst, fp,lr
mov fp,sp

//The target is:
//LzmaDecode( // from lzmaSDK/C/7zip/Compress/LZMA_C/LzmaDecode.h
// a0= &CLzmaDecoderState,
// a1= inp, a2= inSize, a3= &inSizeProcessed,
// a4= outp, a5= outSize, a6= &outSizeProcessed
//)
#define LZMA_BASE_SIZE 1846
#define LZMA_LIT_SIZE 768

ldrb t1,[src,#0] // first byte, replaces LzmaDecodeProperties()
mov t0,#2*LZMA_LIT_SIZE
lsr t1,t1,#3 // lit_context_bits + lit_pos_bits
lslv t0,t0,t1 // 2*LZMA_LIT_SIZE << (lit_context_bits + lit_pos_bits)
mov fp,sp
#define W 4 /* even #bits to round up so that 8 bits span all the 1's */
add t0,t0,#((~(~0<<W) + 2*LZMA_BASE_SIZE)>>W)<<W
add t0,t0,#((~(~0<<W) + 2*LZMA_BASE_SIZE)>>W)<<W // 0 mod 16

mov t1x,sp
sub sp,sp,t0,uxtw

1: // clear inSizeProcessed and CLzmaDecoderState
stp x4,x4,[x3],#2*8
cmp x3,t1x
mov x4,sp
1: // clear lzma probability array
stp xzr,xzr,[x4],#2*8
cmp x4,t1x
blo 1b

#define a0 x0 /* &CLzmaDecoderState */
#define a1 x1 /* inp */
#define a2 w2 /* inSize */
#define a3 x3 /* &inSizeProcessed */
#define a4 x4 /* outp */
#define a5 w5 /* outSize */
#define a6 x6 /* &outSizeProcessed */
//The target is:
//LzmaDecode( // from lzmaSDK/C/7zip/Compress/LZMA_C/LzmaDecode.h
// a0= &CLzmaDecoderState,
// a1= inp, a2= inSize, a3= &inSizeProcessed,
// a4= outp, a5= outSize, a6= &outSizeProcessed
//)
stp xzr,xzr,[sp,#-2*NBPW]! // clear CLzmaDecoderState, inSizeProcessed

mov a6,ldst // &outSizeProcessed
mov a5,t0 // outSize
ldr a5,[a6] // outSize
mov a4,dst // outp
add a3,sp,#8 // &inSizeProcessed
sub w2,lsrc,#2 // inSize
mov a1,src // inp
State= 0
add a0,sp,#State

ldrb t0,[a1],#1 // first byte, replaces LzmaDecodeProperties()
and t0,t0,#7 // posBits
strb t0,[sp,#2 + State]
strb t0,[a0,#2]
ldrb t0,[a1],#1 // second byte, replaces LzmaDecodeProperties()
lsr t1,t0,#4 // lit_pos_bits
strb t1,[sp,#1 + State]
strb t1,[a0,#1]
and t0,t0,#0xf // lib_context_bits
strb t0,[sp,#0 + State]

add a0,sp,#State
strb t0,[a0,#0]
bl 1f // the call
mov sp,fp

eof_lzma:
POP4(x1,x3,x4, lr) // x1= eof_src; r3= orig_dst; r4= plen_dst
SUB2(src,x1) // 0 if actual src length equals expected length
SUB2(dst,x3) // actual dst length
str dstw,[x4]
mov sp,fp
mov x4,x0 // save result value
POP4(x0,x1, fp,lr) // x0= orig_dst; x1= plen_dst
ldr x1,[x1] // outSizeProcessed

mov x0,x3 // orig_dst
add x1,x3,dst // orig_dst + dst_len
add x1,x1,x0 // last
cache_lzma:
dc cvau,x0 // Clean by VA to point of Unification
ic ivau,x0 // Invalidate by VA to point of Unification
Expand Down
12 changes: 6 additions & 6 deletions src/stub/tmp/arm64-darwin.macho-entry.bin.dump
Expand Up @@ -8,12 +8,12 @@ Idx Name Size VMA LMA File off Algn
3 NRV2D 0000011c 0000000000000000 0000000000000000 00000170 2**0 CONTENTS, READONLY
4 NRV2B 000000f0 0000000000000000 0000000000000000 0000028c 2**0 CONTENTS, READONLY
5 NRV_TAIL 00000000 0000000000000000 0000000000000000 0000037c 2**0 CONTENTS, READONLY
6 LZMA_ELF00 000000d0 0000000000000000 0000000000000000 0000037c 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 0000044c 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000db4 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001250 2**0 CONTENTS, READONLY
10 MACHMAINY 00000000 0000000000000000 0000000000000000 00001250 2**0 CONTENTS, READONLY
11 MACHMAINZ 00000150 0000000000000000 0000000000000000 00001250 2**0 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000b8 0000000000000000 0000000000000000 0000037c 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 00000434 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000d9c 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001238 2**0 CONTENTS, READONLY
10 MACHMAINY 00000000 0000000000000000 0000000000000000 00001238 2**0 CONTENTS, READONLY
11 MACHMAINZ 00000150 0000000000000000 0000000000000000 00001238 2**0 CONTENTS, RELOC, READONLY
SYMBOL TABLE:
0000000000000000 l d LZMA_DEC30 0000000000000000 LZMA_DEC30
0000000000000000 l d MACHMAINZ 0000000000000000 MACHMAINZ
Expand Down
12 changes: 6 additions & 6 deletions src/stub/tmp/arm64-linux.elf-entry.bin.dump
Expand Up @@ -8,12 +8,12 @@ Idx Name Size VMA LMA File off Algn
3 NRV2E 00000128 0000000000000000 0000000000000000 00000048 2**0 CONTENTS, READONLY
4 NRV2D 0000011c 0000000000000000 0000000000000000 00000170 2**0 CONTENTS, READONLY
5 NRV2B 000000f0 0000000000000000 0000000000000000 0000028c 2**0 CONTENTS, READONLY
6 LZMA_ELF00 000000d0 0000000000000000 0000000000000000 0000037c 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 0000044c 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000db4 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001250 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001250 2**0 CONTENTS, READONLY
11 ELFMAINZ 0000014c 0000000000000000 0000000000000000 00001290 2**2 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000b8 0000000000000000 0000000000000000 0000037c 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 00000434 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000d9c 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001238 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001238 2**0 CONTENTS, READONLY
11 ELFMAINZ 0000014c 0000000000000000 0000000000000000 00001278 2**2 CONTENTS, RELOC, READONLY
SYMBOL TABLE:
0000000000000000 l d LZMA_DEC30 0000000000000000 LZMA_DEC30
0000000000000000 l d ELFMAINZ 0000000000000000 ELFMAINZ
Expand Down
18 changes: 9 additions & 9 deletions src/stub/tmp/arm64-linux.shlib-init.bin.dump
Expand Up @@ -8,15 +8,15 @@ Idx Name Size VMA LMA File off Algn
3 NRV2E 00000128 0000000000000000 0000000000000000 00000050 2**0 CONTENTS, READONLY
4 NRV2D 0000011c 0000000000000000 0000000000000000 00000178 2**0 CONTENTS, READONLY
5 NRV2B 000000f0 0000000000000000 0000000000000000 00000294 2**0 CONTENTS, READONLY
6 LZMA_ELF00 000000d0 0000000000000000 0000000000000000 00000384 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 00000454 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000dbc 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001258 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001258 2**0 CONTENTS, READONLY
11 ELFMAINZ 00000000 0000000000000000 0000000000000000 00001296 2**0 CONTENTS, READONLY
12 ELFMAJNZ 00000024 0000000000000000 0000000000000000 00001296 2**0 CONTENTS, READONLY
13 ANDMAJNZ 00000004 0000000000000000 0000000000000000 000012ba 2**0 CONTENTS, READONLY
14 ELFMAKNZ 000002a0 0000000000000000 0000000000000000 000012be 2**0 CONTENTS, READONLY
6 LZMA_ELF00 000000b8 0000000000000000 0000000000000000 00000384 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000968 0000000000000000 0000000000000000 0000043c 2**0 CONTENTS, READONLY
8 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000da4 2**0 CONTENTS, READONLY
9 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001240 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001240 2**0 CONTENTS, READONLY
11 ELFMAINZ 00000000 0000000000000000 0000000000000000 0000127e 2**0 CONTENTS, READONLY
12 ELFMAJNZ 00000024 0000000000000000 0000000000000000 0000127e 2**0 CONTENTS, READONLY
13 ANDMAJNZ 00000004 0000000000000000 0000000000000000 000012a2 2**0 CONTENTS, READONLY
14 ELFMAKNZ 000002a0 0000000000000000 0000000000000000 000012a6 2**0 CONTENTS, READONLY
SYMBOL TABLE:
0000000000000000 l d LZMA_DEC30 0000000000000000 LZMA_DEC30
0000000000000000 l d ELFMAINZ 0000000000000000 ELFMAINZ
Expand Down

0 comments on commit d698eb6

Please sign in to comment.