0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00
Commit Graph

650 Commits

Author SHA1 Message Date
H. Peter Anvin
12f6270124 asm: better error messages for missing instructions
The assembler can't know if something is a colonless label or a
misspelled instruction, so print both when complaining about a missing
instruction.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-29 16:09:04 -07:00
H. Peter Anvin
fb9afe4226 build: more fixes for building in a separate build directory
- Fix additional broken rules
- Add some more files to WARNOBJ
- $^ is not supported by POSIX, apparently
- Update warnings.pl to *actually* use the srcdir and list of
  passed-in files.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-25 13:20:29 -07:00
H. Peter Anvin
e8a0c32ba7 DFV: allow {dfv=pf} as an alias for {dfv=cf}; EQU {dfv}
PF and CF are always set to the same value; allow the programmer to
specify either or both.

Allow EQU to take a {dfv} expression without needing parens.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-23 11:56:31 -07:00
H. Peter Anvin
c4ed07830a Tidy up the morass of EVEX bitfield constants
The EVEX bitfields are complicated at best. Tidy them up to the
best of our ability.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-20 18:26:27 -07:00
H. Peter Anvin
5d75c20105 asm: drop support for ER|SAE in 256-bit vectors
An earlier version of the AVX10.2 documentation had support for ER and
SAE in 256-bit vectors using a special encoding. This was never
implemented, and has since been removed from the spec.

Remove from NASM, too.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-20 17:35:13 -07:00
H. Peter Anvin
c714d66d34 Fixes for JMP|CALL near, RETF, and segment instructions
Some weird things happened when macroizing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 18:55:54 -07:00
H. Peter Anvin
49fba5a300 labels: can only promote a *defined* EXTERN to GLOBAL
LBL_LOCAL doesn't necessarily mean defined; have to check the defined
flag explicitly.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 17:01:59 -07:00
H. Peter Anvin
a0396faf3b Fix control/debug register patterns
The control and debug registers are always using the default operand
size. It is probably easiest to just encode it explicitly for now.

Control registers are particularly weird because of the AMD "lock as
REX.R" hack...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 16:26:35 -07:00
H. Peter Anvin
d2aed9fa9d labels: handle "extern" after definition (BR 3392924)
Using "extern" or "required" after the definition should be
interpreted as "global", just as if "extern" or "required" had been
specified before the definition.

Unfortunately the code did not correctly handle the case of upgrading
from LOCAL to GLOBAL via an EXTERN or REQUIRED directive, only from
EXTERN or REQUIRED to GLOBAL via definition or a GLOBAL or COMMON
directive.

Fix.

Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-19 14:22:29 -07:00
Maciej Wieczor-Retman
f0efb28d98 assemble: apx: Add NF forbidden flag and fix SBB and ADC
ADC and SBB don't support using the {nf} prefix. They are the only one
in the arithmetic instructions group that are this way.

Add a flag that will warn when an instructions wants to use {nf} but
doesnt' support it.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2025-09-19 14:53:04 +02:00
H. Peter Anvin
55dd65cddc portability: speed and modernize autoconf; compiler.h improvements
- Add some features to autoconf that makes it cleaner and faster
- Modernize some of the autoconf macros
- Update compiler.h with some C23 features

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-16 13:25:39 -07:00
H. Peter Anvin
f6166e571a preproc: implement %hs2b() and %b2hs() functions for compact binary data
Convenience preprocessor functions that allows for efficient packing
of binary data in source code.

Move some functions that has previously been local but are more
generally useful into more accessible places.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-15 23:01:59 -07:00
H. Peter Anvin
856ac7b7fb preproc: add %chr() and %ord() string <-> byte list functions
It is sometimes just too convenient to be able to convert between
strings and bytes at will. At one point I was considering making
something with the full power of the db (et al) directives, but that
is a much bigger change...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-15 21:48:07 -07:00
H. Peter Anvin
dc247c9f99 Speed up autoconf, use POSIX names instead of cpu_to_le*()
The POSIX names for these functions are htole*(). Use those
preferentially.

Speed up autoconf by allowing early-out during alternative function
searches.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-15 18:26:25 -07:00
H. Peter Anvin
a25bc0a5d4 doc: fix broken section heading for DEFAULT BND
The section heading for DEFAULT BND was broken (missing \); make the
tags saner, too.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-14 23:50:43 -07:00
H. Peter Anvin
31c4d8bcfd doc: describe caveat with old NASM and new %if directives
Older versions of NASM would not try to match unknown %if directives
with a corresponding %endif, resulting in some very odd consequences
when it comes to trying to handle support for multiple NASM versions.

Document the problem.

Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2025-09-14 04:07:19 -07:00
H. Peter Anvin
1f1f3266d6 preproc: look for what looks to be an unknown conditional
If an unknown preprocessor directive starting with %if or %elif is
encountered, assume it should be treated as a conditional directive
for the purpose of balancing %if...%endif.

