Commit graph

266 commits

Author SHA1 Message Date
H. Peter Anvin
ca351fa175 assemble.c: when converting an address to RAWDATA, need to update size
When converting an address to RAWDATA we have to copy the address size
into the size variable, as the size variable may be negative.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 13:49:45 -08:00
H. Peter Anvin
b03d91e6ab assemble.c: fix the handling of zero-extending unsigned relocations
First of all we printed the wrong error message, and second of all we
need to set the segments to NO_SEG before passing them to the output
format generator.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 21:13:54 -08:00
H. Peter Anvin
b64125022d assemble.c: handle oversized relative relocations
Handle the case of oversized (larger than permitted by the output
format) relative relocations.  Relative relocations are always signed,
and quite likely to actually have the sign bits set, so zero-extending
them is not an option.  Fortunately oversized relative relocations
are rare, as no CPU instruction support 64-bit relative addresses.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 21:07:40 -08:00
H. Peter Anvin
33814133bd Replace global maxbits variable with field in struct ofmt
maxbits is strictly a property of the output format, so get rid of
this ad hoc method of reporting.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 20:40:07 -08:00
H. Peter Anvin
ecc9e0ecd7 Set warning name to zext-reloc and fix the warning message
Adjustment to the warning about zero-extended relocations.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 20:29:34 -08:00
H. Peter Anvin
d24dd5fecc Remove the --allow-64-bits option and make it a warning
Remove the --allow-64-bits relocation, and instead make it a
suppressible warning in the case of a zero-extended relocation, and an
error in the case of a sign-extended relocation.

Relocations which can be losslessly represented in the output format
do not issue any diagnostic at all, as there is no problem in that
case.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-08 10:32:13 -08:00
Mark Charney
dcaef4b095 Sync to public Intel EAS version 021.
* http://www.intel.com/software/isa

   * Signed-off-by: Mark Charney <mark.charney@intel.com>
2014-10-16 16:31:31 -07:00
Cyrill Gorcunov
8a5d3e68a4 insns: Move 'np' mnemonic into @plain_codes
This is literal mnemonic so no need to special
handling, move it to @plain_codes instead.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-25 20:04:30 +04:00
Cyrill Gorcunov
5d488a30a4 assemble.c: Introduce mnemonics into bytecode spec
There are a number of mnemonics used in instns.pl plus
insns.dat files, lets document them.

This is first attempt to document mnemonics, so something
might be still missing, need review and updates.

No functional changes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-25 19:32:02 +04:00
H. Peter Anvin
89f78f5010 Merge branch 'nasm-2.11.xx'
Resolved Conflicts:
	assemble.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-05-21 08:30:40 -07:00
H. Peter Anvin
0a9250c2ab BR 3392279: Fix duplicated REX prefixes
The fix for BR 3392278:

aa29b1d93f assemble.c: Don't drop rex prefix from instruction itself

... would cause multiple REX prefixes to be emitted for some
instructions.  Create a new flag to indicate that REX has already been
emitted, which can be cleared for each instance of an instruction.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-05-21 08:24:21 -07:00
H. Peter Anvin
49de44e56d Merge remote-tracking branch 'origin/signrel' 2014-05-09 15:09:43 -07:00
Cyrill Gorcunov
5b144751ee Rename REX_REAL to REX_MASK
"Real" doesn't reflect the meaning of this
macro -- it rather represents a rex prefix mask.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-05-09 14:38:58 +04:00
Jin Kyu Song
eb29cf7b31 AVX512: Remove invalid error checking
An offset-only memref can also have an opmask decorator.
e.g.) vmovdqu32 [0xabcd]{k1}, zmm0

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2014-05-05 13:56:36 -07:00
Cyrill Gorcunov
aa29b1d93f assemble.c: Don't drop rex prefix from instruction itself
emit_rex is supposed to write REX prefix into output stream
if needed, but we happen to drop it off on a first write
which breaks REX required instructions if TIMES directive
is used.

For example the code like

	| times 4		movq	xmm11, xmm11

compiles into

	| 0000000000000000 <.text>:
	|   0:	f3 45 0f 7e db       	movq   %xmm11,%xmm11
	|   5:	f3 0f 7e db          	movq   %xmm3,%xmm3
	|   9:	f3 0f 7e db          	movq   %xmm3,%xmm3
	|   d:	f3 0f 7e db          	movq   %xmm3,%xmm3

instead of proper

	| 0000000000000000 <.text>:
	|   0:	f3 45 0f 7e db       	movq   %xmm11,%xmm11
	|   5:	f3 45 0f 7e db       	movq   %xmm11,%xmm11
	|   a:	f3 45 0f 7e db       	movq   %xmm11,%xmm11
	|   f:	f3 45 0f 7e db       	movq   %xmm11,%xmm11

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

