Skip to content

Commit

Permalink
Merge branch 'master' into avx
Browse files Browse the repository at this point in the history
Conflicts:
	scripts/Makefile.am
  • Loading branch information
vmt committed Jun 29, 2013
2 parents 571b354 + a0c16cc commit 30d28dc
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ udcli/udcli
tests/_results/
tests/*.bin
tests/*.out
tests/difftest.sh
scripts/ud_asmtest*

# Ignore C++ Builder history folders
libudis86/__history/
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ AC_CONFIG_FILES([
docs/Makefile
docs/manual/Makefile
docs/x86/Makefile
tests/difftest.sh
])

AC_OUTPUT
1 change: 1 addition & 0 deletions docs/x86/optable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,7 @@
<def>
<opc>eb</opc>
<opr>Jb</opr>
<mode>def64</mode>
</def>
</instruction>

Expand Down
9 changes: 6 additions & 3 deletions libudis86/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ static int decode_ext(struct ud *u, uint16_t ptr);
static int decode_opcode(struct ud *u);

enum reg_class { /* register classes */
REGCLASS_NONE,
REGCLASS_GPR,
REGCLASS_MMX,
REGCLASS_CR,
Expand Down Expand Up @@ -362,9 +361,13 @@ decode_gpr(register struct ud* u, unsigned int s, unsigned char rm)
return UD_R_SPL + (rm-4);
return UD_R_AL + rm;
} else return UD_R_AL + rm;
case 0:
/* invalid size in case of a decode error */
UD_ASSERT(u->error);
return UD_NONE;
default:
UD_ASSERT(!"invalid operand size");
return 0;
return UD_NONE;
}
}

Expand Down Expand Up @@ -400,7 +403,7 @@ decode_reg(struct ud *u,
}
default:
UD_ASSERT(!"invalid register type");
break;
return;
}
opr->type = UD_OP_REG;
opr->base = reg;
Expand Down
2 changes: 1 addition & 1 deletion libudis86/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern const struct ud_operand* ud_insn_opr(const struct ud *u, unsigned int n);

extern int ud_opr_is_sreg(const struct ud_operand *opr);

extern int ud_opr_isgpr(const struct ud_operand *opr);
extern int ud_opr_is_gpr(const struct ud_operand *opr);

extern const char* ud_lookup_mnemonic(enum ud_mnemonic_code c);

Expand Down
1 change: 1 addition & 0 deletions libudis86/syn-att.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ gen_operand(struct ud* u, struct ud_operand* op)
break;

case UD_OP_IMM:
ud_asmprintf(u, "$");
ud_syn_print_imm(u, op);
break;

Expand Down
3 changes: 2 additions & 1 deletion libudis86/syn.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ ud_syn_rel_target(struct ud *u, struct ud_operand *opr)
case 16: return (u->pc + opr->lval.sword) & trunc_mask;
case 32: return (u->pc + opr->lval.sdword) & trunc_mask;
default: UD_ASSERT(!"invalid relative offset size.");
return 0ull;
}
}

