From f4aa80e6b440a1512b7d36d9654a818f4b425e6f Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 16 Jul 2002 17:06:14 +0000 Subject: [PATCH] Big re-sync with UPX 1.2 branch. committer: mfx 1026839174 +0000 --- src/p_tos.cpp | 160 +++++++++++++++------ src/p_tos.h | 17 ++- src/stub/.cvsignore | 4 + src/stub/Makefile | 72 ++++++---- src/stub/djstub.h | 184 +++++++++++++++++++++++++ src/stub/ident.ash | 11 +- src/stub/ident_n.ash | 14 +- src/stub/ident_s.ash | 13 +- src/stub/l_lx_exec.c | 8 +- src/stub/l_tos.s | 322 ++++++++++++++++++++++++++++++++----------- src/stub/linux.hh | 8 +- 11 files changed, 626 insertions(+), 187 deletions(-) create mode 100644 src/stub/djstub.h diff --git a/src/p_tos.cpp b/src/p_tos.cpp index a3ae6373..92579cb5 100644 --- a/src/p_tos.cpp +++ b/src/p_tos.cpp @@ -2,8 +2,8 @@ This file is part of the UPX executable compressor. - Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996-2001 Laszlo Molnar + Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2002 Laszlo Molnar All Rights Reserved. UPX and the UCL library are free software; you can redistribute them @@ -21,8 +21,8 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Markus F.X.J. Oberhumer Laszlo Molnar - markus@oberhumer.com ml1050@cdata.tvnet.hu + Markus F.X.J. Oberhumer Laszlo Molnar + */ @@ -41,6 +41,10 @@ static const #include "stub/l_t_n2d.h" static const #include "stub/l_t_n2ds.h" +static const +#include "stub/l_t_n2e.h" +static const +#include "stub/l_t_n2es.h" // #define TESTING @@ -62,11 +66,14 @@ const int *PackTos::getCompressionMethods(int method, int level) const { static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2D_8, -1 }; static const int m_nrv2d[] = { M_NRV2D_8, M_NRV2B_8, -1 }; + static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, -1 }; if (M_IS_NRV2B(method)) return m_nrv2b; if (M_IS_NRV2D(method)) return m_nrv2d; + if (M_IS_NRV2E(opt->method)) + return m_nrv2e; if (level == 1 || ih.fh_text + ih.fh_data <= 256*1024) return m_nrv2b; return m_nrv2d; @@ -85,6 +92,8 @@ const upx_byte *PackTos::getLoader() const return opt->small ? nrv2b_loader_small : nrv2b_loader; if (M_IS_NRV2D(ph.method)) return opt->small ? nrv2d_loader_small : nrv2d_loader; + if (M_IS_NRV2E(ph.method)) + return opt->small ? nrv2e_loader_small : nrv2e_loader; return NULL; } @@ -95,6 +104,8 @@ int PackTos::getLoaderSize() const return opt->small ? sizeof(nrv2b_loader_small) : sizeof(nrv2b_loader); if (M_IS_NRV2D(ph.method)) return opt->small ? sizeof(nrv2d_loader_small) : sizeof(nrv2d_loader); + if (M_IS_NRV2E(ph.method)) + return opt->small ? sizeof(nrv2e_loader_small) : sizeof(nrv2e_loader); return 0; } @@ -182,65 +193,118 @@ bool PackTos::checkFileHeader() } +/************************************************************************* +// some 68000 opcodes for patching +**************************************************************************/ + +enum m68k_reg_t { + REG_D0, REG_D1, REG_D2, REG_D3, REG_D4, REG_D5, REG_D6, REG_D7, + REG_A0, REG_A1, REG_A2, REG_A3, REG_A4, REG_A5, REG_A6, REG_A7 +}; + +static unsigned OP_DBRA(int d_reg) +{ + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + return 0x51c8 | (d_reg & 7); +} + +static unsigned OP_JMP(int a_reg) +{ + // jmp (a0) + assert(a_reg >= REG_A0 && a_reg <= REG_A7); + return 0x4ed0 | (a_reg & 7); +} + +static unsigned OP_MOVEI_L(int d_reg) +{ + // movei.l #XXXXXXXX,d0 + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + return 0x203c | ((d_reg & 7) << 9); +} + +static unsigned OP_MOVEQ(int value, int d_reg) +{ + // moveq.l #0,d0 + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + assert(value >= -128 && value <= 127); + return 0x7000 | ((d_reg & 7) << 9) | (value & 0xff); +} + +static unsigned OP_SUBQ_L(int value, int d_reg) +{ + assert(value >= 1 && value <= 8); + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + return 0x5180 | ((value & 7) << 9) | (d_reg & 7); +} + +static unsigned OP_SUBQ_W(int value, int d_reg) +{ + assert(value >= 1 && value <= 8); + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + return 0x5140 | ((value & 7) << 9) | (d_reg & 7); +} + + /************************************************************************* // **************************************************************************/ -unsigned PackTos::patch_d0_subq(void *b, int blen, unsigned d0, - const char *subq_marker) +unsigned PackTos::patch_d_subq(void *b, int blen, + int d_reg, unsigned d_value, + const char *subq_marker) { // patch a "subq.l #1,d0" or "subq.w #1,d0". // also convert into "dbra" if possible - assert((int)d0 > 0); + assert(d_reg >= REG_D0 && d_reg <= REG_D7); + assert((int)d_value > 0); - int boff = find_be16(b, blen, get_be16(subq_marker)); + int boff = find_be16(b, blen, get_be16(subq_marker)); if (boff < 0) throwBadLoader(); - unsigned char *p = (unsigned char *)b + boff; - if (p[2] == 0x66) // bne.b XXX + upx_byte *p = (upx_byte *)b + boff; + if (p[2] == 0x66) // bne.b XXX checkPatch(b, blen, boff, 4); else checkPatch(b, blen, boff, 2); - if (d0 > 65536) + if (d_value > 65536) { - set_be16(p, 0x5380); // subq.l #1,d0 + set_be16(p, OP_SUBQ_L(1, d_reg)); // subq.l #1,d0 } else { - if (p[2] == 0x66) // bne.b XXX + if (p[2] == 0x66) // bne.b XXX { - set_be16(p, 0x51c8); // dbra d0,XXX + set_be16(p, OP_DBRA(d_reg)); // dbra d0,XXX // adjust and extend branch from 8 to 16 bits int branch = (signed char) p[3]; set_be16(p+2, branch+2); // adjust d0 - d0 -= 1; + d_value -= 1; } else { - set_be16(p, 0x5340); // subq.w #1,d0 + set_be16(p, OP_SUBQ_W(1, d_reg)); // subq.w #1,d0 } - d0 &= 0xffff; + d_value &= 0xffff; } - return d0; + return d_value; } -unsigned PackTos::patch_d0_loop(void *b, int blen, unsigned d0, - const char *d0_marker, const char *subq_marker) +unsigned PackTos::patch_d_loop(void *b, int blen, + int d_reg, unsigned d_value, + const char *d_marker, const char *subq_marker) { - d0 = patch_d0_subq(b, blen, d0, subq_marker); + d_value = patch_d_subq(b, blen, d_reg, d_value, subq_marker); - int boff = find_be32(b, blen, get_be32(d0_marker)); + int boff = find_be32(b, blen, get_be32(d_marker)); checkPatch(b, blen, boff, 4); - - unsigned char *p = (unsigned char *)b + boff; - assert(get_be16(p - 2) == 0x203c); // move.l #XXXXXXXX,d0 - set_be32(p, d0); - - return d0; + upx_byte *p = (upx_byte *)b + boff; + assert(get_be16(p - 2) == OP_MOVEI_L(d_reg)); // move.l #XXXXXXXX,d0 + set_be32(p, d_value); + return d_value; } @@ -268,7 +332,7 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize, return -1; if (i >= rsize) // premature EOF in relocs return -1; - int c = relocs[i++]; + unsigned c = relocs[i++]; if (c == 0) // end marker break; else if (c == 1) // increase fixup, no reloc @@ -297,6 +361,18 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize, bool PackTos::canPack() { +#if 0 // debug +# define p(x) printf("%-30s 0x%04x\n", #x, x) + p(OP_DBRA(REG_D0)); + p(OP_MOVEI_L(REG_D0)); + p(OP_MOVEQ(-1, REG_D0)); + p(OP_MOVEQ(1, REG_D2)); + p(OP_MOVEQ(1, REG_D3)); + p(OP_SUBQ_W(1, REG_D0)); + p(OP_SUBQ_L(1, REG_D0)); +# undef p +#endif + if (!readFileHeader()) return false; @@ -365,7 +441,7 @@ void PackTos::pack(OutputFile *fo) printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1); #endif - // Check relocs (see load_and_reloc() in mint/src/mem.c). + // Check relocs (see load_and_reloc() in freemint/sys/memory.c). // Must work around TOS bugs and lots of broken programs. int r = 0; if (overlay < 4) @@ -462,8 +538,8 @@ void PackTos::pack(OutputFile *fo) while (dirty_bss & (dirty_bss_align - 1)) dirty_bss++; // adjust bss, assert room for some stack - if (dirty_bss + 256 > o_bss) - o_bss = dirty_bss + 256; + if (dirty_bss + 512 > o_bss) + o_bss = dirty_bss + 512; // dword align the len of the final bss segment while (o_bss & 3) @@ -477,12 +553,12 @@ void PackTos::pack(OutputFile *fo) patchPackHeader(loader,o_text); if (!opt->small) patchVersion(loader,o_text); - // patch "subq.l #1,d0" or "subq.w #1,d0" - see "up41" below - const unsigned dirty_bss_d0 = - patch_d0_subq(loader, o_text, dirty_bss / dirty_bss_align, "u4"); - patch_be32(loader,o_text,"up31",d_off + offset + decomp_offset); + // patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below + const unsigned dirty_bss_d6 = + patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4"); + patch_be32(loader, o_text, "up31", d_off + offset + decomp_offset); if (opt->small) - patch_d0_loop(loader,o_text,o_data/4,"up22","u1"); + patch_d_loop(loader, o_text, REG_D0, o_data/4, "up22", "u1"); else { if (o_data <= 160) @@ -494,8 +570,8 @@ void PackTos::pack(OutputFile *fo) loop1--; loop2 = 160; } - patch_be16(loader,o_text,"u2", 0x7000 + loop2/4-1); // moveq.l #X,d0 - patch_d0_loop(loader,o_text,loop1,"up22","u1"); + patch_be16(loader, o_text, "u2", OP_MOVEQ(loop2/4-1, REG_D0)); // moveq.l #X,d0 + patch_d_loop(loader, o_text, REG_D0, loop1, "up22", "u1"); } patch_be32(loader,o_text,"up21",o_data + offset); patch_be32(loader,o_text,"up13",i_bss); // p_blen @@ -504,9 +580,9 @@ void PackTos::pack(OutputFile *fo) // patch decompressor upx_byte *p = obuf + d_off; - // patch "moveq.l #1,d3" or "jmp (a5)" - patch_be16(p,d_len,"u3", (nrelocs > 0) ? 0x7601 : 0x4ed5); - patch_be32(p,d_len,"up41", dirty_bss_d0); + // patch "moveq.l #1,d5" or "jmp (ASTACK)" + patch_be16(p, d_len, "u3", (nrelocs > 0) ? OP_MOVEQ(1, REG_D5) : OP_JMP(REG_A7)); + patch_be32(p, d_len, "up41", dirty_bss_d6); // set new file_hdr memcpy(&oh, &ih, FH_SIZE); diff --git a/src/p_tos.h b/src/p_tos.h index 878f3d44..00cf514a 100644 --- a/src/p_tos.h +++ b/src/p_tos.h @@ -2,8 +2,8 @@ This file is part of the UPX executable compressor. - Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996-2001 Laszlo Molnar + Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2002 Laszlo Molnar All Rights Reserved. UPX and the UCL library are free software; you can redistribute them @@ -21,8 +21,8 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Markus F.X.J. Oberhumer Laszlo Molnar - markus@oberhumer.com ml1050@cdata.tvnet.hu + Markus F.X.J. Oberhumer Laszlo Molnar + */ @@ -70,11 +70,14 @@ protected: BE32 fh_reserved; BE32 fh_flag; BE16 fh_reloc; - } ih, oh; + } + __attribute_packed; + + tos_header_t ih, oh; protected: - unsigned patch_d0_subq(void *b, int blen, unsigned, const char*); - unsigned patch_d0_loop(void *b, int blen, unsigned, const char*, const char*); + unsigned patch_d_subq(void *l, int llen, int, unsigned, const char*); + unsigned patch_d_loop(void *l, int llen, int, unsigned, const char*, const char*); }; diff --git a/src/stub/.cvsignore b/src/stub/.cvsignore index 1b42925f..e90af4b7 100644 --- a/src/stub/.cvsignore +++ b/src/stub/.cvsignore @@ -5,6 +5,7 @@ *.lst *.map *.o +GNUmakefile fold_elf86.h fold_exec86.h fold_sh86.h @@ -14,11 +15,14 @@ l_exe.h l_lx_elf86.h l_lx_exec86.h l_lx_sh86.h +l_psx.h l_sys.h l_t_n2b.h l_t_n2bs.h l_t_n2d.h l_t_n2ds.h +l_t_n2e.h +l_t_n2es.h l_tmt.h l_vmlinz.h l_w32pe.h diff --git a/src/stub/Makefile b/src/stub/Makefile index 6d04d68d..8b5ea0bd 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -1,13 +1,13 @@ # # UPX stub Makefile (GNU make) # -# see http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/ +# see http://upx.sourceforge.net/download/tools/ # for required support tools # ifeq ($(strip $(UCLDIR)),) # change this to reflect where the UCL library is -UCLDIR = $(HOME)/local/src/ucl-0.92 +UCLDIR = $(HOME)/local/src/ucl-1.01 endif @@ -28,7 +28,7 @@ STUBS = \ l_exe.h \ l_psx.h \ l_sys.h \ - l_t_n2b.h l_t_n2bs.h l_t_n2d.h l_t_n2ds.h \ + l_t_n2b.h l_t_n2bs.h l_t_n2d.h l_t_n2ds.h l_t_n2e.h l_t_n2es.h \ l_tmt.h \ l_wcle.h \ l_w32pe.h \ @@ -96,15 +96,15 @@ CC_LINUX = gcc -Os -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0 ifeq (1,1) # Preprocessor for the a68k 68000-assembler. -CPP_68K = gcc -I$(UCL_UPX) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional -D__A68K__ -##CPP_68K = cpp -I$(UCL_UPX) -x assembler-with-cpp -P -C -traditional -nostdinc -D__A68K__ -APP_68K = perl -w $(srcdir)/scripts/app_68k.pl -ASM_68K = a68k -q -x +CPP_M68K = gcc -I$(UCL_UPX) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional -D__A68K__ +##CPP_M68K = cpp -I$(UCL_UPX) -x assembler-with-cpp -P -C -traditional -nostdinc -D__A68K__ +APP_M68K = perl -w $(srcdir)/scripts/app_68k.pl +ASM_M68K = a68k -q -x else # Preprocessor for the asl 68000-assembler. -CPP_68K = gcc -I$(UCL_UPX) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional -D__ASL__ -APP_68K = perl -w $(srcdir)/scripts/app_68k.pl -ASM_68K = sh $(srcdir)/scripts/asl_68k.sh +CPP_M68K = gcc -I$(UCL_UPX) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional -D__ASL__ +APP_M68K = perl -w $(srcdir)/scripts/app_68k.pl +ASM_M68K = sh $(srcdir)/scripts/asl_68k.sh endif # MIPS R3000 @@ -206,55 +206,67 @@ l_w32pe.h: l_w32pe.asx # ************************************************************************/ l_t_n2b.h: l_tos.s - $(CPP_68K) -DNRV2B -o $T.i $< - $(ASM_68K) $T.i + $(CPP_M68K) -DNRV2B -o $T.i $< + $(ASM_M68K) $T.i $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2b_loader $@ l_t_n2bs.h: l_tos.s - $(CPP_68K) -DNRV2B -DSMALL -o $T.i $< - $(ASM_68K) $T.i + $(CPP_M68K) -DNRV2B -DSMALL -o $T.i $< + $(ASM_M68K) $T.i $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2b_loader_small $@ l_t_n2d.h: l_tos.s - $(CPP_68K) -DNRV2D -o $T.i $< - $(ASM_68K) $T.i + $(CPP_M68K) -DNRV2D -o $T.i $< + $(ASM_M68K) $T.i $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2d_loader $@ l_t_n2ds.h: l_tos.s - $(CPP_68K) -DNRV2D -DSMALL -o $T.i $< - $(ASM_68K) $T.i + $(CPP_M68K) -DNRV2D -DSMALL -o $T.i $< + $(ASM_M68K) $T.i $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2d_loader_small $@ +l_t_n2e.h: l_tos.s + $(CPP_M68K) -DNRV2E -o $T.i $< + $(ASM_M68K) $T.i + $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' + $(BIN2H) $T.bin nrv2e_loader $@ + +l_t_n2es.h: l_tos.s + $(CPP_M68K) -DNRV2E -DSMALL -o $T.i $< + $(ASM_M68K) $T.i + $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' + $(BIN2H) $T.bin nrv2e_loader_small $@ + # experimental: l_t_x2b.h: l_tos2.s - $(CPP_68K) -DNRV2B -o $T.i $< - $(APP_68K) $T.i $T.asx - $(ASM_68K) $T.asx + $(CPP_M68K) -DNRV2B -o $T.i $< + $(APP_M68K) $T.i $T.asx + $(ASM_M68K) $T.asx $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2b_loader $@ l_t_x2bs.h: l_tos2.s - $(CPP_68K) -DNRV2B -DSMALL -o $T.i $< - $(APP_68K) $T.i $T.asx - $(ASM_68K) $T.asx + $(CPP_M68K) -DNRV2B -DSMALL -o $T.i $< + $(APP_M68K) $T.i $T.asx + $(ASM_M68K) $T.asx $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2b_loader_small $@ l_t_x2d.h: l_tos2.s - $(CPP_68K) -DNRV2D -o $T.i $< - $(APP_68K) $T.i $T.asx - $(ASM_68K) $T.asx + $(CPP_M68K) -DNRV2D -o $T.i $< + $(APP_M68K) $T.i $T.asx + $(ASM_M68K) $T.asx $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2d_loader $@ l_t_x2ds.h: l_tos2.s - $(CPP_68K) -DNRV2D -DSMALL -o $T.i $< - $(APP_68K) $T.i $T.asx - $(ASM_68K) $T.asx + $(CPP_M68K) -DNRV2D -DSMALL -o $T.i $< + $(APP_M68K) $T.i $T.asx + $(ASM_M68K) $T.asx $(O2BIN) $T.o $T.bin 'UPX1' 'UPX9' $(BIN2H) $T.bin nrv2d_loader_small $@ diff --git a/src/stub/djstub.h b/src/stub/djstub.h new file mode 100644 index 00000000..347e4433 --- /dev/null +++ b/src/stub/djstub.h @@ -0,0 +1,184 @@ +/* +; Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details +; Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details +; Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details +; Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details +; -*- asm -*- +; +; KLUDGE-WARNING! +; +; So you say you want to change this file, right? Are you really sure +; that's a good idea? Let me tell you a bit about the pitfalls here: +; +; * Some code runs in protected mode, some in real-mode, some in both. +; * Some code must run on a 8088 without crashing it. +; * Registers and flags may be expected to survive for a long time. +; * The code is optimized for size, not for speed or readability. +; * Some comments are parsed by other programs. +; +; You still want to change it? Oh well, go ahead, but don't come +; crying back saying you weren't warned. +; +;----------------------------------------------------------------------------- +; djgpp extender-less stub loader +; +; (C) Copyright 1993-1995 DJ Delorie +; +; Redistribution and use in source and binary forms are permitted +; provided that: (1) source distributions retain this entire copyright +; notice and comment, (2) distributions including binaries display +; the following acknowledgement: ``This product includes software +; developed by DJ Delorie and contributors to the djgpp project'' +; in the documentation or other materials provided with the distribution +; and in all advertising materials mentioning features or use of this +; software, and (3) binary distributions include information sufficient +; for the binary user to obtain the sources for the binary and utilities +; required to built and use it. Neither the name of DJ Delorie nor the +; names of djgpp's contributors may be used to endorse or promote +; products derived from this software without specific prior written +; permission. +; +; THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +; IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +; +; Revision history: +; +; 93/12/05 DJ Delorie Initial version v2.00, requires DPMI 0.9 +; 94/10/13 CW Sandmann v2.01, accumlated changes: 60K load bug, limits, cwsdpmi, optimization +; 94/10/29 CW Sandmann v2.03, M Welinder changes; cwsdpmi load anywhere, size decrease +; +*/ + +#define STUBIFY_STUB_ADLER32 0x57f49e02 + +unsigned char stubify_stub[2048] = { + 77, 90, 0, 0, 4, 0, 0, 0, 32, 0, 39, 0,255,255, 0, 0, /* 0x 0 */ + 96, 7, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 13, 10,115,116, /* 0x 10 */ +117, 98, 46,104, 32,103,101,110,101,114, 97,116,101,100, 32,102, /* 0x 20 */ +114,111,109, 32,115,116,117, 98, 46, 97,115,109, 32, 98,121, 32, /* 0x 30 */ +100,106, 97,115,109, 44, 32,111,110, 32, 84,104,117, 32, 68,101, /* 0x 40 */ + 99, 32, 32, 57, 32, 49, 48, 58, 53, 57, 58, 51, 49, 32, 49, 57, /* 0x 50 */ + 57, 57, 13, 10, 84,104,101, 32, 83, 84, 85, 66, 46, 69, 88, 69, /* 0x 60 */ + 32,115,116,117, 98, 32,108,111, 97,100,101,114, 32,105,115, 32, /* 0x 70 */ + 67,111,112,121,114,105,103,104,116, 32, 40, 67, 41, 32, 49, 57, /* 0x 80 */ + 57, 51, 45, 49, 57, 57, 53, 32, 68, 74, 32, 68,101,108,111,114, /* 0x 90 */ +105,101, 46, 32, 13, 10, 80,101,114,109,105,115,115,105,111,110, /* 0x a0 */ + 32,103,114, 97,110,116,101,100, 32,116,111, 32,117,115,101, 32, /* 0x b0 */ +102,111,114, 32, 97,110,121, 32,112,117,114,112,111,115,101, 32, /* 0x c0 */ +112,114,111,118,105,100,101,100, 32,116,104,105,115, 32, 99,111, /* 0x d0 */ +112,121,114,105,103,104,116, 32, 13, 10,114,101,109, 97,105,110, /* 0x e0 */ +115, 32,112,114,101,115,101,110,116, 32, 97,110,100, 32,117,110, /* 0x f0 */ +109,111,100,105,102,105,101,100, 46, 32, 13, 10, 84,104,105,115, /* 0x 100 */ + 32,111,110,108,121, 32, 97,112,112,108,105,101,115, 32,116,111, /* 0x 110 */ + 32,116,104,101, 32,115,116,117, 98, 44, 32, 97,110,100, 32,110, /* 0x 120 */ +111,116, 32,110,101, 99,101,115,115, 97,114,105,108,121, 32,116, /* 0x 130 */ +104,101, 32,119,104,111,108,101, 32,112,114,111,103,114, 97,109, /* 0x 140 */ + 46, 10, 13, 10, 36, 73,100, 58, 32,115,116,117, 98, 46, 97,115, /* 0x 150 */ +109, 32, 98,117,105,108,116, 32, 49, 50, 47, 48, 57, 47, 57, 57, /* 0x 160 */ + 32, 49, 48, 58, 53, 57, 58, 51, 49, 32, 98,121, 32,100,106, 97, /* 0x 170 */ +115,109, 32, 36, 10, 13, 10, 64, 40, 35, 41, 32,115,116,117, 98, /* 0x 180 */ + 46, 97,115,109, 32, 98,117,105,108,116, 32, 49, 50, 47, 48, 57, /* 0x 190 */ + 47, 57, 57, 32, 49, 48, 58, 53, 57, 58, 51, 49, 32, 98,121, 32, /* 0x 1a0 */ +100,106, 97,115,109, 10, 13, 10, 26, 0, 0, 0, 0, 0, 0, 0, /* 0x 1b0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 1c0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 1d0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 1e0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 1f0 */ +103,111, 51, 50,115,116,117, 98, 44, 32,118, 32, 50, 46, 48, 50, /* 0x 200 */ + 84, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 210 */ + 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 220 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 230 */ + 0, 0, 0, 0, 67, 87, 83, 68, 80, 77, 73, 46, 69, 88, 69, 0, /* 0x 240 */ + 0, 0, 0, 0, 14, 31,140, 30, 36, 0,140, 6, 96, 7,252,180, /* 0x 250 */ + 48,205, 33, 60, 3,115, 8,176,109,186,167, 5,233,212, 3,162, /* 0x 260 */ +105, 8,190, 32, 0,139, 4, 9,192,117, 2,180,254,187,112, 8, /* 0x 270 */ + 57,195,115, 2,137,195,137, 28,254,199,185, 4,255,211,235,180, /* 0x 280 */ + 74,205, 33,115, 8,211,227,254,207,137, 28,235,216, 38,142, 6, /* 0x 290 */ + 44, 0, 49,255, 48,192,169,242,174, 38,129, 61, 80, 65,117, 21, /* 0x 2a0 */ +175, 38,129, 61, 84, 72,117, 13,175, 38,128, 61, 61,117, 6, 71, /* 0x 2b0 */ +137, 62,140, 4, 79,174,117,223,175,180, 62,187, 19, 0,205, 33, /* 0x 2c0 */ +180, 62,187, 18, 0,205, 33, 6, 87, 49,201,116, 18,176,110,186, /* 0x 2d0 */ +126, 5,233, 94, 3, 9,201,117,244, 65,232,161, 3,114,238,184, /* 0x 2e0 */ +135, 22,205, 47, 9,192,117,237,128,227, 1,116,232,137, 62, 0, /* 0x 2f0 */ + 6,140, 6, 2, 6,137, 54, 4, 6, 95, 7,232,211, 2,137, 62, /* 0x 300 */ + 42, 0,137, 54, 98, 7,128, 62, 44, 0, 0,116, 35,185, 8, 0, /* 0x 310 */ +191, 44, 0,138, 5, 71, 8,192,116, 5,136, 7, 67,226,244,102, /* 0x 320 */ +199, 7, 46, 69, 88, 69,131,195, 4,198, 7, 0,137, 30, 98, 7, /* 0x 330 */ +184, 0, 61,186,100, 7,205, 33, 15,130,179, 2,163, 6, 6,137, /* 0x 340 */ +195,185, 6, 0,186,181, 7,180, 63,205, 33, 49,210, 49,201,161, /* 0x 350 */ +181, 7, 61, 76, 1,116, 27, 61, 77, 90, 15,133,152, 2,139, 22, /* 0x 360 */ +185, 7,193,226, 9,139, 30,183, 7, 9,219,116, 5,128,238, 2, /* 0x 370 */ + 1,218,137, 22,187, 7,137, 14,189, 7,184, 0, 66,139, 30, 6, /* 0x 380 */ + 6,205, 33,185,168, 0,186,191, 7,180, 63,205, 33, 61,168, 0, /* 0x 390 */ +117, 6,129, 62,191, 7, 76, 1, 15,133, 97, 2,102,161,227, 7, /* 0x 3a0 */ +102,163, 16, 6,102,139, 14,187, 7,102,161, 3, 8,102, 1,200, /* 0x 3b0 */ +102,163, 8, 6,102,161, 43, 8,102, 1,200,102,163, 12, 6,102, /* 0x 3c0 */ +139, 30, 75, 8,102,161, 79, 8,102, 1,195,102,184, 1, 0, 1, /* 0x 3d0 */ + 0,102, 57,195,115, 3,102,137,195,102,129,195,255,255, 0, 0, /* 0x 3e0 */ + 49,219,102,137, 30, 28, 0,232,245, 2,139, 30, 4, 6, 9,219, /* 0x 3f0 */ +116, 10,180, 72,205, 33, 15,130, 21, 2,142,192,232, 8, 3,184, /* 0x 400 */ + 1, 0,255, 30, 0, 6, 15,130, 15, 2,140, 6, 38, 0,140, 14, /* 0x 410 */ + 40, 0,140,216,163, 34, 0,142,192, 49,192,185, 1, 0,205, 49, /* 0x 420 */ +114, 7,163, 20, 6, 49,192,205, 49, 15,130,243, 1,163, 22, 6, /* 0x 430 */ +102,139, 14, 28, 0,184, 1, 5,139, 30, 30, 0,205, 49, 15,130, /* 0x 440 */ +229, 1,137, 30, 26, 6,137, 14, 24, 6,137, 54, 26, 0,137, 62, /* 0x 450 */ + 24, 0,184, 7, 0,139, 30, 20, 6,139, 14, 26, 6,139, 22, 24, /* 0x 460 */ + 6,205, 49,184, 9, 0,140,201,131,225, 3,193,225, 5, 81,129, /* 0x 470 */ +201,155,192,205, 49,184, 8, 0,139, 14, 30, 0, 73,186,255,255, /* 0x 480 */ +205, 49,184, 7, 0,139, 30, 22, 6,139, 14, 26, 6,139, 22, 24, /* 0x 490 */ + 6,205, 49,184, 9, 0, 89,129,201,147,192,205, 49,184, 8, 0, /* 0x 4a0 */ +139, 14, 30, 0, 73,186,255,255,205, 49,184, 0, 1,187, 0, 15, /* 0x 4b0 */ +205, 49,115, 16, 61, 8, 0, 15,133,115, 1,184, 0, 1,205, 49, /* 0x 4c0 */ + 15,130,106, 1,163, 28, 6,137, 22, 30, 6,193,227, 4,137, 30, /* 0x 4d0 */ + 32, 6,102,139, 54, 8, 6,102,139, 62,251, 7,102,139, 14,255, /* 0x 4e0 */ + 7,232, 73, 0,102,139, 54, 12, 6,102,139, 62, 35, 8,102,139, /* 0x 4f0 */ + 14, 39, 8,232, 55, 0,142, 6, 22, 6,102,139, 62, 75, 8,102, /* 0x 500 */ +139, 14, 79, 8,102, 49,192,102,193,233, 2,103,243,102,171,180, /* 0x 510 */ + 62,139, 30, 6, 6,205, 33,184, 1, 1,139, 22, 30, 6,205, 49, /* 0x 520 */ + 30, 15,161,142, 30, 22, 6,102,100,255, 46, 16, 6,102,137,240, /* 0x 530 */ +102, 37,255, 1, 0, 0,102, 1,193, 41,198,102, 41,199,102,137, /* 0x 540 */ + 14, 38, 6,102,137, 62, 34, 6,232, 15, 1,137, 54, 62, 6,102, /* 0x 550 */ +193,238, 16,137, 54, 66, 6,139, 30, 6, 6,137, 30, 58, 6,199, /* 0x 560 */ + 6, 70, 6, 0, 66,232, 3, 1,161, 28, 6,163, 78, 6,199, 6, /* 0x 570 */ + 62, 6, 0, 0,198, 6, 71, 6, 63,161, 40, 6, 9,192,117, 9, /* 0x 580 */ +161, 38, 6, 59, 6, 32, 6,118, 3,161, 32, 6,163, 66, 6,232, /* 0x 590 */ +217, 0,102, 49,201,139, 14, 70, 6,102,139, 62, 34, 6,102, 1, /* 0x 5a0 */ + 14, 34, 6,102, 41, 14, 38, 6,102, 49,246,193,233, 2, 30, 6, /* 0x 5b0 */ +142, 6, 22, 6,142, 30, 30, 6,103,243,102,165, 7, 31,102, 3, /* 0x 5c0 */ + 14, 38, 6,117,175,195, 60, 58,116, 6, 60, 47,116, 2, 60, 92, /* 0x 5d0 */ +195,190,100, 7,137,243, 38,138, 5, 71,136, 4, 56,224,116, 14, /* 0x 5e0 */ + 8,192,116, 10, 70,232,222,255,117,236,137,243,116,232,195,176, /* 0x 5f0 */ +102,186, 72, 5,235, 12,176,103,186, 85, 5,235, 5,176,104,186, /* 0x 600 */ + 95, 5, 82,139, 30, 98, 7,198, 7, 36,187,100, 7,235, 40,232, /* 0x 610 */ +245, 0,176,105,186,153, 5,235, 26,176,106,186,178, 5,235, 19, /* 0x 620 */ +176,107,186,196, 5,235, 12,176,108,186,214, 5,235, 5,176,105, /* 0x 630 */ +186,153, 5, 82,187, 59, 5,232, 21, 0, 91,232, 17, 0,187,103, /* 0x 640 */ + 4,232, 11, 0,180, 76,205, 33, 67, 80,180, 2,205, 33, 88,138, /* 0x 650 */ + 23,128,250, 36,117,242,195, 13, 10, 36, 80, 81, 87, 49,192,191, /* 0x 660 */ + 42, 6,185, 25, 0,243,171, 95, 89, 88,195,184, 0, 3,187, 33, /* 0x 670 */ + 0, 49,201,102,191, 42, 6, 0, 0,205, 49,195, 0, 0, 48,228, /* 0x 680 */ +232, 78,255,137,222,139, 62,140, 4,235, 23,180, 59,232, 65,255, /* 0x 690 */ +129,254,100, 7,116, 18,138, 68,255,232, 42,255,116, 4,198, 4, /* 0x 6a0 */ + 92, 70,232, 3, 0,114,228,195,232, 52, 0,187, 68, 0,138, 7, /* 0x 6b0 */ +136, 4, 67, 70, 8,192,117,246, 6, 87, 30, 7,232,155,255,187, /* 0x 6c0 */ + 42, 6,140, 95, 4,137, 95, 2,186,100, 7,184, 0, 75,205, 33, /* 0x 6d0 */ + 95, 7,114, 9,180, 77,205, 33, 45, 0, 3,247,216,235, 40,128, /* 0x 6e0 */ + 62,105, 8, 5,114, 32,184, 0, 88,205, 33,162,103, 8,184, 2, /* 0x 6f0 */ + 88,205, 33,162,104, 8,184, 1, 88,187,128, 0,205, 33,184, 3, /* 0x 700 */ + 88,187, 1, 0,205, 33,195,156,128, 62,105, 8, 5,114, 26, 80, /* 0x 710 */ + 83,184, 3, 88,138, 30,104, 8, 48,255,205, 33,184, 1, 88,138, /* 0x 720 */ + 30,103, 8, 48,255,205, 33, 91, 88,157,195, 76,111, 97,100, 32, /* 0x 730 */ +101,114,114,111,114, 58, 32, 36, 58, 32, 99, 97,110, 39,116, 32, /* 0x 740 */ +111,112,101,110, 36, 58, 32,110,111,116, 32, 69, 88, 69, 36, 58, /* 0x 750 */ + 32,110,111,116, 32, 67, 79, 70, 70, 32, 40, 67,104,101, 99,107, /* 0x 760 */ + 32,102,111,114, 32,118,105,114,117,115,101,115, 41, 36,110,111, /* 0x 770 */ + 32, 68, 80, 77, 73, 32, 45, 32, 71,101,116, 32, 99,115,100,112, /* 0x 780 */ +109,105, 42, 98, 46,122,105,112, 36,110,111, 32, 68, 79, 83, 32, /* 0x 790 */ +109,101,109,111,114,121, 36,110,101,101,100, 32, 68, 79, 83, 32, /* 0x 7a0 */ + 51, 36, 99, 97,110, 39,116, 32,115,119,105,116, 99,104, 32,109, /* 0x 7b0 */ +111,100,101, 36,110,111, 32, 68, 80, 77, 73, 32,115,101,108,101, /* 0x 7c0 */ + 99,116,111,114,115, 36,110,111, 32, 68, 80, 77, 73, 32,109,101, /* 0x 7d0 */ +109,111,114,121, 36,144,144,144,144,144,144,144,144,144,144,144, /* 0x 7e0 */ +144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144 /* 0x 7f0 */ +}; diff --git a/src/stub/ident.ash b/src/stub/ident.ash index 409f6ed3..2fc62530 100644 --- a/src/stub/ident.ash +++ b/src/stub/ident.ash @@ -2,8 +2,8 @@ ; ; This file is part of the UPX executable compressor. ; -; Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer -; Copyright (C) 1996-2001 Laszlo Molnar +; Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer +; Copyright (C) 1996-2002 Laszlo Molnar ; All Rights Reserved. ; ; UPX and the UCL library are free software; you can redistribute them @@ -21,8 +21,8 @@ ; If not, write to the Free Software Foundation, Inc., ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ; -; Markus F.X.J. Oberhumer Laszlo Molnar -; markus@oberhumer.com ml1050@cdata.tvnet.hu +; Markus F.X.J. Oberhumer Laszlo Molnar +; ; @@ -33,6 +33,3 @@ %else; __IDENTBIG__ %include "ident_n.ash" %endif; __IDENTEND__ - - -; vi:ts=8:et:nowrap diff --git a/src/stub/ident_n.ash b/src/stub/ident_n.ash index 18c8426d..5e3465c0 100644 --- a/src/stub/ident_n.ash +++ b/src/stub/ident_n.ash @@ -2,8 +2,8 @@ ; ; This file is part of the UPX executable compressor. ; -; Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer -; Copyright (C) 1996-2001 Laszlo Molnar +; Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer +; Copyright (C) 1996-2002 Laszlo Molnar ; All Rights Reserved. ; ; UPX and the UCL library are free software; you can redistribute them @@ -21,20 +21,18 @@ ; If not, write to the Free Software Foundation, Inc., ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ; -; Markus F.X.J. Oberhumer Laszlo Molnar -; markus@oberhumer.com ml1050@cdata.tvnet.hu +; Markus F.X.J. Oberhumer Laszlo Molnar +; ; ; ------------- COPYRIGHT ------------- db 10,0 - db '$Info: This file is packed with the UPX executable packer http://upx.tsx.org $' + db '$Info: This file is packed with the UPX executable packer http://upx.sf.net $' db 10,0 db '$Id: UPX ' db 'UPXV' - db ' Copyright (C) 1996-2001 the UPX Team. All Rights Reserved. $' + db ' Copyright (C) 1996-2002 the UPX Team. All Rights Reserved. $' db 10,0 - -; vi:ts=8:et:nowrap diff --git a/src/stub/ident_s.ash b/src/stub/ident_s.ash index cf6d852e..8d457536 100644 --- a/src/stub/ident_s.ash +++ b/src/stub/ident_s.ash @@ -2,8 +2,8 @@ ; ; This file is part of the UPX executable compressor. ; -; Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer -; Copyright (C) 1996-2001 Laszlo Molnar +; Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer +; Copyright (C) 1996-2002 Laszlo Molnar ; All Rights Reserved. ; ; UPX and the UCL library are free software; you can redistribute them @@ -21,17 +21,14 @@ ; If not, write to the Free Software Foundation, Inc., ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ; -; Markus F.X.J. Oberhumer Laszlo Molnar -; markus@oberhumer.com ml1050@cdata.tvnet.hu +; Markus F.X.J. Oberhumer Laszlo Molnar +; ; ; ------------- COPYRIGHT ------------- db 10 - db '$Id: UPX ' - db '(C) 1996-2001 the UPX Team. All Rights Reserved. http://upx.tsx.org $' + db '$Id: UPX (C) 1996-2002 the UPX Team. All Rights Reserved. http://upx.sf.net $' db 10,0 - -; vi:ts=8:et:nowrap diff --git a/src/stub/l_lx_exec.c b/src/stub/l_lx_exec.c index 8e118dae..527227ab 100644 --- a/src/stub/l_lx_exec.c +++ b/src/stub/l_lx_exec.c @@ -2,8 +2,8 @@ This file is part of the UPX executable compressor. - Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996-2001 Laszlo Molnar + Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2002 Laszlo Molnar All Rights Reserved. UPX and the UCL library are free software; you can redistribute them @@ -21,8 +21,8 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Markus F.X.J. Oberhumer Laszlo Molnar - markus@oberhumer.com ml1050@cdata.tvnet.hu + Markus F.X.J. Oberhumer Laszlo Molnar + */ diff --git a/src/stub/l_tos.s b/src/stub/l_tos.s index e51b3422..368598b9 100644 --- a/src/stub/l_tos.s +++ b/src/stub/l_tos.s @@ -2,8 +2,8 @@ ; ; This file is part of the UPX executable compressor. ; -; Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer -; Copyright (C) 1996-2001 Laszlo Molnar +; Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer +; Copyright (C) 1996-2002 Laszlo Molnar ; All Rights Reserved. ; ; UPX and the UCL library are free software; you can redistribute them @@ -21,19 +21,21 @@ ; If not, write to the Free Software Foundation, Inc., ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ; -; Markus F.X.J. Oberhumer Laszlo Molnar -; markus@oberhumer.com ml1050@cdata.tvnet.hu +; Markus F.X.J. Oberhumer Laszlo Molnar +; ; #define NRV_BB 8 +#include "../version.h" ; ; see also: -; mint/src/basepage.h -; mint/src/mem.h (FILEHEAD) -; mint/src/mem.c (load_region, load_and_reloc) +; freemint/sys/mint/basepage.h +; freemint/sys/mint/mem.h (FILEHEAD) +; freemint/sys/memory.c (load_region, load_and_reloc) +; freemint/sys/arch/cpu.S (cpush) ; ; @@ -80,19 +82,6 @@ p_parent equ $24 ; .l pointer to parent's basepage p_flags equ $28 ; .l memory usage flags p_env equ $2c ; .l pointer to environment string -#if 0 -; file header offsets (NOT USED) -fh_magic equ $0 ; .w $601a -fh_text equ $2 ; .l -fh_data equ $6 ; .l -fh_bss equ $a ; .l -fh_sym equ $e ; .l -fh_reserved equ $12 ; .l -fh_flag equ $16 ; .l -fh_reloc equ $1a ; .w -FH_SIZE equ $1c ; 28 bytes -#endif - ; ; long living registers: ; d4 p_tbase - start of text segment @@ -100,10 +89,115 @@ FH_SIZE equ $1c ; 28 bytes ; - end of decompressed text+data ; - start of decompressed relocations ; - start of dirty bss -; a5 final startup code copied below stack +; ASTACK (a7) - final startup code copied below stack ; +; /************************************************************************* +; // flush cache macros +; **************************************************************************/ + +; note: +; GEMDOS/XBIOS trashes d0, d1, d2, a0, a1, a2 + + +; Ssystem(S_FLUSHCACHE, base, length) - inside the kernel this +; is called `cpush(base, length)'. +; returns: d0.l should be either 0 or -32 (== ENOSYS == EINVFN) +; Available since FreeMiNT 1.15.1 (1999-04-13). +; +; Note that on a 68060 FreeMiNT just uses `cpusha bc' in all cases, +; so we don't bother passing base and length. (info: base would be d4) + +macro(MINT_FLUSH_CACHE) + pea -1 ; length + clr.l -(sp) ; base +#if 0 + move.w #$0016,-(sp) ; S_FLUSHCACHE (22) + move.w #$0154,-(sp) ; Ssystem (340) +#else + move.l #$01540016,-(sp) +#endif + trap #1 ; GEMDOS + lea 12(sp),sp + endm + + +; First try `cpusha bc' (68040/68060). If that fails try temporary changing +; the cache control register (68030). + +macro(SUPEXEC_FLUSH_CACHE) + pea \@super(pc) + move.w #38,-(sp) ; Supexec + trap #14 ; XBIOS + addq.l #6,sp + bra \@done + + +; exception handler +\@exception: move.l a1,sp ; restore stack (SSP) + jmp (a0) ; and continue + + +\@super: move.l ($10),-(sp) + move.l ($2c),-(sp) + move.l ($f4),-(sp) + move.l sp,a1 ; save stack pointer (SSP) + + ; set exception vectors + lea \@exception(pc),a0 + move.l a0,($10) + move.l a0,($2c) + move.l a0,($f4) + nop ; flush write pipeline + + ; try 68040 / 68060 + lea \@1(pc),a0 + dc.w $f4f8 ; cpusha bc + bra \@ret +\@1: + ; try 68030 + lea \@2(pc),a0 + dc.l $4e7a0002 ; movec.l cacr,d0 + move.l d0,d1 + or.w #$0808,d1 + dc.l $4e7b1002 ; movec.l d1,cacr + dc.l $4e7b0002 ; movec.l d0,cacr +;;; bra \@ret +\@2: + +\@ret: move.l (sp)+,($f4) + move.l (sp)+,($2c) + move.l (sp)+,($10) + nop ; flush write pipeline + rts + +\@done: + endm + + + +macro(BOTH_FLUSH_CACHE) + MINT_FLUSH_CACHE + tst.w d0 + beq \@done + SUPEXEC_FLUSH_CACHE +\@done: + endm + + + +#define ASTACK a7 + +#if 1 +# define FLUSH_CACHE BOTH_FLUSH_CACHE +#elif 0 +# define FLUSH_CACHE MINT_FLUSH_CACHE +#else +# undef FLUSH_CACHE +#endif + + ; /************************************************************************* ; // entry - the text segment of a compressed executable ; // @@ -130,7 +224,7 @@ L(start): movem.l d1-d7/a0-a6,-(sp) ; ------------- restore original basepage - ; we also setup d4, a6 and a1 here + ; we also setup d4 and a6 here, and we prepare a4 move.l d0,a2 ; a2 = basepage addq.l #p_tbase,a2 @@ -141,24 +235,24 @@ L(start): movem.l d1-d7/a0-a6,-(sp) move.l a6,(a2)+ ; p_dbase move.l #'up12',(a2) ; p_dlen add.l (a2)+,a6 ; a6 = decompressed p_bbase - move.l (a2),a1 ; a1 = compressed p_bbase + move.l (a2),a4 ; a4 = compressed p_bbase move.l a6,(a2)+ ; p_bbase move.l #'up13',(a2) ; p_blen -; ------------- copy data segment (from a1 to a0, downwards) +; ------------- copy data segment (from a4 to a3, downwards) - ; a1 (top of compressed data) already initialized above + ; a4 (top of compressed data) already initialized above - move.l d4,a0 - add.l #'up21',a0 ; top of data segment + offset + move.l d4,a3 + add.l #'up21',a3 ; top of data segment + offset #if defined(SMALL) move.l #'up22',d0 ; (len / 4) ; copy 4 bytes per loop -L(loop): move.l -(a1),-(a0) +L(loop): move.l -(a4),-(a3) ;;subq.l #1,d0 dc.b 'u1' ; subq.l #1,d0 / subq.w #1,d0 bne L(loop) @@ -169,15 +263,15 @@ L(loop): move.l -(a1),-(a0) ; loop1 - use 10 registers to copy 4*10*4 = 160 bytes per loop L(loop1): - lea.l -160(a1),a1 - movem.l 120(a1),d1-d3/d5-d7/a2-a5 - movem.l d1-d3/d5-d7/a2-a5,-(a0) - movem.l 80(a1),d1-d3/d5-d7/a2-a5 - movem.l d1-d3/d5-d7/a2-a5,-(a0) - movem.l 40(a1),d1-d3/d5-d7/a2-a5 - movem.l d1-d3/d5-d7/a2-a5,-(a0) - movem.l (a1),d1-d3/d5-d7/a2-a5 - movem.l d1-d3/d5-d7/a2-a5,-(a0) + lea.l -160(a4),a4 + movem.l 120(a4),d1-d3/d5-d7/a0-a2/a5 + movem.l d1-d3/d5-d7/a0-a2/a5,-(a3) + movem.l 80(a4),d1-d3/d5-d7/a0-a2/a5 + movem.l d1-d3/d5-d7/a0-a2/a5,-(a3) + movem.l 40(a4),d1-d3/d5-d7/a0-a2/a5 + movem.l d1-d3/d5-d7/a0-a2/a5,-(a3) + movem.l (a4),d1-d3/d5-d7/a0-a2/a5 + movem.l d1-d3/d5-d7/a0-a2/a5,-(a3) ;;subq.l #1,d0 dc.b 'u1' ; subq.l #1,d0 / subq.w #1,d0 bne L(loop1) @@ -186,45 +280,63 @@ L(loop1): ;;moveq.l #xx,d0 ; ((len % 160) / 4) - 1 dc.b 'u2' ; moveq.l #xx,d0 -L(loop2): move.l -(a1),-(a0) +L(loop2): move.l -(a4),-(a3) dbra d0,L(loop2) #endif - ; a0 now points to the start of the compressed block + ; a3 now points to the start of the compressed block -; ------------- copy code to stack and setup a5 +; ------------- copy code to stack and setup ASTACK ; Copy the final startup code below the stack. This will get -; called via "jmp (a5)" after decompression and relocation. +; called via "jmp (ASTACK)" after decompression and relocation. copy_to_stack: - lea.l clear_bss_end(pc),a2 - move.l sp,a5 - moveq.l #((clear_bss_end-clear_bss)/2-1),d5 - move.l d4,-(a5) ; entry point for final jmp -L(loop): move.w -(a2),-(a5) + lea.l clear_bss_end(pc),a2 + move.l d4,-(ASTACK) ; entry point for final jmp + + moveq.l #((clear_bss_end-clear_bss)/2-1),d5 +L(loop): move.w -(a2),-(ASTACK) subq.l #1,d5 bcc L(loop) +#ifdef FLUSH_CACHE + ; patch code: on the stack, the `rts' becomes a `nop' + move.w #$4e71,flush_cache_rts-clear_bss(ASTACK) +#endif + ; note: d5.l is now -1 (needed for decompressor) +; ------------- + +#ifdef FLUSH_CACHE + bsr flush_cache +#endif + + ; ------------- prepare decompressor - ; a0 still points to the start of the compressed block - move.l d4,a1 ; dest. for decompressing + ; a3 still points to the start of the compressed block + move.l d4,a4 ; dest. for decompressing #define NRV_NO_INIT + ;;moveq.l #-1,d5 ; last_off = -1 - moveq.l #-1,d7 moveq.l #-128,d0 ; d0.b = $80 #if defined(NRV2B) + moveq.l #-1,d7 moveq.l #-$68,d6 ; 0xffffff98 lsl.w #5,d6 ; 0xfffff300 == -0xd00 #elif defined(NRV2D) + moveq.l #-1,d7 + moveq.l #-$50,d6 ; 0xffffffb0 + lsl.w #4,d6 ; 0xfffffb00 == -0x500 +#elif defined(NRV2E) + moveq.l #0,d7 moveq.l #-$50,d6 ; 0xffffffb0 lsl.w #4,d6 ; 0xfffffb00 == -0x500 #endif @@ -245,26 +357,73 @@ L(loop): move.w -(a2),-(a5) clear_bss: - ; on entry d2 is 0 + ; on entry: + ; ASTACK == pc == clear_bss (on stack) + ; a6 start of dirty bss [long living register] + ; d6.l number of clr loops + ; d3.l 0 + #if defined(SMALL) -L(loop): move.l d2,(a6)+ - ;;subq.l #1,d0 - dc.b 'u4' ; subq.l #1,d0 / subq.w #1,d0 +L(loop): move.l d3,(a6)+ + ;;subq.l #1,d6 + dc.b 'u4' ; subq.l #1,d6 / subq.w #1,d6 bne L(loop) #else ; the dirty bss is usually not too large, so we don't ; bother making movem optimizations here -L(loop): move.l d2,(a6)+ - move.l d2,(a6)+ - move.l d2,(a6)+ - move.l d2,(a6)+ - ;;subq.l #1,d0 - dc.b 'u4' ; subq.l #1,d0 / subq.w #1,d0 +L(loop): move.l d3,(a6)+ + move.l d3,(a6)+ + move.l d3,(a6)+ + move.l d3,(a6)+ + ;;subq.l #1,d6 + dc.b 'u4' ; subq.l #1,d6 / subq.w #1,d6 bne L(loop) #endif +; ------------- flush the cache + +#ifdef FLUSH_CACHE + +; info: +; This is also called as a subroutine (before decompression, NOT running +; in the stack). When running in the stack the `rts' is replaced by a `nop'. +; +flush_cache: + FLUSH_CACHE +flush_cache_rts: + rts + +#endif + + +; ------------- restore ASTACK + + lea clear_bss_end-clear_bss+4(ASTACK),sp + + ;; assert sp == clear_bss_end(pc)+4 + + +; ------------- clear the dirty stack + +#if 0 +;;; /* 0 || defined(FLUSH_CACHE) */ + +; better don't do this - we are currently running in the stack +; and don't want to make yet another instruction-cache-line dirty + +clear_dirty_stack: + + ; clear down to clear_bss(pc) + 32 extra longs + moveq.l #((L(loop)-clear_bss+3)/4+32-1),d0 + lea L(loop)(pc),a0 +L(loop): move.l d3,-(a0) + dbra d0,L(loop) + +#endif + + ; ------------- start program movem.l (sp)+,d1-d7/a0-a6 @@ -288,11 +447,8 @@ clear_bss_end: align4 - ; 32 bytes - #include "header.ash" - dc.b 85,80,88,33 ; UPX_MAGIC_LE32 - dc.b 161,216,208,213 ; UPX_MAGIC2_LE32 - dc.l 0,0,0,0,0 ; 20 bytes - dc.b 0,0,0,45 + dc.b 'UPX!' ; magic + dc.l 0,0,0,0,0,0,0 ; 28 bytes - #include "header.ash" ; end of text segment - size is a multiple of 4 @@ -306,31 +462,43 @@ clear_bss_end: cutpoint: -; ------------- decompress (from a0 to a1) +; ------------- decompress (from a3 to a4) + +#define a0 A3 +#define a1 A4 +#define a3 A2 +#define d2 D3 #if defined(NRV2B) # include "m68k/n2b_d.ash" #elif defined(NRV2D) # include "m68k/n2d_d.ash" +#elif defined(NRV2E) +# include "m68k/n2e_d.ash" #else # error #endif - ; note: d2 is 0 from decompressor above +#undef a0 +#undef a1 +#undef a3 +#undef d2 + + ; note: d3.l is 0 from decompressor above -; ------------- prepare d0 for clearing the dirty bss +; ------------- prepare d6 for clearing the dirty bss #if defined(SMALL) - move.l #'up41',d0 ; dirty_bss / 4 + move.l #'up41',d6 ; dirty_bss / 4 #else - move.l #'up41',d0 ; dirty_bss / 16 + move.l #'up41',d6 ; dirty_bss / 16 #endif ; ------------- test if we need to reloc - dc.b 'u3' ; moveq.l #1,d3 / jmp (a5) + dc.b 'u3' ; moveq.l #1,d5 / jmp (ASTACK) ; ------------- reloc @@ -340,20 +508,20 @@ reloc: ; The decompressed relocations now are just after the decompressed ; data segment, i.e. at the beginning of the (dirty) bss. - ; note: d2 is still 0 + ; note: d3.l is still 0 move.l a6,a0 ; a0 = start of relocations move.l d4,a1 add.l (a0)+,a1 ; get initial fixup -L(loop1): add.l d2,a1 ; increase fixup +L(loop1): add.l d3,a1 ; increase fixup add.l d4,(a1) ; reloc one address -L(loop2): move.b (a0)+,d2 +L(loop2): move.b (a0)+,d3 beq reloc_end - cmp.b d3,d2 ; note: d3.b is #1 + cmp.b d5,d3 ; note: d5.b is #1 from above bne L(loop1) - lea 254(a1),a1 ; d2 == 1 -> add 254, don't reloc + lea 254(a1),a1 ; d3 == 1 -> add 254, don't reloc bra L(loop2) reloc_end: @@ -364,9 +532,9 @@ reloc_end: ; We are currently running in the dirty bss. ; Jump to the code we copied below the stack. - ; note: d2 is still 0 + ; note: d3.l is still 0 - jmp (a5) ; jmp clear_bss (on stack) + jmp (ASTACK) ; jmp clear_bss (on stack) diff --git a/src/stub/linux.hh b/src/stub/linux.hh index 2bfd75fe..0fdc1890 100644 --- a/src/stub/linux.hh +++ b/src/stub/linux.hh @@ -2,8 +2,8 @@ This file is part of the UPX executable compressor. - Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996-2001 Laszlo Molnar + Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2002 Laszlo Molnar All Rights Reserved. UPX and the UCL library are free software; you can redistribute them @@ -21,8 +21,8 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Markus F.X.J. Oberhumer Laszlo Molnar - markus@oberhumer.com ml1050@cdata.tvnet.hu + Markus F.X.J. Oberhumer Laszlo Molnar + */