This avoids some really ugly problems when dealing with code that is
intended to work across NASM versions that uses %if directives that
don't yet exist.

Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-14 03:25:26 -07:00
H. Peter Anvin
7276cfde99 preproc: remove the message-generating functions
The message-generating functions appear to get expanded when they
shouldn't, resulting in errors. Disable them for now and remove them
from the documentation.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-14 02:48:58 -07:00
H. Peter Anvin
84115eeca6 preproc: add %find() and %findi() functions
Add the %find() and %findi() functions to look for a string in a
list. This is useful with picking apart the contents of the
__?DEFAULT?__ macro, for example.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-14 01:24:42 -07:00
H. Peter Anvin
4ccdf7e6fe preproc: add __?DEFAULT?__ macro representing the DEFAULT settings
Create a __?DEFAULT?__ magic macro with the settings of the DEFAULT
directive.

The DEFAULT directive is complex enough that this is best done with a
magic macro.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-14 00:38:50 -07:00
H. Peter Anvin
c719835357 Officially deprecate implicit DEFAULT ABS, add DEFAULT [FS|GS]:[ABS|REL]
Making DEFAULT ABS the default for 64-bit mode was a real
mistake. Issue a warning so we can eventually change it.

Support making FS: and GS: references also be REL by default.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-13 23:15:47 -07:00
H. Peter Anvin
04c21dc0c5 Allow synthesis of ROLX
If the shift amount is known, there is really no reason why we can't
accept "ROLX" as an alias for "RORX" with a modified shift operand.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-13 21:25:02 -07:00
H. Peter Anvin
a3291bd8fb preproc: return NULL, not false
In at least one place, returned false instead of NULL, which caused
build failures on some platforms.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 19:04:34 -07:00
H. Peter Anvin
1d63ae2a3b doc: update the documentation, and auto-generate some indexes
There are currently six variations of each conditionals, and there may
be more in the future (e.g. %while). Stop trying to enumerate them all
everywhere.

Add support for index copying in the document processor.

Have pptok.pl auto-generate index metadata for conditional
preprocessor directives.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 17:12:06 -07:00
H. Peter Anvin
ac93d75da3 Sanitize the handling of messsages; improve info and debug
Make the handling of messages saner. In particular, regularize the
handling of info and debug messages, so that nasm_info() and
nasm_debug() actually become useful.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 12:53:20 -07:00
H. Peter Anvin
3ff46c587a assemble: trivially optimize emissions of REX+map prefixes
Emit rex+map prefixes as a single chunk of data.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 03:04:51 -07:00
H. Peter Anvin
5158467d55 Add missing header file asm/asmutil.h
This file was missing from a previous checkin.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 01:08:25 -07:00
H. Peter Anvin
c5faa4a452 assemble.c: don't warn about segment prefixes in 16/32-bit mode
The warning about ignored segment prefixes were incorrectly issued in
16/32-bit mode as well.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 00:49:49 -07:00
H. Peter Anvin
cb20ce6f01 apx: handle RN_L16 on EAs, automatically generate EVEX forms
Memory references should have RN_L16 set if and only if they are
compatible with instruction patterns requiring register numbers below
16.

Add a "vex+" encoding pattern for VEX-encoded instructions that should
be promoted to EVEX when AVX-encoded.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-04 23:49:10 -07:00
H. Peter Anvin
31a160759d Add %ifdirective preprocessor directive
Along with C and other languages, the current trend is to be able to
probe for features rather than relying on version numbers. This is
motivated in part by the intent of bumping the major version number to
3.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-04 19:41:12 -07:00
H. Peter Anvin
ec48f1a3f8 preproc: unbreak %cond()
The previous patch accidentally broke the %cond() function.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-04 18:23:55 -07:00
H. Peter Anvin
d5bd136ced preproc: add message-generating and %null() functions
Add the %null(), %note(), %warning(), %error(), and %fatal()
functions. They behave like the corresponding directives, then expands
to nothing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-04 17:10:42 -07:00
H. Peter Anvin
e80bc631a2 preproc: identify $$ as TOKEN_BASE when tokenizing
$$ is TOKEN_BASE, not a symbol. If this is done incorrectly, ppscan
chokes on $$ as it ends up being an invalid symbol.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 11:33:08 -07:00
H. Peter Anvin
60594fde66 Fix generation of segment references with offsets
Segment references can come from two places: either an explicit SEG
operator or from a far expression. In the former case, the segment can
have a programmer-provided offset, but in the latter case, it
cannot.

The fix for bug 3392949 fixed the latter case, but broke the
former. This patch hopefully makes both work.

Rename out_segment() to out_farseg() and add a comment to explain the
logic behind the difference.

