diff --git a/src/stub/src/arch/i086/cc_test.c b/src/stub/src/arch/i086/cc_test.c index dc8f787e..7ef76808 100644 --- a/src/stub/src/arch/i086/cc_test.c +++ b/src/stub/src/arch/i086/cc_test.c @@ -58,9 +58,11 @@ typedef unsigned short hsize_t; // pia - pointer add hptr __cdecl pia(hptr a, hsize_t d) { return a + d; } +hptr __cdecl pia1(hptr a) { return a + 1; } // pis - pointer subtract hptr __cdecl pis(hptr a, hsize_t d) { return a - d; } +hptr __cdecl pis1(hptr a) { return a - 1; } // pts - pointer diff hptrdiff_t __cdecl pts(hptr a, hptr b) { return a - b; } @@ -85,10 +87,17 @@ int16_t __cdecl i2m(int16_t a, int16_t b) { return a * b; } uint32_t __cdecl u2m4(uint16_t a, uint16_t b) { return a * b; } int32_t __cdecl i2m4(int16_t a, int16_t b) { return a * b; } +uint16_t __cdecl u2shl8 (uint16_t a) { return a << 8; } +uint32_t __cdecl u4shl8 (uint32_t a) { return a << 8; } uint16_t __cdecl u2shl12(uint16_t a) { return a << 12; } -uint32_t __cdecl u4shl14(uint32_t a) { return a << 12; } +uint32_t __cdecl u4shl12(uint32_t a) { return a << 12; } +uint32_t __cdecl u4shl16(uint32_t a) { return a << 16; } +uint32_t __cdecl u4shl24(uint32_t a) { return a << 24; } uint16_t __cdecl u2shlv(uint16_t a, unsigned v) { return a << v; } uint32_t __cdecl u4shlv(uint32_t a, unsigned v) { return a << v; } +hptrdiff_t __cdecl hptr2int(hptr a) { return (hptrdiff_t) a; } +hptr __cdecl int2hptr(hptrdiff_t a) { return (hptr) a; } + /* vim:set ts=4 et: */ diff --git a/src/stub/src/arch/i086/cleanasm.py b/src/stub/src/arch/i086/cleanasm.py index 82b6a01e..4f65709a 100644 --- a/src/stub/src/arch/i086/cleanasm.py +++ b/src/stub/src/arch/i086/cleanasm.py @@ -223,8 +223,8 @@ def main(argv): continue # if inst in [ - "call", "ja", "jae", "jb", "jbe", "jcxz", - "je", "jge", "jl", "jmp", "jne", "loop", + "call", "ja", "jae", "jb", "jbe", "jcxz", "je", + "jg", "jge", "jl", "jle", "jmp", "jne", "loop", ]: k, v = parse_label(inst, args) olines[i][2] = None diff --git a/src/stub/src/arch/i086/lzma_d.S b/src/stub/src/arch/i086/lzma_d.S index 13ee7692..abad9177 100644 --- a/src/stub/src/arch/i086/lzma_d.S +++ b/src/stub/src/arch/i086/lzma_d.S @@ -38,6 +38,56 @@ */ +/************************************************************************* +// override generic macros with special versions +**************************************************************************/ + +// huge pointer diff: dx:ax = dx:ax - cx:bx +// !!! this version does nothing !!! +.macro M_WCC_PTS_lzma +.endm + +#define M_WCC_PTS M_WCC_PTS_lzma + + +// huge pointer compare: set zero and carry flags: dx:ax cmp cx:bx +// !!! this version does not normalize pointers !!! +.macro M_WCC_PTC_lzma + local L1 + cmp dx, cx + jnes L1 + cmp ax, bx +L1: +.endm + +#define M_WCC_PTC M_WCC_PTC_lzma + + +// umul32: dx:ax = dx:ax * 00:bx +.macro M_WCC_U4M_dxax_00bx + // mult high-word + xchg cx, ax // cx: save ax + xchg ax, dx + mul bx + xchg ax, cx // save high-word result, get orig ax + // mult low-word + mul bx // dx:ax := ax * bx + // add high-word + add dx, cx // add high-word result +.endm + +// umul32: dx:ax = ax:cx * 00:bx +.macro M_WCC_U4M_axcx_00bx + // mult high-word + mul bx + xchg ax, cx // save high-word result, get low + // mult low-word + mul bx + // add high-word + add dx, cx // add high-word result +.endm + + /************************************************************************* // support code (see cleanasm.py) **************************************************************************/ @@ -51,26 +101,42 @@ __PIA_V04: mov WORD PTR [bp-4],dx __PIA_V03: mov ax,WORD PTR [bp-12] -// FIXME: need optimized version here movw dx,ds +#if 0 mov bx,0x1 xor cx,cx M_WCC_PIA mov WORD PTR [bp-12],ax movw ds,dx +#else + // optimized version + inc ax + jnes .L1 + add dh, (__AHINCR >> 8) + movw ds, dx +.L1: + mov WORD PTR [bp-12],ax +#endif ret -#if 1 -.macro lzma_WCC_PIA_V02 -// FIXME: need optimized version here - movw dx,ds +.macro M_WCC_PIA_V02_lzma + movw dx, ds +#if 0 mov bx,0x1 xor cx,cx M_WCC_PIA -.endm -#define WCC_PIA_V02 lzma_WCC_PIA_V02 +#else + // optimized version + local L1 + inc ax + jnes L1 + add dh, (__AHINCR >> 8) + movw ds, dx +L1: #endif +.endm +#define WCC_PIA_V02 M_WCC_PIA_V02_lzma __PIA: @@ -88,30 +154,35 @@ __PTC: ret -#if 1 -// FIXME: do we actually need the PTS result ?? #define WCC_PTS M_WCC_PTS -#else -#define WCC_PTS xor ax,ax; xor dx,dx -#endif __U4M_V02: +#if 0 mov bx,WORD PTR es:[bx] mov ax,WORD PTR [bp-102] mov dx,WORD PTR [bp-100] -// FIXME: need optimized version here (cx = 0) xor cx,cx M_WCC_U4M +#else + // optimized version + mov bx,WORD PTR es:[bx] + mov cx,WORD PTR [bp-102] + mov ax,WORD PTR [bp-100] + M_WCC_U4M_axcx_00bx +#endif mov WORD PTR [bp-10],ax mov WORD PTR [bp-6],dx ret __U4M_V01: -// FIXME: need optimized version here (cx = 0) +#if 0 xor cx,cx M_WCC_U4M +#else + M_WCC_U4M_dxax_00bx +#endif ret @@ -119,39 +190,42 @@ __U4M_V01: // **************************************************************************/ - // init section LZMA_DEC00 // .byte 0xcc mov bp, sp lea bx, [bp + lzma_stack_adjust] +#if 0 xor ax, ax .clearstack: push ax cmp sp, bx jnz .clearstack +#else + mov sp, bx +#endif inc si inc si - push ss // outSizeProcessed + push ss // &outSizeProcessed push bx - mov ax, offset lzma_u_len_hi + mov ax, offset lzma_u_len_hi // outSize push ax mov ax, offset lzma_u_len - push ax // outSize - push es - push di // out + push ax + push es // out + push di add bx, 4 - push ss // inSizeProcessed + push ss // &inSizeProcessed push bx - mov ax, offset lzma_c_len_hi + mov ax, offset lzma_c_len_hi // inSize push ax mov ax, offset lzma_c_len - push ax // inSize - push ds - push si // in + push ax + push ds // in + push si add bx, 4 push ss @@ -160,23 +234,23 @@ section LZMA_DEC00 mov ss:[bx + 2], ax mov ax, offset lzma_properties mov ss:[bx], ax - call LZMA_DEC10 -// .byte 0xcc - mov sp, bp + call LZMA_DEC10 jmp LZMA_DEC30 + section LZMA_DEC10 .arch i8086, nojumps #include "lzma_d_cs.S" section LZMA_DEC20 .arch i8086, nojumps #include "lzma_d_cf.S" - .arch i8086, jumps + // cleanup section LZMA_DEC30 + mov sp, bp mov di, offset lzma_u_len section LZMA_DEC31 @@ -186,6 +260,10 @@ section LZMA_DEC31 mov es, ax +#undef M_WCC_PTS +#undef M_WCC_PTC +#undef M_WCC_U4M + #undef WCC_PIA_V02 #undef WCC_PTS diff --git a/src/stub/src/arch/i086/macros.S b/src/stub/src/arch/i086/macros.S index 80ea9d5d..c197a34a 100644 --- a/src/stub/src/arch/i086/macros.S +++ b/src/stub/src/arch/i086/macros.S @@ -149,6 +149,7 @@ .endm +#if 0 // huge pointer sub: dx:ax = dx:ax - cx:bx .macro M_WCC_PIS sub ax, bx @@ -158,8 +159,10 @@ shl bx, cl sub dx, bx .endm +#endif +#if 0 // huge pointer diff: dx:ax = dx:ax - cx:bx .macro M_WCC_PTS // normalize @@ -168,6 +171,7 @@ sub ax, bx sbb dx, cx .endm +#endif #if 0 @@ -180,19 +184,17 @@ cmp ax, bx L1: .endm +#endif +#if 0 // umul32: dx:ax = dx:ax * cx:bx .macro M_WCC_U4M // FIXME - // compute high-word - // add low-word .endm - -#else -# include "tainted.h" #endif + /* ; ============= ; ============= 16-BIT CALLTRICK & JUMPTRICK