Commit Graph

5028 Commits

Author SHA1 Message Date
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
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
2e4df506e0 WIP: APX: can now generate code for tested APX instructions
a
Support generating code for APX instruction and add support for the
{nf} prefix.

No disassembler support yet, and only a handful instructions encoded.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-29 20:58:04 -07:00
H. Peter Anvin
f10f278edd nasmlib: add general sign- and zero-extension functions
We use this all over the place, so make these general. The sign
extension function existed as signed_bits(), but that is an awfully
confusing name.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-29 12:54:39 -07:00
H. Peter Anvin
318a0b9244 WIP: apx: byte code and byte code compiler changes
Change the byte code format and the byte code compiler to be able to
generate various kinds of APX-format instructions.

THE NEW BYTE CODES ARE NOT YET IMPLEMENTED IN THE ASSEMBLER OR
DISASSEMBLER.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-28 21:57:31 -07:00
H. Peter Anvin
1618fa745b apx: support parsing special constants like {dfv=}
{dfv=} is basically a constant (immediate). Treat it as such during
parsing, except that if "naked" (not in an expression), it has special
matching properties and does not need a terminal comma.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-28 16:57:24 -07:00
H. Peter Anvin
bdfa9f952d eval: recognize TOKEN_BRCCONST as integers
If TOKEN_BRCCONST are used in an expression (including simply wrapping
them in parentheses), then just treat them as integers.  This makes
things like ({dfv=cf}|{dfv=of}) work.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-27 18:19:35 -07:00
H. Peter Anvin
6389ac8e47 scanner: generalize the handling of {dfv=}
Change the handling of {dfv=} to a more general "braced constant"
expression, to be tagged with an instruction flag to make sure they
match the instruction in question.

This really ought to be an operand flag, but the opflags are precious;
as the CCMP/CTEST instructions can also take an immediate it probably
is necessary to invent a "special immediate" operand type that can
fold these together.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-27 18:06:51 -07:00
H. Peter Anvin
4f0d89dbe6 apx: modify the tokenizer to be able to handle {dfv=...}
The {dfv=} prefix sequences for the CCMP and CTEST instructions need
special handling in the parser. This means a fair bit of new magic in
the handler of the parser, but it just adds to the fun.

Try to make this as general as possible, so we can use it for other
things.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-27 17:57:08 -07:00
H. Peter Anvin
caff3203bc Merge remote-tracking branch 'origin/nasm-2.16.xx' into apx 2024-07-27 17:46:55 -07:00
H. Peter Anvin
699684bf17 Merge remote-tracking branch 'github/nasm-2.16.xx' 2024-07-27 17:45:53 -07:00
H. Peter Anvin
8ef2fa22a2 mkdep: handle breakage from srcdir changes
The handling of "path" and "fullpath" was inconsistent, resulting in a
lot of missing dependencies regardless if a separate build directory
was in use.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-27 17:43:34 -07:00
H. Peter Anvin
7cc9fc4773 stdscan: abstract out the saving/restoring of parser state
The parser state does not just necessarily include the position of the
buffer, but make it possible to maintain additional state.

Furthermore, add an explicit ability to push back a token.

All of this might make it easier at some point in the future to keep
track of horizontal position, although that will require lots of
changes to the preprocessor.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-24 14:15:35 -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
a556ea3edf regs: clean up and somewhat automate register range flags
Doing the register range flags by hand is a bit more work than
necessary when dealing with APX, so auto-generate the flags for ranges
{0, 1-15, 16+} using 3 bits.

In theory we could handle even more automagically by splitting ranges
up further: the existing ranges are sets of {0, 1, 2, 3, 4-5, 6-7,
8-15, 16-31} which would require 7 bits, although it would remove most
of the subclass bits for registers; it would require separating the
subclass bits for EAs from the ones for registers (which might be a
good idea anyway...)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-07-23 16:04:47 -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
77df155c70 .editorconfig: hard tabs are still 8 spaces
The hard tab character is 8 spaces, that's just how it is.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 21:12:52 -07:00
H. Peter Anvin
a1e3140808 doc: fix the equivalent description for %cond()
%cond(x,y,z) == %sel(1+!(x),y,z), not %sel(2-!(x),y,z).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-01 17:30:27 -07:00
Yegor Yefremov
9d38bed4d2 Add EditorConfig support
Provide common indentation configuration for the source files.

For more information, visit https://editorconfig.org/.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2024-05-31 11:11:41 -07:00
H. Peter Anvin
aa03a95edd doc: improve the build from source documentation
Update and improve the build from source documentation, including add
an auto-generated list of Perl build dependencies.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-05-20 10:54:26 -07:00
H. Peter Anvin
2e0212bcd3 doc/rdsrc.pl: add \w{...} to reduce the verbosity of web links
Create a shorthand for a web link where the URL itself is also the text.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-05-20 10:31:57 -07:00
Cyrill Gorcunov
0421148e33 doc/nasmdoc.src: fix typo in web link
Reported-by: Danny Cohen <dannycoh@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2024-05-01 21:54:17 +03:00
H. Peter Anvin
68999937f3 doc/nasmdoc.css: @media only print -> @media print
There is no point in using "only" unless there is another
qualifier. The "only" is specifically to prevent older parsers from
unconditionally applying a section with qualifiers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-25 15:42:25 -07:00
H. Peter Anvin
6165d6c014 Merge remote-tracking branch 'github/nasm-2.16.xx'
Resolved Conflicts:
	doc/changes.src
2024-04-25 15:37:36 -07:00
H. Peter Anvin
68d59933f7 doc/changes.src: begin release notes for 2.16.04.
Better to keep up with it now...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-25 15:36:25 -07:00
H. Peter Anvin
cd1fd8ac8e nasm.c: tidy up the help text and break it into topics
The help output has gotten way too long to be shown on a single
command line. It can of course be piped to a pager, but to be a little
nicer to the user, break it up into subtopics that can be individually
displayed. --help all (-h all) can still show all the help information
as a single data dump.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-25 15:14:20 -07:00
H. Peter Anvin
3334c3c2dc Merge remote-tracking branch 'github/nasm-2.16.xx' 2024-04-18 15:32:59 -07:00
H. Peter Anvin
2553833cc1 nasm.spec.in: fix mistakes in previous checkin
Fix small mistakes in previous nasm.spec.in patch.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-18 15:31:51 -07:00
H. Peter Anvin
0537b16fdc doc: fix tag label for cl-2.16.03
cl-2.16.03 was incorrectly marked as a dup of cl-2.16.02.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-18 15:30:31 -07:00
H. Peter Anvin
843976d343 Merge remote-tracking branch 'github/nasm-2.16.xx'
Resolved Conflicts:
	autoconf/m4/pa_add_langflags.m4
	autoconf/m4/pa_option_lto.m4
	autogen.sh
	configure.ac
	doc/changes.src
2024-04-18 15:25:48 -07:00
H. Peter Anvin
0346e58b6e nasm.spec.in: add Obsoletes tags where applicable; fix License tag
Add Obsoletes tags: nasm-rdoff; old nasm-doc.

Add a few BuildRequires: tags.

Update License: tag to match SPDX.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2024-04-18 14:01:40 -07:00