Commit Graph

115 Commits

Author SHA1 Message Date
H. Peter Anvin
cd7893d02d Remove additional function pointers that never change
Remove additional cached function pointers which point to static
variables which are never actually changed.  Just refer to the global
variable instead.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 01:25:46 -08:00
H. Peter Anvin
130736c0cf Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments,
which then just get stashed in static variables.  Clean this mess
up and in particular handle the error management in the preprocessor
using nasm_set_verror() which already exists.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:27:41 -08:00
Cyrill Gorcunov
5c0b082c92 parser: Check for eval error before memory reference parsing
If there is an error in evaluate() happened then @value
is NULL so that we better fail with error report instead
of trying processing it.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-11-22 18:20:29 +03: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
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
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
487f352b62 stdscan: Rework curly brace parsing routines
As recommended by the community, a comma-separated decorators ({k1,z})
and nested braces ({{k1},{z}}) are dropped out. So only standard syntax
is supported from now.

This rework made source code neat and easy to maintain. Most of the codes
for handling corner cases are removed.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-11-27 15:43:33 -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
c9486b965b Build: Suppress warning messages
Giving a correct printf format specifier supresses the warning message.
And a local pointer variable is initialized with NULL.

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
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
9148fb5951 parser: support split base,index effective address
Mostly intended for the "mib" expressions in BNDLDX/BNDSTX.

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
H. Peter Anvin
9f4706ff45 parse: factor out mref parsing
Factor out the parsing of an mref from parse_line().  In order to
support the [base,index] syntax we need to be able to parse an mref in
two steps.

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
H. Peter Anvin
df0d1ba107 parser: simplify code by keeping a pointer to the current operand
There is an awful lot of syntax-heavy "result->oprs[operand]" going
on; simplify by making a pointer to the current operand.

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
H. Peter Anvin
9d5461069d Add support for DZ and RESZ, document the ZWORD keyword
Add the DZ and RESZ pseudoinstructions and add ZWORD to the
documentation.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-10-02 18:28:49 -07: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
50ab1522e9 AVX-512: Fix parser to handle opmask decorator correctly
When a memory reference operand is a destination, this could have
an opmask decorator as well.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-22 19:37:49 +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
f9a71e0c38 AVX-512: Reword comment about opmask decorators
Previous comment was not so clear.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-22 19:37:32 +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
Jin Kyu Song
72018a2b43 AVX-512: Add support for parsing braces
AVX-512 introduced new syntax using braces for decorators.
Opmask, broadcat, rounding control use this new syntax.

http://software.intel.com/sites/default/files/319433-015.pdf

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-08-06 09:37:52 +04:00
H. Peter Anvin
e20ca02cfb BR 3392260: Handle instructions only separated by vector SIB size
There are two instructions (VGATHERQPS, VPGATHERQD) where the only
separation between two forms is the vector length given to the vector
SIB.  This means the *matcher* has to be able to distinguish
instructions by vector SIB length and the matcher only operates on the
operands and the instruction flags, not on the bytecode.

Export the vector index-ness into the operand flags and add to the
matcher.

This resolves BR 3392260.

Reported-by: Agner <agner@anger.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-07-19 17:09:39 -07:00
Cyrill Gorcunov
836492fbcf parse_line: Shrink code with memset helper
We know that P_none = 0 thus instead of using
for() statement assign them all in one memset
call.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-07-16 01:33:09 +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
Cyrill Gorcunov
167917abe5 opflags: Extend opflags_t to 64 bits
Soon we will need to encode 512 bits values
thus there is no space left in our opflags_t
which is 32 bitfield.

Extend it to 64 bits width.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-09-10 01:35:38 +04: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
Cyrill Gorcunov
18914e6330 BR3392198: Fix compilation warning on prefixes
insn->prefixes might contain not only values from
'enum prefixes' but from 'enum reg_enum' as well so
make it generic 'int' instead.

