Commit Graph

4351 Commits

Author SHA1 Message Date
Richard Sandiford
4eede8c244 aarch64: Prefer register ranges & support wrapping
Until now, binutils has supported register ranges such
as { v0.4s - v3.4s } as an unofficial shorthand for
{ v0.4s, v1.4s, v2.4s, v3.4s }.  The SME2 ISA embraces this form
and makes it the preferred disassembly.  It also embraces wrapped
lists such as { z31.s - z2.s }, which is something that binutils
didn't previously allow.

The range form was already binutils's preferred disassembly for 3- and
4-register lists.  This patch prefers it for 2-register lists too.
The patch also adds support for wrap-around.
2023-03-30 11:09:10 +01:00
Richard Sandiford
f5b57feac2 aarch64: Add support for strided register lists
SME2 has instructions that accept strided register lists,
such as { z0.s, z4.s, z8.s, z12.s }.  The purpose of this
patch is to extend binutils to support such lists.

The parsing code already had (unused) support for strides of 2.
The idea here is instead to accept all strides during parsing
and reject invalid strides during constraint checking.

The SME2 instructions that accept strided operands also have
non-strided forms.  The errors about invalid strides therefore
take a bitmask of acceptable strides, which allows multiple
possibilities to be summed up in a single message.

I've tried to update all code that handles register lists.
2023-03-30 11:09:10 +01:00
Richard Sandiford
b5c36ad2e0 aarch64: Sort fields alphanumerically
This patch just sorts the field enum alphanumerically, which makes
it easier to see if a particular field has already been defined.
2023-03-30 11:09:09 +01:00
Richard Sandiford
ccb6da7c82 aarch64: Resync field names
This patch just makes the comments in aarch64-opc.c:fields match
the names of the associated FLD_* enum.
2023-03-30 11:09:09 +01:00
Richard Sandiford
1d1060427d aarch64: Regularise FLD_* suffixes
Some FLD_imm* suffixes used a counting scheme such as FLD_immN,
FLD_immN_2, FLD_immN_3, etc., while others used the lsb as the
suffix.  The latter seems more mnemonic, and was a big help
in doing the SME2 work.

Similarly, the _10 suffix on FLD_SME_size_10 was nonobvious.
Presumably it indicated a 2-bit field, but it actually starts
in bit 22.
2023-03-30 11:09:09 +01:00
Richard Sandiford
199cfcc475 aarch64: Add a aarch64_cpu_supports_inst_p helper
Quite a lot of SME2 instructions have an opcode bit that selects
between 32-bit and 64-bit forms of an instruction, with the 32-bit
forms being part of base SME2 and with the 64-bit forms being part
of an optional extension.  It's nevertheless useful to have a single
opcode entry for both forms since (a) that matches the ISA definition
and (b) it tends to improve error reporting.

This patch therefore adds a libopcodes function called
aarch64_cpu_supports_inst_p that tests whether the target
supports a particular instruction.  In future it will depend
on internal libopcodes routines.
2023-03-30 11:09:09 +01:00
Richard Sandiford
d09b87e0b1 aarch64: Reorder some OP_SVE_* macros
This patch just moves some out-of-order-looking OP_SVE_* macros.
2023-03-30 11:09:09 +01:00
Richard Sandiford
56723f6934 aarch64: Rename aarch64-tbl.h OP_SME_* macros
This patch renames the OP_SME_* macros in aarch64-tbl.h so that
they follow the same scheme as the OP_SVE_* ones.  It also uses
OP_SVE_ as the prefix, since there is no real distinction between
the SVE and SME uses of qualifiers: a macro defined for one can
be useful for the other too.
2023-03-30 11:09:08 +01:00
Richard Sandiford
b5b4f66545 aarch64: Try to report invalid variants against the closest match
If an instruction has invalid qualifiers, GAS would report the
error against the final opcode entry that got to the qualifier-
checking stage.  It seems better to report the error against
the opcode entry that had the closest match, just like we
pick the closest match within an opcode entry for the
"did you mean this?" message.

This patch adds the number of invalid operands as an
argument to AARCH64_OPDE_INVALID_VARIANT and then picks the
AARCH64_OPDE_INVALID_VARIANT with the lowest argument.
2023-03-30 11:09:08 +01:00
Richard Sandiford
38c5aa5e88 aarch64: Make AARCH64_OPDE_REG_LIST take a bitfield
AARCH64_OPDE_REG_LIST took a single operand that specified the
expected number of registers.  However, there are quite a few
SME2 instructions that have both 2-register forms and (separate)
4-register forms.  If the user tries to use a 3-register list,
it isn't obvious which opcode entry they meant.  Saying that we
expect 2 registers and saying that we expect 4 registers would
both be wrong.

