0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00
Commit Graph

5245 Commits

Author SHA1 Message Date
H. Peter Anvin
7a5502142b bytesex, ilog2: use C23 <stdbit.h> if available; use in disassembler
Merge the macros used in the assembler and disassembler.
Simplify and slightly correct the byte order/unaligned handling macros.
Use <stdbit.h> from C23 if available for bytesex.h and ilog2.h.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 01:46:57 -07:00
H. Peter Anvin
25e3864f8e disasm: fix a number of problems with sizes of addresses
Fix incorrect truncations of address sizes, and completely unnecessary
annotations about the size of displacements when not default.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 01:29:37 -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
5bc1da7fa9 zlib/zconf.h: set HAVE_VSNPRINTF
We *will* have vsnprintf(), if we so have to add it ourselves ;)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 20:10:44 -07:00
H. Peter Anvin
0b73367874 nasmlib/asprintf: check the return value from vsnprintf()
Without this, gcc may throw a warning which breaks the --enable-werror
build. It is good practice anyway...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 20:10:41 -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
2bf3585547 mkdep: disable some debug messages
A handful of debug messages in mkdep.pl were not guarded with
if ( $debug ), resulting in really annoying unnecessary verbosity.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-15 16:54:17 -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
H. Peter Anvin
0843052f05 preproc: implement %pathsearch() and %depend() as functions
Implement preprocessor function equivalents of the %pathsearch and
%depend directives.

Simplify the incbin standard macro by using these functions.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 21:46:55 -07:00
H. Peter Anvin
8ecb5d817a doc: cross-link %if and %is()
Link from %if to %is(), not just the other way.

