diff --git a/src/p_tos.cpp b/src/p_tos.cpp index 0d66eded..a10ff3e2 100644 --- a/src/p_tos.cpp +++ b/src/p_tos.cpp @@ -170,16 +170,15 @@ void PackTos::buildLoader(const Filter *ft) addLoader("IDENTSTR,+40D,UPX1HEAD,CUTPOINT", NULL); - // FIXME: symbols.decompr_offset should not be hardcoded if (M_IS_NRV2B(ph.method)) { addLoader(opt->small ? "nrv2b_8.small" : "nrv2b_8.fast", NULL); - symbols.decompr_offset = 2; + symbols.decompr_offset = 2; // FIXME: do not hardcode this value } else if (M_IS_NRV2D(ph.method)) { addLoader(opt->small ? "nrv2d_8.small" : "nrv2d_8.fast", NULL); - symbols.decompr_offset = 2; + symbols.decompr_offset = 2; // FIXME: do not hardcode this value } else if (M_IS_NRV2E(ph.method)) { addLoader(opt->small ? "nrv2e_8.small" : "nrv2e_8.fast", NULL); - symbols.decompr_offset = 2; + symbols.decompr_offset = 2; // FIXME: do not hardcode this value } else if (M_IS_LZMA(ph.method)) { addLoader("__mulsi3", NULL); addLoader(opt->small ? "lzma.small" : "lzma.fast", NULL); diff --git a/src/p_tos.h b/src/p_tos.h index 5bb0977e..631dc2bb 100644 --- a/src/p_tos.h +++ b/src/p_tos.h @@ -78,19 +78,19 @@ protected: // symbols for buildLoader() struct LinkerSymbols { - // "constant" - bool need_reloc; - // these are updated by buildLoader() enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA }; struct LoopInfo { unsigned mode; unsigned count; unsigned value; void init(unsigned count, bool allow_dbra=true); }; + // buildLoader() input + bool need_reloc; LoopInfo loop1; LoopInfo loop2; LoopInfo loop3; + // buildLoader() output unsigned decompr_offset; - // + // currently not used by buildLoader() unsigned flush_cache_rts_offset; unsigned clear_dirty_stack_len; unsigned copy_to_stack_len; diff --git a/src/stub/m68k-atari.tos.h b/src/stub/m68k-atari.tos.h index 58e3946f..1b23119f 100644 --- a/src/stub/m68k-atari.tos.h +++ b/src/stub/m68k-atari.tos.h @@ -28,8 +28,8 @@ #define NRV_LOADER_SIZE 22678 -#define NRV_LOADER_ADLER32 0x4eff9534 -#define NRV_LOADER_CRC32 0x18a1e612 +#define NRV_LOADER_ADLER32 0xff879594 +#define NRV_LOADER_CRC32 0x0fa53df8 unsigned char nrv_loader[22678] = { 127, 69, 76, 70, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */ @@ -396,7 +396,7 @@ unsigned char nrv_loader[22678] = { 0,255,255,255, 98, 8,185,239, 0, 84,103, 24, 82,140,153,239, /* 0x1690 */ 0,116, 32,111, 0,124, 32,140, 34,111, 0,136, 34,175, 0, 50, /* 0x16a0 */ 112, 0, 96, 2,112, 1, 76,223, 92,252, 79,239, 0, 68,118, 0, /* 0x16b0 */ - 79,234,255, 0, 46,195, 46,195, 46,195, 46,195,190,143,102,244, /* 0x16c0 */ + 79,234,255, 96, 46,195, 46,195, 46,195, 46,195,190,143,102,244, /* 0x16c0 */ 32, 78,122, 1, 34, 68,211,216,211,195,217,145, 22, 24,103, 10, /* 0x16d0 */ 182, 5,102,244, 67,233, 0,254, 96,242,124, 0, 60, 60, 0, 0, /* 0x16e0 */ 44, 60, 0, 0, 0, 0, 78,215, 65,239, 0, 4, 50, 24, 48, 24, /* 0x16f0 */ diff --git a/src/stub/src/arch/m68k/lzma_d.S b/src/stub/src/arch/m68k/lzma_d.S index 89e8f45e..6cb95d95 100644 --- a/src/stub/src/arch/m68k/lzma_d.S +++ b/src/stub/src/arch/m68k/lzma_d.S @@ -48,17 +48,15 @@ section lzma.init move.l sp,a2 -// move.l (a2)+,-(sp) // &outSizeProcessed - pea (a2) // &outSizeProcessed + // push 32 bytes on stack + pea (a2) // &outSizeProcessed move.l #lzma_u_len,-(sp) // outSize move.l d4,-(sp) // out -// move.l (a2)+,-(sp) // &inSizeProcessed - pea 4(a2) // &inSizeProcessed + pea 4(a2) // &inSizeProcessed move.l #lzma_c_len,-(sp) // inSize move.l a3,-(sp) // in -// move.l (a2),-(sp) // &CLzmaDecoderState pea 8(a2) // &CLzmaDecoderState - move.l d0,-(sp) // dummy for call + move.l d0,-(sp) // dummy return address (instead of call) // hardwired LzmaDecodeProperties() move.l #lzma_properties,8(a2) // lc, lp, pb, dummy @@ -75,14 +73,21 @@ section lzma.small section lzma.finish moveq.l #0,d3 -// add.l 4(a2),XX // inSizeProcessed -// add.l (a2),XX // outSizeProcessed + //add.l 4(a2),a3 // inSizeProcessed + //add.l (a2),d4 // outSizeProcessed #if 0 move.l d7,sp // restore stack #else -// Partially clear exposed stack (only because of paranoia.) - lea -256(a2),sp + +// Clear dirty stack (also see m68000/tmp/lzma_d_c[fs].out.disasm) +// 32 bytes pushed above +// 68 bytes local stack in LzmaDecode +// 40 bytes for saving 10 registers in LzmaDecode +// 12 bytes for calling __mulsi3 +// 152 *TOTAL* (round up by 16 to 160) + + lea -160(a2),sp .clearstack2: move.l d3,(sp)+ move.l d3,(sp)+ diff --git a/src/stub/src/m68k-atari.tos.S b/src/stub/src/m68k-atari.tos.S index 0748f38a..330dcf64 100644 --- a/src/stub/src/m68k-atari.tos.S +++ b/src/stub/src/m68k-atari.tos.S @@ -64,7 +64,6 @@ p_flags equ $28 ; .l memory usage flags p_env equ $2c ; .l pointer to environment string */ -p_tbase = 8 /* ; long living registers: @@ -210,7 +209,7 @@ section entry // we also setup d4 and a6 here, and we prepare a4 move.l d0,a2 // a2 = basepage - addq.l #p_tbase,a2 + addq.l #8,a2 move.l (a2)+,a6 move.l a6,d4 // d4 = p_tbase move.l #up11,(a2) // p_tlen @@ -270,8 +269,8 @@ section loop1_dbra section loop2.fast // loop2 - copy the remaining 4..160 bytes moveq.l #loop2_count,d0 -loop2: move.l -(a4),-(a3) - dbra d0,loop2 +1: move.l -(a4),-(a3) + dbra d0,1b section loop2.small // loop2 - EMPTY section @@ -292,9 +291,9 @@ section copy_to_stack //moveq.l #((clear_bss_end-clear_bss)/2-1),d5 moveq.l #copy_to_stack_len,d5 -loop6: move.w -(a2),-(ASTACK) +1: move.w -(a2),-(ASTACK) subq.l #1,d5 - bccs loop6 + bccs 1b // note: d5.l is now -1 (needed for decompressor) @@ -411,7 +410,7 @@ section clear_dirty_stack // ------------- clear the dirty stack // clear down to clear_bss(pc) + 32 extra longs - //moveq.l #((L(loop)-clear_bss+3)/4+32-1),d0 + ////moveq.l #((clear_dirty_stack_loop-clear_bss+3)/4+32-1),d0 moveq.l #clear_dirty_stack_len,d0 lea 1f(pc),a0 GL(clear_dirty_stack_loop) // for clear_dirty_stack_len