This patch therefore switches the operand to a bitfield.  If a
AARCH64_OPDE_REG_LIST is reported against multiple opcode entries,
the patch ORs up the expected lengths.

This has no user-visible effect yet.  A later patch adds more error
strings, alongside tests that use them.
2023-03-30 11:09:08 +01:00
Richard Sandiford
db3c06bf93 aarch64: Add an operand class for SVE register lists
SVE register lists were classified as SVE_REG, since there had been
no particular reason to separate them out.  However, some SME2
instructions have tied register list operands, and so we need to
distinguish registers and register lists when checking whether two
operands match.

Also, the register list operands used a general error message,
even though we already have a dedicated error code for register
lists that are the wrong length.
2023-03-30 11:09:07 +01:00
Richard Sandiford
56ead579a5 aarch64: Commonise checks for index operands
This patch splits out the constraint checking for index operands,
so that it can be reused by new SME2 operands.
2023-03-30 11:09:07 +01:00
Richard Sandiford
859f51df4d aarch64: Add an error code for out-of-range registers
libopcodes currently reports out-of-range registers as a general
AARCH64_OPDE_OTHER_ERROR.  However, this means that each register
range needs its own hard-coded string, which is a bit cumbersome
if the range is determined programmatically.  This patch therefore
adds a dedicated error type for out-of-range errors.
2023-03-30 11:09:07 +01:00
Richard Sandiford
7da28504bf aarch64: Move w12-w15 range check to libopcodes
In SME, the vector select register had to be in the range
w12-w15, so it made sense to enforce that during parsing.
However, SME2 adds instructions for which the range is
w8-w11 instead.

This patch therefore moves the range check from the parsing
stage to the constraint-checking stage.

Also, the previous error used a capitalised range W12-W15,
whereas other register range errors used lowercase ranges
like p0-p7.  A quick internal poll showed a preference for
the lowercase form, so the patch uses that.

The patch uses "selection register" rather than "vector
select register" so that the terminology extends more
naturally to PSEL.
2023-03-30 11:09:05 +01:00
Richard Sandiford
ff60bcbfbe aarch64: Move ZA range checks to aarch64-opc.c
This patch moves the range checks on ZA vector select offsets from
gas to libopcodes.  Doing the checks there means that the error
messages contain the expected range.  It also fits in better
with the error severity scheme, which becomes important later.
(This is because out-of-range indices are treated as more severe than
syntax errors, on the basis that parsing must have succeeded if we get
to the point of checking the completed opcode.)

The patch also adds a new check_za_access function for checking
ZA accesses.  That's a bit over the top for one offset check, but the
function becomes more complex with later patches.

sme-9-illegal.s checked for an invalid .q suffix using:

  psel p1, p15, p3.q[w15]

but this is doubly invalid because it misses the immediate part
of the index.  The patch keeps that test but adds another with
a zero index, so that .q is the only thing wrong.

The aarch64-tbl.h change includes neatening up the backslash
positions.
2023-03-30 11:09:05 +01:00
Richard Sandiford
c888354c61 aarch64: Make indexed_za use 64-bit immediates
A later patch moves the range checking for ZA vector select
offsets from gas to libopcodes.  That in turn requires the
immediate field to be big enough to support all parsed values.

This shouldn't be a particularly size-sensitive structure,
so there should be no memory problems with doing this.
2023-03-30 11:09:04 +01:00
Richard Sandiford
575c497a4a aarch64: Rename za_tile_vector to za_index
za_tile_vector is also used for indexing ZA as a whole, rather than
just for indexing tiles.  The former is more common than the latter
in SME2, so this patch generalises the name to "indexed_za".

The patch also names the associated structure, so that later patches
can reuse it during parsing.
2023-03-30 11:09:04 +01:00
Richard Sandiford
e9e1ddbb98 aarch64: Treat ZA as a register
We already treat the ZA tiles ZA0-ZA15 as registers.  This patch
does the same for ZA itself.  parse_sme_zero_mask can then parse
ZA tiles and ZA in the same way, through parsed_type_reg.

One important effect of going through parsed_type_reg (in general)
is that it allows ZA to take qualifiers.  This is necessary for many
SME2 instructions.

