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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
When throwing one of the "instruction expected" error messages, print
what was encountered instead.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
"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>