This commit is contained in:
John Reiser
2007-02-18 09:09:17 -08:00
12 changed files with 8123 additions and 8462 deletions
+2
View File
@@ -140,6 +140,8 @@ RTRIM := sed -e 's/[ $(tab)]*$$//'
BLSQUEEZE := $(RTRIM) | cat --squeeze-blank | sed -e '1{/^$$/d}' -e '$${/^$$/d}' BLSQUEEZE := $(RTRIM) | cat --squeeze-blank | sed -e '1{/^$$/d}' -e '$${/^$$/d}'
# delete blank lines # delete blank lines
BLDEL := $(RTRIM) | sed -e '/^$$/d' BLDEL := $(RTRIM) | sed -e '/^$$/d'
#
UNIX2DOS := perl -i -pe 's/$$/\r/;'
# clear some vars, just in case # clear some vars, just in case
LABEL_PREFIX = LABEL_PREFIX =
+1464 -1479
View File
File diff suppressed because it is too large Load Diff
+175 -135
View File
@@ -1,6 +1,10 @@
# #
# highly experimental support for i086 using Digital Mars C/C++ # highly experimental support for i086 using Digital Mars C/C++
# #
# $(DM849DIR)
# $(WATCOM)
# /usr/bin/wine
#
MAKEFLAGS += -rR MAKEFLAGS += -rR
.SUFFIXES: .SUFFIXES:
@@ -29,85 +33,19 @@ include $(top_srcdir)/src/stub/Makefile
# /*********************************************************************** # /***********************************************************************
# // method-lzma # //
# ************************************************************************/ # ************************************************************************/
lzma_d_c% : tc_list = method-lzma arch-i086 default DOSBOX = true
lzma_d_c% : tc_bfdname = DOSBOX = dosbox
DOSBOX = /usr/bin/time -p dosbox -exit
# gcc
c := tc.arch-i086.gcc
$c += -MF /dev/null
$c += -Wall -W
$c += -I$(UPX_LZMADIR)
$c += -I$(top_srcdir)/src
# 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),)
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,dmc) $(PP_FLAGS) -c -otmp/$T_dm.obj $<
$(call tc,wdis) tmp/$T_dm.obj | $(RTRIM) > tmp/$T_dm.obj.disasm
## $(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
.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
endif
endif
endif
endif
# /***********************************************************************
# // cc_test
# ************************************************************************/
CC_TEST_DEPS = $(MAKEFILE_LIST) $(TMP_DEPS)
WINEENV = env WINEENV = env
WINEENV = env -i DISPLAY='$(DISPLAY)' HOME='$(HOME)' PATH='$(PATH)' USER='$(USER)' WINEENV = env -i DISPLAY='$(DISPLAY)' HOME='$(HOME)' PATH='$(PATH)' USER='$(USER)'
winedir_s = $(shell winepath -s z:$(realpath $1))
winedir_w = $(shell winepath -w $(realpath $1))
# work around limitations of wine's cmd.exe # work around limitations of wine's cmd.exe
define mkbat define mkbat
echo -E '@set PATH=$3;%PATH%' > $1 echo -E '@set PATH=$3;%PATH%' > $1
@@ -120,19 +58,76 @@ define mkbat
echo -e '@shift\n@shift\n@shift\n@shift\n@shift' >> $1 echo -e '@shift\n@shift\n@shift\n@shift\n@shift' >> $1
echo -e '@shift\n@shift\n@shift\n@shift' >> $1 echo -e '@shift\n@shift\n@shift\n@shift' >> $1
echo -E '$2 %a% %b% %1 %2 %3 %4 %5 %6 %7 %8 %9' >> $1 echo -E '$2 %a% %b% %1 %2 %3 %4 %5 %6 %7 %8 %9' >> $1
unix2dos -q $1 $(UNIX2DOS) $1
endef endef
TMP_DEPS = tmp/.tmp-stamp tmp/bcc.bat tmp/cl.bat tmp/dmc.bat
tmp/bcc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) tmp/bcc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
@$(call mkbat,$@,bcc.exe,$(BC502WINDIR)\bin,,) @$(call mkbat,$@,bcc.exe,$(call winedir_w,$(BC502DIR)/bin))
tmp/cl.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) tmp/cl.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
@$(call mkbat,$@,cl.exe,$(VC152WINDIR)\bin,$(VC152WINDIR)\include,$(VC152WINDIR)\lib) @$(call mkbat,$@,cl.exe,$(call winedir_w,$(VC152DIR)/bin),$(call winedir_w,$(VC152DIR)/include),$(call winedir_w,$(VC152DIR)/lib))
tmp/dmc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) tmp/dmc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST)
@$(call mkbat,$@,dmc.exe,$(shell winepath -w $(DM849DIR)/bin),,) @$(call mkbat,$@,dmc.exe,$(call winedir_w,$(DM849DIR)/bin))
# /***********************************************************************
# // method-lzma
# ************************************************************************/
lzma_d_c% : tc_list = method-lzma arch-i086 default
lzma_d_c% : tc_bfdname =
# gcc
c := tc.arch-i086.gcc
$c += -MF /dev/null
$c += -Wall -W
$c += -I$(UPX_LZMADIR)
$c += -I$(top_srcdir)/src
# Borland C/C++ 5.02
ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),)
c := tc.method-lzma.bcc
$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat
$c += -ms
$c += -O1 -1
$c += -w
$c += -D__INT_MAX__=32767
$c += -I$(subst \,/,$(call winedir_w,$(UPX_LZMADIR)/C/7zip/Compress/LZMA_C))
$c += -I$(top_srcdir)/src
endif
# Digital Mars C/C++ 8.49
# http://www.digitalmars.com/download/freecompiler.html
ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),)
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$(call winedir_w,$(UPX_LZMADIR))
DMC += -I$(call winedir_w,$(top_srcdir)/src)
endif
# Visual C/C++ 1.52 (8.00c)
ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),)
c := tc.method-lzma.cl
$c = @$(WINEENV) CL='$(CL)' wine cmd.exe /c tmp/cl.bat
$c += -AS -Gd
$c += -Gy
$c += -O2 -Gf -Gs -G0
$c += -W4
CL := -nologo
CL += -D__INT_MAX__=32767
CL += -I$(call winedir_s,$(UPX_LZMADIR))
CL += -I$(call winedir_s,$(top_srcdir)/src)
endif
# Open Watcom C/C++ 1.6 # Open Watcom C/C++ 1.6
# http://openwatcom.com/ # http://openwatcom.com/
ifneq ($(wildcard $(WATCOM)/binl/.),) ifneq ($(wildcard $(WATCOM)/binl/wcl),)
c := tc.method-lzma.wcl c := tc.method-lzma.wcl
$c = PATH='$(WATCOM)/binl:$(PATH)' $(WATCOM)/binl/wcl -zq -bt=dos $c = PATH='$(WATCOM)/binl:$(PATH)' $(WATCOM)/binl/wcl -zq -bt=dos
$c += -ms -ecc $c += -ms -ecc
@@ -144,103 +139,148 @@ $c += -I$(UPX_LZMADIR)
$c += -I$(top_srcdir)/src $c += -I$(top_srcdir)/src
endif endif
# Borland C/C++ 5.02 lzma_d_c%.S : lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST)
ifneq ($(wildcard $(BC502DIR)/bin/.),) python cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@
c := tc.method-lzma.bcc
$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
$c += -ms ##ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),)
$c += -O1 -1 ifneq ($(wildcard $(WATCOM)/binl/wcl),)
$c += -w ifneq ($(wildcard /usr/bin/wine),)
$c += -D__INT_MAX__=32767
##$c += -I$(subst \,/,$(shell winepath -s z:$(realpath $(UPX_LZMADIR)))) lzma_d_c%.i : tmp/lzma_d_c%.i
$c += -I$(subst \,/,$(shell winepath -s z:$(realpath $(UPX_LZMADIR)/C/7zip/Compress/LZMA_C))) cp $< $@
$c += -I$(top_srcdir)/src
tmp/lzma_d_c%.i : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS)
rm -f tmp/$T*.i tmp/$T*.o tmp/$T*.obj tmp/$T*.S
# compile
ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),)
## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T_bc.obj $<
## $(call tc,wdis) tmp/$T_bc.obj | $(RTRIM) > tmp/$T_bc.obj.disasm
endif
ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),)
$(call tc,dmc) $(PP_FLAGS) -c -otmp/$T_dm.obj $<
$(call tc,wdis) tmp/$T_dm.obj | $(RTRIM) > tmp/$T_dm.obj.disasm
endif
ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),)
$(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T_vc.obj $<
$(call tc,wdis) tmp/$T_vc.obj | $(RTRIM) > tmp/$T_vc.obj.disasm
endif
ifneq ($(wildcard $(WATCOM)/binl/wcl),)
$(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T_wc.obj $<
$(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T_wc.obj.disasm
endif
# convert
python wdis2gas.py tmp/$T_wc.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
.PRECIOUS: tmp/lzma_d_cf.i tmp/lzma_d_cs.i
endif
endif
##endif
endif endif
# Visual C/C++ 1.52 (8.00c) lzma_d_cf.% : PP_FLAGS = -DFAST
ifneq ($(wildcard $(VC152DIR)/bin/.),) lzma_d_cs.% : PP_FLAGS = -DSMALL
c := tc.method-lzma.cl lzma_d_cf.% : LABEL_PREFIX = .Lf
$c = @$(WINEENV) CL='$(CL)' wine cmd.exe /c tmp/cl.bat lzma_d_cs.% : LABEL_PREFIX = .Ls
$c += -AS -Gd
$c += -Gy
$c += -O2 -Gf -Gs -G0
$c += -W4
CL := -nologo
CL += -D__INT_MAX__=32767
CL += -I$(shell winepath -s z:$(realpath $(UPX_LZMADIR)))
CL += -I$(shell winepath -s z:$(realpath $(top_srcdir)/src))
endif
ifneq ($(wildcard $(WATCOM)/binl/.),) # /***********************************************************************
cc_test_wc : tc_list = method-lzma arch-i086 default # // cc_test
cc_test_wc: cc_test.c $(CC_TEST_DEPS) # ************************************************************************/
$(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## cat tmp/$T.obj.disasm
endif
ifneq ($(wildcard $(BC502DIR)/bin/.),) ifneq ($(wildcard $(WATCOM)/binl/wdis),)
CC_TEST_DEPS = $(MAKEFILE_LIST) $(TMP_DEPS)
ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),)
cc_test_bc : tc_list = method-lzma arch-i086 default cc_test_bc : tc_list = method-lzma arch-i086 default
cc_test_bc: cc_test.c $(CC_TEST_DEPS) cc_test_bc: cc_test.c $(CC_TEST_DEPS)
$(call tc,bcc) $(PP_FLAGS) -c -otmp/$T.obj $< $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## cat tmp/$T.obj.disasm cc_test_all: cc_test_bc
endif endif
ifneq ($(wildcard $(DM849DIR)/bin/.),) ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),)
cc_test_dm : tc_list = method-lzma arch-i086 default cc_test_dm : tc_list = method-lzma arch-i086 default
cc_test_dm: cc_test.c $(CC_TEST_DEPS) cc_test_dm: cc_test.c $(CC_TEST_DEPS)
$(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $< $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## cat tmp/$T.obj.disasm cc_test_all: cc_test_dm
endif endif
ifneq ($(wildcard $(VC152DIR)/bin/.),) ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),)
cc_test_vc : tc_list = method-lzma arch-i086 default cc_test_vc : tc_list = method-lzma arch-i086 default
cc_test_vc: cc_test.c $(CC_TEST_DEPS) cc_test_vc: cc_test.c $(CC_TEST_DEPS)
$(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T.obj $< $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## cat tmp/$T.obj.disasm cc_test_all: cc_test_vc
endif endif
ifneq ($(wildcard $(WATCOM)/binl/wcl),)
cc_test_wc : tc_list = method-lzma arch-i086 default
cc_test_wc: cc_test.c $(CC_TEST_DEPS)
$(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
cc_test_all: cc_test_wc
endif
.PHONY: cc_test_all
endif # wdis
# /*********************************************************************** # /***********************************************************************
# // l_test # // l_test
# ************************************************************************/ # ************************************************************************/
L_TEST_DEPS = lzma_d_c.c $(MAKEFILE_LIST) $(TMP_DEPS) 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-i086 default tmp/l_test_gcc_i386.% : tc_list = arch-i086 default
tmp/l_t_gcc_i386.out: l_test.c $(L_TEST_DEPS) tmp/l_test_gcc_i386.out: l_test.c $(L_TEST_DEPS)
$(call tc,gcc) -O0 -g -o $@ $< $(call tc,gcc) -O0 -g -o $@ $<
./$@ ./$@
l_test_all: tmp/l_test_gcc_i386.out
tmp/l_t_bc.% : tc_list = method-lzma arch-i086 default ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),)
tmp/l_t_bc.exe: l_test.c $(L_TEST_DEPS) tmp/l_test_bc.% : tc_list = method-lzma arch-i086 default
tmp/l_test_bc.exe: l_test.c $(L_TEST_DEPS)
$(call tc,bcc) -o$(subst /,\\,$@) $< $(call tc,bcc) -o$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj @rm -f l_test.o l_test.obj
$(DOSBOX) $@ cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe
##l_test_all: tmp/l_test_bc.exe
endif
tmp/l_t_dm.% : tc_list = method-lzma arch-i086 default ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),)
tmp/l_t_dm.exe: l_test.c $(L_TEST_DEPS) tmp/l_test_dm.% : tc_list = method-lzma arch-i086 default
tmp/l_test_dm.exe: l_test.c $(L_TEST_DEPS)
$(call tc,dmc) -ml -o$(subst /,\\,$@) $< $(call tc,dmc) -ml -o$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj @rm -f l_test.o l_test.obj
$(DOSBOX) $@ cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe
l_test_all: tmp/l_test_dm.exe
endif
tmp/l_t_wc.% : tc_list = method-lzma arch-i086 default ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),)
tmp/l_t_wc.exe: l_test.c $(L_TEST_DEPS) tmp/l_test_vc.% : tc_list = method-lzma arch-i086 default
$(call tc,wcl) -fe=$@ $< tmp/l_test_vc.exe: l_test.c $(L_TEST_DEPS)
@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 /,\\,$@) $< $(call tc,cl) -Fe$(subst /,\\,$@) $<
@rm -f l_test.o l_test.obj @rm -f l_test.o l_test.obj
$(DOSBOX) $@ cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe
l_test_all: tmp/l_test_vc.exe
endif
.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 ifneq ($(wildcard $(WATCOM)/binl/wcl),)
tmp/l_test_wc.% : tc_list = method-lzma arch-i086 default
tmp/l_test_wc.exe: l_test.c $(L_TEST_DEPS)
$(call tc,wcl) -fe=$@ $<
@rm -f l_test.o l_test.obj
cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe
l_test_all: tmp/l_test_wc.exe
endif
.PHONY: l_test_all
+120 -30
View File
@@ -41,8 +41,12 @@ class opts:
inline_map = { inline_map = {
"__aNNalshl": "M_aNNalshl", "__aNNalshl": ["M_aNNalshl", 1],
"__aNahdiff": "M_aNahdiff", "__aNahdiff": ["M_aNahdiff", 1],
"__PIA": ["M_PIA", 999],
"__PTS": ["M_PTS", 999],
"__PTC": ["M_PTC", 999],
"__U4M": ["M_U4M", 999],
} }
@@ -63,6 +67,7 @@ def main(argv):
else: assert 0, ("getopt problem:", opt, optarg, xopts, args) else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
# #
assert opts.label_prefix
assert len(args) == 2 assert len(args) == 2
ifile = args[0] ifile = args[0]
ofile = args[1] ofile = args[1]
@@ -100,30 +105,54 @@ def main(argv):
return k return k
olines = [] olines = []
def omatch(pos, m): def omatch(pos, mlen, m, debug=0):
i = 0 assert len(m) >= abs(mlen)
dpos = [] def sgn(x):
while i < len(m): if x < 0: return -1
if x > 0: return 1
return 0
def match(a, b):
if b is None:
return False
if "^" in a or "*" in a:
# regexp
return re.search(a, b.lower())
else:
return a.lower() == b.lower()
mpos = []
while len(mpos) != abs(mlen):
if pos < 0 or pos >= len(olines): if pos < 0 or pos >= len(olines):
return [] return []
dpos.append(pos) o = olines[pos]
o = olines[pos][1:3] if o[1] != "*DEL*":
mpos.append(pos)
pos += sgn(mlen)
if mlen < 0:
mpos.reverse()
if debug and 1: print mlen, m, [olines[x] for x in mpos]
dpos = []
i = -abs(mlen)
while i < 0:
pos = mpos[i]
o = olines[pos]
assert o[1] != "*DEL*"
assert len(m[i]) == 2, (i, m) assert len(m[i]) == 2, (i, m)
if o[0].lower() != m[i][0].lower(): m0 = match(m[i][0], o[1])
m1 = match(m[i][1], o[2])
if not m0 or not m1:
return [] return []
if o[1].lower() != m[i][1].lower(): dpos.append([pos, m0, m1])
return []
pos += 1
i += 1 i += 1
assert len(dpos) == abs(mlen)
return dpos return dpos
def orewrite_inst(i, inst, args, dpos): def orewrite_inst(i, inst, args, dpos):
for pos in dpos: for pos, m0, m1 in dpos:
olines[pos][1] = "*DEL*" olines[pos][1] = "*DEL*"
olines[i][1] = inst olines[i][1] = inst
olines[i][2] = args olines[i][2] = args
olines[i][3] = None olines[i][3] = None
def orewrite_call(i, k, v, dpos): def orewrite_call(i, k, v, dpos):
for pos in dpos: for pos, m0, m1 in dpos:
olines[pos][1] = "*DEL*" olines[pos][1] = "*DEL*"
v[2] = k v[2] = k
olines[i][2] = None olines[i][2] = None
@@ -166,11 +195,16 @@ def main(argv):
if opts.call_rewrite and inst in ["call"]: if opts.call_rewrite and inst in ["call"]:
k, v = parse_label(inst, args) k, v = parse_label(inst, args)
if v[:2] == [1, 2]: # external 2-byte if v[:2] == [1, 2]: # external 2-byte
if k == "__LMUL": if k in ["__LMUL", "__U4M",]:
s = [ s = [
["mov", "bx,word ptr [bx]"],
["xor", "cx,cx"], ["xor", "cx,cx"],
] ]
dpos = omatch(i - 1, s[-1:]) dpos = omatch(i-1, -2, s, debug=0)
if 0 and dpos:
orewrite_inst(i, "M_LMUL_dxax_00bx_ptr", "", dpos)
continue
dpos = omatch(i-1, -1, s)
if dpos: if dpos:
orewrite_inst(i, "M_LMUL_dxax_00bx", "", dpos) orewrite_inst(i, "M_LMUL_dxax_00bx", "", dpos)
continue continue
@@ -181,37 +215,93 @@ def main(argv):
["push", "word ptr [bp-66]"], ["push", "word ptr [bp-66]"],
["push", "word ptr [bp-68]"], ["push", "word ptr [bp-68]"],
] ]
dpos = omatch(i - 4, s[-4:]) dpos = omatch(i-1, -4, s)
if dpos: if dpos:
orewrite_inst(i, "*DEL*", "", dpos) orewrite_inst(i, "*DEL*", "", dpos)
continue continue
if k == "__PIA":
s = [
["mov", "bx,0x1"],
["xor", "cx,cx"],
]
dpos = omatch(i-1, -2, s)
if dpos:
orewrite_inst(i, "M_PIA1", "", dpos)
continue
if k == "__PTC":
s = [
["jne", "(.*)"],
]
dpos = omatch(i+1, 1, s)
if dpos:
olines[i][1] = "M_PTC_JNE"
k, v = parse_label("jne", dpos[0][2].group(1))
orewrite_call(i, k, v, dpos)
continue
if opts.loop_rewrite and inst in ["loop"]: if opts.loop_rewrite and inst in ["loop"]:
s = [ s = [
["mov", "cx,0xb"], ["mov", r"^c[lx],0xb$"],
["shr", "dx,1"], ["shr", "dx,1"],
["rcr", "ax,1"], ["rcr", "ax,1"],
] ]
dpos = omatch(i - 3, s[-3:]) dpos = omatch(i-1, -3, s)
if dpos: if dpos:
orewrite_inst(i, "M_shrd_11", "", dpos) orewrite_inst(i, "M_shrd_11", "", dpos)
continue continue
s = [ s = [
["mov", "cl,0x8"], ["mov", r"^c[lx],0x8$"],
["shl", "ax,1"], ["shl", "ax,1"],
["rcl", "dx,1"], ["rcl", "dx,1"],
] ]
dpos = omatch(i - 3, s[-3:]) dpos = omatch(i-1, -3, s)
if dpos: if dpos:
orewrite_inst(i, "M_shld_8", "", dpos) orewrite_inst(i, "M_shld_8", "", dpos)
continue continue
s = [ s1 = [
["mov", "cx,0x8"], ["mov", r"^c[lx],0x8$"],
["shl", "ax,1"], ["shl", r"^word ptr \[bp([+-]\d+)\],1$"],
["rcl", "dx,1"], ["rcl", r"^word ptr \[bp([+-]\d+)\],1$"],
] ]
dpos = omatch(i - 3, s[-3:]) s2 = [
if dpos: ["mov", r"^dx,word ptr"],
orewrite_inst(i, "M_shld_8", "", dpos) ["mov", r"^ax,word ptr"],
]
s3 = [
["mov", r"^ax,word ptr"],
["mov", r"^dx,word ptr"],
]
dpos1 = omatch(i-1, -3, s1)
dpos2 = omatch(i+1, 2, s2)
dpos3 = omatch(i+1, 2, s3)
if dpos1 and (dpos2 or dos3):
bp_dx, bp_ax = dpos1[-1][2].group(1), dpos1[-2][2].group(1)
m = "M_shld_8_bp %s %s" % (bp_dx, bp_ax)
orewrite_inst(i, m, "", dpos1)
continue
s1 = [
["mov", r"^word ptr \[bp([+-]\d+)\],si$"],
["mov", r"^word ptr \[bp([+-]\d+)\],di$"],
["mov", r"^c[lx],0xb$"],
["shr", r"^word ptr \[bp([+-]\d+)\],1$"],
["rcr", r"^word ptr \[bp([+-]\d+)\],1$"],
]
s2 = [
["mov", r"^bx,word ptr"],
["mov", r"^bx,word ptr"],
["mov", r"^ax,word ptr \[bp([+-]\d+)\]$"],
["mov", r"^dx,word ptr \[bp([+-]\d+)\]$"],
]
dpos1 = omatch(i-1, -5, s1)
dpos2 = omatch(i+1, 4, s2)
if dpos1 and dpos2:
bp_dx, bp_ax = dpos1[-2][2].group(1), dpos1[-1][2].group(1)
bp_di, bp_si = dpos1[-4][2].group(1), dpos1[-5][2].group(1)
assert bp_dx == dpos2[-1][2].group(1)
assert bp_ax == dpos2[-2][2].group(1)
assert bp_dx == bp_di
assert bp_ax == bp_si
m = "M_shrd_11_disi_bp %s %s" % (bp_dx, bp_ax)
orewrite_inst(i, m, "", dpos1 + dpos2[-2:])
continue continue
# #
if inst in [ if inst in [
@@ -241,11 +331,11 @@ def main(argv):
if opts.auto_inline and inst == "call": if opts.auto_inline and inst == "call":
v = labels[args_label] v = labels[args_label]
if v[:2] == [1, 2]: # external 2-byte if v[:2] == [1, 2]: # external 2-byte
if v[3] == 1: # only one call
x = inline_map.get(v[2]) x = inline_map.get(v[2])
if x and v[3] <= x[1]: # max. number of calls
##print "inline", v, x ##print "inline", v, x
if x: if x:
olines[i][1] = x olines[i][1] = x[0]
olines[i][2] = "/* inlined */" olines[i][2] = "/* inlined */"
olines[i][2] = "" olines[i][2] = ""
olines[i][3] = None olines[i][3] = None
+104 -19
View File
@@ -52,16 +52,29 @@
// umul32: dx:ax = dx:ax * 00:bx // umul32: dx:ax = dx:ax * 00:bx
.macro M_LMUL_dxax_00bx .macro M_LMUL_dxax_00bx
// mult high-word // mult high-word
mov cx, ax // cx: save ax mov cx, ax // save ax
mov ax, dx mov ax, dx
mul bx mul bx
xchg ax, cx // save high-word result, get orig ax xchg ax, cx // save high-word result, get saved ax
// mult low-word // mult low-word
mul bx // dx:ax := ax * bx mul bx // dx:ax := ax * bx
// add high-word // add high-word
add dx, cx // add high-word result add dx, cx // add high-word result
.endm .endm
// umul32: dx:ax = dx:ax * word ptr [bx]
.macro M_LMUL_dxax_00bx_ptr
// mult high-word
mov cx, ax // save ax
mov ax, dx
mul word ptr [bx]
xchg ax, cx // save high-word result, get saved ax
// mult low-word
mul word ptr [bx]
// add high-word
add dx, cx // add high-word result
.endm
// umul32: dx:ax = ax:cx * 00:bx // umul32: dx:ax = ax:cx * 00:bx
.macro M_LMUL_axcx_00bx .macro M_LMUL_axcx_00bx
@@ -81,13 +94,20 @@
mov dl, ah mov dl, ah
mov ah, al mov ah, al
xor al, al xor al, al
//xor cx, cx // FIXME - do we need this ? .endm
.macro M_shld_8_bp h l
mov dx, word ptr[bp+h]
mov ax, word ptr[bp+l]
M_shld_8
mov word ptr[bp+h], dx
mov word ptr[bp+l], ax
.endm .endm
// shld: dx:ax >>= 11 // shld: dx:ax >>= 11
.macro M_shrd_11 .macro M_shrd_11
#if 1 #if 0
mov al, ah mov al, ah
mov ah, dl mov ah, dl
mov dl, dh mov dl, dh
@@ -99,33 +119,69 @@
shr dx shr dx
rcr ax rcr ax
#else #else
mov bx, dx // WARNING: this trashes "bx" !
mov cl, 11 mov cl, 11
shr dx, cl mov bx, dx // save dx
shr ax, cl shr ax, cl
mov cl, 5 shr dx, cl
mov cl, 5 // cl = 16 - cl
shl bx, cl shl bx, cl
or ax, bx or ax, bx
#endif #endif
//xor cx, cx // FIXME - do we need this ? .endm
.macro M_shrd_11_bp h l
mov dx, word ptr[bp+h]
mov ax, word ptr[bp+l]
M_shrd_11
mov word ptr[bp+h], dx
mov word ptr[bp+l], ax
.endm
.macro M_shrd_11_disi_bp h l
mov dx, di
mov ax, si
M_shrd_11
mov word ptr[bp+h], dx
mov word ptr[bp+l], ax
.endm .endm
#if 0 // shld: dx:ax <<= cl; trashes cl and register "r1" (bx, di, si or bp)
// shld: dx:ax <<= cl; trashes register "r1" (bx, di, si or bp) // REQUIRED: 0 <= cl <= 15
// REQUIRED: 0 <= cl < 32 .macro M_shld_00_15 r1
// FIXME - this does not work yet
.macro M_shld r1
local L1
mov r1, ax // save ax mov r1, ax // save ax
shl dx, cl shl dx, cl
shl ax, cl shl ax, cl
neg cl sub cl, 16
and cl, 15 // the 8086 uses all eight bits of the shift count neg cl // cl = 16 - cl
shr r1, cl shr r1, cl
or dx, r1 or dx, r1
.endm .endm
#endif
// shld: dx:ax <<= cl; trashes cl
// REQUIRED: 16 <= cl <= 32
.macro M_shld_16_32
sub cl, 16
shr ax, cl
mov dx, ax
xor ax, ax
.endm
// shld: dx:ax <<= cl; trashes cl and register "r1" (bx, di, si or bp)
// REQUIRED: 0 <= cl <= 32
.macro M_shld r1
local L1, L2
cmp cl, 16
jaes L1
// 0 <= cl <= 15
M_shld_00_15 r1
jmps L2
L1:
// 16 <= cl <= 32
M_shld_16_32
L2:
.endm
/************************************************************************* /*************************************************************************
@@ -134,6 +190,36 @@
section LZMA_DEC99 section LZMA_DEC99
.macro M_PIA
M_WCC_PIA
.endm
.macro M_PIA1
#if 1
local L1
inc ax
jnes L1
//add dx, __AHINCR
add dh, __AHINCR >> 8
L1:
#else
add ax, 1
sbb bl, bl
and bl, __AHINCR >> 8
add dh, bl
#endif
.endm
.macro M_PTC
M_WCC_PTC
.endm
.macro M_PTC_JNE l
cmp ax, bx
jnes l
cmp dx, cx
jnes l
.endm
.macro M_PTS
.endm
/************************************************************************* /*************************************************************************
// //
@@ -145,7 +231,7 @@ section LZMA_DEC00
push ds push ds
mov bp, sp mov bp, sp
#if 1 #if 0
// DEBUG - check for enough stack // DEBUG - check for enough stack
lea bx, [bp + lzma_stack_adjust - 256] lea bx, [bp + lzma_stack_adjust - 256]
cmp bp, bx cmp bp, bx
@@ -229,5 +315,4 @@ section LZMA_DEC31
mov es, ax mov es, ax
// vi:ts=4:et // 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
+2 -2
View File
@@ -139,7 +139,7 @@
#define __AHINCR (1 << __AHSHIFT) /* 4096 */ #define __AHINCR (1 << __AHSHIFT) /* 4096 */
#if 0 #if 1
// huge pointer add: dx:ax = dx:ax + cx:bx // huge pointer add: dx:ax = dx:ax + cx:bx
.macro M_WCC_PIA .macro M_WCC_PIA
add ax, bx add ax, bx
@@ -177,7 +177,7 @@
#endif #endif
#if 0 #if 1
// huge pointer compare: set zero and carry flags: dx:ax cmp cx:bx // huge pointer compare: set zero and carry flags: dx:ax cmp cx:bx
.macro M_WCC_PTC .macro M_WCC_PTC
// FIXME: should we normalize the pointers ??? // FIXME: should we normalize the pointers ???
+1 -1
View File
@@ -111,7 +111,7 @@ def main(argv):
olines.append(" call " + f) olines.append(" call " + f)
elif 1: elif 1:
s = m.group(3).strip() s = m.group(3).strip()
s = re.sub("L\$(\d+)", opts.label_prefix + "\g<1>", s) s = re.sub(r"L\$(\d+)", opts.label_prefix + r"\g<1>", s)
olines.append(" " + s) olines.append(" " + s)
else: else:
s = re.split(r"\s+", m.group(1).strip()) s = re.split(r"\s+", m.group(1).strip())
+28 -29
View File
@@ -45,26 +45,26 @@ Idx Name Size VMA LMA File off Algn Flags
40 N2E64K02 0000000b 00000000 00000000 00000290 2**0 CONTENTS, READONLY 40 N2E64K02 0000000b 00000000 00000000 00000290 2**0 CONTENTS, READONLY
41 NRV2EEX9 00000004 00000000 00000000 0000029b 2**0 CONTENTS, READONLY 41 NRV2EEX9 00000004 00000000 00000000 0000029b 2**0 CONTENTS, READONLY
42 LZMA_DEC99 00000000 00000000 00000000 0000029f 2**0 CONTENTS, READONLY 42 LZMA_DEC99 00000000 00000000 00000000 0000029f 2**0 CONTENTS, READONLY
43 LZMA_DEC00 00000043 00000000 00000000 0000029f 2**0 CONTENTS, RELOC, READONLY 43 LZMA_DEC00 0000003b 00000000 00000000 0000029f 2**0 CONTENTS, RELOC, READONLY
44 LZMA_DEC10 00001203 00000000 00000000 000002e2 2**0 CONTENTS, READONLY 44 LZMA_DEC10 000011a4 00000000 00000000 000002da 2**0 CONTENTS, READONLY
45 LZMA_DEC20 00001203 00000000 00000000 000014e5 2**0 CONTENTS, READONLY 45 LZMA_DEC20 000011a4 00000000 00000000 0000147e 2**0 CONTENTS, READONLY
46 LZMA_DEC30 00000006 00000000 00000000 000026e8 2**0 CONTENTS, RELOC, READONLY 46 LZMA_DEC30 00000006 00000000 00000000 00002622 2**0 CONTENTS, RELOC, READONLY
47 LZMA_DEC31 00000007 00000000 00000000 000026ee 2**0 CONTENTS, RELOC, READONLY 47 LZMA_DEC31 00000007 00000000 00000000 00002628 2**0 CONTENTS, RELOC, READONLY
48 EXEMAIN5 00000001 00000000 00000000 000026f5 2**0 CONTENTS, READONLY 48 EXEMAIN5 00000001 00000000 00000000 0000262f 2**0 CONTENTS, READONLY
49 EXEADJUS 00000007 00000000 00000000 000026f6 2**0 CONTENTS, READONLY 49 EXEADJUS 00000007 00000000 00000000 00002630 2**0 CONTENTS, READONLY
50 EXENOADJ 00000002 00000000 00000000 000026fd 2**0 CONTENTS, READONLY 50 EXENOADJ 00000002 00000000 00000000 00002637 2**0 CONTENTS, READONLY
51 EXERELO1 0000001e 00000000 00000000 000026ff 2**0 CONTENTS, RELOC, READONLY 51 EXERELO1 0000001e 00000000 00000000 00002639 2**0 CONTENTS, RELOC, READONLY
52 EXEREL9A 00000012 00000000 00000000 0000271d 2**0 CONTENTS, RELOC, READONLY 52 EXEREL9A 00000012 00000000 00000000 00002657 2**0 CONTENTS, RELOC, READONLY
53 EXERELO2 00000004 00000000 00000000 0000272f 2**0 CONTENTS, READONLY 53 EXERELO2 00000004 00000000 00000000 00002669 2**0 CONTENTS, READONLY
54 EXEREBIG 00000002 00000000 00000000 00002733 2**0 CONTENTS, RELOC, READONLY 54 EXEREBIG 00000002 00000000 00000000 0000266d 2**0 CONTENTS, RELOC, READONLY
55 EXERELO3 00000002 00000000 00000000 00002735 2**0 CONTENTS, RELOC, READONLY 55 EXERELO3 00000002 00000000 00000000 0000266f 2**0 CONTENTS, RELOC, READONLY
56 EXEMAIN8 00000003 00000000 00000000 00002737 2**0 CONTENTS, READONLY 56 EXEMAIN8 00000003 00000000 00000000 00002671 2**0 CONTENTS, READONLY
57 DEVICEEND 00000013 00000000 00000000 0000273a 2**0 CONTENTS, READONLY 57 DEVICEEND 00000013 00000000 00000000 00002674 2**0 CONTENTS, READONLY
58 EXESTACK 00000006 00000000 00000000 0000274d 2**0 CONTENTS, RELOC, READONLY 58 EXESTACK 00000006 00000000 00000000 00002687 2**0 CONTENTS, RELOC, READONLY
59 EXESTASP 00000003 00000000 00000000 00002753 2**0 CONTENTS, RELOC, READONLY 59 EXESTASP 00000003 00000000 00000000 0000268d 2**0 CONTENTS, RELOC, READONLY
60 EXEJUMPF 00000005 00000000 00000000 00002756 2**0 CONTENTS, RELOC, READONLY 60 EXEJUMPF 00000005 00000000 00000000 00002690 2**0 CONTENTS, RELOC, READONLY
61 EXERCSPO 00000004 00000000 00000000 0000275b 2**0 CONTENTS, RELOC, READONLY 61 EXERCSPO 00000004 00000000 00000000 00002695 2**0 CONTENTS, RELOC, READONLY
62 EXERETIP 00000006 00000000 00000000 0000275f 2**0 CONTENTS, RELOC, READONLY 62 EXERETIP 00000006 00000000 00000000 00002699 2**0 CONTENTS, RELOC, READONLY
SYMBOL TABLE: SYMBOL TABLE:
00000000 l d DEVICEENTRY 00000000 DEVICEENTRY 00000000 l d DEVICEENTRY 00000000 DEVICEENTRY
00000000 l d EXEENTRY 00000000 EXEENTRY 00000000 l d EXEENTRY 00000000 EXEENTRY
@@ -255,15 +255,14 @@ OFFSET TYPE VALUE
RELOCATION RECORDS FOR [LZMA_DEC00]: RELOCATION RECORDS FOR [LZMA_DEC00]:
OFFSET TYPE VALUE OFFSET TYPE VALUE
00000005 R_386_16 lzma_stack_adjust 00000005 R_386_16 lzma_stack_adjust
0000000d R_386_16 lzma_stack_adjust 0000000d R_386_16 lzma_u_len_hi
00000015 R_386_16 lzma_u_len_hi 00000011 R_386_16 lzma_u_len
00000019 R_386_16 lzma_u_len 0000001b R_386_16 lzma_c_len_hi
00000023 R_386_16 lzma_c_len_hi 0000001f R_386_16 lzma_c_len
00000027 R_386_16 lzma_c_len 0000002b R_386_16 lzma_properties_hi
00000033 R_386_16 lzma_properties_hi 00000031 R_386_16 lzma_properties
00000039 R_386_16 lzma_properties 00000036 R_386_PC16 LZMA_DEC10
0000003e R_386_PC16 LZMA_DEC10 00000039 R_386_PC16 LZMA_DEC30
00000041 R_386_PC16 LZMA_DEC30
RELOCATION RECORDS FOR [LZMA_DEC30]: RELOCATION RECORDS FOR [LZMA_DEC30]:
OFFSET TYPE VALUE OFFSET TYPE VALUE