Commit graph

5619 commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
6b0e02de3a outform.h: add "omf", "omf2" and "os2" as aliases for obj[2]
Add aliases for the OMF object code formats.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 18:14:56 -07:00
H. Peter Anvin (Intel)
447bb02e1d Changes: document arith AL,imm8 fix
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 18:09:48 -07:00
H. Peter Anvin (Intel)
b1ee0338a3 NASM 3.02rc5 2026-04-06 17:57:13 -07:00
H. Peter Anvin (Intel)
e63209628f nasmlib/file.c: on Win32, need <stringapiset.h>
MultiByteToWideChar() and its constants are defined in
<stringapiset.h>, which is *not* included in <windows.h>.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 17:55:29 -07:00
H. Peter Anvin (Intel)
c8ce9504ca x86/insns.pl: show the correct instruction flags in comments
Adding the pattern number broke show_iflags(). This only produced
incorrect code comments and so had no actual effect, but it definitely
is not good for debugging!

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 17:42:54 -07:00
H. Peter Anvin (Intel)
0894bdae30 x86/insns.dat: remove APX flag from MSR immediate instructions
These aren't APX instructions; the vex+ annotation automatically adds
the APX flag when appropriate.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 17:16:52 -07:00
H. Peter Anvin (Intel)
fcb49f5dd6 NASM 3.02rc4 2026-04-06 16:56:18 -07:00
H. Peter Anvin (Intel)
4b37759129 nasmlib/file.c: Win32: add missing filename argument to conversion
In os_mangle_filename() with _WIN32, MultiByteToWideChar() was being
called with five arguments instead of six, missing the actual
string to convert(!)

Fixes: 5dfcfc8cab
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 16:53:11 -07:00
H. Peter Anvin (Intel)
0dd578ce68 nasmlib/alloc.c: no reason to clear q in nasm_free()
q is passed in by reference and the value of q is never examined, so
there is absolutely no reason to set q = NULL in nasm_free().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 16:48:18 -07:00
H. Peter Anvin (Intel)
8d4733962e saa: make saa_wleb128[us]() take appropriate types; recode
Make saa_wleb128[us]() take uint64_t and int64_t, respectively, rather
than int.

Notably, if saa_wleb128u() were to receive negative int, it would have
looped forever.

Recode these functions in a style more consistent with NASM code in
general, and possibly a bit simpler.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 16:43:51 -07:00
H. Peter Anvin (Intel)
9fdc7eab6e nasmlib/path.c: filename_set_extension() missing NUL termination
filename_set_extension() with extension "" would leave the string not
NUL-terminated, because elen == 0.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 15:49:23 -07:00
Iouri Kharon
8ccb56cb10 insns.dat: add missing reg_al,imm8 (04+ opcode) to the arithmetic macro
The "reg_al,imm8" (04+ opcodes) were missing from the $arith macro.
Check via: 04 11 => must be add al, 11

Fixes: f0dc7c220d
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-06 15:42:47 -07:00
H. Peter Anvin (Intel)
1e494b46c1 NASM 3.02rc3 2026-03-06 18:00:05 -08:00
H. Peter Anvin (Intel)
c8fa17205b Add support for C2y-style \o and braced escapes, and \d for decimal
C2y adds \o for octal byte escapes, and allows \x, \o, or \u escape
sequences to be enclosed in braces to indicate their termination.

Add a \d sequence as a NASM extension to allow decimal bytes to be
specified.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-06 17:59:28 -08:00
H. Peter Anvin (Intel)
b1909cf39b listing: move LIST_* enums to listing.h
The LIST_* enums belongs in listing.h, move them there and actually
use them in listing.c.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-04 14:14:02 -08:00
H. Peter Anvin (Intel)
89e1d6203a assemble: for -LX emit specific template number as well
When using -LX to debug template selection, emit the specific template
number (as per insnsa.c) as well as the xda line number.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-04 14:12:55 -08:00
H. Peter Anvin (Intel)
5606bdb335 listing: move the setting of options to one function
Disentangle the list option setting from the list option
checking. This makes the code simpler for the compiler to grok, and
centralizing code is usually a good idea.

The option setting is hardly performance critical anyway.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 15:26:56 -08:00
H. Peter Anvin (Intel)
fe9586f201 listing: separate "user" and "debug" flag, add matching debug option
Adding information about the NASM internal state to the list file can
be useful for debugging purposes. Separate the list of options that
are "user" options and those that are "debugging" options. The latter
are not implied by -L+ and are intended for NASM developer use.