Reported-by: E. C. Masloch <pushbx@ulukai.org>
Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392950
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 11:06:16 -07:00
H. Peter Anvin
7e8f1d571e preproc: fix generation of macro invocation debug data
It is possible for m->mstk.mmac to point back to itself. In that case,
don't terminate the macro debug invocation just yet.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 10:34:28 -07:00
H. Peter Anvin
78abbf26df asm/floats.c: micro-optimize set_bit()
Micro-optimize the set_bit() function. Using size_t (in particular,
using an unsigned type) produces better code.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 01:27:30 -07:00
H. Peter Anvin
a84925df12 $ numeric syntax: require a digit to follow
The documentation actually states that $ as a hex prefix is only valid
when followed by a digit, which at least makes the syntax conflict
less complicated. Actually match the documentation.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 01:05:41 -07:00
H. Peter Anvin
54efdde7b1 preproc: warn for leading $ when a number is consumed in preprocessor
To avoid repeated warnings, there is no warning issued for when
tokenizing a number starting with $ in the preprocessor, but issue a
warning if such a number is *consumed* (used in arithmetic) in the
preprocessor.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 00:46:23 -07:00
H. Peter Anvin
178a1b7443 Add directive to disable dollar-hex constants
The use of $ prefixes for hexadecimal numbers conflicts with
the use of $ to escape symbols.  Add a directive to disable
$ for hexadecimal numbers so that those escapes work OK.

As a result, allow escaped symbols to start with a digit.

Add a warning that this syntax is deprecated.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-03 00:35:41 -07:00
H. Peter Anvin
9c3d6ff000 stdscan: handle $-escaped symbols starting with $
For a symbol to start with $, it needs to be escaped with a second
dollar sign: $$. This was not handled correctly, instead $$ was seen
as TOKEN_BASE.

Fix this.

Reported-by: E. C. Masloch <pushbx@ulukai.org>
Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392922
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 17:55:22 -07:00
H. Peter Anvin
80225b4722 Add support for the {pt} and {pn} branch hint prefixes
Add support for the {pt} and {pn} branch hint prefixes, now when they
are no longer orphanned...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 16:29:46 -07:00
H. Peter Anvin
acd01496d7 asm: distinguish between VEX.V as an immediate and a prefix; fix WW
If VEX.V is an immediate, it should not be subject to register range
checks.

If the WW flag is set, REX_W needs to be OR'd in, not XOR'd, because
the map might have the W bit set for matching purposes.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 15:38:49 -07:00
H. Peter Anvin
e05867ce3d ndisasm: make the assembler (hopefully) work again
- Significantly overhauled the disassembler internals to make
  better use of the information already in the instruction template
  and to reduce the implementation differences with the assembler
- Add APX support to the disassembler
- Fix problem with disassembler truncating addresses of jumps
- Fix generation of invalid EAs in 16-bit mode
- Fix array overrun for types in a few modules
- Fix invalid ND flag on near JMP

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-30 16:16:43 -07:00
H. Peter Anvin
3efdd3cf9a assemble: rex2.w; hinted Jcc in 64-bit mode; UDB
- rex2.w is used as a opcode extension (JMPABS), not rex2.x1 as an
  earlier version of the spec had.
- Segment prefixes used as Jcc hints are valid in 64-bit mode.
- Avoid duplicate warning messages for ignored/invalid prefixes.
  * emit_prefixes() is called twice during code generation.
- Add the UDB #UD opcode in 64-bit mode; SALC is 16/32-bit only.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 13:55:30 -07:00
H. Peter Anvin
83534f1f37 Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	Makefile.in
	Mkfiles/msvc.mak
	Mkfiles/openwcom.mak
	asm/assemble.c
	asm/nasm.c
	asm/parser.c
	doc/Makefile.in
	include/nasm.h
	include/tables.h
	output/legacy.c
	travis/test/br3392531.stderr
	travis/test/br3392716.stderr
	travis/test/org.stderr
	x86/insns.dat

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 21:09:15 -07:00
H. Peter Anvin
9ea92eab6e preproc: reference counting for mmacros, minor cleanups
The late cleanup of macros can cause severe memory hogging with nested
%reps. Instead, implement proper reference counting for mmacros.

Adds some other minor cleanups as well, notably delete_*() are
designed to update or null the pointer that is passed to it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 20:11:02 -07:00
H. Peter Anvin
ada267ec8c preproc: let %ifdef test for existence of macro functions
It is good to have a way to test for the existence of macro functions,
and since they are really just a special case of single-line macros,
allow %ifdef to test for them instead of coming up with something
entirely new.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-16 19:15:00 -07:00
H. Peter Anvin
06f7ce2dba preproc: actually use uleb128 format for encoding macros
The format wasn't actually uleb128 because it was accidentally
bigendian (like UTF-8). That is just begging for confusion in the
future, if and when the uleb128 code gets librarized.

Fix it now.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-15 17:07:15 -07:00
H. Peter Anvin
df4555d68b preproc: compress standard macros with zlib
The very simple compression scheme used for the builtin macro sets no
longer works adequately, and in fact it generates incorrect output
now.

Drop the whole idea of an ad hoc compression scheme and just use
zlib. For the case where there is no system zlib available, include a
(subset of) the zlib distribution. The configure script can be set to
force this included zlib if desired (e.g. for testing.)

Unfortunately this turned out to be a pretty painful can of worms in
terms of complexity. On the other hand having zlib available might be
useful at some point in the future.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-15 16:51:39 -07:00
H. Peter Anvin
0c533873f0 preproc: add %iffile|%isfile() and %realpath()
Add a function to test for the existence of a file, and a function
query the real operating system path, if available.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-15 00:32:33 -07:00