Commit Graph

138 Commits

Author SHA1 Message Date
Cyrill Gorcunov
dcc2cbce8d disasm: Drop unused variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 01:16:09 +03:00
Cyrill Gorcunov
a2a2d19f43 disasm: Fix disassembling of evex prefix
As been pointed by @hpa evex is pretty fine in ia-32.

Quoting Peter

 | This is wrong, though; EVEX is permitted in 32-bit mode just as VEX is.
 | The key thing is that bits [7:5] have to be 1 in 32-bit mode.  It is
 | unclear what happens if these bits are 110 as that depends on if it is
 | decoded using the modr/m decoder or not.  For VEX prefixes we accept
 | them as VEX in that case, which may not match the CPU.

This is a fix for commit db6ecf9b76

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 01:14:45 +03:00
Mark Scott
db6ecf9b76 disasm: Fix for disassembly of BOUND
The opcode for BOUND, 62h, has a different meaning in long mode - it is the
prefix for EVEX instructions. ndisasm did not take this into account and always
tried to disassemble 62h back to an EVEX instruction.

Attached patch only permits EVEX disassembly if bitness is 64.
In 16/32 bit mode 62h will be not be a prefix and so disassemble
to BOUND.

Signed-off-by: Mark Scott <nasm@mscott.cx>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-03 23:09:05 +03:00
Cyrill Gorcunov
b0b969eec4 disasm: Fix segment prefix name
http://bugzilla.nasm.us/show_bug.cgi?id=3392322

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-09-13 17:16:06 +03:00
Cyrill Gorcunov
1006a47fe8 disasm: Add explicit type conversion to placate compiler
Otherwise getting

 | disasm.c:200:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 |         return GET_REGISTER(nasm_rd_bndreg, regval);

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-12-20 11:40:36 +03:00
Cyrill Gorcunov
9b05974022 ndisasm: Prevent nil dereference on registerd decoding
The sequence | 0x0F 0x1B 0x75 | get matched into
one of BNDx instruction which register value 6
which is of course out of possible BND registers
implemented in hardware at the moment leading to
nil dereference.

Instead lets use a macro in whichreg() helper
which would test the registers bounds and force
the caller to try another template if register is
out of range. In the case above it simply means
ndisasm instead of crashing outputs

 | 00000000  0F                db 0x0f
 | 00000001  1B                db 0x1b
 | 00000002  75                db 0x75

http://bugzilla.nasm.us/show_bug.cgi?id=3392289

Reported-by: Hanno Boeck <hanno@hboeck.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-12-14 22:44:54 +03:00
Cyrill Gorcunov
1cccb1e8d5 disasm: matches -- Use proper return type
matches() declared as int and better return explicit
zero here instead of @false.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-12-14 10:57:53 +03:00
Jin Kyu Song
abdc8bdea2 ndisasm: Match vector length with EVEX.b set
With broadcasting, EVEX.L'L should be matched even when EVEX.b is set.
Only in a case of embedded rounding, EVEX.L'L is ignored in matching
function since it becomes EVEX.RC.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2014-05-05 13:58:51 -07:00
H. Peter Anvin
3143a462c2 disasm: Don't rely on iflag_cmp() returning +/-1
It is safer to just rely on the sign, for future options.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-11-27 13:43:45 -08:00
Cyrill Gorcunov
0835915c1d iflag: Start using new instruction flags engine
Here we start using instruction flags generator.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-11-24 13:20:59 +04:00
Jin Kyu Song
5f3bfee708 disp8: Consolidate a logic to get compressed displacement
Consolidated two separate but similar functions in nasm and ndisasm
into a commonly linked source code.
To encode and decode the compressed displacement (disp8*N) for EVEX,
N value should be derived using various conditions.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 15:40:55 -08:00
Jin Kyu Song
28d5bf811b disasm: Add suport for bnd registers
MPX uses a new bnd registers and a new mib syntax.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
5f80dace3a disasm: Add EVEX decorator syntax
Broadcasting, opmask, embedded rounding and SAE decorators
are not added at proper position.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
6076e8f335 disasm: Add ZMM vsib
ZMM registers can be used for vsib index and the number of registers
has been increased to 32.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
6b29602bf4 disasm: Support EVEX compressed displacement
When tuple type is indicated in the bytecode, disp8 is
treated as a compressed disp and gets calculated back to disp8*N.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
4a8dc019ef disasm: Add basic AVX512 support
Disassembler can translate EVEX prefix, count up to 32 vector registers
and recognize new ZMM / opmask registers.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
9e59ace66c disasm: style cleanup
Fix indentation.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
b4e1ae18e2 MPX: Move BND prefix indication from bytecode to iflags
As BND prefix validity check conflicts with jcc8 prefix,
IF_BND is added for the instruction templates which can have
bnd prefix for preserving the content of bound register.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
0304109b3d MPX: Add BND prefix for branch instructions
BND prefix is used for adding bounds checking protection
across flow control changes such as call, ret, jmp and jcc calls.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
H. Peter Anvin
0bc288f8b9 disasm: add support for emitting split EA format
Add support for emitting split EA format in the disassembler,
indicated by the MIB instruction flag.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:41 -08:00
Jin Kyu Song
9bb987d8e0 AVX-512: Change the data type for instruction flags
Increased the size of data type for instruction flags from 32bits to 64bits.
And a new type (iflags_t) is defined for better maintainability.

