Commit Graph

5058 Commits

Author SHA1 Message Date
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
H. Peter Anvin
557d99d796 insns: more macro goodness
Even better macro support, add match for the BX register.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 20:48:18 -07:00
H. Peter Anvin
1b136eb543 insns: use the pre-existing instruction flags handler for preinsns.pl
There is no reason to reinvent the wheel; reusing the existing code
will be cleaner anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 16:45:09 -07:00
H. Peter Anvin
3b55b62f02 apx: implement the mechanism for evex.zu
Implement the mechanism needed to handle {zu} suffixes that actually
set ND (IMUL, SETcc).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 15:44:38 -07:00
H. Peter Anvin
b31f82bf79 insns.dat: add APX SETcc, fix a few more patterns
Add patterns for APX SETcc; fix a few more patterns to work with the
new matcher algorithm.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-14 15:17:24 -07:00
H. Peter Anvin
cb8ca3bb95 insns.pl: for scc encodings, add null string = true
Allow the null string encoding for "true" for scc instructions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 03:16:09 -07:00
H. Peter Anvin
3d24dc6fb9 x86/preinsns.pl: use //g matching instead of split+grep
//g matching is a much better way to positively define tokens. Learn
something new every day!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 02:44:54 -07:00
H. Peter Anvin
b205311fa2 x86/preinsns.pl: correctly handle quoted commas
Don't break a string on a quoted comma, for obvious reasons. Allow an
op argument to be quoted in general.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 02:06:54 -07:00
H. Peter Anvin
7ecc9c1f9c insns.dat: more macro feature improvements; now can generate shiftX
Add more improvements to the macro features. Now it is possible to
generate the -X versions of the shift instructions as part of the
macroization, which is highly desirable in order to allow them to be
generated using {nf} syntax.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 01:32:17 -07:00
H. Peter Anvin
d5f981e035 WIP: insns.dat: further improve macro facility; use for APX and shifts
Work more on the macro facility. Add the ability to kill an
instruction pattern based on expansion (if the token KILL appears.)
Add APX patterns to the arithmetic macro and macroize the shift and
rotate patterns.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-12 00:28:04 -07:00
H. Peter Anvin
4bb1bc8fe6 x86/preinsns.pl: make the macro facility more general
Make the macro facility in preinsns.pl more general, and relying less
on evaluating Perl constructs. This *might* be practical with some
more work, to move to a data file, but wait until we have a better
idea of the needs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 23:12:25 -07:00
H. Peter Anvin
b6407947a0 test: add some new simple tests
Some simple tests used during debugging; no reason not to keep them
around.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 21:35:58 -07:00
H. Peter Anvin
67339f6965 insns: rename addflags.pl to preinsns.pl; use insns.xda for doc
The former addflags.pl now does more general preprocessing, so rename
it from addflags.pl to preinsns.pl.

To generate the instruction list in the documentation, use the
post-preprocessed insns.xda file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-11 21:34:02 -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
f13bad288b assemble.c: set ins->op_size for byte code "osz"
When encountering byte code "osz", set ins->op_size accordingly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-07 17:33: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
7eb0045c5d Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	asm/assemble.c
	asm/parser.c
	include/nasm.h

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 23:55:42 -07:00
H. Peter Anvin
86142b00e1 assemble: limit-check operand references
Don't do an out-of-range check for the operands, even
temporarily. Setting the operand pointer to NULL will help catch
errors when accessing non-operands, too.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 23:45:20 -07:00
H. Peter Anvin
19a6fca486 insns.dat: add MOVSX -> CBW/CWDE/CDQE optimiztion; add MOVZX[D]
Add MOVSX[D] -> CBW/CWDE/CDQE optimization patterns when the suitable
form of the AX register are referenced.

Add MOVZX reg64,rm32 pattern which converts to a 32-bit MOV.

