0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

248 Commits

Author SHA1 Message Date
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
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
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
c9457d42a6 WIP checkpoint: more matching changes, starting to work on patterns
This is a WIP checkpoint; not all tests pass yet.

More matching changes, and hopefully something much closer to what
really is desired now. The number of required patterns is now much
smaller.

However, a lot of *changes* are needed to the patterns.

Since some patterns are repeated all over the place, clean up the
x86/addflags.pl script and make it able to generate macro-based
common patterns; first use being the patterns for the "basic 8"
arithmetic patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 21:28:57 -07:00
H. Peter Anvin
bff94fbd39 Major changes to a number of subsystems to improve matching
Work through a number of changes toward making matching a lot saner,
both to reduce the number of patterns to generate for APX but also to
make a number of code patterns simpler.

This replaces a fair number of byte codes.

Improve a number of error messages, especially related to overflows.

Move process_insn() from nasm.c to assemble.c, as it really is the
primary entry point to the assembler module.

Reorder some prefixes. In particular, F2/F3 override 66 when used as a
mandatory prefix, so it makes more sense for them to be closer to the
opcode.

Move a lot more information into struct insn. It is better to have it
in one place; memory consumption is not an issue because struct insn
is transient information.

Get rid of "optimization levels" and replace it with a mask of
flags. That was already halfway done; complete the job.

Replace seg:offset in struct out_data with a struct location. It would
be better to extend this to more places, too.

The ARx and SMx flags are now explicit bitmasks, instead of having a
couple of hard-coded ranges.

Add __func__ to assert or panic messages.

Because of prefix and message changes, a number of travis tests had to
be audited and updated.

Fix a number of instruction patterns which had .128 when they ought to
be .lig. This is no longer a minor issue with the disassembler: for
AVX10, the pattern vector length determines how SAE/RC are encoded,
and there is no valid 128-bit encoding. However, with .lig the 512-bit
encoding can be used.

Separate "o64nw" into two pieces: opsize 64 and "nw" = "REX.w not necessary". The
latter can be included in non-64-bit patterns. "o64" still set REX.W
since that is still the common thing.

New "osz" bytecode: emit an OSP *or* REX.W depending on the current
mode and operand size. Useful for special cases like "nop" where "o64
nop" probably wants to be encoded as "48 90".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-07 17:13:44 -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
973fe19a1b WIP: apx: now can encode most instructions; handle subcases in EVEX
EVEX encoding is really messy, with the 4th register bit in one of
several places depending on which type of register it is. It seems to
work now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-30 17:03:58 -07:00
H. Peter Anvin
e03b9325e2 parser: tidy up handling of prefixes; allow braced prefix after insn
Clean up the handling of prefixes in general. Allow a set of braced
prefixes to follow the instruction; this is required for things like
{dfv=} but might also be a nicer syntax for things like {rex}.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-24 13:09:36 -07:00
H. Peter Anvin
07cef15235 travis: update the warning message in hle.stderr
Nothing wrong, but the text of the warning message has changed after
subordinating it to another warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-13 20:54:56 -07:00
H. Peter Anvin
73676357de BR 3392906: error out on bad syntax "db 1 2"
NASM would try to "eat the comma token" in db expressions, even for
cases where the token was not a comma. Fix that and error out
properly.

To give better error messages, track where in the input string a token
starts or ends. This information is only valid as long as the input
string is kept, but that is just fine for error messages during
parsing.

Reported-by: Peter Cordes <pcordes@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-11 12:06:58 -07:00
H. Peter Anvin
494d9531dd travis: fix the masmdisp travis test
The masmdisp travis test incorrectly contained an expectation of
error, from the bug fixed in checkin
e0959432fe24c597e0bfb07412276f622d93a4b9.

Fix the test to contain the actually expected output.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-12-07 09:45:36 -08:00
H. Peter Anvin
db6549c5aa preproc: classify warnings, move into common pp-* namespace
Classify all remaining WARN_OTHER warnings in the preprocessor. Move
all preprocessor warnings except "user" under a common pp-* prefix.

Warn for an out-of-range argument to the %sel() function.