This calms down the compiler about enum's mess and
eliminates a wrong assumption that we always have
values by particular type in this field.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-12 11:41:51 +04:00
Cyrill Gorcunov
1f4ccb9282 parser: No need to split line if it a bit longer than 80 chars
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 19:53:11 +04:00
Cyrill Gorcunov
5abbe375cf Add IS_SREG and IS_FSGS helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 18:49:00 +04:00
Cyrill Gorcunov
447e20cf96 A few style fixups in parser.c
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 18:02:31 +04:00
Victor van den Elzen
d55a158cec BR3104852: only warn once for repeated prefixes 2010-11-07 23:47:13 +01:00
Cyrill Gorcunov
68a344003a parser.c: Drop space line and use hex notation
For big numbers it's easier to estimate bytes count
if they are written in hex notation. Let it be so.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-08-27 23:25:04 +04:00
H. Peter Anvin
9df010725f Optimize mov r64,imm
Handle immediate-size optimization for "mov r64,imm" -- reduce it to
"mov r32,imm32" or "mov r64,imm32" as appropriate.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-24 14:08:16 -07:00
H. Peter Anvin
ab5bd05d82 Revert "Improve process_ea and introduce -OL"
This reverts commit ac732cb6a5.

Resolved Conflicts:

	doc/nasmdoc.src

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-25 12:43:30 -07:00
Victor van den Elzen
ac732cb6a5 Improve process_ea and introduce -OL
Two fixes:
1. Optimization of [bx+0xFFFF] etc
   0xFFFF is an sbyte under 16-bit semantics,
   so make sure to check it right.

2. Don't optimize displacements in -O0
   Displacements that fit into an sbyte or
   can be removed should *not* be optimized in -O0.

   Implicit zero displacements are still optimized, e.g.:
   [eax] -> 0 bit displacement, [ebp] -> 8 bit displacement.
   However explicit displacements are not optimized:
   [eax+0] -> 32 bit displacement, [ebp+0] -> 32 bit displacement.

Because #2 breaks compatibility with 0.98,
I introduced a new optimization level: -OL, legacy.
2010-07-24 22:00:12 +02:00
Cyrill Gorcunov
210c10110b Revert "BR 2887108: Use overflow_ helper to catch inappropriate imm optimization"
This reverts commit 41208028ff.
|
| From: "H. Peter Anvin" <hpa@zytor.com>
|
| The tests for overflow_signed() are wrong too.  Those are relevant for if a
| warning should be issued, but not for how the value should be encoded in
| the byte stream.
|

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2009-11-01 10:24:48 +03:00
Cyrill Gorcunov
cfbcddf1a5 Various tab/space/comment cleanup
No change on binary level

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:05:32 +03:00
Cyrill Gorcunov
917117ff69 stdscan: switch to stdscan_get/set routines
Instead of manipulating stdscan buffer pointer directly
we switch to a routine interface.

This allow us to unify stdscan access: ie caller should
"talk" to stdscan via stdscan_get/set routines.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:02:43 +03:00
Cyrill Gorcunov
bafd877d48 nasmlib: Introduce idata_bytes helper
This allow us to eliminate code duplication

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:02:14 +03:00
Cyrill Gorcunov
41208028ff BR 2887108: Use overflow_ helper to catch inappropriate imm optimization
We should use overflow_ helpers before check if an immediate
operand fit a type range, otherwise we may loose high bits.

For example when we assemble the following instruction

	imul eax,eax,0x10000

with -Ox passed we optimze it up to imm8 though it must be imm32.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 10:35:11 +03:00
Cyrill Gorcunov
c2509508b5 parser.c: pasrse_line -- fix alignment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-14 19:39:22 +04:00
Cyrill Gorcunov
3757524161 Use I_none opcode instead of hardcoded number
Consolidate I_none opcode to be used everywhere
instead of mix (-1,I_none).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-08-23 10:40:17 -07:00
Victor van den Elzen
15bb233036 Fix some format strings for nasm_error
Added a format attribute to nasm_error (only for GCC) and
used the resulting warnings to fix some format strings.
2009-08-11 02:43:41 +02:00
H. Peter Anvin
00444ae04e Drop efunc and evaluate argument to parse_line()
We never invoked the parser with anything but the default definitions
for evaluate and efunc.  Unlike the backend, though, we sometimes
invoke parse_line() with redefine_label() instead of define_label().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:49:55 -07:00
H. Peter Anvin
605f5155ee Drop the ofmt and errfunc arguments to label definition functions
We never set ofmt and errfunc to anything but the global values.
Dropping them from the label definition function command line
simplifies the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:43:58 -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
H. Peter Anvin
3512d71748 parser.c: fix stylistic nitpick
Fix stray blank line in parser.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 16:26:25 -07:00