Commit Graph

266 Commits

Author SHA1 Message Date
Philipp Kloke
dae212d049 Fixed several resource and memory leaks
Bug found by: CppCheck 1.59 (static source analysis tool)

Signed-off-by: Philipp Kloke <philipp.kloke@web.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-04-01 02:16:27 +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
Cyrill Gorcunov
83e6924e1a Move conditional opcodes close to enum ccode definition
Thus if someone need to rework this code he won't need
to jump between files trying to figure out where enum
and opcodes lay.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-03 14:34:31 +04:00
Cyrill Gorcunov
982387606b assemble: Make emit_rex being a function
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-02 02:59:29 +04:00
Cyrill Gorcunov
59df421af3 assemble: Use case3/4 where appropriate
This allows to shrink code a bit.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-02 02:59:21 +04:00
Cyrill Gorcunov
62576a016d assemble: Add case3 helper
Signed-off-by: cyrill <cyrill@cyrills-MacBook-Pro.local>
2013-03-02 02:46:17 +04:00
Cyrill Gorcunov
c7ce6a4f22 process_ea: Drop redundant variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-03-02 02:45:53 +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
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
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
e014f354d5 HLE: One more byte code conversion
Add missing site for the \265..267 -> \271..273 byte code move.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 22:35:19 -08: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
5a24fdd547 Make the LOCK and HLE warnings suppressable.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 15:11:11 -08:00
H. Peter Anvin
755f5214b7 Remove all remaining explicit bytecodes from insns.dat
Get rid of the last vestiges of the explicit byte codes in insns.dat.
The only files that now depend on actual byte code numbers are
insns.pl, assemble.c and disasm.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 11:41:34 -08:00
H. Peter Anvin
8cc8a1d836 Add support for warning on invalid LOCK prefixes
Add an LOCK flag to the instruction template, and make the presence of
a LOCK prefix trigger a warning if it is not set.  Simplify the LOCK
and HLE logic by hard-coding the knowledge that operand 0 has to be
memory.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 11:11:42 -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
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
d6851d4d26 assemble: Drop redundant variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-09-25 18:01:45 +04:00
Cyrill Gorcunov
10734c7e58 A couple of simplifications to assemble.c
- GEN_SIB and GEN_MODRM helpers added
 - a number of tabs vs space fixs
 - more use of is_class() helper

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-29 00:07:17 +04:00
Cyrill Gorcunov
cdb8cd7b22 Drop empty line and bracket
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 16:33:39 +04:00
H. Peter Anvin
9f2043eaad assemble.c: remove stray debugging code
My bad for checking this in at all.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-08-22 13:52:02 -07:00
Cyrill Gorcunov
c4d328c165 assemble.c: Comment out debug printing
Probably we need some kind of pr_debug or
something like that instead.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-23 00:12:50 +04:00
Cyrill Gorcunov
397402016f Drop unused 'type' from gencode
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-07-17 14:02:52 +04: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
Victor van den Elzen
6dfbddb6b0 Move implicit operand size override logic to calc_size
It is more logical, it cleans up the code and it makes implicit
operand size override prefixes come out in the same order as explicit
ones instead of after all other prefixes.

Suggested-by: H. Peter Anvin <hpa@zytor.com>
2010-12-29 18:13:38 +01:00
H. Peter Anvin
bcf9f2a08b Merge branch 'nasm-2.09.xx' 2010-11-16 09:40:03 -08:00
H. Peter Anvin
3cb0e8c052 BR 3109604: Fix C4 vs C5 VEX form selection in calcsize()
calcsize() had the wrong criterion for when C5 prefixes are permitted
(REX.R is permitted, REX.X is forbidden.)  assemble() had the right
test already.  This caused symbol value errors.
2010-11-16 09:39:32 -08:00
Victor van den Elzen
b3cee5a57a BR3058845: mostly fix bogus warning with implicit operand size override
The implicit operand size override code didn't set the operand size
prefix, which confused the size calculation code for the range check.