Bigger data type is needed because more instruction set types are coming
but there were not enough space for them. Since they are not bit masks,
only one instruction set is allowed for each instruction.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-28 09:37:21 +04:00
Jin Kyu Song
d4760c19b5 AVX-512: Add ZWORD keyword
ZWORD (512 bits) keyword is added

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-22 19:37:44 +04:00
Jin Kyu Song
cc1dc9de53 AVX-512: Add EVEX encoding and new instructions
EVEX encoding support includes 32 vector regs (XMM/YMM/ZMM),
opmask, broadcasting, embedded rounding mode,
suppress all exceptions, compressed displacement.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-16 09:06:15 +04:00
Ben Rudiak-Gould
94ba02fa16 Make F2 and F3 SSE prefixes override 66
According to XED and experimentation, the 66 is ignored.

Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-10 21:46:12 +04:00
Ben Rudiak-Gould
6e87893f06 Drop SAME_AS flag from instruction matcher
It was there to support the SSE5 DREX encoding,
which as far as I know is dead forever.

Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-04 00:46:16 +04:00
Ben Rudiak-Gould
d1ac29a3cc insns: Remove pushseg/popseg internal bytecodes
This patch is getting rid of the following bytecodes
'pushseg','popseg','pushseg2','popseg2' and simplifies
overall code.

[gorcunov@: a few style fixes]
Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-03 20:50:46 +04:00
Ben Rudiak-Gould
4e8396b5cf Remove +s
It doesn't seem worth >200 lines of C and Perl to save ~50 lines in insns.dat.

In order to make this work I had to rename sbyte16/sbyte32 so that
they can take an ordinary size suffix (their size suffix was formerly
treated specially).

This fixes one disassembly bug: 48C7C000000080 disassembles to mov
rax,0x80000000, which reassembles to B800000080, which loads a
different value.

Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Acked-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-01 10:28:32 +04:00
Ben Rudiak-Gould
bf0f42390d Fix jmp/call near offsets in long mode
In long mode relative offsets are always 32 bits sign-extended to 64
bits and absolute near addresses are always 64 bits, regardless of the
operand size.

Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-02-20 23:25:59 +04:00
Ben Rudiak-Gould
d7ab1f9638 Add np and similar prefixes to instructions that should have them
This adds "np" to a bunch of SSE-style instructions that should have
it, "norep" (which was implemented but unused) on quasi-SSE instructions
that use F2 and F3 as instruction extensions but 66 for operand size,
"nof3" (newly implemented) on a few instructions, "norexw" on some
instructions that have only 32-bit and 64-bit versions, and one NOLONG.

It also removes some incorrect "np"s, changes some "f3"s to "f3i"s,
and fixes the decoding of the XCHG/NOP/PAUSE mess: F390 is always
PAUSE even when rex.b=1 (at least according to XED).