Clarify that %is() is valid everywhere, not just in an %if expression
(unlike defined() in C.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 19:34:43 -07:00
H. Peter Anvin
23dffbd57a doc: highlight %unimacro a bit more
The %unimacro directive is almost a footnote, but it is really
important to use the correct directive.  Put it on equal footing with
%unmacro.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 19:28:33 -07:00
H. Peter Anvin
af3cbc7633 doc: tidy up the section about REQUIRED versus EXTERN
It is not great to have the documentation of a behavior change in
EXTERN under REQUIRED.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 19:16:56 -07:00
H. Peter Anvin
9f24de1034 parser: improve the "instruction expected" error messages
When throwing one of the "instruction expected" error messages, print
what was encountered instead.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-14 18:43:02 -07:00
H. Peter Anvin
161b64f485 Merge remote-tracking branch 'github/nasm-2.16.xx' 2025-08-13 13:58:34 -07:00
H. Peter Anvin
e2ccd5de26 travis: remove obsolete error message about %unmacro
%unmacro now *is* permitted on a macro being expanded; the entire
expansion is strictly performed when the macro is invoked, and the
lifetime issue related to %unmacro and %exitrep has been hacked
around.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-13 13:57:59 -07:00
H. Peter Anvin
2726aefb06 output: remove the legacy output entry point
Remove the legacy output entry point. It has proven impossible to find
the time to completely port the backends all at once.

Instead, always generate the legacy output data, but put them into the
out_data structure. Then add a macro to explode these arguments into
separate variables, equivalent to the old function arguments. This
also centralizes the type definitions for these variables.

Most importantly, it means that the entire struct out_data is now
always available, which means that backends that need the additional
information available in that structure, such as the specific
instruction template, can access that information without needing to
revamp the entire backend code all at once.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-13 13:51:25 -07:00
H. Peter Anvin
33eda43042 autoconf: update m4 macros and config/unconfig.h
(Does unconfig.h really need to be in the git tree?)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2025-08-11 18:54:17 -07:00
H. Peter Anvin
1da646aeba Merge remote-tracking branch 'origin/nasm-2.16.xx'
Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-11 18:52:20 -07:00
H. Peter Anvin
9e6a4dd028 preproc: inc_fopen(): use the correct path for hashing the fullpath
This code incorrectly would try to use "path" as the hash key instead
of full->path, causing the key in struct hash_insert to diverge from
the one used in hash_add(). Fix that.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-11 14:42:47 -07:00
H. Peter Anvin
f49e9f1bea preproc: hack around mmacro lifetime problems by deferring free
Under some circumstances, such as:

- Certain uses of %exitrep in syntactically invalid code;
- %unmacro of a *alias* to a macro currently being expanded;

... it is possible for an mmacro to get freed while it is still in
use. Although inefficient, the easiest way to avoid this is to not
free mmacros until the end of pass cleanup, when named mmacros are
also freed.

To support this, use the existing ->next field in the MMacro structure
to keep a list of anonymous or removed MMacros. Don't free ->name at
this point, though, since that is currently used to distinguish
between %rep's and %macro's.  (This needs to be cleaned up to support
constructs such as %while or %for, but that is for later.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-11 14:02:12 -07:00
H. Peter Anvin
5457220e55 Merge remote-tracking branch 'origin/nasm-2.16.xx' 2025-08-11 11:23:39 -07:00
H. Peter Anvin
3ed10eccf1 insns.dat: avoid obsolete-removed warning on UD0
UD0 without a modr/m is obsolete in terms of syntax, but not as an
instruction per se. Match UD1 and assemble it without warnings, but
disassemble it with operands.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-11 11:10:38 -07:00
H. Peter Anvin
df1c055b5e insns.dat: add "UDB" opcode (permanent official #UD in 64-bit mode)
The opcode D6 has been officially reserved as a single-byte permanent
undefined (#UD) opcode in 64-bit mode with the mnemonic UDB.  This is
already the behavior of all known 64-bit implementations; this is thus
merely an official statement of forward compatibility and the
assignment of a mnemonic.

This will be documented in the next version of the Intel Software
Developer's Manual; in the meantime I DO speak officially for Intel on
this issue.

The x86 Advisory Council has ratified this decision, and so it is
expected to be honored across vendors, but I obviously cannot make any
official statement on any other vendor's behalf.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-11 11:01:34 -07:00
H. Peter Anvin
af0430fab3 path: tidy up syntax selection, add Haiku to Unix syntax list
Tidy up the way path syntax selection is handled, and make it possible
to specify it outside this file (e.g. in a Makefile) if need be.

Haiku, like BeOS, uses Unix syntax.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-05-02 22:40:22 -07:00
H. Peter Anvin
0ab85c391c x86: add Perl script for rex2 compatibility testing (not yet used)
Add a Perl script to try to automate REX2 compatibility flagging. Not
yet integrated into the build process.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-03-04 08:43:09 -08:00
H. Peter Anvin
3d686291c0 assemble: make assemble() and insn_size() static
These functions are only used in assemble.c, so make them static.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-03-04 08:38:45 -08:00
H. Peter Anvin
888d9ab550 configure.ac: enable some -Werror= warnings not included in -W -Wall -pedantic
For some reason, these warnings are not included in -W -Wall -pedantic, at least
not on gcc 14.2.1:

	-Wstrict-prototypes
	-Wmissing-prototypes
	-Wmissing-declarations

This caused a missing prototype error (because nasm_note[f]()
prototypes were missing from include/error.h) to get missed when
compiling with --enable-werror, which is ironic at best.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-11-04 10:30:14 -08:00
H. Peter Anvin
25757f83c5 autoconf: update some of the m4 library
Update some files in the m4 library. This also updates
config/unconfig.h to match.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-11-04 10:19:43 -08:00
H. Peter Anvin
ef5fd5391c error.h: add prototypes for nasm_note[f]()
Apparently -Wall -W doesn't enable -Wmissing-prototypes for some
bizarre reason.

This allowed this to slink through unnoticed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-11-04 10:17:06 -08:00
H. Peter Anvin
8d62e99e14 Add %note directive to add a note in the list file
This differs from a plain old comment in the following ways:

1. It is optionally macro-expanded;
2. It has a dash prefix;
3. It can be used inside .nolist macros.

Suggested-by: <pushbx@ulukai.org>
Resolves: https://bugzilla.nasm.us/show_bug.cgi?id=3392915
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-09-19 13:21:30 +02:00
H. Peter Anvin
84ae32bf0a insns: add PROT flag if either EVEX or LONG is set
EVEX is not supported in real or v86 modes.
LONG is a submode of PROT.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-23 13:15:46 -07:00
H. Peter Anvin
49a56ea9ee Add optimization for operand narrowing; tidy up selector handling
Add a optimization frameword for operand narrowing (where the operand
size doesn't matter beyond a certain range because only certain bits
are referenced.)

Add a macro *and* matching facility for dealing with segment selectors, which are
typically rm16/r32/r64, but exactly how that is applied varies
depending on if a datum is read or written.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-23 02:25:21 -07:00
H. Peter Anvin
863bddbdcb iflags: add NOREX flag
Add a NOREX flag to indicate that an instruction pattern is not
compatible with REX encoding.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 23:41:32 -07:00
H. Peter Anvin
ecbd1c81b3 insns: fix MOVBE CPUID flag, BSWAP 16-bit XCHG patterns
Add the MOVBE CPUID flag, add helper patterns for 16-bit BSWAP
emulation. Unfortunately using ROL/ROR for registers other than the
ones for which XCHG can work clobbers the flags.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 23:32:42 -07:00
H. Peter Anvin
2b2f1fc98a More macroizing and sorting of instructions into categories
More work on cleaning up instruction patterns, fixing matchig corner
cases, and tidying up the organization of insns.dat.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 23:22:59 -07:00
H. Peter Anvin
ea90c8f498 insns: macroize CALL
Macroize the CALL instructions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-22 22:17:39 -07:00
H. Peter Anvin
e515dac43f More matching/macrofication work; now passes "make travis"
More matching and macrofication work.
Improve some error and warning messages.
Update some travis tests for better messages and added optimizations.

Fix duplicated warning messages for the same out-of-range value
problem.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-22 22:07:31 -07:00
H. Peter Anvin
253ff4f370 insns: tag pseudo-instructions explicitly; change insnsa.c format
Tag pseudo-instructions explicitly and don't set any CPU level flag
for those.

Change insnsa.c to have (length, pointer) rather than using an ever
increasing in size sentinel at the end of each table. This also means
that empty tables (Dx, INCBIN) can be omitted entirely.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-21 12:50:31 -07:00
H. Peter Anvin
58024b4611 insns: more instruction macroizing/fixups; remote FUTURE tags
Add more instruction macros and fix problems. Adjust some matching
problems.

Remove all FUTURE tags from the instruction list, and add a bunch of
new CPUID tags. Hopefully a small step toward actually getting CPU
feature selection working properly in the future.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-21 11:48:47 -07:00
H. Peter Anvin
cdfe0422b2 x86/insns.dat: macroize the UDx "instructions"
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-20 13:16:20 -07:00
H. Peter Anvin
75f6f4cdb2 WIP: more matching and template work
Further work on a better matching system. Still a work in progress,
however.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-08-20 12:59:07 -07:00
H. Peter Anvin
f114a6276e insns: more macroization and organization
Macroize and update more instruction patterns.

Begin organizing the instructions by functional groups.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 22:15:48 -07:00
H. Peter Anvin
ea25d2ebe2 insns: more cleanup and macroization
Checkpoint.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 20:00:13 -07:00
H. Peter Anvin
8f97af7d71 insns: more macro fun; handle things like RET, RETW, RETD, RETQ
Add macro handling for patterns with a non-suffixed default operand
and alternative suffixed operands.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 19:23:33 -07:00
H. Peter Anvin
05f1b6b658 insns: sanitize the handling of "nw" and "osz"; fix more patterns
"nw" now means: 64-bit operand size is the default, o32 is not
permitted in 64-bit mode.

"osz" means: instruction size determined by prefixes, otherwise the
mode default.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-15 17:52:54 -07:00
H. Peter Anvin
fb74d63180 insns: macroize more instructions
Macroize a few more instructions, and add support for a few more types
of common instruction patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 23:57:41 -07:00
H. Peter Anvin
8ee33d2734 insns: more macroized instructions and fix preprocessor bugs
Add more macroized instructions, and fix some bugs in the
instruction preprocessor.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 21:26:23 -07:00