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

27 Commits

Author SHA1 Message Date
H. Peter Anvin
a92616af5c disasm: fix the masking of the V4/X4 bit
This bit needs to be masked *except* when:
- There is no V operand
- The modr/m has mod == 3 OR there is an scc

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 03:32:28 -07:00
H. Peter Anvin
52c5ee24cf ndisasm: fix legacy map handling, 8-bit GPRs
Fix the handling of legacy map prefixes (0F, 0F 38, 0F 3A).

Fix 8-bit GPRs decoding (REX vs no-REX versions.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 02:41:59 -07:00
H. Peter Anvin
3ec5f486c6 disasm: fix VEX3 parsing, ignore immediate sizes
Immediate size annotations are irrelevant for disassembly matching.

VEX3 parsing corrected.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 22:22:35 -07:00
H. Peter Anvin
6698897d4f disasm: correct the offset of IP-relative displacement
IP-relative values, both jump addresses and RIP-relative memory
addressing, are relative to the end of the instruction.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 22:05:53 -07:00
H. Peter Anvin
b6d3474a00 disasm: strip sizes from unsized registers; fix VEX map parsing
- Correct the parsing of VEX map numbers
- Strip the size bits from register names that don't have
  intrinsic size

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 22:01:33 -07:00
H. Peter Anvin
0852ca5694 disasm: handle NOP disassembly, remove debug message
NOP disassembly is a little "special" because it sits as part of the
XCHG instructions. Add a flag to bail out of the disassembler search
early, and ignore the 0330 bytecode.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 20:01:36 -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
56567a0c4c disasm: fix the disassembler for many APX cases
With these changes, the disassembler correctly decodes the ccmp.asm
and apx.asm tests.

Fix rebuilding the main tools from test/Makefile.in.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-02 15:40:32 -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
9f86275c74 Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	disasm/disasm.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 01:51:27 -07:00
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
1286a2da4e Tidy up handling of modr/m and compressed immediates
Merge a bunch of common code in the handling of modr/m
generation. Make the handing of compressed disp8 simpler and more
transparent by exporting a the shift factor for the compressed
immediate in ea_data. For the case of no compression, the shift factor
is simply 0; there is no need to distinguish "compressed" from
"uncompressed".

The tidied up version of the disp8 code is simple enough that it makes
more sense to inline it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 16:24:49 -07:00
H. Peter Anvin
49640ed315 x86: move the bytecode defintion into a separate file in x86/
At least three files (asm/assemble.c, disasm/disasm.c, and
x86/insns.pl) depend on the bytecode defintions. It makes a lot more
sense for them to live in an explicit documentation file in the x86/
directory.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-23 12:47:25 -07:00
H. Peter Anvin
a2eabbe1d7 insns: drop special handling of conditional instructions
Instead of handling conditional instructions ad hoc, generate
individual instruction patterns as normal. This simplifies the code
and makes CMPccXADD support simpler (otherwise it would be necessary
to hack in the handling of a condition code in the middle of an
instruction.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-12 12:37:37 -08:00
H. Peter Anvin
ec2074d27f fp16: fix incorred handling of broadcast flags
The FP16 patch had a case of bit overlap. Clean up the handling of
broadcast flags a little in the process.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 16:24:39 -08:00
Iouri Kharon
21d8dbfabb restire: Support of AVX512-FP16 Instructions
Add support for AVX512-FP16 instructions and the associated
handling. Allow "mapN" syntax as well as "mN" syntax to match the
documentation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:21:23 -08:00
H. Peter Anvin
bb1233ccde Add FRED instructions
Add the FRED instructions: ERETU, ERETS, LKGS

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 13:31:30 -07:00
H. Peter Anvin
b31a4c9906 Add support for new instructions from ISE June 2020
Add support for new instructions as defined in the Instruction Set
Extensions manual as of June 2020.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-07-16 21:52:15 -07:00
H. Peter Anvin
8960e1bc83 Remove #includes already provided by "compiler.h"
"compiler.h" already includes a bunch of common include files. There
is absolutely no reason to duplicate them in individual files, and in
fact it robs us of central control of how these files are used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:45:44 -08:00
H. Peter Anvin
2e53f27e9d Move <string.h> inclusion to compiler.h
There is absolutely no reason not to include <string.h> globally, and
with the inline function for mempcpy() we need it there anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-26 06:32:37 -08:00
Cyrill Gorcunov
55d09bbf6f disasm: Fix buffer overread in ndisasm
https://nvd.nist.gov/vuln/detail/CVE-2018-10254
https://sourceforge.net/p/nasm/bugs/561/

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-08-16 01:20:01 +03:00
H. Peter Anvin
cd26fccab4 asm: support the +n syntax for register sets
Support the +n syntax for multiple contiguous registers, and emit it
in the output from ndisasm as well.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 17:15:08 -07:00
Ruslan Kabatsayev
3ebed50146 disasm: Add support for 64-bit origin
This fixes disassembly of instructions like jmp/call when target address
is larger than 2^32-1, and also printing of current address when it's
large.

After this change ndisasm still assumes that the files to disassemble
will never reach 4GiB: only offsets are made 64 bit, but not lengths.

https://bugzilla.nasm.us/show_bug.cgi?id=3392349

Signed-off-by: Ruslan Kabatsayev <b7.10110111@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-02-12 20:19:34 +03:00
Martin Lindhe
3478078c5f disasm: matches -- fix operator priority error with parenthesis
fixes pvs-studio error 'V502 Perhaps the '?:' operator works in a different way
than it was expected. The '?:' operator has a lower priority than the '!=' operator.'

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
Martin Lindhe
e29e321e62 Dont set @mod twice
pvs-studio: V519 The 'mod' variable is assigned values twice successively.
Perhaps this is a mistake. Check lines: 398, 405.

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
H. Peter Anvin
e1f985c167 Reorganize the source code into subdirectories
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-25 12:06:29 -07:00