Commit Graph

152 Commits

Author SHA1 Message Date
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
H. Peter Anvin
6c80ab6f7f assemble.c: do not warn on valid SBYTE optimizations
Do not warn on valid SBYTE optimizations.  If we are optimizing and
match one of the SBYTE conditions, do not error out.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-04 18:50:47 -07:00
Victor van den Elzen
cf9332ca51 Apply patch from BR 1197827 2008-10-01 12:18:28 +02:00
H. Peter Anvin
2d5baaa69a assemble.c: cleanups
Formatting and some other minor cleanups.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-30 16:31:06 -07:00
Charles Crayne
f1aefd8456 Change behavior of -O0 and -O1 for backward compatibility
-O0: JMP default to NEAR, Jcc/LOOP/JCXZ default to SHORT.
      In other words, this is reverting to full-blown 0.98 behavior, not
      0.98.39.
-O1: JMP and Jcc default to NEAR, LOOP/JCXZ default to SHORT (only
      possible form).
2008-09-30 16:11:32 -07:00
Charles Crayne
2581c869b1 Decouple forward references from optimization
Users who wish to control the level of optimization can
continue to specify -O0, -O1, or -Ox,
where x can be the letter itself, or any number > 1.

However, even with optimization turned off,
NASM will always make enough passes to resolve
forward references. As a result, INCBIN is now the only
item left in the critical expressions list, although TIMES
still has its own constant value check.
2008-09-10 19:21:52 -07:00
H. Peter Anvin
962e30519c BR 2029829: Accept VIA XCRYPT instructions with or without REP
Accept the VIA XCRYPT instructions either with or without a REP
prefix, as documented.

Add the missing XCRYPTCTR instruction.
2008-08-28 17:47:16 -07:00
H. Peter Anvin
19f15a50f6 BR 2067837: remove double add of VEX instruction length
We added the length of VEX prefixes twice in calcsize(); this resulted
in the wrong symbol addresses when compiling without the optimizer.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-08-24 18:09:04 -07:00
H. Peter Anvin
1c3277b625 BR 2003451: avoid "forwardness" leaks between operands
Any use of ins->forw_ref that isn't related to control of the
optimizer is fundamentally broken.  Use
operand->opflags & OPERAND_FORWARD instead.  This even has the nice
side benefit of simplifying the code.
2008-07-19 21:38:56 -07:00
H. Peter Anvin
2aa77394b7 Free EOT_DB_STRING_FREE in cleanup_insn()
Free EOT_DB_STRING_FREE data in cleanup_insn(), which is where we free
all the other extop data.
2008-06-15 17:39:45 -07:00
H. Peter Anvin
518df30308 Implement __utf16__() and __utf32__() for the DB family
Implement __utf16__() and __utf32__() for the DB family of
pseudo-instructions.  Not yet implemented for evaluation context.
2008-06-14 16:53:48 -07:00
H. Peter Anvin
418ca70d4e Introduce %depend and %pathsearch, and make incbin a macro
Introduce new preprocessor directives %depend and %pathsearch, and
make incbin a standard macro using these filenames.  This lets us
remove the code that makes incbin search the path.
2008-05-30 10:42:30 -07:00
H. Peter Anvin
bd420c7095 Add tokens vex.ww and vex.wx; vex.wx is the default
Add vex.ww (for VEX.W follows REX.W) and vex.wx (for VEX.W is a don't
care); vex.wx is the default since that seems to match existing usage
better.
2008-05-22 11:24:35 -07:00
H. Peter Anvin
52dc353868 Handle is4 bytes without meaningful information in the bottom bits
Support is4 bytes without meaningful information in the bottom bits.
This is equivalent to /is4=0 for the assembler, but makes the bottom
bits don't care for the disassembler.
2008-05-20 19:29:04 -07:00
H. Peter Anvin
3be5d85913 No 32-byte floating point format: fix error for DY
Output a more legible error message for floating-point with "DY".
2008-05-20 14:49:32 -07:00