Add MOVZXD reg64,rm32 alias pattern for consistency.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 16:29:08 -07:00
H. Peter Anvin
de84c3dcc0 insns.h: update the prototype for the disassembly root table
The disassembly table is now totally different, so update the header
file accordingly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 16:13:14 -07:00
H. Peter Anvin
d49f49b04c Makefile.in: fix "make cleaner"/"make spotless"
Generated files $(PERLREQ_CLEANABLE) never got cleaned up due to an
incorrect reference.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 16:07:52 -07:00
H. Peter Anvin
e1a912308e Makefile.in: change .dax -> .xda to unbreak tab completion
.dat versus .dax is annoying for tab completion, change the extension
for the preprocessed insns.dat to .xda.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 16:04:16 -07:00
H. Peter Anvin
065f60f062 insns.dat: add {nf} forms of the non-flag-modifying -x instructions
For the instructions ending in -x because they don't modify the flags,
also accept {nf}. Add 2-operand relaxed versions like for most other
instructions, too.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 16:01:00 -07:00
H. Peter Anvin
804a1f215b x86/addflags.pl: for instructions with explicit NF, don't add FL
For instructions explicitly tagged NF, don't add an FL
annotation. Used for things like ror{nf} -> rorx.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 15:58:48 -07:00
H. Peter Anvin
d55f780b96 insns.pl: fix the types for the disassembly tables
Make sure to get the right type for the disassembly tables. This is
now a fixed-depth tree, so there is no reason to use union types or
anything along those lines.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-04 15:57:14 -07:00
H. Peter Anvin
84f2553d7f x86/insns.pl: redo the way tables are generated for disassembly
Change the generation of tables for disassembly to be map-based. This
also makes the code a bit more regular.

This is the first step at catching up with APX support in the
disassembler.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 21:24:59 -07:00
H. Peter Anvin
c79b6a97f0 insns.dat: script to auto-generate ZU and FL flags
These are mostly structured. Leave this as an explicit processing
step, at least until the correctness of these flags have been fully
verified; perhaps after that as well.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 19:07:57 -07:00
H. Peter Anvin
5225d57cd7 Correctly handle instruction masking based on {zu} flag
Fix instruction masking based on {zu} flag.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 18:54:13 -07:00
H. Peter Anvin
dc76618f5d insns.pl: don't generate NDD ZU patterns if not necessary
If the patterns are inherently ZU, then there is no reason to also
generate NDD forms.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 18:18:11 -07:00
H. Peter Anvin
c2eade6379 insns.pl: fix the generation of NDD patterns for {zu}
When specified with {zu}, allow generation of NDD patterns if
applicable.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-03 18:05:51 -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
b5e613fdf8 Allow more flexiblity for {nf} and {zu}
The {nf} and {zu} prefixes (or suffixes) can be used on a number of
instructions without actually change the encodings (either they don't
touch the flags at all, or they write a 32- or 64-bit register
already.)

Make this a bit more flexible, by adding an FL instruction flag for
the instructions which actually touch the flags, and a ZU instruction
flag for the instructions which zero the upper half.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-31 17:23:06 -07:00
H. Peter Anvin
b32f572f2d insns.dat: tag instructions from REX2-excluded opcode spaces as NOAPX
For the instruction space that are explicitly excluded by REX2, add
NOAPX tags. This was done with an automated script.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-31 16:46:53 -07:00
H. Peter Anvin
8c4ccba365 insns.dat: mark a few old Cyrix instructions obsolete
Mark a few old Cyrix instructions obsolete that conflict with opcode
map prefixes.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-31 16:43:38 -07:00
H. Peter Anvin
dda9152b35 apx: smarter determination of REX2 prefix eligibility
REX2 encoding is mostly default, so flag the instruction patters which
do *not* support REX2 instead.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-31 16:18:17 -07:00
H. Peter Anvin
fd08822070 apx: implement JMPABS
Implement the JMPABS instruction, which can also be specified as JMP
ABS for consistency. Since ABS is already a keyword, this does not
pollute the namespace.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-30 17:32:00 -07:00