Reported-by: Javier <elpochodelagente@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-05-05 11:20:17 -07:00
Jin Kyu Song
26ddad67ca nosplit: Generate index-only EA only when a multiplier is used.
[nosplit eax] has been encoded as [eax*1+0] since 0.98.34.
But this seems like unexpected behavior.
So only when a register is multiplied, that will be treated
as an index. ([nosplit eax*1] -> [eax*1+0])
Document is updated accordingly.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-18 22:38:44 -08:00
Jin Kyu Song
3d06af2bd9 nosplit: Limit the effect of NOSPLIT
[nosplit eax+eax] was encoded [eax*2] previously but
this seems against the user's intention.
So in this case, nosplit is ignored now and [eax+eax] will be
generated.
Document is also updated accordingly.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-18 22:37:30 -08:00
Jin Kyu Song
97f6faec62 mib: Avoid RIP-relative addressing in mib
Using RIP relative for mib operands causes #UD exception.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-18 22:27:47 -08:00
Jin Kyu Song
4360ba28f0 mib: Handle MIB EA in a different way from regular EA's
In mib operands, users' intention should be preserved.
e.g.) [eax + eax*1] and [eax*2] must be distinguished and encoded differently.

So  a new EA flag EAF_MIB for mib operands is added.
And a new EA hint EAH_SUMMED for the case of [eax+eax*4] being parsed
as [eax*5] is also added.

NOSPLIT specifier does not have an effect in mib, so [nosplit eax + eax*1]
will be encoded as [eax, eax] rather than [eax*2] as in a regular EA.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-11 16:56:19 -08:00
Jin Kyu Song
b287ff0ddb bnd: Add a new nobnd prefix
bnd and nobnd prifixes can be used for each instruction line to
direct whether bnd registers should be preserved or not.

And those are also added as options for DEFAULT directive.
Once bnd is set with default, DEFAULT BND, all bnd-prefix
available instructions are prefixed with bnd. To override it,
nobnd prefix can be used.

In the other way, DEFAULT NOBND can disable DEFAULT BND and
have nasm encode in the normal way.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-04 20:10:08 -08:00
Jin Kyu Song
bb8cf3fa77 bnd: Show warning when bnd prefix is dropped
When bnd prefix is dropped as jmp is encoded as jmp short,
nasm shows a warning message, which can be suppressed with a new
command line option, -w-bnd.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-04 20:06:23 -08:00
H. Peter Anvin
621a69ac5c Add {vex3} and {vex2} prefixes by analogy with {evex}
Allow specifying {vex3} or {vex2} (the latter is currently always
redundant, unless we end up with instructions at some point can be
specified with legacy prefixes or VEX) to select a specific encoding
of VEX-encoded instructions.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-11-28 12:21:11 -08:00
Jin Kyu Song
6cfa968e8d iflags: Add IF_EVEX for checking {evex} availability
For checking the availability of {evex} prefix, AVX512 iflag
has been used. But this is a flag for an instruction set
not for an encoding scheme. And there are some AVX512 instructions
encoded with VEX prefix.

So a new instruction flag (IF_EVEX) is added for the instructions
which are actually encoded with EVEX prefix.

This flag is automatically added by insns.pl, so no need to add manually
in insns.dat.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-27 15:43:33 -08:00
Jin Kyu Song
08ae610ec9 opflags: Separate vector registers into low-16 and high-16
Since only EVEX supports all 32 vector registers encoding for now,
VEX/REX encoded instructions should not take high-16 registers as operands.

This filtering had been done using instruction flag so far, but
using the opflags makes more sense.

[XYZ]MMREG operands used for non-EVEX instructions are automatically
converted to [XYZ]MM_L16 in insns.pl

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-27 15:43:32 -08:00
H. Peter Anvin
72bf3fe98c assemble: Only treat a displacement as signed if it is < asize
Only generate a signed relocation if the displacement size is less
than the address size.  This matters when involving address size
overrides.

It is technically impossible to do this one perfectly, because it is
never really knowable if the displacement offset is used as a base or
an index.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2013-11-26 20:19:53 -08:00
H. Peter Anvin
89a2ac0d0a assemble: Emit signed relocations where appropriate
Emit signed relocations where we know they are necessary.  This is not
at all exhaustive; in particular we are missing this for a number of
8- and 16-bit cases, and probably others.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2013-11-26 18:23:20 -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
305f3cee04 bnd: Drop bnd prefix for relaxed short jmp instructions
Reverted the redundant branch instruction patterns for bnd prefix.
And when a relaxed jmp instruction becomes a short (Jb) form,
bnd prefix is not needed because it does not initialize bnd registers.
So in that case, bnd prefix is silently dropped.