Signed-off-by: Ben Rudiak-Gould <benrudiak@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-02-20 23:25:54 +04:00
H. Peter Anvin
574784d177 HLE: Move byte codes back to \271-\273
Since we are back to three bytecodes, move them back to the \271-\273
slot to free up the \264 complete quad.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 22:33:46 -08:00
H. Peter Anvin
fb3f4e6ddb HLE: Change NOHLE to be an instruction flag
The way our matching system works we have to make NOHLE an instruction
flag rather than an byte code; by the time we run the byte code
interpreter we have already picked an instruction pattern once and for
all.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 22:22:07 -08:00
H. Peter Anvin
9898c80cb1 disasm: ignore opcodes 370 and 371 2012-02-25 11:46:56 -08:00
H. Peter Anvin
8ea2200415 Move HLE byte codes to \264..\267
Move the HLE byte codes to \264..\267 so as not to break up an unused
group of 8 (\240..\247).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 10:24:24 -08:00
H. Peter Anvin
7849dd07b9 Add a "nohle" byte code to skip an instruction pattern
The a2/a3 mem_offs MOV opcodes are invalid with XRELEASE; those
instructions instead have to use a modrm form.  Therefore give a way
to annotate those instruction patters so the pattern matcher will move
on to the next pattern, rather than selecting them and then issue a
warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 10:19:56 -08:00
H. Peter Anvin
4ecd5d79fc HLE: Implement the basic mechanism for XACQUIRE/XRELEASE
This implements the mechanism for XACQUIRE/XRELEASE.  It does not
include the necessary annotations in insns.dat.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-24 21:57:17 -08:00
H. Peter Anvin
10da41e328 HLE: Split the LOCK and REP prefix slots
With HLE, the sequence REP LOCK actually makes sense, so support it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-24 20:57:04 -08:00
H. Peter Anvin
57078f061d disasm.c: ESP/RSP cannot be indicies, but XMM4/YMM4 can be
If we have XMM4/YMM4 as a VSIB, it does not mean no index; that is
only for scalar encoding.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-08-22 14:09:04 -07:00
H. Peter Anvin
cffe61e776 Use a normal quad-case for valueless /is4
When we don't have an immediate for the i-field in /is4, then use a
normal quad-bytecode encoding for it to save some small amount of
space and re-use existing machinery.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-07-07 17:21:24 -07:00
H. Peter Anvin
fc561203fd Remove support for DREX encoding
The DREX encoding never hit production silicon, and has been replaced
by VEX/XOP encoding, so remove support for it.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-07-07 16:58:22 -07:00
H. Peter Anvin
3089f7ef8a Add support for VSIB instructions
Add support for VSIB instructions, which use vector registers as the
index registers in an EA.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-06-22 18:19:28 -07:00
Cyrill Gorcunov
9e1c9ce8e9 BR3064376: ndisasm crash
ndisasm may crash due to lack of check of VEX table index.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-09-12 13:37:53 +04:00
H. Peter Anvin
5d62e57a0c ndisasm: handle VEX.LIG
A lot of instructions ignore the L bit in the VEX prefix, just like
a lot of instructions ignore the W bit, so don't use them in the
sub-table select.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-19 17:04:36 -07:00
H. Peter Anvin
23f0b16c21 ndisasm: unify VEX handling
Unify VEX handling between the 026x and 0270 bytecodes.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-19 16:59:35 -07:00
H. Peter Anvin
7023d638de ndisasm: fix handing of byte codes 250-253, 324
Fix handling of byte codes 250-253 (sign-extended 32-bit immediate,
extended to 64 bits) and 324 (instruction must have osize 64).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-08-16 22:13:14 -07:00
H. Peter Anvin
421059c689 assemble: handle vex.lig
AVX version 7 introduces the concept of .lig, meaning VEX.L is
ignored.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-16 14:56:33 -07:00
Cyrill Gorcunov
e4f526be5c continue using is_class helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-18 12:41:14 +04:00
H. Peter Anvin
f8563f7a98 opflags: more int32_t -> opflags_t conversions
Hopefully this should catch all of them... but please keep an eye out
for any other uses of int32_t for the operand flags.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-10-13 12:29:01 -07:00
Cyrill Gorcunov
0a45cc8ce8 disasm.c: eatbyte -- use snprintf to prevent potential buffer overflow
At moment we can't overrun buffer even if we would like to
but better to stay on a safe side and use snprintf.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-08-09 10:30:48 -07:00
H. Peter Anvin
8ee2e244eb NASM: relicense under the 2-clause BSD license
*To the best of my knowledge*, we now have authorization from everyone
who has significantly contributed to NASM in the past.  As such,
change the license to the 2-clause BSD license.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 11:09:11 -07:00
H. Peter Anvin
9e6747ccac Add copyright headers to the *.c/*.h files in the main directory
Add copyright headers to the *.c/*.h files in the main directory.  For
files where I'm sure enough that we have all the approvals, I have
given them the 2-BSD license, the others have been given the "LGPL for
now" license header.  Most of them can probably be changed after
auditing.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28 17:13:04 -07:00