Introduce -LX, which lists which instruction patterns are matched by
each instruction.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 14:12:48 -08:00
H. Peter Anvin (Intel)
a4c5b2829c changes.src: document JMP/CALL immediate size fix
- Document the fix to the JMP/CALL immediate size.
- Keep the convention to use capitals for keywords and instructions.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 13:23:26 -08:00
H. Peter Anvin (Intel)
7f92d306a9 NASM 3.02rc2 2026-03-03 13:17:56 -08:00
H. Peter Anvin (Intel)
5de64ecd20 changes.src: minor formatting fixes
- Minor format cleanups
- Correct the statement on PUSH.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 13:17:05 -08:00
Maciej Wieczor-Retman
e7aa83c68e doc: Update changelogs with bugfixes
Write up regression solving results for the upcoming 3.02.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 13:09:16 -08:00
H. Peter Anvin (Intel)
2aab21b3fb Fix the handling of the "rel" and "iwd" byte codes with oXX prefixes
The "rel" and "iwd" byte codes are supposed to be sensitive to the
operand size of the instruction, but inadvertently were only sensitive
to the CPU mode or an explicit size override for the operand.

"rel" affects direct near jumps, calls, and XBEGIN; "iwd" direct far
jumps and calls. No other instructions use these opcodes.

Fix this, so that e.g. "o32 jmp foo" is treated the same as "jmp dword
foo".

