lzma PackLinuxElf64amd works!
This commit is contained in:
+705
-706
File diff suppressed because it is too large
Load Diff
@@ -73,7 +73,6 @@ ret_main:
|
|||||||
/* Returns 0 on success; non-zero on failure. */
|
/* Returns 0 on success; non-zero on failure. */
|
||||||
decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint method)
|
decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint method)
|
||||||
|
|
||||||
section NRV_COMMON
|
|
||||||
/* Arguments according to calling convention */
|
/* Arguments according to calling convention */
|
||||||
#define src %arg1
|
#define src %arg1
|
||||||
#define lsrc %arg2
|
#define lsrc %arg2
|
||||||
@@ -82,6 +81,13 @@ decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint meth
|
|||||||
#define meth %arg5l
|
#define meth %arg5l
|
||||||
#define methb %arg5b
|
#define methb %arg5b
|
||||||
|
|
||||||
|
push %rbp; push %rbx // C callable
|
||||||
|
push ldst
|
||||||
|
push dst
|
||||||
|
addq src,lsrc; push lsrc // &input_eof
|
||||||
|
|
||||||
|
section NRV_COMMON
|
||||||
|
|
||||||
/* Working registers */
|
/* Working registers */
|
||||||
#define off %eax /* XXX: 2GB */
|
#define off %eax /* XXX: 2GB */
|
||||||
#define len %ecx /* XXX: 2GB */
|
#define len %ecx /* XXX: 2GB */
|
||||||
@@ -89,11 +95,6 @@ decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint meth
|
|||||||
#define bits %ebx
|
#define bits %ebx
|
||||||
#define disp %rbp
|
#define disp %rbp
|
||||||
|
|
||||||
push %rbp; push %rbx // C callable
|
|
||||||
push ldst
|
|
||||||
push dst
|
|
||||||
addq src,lsrc; push lsrc // &input_eof
|
|
||||||
|
|
||||||
movq src,%rsi // hardware src for movsb, lodsb
|
movq src,%rsi // hardware src for movsb, lodsb
|
||||||
movq dst,%rdi // hardware dst for movsb
|
movq dst,%rdi // hardware dst for movsb
|
||||||
xor bits,bits // empty; force refill
|
xor bits,bits // empty; force refill
|
||||||
@@ -272,7 +273,7 @@ unfold:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
main:
|
main:
|
||||||
int3 # uncomment for debugging
|
//// int3 # uncomment for debugging
|
||||||
pop %rbp // &decompress
|
pop %rbp // &decompress
|
||||||
movl -4-(ret_main - _start)(%rbp),%r15d // length which precedes stub
|
movl -4-(ret_main - _start)(%rbp),%r15d // length which precedes stub
|
||||||
subl $ sz_Ehdr + 2*sz_Phdr + sz_l_info + sz_p_info,%r15d
|
subl $ sz_Ehdr + 2*sz_Phdr + sz_l_info + sz_p_info,%r15d
|
||||||
|
|||||||
@@ -39,53 +39,56 @@ section LZMA_ELF00
|
|||||||
#define meth %arg5l /* %r8 */
|
#define meth %arg5l /* %r8 */
|
||||||
#define methb %arg5b
|
#define methb %arg5b
|
||||||
|
|
||||||
|
// ELFMAINX has already done this for us:
|
||||||
|
// pushq %rbp; push %rbx // C callable
|
||||||
|
// pushq ldst
|
||||||
|
// pushq dst
|
||||||
|
// addq src,lsrc; push lsrc // &input_eof
|
||||||
|
|
||||||
#define M_LZMA 14
|
#define M_LZMA 14
|
||||||
cmpb $ M_LZMA,methb; jne not_lzma
|
cmpb $ M_LZMA,methb; jne not_lzma
|
||||||
// C calling convention
|
|
||||||
pushq %rbp; movq %rsp,%rbp
|
pushq %rbp; movq %rsp,%rbp // we use alloca
|
||||||
pushq %rbx
|
|
||||||
|
|
||||||
//LzmaDecode( // from lzmaSDK/C/7zip/Compress/LZMA_C/LzmaDecode.h
|
//LzmaDecode( // from lzmaSDK/C/7zip/Compress/LZMA_C/LzmaDecode.h
|
||||||
// %arg1= &CLzmaDecoderState,
|
// %arg1= &CLzmaDecoderState,
|
||||||
// %arg2= in, %arg3l= inSize, %arg4= &inSizeProcessed,
|
// %arg2= in, %arg3l= inSize, %arg4= &inSizeProcessed,
|
||||||
// %arg5= out, %arg6l= outSize, 8+%esp/ &outSizeProcessed
|
// %arg5= out, %arg6l= outSize, arg7@ 8+%esp/ &outSizeProcessed
|
||||||
//)
|
//)
|
||||||
|
movl (ldst),%arg6l // &outSize XXX: 4GB
|
||||||
|
movq dst,%arg5 // outp
|
||||||
|
movq lsrc,%arg3 // inSize
|
||||||
|
leaq 2(src),%arg2; pushq %arg2 // in; save @-8(%rbp) for size calc at eof
|
||||||
|
|
||||||
|
movb (src),%al; decl %arg3l // first byte, replaces LzmaDecodeProperties()
|
||||||
|
movb %al,%cl // cl= ((lit_context_bits + lit_pos_bits)<<3) | pos_bits
|
||||||
|
andb $7,%al // al= pos_bits
|
||||||
|
shrb $3,%cl // cl= lit_context_bits + lit_pos_bits
|
||||||
|
|
||||||
#define LZMA_BASE_SIZE 1846
|
#define LZMA_BASE_SIZE 1846
|
||||||
#define LZMA_LIT_SIZE 768
|
#define LZMA_LIT_SIZE 768
|
||||||
#define szSizeT 8
|
#define szSizeT 4
|
||||||
|
|
||||||
movq dst,%arg5 // outp
|
|
||||||
movq lsrc,%arg3 // inSize
|
|
||||||
movq src,%arg2 // in
|
|
||||||
movq ldst,%r10
|
|
||||||
|
|
||||||
lodsb; decl %arg3l // first byte, replaces LzmaDecodeProperties()
|
|
||||||
movb %al,%cl // cl= ((lit_context_bits + lit_pos_bits)<<3) | pos_bits
|
|
||||||
andb $6,%al // al= pos_bits
|
|
||||||
shrb $3,%cl // cl= lit_context_bits + lit_pos_bits
|
|
||||||
|
|
||||||
movq $-LZMA_LIT_SIZE,%rbx
|
movq $-LZMA_LIT_SIZE,%rbx
|
||||||
shlq %cl,%rbx
|
shlq %cl,%rbx; movb %al,%cl // %cl= pos_bits
|
||||||
// inSizeProcessed, outSizeProcessed, *_bits, CLzmaDecoderState
|
// alloca{inSizeProcessed, outSizeProcessed, *_bits, CLzmaDecoderState}
|
||||||
leaq -(2*szSizeT +4) - 2*LZMA_BASE_SIZE(%rsp,%rbx,2), %rbx
|
leaq -(2*szSizeT +4) - 2*LZMA_BASE_SIZE(%rsp,%rbx,2), %rbx
|
||||||
andq $~0<<6,%rbx // 64-byte align
|
andq $~0<<6,%rbx // 64-byte align
|
||||||
1:
|
1:
|
||||||
pushq $0
|
pushq $0 // clera CLzmaDecoderState on stack
|
||||||
cmpq %rbx,%rsp
|
cmpq %rbx,%rsp
|
||||||
jne 1b
|
jne 1b
|
||||||
|
|
||||||
pushq %rbx; addq $ szSizeT,%rbx // &outSizeProcessed
|
|
||||||
movl (%r10),%arg6l // &outSize XXX: 4GB
|
|
||||||
movq %rbx,%arg4; addq $ szSizeT,%rbx // &inSizeProcessed
|
|
||||||
|
|
||||||
movb %al,2(%rbx) // store pos_bits
|
pushq %rbx // &outSizeProcessed [arg7]
|
||||||
lodsb; decl %arg3l // second byte, replaces LzmaDecodeProperties()
|
leaq 2*szSizeT(%rbx),%arg1 // &CLzmaDecoderState
|
||||||
movb %al,%cl // cl= (lit_pos_bits<<4) | lit_context_bits
|
movb -1(%arg2),%cl; decl %arg3l // second byte, replaces LzmaDecodeProperties()
|
||||||
andb $0xf,%al; movb %al, (%rbx) // store lit_context_bits
|
movb %al,2(%arg1) // store pos_bits
|
||||||
shrb $4, %cl; movb %cl,1(%rbx) // store lit_pos_bits
|
movb %cl,%al // al= (lit_pos_bits<<4) | lit_context_bits
|
||||||
|
shrb $4,%cl; movb %cl,1(%arg1) // store lit_pos_bits
|
||||||
|
andb $0xf,%al; movb %al, (%arg1) // store lit_context_bits
|
||||||
|
leaq -szSizeT(%arg1),%arg4 // &inSizeProcessed
|
||||||
|
|
||||||
movq %rbx,%arg1 // &CLzmaDecoderState
|
|
||||||
pushq %rax // return address slot (dummy CALL)
|
pushq %rax // return address slot (dummy CALL)
|
||||||
|
|
||||||
section LZMA_DEC10
|
section LZMA_DEC10
|
||||||
@@ -94,25 +97,12 @@ section LZMA_DEC10
|
|||||||
section LZMA_DEC20
|
section LZMA_DEC20
|
||||||
#include "lzma_d_cf.S"
|
#include "lzma_d_cf.S"
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// cleanup
|
|
||||||
section LZMA_DEC30
|
section LZMA_DEC30
|
||||||
|
movq -1*8(%rbp),%rsi // src [after header]
|
||||||
movl -1*szSizeT(%rbx),%eax; addq %rax,%rsi // inSizeProcessed
|
movq 2*8(%rbp),%rdi // dst
|
||||||
movl -2*szSizeT(%rbx),%eax; addq %rax,%rdi // outSizeProcessed
|
movl szSizeT(%rbx),%ecx; addq %rcx,%rsi // inSizeProcessed
|
||||||
xorq %rax,%rax
|
movl (%rbx),%edx; addq %rdx,%rdi // outSizeProcessed
|
||||||
|
leave // movl %ebp,%rsp; popq %rbp
|
||||||
leaq -256(%rsp),%rcx
|
|
||||||
movq %rbp,%rsp // restore stack
|
|
||||||
1:
|
|
||||||
pushq %rax
|
|
||||||
cmpq %rcx,%rsp
|
|
||||||
jne 1b
|
|
||||||
|
|
||||||
movq -8(%rbp),%rbx
|
|
||||||
xorq %rcx,%rcx
|
|
||||||
leave
|
|
||||||
not_lzma:
|
not_lzma:
|
||||||
|
|
||||||
// vi:ts=8:et
|
// vi:ts=8:et
|
||||||
|
|||||||
Reference in New Issue
Block a user