However, to support existing unqualified uses of ZA, parse_reg_with_qual
needs to treat the qualiier as optional.  Hopefully the net effect is
to give better error messages, since now that SME2 makes "za.<T>"
valid in some contexts, it might be natural to use it (incorrectly)
in ZERO too.

While there, the patch also tweaks the error messages for invalid
ZA tiles, to try to make some cases more specific.

For now, parse_sme_za_array just uses parse_reg, rather than
parse_typed_reg/parse_reg_with_qual.  A later patch consolidates
the parsing further.
2023-03-30 11:09:04 +01:00
Richard Sandiford
a5791d5814 aarch64: Make SME instructions use F_STRICT
This patch makes all SME instructions use F_STRICT, so that qualifiers
have to be provided explicitly rather than being inferred from other
operands.  The main change is to move the qualifier setting from the
operand-level decoders to the opcode level.

This is one step towards consolidating the ZA parsing code and
extending it to handle SME2.
2023-03-30 11:09:02 +01:00
Richard Sandiford
89f55b440a aarch64: Restrict range of PRFM opcodes
In the register-index forms of PRFM, the unallocated prefetch opcodes
24-31 have been reused for the encoding of the new RPRFM instruction.
The PRFM opcode space is now capped at 23 for these forms.  The other
forms of PRFM are unaffected.
2023-03-30 11:09:02 +01:00
Richard Sandiford
d346e1aafd aarch64: Fix PSEL opcode mask
The opcode mask for PSEL was missing some bits, which meant
that some upcoming SME2 opcodes would be misinterpreted as PSELs.
2023-03-30 11:09:02 +01:00
Richard Sandiford
78addeae53 aarch64: Add sme-i16i64 and sme-f64f64 aliases
Most extension flags are named after the associated architectural
FEAT_* flags, but sme-i64 and sme-f64 were exceptions.  This patch
adds sme-i16i64 and sme-f64f64 aliases, but keeps the old names too
for compatibility.
2023-03-30 11:09:01 +01:00
Jiawei
e43d8768d9 RISC-V: Fix disassemble fetch fail return value.
This bug reported in
https://sourceware.org/bugzilla/show_bug.cgi?id=30184
And discussed in
https://sourceware.org/pipermail/binutils/2023-February/126213.html

We also checked the implementation of return value in arm and mips.
So this patch changes the return value to -1, that can fix bugs and maintain
consistency with other architectures.

opcodes/ChangeLog:

        * riscv-dis.c (print_insn_riscv):Change the return value.
2023-03-21 17:47:47 +08:00
Jan Beulich
3f155099ad x86: drop "shimm" special case template expansions
With VexVVVV only being boolean, the SSE shift-by-immediate instructions
don't need special casing anymore for SSE2AVX handling. Simplify the two
respective templates. (No change to generated tables.)
2023-03-20 16:57:19 +01:00
Jan Beulich
eea96d3f86 x86: VexVVVV is now merely a boolean
With the SDM long having dropped the NDS/NDD/DDS concept of identifying
encoding variants, we can finally do away with this concept as well. Of
the few consumers of the attribute, only an assertion was still checking
for a particular value, which we don't really need to retain.

When touching lines anyway, modernize other aspects as well. This often
improves similarity to adjacent lines.
2023-03-20 16:56:53 +01:00
Jan Beulich
ecb96e5549 x86: re-work build_modrm_byte()'s register assignment
The function has accumulated a number of special cases for no real
reason. Some were necessary because insn attributes (SwapSources in
particular) weren't suitably utilized instead. Note that the addition of
SwapSources actually increases consistency among the templates: Like
others which already have the attribute, these are all insns where the
VEX.VVVV-encoded register comes first (or last when looking at the SDM).

Note that the vexvvvv attribute now has merely boolean meaning anymore,
in line with the SDM long having dropped the NDS/NDD/DDS concept of
identifying encoding variants. The fallout will be taken care of
subsequently, though, to not further clutter the change here.

As to the TILEZERO special case: If more instructions like this
appeared, a new attribute would likely be the way to go. But as long as
it's only a single insn, going from the mnemonic is cheaper.
2023-03-20 16:56:24 +01:00
Alan Modra
834e4d7162 Revert "segfault at i386-dis.c:9815"
This reverts commit 92d450c79a.

Accessing these local var structs using a volatile qualified pointer
may indeed read the object, but I don't think changed values are
guaranteed to be written back to the object unless the actual object
is declared volatile.  That would probably slow down i386 disassembly
unacceptably.
2023-03-20 21:02:14 +10:30
Alan Modra
92d450c79a segfault at i386-dis.c:9815
* i386-dis.c (print_insn): Access "ins" and "priv" via volatile
	pointers after second sigsetjmp return.