Finally, use "dname" in additional places for consistency and future
ease of use.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-14 13:12:01 -08:00
H. Peter Anvin
caffd140c0 asm: factor out more warnings into warning classes
Hopefully we'll eventually get rid of WARN_OTHER completely...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-08 17:50:45 -08:00
H. Peter Anvin
665e5e3da8 travis: update COFF tests to not expect an embedded filename
When doing a reproducible build with COFF, since checkin
e1423b057304b4fc8af7d1fc048ccaa5cc66a2bd the filename is suppressed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 16:18:50 -08:00
Elyes HAOUAS
cdf7ad02c2 Fix some typos
while on it, remove unneeded white spaces.

Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2022-01-09 17:34:35 +01:00
Cyrill Gorcunov
4b5224ba8f test: add dbxsize test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-11-20 23:57:49 +03:00
Cyrill Gorcunov
e2ed7b7e12 x86/insns: add VMGEXIT
The instruction supports two forms with [f2] and [f3].
I guess we might add aliases as VMGEXIT2 and VMGEXIT3.
For now simly leave a second form for ndisasm sake.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 09:14:10 +03:00
Cyrill Gorcunov
c4babdf2db x86/insns: add RMPADJUST
https://bugzilla.nasm.us/show_bug.cgi?id=3392754

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:29:32 +03:00
Cyrill Gorcunov
1430995095 x86/insns: add PVALIDATE
https://bugzilla.nasm.us/show_bug.cgi?id=3392753

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:27:07 +03:00
Cyrill Gorcunov
984761f924 travis: add vmx test
To test VMX instructions.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:25:04 +03:00
Cyrill Gorcunov
aa2dcdec09 travis: add br3392751
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-03 17:59:08 +03:00
H. Peter Anvin
2469b8b66e Add {rex} prefix, simplify prefix handling, better error messages
Add a {rex} prefix to force REX encoding (typically a redundant 40h
prefix).

For prefix parsing, we can use t_inttwo to encode the prefix slot
number.

Give more verbose error messages for encoding mismatches.
2021-04-27 11:37:42 -07:00
Cyrill Gorcunov
6d95cc8d29 travis: add br3392739
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-02-21 01:10:05 +03:00
Cyrill Gorcunov
79ac0d686d Merge branch 'nasm-2.15.xx'
* nasm-2.15.xx:
  preproc: prohibit unmacro while macro expansion
2020-12-31 16:50:25 +03:00
Igor Munkin
f95c7e983c preproc: prohibit unmacro while macro expansion
If macro is undefined while it's being expanded, use after free occurs,
since the MMacro instance is released, but it is still used to proceed
the expansion.

This change forbids macro undefinition: non-fatal error is raised and
the MMacro instance is not released if it is being processed by NASM
preprocessor.

Consider the following example:
| $ cat test.asm
| %macro m 0
| %unmacro m 0
| %endmacro
| m
| $ ./nasm test.asm
| test.asm:4: error: `%unmacro' can't undefine the macro being expanded
| test.asm:2: ... from macro `m' defined here

Fixes BR3392531 and BR3392716.

Signed-off-by: Igor Munkin <imun@cpan.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-12-31 16:42:31 +03:00
Cyrill Gorcunov
dc4a619426 travis: add br3392637
Code for testcase provided by Suhwan.

Reported-by: Suhwan <prada960808@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-11-04 13:15:52 +03:00
Cyrill Gorcunov
e24e18e6b9 travis: add rdpid
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 23:06:45 +03:00
Cyrill Gorcunov
b3233c77fc travis: update avx
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 23:02:45 +03:00
Cyrill Gorcunov
4431776fc0 travis: add imm
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 22:12:02 +03:00
Cyrill Gorcunov
8ff5cecc29 travis: add ilog
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 22:01:21 +03:00
Cyrill Gorcunov
daa534e55c travis: add hle
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
9d68a8babd travis: add hexfp
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
32efe62b81 travis: add gather
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
0137027911 travis: add floatx
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:06 +03:00
Cyrill Gorcunov
ecd704d846 travis: update float test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:40:36 +03:00
Cyrill Gorcunov
e715b61509 travis: add ctxlocal
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:14:59 +03:00
Cyrill Gorcunov
6334ea16ab travis: add cofftest
Lets run it as win32 since they are sharing
backends in most places but win32 is a way
more widely used.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:11:13 +03:00
Cyrill Gorcunov
247e8ef151 travis: add coffalign
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:07:03 +03:00
Cyrill Gorcunov
407fe40f66 travis: add insertps
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 15:57:08 +03:00
Cyrill Gorcunov
84c35517de travis: add masmdisp
It is failing right now so I'm not sure if
masm test is correct one. Lets merge it in
this form and update if needed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 15:52:41 +03:00
Cyrill Gorcunov
c0e2bbc66a travis: add movd64
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 15:37:46 +03:00
Cyrill Gorcunov
5f753b9b0d travis: add movhpd
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 15:33:22 +03:00
Cyrill Gorcunov
7eb3b34ece travis: update nasmformat
No need to generate binaries, just compare
__OUTPUT_FORMAT__ output and add missing
formats.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 15:31:27 +03:00
Cyrill Gorcunov
4bedceb83c travis: add objexe
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 13:00:57 +03:00
Cyrill Gorcunov
31ad91346b travis: add time
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 12:57:08 +03:00
Cyrill Gorcunov
62b8ea045c travis: add selfref
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-11 12:50:08 +03:00
Cyrill Gorcunov
985f30df21 travis: add timesneg
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-10 16:47:36 +03:00
Cyrill Gorcunov
bbed2ce3ce travis: add pragma
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-10 16:43:17 +03:00
Cyrill Gorcunov
e85492c824 travis: add ppindirect
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-10 16:37:00 +03:00
Cyrill Gorcunov
b511da48c1 travis: add nullfile
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-10 16:33:28 +03:00