Use Wine + Digital Mars C/C++ in small model. Does not work yet.

This commit is contained in:
Markus F.X.J. Oberhumer 2007-02-16 15:22:01 +01:00
parent ce7e94030c
commit 8f68f31877
14 changed files with 8528 additions and 8280 deletions

View File

@ -107,7 +107,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
unsigned minsp = 0x200;
if (M_IS_LZMA(ph.method))
minsp = getDecompressorWrkmemSize() + 0x1100;
minsp = getDecompressorWrkmemSize() + 0x1500; // FIXME ???
assert(minsp < 0xff00);
oh.sp = ih.sp > minsp ? (unsigned) ih.sp : minsp;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#
# highly experimental support for i086 using Open Watcom 1.6
# highly experimental support for i086 using Digital Mars C/C++
#
MAKEFLAGS += -rR
@ -35,60 +35,69 @@ include $(top_srcdir)/src/stub/Makefile
lzma_d_c% : tc_list = method-lzma arch-i086 default
lzma_d_c% : tc_bfdname =
# Open Watcom C/C++ 1.6
c := tc.method-lzma.wcl
$c = PATH='$(WATCOM)/binl:$(PATH)' $(WATCOM)/binl/wcl -zq -bt=dos
$c += -mc -ecc
$c += -zm -zc
$c += -os -s -0 -d0
$c += -w5 -we -fr=/dev/null
$c += -D__INT_MAX__=32767
# gcc
c := tc.arch-i086.gcc
$c += -MF /dev/null
$c += -Wall -W
$c += -I$(UPX_LZMADIR)
$c += -I$(top_srcdir)/src
tc.method-lzma.dmpobj = $(WATCOM)/binl/dmpobj
tc.method-lzma.wdump = $(WATCOM)/binl/wdump
# Digital Mars C/C++ 8.49
# http://www.digitalmars.com/download/freecompiler.html
ifneq ($(wildcard $(DM849DIR)/bin/.),)
c := tc.method-lzma.dmc
$c = @$(WINEENV) CFLAGS='$(DMC)' wine cmd.exe /c tmp/dmc.bat
$c += -ms -R
$c += -NS
$c += -w- -w7 -r
DMC := -o -0
DMC += -D__INT_MAX__=32767
DMC += -I$(shell winepath -s z:$(realpath $(UPX_LZMADIR)))
DMC += -I$(shell winepath -s z:$(realpath $(top_srcdir)/src))
endif
TMP_DEPS = tmp/.tmp-stamp tmp/bcc.bat tmp/cl.bat tmp/dmc.bat
lzma_d_c%.S : lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST)
python cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
ifneq ($(wildcard $(DM849DIR)/bin/.),)
ifneq ($(wildcard $(WATCOM)/binl/.),)
ifneq ($(wildcard /usr/bin/wine),)
ifneq ($(wildcard $(VCLINK.exe)),)
lzma_d_c%.i : lzma_d_c.c $(MAKEFILE_LIST) $(TMP_DEPS)
lzma_d_c%.i : tmp/lzma_d_c%.i
cp $< $@
tmp/lzma_d_c%.i : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS)
rm -f tmp/$T.a tmp/$T.o tmp/$T.obj
# compile
$(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T_wc.obj $<
$(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T.obj.disasm
## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T_bc.obj $<
## $(call tc,wdis) tmp/$T_bc.obj | $(RTRIM) > tmp/$T_bc.obj.disasm
$(call tc,dmc) $(PP_FLAGS) -c -otmp/$T_dm.obj $<
$(call tc,wdis) tmp/$T_dm.obj | $(RTRIM) > tmp/$T_dm.obj.disasm
$(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T_vc.obj $<
$(call tc,wdis) tmp/$T_vc.obj | $(RTRIM) > tmp/$T_vc.obj.disasm
# convert OMF to COFF because objdump does not support OMF
# TODO: should write a Python script wdis2gas.py and use that instead
cp -p tmp/$T_wc.obj tmp/$T.o
cd tmp && $(WINEENV) wine $(VCLINK.exe) -lib -nologo -out:$T.a $T.o
cd tmp && $(call tc,m-ar) x $T.a
# dump
$(call tc,objdump) -b coff-i386 -m i8086 -M intel -Dr --no-show -w tmp/$T.o | $(RTRIM) > $@
## $(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T_wc.obj $<
## $(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T.obj.disasm
## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T_bc.obj $<
## $(call tc,wdis) tmp/$T_bc.obj | $(RTRIM) > tmp/$T_bc.obj.disasm
## $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T_vc.obj $<
## $(call tc,wdis) tmp/$T_vc.obj | $(RTRIM) > tmp/$T_vc.obj.disasm
# convert
python wdis2gas.py tmp/$T_dm.obj.disasm tmp/$T.S
$(call tc,gcc) -c -o tmp/$T.o tmp/$T.S
$(call tc,f-objstrip,tmp/$T.o)
$(call tc,objdump) -b elf32-i386 -m i8086 -M intel -dr -j .text.LzmaDecode --no-show -w tmp/$T.o | $(RTRIM) | perl -pe 's/DWORD/dword/g; s/WORD/word/g; s/BYTE/byte/g; s/PTR/ptr/g;' > $@
.PRECIOUS: lzma_d_cf.i lzma_d_cs.i
endif
endif
endif
endif
.PRECIOUS: tmp/lzma_d_cf.i tmp/lzma_d_cs.i
lzma_d_cf.% : PP_FLAGS = -DFAST
lzma_d_cs.% : PP_FLAGS = -DSMALL
lzma_d_cf.% : LABEL_PREFIX = .Lf
lzma_d_cs.% : LABEL_PREFIX = .Ls
TMP_DEPS = tmp/.tmp-stamp tmp/bcc.bat tmp/cl.bat tmp/dmc.bat
endif
endif
endif
endif
# /***********************************************************************
@ -119,19 +128,27 @@ tmp/bcc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
tmp/cl.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
@$(call mkbat,$@,cl.exe,$(VC152WINDIR)\bin,$(VC152WINDIR)\include,$(VC152WINDIR)\lib)
tmp/dmc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
@$(call mkbat,$@,dmc.exe,$(DM847WINDIR)\bin,,)
@$(call mkbat,$@,dmc.exe,$(shell winepath -w $(DM849DIR)/bin),,)
# gcc
c := tc.arch-i386.gcc
$c += -Wall -W
# Open Watcom C/C++ 1.6
# http://openwatcom.com/
ifneq ($(wildcard $(WATCOM)/binl/.),)
c := tc.method-lzma.wcl
$c = PATH='$(WATCOM)/binl:$(PATH)' $(WATCOM)/binl/wcl -zq -bt=dos
$c += -ms -ecc
$c += -zm -zc
$c += -os -s -0 -d0
$c += -w5 -we -fr=/dev/null
$c += -D__INT_MAX__=32767
$c += -I$(UPX_LZMADIR)
$c += -I$(top_srcdir)/src
endif
# Borland C/C++ 5.02
ifneq ($(wildcard $(BC502DIR)/bin/.),)
c := tc.method-lzma.bcc
$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat
$c += -mc
$c += -ms
$c += -O1 -1
$c += -w
$c += -D__INT_MAX__=32767
@ -140,20 +157,6 @@ $c += -I$(subst \,/,$(shell winepath -s z:$(realpath $(UPX_LZMADIR)/C/7zip/Compr
$c += -I$(top_srcdir)/src
endif
# Digital Mars C/C++ 8.47
# http://www.digitalmars.com/download/freecompiler.html
ifneq ($(wildcard $(DM847DIR)/bin/.),)
c := tc.method-lzma.dmc
$c = @$(WINEENV) CFLAGS='$(DMC)' wine cmd.exe /c tmp/dmc.bat
$c += -ms
$c += -NS
$c += -w-
DMC := -o -0
DMC += -D__INT_MAX__=32767
DMC += -I$(shell winepath -s z:$(realpath $(UPX_LZMADIR)))
DMC += -I$(shell winepath -s z:$(realpath $(top_srcdir)/src))
endif
# Visual C/C++ 1.52 (8.00c)
ifneq ($(wildcard $(VC152DIR)/bin/.),)
c := tc.method-lzma.cl
@ -185,7 +188,7 @@ cc_test_bc: cc_test.c $(CC_TEST_DEPS)
## cat tmp/$T.obj.disasm
endif
ifneq ($(wildcard $(DM847DIR)/bin/.),)
ifneq ($(wildcard $(DM849DIR)/bin/.),)
cc_test_dm : tc_list = method-lzma arch-i086 default
cc_test_dm: cc_test.c $(CC_TEST_DEPS)
$(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $<
@ -210,7 +213,7 @@ L_TEST_DEPS = lzma_d_c.c $(MAKEFILE_LIST) $(TMP_DEPS)
DOSBOX = /usr/bin/time -v dosbox -exit
DOSBOX = dosbox
tmp/l_t_gcc_i386.% : tc_list = arch-i386 default
tmp/l_t_gcc_i386.% : tc_list = arch-i086 default
tmp/l_t_gcc_i386.out: l_test.c $(L_TEST_DEPS)
$(call tc,gcc) -O0 -g -o $@ $<
./$@
@ -218,21 +221,25 @@ tmp/l_t_gcc_i386.out: l_test.c $(L_TEST_DEPS)
tmp/l_t_bc.% : tc_list = method-lzma arch-i086 default
tmp/l_t_bc.exe: l_test.c $(L_TEST_DEPS)
$(call tc,bcc) -o$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj
$(DOSBOX) $@
tmp/l_t_dm.% : tc_list = method-lzma arch-i086 default
tmp/l_t_dm.exe: l_test.c $(L_TEST_DEPS)
$(call tc,dmc) -ml -o$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj
$(DOSBOX) $@
tmp/l_t_wc.% : tc_list = method-lzma arch-i086 default
tmp/l_t_wc.exe: l_test.c $(L_TEST_DEPS)
$(call tc,wcl) -fe=$@ $<
@rm -f l_test.o l_test.obj
$(DOSBOX) $@
tmp/l_t_vc.% : tc_list = method-lzma arch-i086 default
tmp/l_t_vc.exe: l_test.c $(L_TEST_DEPS)
$(call tc,cl) -Fe$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj
$(DOSBOX) $@
.PHONY: tmp/l_t_gcc_i386.out tmp/l_t_bc.exe tmp/l_t_dm.exe tmp/l_t_wc.exe tmp/l_t_vc.exe

View File

@ -37,14 +37,12 @@ class opts:
# optimizer flags
auto_inline = 1
call_rewrite = 1
loop_rewrite = 1
inline_map = {
## "__PIA": "WCC_PIA",
"__PTS": "WCC_PTS",
## "__U4M_V01": "WCC_U4M_V01",
"__PIA_V02": "WCC_PIA_V02",
"__PIA_V01": "WCC_PIA_V01",
"__aNNalshl": "M_aNNalshl",
"__aNahdiff": "M_aNahdiff",
}
@ -75,14 +73,20 @@ def main(argv):
#
labels = {}
def parse_label(inst, args):
m = re.search("^([0-9a-z]+)\s+<", args)
if m:
k = v = None
m = re.search(r"^(.*?)\b(2|R_386_PC16)\s+(__\w+)$", args)
if m and k is None:
# external 2-byte label
k, v = m.group(3).strip(), [1, 2, None, 0]
m = re.search("^0x([0-9a-z]+)$", args)
if m and k is None:
# local label
k, v = m.group(1).strip(), [0, 0, None, 0]
m = re.search(r"^(.*?)\b2\s+(__\w+)$", args)
if m:
# external 2-byte label
k, v = m.group(2).strip(), [1, 2, None, 0]
m = re.search("^([0-9a-z]+)\s+<", args)
if m and k is None:
# local label
k, v = m.group(1).strip(), [0, 0, None, 0]
assert k and v, (inst, args)
v[2] = k # new name
if labels.has_key(k):
assert labels[k][:2] == v[:2]
@ -101,33 +105,38 @@ def main(argv):
dpos = []
while i < len(m):
if pos < 0 or pos >= len(olines):
return False
return []
dpos.append(pos)
o = olines[pos][1:3]
assert len(m[i]) == 2, (i, m)
if o[0].lower() != m[i][0].lower():
return False
return []
if o[1].lower() != m[i][1].lower():
return []
pos += 1
i += 1
return dpos
def orewrite(i, k, v, dpos):
def orewrite_inst(i, inst, args, dpos):
for pos in dpos:
olines[pos][1] = "*DEL*"
olines[i][1] = inst
olines[i][2] = args
olines[i][3] = None
def orewrite_call(i, k, v, dpos):
for pos in dpos:
olines[pos][1] = "*DEL*"
v[2] = k
olines[i][2] = None
olines[i][3] = add_label(k, v)
#
# pass 1
func = None
for i in range(len(lines)):
l = lines[i]
m = re.search(r"^0000000000000000\s*<(\w+)>:", l)
m = re.search(r"^0{8,16}\s*<(\.text\.)?(\w+)>:", l)
if m:
func = re.sub(r"^_+|_+$", "", m.group(1))
func = re.sub(r"^_+|_+$", "", m.group(2))
if not func in ["LzmaDecode"]:
continue
m = re.search(r"^(\s*[0-9a-z]+):\s+(\w+)(.*)", l)
@ -141,10 +150,10 @@ def main(argv):
if inst in ["movl",] and re.search(r"\b[de]s\b", args):
# fix bug in objdump
inst = "movw"
m = re.search(r"^(.+?)\b0x0\s+(\w+):\s+[12]\s+(__\w+)$", args)
m = re.search(r"^(.+?)\b0x0\s+(\w+):\s+(1|2|R_386_16|R_386_PC16)\s+(__\w+)$", args)
if m:
# 1 or 2 byte reloc
args = m.group(1) + m.group(3)
args = m.group(1) + m.group(4)
olines.append([label, inst, args, None])
#
# pass 2
@ -157,70 +166,53 @@ def main(argv):
if opts.call_rewrite and inst in ["call"]:
k, v = parse_label(inst, args)
if v[:2] == [1, 2]: # external 2-byte
if k == "__PIA":
inst1 = [
["mov", "bx,WORD PTR [bp-94]"],
["or", "bx,ax"],
["mov", "WORD PTR [bp-8],bx"],
["mov", "WORD PTR [bp-4],dx"],
["mov", "ax,WORD PTR [bp-12]"],
["movw", "dx,ds"],
["mov", "bx,0x1"],
if k == "__LMUL":
s = [
["xor", "cx,cx"],
]
inst2 = [
["mov", "WORD PTR [bp-12],ax"],
["movw", "ds,dx"],
]
dpos1 = omatch(i - 8, inst1[-8:])
dpos2 = omatch(i + 1, inst2)
if dpos1 and dpos2:
orewrite(i, "__PIA_V04", v, dpos1 + dpos2)
continue
dpos1 = omatch(i - 4, inst1[-4:])
dpos2 = omatch(i + 1, inst2)
if dpos1 and dpos2:
orewrite(i, "__PIA_V03", v, dpos1 + dpos2)
continue
dpos = omatch(i - 3, inst1[-3:])
dpos = omatch(i - 1, s[-1:])
if dpos:
orewrite(i, "__PIA_V02", v, dpos)
orewrite_inst(i, "M_LMUL_dxax_00bx", "", dpos)
continue
dpos = omatch(i - 2, inst1[-2:])
if dpos:
orewrite(i, "__PIA_V01", v, dpos)
continue
if k == "__PTC":
inst1 = [
["mov", "ax,WORD PTR [bp-12]"],
["movw", "dx,ds"],
["mov", "bx,WORD PTR [bp-26]"],
["mov", "cx,WORD PTR [bp-24]"],
if k == "__aNahdiff":
s = [
["push", "word ptr [bp+8]"],
["push", "word ptr [bp+6]"],
["push", "word ptr [bp-66]"],
["push", "word ptr [bp-68]"],
]
dpos = omatch(i - 4, inst1[-4:])
dpos = omatch(i - 4, s[-4:])
if dpos:
orewrite(i, "__PTC_V01", v, dpos)
continue
if k == "__U4M":
inst1 = [
["mov", "bx,WORD PTR es:[bx]"],
["mov", "ax,WORD PTR [bp-102]"],
["mov", "dx,WORD PTR [bp-100]"],
["xor", "cx,cx"],
]
inst2 = [
["mov", "WORD PTR [bp-10],ax"],
["mov", "WORD PTR [bp-6],dx"],
]
dpos1 = omatch(i - 4, inst1[-4:])
dpos2 = omatch(i + 1, inst2)
if dpos1 and dpos2:
orewrite(i, "__U4M_V02", v, dpos1 + dpos2)
continue
dpos = omatch(i - 1, inst1[-1:])
if dpos:
orewrite(i, "__U4M_V01", v, dpos)
orewrite_inst(i, "*DEL*", "", dpos)
continue
if opts.loop_rewrite and inst in ["loop"]:
s = [
["mov", "cx,0xb"],
["shr", "dx,1"],
["rcr", "ax,1"],
]
dpos = omatch(i - 3, s[-3:])
if dpos:
orewrite_inst(i, "M_shrd_11", "", dpos)
continue
s = [
["mov", "cl,0x8"],
["shl", "ax,1"],
["rcl", "dx,1"],
]
dpos = omatch(i - 3, s[-3:])
if dpos:
orewrite_inst(i, "M_shld_8", "", dpos)
continue
s = [
["mov", "cx,0x8"],
["shl", "ax,1"],
["rcl", "dx,1"],
]
dpos = omatch(i - 3, s[-3:])
if dpos:
orewrite_inst(i, "M_shld_8", "", dpos)
continue
#
if inst in [
"call", "ja", "jae", "jb", "jbe", "jcxz", "je",
@ -229,9 +221,8 @@ def main(argv):
k, v = parse_label(inst, args)
olines[i][2] = None
olines[i][3] = add_label(k, v)
#
# rewrite local labels
# pass 3
digits, i = 1, len(labels)
while i >= 10:
digits += 1
@ -258,7 +249,7 @@ def main(argv):
olines[i][2] = "/* inlined */"
olines[i][2] = ""
olines[i][3] = None
#
# write ofile
ofp = open(ofile, "wb")
for label, inst, args, args_label in olines:

View File

@ -68,7 +68,7 @@ typedef unsigned int uint32_t;
>>> import pylzma; d="\1" + "\0"*131070 + "\2"; print len(d)
>>> c=pylzma.compress(d, eos=0)[5:]; print len(c), map(ord, c)
*/
static const unsigned char c_data[96] = {
static const unsigned char c_data[92] = {
0, 0, 128, 65, 72, 1, 140, 46, 188, 80, 161, 51, 135, 75, 212, 2, 20, 181, 241, 145, 230, 34, 107, 72, 201, 86, 118, 176, 70, 120, 214, 184, 247, 212, 250, 132, 59, 160, 44, 112, 185, 177, 245, 126, 103, 190, 14, 145, 73, 36, 148, 246, 166, 58, 41, 192, 68, 167, 144, 98, 122, 42, 61, 195, 135, 248, 98, 136, 254, 191, 96, 21, 192, 75, 86, 63, 228, 231, 15, 70, 52, 239, 169, 194, 249, 109, 126, 11, 123, 48, 0, 0
};
@ -100,7 +100,7 @@ int main()
s->Properties.lc = 3; s->Properties.lp = 0; s->Properties.pb = 2;
r = LzmaDecode(s, src, src_len, &src_out, dst, dst_len, &dst_out);
if (r != 0 || src_out > src_len || dst_out != dst_len)
if (r != 0 || src_out != src_len || dst_out != dst_len)
{
printf("ERROR: Decompression error %d %lu %lu\n", r, (long)src_out, (long)dst_out);
return 1;

View File

@ -39,35 +39,21 @@
/*************************************************************************
// override generic macros with special versions
// support macros
**************************************************************************/
// huge pointer diff: dx:ax = dx:ax - cx:bx
// !!! this version does nothing !!!
.macro M_WCC_PTS_lzma
.macro M_aNahdiff
add sp, 8
.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
.macro M_LMUL_dxax_00bx
// mult high-word
xchg cx, ax // cx: save ax
xchg ax, dx
mov cx, ax // cx: save ax
mov ax, dx
mul bx
xchg ax, cx // save high-word result, get orig ax
// mult low-word
@ -76,8 +62,9 @@ L1:
add dx, cx // add high-word result
.endm
// umul32: dx:ax = ax:cx * 00:bx
.macro M_WCC_U4M_axcx_00bx
.macro M_LMUL_axcx_00bx
// mult high-word
mul bx
xchg ax, cx // save high-word result, get low
@ -88,6 +75,43 @@ L1:
.endm
// shld: dx:ax <<= 8
.macro M_shld_8
mov dh, dl
mov dl, ah
mov ah, al
xor al, al
//xor cx, cx // FIXME - do we need this ?
.endm
// shld: dx:ax >>= 11
.macro M_shrd_11
#if 1
mov al, ah
mov ah, dl
mov dl, dh
xor dh, dh
shr dx
rcr ax
shr dx
rcr ax
shr dx
rcr ax
#else
mov bx, dx
mov cl, 11
shr dx, cl
shr ax, cl
mov cl, 5
shl bx, cl
or ax, bx
#endif
//xor cx, cx // FIXME - do we need this ?
.endm
#if 0
// shld: dx:ax <<= cl; trashes register "r1" (bx, di, si or bp)
// REQUIRED: 0 <= cl < 32
// FIXME - this does not work yet
@ -101,6 +125,7 @@ L1:
shr r1, cl
or dx, r1
.endm
#endif
/*************************************************************************
@ -109,97 +134,6 @@ L1:
section LZMA_DEC99
__PIA_V04:
mov bx,WORD PTR [bp-94]
or bx,ax
mov WORD PTR [bp-8],bx
mov WORD PTR [bp-4],dx
__PIA_V03:
mov ax,WORD PTR [bp-12]
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 1f
add dh, (__AHINCR >> 8)
movw ds, dx
1:
mov WORD PTR [bp-12],ax
#endif
ret
.macro M_WCC_PIA_V02_lzma
movw dx, ds
#if 0
mov bx,0x1
xor cx,cx
M_WCC_PIA
#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:
M_WCC_PIA
ret
__PTC_V01:
mov ax,WORD PTR [bp-12]
movw dx,ds
mov bx,WORD PTR [bp-26]
mov cx,WORD PTR [bp-24]
__PTC:
M_WCC_PTC
ret
#define WCC_PTS M_WCC_PTS
__U4M_V02:
#if 0
mov bx,WORD PTR es:[bx]
mov ax,WORD PTR [bp-102]
mov dx,WORD PTR [bp-100]
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:
#if 0
xor cx,cx
M_WCC_U4M
#else
M_WCC_U4M_dxax_00bx
#endif
ret
/*************************************************************************
//
@ -207,14 +141,22 @@ __U4M_V01:
// init
section LZMA_DEC00
// .byte 0xcc
//.byte 0xcc
push ds
mov bp, sp
#if 1
// DEBUG - check for enough stack
lea bx, [bp + lzma_stack_adjust - 256]
cmp bp, bx
1: jcs 1b
#endif
lea bx, [bp + lzma_stack_adjust]
#if 0
// clear stack
xor ax, ax
1:
push ax
1: push ax
cmp sp, bx
jnz 1b
#else
@ -224,32 +166,33 @@ section LZMA_DEC00
inc si
inc si
push ss // &outSizeProcessed
push bx
push bx // &outSizeProcessed __near [bp + 24]
mov ax, offset lzma_u_len_hi // outSize
push ax
push ax // [bp + 22]
mov ax, offset lzma_u_len
push ax
push es // out
push di
push ax // [bp + 20]
push es // out [bp + 18]
push di // [bp + 16]
add bx, 4
push ss // &inSizeProcessed
push bx
push bx // &inSizeProcessed __near [bp + 14]
mov ax, offset lzma_c_len_hi // inSize
push ax
push ax // [bp + 12]
mov ax, offset lzma_c_len
push ax
push ds // in
push si
push ax // [bp + 10]
push ds // in [bp + 8]
push si // [bp + 6]
// enter small model
push ss
pop ds
add bx, 4
push ss
push bx
push bx // &state __near [bp + 4]
mov ax, offset lzma_properties_hi
mov ss:[bx + 2], ax
mov [bx + 2], ax
mov ax, offset lzma_properties
mov ss:[bx], ax
mov [bx], ax
call LZMA_DEC10
jmp LZMA_DEC30
@ -268,15 +211,15 @@ section LZMA_DEC20
section LZMA_DEC30
#if 0
// clear dirty stack
lea bx, [bp + lzma_stack_adjust - 128]
lea bx, [bp + lzma_stack_adjust - 256]
mov sp, bp
xor ax, ax
1:
push ax
1: push ax
cmp sp, bx
jnz 1b
#endif
mov sp, bp
pop ds
mov di, offset lzma_u_len
section LZMA_DEC31
@ -286,12 +229,5 @@ 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
// vi:ts=4:et

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -120,6 +120,7 @@
.byte 0x7f, \target - . - 1
.endm
#define jaes jncs
#define jbes jnas
#define jbs jcs
#define jes jzs
@ -129,7 +130,7 @@
/*
; =============
; ============= WATCOM C/C++ HUGE POINTER SUPPORT
; ============= HUGE POINTER SUPPORT
; =============
*/
@ -138,6 +139,7 @@
#define __AHINCR (1 << __AHSHIFT) /* 4096 */
#if 0
// huge pointer add: dx:ax = dx:ax + cx:bx
.macro M_WCC_PIA
add ax, bx
@ -147,6 +149,7 @@
shl bx, cl
add dx, bx
.endm
#endif
#if 0

View File

@ -0,0 +1,146 @@
#! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
#
# wdis2gas.py --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# 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
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
import getopt, os, re, string, sys
class opts:
arch = "i086"
label_prefix = ".L"
verbose = 0
# /***********************************************************************
# // main
# ************************************************************************/
def main(argv):
shortopts, longopts = "qv", [
"arch", "label-prefix=", "quiet", "verbose"
]
xopts, args = getopt.gnu_getopt(argv[1:], shortopts, longopts)
for opt, optarg in xopts:
if 0: pass
elif opt in ["-q", "--quiet"]: opts.verbose = opts.verbose - 1
elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1
elif opt in ["--arch"]: opts.arch = optarg
elif opt in ["--label-prefix"]: opts.label_prefix = optarg
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
#
assert len(args) == 2
ifile = args[0]
ofile = args[1]
# read ifile
lines = open(ifile, "rb").readlines()
lines = map(string.rstrip, lines)
#
section = None
func = None
olines = []
for i in range(len(lines)):
l = lines[i]
if not l: continue
m = re.search(r"^No disassembly errors", l)
if m: continue
m = re.search(r"^Module:", l)
if m: continue
m = re.search(r"^GROUP:", l)
if m: continue
m = re.search(r"^(BSS|Routine) Size:", l)
if m: continue
m = re.search(r"Segment:\s+(.+)\s+([0-9a-fA-F]+)\s+bytes$", l)
if m:
s = re.split(r"\s+", m.group(1))
assert len(s) == 3, (i, l, s, m.groups())
section = s
func = None
continue
m = re.search(r"Comdat:\s+(.+)\s+SEGMENT NONE '(\w+)'\s+([0-9a-fA-F]+)\s+bytes$", l)
if m:
section = [m.group(2)]
assert section[0].endswith("_TEXT"), (i, l, section)
func = re.sub(r"^[_@]+|[_@]+$", "", m.group(1))
olines.append(".section .text." + func)
continue
assert section, (i, l)
m = re.search(r"^0000\s+(\w+):$", l)
if m:
assert section[0].endswith("_TEXT"), (i, l, section)
func = re.sub(r"^[_@]+|[_@]+$", "", m.group(1))
olines.append(".section .text." + func)
continue
assert func, (i, l, section)
m = re.search(r"^[0-9a-fA-F]{4}\s+L\$(\d+):$", l)
if m:
olines.append(opts.label_prefix + m.group(1) + ":")
continue
m = re.search(r"^[0-9a-fA-F]{4} (([0-9a-fA-F]{2} )+)\s+(.+)$", l)
assert m, (i, l)
if m.group(3).startswith("call"):
s = re.split(r"\s+", m.group(3))
assert len(s) == 2, (i, l, s, m.groups())
f = re.sub(r"^[@]+|[@]+$", "", s[1])
olines.append(" call " + f)
elif 1:
s = m.group(3).strip()
s = re.sub("L\$(\d+)", opts.label_prefix + "\g<1>", s)
olines.append(" " + s)
else:
s = re.split(r"\s+", m.group(1).strip())
assert 1 <= len(s) <= 5, (i, l, s, m.groups())
s = ["0x" + x for x in s]
olines.append(" .byte " + ",".join(s))
# write ofile
ofp = open(ofile, "wb")
ofp.write(".code16\n")
ofp.write(".intel_syntax noprefix\n")
if opts.arch in ["i086", "8086", "i8086"]:
ofp.write(".arch i8086, jumps\n")
elif opts.arch in ["i286"]:
ofp.write(".arch i286, jumps\n")
else:
assert 0, ("invalid arch", opts.arch)
if 0:
for sym in ["__AHSHIFT", "__AHINCR", "__LMUL", "__aNahdiff"]:
ofp.write(".extern %s\n" % (sym))
ofp.write(".type %s,@function\n" % (sym))
ofp.write(".size %s,2\n" % (sym))
for l in olines:
ofp.write(l.rstrip() + "\n")
ofp.close()
##print olines
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@ -83,11 +83,6 @@ ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(CLzmaDecoderState) == 32768u)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(SizeT) >= 4)
#if (ACC_ARCH_I086)
# if (ACC_MM_HUGE)
typedef unsigned short __far MyCProb;
# undef CProb
# define CProb MyCProb
# endif
# define char char __huge
#elif (ACC_CC_WATCOMC)
#else

View File

@ -44,27 +44,27 @@ Idx Name Size VMA LMA File off Algn Flags
39 NRV2EEX3 00000015 00000000 00000000 0000027b 2**0 CONTENTS, RELOC, READONLY
40 N2E64K02 0000000b 00000000 00000000 00000290 2**0 CONTENTS, READONLY
41 NRV2EEX9 00000004 00000000 00000000 0000029b 2**0 CONTENTS, READONLY
42 LZMA_DEC99 0000005d 00000000 00000000 0000029f 2**0 CONTENTS, READONLY
43 LZMA_DEC00 0000003d 00000000 00000000 000002fc 2**0 CONTENTS, RELOC, READONLY
44 LZMA_DEC10 00000e94 00000000 00000000 00000339 2**0 CONTENTS, RELOC, READONLY
45 LZMA_DEC20 00000e94 00000000 00000000 000011cd 2**0 CONTENTS, RELOC, READONLY
46 LZMA_DEC30 00000005 00000000 00000000 00002061 2**0 CONTENTS, RELOC, READONLY
47 LZMA_DEC31 00000007 00000000 00000000 00002066 2**0 CONTENTS, RELOC, READONLY
48 EXEMAIN5 00000001 00000000 00000000 0000206d 2**0 CONTENTS, READONLY
49 EXEADJUS 00000007 00000000 00000000 0000206e 2**0 CONTENTS, READONLY
50 EXENOADJ 00000002 00000000 00000000 00002075 2**0 CONTENTS, READONLY
51 EXERELO1 0000001e 00000000 00000000 00002077 2**0 CONTENTS, RELOC, READONLY
52 EXEREL9A 00000012 00000000 00000000 00002095 2**0 CONTENTS, RELOC, READONLY
53 EXERELO2 00000004 00000000 00000000 000020a7 2**0 CONTENTS, READONLY
54 EXEREBIG 00000002 00000000 00000000 000020ab 2**0 CONTENTS, RELOC, READONLY
55 EXERELO3 00000002 00000000 00000000 000020ad 2**0 CONTENTS, RELOC, READONLY
56 EXEMAIN8 00000003 00000000 00000000 000020af 2**0 CONTENTS, READONLY
57 DEVICEEND 00000013 00000000 00000000 000020b2 2**0 CONTENTS, READONLY
58 EXESTACK 00000006 00000000 00000000 000020c5 2**0 CONTENTS, RELOC, READONLY
59 EXESTASP 00000003 00000000 00000000 000020cb 2**0 CONTENTS, RELOC, READONLY
60 EXEJUMPF 00000005 00000000 00000000 000020ce 2**0 CONTENTS, RELOC, READONLY
61 EXERCSPO 00000004 00000000 00000000 000020d3 2**0 CONTENTS, RELOC, READONLY
62 EXERETIP 00000006 00000000 00000000 000020d7 2**0 CONTENTS, RELOC, READONLY
42 LZMA_DEC99 00000000 00000000 00000000 0000029f 2**0 CONTENTS, READONLY
43 LZMA_DEC00 00000043 00000000 00000000 0000029f 2**0 CONTENTS, RELOC, READONLY
44 LZMA_DEC10 00001203 00000000 00000000 000002e2 2**0 CONTENTS, READONLY
45 LZMA_DEC20 00001203 00000000 00000000 000014e5 2**0 CONTENTS, READONLY
46 LZMA_DEC30 00000006 00000000 00000000 000026e8 2**0 CONTENTS, RELOC, READONLY
47 LZMA_DEC31 00000007 00000000 00000000 000026ee 2**0 CONTENTS, RELOC, READONLY
48 EXEMAIN5 00000001 00000000 00000000 000026f5 2**0 CONTENTS, READONLY
49 EXEADJUS 00000007 00000000 00000000 000026f6 2**0 CONTENTS, READONLY
50 EXENOADJ 00000002 00000000 00000000 000026fd 2**0 CONTENTS, READONLY
51 EXERELO1 0000001e 00000000 00000000 000026ff 2**0 CONTENTS, RELOC, READONLY
52 EXEREL9A 00000012 00000000 00000000 0000271d 2**0 CONTENTS, RELOC, READONLY
53 EXERELO2 00000004 00000000 00000000 0000272f 2**0 CONTENTS, READONLY
54 EXEREBIG 00000002 00000000 00000000 00002733 2**0 CONTENTS, RELOC, READONLY
55 EXERELO3 00000002 00000000 00000000 00002735 2**0 CONTENTS, RELOC, READONLY
56 EXEMAIN8 00000003 00000000 00000000 00002737 2**0 CONTENTS, READONLY
57 DEVICEEND 00000013 00000000 00000000 0000273a 2**0 CONTENTS, READONLY
58 EXESTACK 00000006 00000000 00000000 0000274d 2**0 CONTENTS, RELOC, READONLY
59 EXESTASP 00000003 00000000 00000000 00002753 2**0 CONTENTS, RELOC, READONLY
60 EXEJUMPF 00000005 00000000 00000000 00002756 2**0 CONTENTS, RELOC, READONLY
61 EXERCSPO 00000004 00000000 00000000 0000275b 2**0 CONTENTS, RELOC, READONLY
62 EXERETIP 00000006 00000000 00000000 0000275f 2**0 CONTENTS, RELOC, READONLY
SYMBOL TABLE:
00000000 l d DEVICEENTRY 00000000 DEVICEENTRY
00000000 l d EXEENTRY 00000000 EXEENTRY
@ -80,7 +80,6 @@ SYMBOL TABLE:
00000000 l d NRV2EEX2 00000000 NRV2EEX2
00000000 l d NRV2EEX3 00000000 NRV2EEX3
00000000 l d NRV2EEX9 00000000 NRV2EEX9
00000000 l d LZMA_DEC99 00000000 LZMA_DEC99
00000000 l d LZMA_DEC10 00000000 LZMA_DEC10
00000000 l d LZMA_DEC30 00000000 LZMA_DEC30
00000000 l d EXERELO1 00000000 EXERELO1
@ -113,6 +112,7 @@ SYMBOL TABLE:
00000000 l d N2EX8602 00000000 N2EX8602
00000000 l d N2E28602 00000000 N2E28602
00000000 l d N2E64K02 00000000 N2E64K02
00000000 l d LZMA_DEC99 00000000 LZMA_DEC99
00000000 l d LZMA_DEC00 00000000 LZMA_DEC00
00000000 l d LZMA_DEC20 00000000 LZMA_DEC20
00000000 l d LZMA_DEC31 00000000 LZMA_DEC31
@ -254,127 +254,20 @@ OFFSET TYPE VALUE
RELOCATION RECORDS FOR [LZMA_DEC00]:
OFFSET TYPE VALUE
00000004 R_386_16 lzma_stack_adjust
0000000d R_386_16 lzma_u_len_hi
00000011 R_386_16 lzma_u_len
0000001c R_386_16 lzma_c_len_hi
00000020 R_386_16 lzma_c_len
0000002b R_386_16 lzma_properties_hi
00000032 R_386_16 lzma_properties
00000038 R_386_PC16 LZMA_DEC10
0000003b R_386_PC16 LZMA_DEC30
RELOCATION RECORDS FOR [LZMA_DEC10]:
OFFSET TYPE VALUE
000000e5 R_386_PC16 LZMA_DEC99
0000011b R_386_PC16 LZMA_DEC99
00000127 R_386_PC16 LZMA_DEC99
00000170 R_386_PC16 LZMA_DEC99
00000199 R_386_PC16 LZMA_DEC99
000001b0 R_386_PC16 LZMA_DEC99
00000213 R_386_PC16 LZMA_DEC99
00000247 R_386_PC16 LZMA_DEC99
00000283 R_386_PC16 LZMA_DEC99
000002af R_386_PC16 LZMA_DEC99
000002c6 R_386_PC16 LZMA_DEC99
0000034c R_386_PC16 LZMA_DEC99
00000378 R_386_PC16 LZMA_DEC99
0000038f R_386_PC16 LZMA_DEC99
000003ff R_386_PC16 LZMA_DEC99
00000467 R_386_PC16 LZMA_DEC99
00000493 R_386_PC16 LZMA_DEC99
000004aa R_386_PC16 LZMA_DEC99
0000054e R_386_PC16 LZMA_DEC99
0000057a R_386_PC16 LZMA_DEC99
00000591 R_386_PC16 LZMA_DEC99
000005f5 R_386_PC16 LZMA_DEC99
0000064d R_386_PC16 LZMA_DEC99
000006a6 R_386_PC16 LZMA_DEC99
000006c7 R_386_PC16 LZMA_DEC99
00000730 R_386_PC16 LZMA_DEC99
00000784 R_386_PC16 LZMA_DEC99
000007ee R_386_PC16 LZMA_DEC99
0000081a R_386_PC16 LZMA_DEC99
00000831 R_386_PC16 LZMA_DEC99
000008e0 R_386_PC16 LZMA_DEC99
0000090c R_386_PC16 LZMA_DEC99
00000926 R_386_PC16 LZMA_DEC99
000009a3 R_386_PC16 LZMA_DEC99
000009cf R_386_PC16 LZMA_DEC99
000009e9 R_386_PC16 LZMA_DEC99
00000a89 R_386_PC16 LZMA_DEC99
00000ab5 R_386_PC16 LZMA_DEC99
00000acc R_386_PC16 LZMA_DEC99
00000b85 R_386_PC16 LZMA_DEC99
00000bb1 R_386_PC16 LZMA_DEC99
00000bc8 R_386_PC16 LZMA_DEC99
00000c86 R_386_PC16 LZMA_DEC99
00000cb2 R_386_PC16 LZMA_DEC99
00000d1d R_386_PC16 LZMA_DEC99
00000d49 R_386_PC16 LZMA_DEC99
00000d60 R_386_PC16 LZMA_DEC99
00000e0d R_386_PC16 LZMA_DEC99
00000e31 R_386_PC16 LZMA_DEC99
00000e61 R_386_PC16 LZMA_DEC99
00000e69 R_386_PC16 LZMA_DEC99
RELOCATION RECORDS FOR [LZMA_DEC20]:
OFFSET TYPE VALUE
000000e5 R_386_PC16 LZMA_DEC99
0000011b R_386_PC16 LZMA_DEC99
00000127 R_386_PC16 LZMA_DEC99
00000170 R_386_PC16 LZMA_DEC99
00000199 R_386_PC16 LZMA_DEC99
000001b0 R_386_PC16 LZMA_DEC99
00000213 R_386_PC16 LZMA_DEC99
00000247 R_386_PC16 LZMA_DEC99
00000283 R_386_PC16 LZMA_DEC99
000002af R_386_PC16 LZMA_DEC99
000002c6 R_386_PC16 LZMA_DEC99
0000034c R_386_PC16 LZMA_DEC99
00000378 R_386_PC16 LZMA_DEC99
0000038f R_386_PC16 LZMA_DEC99
000003ff R_386_PC16 LZMA_DEC99
00000467 R_386_PC16 LZMA_DEC99
00000493 R_386_PC16 LZMA_DEC99
000004aa R_386_PC16 LZMA_DEC99
0000054e R_386_PC16 LZMA_DEC99
0000057a R_386_PC16 LZMA_DEC99
00000591 R_386_PC16 LZMA_DEC99
000005f5 R_386_PC16 LZMA_DEC99
0000064d R_386_PC16 LZMA_DEC99
000006a6 R_386_PC16 LZMA_DEC99
000006c7 R_386_PC16 LZMA_DEC99
00000730 R_386_PC16 LZMA_DEC99
00000784 R_386_PC16 LZMA_DEC99
000007ee R_386_PC16 LZMA_DEC99
0000081a R_386_PC16 LZMA_DEC99
00000831 R_386_PC16 LZMA_DEC99
000008e0 R_386_PC16 LZMA_DEC99
0000090c R_386_PC16 LZMA_DEC99
00000926 R_386_PC16 LZMA_DEC99
000009a3 R_386_PC16 LZMA_DEC99
000009cf R_386_PC16 LZMA_DEC99
000009e9 R_386_PC16 LZMA_DEC99
00000a89 R_386_PC16 LZMA_DEC99
00000ab5 R_386_PC16 LZMA_DEC99
00000acc R_386_PC16 LZMA_DEC99
00000b85 R_386_PC16 LZMA_DEC99
00000bb1 R_386_PC16 LZMA_DEC99
00000bc8 R_386_PC16 LZMA_DEC99
00000c86 R_386_PC16 LZMA_DEC99
00000cb2 R_386_PC16 LZMA_DEC99
00000d1d R_386_PC16 LZMA_DEC99
00000d49 R_386_PC16 LZMA_DEC99
00000d60 R_386_PC16 LZMA_DEC99
00000e0d R_386_PC16 LZMA_DEC99
00000e31 R_386_PC16 LZMA_DEC99
00000e61 R_386_PC16 LZMA_DEC99
00000e69 R_386_PC16 LZMA_DEC99
00000005 R_386_16 lzma_stack_adjust
0000000d R_386_16 lzma_stack_adjust
00000015 R_386_16 lzma_u_len_hi
00000019 R_386_16 lzma_u_len
00000023 R_386_16 lzma_c_len_hi
00000027 R_386_16 lzma_c_len
00000033 R_386_16 lzma_properties_hi
00000039 R_386_16 lzma_properties
0000003e R_386_PC16 LZMA_DEC10
00000041 R_386_PC16 LZMA_DEC30
RELOCATION RECORDS FOR [LZMA_DEC30]:
OFFSET TYPE VALUE
00000003 R_386_16 lzma_u_len
00000004 R_386_16 lzma_u_len
RELOCATION RECORDS FOR [LZMA_DEC31]:
OFFSET TYPE VALUE