BND JMP foo       -> drops bnd prefix
BND JMP short foo -> shows an explicit error

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-22 11:59:14 -08: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
25c2212586 match: Check the number of elements in broadcasting operands
The broadcasting decorator {1to##} must describe exactly how many times
the memory element is repeated in order to clearly match the correct
instruction format.

For example,
    vaddpd zmm30,zmm29,QWORD [rdx+0x3f8]{1to8}   ; good
    vaddpd zmm30,zmm29,QWORD [rdx+0x3f8]{1to16}  ; fail qword * 16 = 1024b

    vaddps zmm30,zmm29,DWORD [rcx]{1to16}	 ; good
    vaddps zmm30,zmm29,DWORD [rcx]{1to8}	 ; fail dword * 8 = 256b

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
7903c07b77 match: Improve broadcast opsize matching
Broadcasting operand size is different from the original
operand size because 32b or 64b element is repeated to form a vector.
So when matching a broadcasting operand, opsize should be treated
differently.
The broadcasting element size is specified in the decorator information.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:42 -08:00
Jin Kyu Song
945b1b8f36 AVX-512: Add {evex} instruction prefix
For instructions that can be encoded either in VEX or EVEX,
{evex} forces nasm to encode in EVEX.

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
3b65323d80 MPX: Adapt GAS's mib syntax with an index reg only
GAS uses *1 multiplier for explicitly marking an index register in mib operand.
e.g.) [rdx * 1 + 3] is equivalent to [3, rdx] in NASM's split EA format
So only for mib operands, this is encoded same as gas does.

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
Jin Kyu Song
164d60740f MPX: Add MPX instructions
Added MPX instructions and corresponding parser and encoder.

ICC style mib - base + disp and index are separate - is supported.
E.g. bndstx [ebx+3], bnd2, edx -> ebx+3 : base+disp, edx : index

As a supplement to NASM style mib - split EA - parser,
omitted base+disp is now treated as 0 displacement.
E.g. bndstx [,edx], bnd2 -> bndstx [0,edx], bnd2

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-20 11:29:41 -08:00
H. Peter Anvin
c6c750cb3d Add (redundant) parentheses around bit tests mixed with &&
It is easy to get confused when mixing & and &&, so add redundant
parenteses for clarity.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-11-08 15:28:19 -08:00
Jin Kyu Song
1be09ee0d7 REX: Set REX bits in accordance with 32-register environment
REX.RXB bits were set for high-8 registers previously.
Since high-16 zmm registers are newly added, those bits should
be set as one bit of binary number of register value.
Similarly EVEX.R'/V'/X should be set in the same manner.

Authored-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-08 01:48:31 -08:00
Jin Kyu Song
db358a2993 AVX-512: Fix bugs related to uninitialized variables
Initialized disp8 to avoid a case that disp8 encoded
instead of the actual offset value.
Added a checking routine for basereg value before using it
as an index of array.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-09-21 12:26:36 +04:00
Jin Kyu Song
dd1c0c13c8 AVX-512: Add AVX-512ER instructions
Added Exponential and Reciprocal (AVX-512ER) instructions.
These instructions are supported
if CPUID.(EAX=07H, ECX=0):EBX.AVX512ER[bit 27] = 1.
IF_AVX512 is now shared by all AVX-512* instructions as a bit mask.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-09-14 01:27:06 +04:00
Jin Kyu Song
c47ef9490b AVX-512: Fix rounding mode value in EVEX prefix with SAE
If SAE is set, VL(vector length) is implied to be 512.
EVEX.L'L (=EVEX.RC) is set to 00b by default.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-09-07 11:50:11 +04:00
Jin Kyu Song
7abc78dee0 AVX-512: Fix bug in checking high-16 registers
Register value needs to be checked. Previous patch compared with reg_enum.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-29 10:03:14 +04:00
Jin Kyu Song
e3a06b9d0a AVX-512: Remember the position of operand with broadcast or embedded rounding
It was not so straight forward to find the postion of operand that has
a broadcasting, embedded rounding mode or SAE (Suppress All Exceptions)
decorator out from operands types or bytecode.
Remebering the postion of the operand of interest in the parser reduces
the burden that assembler looks through the operands.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-29 10:03:02 +04:00
Jin Kyu Song
66c61926b1 AVX-512: Fix match function to check the range of registers
High-16 registers of XMM and YMM need to be encoded with EVEX not VEX.
Even if all the operand types match with VEX instruction format,
it should use EVEX instead.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-28 09:37:31 +04: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
d2d9c3ee38 AVX-512: Fix a bug in calculating Disp8*N value
Fixed a bug that derived an incorrect N value for tuple types of
T2, T4, T8.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-28 09:37:14 +04:00
Jin Kyu Song
4a6570616a AVX-512: Find the correct position of the last SIMD op
Since embedded rounding mode is following the last SIMD op,
GPR op should be skipped when finding the last SIMD op.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-28 09:35:54 +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
4d1fc3f1a0 AVX-512: Fix instruction match function
When an instruction allows broadcasting, the memory element size is
different from the size of normal memory operation.
This information is provided in a decoflags field, so it should try to
match those properties before it fails.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-22 19:37:37 +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