The BITS 64 operand size calculation is still off, but "fixing" it by
making it 32-bit unless REX.W is set breaks PUSH and maybe others.
2010-11-07 23:27:48 +01:00
H. Peter Anvin
47fb7bc088 assemble: add an OPT instruction flags for optimizing assembly only
Add an OPT flag to only use a pattern for optimizing assembly only.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-24 13:53:22 -07:00
H. Peter Anvin
229fa6c465 assmemble.c: fix VEX.W logic
Fix the generation logic for VEX.W, which unfortunately got the wrong
constants.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-16 15:21:48 -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
H. Peter Anvin
978c2170fc vex: change .wx to .wig to match the latest AVX spec
Change the .wx (ignore the W field) to .wig, to match the latest
version of the AVX specification.  This is not a functional change,
but just makes instruction patterns a little easier to write.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-08-16 13:48:43 -07:00
Cyrill Gorcunov
d6f31240c5 assemble.c: Style nitfix
Various tabs/space mixture cleaned and some more.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-26 23:16:45 +04: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
Cyrill Gorcunov
2124b7b7dc Use is_register helper
Save us some line of code

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-25 01:16:33 +04: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
H. Peter Anvin
fea84d7fec Permit short intersegment jumps
Allow an intersegment jump to be short (OUT_REL1ADR) if explicitly
specified so by the user.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 15:33:24 -07:00
H. Peter Anvin
55ae12052c Add support for one-byte relocations
Add OUT_REL1ADR (one-byte relative address) and support for
OUT_ADDRESs with size == 1.  Add support for it in
outbin and outdbg.  *It still needs to be added to other backends*,
both the OUT_REL*ADR and OUT_ADDRESS codepaths need to be handled.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 15:33:24 -07:00
Victor van den Elzen
0d268fb78c BR 2496848: Tighten ea checks
Check if the offset and the representation are equivalent.

Disallow REL on absolute addresses.
I'm not sure what that would mean and the output formats don't support it.

Warn about ignored displacement size modifiers.
2010-03-12 23:52:04 +01:00
Cyrill Gorcunov
6531d6d159 BR2907058: insn_size - close file handle before returning
As example of such behaviour is when fseek fails for
some reason.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-12-05 14:10:41 +03:00
Cyrill Gorcunov
1de9500c89 Comment out matches() operand flags logic
Also space fix

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 00:08:38 +03:00
Cyrill Gorcunov
bc31bee760 matches: simplify check operand size actions
We may throw out j variable (since we break anyway)
and don't assign asize for free (since we don't
use it after).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-03 21:37:09 +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
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
a7643f4c04 assemble: xsizeflags[] is an opflags_t variable
One more case of int32_t instead of opflags_t...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-10-13 12:32:20 -07: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
9ccabd2922 assemble.c: check constants for overflow
Lets check if a constant supplied to DB and etc
does not overflow storage size and emit warning
if needed.