Correct the golden copies of the jmpxx travis tests (which were always
wrong.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 09:57:44 -08:00
H. Peter Anvin (Intel)
fbacd59cce struct itemplate: add insns.xda line number to the structure
Add the line number from insns.xda to struct itemplate. NASM itself
doesn't need this information, but it makes debugging matching *much*
easier; it is worth a few more bytes.

In theory it could be conditionalized on --enable-debug, but it is
probably not worth it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 09:55:27 -08:00
H. Peter Anvin (Intel)
99898edfc1 test/crc32.asm: remove "bits BITS" hack
The --bits option makes this pointless.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 08:54:01 -08:00
H. Peter Anvin (Intel)
b4f74befce test/immsize2.asm: remove bits BITS
The --bits option makes this pointless.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 08:54:01 -08:00
H. Peter Anvin (Intel)
5bb69e6c8b test.inc: remove BITS hack
The --bits option makes the BITS hack unnecessary, and it somewhat
conflicts with the directive name itself.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-03 08:54:01 -08:00
Maciej Wieczor-Retman
320bc224b5 travis: Fix v4 tests
Update the test after fixing the typo in the mnemonic.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
Maciej Wieczor-Retman
ddcf4d4f99 insns.dat: Fix issue #200 - push not allowing dword keyword
After macroization PUSH lost the NOLONG flags. That in turn caused
matching the 32-bit template when using the dword size specifier and
when in 64-bit mode. Giving the o32 entry the NOLONG flag seems to force
the o64 template instead which doesn't trigger warnings about 32-bit
sizes not being allowed.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
Maciej Wieczor-Retman
f0dc7c220d preinsns: Fix issue #159 - incorrect byte encoding
Revert part of macroization that caused incorrect instruction template
matching. The behavior known at 2.16.03 changed due to the rm#,sbyte#
format overtaking other formats. To get back to the previous behavior
the patterns need to intertwine just as is presented here.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
Maciej Wieczor-Retman
e68a08cd7d insns.dat: travis: Fix lost FAR encoding
Previous disassembler fix caused the FAR enconding not getting properly
applied when using the rm format.

Put the disassembler entries at the back so they are preffered by the
assembler and the FAR versions of memory references are correctly
matched.

Update the far tests.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
Maciej Wieczor-Retman
f4defff3ea insns.dat: Fix issue #157 - POP not accepting valid size prefixes
POP doesn't have the OSIZE iflag which made it match the 16-bit
instruction variant and the reject valid osize prefixes likes o32 in 32
bit mode.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
Maciej Wieczor-Retman
2fe0c39bdc travis: Update test binaries
Update the travis test binaries that the tests are compared against.
Changes were made to some instruction patterns and the binaries need to
be refreshed.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-03-03 08:53:44 -08:00
H. Peter Anvin (Intel)
c2344472c2 test: add a test for pushing immediates. Add a common header file.
- Add a test for pushing immediates and popping registers of various
  sizes.
- Add a common header file which probably will be useful for many
  tests.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-02 12:50:49 -08:00
H. Peter Anvin (Intel)
7c6bcd9589 test: add additional test for immediate sizes and arithmetic
Immediate sizes in arithmetic instructions can be tricky when using
optimization.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-03-02 12:13:21 -08:00
Maciej Wieczor-Retman
9dbff83e77 insns.dat: Fix JMP not assembling sometimes
After readding the JMP rm# variant, to fix the disassembler not
recognizing it, some patterns stopped assembling. It happened due to the
program matching an incorrect template and then complaining that it's
illegal.

Adding the NOLONG to word and dword versions (similarly to CALL) fixes
the problem.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-27 13:48:05 +01:00
H. Peter Anvin (Intel)
f7a4d8fd1b openwcom.mak: add zlib to the VPATH
It isn't clear if this is actually mandatory, but it is consistent
with the rest of the directories.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-02-26 15:44:17 -08:00
H. Peter Anvin (Intel)
724efa686f Merge remote-tracking branch 'maciej/for-hpa-fixes' 2026-02-26 15:32:29 -08:00
Maciej Wieczor-Retman
ef587a2566 docs: Fix issue #190 - no cp -u on MacOS prevents building
Use cp without -u to generate the documentation as the -u option doesn't
have to be present on other POSIX platforms and breaks builing the
project on MacOS.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-26 07:53:04 +01:00
Maciej Wieczor-Retman
85cd46de67 insns.dat: Fix issue #164 - broken dissasembly on JMP, JMPE and CALL
After macroization it seems the 'JMP rm' form was replaced by 'JPM
rm#|near' which caused the dissasembler to not emit anything.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-23 14:29:58 +01:00
Maciej Wieczor-Retman
14f887fb4e insns.dat: Fix issue #171 - valid prefixes not allowed
Instructions like IRET, POPF and PUSHF used to not have a operand size
specifier but after applying macros they received the 'osm' one -
meaning must be the same as the BITS mode. Which is not true for these
instructions, using the operand size prefix doesn't change their
encoding and their default 64-bit encoding is the 32-bit version.

Align these with other similar instructions like RET, RETF and use the
'od#' keyword which returns their previous behavior.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-20 19:35:26 +01:00
H. Peter Anvin (Intel)
184f8485b5 nxdisasm.pl: script to use objdump + ndisasm for better disassembly
Add a script which uses objdump to discover sections and symbols from
a binary, and call ndisasm accordingly, then add symbol references to
the ndisasm output.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-02-09 16:11:58 -08:00
H. Peter Anvin (Intel)
ed23d3ba34 ndisasm: add -z option for data size; clean up address handling
- Add a -z option to set the data size to be read (useful with -e)
- Clean up at least some remaining 32-bit assumptions.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-02-09 16:10:32 -08:00
Maciej Wieczor-Retman
8744226309 doc: Document jump size behavior
Document the logic behind determining the jump sizes, amounts of bytes
emitted related to size and length keywords. Change is related to
issue #181.

Also fix the JMPABS not being visible due to wrong tag used.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-06 19:40:52 +01:00
Maciej Wieczor-Retman
1ef93d643d doc: Fix issue #191 - badly formatted link
Fix bad link formatting that prevents building the documentation.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-06 19:15:52 +01:00
Maciej Wieczor-Retman
627ec8b865 insns.dat: Fix issue #196 - CMP not being lockable
Using LOCK on any CMP configuration of operands will result in #UD.

Remove the possibility of adding the LOCK prefix to the CMP instruction.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-06 18:13:09 +01:00
Maciej Wieczor-Retman
3910b58e96 parser.c: Fix issue #181 - redundancy needed to avoid NEAR optimized out
To assemble a JMP in the NEAR form the STRICT keyword is needed. This
change introduced recently reportedly breaks building boot sectors and
is non-intuitive since other JMP versions don't behave this way.

Disable optimizing the JMP size if the NEAR keyword is used.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-04 17:18:44 +01:00
Maciej Wieczor-Retman
bbff2d7ec6 parser.c: Fix issue #182 - no warning when size is omitted with labels
In cases such as "mov [es:bx], a_label" the operation defaults to a BYTE
size which copies only part of the label value.

Implement a check that warns the user of this issue when no size
specifier is used.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-03 23:12:46 +01:00
Maciej Wieczor-Retman
0058d91bec travis: Fix tests after instruction corrections
The UWRMSR was incorrectly encoded with operands swapped. Correct that
mistake.

Some AVX512 and AVX10.2 instructions had incorrect operands in the
database. Correct the tests after fixing the database entries.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-02-03 23:12:42 +01:00
Maciej Wieczor-Retman
89682def9b disp8: Fix issue #185 - EVEX compressed shift for MOVDDUP tuple type
MOVDDUP tuple type uses a compression shift for the disp8 addressing
scheme. The shift depends on the vector lenght and is defined as 8 for
128 bits, 32 for 256 bits and 64 for 512 bits.

Current implementation doesn't work for the 128 bit vector case since
the expression used evaluates to 16 instead of 8. Fix it with a special
if check before the current expression is returned.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
2026-01-27 22:24:25 +01:00