mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Some cleanasm.py updates.
This commit is contained in:
parent
8f68f31877
commit
6f760308bd
|
@ -140,6 +140,8 @@ RTRIM := sed -e 's/[ $(tab)]*$$//'
|
|||
BLSQUEEZE := $(RTRIM) | cat --squeeze-blank | sed -e '1{/^$$/d}' -e '$${/^$$/d}'
|
||||
# delete blank lines
|
||||
BLDEL := $(RTRIM) | sed -e '/^$$/d'
|
||||
#
|
||||
UNIX2DOS := perl -i -pe 's/$$/\r/;'
|
||||
|
||||
# clear some vars, just in case
|
||||
LABEL_PREFIX =
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -120,15 +120,18 @@ define mkbat
|
|||
echo -e '@shift\n@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
|
||||
unix2dos -q $1
|
||||
$(UNIX2DOS) $1
|
||||
endef
|
||||
|
||||
winedir_s = $(shell winepath -s z:$(realpath -f -n $1))
|
||||
winedir_w = $(shell winepath -w $(realpath -f -n $1))
|
||||
|
||||
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)
|
||||
@$(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)
|
||||
@$(call mkbat,$@,dmc.exe,$(shell winepath -w $(DM849DIR)/bin),,)
|
||||
@$(call mkbat,$@,dmc.exe,$(call winedir_w,$(DM849DIR)/bin))
|
||||
|
||||
# Open Watcom C/C++ 1.6
|
||||
# http://openwatcom.com/
|
||||
|
|
|
@ -101,29 +101,37 @@ def main(argv):
|
|||
|
||||
olines = []
|
||||
def omatch(pos, m):
|
||||
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()
|
||||
i = 0
|
||||
dpos = []
|
||||
while i < len(m):
|
||||
if pos < 0 or pos >= len(olines):
|
||||
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 []
|
||||
if o[1].lower() != m[i][1].lower():
|
||||
m0 = match(m[i][0], o[0])
|
||||
m1 = match(m[i][1], o[1])
|
||||
if not m0 or not m1:
|
||||
return []
|
||||
dpos.append([pos, m0, m1])
|
||||
pos += 1
|
||||
i += 1
|
||||
return dpos
|
||||
def orewrite_inst(i, inst, args, dpos):
|
||||
for pos in dpos:
|
||||
for pos, m0, m1 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:
|
||||
for pos, m0, m1 in dpos:
|
||||
olines[pos][1] = "*DEL*"
|
||||
v[2] = k
|
||||
olines[i][2] = None
|
||||
|
@ -187,7 +195,7 @@ def main(argv):
|
|||
continue
|
||||
if opts.loop_rewrite and inst in ["loop"]:
|
||||
s = [
|
||||
["mov", "cx,0xb"],
|
||||
["mov", r"^c[lx],0xb$"],
|
||||
["shr", "dx,1"],
|
||||
["rcr", "ax,1"],
|
||||
]
|
||||
|
@ -196,7 +204,7 @@ def main(argv):
|
|||
orewrite_inst(i, "M_shrd_11", "", dpos)
|
||||
continue
|
||||
s = [
|
||||
["mov", "cl,0x8"],
|
||||
["mov", r"^c[lx],0x8$"],
|
||||
["shl", "ax,1"],
|
||||
["rcl", "dx,1"],
|
||||
]
|
||||
|
@ -204,14 +212,25 @@ def main(argv):
|
|||
if dpos:
|
||||
orewrite_inst(i, "M_shld_8", "", dpos)
|
||||
continue
|
||||
s = [
|
||||
["mov", "cx,0x8"],
|
||||
["shl", "ax,1"],
|
||||
["rcl", "dx,1"],
|
||||
s1 = [
|
||||
["mov", r"^c[lx],0x8$"],
|
||||
["shl", r"^word ptr \[bp([+-]\d+)\],1$"],
|
||||
["rcl", r"^word ptr \[bp([+-]\d+)\],1$"],
|
||||
]
|
||||
dpos = omatch(i - 3, s[-3:])
|
||||
if dpos:
|
||||
orewrite_inst(i, "M_shld_8", "", dpos)
|
||||
s2 = [
|
||||
["mov", r"^dx,word ptr"],
|
||||
["mov", r"^ax,word ptr"],
|
||||
]
|
||||
s3 = [
|
||||
["mov", r"^ax,word ptr"],
|
||||
["mov", r"^dx,word ptr"],
|
||||
]
|
||||
dpos1 = omatch(i - 3, s1[-3:])
|
||||
dpos2 = omatch(i + 1, s2)
|
||||
dpos3 = omatch(i + 1, s3)
|
||||
if dpos1 and (dpos2 or dos3):
|
||||
m = "M_shld_8_bp %s %s" % (dpos1[-2][2].group(1), dpos1[-1][2].group(1))
|
||||
orewrite_inst(i, m, "", dpos1)
|
||||
continue
|
||||
#
|
||||
if inst in [
|
||||
|
|
|
@ -52,14 +52,15 @@
|
|||
// umul32: dx:ax = dx:ax * 00:bx
|
||||
.macro M_LMUL_dxax_00bx
|
||||
// mult high-word
|
||||
mov cx, ax // cx: save ax
|
||||
mov cx, ax // save ax
|
||||
mov ax, dx
|
||||
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
|
||||
mul bx // dx:ax := ax * bx
|
||||
// add high-word
|
||||
add dx, cx // add high-word result
|
||||
//xor cx, cx // FIXME - do we need this ?
|
||||
.endm
|
||||
|
||||
|
||||
|
@ -72,6 +73,7 @@
|
|||
mul bx
|
||||
// add high-word
|
||||
add dx, cx // add high-word result
|
||||
//xor cx, cx // FIXME - do we need this ?
|
||||
.endm
|
||||
|
||||
|
||||
|
@ -84,6 +86,17 @@
|
|||
//xor cx, cx // FIXME - do we need this ?
|
||||
.endm
|
||||
|
||||
.macro M_shld_8_bp l h
|
||||
mov dx, word ptr[bp+h]
|
||||
mov ax, word ptr[bp+l]
|
||||
mov dh, dl
|
||||
mov dl, ah
|
||||
mov ah, al
|
||||
xor al, al
|
||||
mov word ptr[bp+h], dx
|
||||
mov word ptr[bp+l], ax
|
||||
.endm
|
||||
|
||||
|
||||
// shld: dx:ax >>= 11
|
||||
.macro M_shrd_11
|
||||
|
@ -99,11 +112,11 @@
|
|||
shr dx
|
||||
rcr ax
|
||||
#else
|
||||
mov bx, dx
|
||||
mov cl, 11
|
||||
shr dx, cl
|
||||
mov bx, dx // save dx
|
||||
shr ax, cl
|
||||
mov cl, 5
|
||||
shr dx, cl
|
||||
mov cl, 5 // cl = 16 - cl
|
||||
shl bx, cl
|
||||
or ax, bx
|
||||
#endif
|
||||
|
@ -111,21 +124,41 @@
|
|||
.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
|
||||
.macro M_shld r1
|
||||
local L1
|
||||
// shld: dx:ax <<= cl; trashes cl and register "r1" (bx, di, si or bp)
|
||||
// REQUIRED: 0 <= cl <= 15
|
||||
.macro M_shld_00_15 r1
|
||||
mov r1, ax // save ax
|
||||
shl dx, cl
|
||||
shl ax, cl
|
||||
neg cl
|
||||
and cl, 15 // the 8086 uses all eight bits of the shift count
|
||||
sub cl, 16
|
||||
neg cl // cl = 16 - cl
|
||||
shr r1, cl
|
||||
or dx, r1
|
||||
.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
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -111,7 +111,7 @@ def main(argv):
|
|||
olines.append(" call " + f)
|
||||
elif 1:
|
||||
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)
|
||||
else:
|
||||
s = re.split(r"\s+", m.group(1).strip())
|
||||
|
|
|
@ -46,25 +46,25 @@ Idx Name Size VMA LMA File off Algn Flags
|
|||
41 NRV2EEX9 00000004 00000000 00000000 0000029b 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
|
||||
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
|
||||
44 LZMA_DEC10 00001289 00000000 00000000 000002e2 2**0 CONTENTS, READONLY
|
||||
45 LZMA_DEC20 00001289 00000000 00000000 0000156b 2**0 CONTENTS, READONLY
|
||||
46 LZMA_DEC30 00000006 00000000 00000000 000027f4 2**0 CONTENTS, RELOC, READONLY
|
||||
47 LZMA_DEC31 00000007 00000000 00000000 000027fa 2**0 CONTENTS, RELOC, READONLY
|
||||
48 EXEMAIN5 00000001 00000000 00000000 00002801 2**0 CONTENTS, READONLY
|
||||
49 EXEADJUS 00000007 00000000 00000000 00002802 2**0 CONTENTS, READONLY
|
||||
50 EXENOADJ 00000002 00000000 00000000 00002809 2**0 CONTENTS, READONLY
|
||||
51 EXERELO1 0000001e 00000000 00000000 0000280b 2**0 CONTENTS, RELOC, READONLY
|
||||
52 EXEREL9A 00000012 00000000 00000000 00002829 2**0 CONTENTS, RELOC, READONLY
|
||||
53 EXERELO2 00000004 00000000 00000000 0000283b 2**0 CONTENTS, READONLY
|
||||
54 EXEREBIG 00000002 00000000 00000000 0000283f 2**0 CONTENTS, RELOC, READONLY
|
||||
55 EXERELO3 00000002 00000000 00000000 00002841 2**0 CONTENTS, RELOC, READONLY
|
||||
56 EXEMAIN8 00000003 00000000 00000000 00002843 2**0 CONTENTS, READONLY
|
||||
57 DEVICEEND 00000013 00000000 00000000 00002846 2**0 CONTENTS, READONLY
|
||||
58 EXESTACK 00000006 00000000 00000000 00002859 2**0 CONTENTS, RELOC, READONLY
|
||||
59 EXESTASP 00000003 00000000 00000000 0000285f 2**0 CONTENTS, RELOC, READONLY
|
||||
60 EXEJUMPF 00000005 00000000 00000000 00002862 2**0 CONTENTS, RELOC, READONLY
|
||||
61 EXERCSPO 00000004 00000000 00000000 00002867 2**0 CONTENTS, RELOC, READONLY
|
||||
62 EXERETIP 00000006 00000000 00000000 0000286b 2**0 CONTENTS, RELOC, READONLY
|
||||
SYMBOL TABLE:
|
||||
00000000 l d DEVICEENTRY 00000000 DEVICEENTRY
|
||||
00000000 l d EXEENTRY 00000000 EXEENTRY
|
||||
|
|
Loading…
Reference in New Issue
Block a user