Commit graph

152 commits

Author SHA1 Message Date
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
3539225609 Align enum prefixes members
It's a way easier to read.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-02-15 02:06:24 +04:00
H. Peter Anvin
290b4cb3a4 eval: add general support for "integer functions" and add ilog2*()
Add general support in the function parser for "integer functions"
(actually implemented as special unary operators, then wrapped in
macros) and implement a family of integer logarithms.  The only
difference is the behavior on a non-power-of-two argument:

	ilog2[e]	-- throw an error
	ilog2w		-- throw a warning
	ilog2f		-- round down to power of 2
	ilog2c		-- round up to power of 2

This is useful for back-converting from masks to bit values.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-05-31 10:25:37 -07:00
Cyrill Gorcunov
b5e8fec848 preproc: Move NOP preprocessor into separate file
No need to carry it in nasm.c, let it be more modular.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-05-07 11:34:27 +04:00
Cyrill Gorcunov
0b78bff510 preproc: Split get rid of global preproc methods
This will allow to hook on updated preprocessor
without breaking existing one.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-05-07 01:57:55 +04:00
H. Peter Anvin
9fa2e72997 Add support for UTF-16BE and UTF-32BE
Add support for bigendian UTF-16 and UTF-32, and (for symmetry) add
explicitly littleendian operators.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 15:29:37 -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
c026df26c3 Style tuneup of nasm.h
- a number of tabs to space conversion
 - redundant spaces removed
 - structure elements alignment

No functional changes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 15:00:26 +04:00
Cyrill Gorcunov
d47e00db4c nasm.h: Reorder tokenval members to drop padding
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-07-17 20:00:30 +04: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
Cyrill Gorcunov
86b2ad05f8 preproc: Move Preproc type to preproc_ops structure
There is no need to hide this structure into a type.
The former preproc_ops is a way more descriptive.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-07-02 00:15:24 +04:00
Cyrill Gorcunov
a39912dcd9 Move numvalue herleper into nasmlib.h
No need to duplicate implementation.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-06-25 12:10:40 +04: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
c1936da942 ofmt: Alias shortname must be used for __OUTPUT_FORMAT__ macro
__OUTPUT_FORMAT__ must consist of shortname of output format
or its alias, otherwise userspace ABI gets broken.

For example source code still can refer to __OUTPUT_FORMAT__=elf,
instead of __OUTPUT_FORMAT__=elf32.

BR3246990

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-04-06 18:32:15 +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
H. Peter Anvin
b453c866ab nasm.h: move "regs.h" to top; make is_register() a bool
Move the #include of regs.h to the top with the other includes, and
make is_register() -- being a boolean predicate -- return bool.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-25 00:17:12 -07:00
Cyrill Gorcunov
a38b86aecf move is_register helper to nasm.h
H. Peter Anvin noted:
 |
 | Could we avoid putting static code that has no dynamic content in
 | dynamically generated files... it just complicates things unnecessarily.
 |
 | The above can move into nasm.h for example.
 |

Good idea.

CC: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-25 11:09:56 +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
5e2e8b9105 Rename filenames to 8.3 format
Apparently some people still care about compiling native on MS-DOS,
and we don't have a significant number of files which need adjustment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-15 10:47:16 -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
Cyrill Gorcunov
2ef5c27be7 Rename SEGALIGN to SECTALIGN
"sectalign" is preferred over "segalign"
since it operates over section attributes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:09:54 +04:00
Cyrill Gorcunov
2a587ab1c9 ofmt: Implement null_segalign stubs
Set stubs for all targets

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:08:36 +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
1985416b0b nasm.h: introduce is_class macro helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:45 +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
dbb640b846 Drop efunc and evalfunc as input to the preprocessor
We only ever invoked the preprocessor with fixed values for efunc and
evalfunc, so call nasm_error() and evaluate() directly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:57:16 -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
9bd1506d59 Remove function pointers in output, simplify error handling
Remove a bunch of function pointers in the output stage; they are
never changed and don't add any value.  Also make "ofile" a global
variable and let the backend use it directly.

All we ever did with these variables were stashing it in locals and
using them as-is anyway for no benefit.

Also change the global error function, nasm_error() into a true
function which invokes a function pointer internally.  That lets us
use direct calls to it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:43:12 -07:00
H. Peter Anvin
afa06137fa Hash even backend-specific directives, unify null functions
Hash all directives, even the ones that are backend-specific,
and instead pass the backend an already-parsed directive number.

Furthermore, unify null functions across various backends.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-12 12:55:24 -07:00
H. Peter Anvin
a23aa4a3e9 listing: preserve list file on error, include errors
Instead of removing the list file on error, keep the list file and
include the errors in the list file.  This makes it actually possible
to debug things that involve deep macro recursion, where the line
number is pretty much meaningless.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-07 12:04:12 -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
0cba107579 Make it possible for outputs to be either text or binary
Allow the backend to specify that an output format is either text or
binary.  For future uses, define this as a flag word so we can define
other flags in the future if it would make sense.

Currently, the ieee and dbg formats are text; all the others are
binary.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 14:45:12 -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
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
40b81a40c7 Add symbolic constants for REX_V "classes" (VEX, XOP, ...)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-08 18:01:21 -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
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
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
4b9358928b Move all version strings to a single compilation unit (ver.c)
Move all the version strings to a single compilation unit, ver.c; this
does not include the version macros, which are fed into macros.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-31 16:53:49 -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
a70547f3ae Avoid redundant "const" for macros_t
Don't use a redundant "const" for macros_t (which is const unsigned
char), since OpenWatcom doesn't like it, and I believe it is incorrect
per the C standard.
2008-07-19 21:44:26 -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
f221b9ee08 Fix a few more <ctype.h> instances
A few isolated instances of isalpha() and isxdigit().
2008-06-21 11:03:51 -07:00
H. Peter Anvin
bda7a6e371 ctype.h: wrapper ctype functions with a cast to (unsigned char)
ctype functions take an *int*, which the user is expected to have
taken the input character from getc() and friends, or taken a
character and cast it to (unsigned char).

We don't care about EOF (-1), so use macros that cast to (unsigned
char) for us.
2008-06-21 10:23:17 -07:00
H. Peter Anvin
cfb7176ca2 Move the output format macros into the macros.pl mechanism
Move the handling of "extra" macros (i.e. output format macros) into
the macros.pl mechanism.  This allows us to change the format of the
internal macro store in the future - e.g. to a single byte store
without redundant pointers.

Also, stop using indicies into a long array when there is no good
reason to not just use different arrays.
2008-06-20 15:20:16 -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
11627049ae Make strings a first-class token type; defer evaluation
Make strings a proper, first-class token type, instead of relying on
the "TOKEN_NUM with tv_charptr" hack.  Only convert a string to a
number if requested in an expression context; this also makes it
possible to actually issue a warning when it overflows.
2008-06-09 20:45:19 -07:00
H. Peter Anvin
9e1f528c36 Add the -MP option to emit phony targets
Add the -MP option to emit phony targets.  Since this means each
header file has to be visited more than once, change the
implementation to use an internal list of all the dependencies, and
centralize the emission of the dependency files.
2008-05-29 21:38:00 -07:00