2023-03-19 23:35:18 +10:30
Alan Modra
3e8b13bf77 cpu/mem.opc whitespace tidy
cpu/
	* mep.opc: Whitespace and formatting.
opcodes/
	* mep-asm.c: Regenerate.
	* mep-dis.c: Regenerate.
2023-03-16 17:30:19 +10:30
Nick Clifton
71f646f2b3 Fix an illegal memory access when disassembling a corrupt MeP file.
PR 30231
  * mep.opc (mep_print_insn): Check for an out of range index.
2023-03-15 13:06:23 +00:00
Nick Clifton
7718604518 Fix an illegal memory access when disassebling a corrupt ARM file.
PR 30230
  * arm-dis.c (get_sym_code_type): Check for non-ELF symbols.
2023-03-15 11:44:56 +00:00
Richard Ball
31f2faf5cf [Aarch64] Add Binutils support for MEC
This change supports MEC which is part of RME (Realm Management Extension).
2023-02-28 10:55:25 +00:00
Nick Clifton
85b922fcdd Updated Serbian translations for gold, gprof and opcodes sub-directories 2023-02-27 12:50:31 +00:00
Andrew Burgess
82341e9798 opcodes/m68k: enable libopcodes styling for GDB
The following commit added libopcodes styling for m68k:

  commit c22ff44927
  Date:   Tue Feb 14 18:07:19 2023 +0100

      opcodes: style m68k disassembler output

but didn't set disassemble_info::created_styled_output in
disassemble.c, which is needed in order for GDB to start using the
libopcodes based styling.

This commit fixes this small oversight.  GDB now styles correctly.
2023-02-25 10:20:01 +00:00
Jan Beulich
cafa5ef72e x86: MONITOR/MWAIT are not SSE3 insns
These have their own CPUID bit and hence they should also have their own
separate control.
2023-02-24 13:59:35 +01:00
Jan Beulich
c3bb24f566 x86-64: don't permit LAHF/SAHF with "generic64"
The feature isn't universally available on 64-bit CPUs.