[ Bug #2857628 http://sourceforge.net/tracker/?func=detail&aid=2857628&group_id=6208&atid=106208 ]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:57 +04:00
Cyrill Gorcunov
8a6345ca47 assemble.c: use is_class helper
is_class does not checking flags "strictly". Which means
it may fail if type is specified to REGMEM and you check for
is_class(MEMORY, ...).

Anyway in current patch we check for REGISTER which doesn't
overlap and it is safe to use is_class here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:49 +04:00
Cyrill Gorcunov
1f75420d61 use opflags_t type for operands
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:41 +04:00
H. Peter Anvin
8d2c4edd22 assemble: when looking for a REGISTER operand, do an exclusive test
Do an "exclusive" test for a REGISTER operand when deciding to treat
sizes as wildcards.  "Exclusive" meaning don't just accept any class
that could be REGISTER, but something that is strictly a part of the
REGISTER class.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-10-06 09:58:40 -07:00
H. Peter Anvin
ff5d656929 assemble: treat register operands without size as wildcards
Register with no size are a bit special: we don't honor extrinsic
register sizes in the first place ("oword xmm1" gives a warning,
even), and they should match any xmmrm size.  As such, explicitly
handle sizeless register operands as a hard match, instead of relying
on the fuzzy-matching mechanism to handle them.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-10-05 14:08:05 -07: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
H. Peter Anvin
e873c9b16b Merge commit 'cyr/hpa-list' 2009-07-30 15:06:47 -07:00
Cyrill Gorcunov
a92a3a5c49 assemble.c -- use list helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-27 22:33:59 +04:00
H. Peter Anvin
ed3e84f9cd assemble.c: quiet warning
Clear an uninitialized variable warning.  The case can't actually
happen, but the compiler doesn't know that.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-27 11:10:33 -07:00
H. Peter Anvin
60926244f1 assemble.c: clean up matches()
Simplify matches(), and quite possibly make it more correct.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-26 16:25:38 -07:00
H. Peter Anvin
3fb86f2cd6 assemble: defer "operand size missing" until end of type check
Defer the "operand size missing" error until we know all the other
operands have the correct type.  Otherwise we'll end up with false
positives, which result in noise entered into the xsizeflags array,
thus causing fuzzy matching to fail.

It's possible we should defer it even further.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-25 19:12:10 -07:00
H. Peter Anvin
a81655bffb Enable fuzzy matching of operand sizes
This allows automatic fuzzy matching of operand sizes.  If an operand
size is not specified, but there is exactly one possible size for the
instruction, select that instruction size.  This requires a second
pass through the instruction patterns, and so is slightly slower, but
should be a lot easier to get right than the S- flags, and works even
when there is more than one instruction.

The new SX (Size eXact) flag can be used to prevent fuzzy matching
completely.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-25 18:15:28 -07:00
H. Peter Anvin
23595f5946 assemble: move the instruction-matching loop into a common function
Move the instruction-matching loop into a common function.  This gives
us a single point to adjust the instruction-selection algorithm.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-25 17:44:25 -07:00
H. Peter Anvin
65289e84ed assemble: replace random integers with an enum for match results
Match results were reported with random integers.  Replace with an
enum.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-25 17:25:11 -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
4a5a6dfed0 assemble.c: stylistic nitpick
Fix stylistic nitpick

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 16:14:18 -07:00
H. Peter Anvin
d28f07f7e3 ndisasm: fix disassembly of JRCXZ
Fix the disassembly of JRCXZ; in 64-bit mode, we should only accept
JECXZ for disassembly with 32-bit address size override.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-26 16:18:00 -07:00
H. Peter Anvin
9472dab6ed Add support for instructions which always use low 8-bit registers
Add a byte code to explicitly support instructions which only uses the
low 8-bit registers (as if a REX prefix always was present.)  This is
usable for instructions which are officially documented as using "the
low byte of a 32-bit register" and so on.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-24 21:38:29 -07:00
H. Peter Anvin
a04019c7f4 Infrastructure support for AMD's new XOP prefix
Handle AMD's XOP prefixes; they use basically the same encoding as VEX
prefixes, so treat them simply as a variant of VEX.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-03 21:42:34 -07:00
H. Peter Anvin
16a856cd85 Most instruction codes are octal, so print errors that way too
Most of our instruction opcodes are written in octal.  Thus, it makes
sense to print them that way if we ever have an error message.
2009-03-01 00:22:16 -08:00
H. Peter Anvin
e8ab891a65 sbyte: optimization is OK if UNKNOWN isn't set
We can optimize the sbytes if the UNKNOWN flag isn't set
2009-02-26 16:34:56 -08:00
H. Peter Anvin
9945feeed6 BR 2413265: don't pessimize displacements
Optimize displacements, don't pessimize them.  When running in the
optimizer, we always keep track of when a reference is forward.  That
doesn't mean it is unknown.
2009-02-26 14:48:03 -08:00
Victor van den Elzen
154e5920a1 Do not confuse segmentless adresses and unknown forward references
Also be optimistic with immediate forward references.
2009-02-25 17:32:00 +01:00
H. Peter Anvin
eea57cc6c5 assemble: only be optimistic with NO_SEG if we're really in pass 1
Only be optimistic about the reachability of a symbol with NO_SEG if
we are truly in pass 1, i.e. it could possibly be just a forward
reference.  After we have done a single pass, if it is still NO_SEG,
then it is an absolute symbol and need to be treated as such.
2009-02-23 17:51:25 -08:00
Victor van den Elzen
ccafc3c4b7 BR 2420167: jmp not always optimized
Begin by assuming short jumps are possible to prevent suboptimal convergence.
2009-02-23 04:35:00 +01:00
H. Peter Anvin
c2acf7b047 BR 2592476: Treat WAIT as a prefix even though it's really an instruction
WAIT is technically an instruction, but from an assembler standpoint
it behaves as if it had been a prefix.  In particular, it has to be
ordered *before* any real hardware prefixes.
2009-02-21 18:22:56 -08:00
H. Peter Anvin
999868f06f Unify all-zero buffers; add fwritezero()
We have a number of all-zero buffers in the code.  Put a single
all-zero buffer in nasmlib.c.  Additionally, add fwritezero()
which can be used to write an arbitrary number of all-zero bytes;
this prevents the situation where the all-zero buffer is simply
too small.
2009-02-21 17:24:08 -08:00
H. Peter Anvin
6cda414a0e BR 2432826: Fix enforcement of the LONG bit
Somewhere we lost the enforcement of the LONG bit, as opposed to
NOLONG.  Fix this in the most obvious way.
2008-12-29 20:52:28 -08:00
Victor van den Elzen
352fe06e02 BR 2413272: Warn about byte displacement overflow
Remove the special case for single byte displacements,
which was already in out() anyway.
2008-12-10 13:04:58 +01:00
H. Peter Anvin
ae64c9d819 assemble: use opx and opy in a few more places
Use opx and opy in a few more places where we can do so.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-25 00:41:00 -07:00
H. Peter Anvin
33d5fc074f Fix op2 references that had not yet been converted; introduce opy
Fix op2 references not yet converted to accessing op2; add an opy
pointer similar to the opx pointer instead of multiple references.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-23 23:07:53 -07:00
H. Peter Anvin
dcffe4b9f6 Add extension bytecodes to support operands 4+
The bytecode format assumes max 4 operands pretty strictly, but we
already have one instruction with 5 operands, and it's likely to get
more.  Support them via extension prefixes (similar to REX prefixes).
For bytecodes which use argument bytes we encode the number directly,
however.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-23 23:03:59 -07:00
H. Peter Anvin
b21141a301 When issuing warnings for EA displacements, use the *EA* operand
When issuing warnings for EA displacements during address generation,
actually look a the proper operand!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-23 20:49:09 -07:00
H. Peter Anvin
e286c7e79c assemble: not all backends handle intra-segment OUT_REL*ADR
Not all backends can handle being handled an intrasegment OUT_REL*ADR,
and we don't fix them up in common code either (which would be the
logical thing to do -- right now we fix them up in a bunch of
individual places.)

