From ee37b42a913ea9de980ed73269fda3bd13d0d617 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 17 Nov 2010 20:21:41 -0800 Subject: [PATCH] DEBUG for MIPS i386-linux.elf-main.c --- src/stub/src/i386-linux.elf-main.c | 38 +++++++++++++--------- src/stub/src/include/linux.h | 4 +-- src/stub/src/mipsel.r3000-linux.elf-fold.S | 3 ++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/stub/src/i386-linux.elf-main.c b/src/stub/src/i386-linux.elf-main.c index 5828c76d..a435e76b 100644 --- a/src/stub/src/i386-linux.elf-main.c +++ b/src/stub/src/i386-linux.elf-main.c @@ -29,6 +29,9 @@ */ +#ifndef DEBUG /*{*/ +#define DEBUG 0 +#endif /*}*/ #include "include/linux.h" void *mmap(void *, size_t, int, int, int, off_t); @@ -43,11 +46,7 @@ ssize_t write(int, void const *, size_t); // it at an address different from it load address: there must be no // static data, and no string constants. -#ifndef DEBUG /*{*/ -#define DEBUG 0 -#endif /*}*/ - -#if !DEBUG || defined(__mips__) /*{*/ +#if !DEBUG /*{*/ #define DPRINTF(a) /* empty: no debug drivel */ #define DEBUG_STRCON(name, value) /* empty */ #else /*}{ DEBUG */ @@ -62,30 +61,35 @@ ssize_t write(int, void const *, size_t); #if defined(__i386__) /*{*/ #define PIC_STRING(value, var) \ + char const *var; \ __asm__ __volatile__ ( \ "call 0f; .asciz \"" value "\"; \ 0: pop %0;" : "=a"(var) : \ - ) + ); \ + return var; #elif defined(__arm__) /*}{*/ +#define PIC_STRING(value, var) \ + char const *var; \ __asm__ __volatile__ ( \ "mov r0,pc; ret; \ .asciz \"" value "\"; .balign 4" : "=a"(var) : \ - ) + ); \ + return var; #elif defined(__mips__) /*}{*/ +#define PIC_STRING(value, var) \ + register char const *rv asm("v0"); \ __asm__ __volatile__ ( \ - "mov at,ra; bal 0f; move v0,ra; \ + ".set noreorder; bal 0f; move %0,$31; .set reorder; \ .asciz \"" value "\"; .balign 4; \ - 0: jr at; nop" : "=a"(var) : \ - ) + 0: " \ + : "+r"(rv) \ + ); \ + return var; #endif /*}*/ #define DEBUG_STRCON(name, value) \ - static char const *name(void) \ - { \ - char *rv; PIC_STRING(value, rv); \ - return rv; \ - } + static char const *name(void) { PIC_STRING(value, rv); } #ifdef __arm__ /*{*/ @@ -702,6 +706,10 @@ void *upx_main( xi.buf = CONST_CAST(char *, bi); xi.size = sz_compressed; xj.buf = CONST_CAST(char *, bi); xj.size = sz_compressed; + DPRINTF((STR_upx_main(), + av, sz_compressed, f_decompress, f_unf, &xo, xo.size, xo.buf, + &xi, xi.size, xi.buf, dynbase)); + // ehdr = Uncompress Ehdr and Phdrs unpackExtent(&xj, &xo, f_decompress, 0); // never filtered? #else /*}{ !__mips__ */ diff --git a/src/stub/src/include/linux.h b/src/stub/src/include/linux.h index e524c2eb..b844f4e0 100644 --- a/src/stub/src/include/linux.h +++ b/src/stub/src/include/linux.h @@ -511,7 +511,7 @@ static ssize_t open(char const *path, int kind, int mode) return v0; } -#if 0 /*{ UNUSED */ +#if DEBUG /*{*/ static ssize_t write(int fd, void const *buf, size_t len) { #define __NR_write (4+ 4000) @@ -520,7 +520,7 @@ static ssize_t write(int fd, void const *buf, size_t len) register size_t const a2 asm("a2") = len; register size_t v0 asm("v0") = __NR_write; __asm__ __volatile__( - "bal sysgo" + "b sysgo" : "+r"(v0) : "r"(a0), "r"(a1), "r"(a2) : "a3" diff --git a/src/stub/src/mipsel.r3000-linux.elf-fold.S b/src/stub/src/mipsel.r3000-linux.elf-fold.S index 97d9db61..50223bc1 100644 --- a/src/stub/src/mipsel.r3000-linux.elf-fold.S +++ b/src/stub/src/mipsel.r3000-linux.elf-fold.S @@ -62,6 +62,7 @@ __NR_munmap = 91+ __NR_Linux __NR_open = 5+ __NR_Linux __NR_read = 3+ __NR_Linux __NR_readlink = 85+ __NR_Linux +__NR_write = 4+ __NR_Linux PATHSIZE=4096 OVERHEAD=2048 @@ -183,6 +184,8 @@ sysret: or v0,v0,tmp read: .globl read b sysgo; li v0,__NR_read +write: .globl write + b sysgo; li v0,__NR_write open: .globl open b sysgo; li v0,__NR_open close: .globl close