Expand All @@ -109,7 +110,7 @@ ud_syn_rel_target(struct ud *u, struct ud_operand *opr)
* returns a negative number and truncates the output.
*/
int
ud_asmprintf(struct ud *u, char *fmt, ...)
ud_asmprintf(struct ud *u, const char *fmt, ...)
{
int ret;
int avail;
Expand Down
4 changes: 2 additions & 2 deletions libudis86/syn.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ extern const char* ud_reg_tab[];
uint64_t ud_syn_rel_target(struct ud*, struct ud_operand*);

#ifdef __GNUC__
int ud_asmprintf(struct ud *u, char *fmt, ...)
int ud_asmprintf(struct ud *u, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
#else
int ud_asmprintf(struct ud *u, char *fmt, ...);
int ud_asmprintf(struct ud *u, const char *fmt, ...);
#endif

void ud_syn_print_addr(struct ud *u, uint64_t addr);
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ MAINTAINERCLEANFILES = Makefile.in

clean-local:
-rm -f *.pyc
-rm -f ud_yasmtest*
-rm -f ud_asmtest*
72 changes: 11 additions & 61 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ symresolve_CFLAGS = -I$(top_srcdir)/libudis86 -I$(top_srcdir)

MAINTAINERCLEANFILES = Makefile.in

DISTCLEANFILES = difftest.sh

YASM = @YASM@
PYTHON = @PYTHON@
TESTDIS = $(top_builddir)/udcli/udcli
Expand All @@ -26,7 +28,7 @@ EXTRA_DIST = \
$(srcdir)/installcheck.c

if HAVE_YASM
tests: diff-test test-buf-overrun test-sym-resolver
tests: difftest test-buf-overrun test-sym-resolver
else
tests: warn_no_yasm test-buf-overrun test-sym-resolver
endif
Expand Down Expand Up @@ -62,66 +64,14 @@ oprtest: oprgen.py
@$(call oprtest_generate,16)


diff_test_asm = \
for mode in 16 32 64; do \
for vendor in amd intel any; do \
if [ "$${vendor}" == "any" ]; then \
vendor_opt=""; \
asmdir=$(srcdir)/asm/$${mode}; \
outdir=$(abs_builddir)/_results/asm/$${mode}; \
else \
vendor_opt="-v $${vendor}"; \
asmdir=$(srcdir)/asm/$${mode}/$${vendor}; \
outdir=$(builddir)/_results/asm/$${mode}/$${vendor}; \
fi; \
if [ ! -d "$${asmdir}" ]; then \
continue; \
fi; \
mkdir -p $${outdir} && \
for a in `find $${asmdir} -maxdepth 1 -name "*.asm"` \
`find $${outdir} -maxdepth 1 -name "*.asm"`; do \
srcasm=$$a && outasm=$${outdir}/$$(basename $$a) && \
$(YASM) -f bin $${srcasm} -o $${outasm}.bin && \
if [ "x$(1)" == "xrefup" ]; then \
if [ -f "$${srcasm}.ref" ]; then \
echo "REFUP $${outasm}.out -> $${srcasm}.ref" && \
$(TESTDIS) $${vendor_opt} -$${mode} $${outasm}.bin > $${outasm}.out && \
cp $${outasm}.out $${srcasm}.ref; \
fi; \
if [ -f "$${srcasm}.Sref" ]; then \
echo "REFUP $${outasm}.out -> $${srcasm}.Sref" && \
$(TESTDIS) $${vendor_opt} -att -$${mode} $${outasm}.bin > $${outasm}.out && \
cp $${outasm}.out $${srcasm}.Sref; \
fi; \
else \
if [ ! -f "$${srcasm}.ref" ]; then \
echo "[bits $${mode}]" > $${outasm}.out && \
$(TESTDIS) $${vendor_opt} -$${mode} -noff -nohex $${outasm}.bin >> $${outasm}.out && \
diff -w $${srcasm} $${outasm}.out 2>&1 > $${outasm}.diff.log; \
else \
$(TESTDIS) $${vendor_opt} -$${mode} $${outasm}.bin > $${outasm}.out && \
diff -w $${srcasm}.ref $${outasm}.out 2>&1 > $${outasm}.diff.log; \
fi && \
if [ -f "$${srcasm}.Sref" ]; then \
$(TESTDIS) $${vendor_opt} -att -$${mode} $${outasm}.bin > $${outasm}.out && \
diff -w $${srcasm}.Sref $${outasm}.out 2>&1 > $${outasm}.diff.log; \
fi && \
echo "DIFFTEST $${srcasm}: PASS" || \
echo "DIFFTEST $${srcasm}: ***FAIL*** ($${outasm}.diff.log)"; \
fi; \
done \
done \
done


.PHONY: diff-test
diff-test: oprtest
@$(call diff_test_asm,"diff")


.PHONY: diff-test-refup
diff-test-refup:
@$(call diff_test_asm,"refup")
.PHONY: difftest
difftest: oprtest $(builddir)/difftest.sh
@sh $(builddir)/difftest.sh


.PHONY: difftest-refup
difftest-refup: $(builddir)/difftest.sh
@sh $(builddir)/difftest.sh refup


.PHONY: warn_no_yasm
Expand Down
3 changes: 3 additions & 0 deletions tests/asm/32/att.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[bits 32]
mov eax, 0x1234
mov eax, [0x1234]
2 changes: 2 additions & 0 deletions tests/asm/32/att.asm.Sref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000 b834120000 mov $0x1234, %eax
0000000000000005 a134120000 mov 0x1234, %eax
2 changes: 2 additions & 0 deletions tests/asm/32/att.asm.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000 b834120000 mov eax, 0x1234
0000000000000005 a134120000 mov eax, [0x1234]
24 changes: 24 additions & 0 deletions tests/asm/32/reljmp.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[bits 32]
[org 0x80000000]

l1:
nop
nop
nop
nop
nop

jmp l1
nop
jmp word l2

nop
nop
jmp dword l2
nop
nop
nop
l2:
nop
nop
jmp l1
17 changes: 17 additions & 0 deletions tests/asm/32/reljmp.asm.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
0000000080000000 90 nop
0000000080000001 90 nop
0000000080000002 90 nop
0000000080000003 90 nop
0000000080000004 90 nop
0000000080000005 ebf9 jmp 0x80000000
0000000080000007 90 nop
0000000080000008 66e90a00 jmp 0x16
000000008000000c 90 nop
000000008000000d 90 nop
000000008000000e e903000000 jmp 0x80000016
0000000080000013 90 nop
0000000080000014 90 nop
0000000080000015 90 nop
0000000080000016 90 nop
0000000080000017 90 nop
0000000080000018 ebe6 jmp 0x80000000
24 changes: 24 additions & 0 deletions tests/asm/64/reljmp.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[bits 64]
[org 0x8000000000000000]

l1:
nop
nop
nop
nop
nop

jmp l1
nop
jmp word l2

nop
nop
jmp dword l2
nop
nop
nop
l2:
nop
nop
jmp l1
17 changes: 17 additions & 0 deletions tests/asm/64/reljmp.asm.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
8000000000000000 90 nop
8000000000000001 90 nop
8000000000000002 90 nop
8000000000000003 90 nop
8000000000000004 90 nop
8000000000000005 ebf9 jmp 0x8000000000000000
8000000000000007 90 nop
8000000000000008 66e90a00 jmp 0x16
800000000000000c 90 nop
800000000000000d 90 nop
800000000000000e e903000000 jmp 0x8000000000000016
8000000000000013 90 nop
8000000000000014 90 nop
8000000000000015 90 nop
8000000000000016 90 nop
8000000000000017 90 nop
8000000000000018 ebe6 jmp 0x8000000000000000
Loading

0 comments on commit 30d28dc

Please sign in to comment.