diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2023-07-29 13:24:03 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2023-08-02 01:08:29 +0100 |
commit | 472b37fbf06e3588ff8ec9496aef44758ebf1bc3 (patch) | |
tree | 39dc5411507cb967de6a6ee4b99d60e5670a1826 | |
parent | 1e310fa30a1bca4448f47116f5d05037cc2ada1a (diff) |
Fix another x86 case and add regression tests
-rwxr-xr-x | compile | 2 | ||||
-rw-r--r-- | compile.bat | 2 | ||||
-rw-r--r-- | src/x86.c | 2 | ||||
-rw-r--r-- | test/x86.test.c | 41 |
4 files changed, 46 insertions, 1 deletions
@@ -102,5 +102,7 @@ $HOSTCC -O2 -g3 -include test/test.h -o .build/bitbuf.test test/bitbuf.test.c #.build/hook.test $HOSTCC -O2 -g3 -include test/test.h -o .build/kv.test test/kv.test.c .build/kv.test +$HOSTCC -O2 -g3 -include test/test.h -o .build/x86.test test/x86.test.c +.build/x86.test # vi: sw=4 tw=4 noet tw=80 cc=80 diff --git a/compile.bat b/compile.bat index 67b35f4..75ac2fe 100644 --- a/compile.bat +++ b/compile.bat @@ -121,6 +121,8 @@ del .build\sst.lib .build\hook.test.exe || exit /b
%HOSTCC% -O2 -g -include test/test.h -o .build/kv.test.exe test/kv.test.c || exit /b
.build\kv.test.exe || exit /b
+%HOSTCC% -O2 -g -include test/test.h -o .build/x86.test.exe test/x86.test.c || exit /b
+.build\x86.test.exe || exit /b
endlocal
@@ -74,7 +74,7 @@ P: X86_SEG_PREFIXES(CASES) case X86_CRAZY8: operandlen = 1; case X86_CRAZYW: if ((insn[1] & 0x38) >= 0x10) operandlen = 0; - return pfxlen + 2 + operandlen + mrmsib(insn + 1, addrlen); + return pfxlen + 1 + operandlen + mrmsib(insn + 1, addrlen); case X86_2BYTE: ++insn; goto b2; } return -1; diff --git a/test/x86.test.c b/test/x86.test.c new file mode 100644 index 0000000..ab0a679 --- /dev/null +++ b/test/x86.test.c @@ -0,0 +1,41 @@ +/* This file is dedicated to the public domain. */ + +{.desc = "x86 opcode parsing"}; + +#include "../src/x86.c" +#include "../src/intdefs.h" + +TEST("The \"crazy\" instructions should be given correct lengths\n") { + const uchar test8[] = { + 0xF6, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12 + }; + const uchar test16[] = { + 0x66, 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34 + }; + const uchar test32[] = { + 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78 + }; + const uchar not8[] = { + 0xF6, 0x15, 0x12, 0x34, 0x56, 0x78 + }; + const uchar not16[] = { + 0x66, 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78 + }; + const uchar not32[] = { + 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78 + }; + if (x86_len(test8) != 7) return false; + if (x86_len(test16) != 9) return false; + if (x86_len(test32) != 10) return false; + if (x86_len(not8) != 6) return false; + if (x86_len(not16) != 7) return false; + if (x86_len(not32) != 6) return false; + return true; +} + +TEST("SIB bytes should be decoded correctly") { + const uchar fstp[] = {0xD9, 0x1C, 0x24}; // old buggy case, for regressions + return x86_len(fstp) == 3; +} + +// vi: sw=4 ts=4 noet tw=80 cc=80 |