For now, just fix up the one in address generation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-22 11:15:00 -07:00
H. Peter Anvin
0a20bcfaf1 assemble: for OUT_REL*ADR, the "size" argument is not really size...
For OUT_REL*ADR, the "size" argument is actually the offset inside the
instruction; that is in fact why we encode the real size in the
instruction itself.  Thus, emit the offsets properly using this
mechanism when generating relative EAs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 23:29:11 -07:00
H. Peter Anvin
779ed8bcfd BR 2172659: Fix incorrect output value for byte operands
A typo in checkin c1377e9a98 caused a
bunch of signed-byte immediates to incorrectly be issued as zero.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-16 13:01:43 -07:00
H. Peter Anvin
507ae03bd1 assemble.c: use case4() macros like in disasm.c
Use the case4() macros as we already do in disasm.c.  It helps reduce
visual clutter, and more clearly demonstrates that groups of four
belong together.  Furthermore, it makes the text compact enough that
we can now use case statements to mask down the EA patterns correctly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-09 15:37:10 -07:00
H. Peter Anvin
ff6e12da50 Reshuffle and move the bytecodes for segment register push/pop
Reshuffle the bytecodes for segment register push/pop to make more
sense, and move them from \4 to \344, thus freeing up the single-digit
bytecodes \4..\7 for future use.  It doesn't really make sense to use
single-digit bytecodes for this very oddball use.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-08 21:17:32 -07:00
H. Peter Anvin
588df78b0d New opcode for 32->64 bit sign-extended immediate with warning
Add a new opcode for 32->64 bit sign-extended immediate, with warning
on the number not matching.

This unfortunately calls for an audit of all the \4[0123] opcodes, if
they should be replaced by \25[4567].  This only replaces one
instruction (MOV reg64,imm32); other instructions need to be
considered.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-07 10:05:10 -07:00
H. Peter Anvin
ad6b8595b9 Remove is_sbyte64() and replace with is_sbyte32() plus custom warning
is_sbyte64() was equivalent to is_sbyte32() plus the warning; however,
the warning is only used in one place (and conflicts with another
warning there), so remove the function.

Furthermore, add back the test for pure immediates in
possible_sbyte(); they had been broken out but never folded back in --
and are essential.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-07 09:56:38 -07:00
H. Peter Anvin
98a22a65c0 Avoid double warning for signed dword immediate
Avoid double warning for the case where a signed dword immediate is
incorrectly extended to 64 bits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-06 23:49:01 -07:00
H. Peter Anvin
c1377e9a98 New opcodes to deal with 8-bit immediate sign extended to opsize
New opcodes to deal with 8-bit immediates which are then sign-extended
to the operand size.  These allow us to warn appropriately.
Not sure I'm using these in all the proper places; need audit of all
uses of the \14..\17 opcodes.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-06 23:40:31 -07:00
H. Peter Anvin
9f8171317d BR 2148448: Fix RIP-relative addressing with an immediate
When there is an immediate in the instruction, a RIP-relative offset
may not be relative to the end of the offset itself, since it is
relative to the end of the *instruction*, not the end of the *offset*.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-06 19:11:07 -07:00
H. Peter Anvin
e9d7f1a074 Better warnings for out-of-range values
Issue better warnings for out-of-range values.  This is not yet
complete.

In particular, note we may have out-of-range for values that end up
being subject to optimization.  That is because the optimization takes
place on the *truncated* value, not the pre-truncated value.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-06 18:47:29 -07:00
H. Peter Anvin
833caeab28 assemble.c: be smarter about when to suppress warnings due to SBYTE
Be smarter and don't suppress warnings due to SBYTE when the SBYTE
didn't actually match.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-04 19:02:30 -07:00