1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

lzma PackLinuxElf64amd works!

This commit is contained in:
John Reiser 2006-07-15 20:05:41 -07:00
parent 3843ec1e02
commit 7185358b98
3 changed files with 748 additions and 758 deletions

File diff suppressed because it is too large Load Diff

View File

@ -73,7 +73,6 @@ ret_main:
/* Returns 0 on success; non-zero on failure. */
decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint method)
section NRV_COMMON
/* Arguments according to calling convention */
#define src %arg1
#define lsrc %arg2
@ -82,6 +81,13 @@ decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint meth
#define meth %arg5l
#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 */
#define off %eax /* 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 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 dst,%rdi // hardware dst for movsb
xor bits,bits // empty; force refill
@ -272,7 +273,7 @@ unfold:
ret
main:
int3 # uncomment for debugging
//// int3 # uncomment for debugging
pop %rbp // &decompress
movl -4-(ret_main - _start)(%rbp),%r15d // length which precedes stub
subl $ sz_Ehdr + 2*sz_Phdr + sz_l_info + sz_p_info,%r15d

View File

@ -39,53 +39,56 @@ section LZMA_ELF00
#define meth %arg5l /* %r8 */
#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
cmpb $ M_LZMA,methb; jne not_lzma
// C calling convention
pushq %rbp; movq %rsp,%rbp
pushq %rbx
pushq %rbp; movq %rsp,%rbp // we use alloca
//LzmaDecode( // from lzmaSDK/C/7zip/Compress/LZMA_C/LzmaDecode.h
// %arg1= &CLzmaDecoderState,
// %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_LIT_SIZE 768
#define szSizeT 8
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
#define szSizeT 4
movq $-LZMA_LIT_SIZE,%rbx
shlq %cl,%rbx
// inSizeProcessed, outSizeProcessed, *_bits, CLzmaDecoderState
shlq %cl,%rbx; movb %al,%cl // %cl= pos_bits
// alloca{inSizeProcessed, outSizeProcessed, *_bits, CLzmaDecoderState}
leaq -(2*szSizeT +4) - 2*LZMA_BASE_SIZE(%rsp,%rbx,2), %rbx
andq $~0<<6,%rbx // 64-byte align
1:
pushq $0
pushq $0 // clera CLzmaDecoderState on stack
cmpq %rbx,%rsp
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
lodsb; decl %arg3l // second byte, replaces LzmaDecodeProperties()
movb %al,%cl // cl= (lit_pos_bits<<4) | lit_context_bits
andb $0xf,%al; movb %al, (%rbx) // store lit_context_bits
shrb $4, %cl; movb %cl,1(%rbx) // store lit_pos_bits
pushq %rbx // &outSizeProcessed [arg7]
leaq 2*szSizeT(%rbx),%arg1 // &CLzmaDecoderState
movb -1(%arg2),%cl; decl %arg3l // second byte, replaces LzmaDecodeProperties()
movb %al,2(%arg1) // store 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)
section LZMA_DEC10
@ -94,25 +97,12 @@ section LZMA_DEC10
section LZMA_DEC20
#include "lzma_d_cf.S"
//
// cleanup
section LZMA_DEC30
movl -1*szSizeT(%rbx),%eax; addq %rax,%rsi // inSizeProcessed
movl -2*szSizeT(%rbx),%eax; addq %rax,%rdi // outSizeProcessed
xorq %rax,%rax
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
movq -1*8(%rbp),%rsi // src [after header]
movq 2*8(%rbp),%rdi // dst
movl szSizeT(%rbx),%ecx; addq %rcx,%rsi // inSizeProcessed
movl (%rbx),%edx; addq %rdx,%rdi // outSizeProcessed
leave // movl %ebp,%rsp; popq %rbp
not_lzma:
// vi:ts=8:et