Note that in i386-gen.c:isa_dependencies[] I'm only adding it to models
where I'm certain the functionality exists. For Nocona and Core I'm
uncertain in particular.
2023-02-24 13:58:35 +01:00
Jan Beulich
5eeeafe0a6 x86: have insns acting on segment selector values allow for consistent operands
While MOV to/from segment register as well as selector storing insns
already permit 32- and 64-bit GPR operands, selector loading insns and
ARPL do not. Split templates accordingly.
2023-02-24 13:57:31 +01:00
Jan Beulich
c34d1cc920 x86: restrict insn templates accepting negative 8-bit immediates
For shifts (but not ordinary rotates) and other cases where an immediate
describes e.g. a bit count or position, allowing negative operands is at
best confusing. An extreme example would be the two rotate-through-carry
insns, where a negative value would _not_ mean rotating the
corresponding number of bits in the other direction. To refuse such,
give meaning to the combination of Imm8 and Imm8S in templates (so far
these weren't used together anywhere). The issue was with
smallest_imm_type() blindly setting .imm8 for signed numbers determined
to fit in a byte.

VPROT{B,W,D,Q} is a little special: The rotate count there is a signed
quantity, so Imm8 is replaced by Imm8S. Adjust affected testcases
accordingly as well.

Another small adjustment to the testsuite is necessary: AAM and AAD were
never sensible to use with 0xffffff90 operands. This should have been an
error.
2023-02-24 13:56:57 +01:00
Jan Beulich
ba25141c1e x86-64: LAR and LSL don't need REX.W
Just like we suppress emitting REX.W for e.g. MOV from/to segment
register, there's also no need for it for LAR and LSL - these can only
ever return 32-bit values and hence always zero-extend their results
anyway.

While there also drop the redundant Word from the first operand of
the second template each - this is already implied by Reg16.
2023-02-22 14:12:52 +01:00
Jan Beulich
ad2f443680 x86: optimize BT{,C,R,S} $imm,%reg
In 64-bit mode BT can have REX.W or a data size prefix dropped in
certain cases. Outside of 64-bit mode all 4 insns can have the data
size prefix dropped in certain cases.
2023-02-22 14:12:24 +01:00
Andreas Schwab
c22ff44927 opcodes: style m68k disassembler output 2023-02-20 19:39:01 +01:00
Jan Beulich
676dcbb0a0 x86: {LD,ST}TILECFG use an extension opcode
It being zero and happening to work right now doesn't mean the insns
shouldn't be spelled out properly.
2023-02-14 08:34:42 +01:00
Michael Matz
25a0d393c7 PR30120: fix x87 fucomp misassembled
this fixes the entry for 'fucomp' to use the correct Reg value
(otherwise it's assembled as 'fucom').
2023-02-13 18:41:05 +01:00
Andrew Burgess
77be725744 opcodes/mips: disassemble unknown micromips instructions as two shorts
Before commit:

  commit 2438b771ee
  Date:   Wed Nov 2 15:53:43 2022 +0000

      opcodes/mips: use .word/.short for undefined instructions

unknown 32-bit microMIPS instructions were disassembled as a raw
32-bit number with no '.word' directive.  The above commit changed
this and added a '.word' directive before the 32-bit number.

It was pointed out on the mailing list, that for microMIPS it would be
better to display such 32-bit instructions using a '.short' directive
followed by two 16-bit values.

This commit updates the mips disassembler to do this, and adds a new
test that validates this output.
2023-02-13 12:05:32 +00:00
Jan Beulich
aa1807419b x86: drop use of VEX3SOURCES
The attribute really specifies that the sum of register and memory
operands is 4. Express it like that in most places, while using the 2nd
(apart from XOP) CPU feature flags (FMA4) in reversed operand matching
logic.

With the use in build_modrm_byte() gone, part of an assertion there
also becomes meaningless - simplify that at the same time.

With all uses of the opcode modifier field gone, also drop that.
2023-02-10 08:15:11 +01:00
Jan Beulich
5dab1799d7 x86: drop use of XOP2SOURCES
The few XOP insns which used it wrongly didn't have VexVVVV specified.
With that added, the only further missing piece to use more generic code
elsewhere is SwapSources - see e.g. the BMI2 insns for similar operand
patterns.

With the only users gone, drop the #define as well as the special case
code.
2023-02-10 08:14:46 +01:00
Jan Beulich
ba3ffa6de0 x86: limit use of XOP2SOURCES
The VPROT* forms with an immediate operand are entirely standard in the
way their ModR/M bytes are built. There's no reason to invoke special
case code. With that the handling of an immediate there can also be
dropped; it was partially bogus anyway, as in its "no memory operands"
portion it ignores the possibility of an immediate operand (which was
okay only because that case was already handled by more generic code).
2023-02-10 08:14:27 +01:00
Jan Beulich
ddb6249593 x86: move (and rename) opcodespace attribute
This really isn't a "modifier" and rather ought to live next to the base
opcode anyway. Use the bits we presently have available to fit in the
field, renaming it to opcode_space. As an intended side effect this
helps readability at the use sites, by shortening the references quite a
bit.

In generated code arrange for human readable output, by using the
SPACE_* constants there rather than raw numbers. This may aid debugging
down the road.
2023-02-10 08:10:38 +01:00
Guillermo E. Martinez
7f6ebecd56 bpf: fix error conversion from long unsigned int to unsigned int [-Werror=overflow]
Regenerating BPF target using the maintainer mode emits:
.../opcodes/bpf-opc.c:57:11: error: conversion from ‘long unsigned int’ to ‘unsigned int’ changes value from ‘18446744073709486335’ to ‘4294902015’ [-Werror=overflow]
  57 |   64, 64, 0xffffffffffff00ff, { { F (F_IMM32) }, { F (F_OFFSET16) }, { F (F_SRCLE) }, { F (F_OP_CODE) }, { F (F_DSTLE) }, { F (F_OP_SRC) }, { F (F_OP_CLASS) }, { 0 } }

The use of a narrow size to handle the mask CGEN in instruction format
is causing this error.  Additionally eBPF `call' instructions
constructed by expressions using symbols (BPF_PSEUDO_CALL) emits
annotations in `src' field of the instruction, used to identify BPF
target endianness.

cpu/
	* bpf.cpu (define-call-insn): Remove `src' field from
	instruction mask.

include/
	*opcode/cge.h (CGEN_IFMT): Adjust mask bit width.

opcodes/
	* bpf-opc.c: Regenerate.
2023-02-03 11:18:50 -06:00
Jan Beulich
0655669b86 RISC-V: don't disassemble unrecognized insns as .byte
Insn width granularity being 16 bits, producing byte granular output
isn't very useful. With there being a way to specific otherwise
unknown insns to the assembler, use that same representation (to be
precise: its <length>,<encoding> flavor) for disassembly.
2023-02-03 08:20:32 +01:00