Commit Graph

4410 Commits

Author SHA1 Message Date
H.J. Lu
0d29b1a462 x86: Disable 2 tests with large memory requirement
gas/

	* testsuite/gas/i386/i386.exp: Disable rept.

ld/

	* testsuite/ld-x86-64/x86-64.exp: Disable pr17618.
2022-04-27 11:51:35 -07:00
Jan Beulich
36b124126b x86: VFPCLASSSH is Evex.LLIG
This also was mistakenly flagged as Evex.128.
2022-04-27 11:08:57 +02:00
Jan Beulich
1db5a7fe0b x86: reject all invalid SAE variants
So far an SAE-only specifier was accepted for static-rounding insns,
while SAE-only insns didn't accept static rounding specifiers. If
anything it would make sense the other way around, allowing SAE-only
insns to have the (ignored) rounding mode specified individually rather
than globally via -mevexrcig=. But for now make things match the SDM.
2022-04-20 16:56:05 +02:00
Alan Modra
c64242d8ab Revert "as: Reject unknown -gXXX option" testsuite
This reverts the test committed as part of 6ea673e2d6.
2022-04-20 23:47:19 +09:30
H.J. Lu
6ea673e2d6 as: Reject unknown -gXXX option
* as.c (parse_args): Reject unknown -gXXX option.
	* testsuite/gas/all/empty.s: New file.
	* testsuite/gas/all/pr29067.d: Likewise.
	* testsuite/gas/all/pr29067.err: Likewise.
	* testsuite/gas/all/gas.exp: Run pr29067.
2022-04-19 10:35:41 -07:00
Jan Beulich
2aaee75f81 x86: don't mistake ordinary immediates for SAE / rounding control
The way SAE templates are constructed was always puzzling me (including
the need for separate templates in the first place), and expressing the
extzra attribute via Imm8 actually has a bad effect: Ordinary immediates
would also be accepted, leading to an extra byte being added after the
instruction (i.e. generating bad code). Before re-working this (in
particular to accept proper Intel syntax there), fix the immediate issue
by adding the so far missing check.
2022-04-19 09:26:17 +02:00
Jan Beulich
bb80cf5b42 x86: VCMPSH is Evex.LLIG
These were mistakenly flagged as Evex.128. Getting the LLIG status right
for insns allowing for SAE is a prereq for planned further work.
2022-04-19 09:25:25 +02:00
Jan Beulich
b097040238 x86/Intel: test non-legacy VCVT{,U}SI2SH insn forms
For an unclear reason corresponding AVX512F tests were apparently not
cloned or used as reference here, and instead the bogus legacy forms of
the insns (with the embedded rounding specifier not last) were used.
2022-04-19 09:24:24 +02:00
Jan Beulich
2f399d995b x86: correct and simplify NOP disassembly
It's not just REX.W which is ignored with opcode 0x90. The same goes for
REX.R and REX.X as well as empty REX. None of these are forms of
"xchg %eax,%eax" (which would mean zero-extending %eax to %rax), so they
also shouldn't be disassembled this way.

While there simplify things: A single hook function suffices, thus
making it unnecessary to keep two expressions in sync. And checking
ins->address_mode for mode_64bit also is unnecessary, as "rex" can be
non-zero only in that case anyway.
2022-04-19 09:23:49 +02:00
Jan Beulich
657edeab38 gas: further adjust file/line handling for .macro
Commit 7992631e8c ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .macro, has
undue effects when the logical file/line pair was already overridden:
Line numbers would continuously increment while processing the expanded
macro, while the goal of the PR gas/16908 workaround is to keep the
expansion associated with the line invoking the macro. However, as soon
as enough state was overridden _inside_ the macro to cause as_where() to
no longer fall back top as_where_physical(), honor this by resuming the
bumping of the logical line number.

Note that from_sb_is_expansion's initializer was 1 for an unknown
reason. While renaming the variable and changing its type, also change
the initializer to "expanding_none", which would have been "0" in the
original code. Originally the initializer value itself wasn't ever used
anyway (requiring sb_index != -1), as it necessarily had changed in
input_scrub_include_sb() alongside setting sb_index to other than -1.

Strictly speaking input_scrub_insert_line() perhaps shouldn't use
expanding_none, yet none of the other enumerators fit there either. And
then strictly speaking that function probably shouldn't exist in the
first place. It's used only by tic54x.
2022-04-12 09:03:43 +02:00
Jan Beulich
2ee1792bec gas: further adjust file/line handling for .irp and alike
Commit 7992631e8c ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .irp et al,
has undue effects when the logical file/line pair was already
overridden: Line numbers would continuously increment upon every
iteration, thus potentially getting far off. Furthermore it left it to
the user to actually insert .file/.line inside such constructs. Note
though that before aforementioned change things weren't pretty either:
Diagnostics (and debug info) would be associated with the directive
terminating the iteration construct, rather than with the actual lines.

Handle this automatically by simply latching the present line and then
re-instating coordinates first thing on every iteration; note that the
file can't change from what was previously pushed on the scrubber's
state stack, and hence can be taken from there by using a new flavor of
.linefile (which is far better memory-footprint-wise than recording the
full path in the inserted directive). (This then leaves undisturbed any
file/line control occurring in the body of the construct, as these will
only be seen and processed afterwards.)
2022-04-12 09:03:13 +02:00
Jan Beulich
1a42a9fe4e x86: make {disp16} work similarly to {disp32}
In a few places {disp32} was handled specially when really {disp16}
wants handling just the same.
2022-04-12 09:01:55 +02:00
Alan Modra
480a4dd5f3 Don't run pr27228 test for hppa
As the comment says, hppa doesn't support use of BFD_RELOC_* in
.reloc directives.  Using xfail can result in a spurious XPASS result
as BFD_RELOC values change.

	* testsuite/gas/elf/pr27228.d: Change xfail to notarget for hppa.
2022-04-09 15:26:25 +09:30
Fangrui Song
a3a7f5e158 gas: Port "copy st_size only if unset" to aarch64 and riscv
And disable the new test gas/elf/size.s for alpha which uses its own
.set, for hppa*-*-hpux* which does not allow .size before declaration.
2022-04-08 14:06:36 -07:00
Mark Harmstone
145667f8d9 Add support for COFF secidx relocations
bfd	* coff-i386.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_i386_relocation_section): Add support for R_SECTION.
	(coff_i386_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* coff-x86_64.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_amd64_relocation_section): Add support for R_SECTION.
	(coff_amd64_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* reloc.c: Add BFD_RELOC_16_SECIDX.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

gas	* config/tc-i386.c (pe_directive_secidx): New function.
	(md_pseudo_table): Add support for secidx.
	(x86_cons_fix_new): Likewise.
	(tc_gen_reloc): Likewise.
	* expr.c (op_rank): Add O_secidx.
	* expr.h (operatorT): Likewise.
	* symbols.c (resolve_symbol_value): Add support for O_secidx.
	* testsuite/gas/i386/secidx.s: New test source file.
	* testsuite/gas/i386/secidx.d: New test driver file.
	* testsuite/gas/i386/i386.exp: Run new test.

include	* coff/i386.h: Define R_SECTION.
	* coff/x86_64.h: Likewise.

ld	* testsuite/ld-pe/secidx1.s: New test source file.
	* testsuite/ld-pe/secidx2.s: New test source file.
	* testsuite/ld-pe/secidx.d: New test driver file.
	* testsuite/ld-pe/secidx_64.d: New test driver file.
	* testsuite/ld-pe/pe.exp: Add new tests.
2022-04-07 14:47:17 +01:00
Jan Beulich
591cc9fbbf gas/Dwarf: record functions
To help tools like addr2line looking up function names, in particular
when dealing with e.g. PE/COFF binaries (linked from ELF objects), where
there's no ELF symbol table to fall back to, emit minimalistic
information for functions marked as such and having their size
specified.

Notes regarding the restriction to (pure) ELF:
- I realize this is a layering violation; I don't see how to deal with
  that in a better way.
- S_GET_SIZE(), when OBJ_MAYBE_ELF is defined, looks wrong: Unlike
  S_SET_SIZE() it does not check whether the hook is NULL.
- symbol_get_obj(), when OBJ_MAYBE_ELF is defined, looks unusable, as
  its return type can only ever be one object format's type (and this
  may then not be ELF's).

The new testcases are limited to x86 because I wanted to include the
case where function size can't be determined yet at the time Dwarf2 info
is generated. As .nops gains support by further targets, they could also
be added here then (with, as necessary, expecations suitably relaxed to
cover for insn size differences).
2022-04-07 08:18:00 +02:00
Jan Beulich
0f47cb17d1 Arm64: arrange for line number emission for .inst
Just like insns encoded the more conventional way these should have line
number info associated with them.
2022-04-07 08:16:29 +02:00
Jan Beulich
13d414afa0 Arm32: arrange for line number emission for .inst
Just like insns encoded the more conventional way these should have line
number info associated with them.
2022-04-07 08:15:24 +02:00
Jan Beulich
ff82bd7405 RISC-V: add testcase to check line number emission for .insn
Since no such test looks to exist, derive one from insn.s.
2022-04-07 08:14:33 +02:00
Nick Clifton
19c26da69d Add code to display the contents of .debug_loclists sections which contain offset entry tables.
PR 28981
	* dwarf.c (fetch_indexed_value): Rename to fecth_indexed_addr and
	return the address, rather than a string.
	(fetch_indexed_value): New function - returns a value indexed by a
	DW_FORM_loclistx or DW_FORM_rnglistx form.
	(read_and_display_attr_value): Add support for DW_FORM_loclistx
	and DW_FORM_rnglistx.
	(process_debug_info): Load the loclists and rnglists sections.
	(display_loclists_list): Add support for DW_LLE_base_addressx,
	DW_LLE_startx_endx, DW_LLE_startx_length and
	DW_LLE_default_location.
	(display_offset_entry_loclists): New function.  Displays a
	.debug_loclists section that contains offset entry tables.
	(display_debug_loc): Call the new function.
	(display_debug_rnglists_list): Add support for
	DW_RLE_base_addressx, DW_RLE_startx_endx and DW_RLE_startx_length.
	(display_debug_ranges): Display the contents of the section's
	header.
	* dwarf.h (struct debug_info): Add loclists_base field.
	* testsuite/binutils-all/dw5.W: Update expected output.
	* testsuite/binutils-all/x86-64/pr26808.dump: Likewise.
2022-04-06 14:43:37 +01:00
Fangrui Song
867b8c308a gas: copy st_size only if unset
For
```
.size foo1, 1
foo1:

.set bar1, foo1
.size bar1, 2
.size bar2, 2
.set bar2, foo1

.set bar3, foo2
.size bar3, 2
.size bar4, 2
.set bar4, foo2

.size foo2, 1
foo2:
```

bar1's size is 2 while bar2, bar3, bar4's is 1. The behavior of bar1 makes sense
(generally directives on the new symbol should win) and is relied upon by glibc
stdio-common/errlist.c:

```
        .hidden _sys_errlist_internal
        .globl  _sys_errlist_internal
        .type   _sys_errlist_internal, @object
        .size   _sys_errlist_internal, 1072
_sys_errlist_internal:

        .globl __GLIBC_2_1_sys_errlist
        .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
        .type __GLIBC_2_1_sys_errlist, %object
        .size __GLIBC_2_1_sys_errlist, 125 * (64 / 8)

// glibc expects that .size __GLIBC_2_1_sys_errlist, 125 * (64 / 8) wins.
```

The behavior of bar2/bar3/bar4 seems brittle. To avoid the reordering of the two
code blocks which will result in the bar3 situation, glibc compiles errlist.c
with gcc -fno-toplevel-reorder (previously -fno-unit-at-a-time).

To fix the inconsistency and improve robustness, make bar2/bar3/bar4 match bar1,
removing the directive order sensitivity.

There is a pity that `.size dest, 0` is indistinguishable from the case where
dest is unset, but the compromise seems fine.

    PR gas/29012
    * config/obj-elf.c (elf_copy_symbol_attributes): don't copy if src's size
      has been set.
    * testsuite/gas/elf/elf.exp: New test.
    * testsuite/gas/elf/size.d: New file.
    * testsuite/gas/elf/size.s: Likewise.
2022-04-04 08:43:50 -07:00
Richard Sandiford
025f768ffc aarch64: Relax check for RNG system registers
FEAT_RNG is an optional Armv8.5-A extension, but it can be backported
to earlier architectures as well.  GAS previously made the RNG registers
conditional on having both armv8.5-a and +rng, but only +rng should be
required.

This seems to be the only feature that was handled like this.

opcodes/
	* aarch64-opc.c (SR_RNG): Don't require V8_5.

gas/
	* testsuite/gas/aarch64/rng-1.s, testsuite/gas/aarch64/rng-1.d: New
	test.
2022-03-31 17:51:16 +01:00
Jan Beulich
be13be5b68 gas/Dwarf: special-case .linefile only for macros
Restrict the PR gas/16908 workaround to just macros, matching the
original intention as well as the comment there. For constructs like
.irp or .rept the reasoning doesn't apply, as there's no separate
"invocation" point which may be of interest to record (for, as said
there, short macros).
2022-03-29 08:18:14 +02:00
Jan Beulich
1d1595b48b RISC-V: correct FCVT.Q.L[U]
While the spec isn't explicit about this, it pointing out the similarity
with the D extension ought to extend to the ignoring of a meaningless
rounding mode: "Note FCVT.D.W[U] always produces an exact result and is
unaffected by rounding mode." Hence the chosen encodings also ought to
match.

Note that to avoid breaking existing code the forms with a 3rd operand
are not removed, which means there continues to be a difference to
FCVT.D.W[U].
2022-03-29 08:17:49 +02:00
Alan Modra
ee41183df4 Re: gas/Dwarf: improve debug info generation from .irp and alike blocks
am33_2.0-linux is a mn10300 target.

	* testsuite/gas/elf/dwarf-5-irp.d: xfail am33.
2022-03-25 11:35:19 +10:30
Jan Beulich
e52a16f2aa x86: reject relocations involving registers
To prevent fatal or even internal errors, add a simple check to
i386_validate_fix(), rejecting relocations when their target symbol is
an equate of a register (or resolved to reg_section for any other
reason).
2022-03-23 12:31:29 +01:00
Jan Beulich
64d23078e3 x86: improve resolution of register equates
Allow transitive (or recursive) equates to work in addition to direct
ones. The only requirements are that
- the equate being straight of a register, i.e. no expressions involved
  (albeit I'm afraid something like "%eax + 0" will be viewed as %eax),
- at the point of use there's no forward ref left which cannot be
  resolved, yet.
2022-03-23 12:31:04 +01:00
Jan Beulich
4faaa10f3f x86: don't attempt to resolve equates and alike from i386_parse_name()
PR gas/28977

Perhaps right from its introduction in 4d1bb7955a it was wrong for
i386_parse_name() to call parse_register(). This being a hook from the
expression parser, it shouldn't be resolving e.g. equated symbols.
That's relevant only for all other callers of parse_register().

To compensate, in Intel syntax mode check_register() needs calling;
perhaps not doing so was an oversight right when the function was
introduced. This is necessary in particular to force EVEX encoding when
VRex registers are used (but of course also to reject bad uses of
registers, i.e. fully matching what parse_register() needs it for).
2022-03-23 12:28:53 +01:00
Jan Beulich
7992631e8c gas/Dwarf: improve debug info generation from .irp and alike blocks
Tying the bumping of the logical line number to reading from the
original source file looks wrong: Upon finishing of the processing of an
sb the original values will be restored anyway. Yet without bumping the
line counter uses of .line inside e.g. an .irp construct won't have the
intended effect: Such uses may be necessary to ensure proper debug info
is emitted in particular when switching sections inside the .irp body,
as dwarf2_gen_line_info() would bail without doing anything when it
finds the line number unchanged from what it saw last.
2022-03-23 08:46:39 +01:00
Jan Beulich
36e2d65d26 ELF32: don't silently truncate relocation addends
At least x86-64's x32 sub-mode and RISC-V's 32-bit mode calculate
addends as 64-bit values, but store them in signed 32-bit fields when
generating the file without encountering any earlier error. When the
relocated field is a 64-bit one, the value resulting after processing
the relocation record when linking (or the latest when loading) may
thus be wrong due to the truncation.

With the code change in place, one x32 testcase actually triggers the
new diagnostic. That one case of too large a (negative) addend is being
adjusted alongside the addition of a new testcase to actually trigger
the new error. (Note that due to internal BFD behavior the relocation in
.data doesn't get processed anymore after the errors in .text.)

Note that in principle it is possible to express 64-bit relocations in
ELF32, but this would require .rel relocations, i.e. with the addend
stored in the 64-bit field being relocated. But I guess it would be a
lot of effort for little gain to actually support this.
2022-03-23 08:43:13 +01:00
Jan Beulich
b3446f947b gas: retain whitespace between strings
Macro arguments may be separated by commas or just whitespace. Macro
arguments may also be quoted (where one level of quotes is removed in
the course of determining the values for the respective formal
parameters). Furthermore this quote removal knows _two_ somewhat odd
escaping mechanisms: One, apparently in existence forever, is that a
pair of quotes counts as the escaping of a quote, with the pair being
transformed to a single quote in the course of quote removal. The other
(introduced by c06ae4f232) looks more usual on the surface in that it
deals with \" sequences, but it _retains_ the escaping \. Hence only the
former mechanism is suitable when the value to be used by the macro body
is to contain a quote. Yet this results in ambiguity of what "a""b" is
intended to mean; elsewhere (e.g. for .ascii) it represents two
successive string literals. However, in any event is the above different
from "a" "b": I don't think this can be viewed the same as "a""b" when
processing macro arguments.

Change the scrubber to retain such whitespace, by making the processing
of strings more similar to that of symbols. And indeed this appears to
make sense when taking into account that for quite a while gas has been
supporting quoted symbol names.

Taking a more general view, however, the change doesn't go quite far
enough. There are further cases where significant whitespace is removed
by the scrubber. The new testcase enumerates a few in its ".if 0"
section. I'm afraid the only way that I see to deal with this would be
to significantly simplify the scrubber, such that it wouldn't do much
more than collapse sequences of unquoted whitespace into a single blank.
To be honest problems in this area aren't really surprising when seeing
that there's hardly any checking of .macro use throughout the testsuite
(and in particular in the [relatively] generic tests under all/).
2022-03-23 08:41:54 +01:00
Jan Beulich
46fb6d5aa2 x86: don't suppress overflow diagnostics in x32 mode
Unlike in 64-bit mode, where values wrap at the 64-bit boundary anyway,
there's no wrapping at the 32-bit boundary here, and hence overflow
detection shouldn't be suppressed just because rela relocations are
going to be used.

The extra check against NO_RELOC is actually a result of an ilp32 test
otherwise failing. But thinking about it, reporting overflows for
not-really-relocations (typically because of earlier errors) makes
little sense in general. Perhaps this should even be extended to non-
64-bit modes.
2022-03-21 15:13:35 +01:00
Nick Clifton
a58b0053f4 z80 assembler: Fix new unexpected overflow warning in v2.37
PR 28791
	* config/tc-z80.c (emit_data_val): Do not warn about overlarge
	constants generated by bit manipulation operators.
	* testsuite/gas/z80/pr28791.s: New test source file.
	* testsuite/gas/z80/pr28791.d: New test driver file.
2022-03-21 11:33:59 +00:00
Tsukasa OI
41d6ac5da6 RISC-V: Cache management instructions
This commit adds 'Zicbom' / 'Zicboz' instructions.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Add handling for
	new instruction classes.

include/ChangeLog:

	* opcode/riscv-opc.h (MATCH_CBO_CLEAN, MASK_CBO_CLEAN,
	MATCH_CBO_FLUSH, MASK_CBO_FLUSH, MATCH_CBO_INVAL,
	MASK_CBO_INVAL, MATCH_CBO_ZERO, MASK_CBO_ZERO): New macros.
	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	classes INSN_CLASS_ZICBOM and INSN_CLASS_ZICBOZ.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Add cache-block management
	instructions.
2022-03-18 15:32:22 +08:00
Tsukasa OI
3b374308d3 RISC-V: Prefetch hint instructions and operand set
This commit adds 'Zicbop' hint instructions.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Add handling for
	new instruction class.

gas/ChangeLog:

	* config/tc-riscv.c (riscv_ip): Add handling for new operand
	type 'f' (32-byte aligned pseudo S-type immediate for prefetch
	hints).
	(validate_riscv_insn): Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (MATCH_PREFETCH_I, MASK_PREFETCH_I,
	MATCH_PREFETCH_R, MASK_PREFETCH_R, MATCH_PREFETCH_W,
	MASK_PREFETCH_W): New macros.
	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	class INSN_CLASS_ZICBOP.

opcodes/ChangeLog:

	* riscv-dis.c (print_insn_args): Add handling for new operand
	type.
	* riscv-opc.c (riscv_opcodes): Add prefetch hint instructions.
2022-03-18 15:32:16 +08:00
Jan Beulich
ed971d9fa6 x86: don't accept base architectures as extensions
The -march= intentions are quite clear: A base architecture may be
followed by any number of extensions. Accepting a base architecture in
place of an extension will at best result in confusion, as the first of
the two (or more) items specified simply would not take effect, due to
being overridden by the later one(s).
2022-03-17 11:05:56 +01:00
Jan Beulich
b1f8a900fd x86: add another IAMCU testcase
Now that {L,K}1OM support is gone, and with it the brokenness in
check_cpu_arch_compatible(), put in place a test making sure that only
extensions can be enabled via .arch for IAMCU, and that the base
architecture cannot be changed.
2022-03-17 11:03:22 +01:00
Jan Beulich
c085ab00c7 x86: drop L1OM/K1OM support from gas
This was only rudimentary support anyway; none of the sub-architecture
specific insns were ever supported.
2022-03-17 11:02:42 +01:00
Jan Beulich
648d04db39 x86: assorted IAMCU CPU checking fixes
The checks done by check_cpu_arch_compatible() were halfway sensible
only at the time where only L1OM support was there. The purpose,
however, has always been to prevent bad uses of .arch (turning off the
base CPU "feature" flag) while at the same time permitting extensions to
be enabled / disabled. In order to achieve this (and to prevent
regressions when L1OM and K1OM support are removed)
- set CpuIAMCU in CPU_IAMCU_FLAGS,
- adjust the IAMCU check in the function itself (the other two similarly
  broken checks aren't adjusted as they're slated to be removed anyway),
- avoid calling the function for extentions (which would never have the
  base "feature" flag set),
- add a new testcase actually exercising ".arch iamcu" (which would also
  regress with the planned removal).
2022-03-17 11:01:38 +01:00
Alan Modra
51ba92c795 PowerPC VLE extended instructions in powerpc_macros
This moves VLE insn out of the macro table.  "e_slwi" and "e_srwi"
already exist in vle_opcodes as distinct instructions rather than
encodings of e_rlwinm.

opcodes/
	* ppc-opc.c (vle_opcodes): Typo fix e_rlwinm operand.
	Add "e_inslwi", "e_insrwi", "e_rotlwi", "e_rotrwi", "e_clrlwi",
	"e_clrrwi", "e_extlwi", "e_extrwi", and "e_clrlslwi".
	(powerpc_macros): Delete same.  Delete "e_slwi" and "e_srwi" too.
gas/
	* testsuite/gas/ppc/vle-simple-5.d: Update.
2022-03-16 10:07:02 +10:30
Alan Modra
f304c63d24 PowerPC32 extended instructions in powerpc_macros
As for PowerPC64, move instructions to the main opcode table.

opcodes/
	* ppc-opc.c (insert_crwn, extract_crwn, insert_elwn, extract_elwn),
	(insert_erwn, extract_erwn, insert_erwb, extract_erwb),
	(insert_cslwn, extract_cslwb, insert_ilwb, extract_ilwn),
	(insert_irwb, extract_irwn, insert_rrwn, extract_rrwn),
	(insert_slwn, extract_slwn, insert_srwn, extract_srwn): New functions.
	(CRWn, ELWn, ERWn, ERWb, CSLWb, CSLWn, ILWn, ILWb, IRWn, IRWb),
	(RRWn, SLWn, SRWn): Define and add powerpc_operands entries.
	(MMB_MASK, MME_MASK, MSHMB_MASK): Define.
	(powerpc_opcodes): Add "inslwi", "insrwi", "rotrwi", "clrrwi",
	"slwi", "srwi", "extlwi", "extrwi", "sli", "sri" and corresponding
	record (ie. dot suffix) forms.
	(powerpc_macros): Delete same.
gas/
	* testsuite/gas/ppc/476.d: Update.
	* testsuite/gas/ppc/simpshft.d: Update.
2022-03-16 10:05:37 +10:30
Alan Modra
42952a9605 PowerPC64 extended instructions in powerpc_macros
The extended instructions implemented in powerpc_macros aren't used by
the disassembler.  That means instructions like "sldi r3,r3,2" appear
in disassembly as "rldicr r3,r3,2,61", which is annoying since many
other extended instructions are shown.

Note that some of the instructions moved out of the macro table to the
opcode table won't appear in disassembly, because they are aliases
rather than a subset of the underlying raw instruction.  If enabled,
rotrdi, extrdi, extldi, clrlsldi, and insrdi would replace all
occurrences of rotldi, rldicl, rldicr, rldic and rldimi.  (Or many
occurrences in the case of clrlsldi if n <= b was added to the extract
functions.)

The patch also fixes a small bug in opcode sanity checking.

include/
	* opcode/ppc.h (PPC_OPSHIFT_SH6): Define.
opcodes/
	* ppc-opc.c (insert_erdn, extract_erdn, insert_eldn, extract_eldn),
	(insert_crdn, extract_crdn, insert_rrdn, extract_rrdn),
	(insert_sldn, extract_sldn, insert_srdn, extract_srdn),
	(insert_erdb, extract_erdb, insert_csldn, extract_csldb),
	(insert_irdb, extract_irdn): New functions.
	(ELDn, ERDn, ERDn, RRDn, SRDn, ERDb, CSLDn, CSLDb, IRDn, IRDb):
	Define and add associated powerpc_operands entries.
	(powerpc_opcodes): Add "rotrdi", "srdi", "extrdi", "clrrdi",
	"sldi", "extldi", "clrlsldi", "insrdi" and corresponding record
	(ie. dot suffix) forms.
	(powerpc_macros): Delete same from here.
gas/
	* config/tc-ppc.c (insn_validate): Don't modify value passed
	to operand->insert for PPC_OPERAND_PLUS1 when calculating mask.
	Handle PPC_OPSHIFT_SH6.
	* testsuite/gas/ppc/prefix-reloc.d: Update.
	* testsuite/gas/ppc/simpshft.d: Update.
ld/
	* testsuite/ld-powerpc/elfv2so.d: Update.
	* testsuite/ld-powerpc/notoc.d: Update.
	* testsuite/ld-powerpc/notoc3.d: Update.
	* testsuite/ld-powerpc/tlsdesc2.d: Update.
	* testsuite/ld-powerpc/tlsget.d: Update.
	* testsuite/ld-powerpc/tlsget2.d: Update.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
	* testsuite/ld-powerpc/tlsopt6.d: Update.
2022-03-16 09:59:07 +10:30
Alan Modra
fb0e49d8e0 Constant fold view increment expressions
The idea here is to replace expressions like v + 1 + 1 + 1 with v + 3.

	* dwarf2dbg.c (set_or_check_view): Remove useless assertion.
	Resolve multiple view increments.
	* testsuite/gas/elf/dwarf2-18.d: Don't xfail mep.
2022-03-09 15:50:34 +10:30
Jan Beulich
7919e5667c RISC-V: make .insn actually work for 64-bit insns
Presently in this case, due to an undefined behavior shift, at least
with x86 cross builds I'm observing:

Error: value conflicts with instruction length `8,0x0000003f'

Eliminate the UB and extend the respective testcase.
2022-03-04 13:37:59 +01:00
Jan Beulich
6a778a2100 x86: drop redundant x86-64-code16-2 test
The code16-2 test is already meaningless enough as a gas test, identical
to this one, and is run uniformly for all ELF targets anyway.
2022-03-04 13:37:30 +01:00
Patrick O'Neill
e4028336b1 RISC-V: PR28733, add missing extension info to 'unrecognized opcode' error
Currently we report errors as "unrecognized opcode `fence.i'" when the
opcode isn't part of the selected extensions.
This patch expands that error message to include the missing extension
information. For example, now the error message would be "unrecognized
opcode `fence.i', extension `zifencei' required".
If the opcode is not a part of any extension, the error message reverts
to "unrecognized opcode `<op statement>'".

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>

bfd/
	pr 28733
	* elfxx-riscv.c (riscv_multi_subset_supports_ext): New function,
	used to return the extension string for each INSN_CLASS_*.
	* elfxx-riscv.h: Added extern riscv_multi_subset_supports_ext.
gas/
	pr 28733
	* config/tc-riscv.c (struct riscv_ip_error): New structure,
	contains information about errors that occur within the riscv_ip.
	(riscv_ip): Use struct riscv_ip_error to report more detailed errors.
	* testsuite/gas/riscv/c-fld-fsd-fail.l: Updated.
	* testsuite/gas/riscv/march-imply-i2p1-01.: Likewise.
2022-02-23 19:45:52 +08:00
Patrick O'Neill
df0a549ebd RISC-V: PR28733, add missing extension info to 'invalid CSR' error
Currently we report errors as "invalid CSR 'fscr' for the current ISA"
when the instruction isn't valid.

This patch expands that error message to include the missing extension
information. For example, now the error message would be "invalid CSR
'fscr' for the current ISA, CSR 'fscr' needs 'f' extension".

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>

gas/
	pr 28733
	* config/tc-riscv.c (riscv_csr_address): Report more details
	when the CSR is invalid.
	* testsuite/gas/riscv/csr-version-1p10.l: Updated detailed errors.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
2022-02-23 19:08:19 +08:00
Nelson Chu
9cbed90ee6 RISC-V: Updated CSRs to privileged spec v1.12 and debug spec v1.0.
* Removed N extension CSRs,
ustatus, uie, utvec, uscratch, uepc, ucause, utval and uip.

* Removed two supervisor CSRs,
sedeleg and sideleg.

* Changed debug CSR address of scontext from 0x7aa to 0x5a8.  We cannot support
different versions of debug specs for now, so only supporting the latest one is
the only way to move forward.

* Added debug CSRs,
mscontext (0x7aa), mcontrol6 (0x7a1, tdata1) and tmexttrigger ((0x7a1, tdata1).

* Regarded hcontext as a debug CSR.

include/
	* opcode/riscv-opc.h: Updated CSRs to privileged spec v1.12 and
	debug spec v1.0.
gas/
	* testsuite/gas/riscv/csr.s: Updated CSRs to privileged spec v1.12
	and debug spec v1.0.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.s: Likewise.
2022-02-23 14:54:34 +08:00
Tsukasa OI
f4ce10b14f RISC-V: Add Privileged Architecture 1.12 CSRs
This commit adds,

* Most of CSRs as listed in the Privileged Architecture,
version 1.12 (except scontext and mscontext).

* Testcases for most CSRs added on the Privileged
Architecture, version 1.12 (except moved "scontext" and
new "mscontext").

include/ChangeLog:

	* opcode/riscv-opc.h (CSR_SENVCFG, CSR_MCONFIGPTR, CSR_MENVCFG,
	CSR_MSTATUSH, CSR_MENVCFGH, CSR_MTINST, CSR_MTVAL2, CSR_MSECCFG,
	CSR_MSECCFGH, CSR_PMPCFG4, CSR_PMPCFG5, CSR_PMPCFG6,
	CSR_PMPCFG7, CSR_PMPCFG8, CSR_PMPCFG9, CSR_PMPCFG10,
	CSR_PMPCFG11, CSR_PMPCFG12, CSR_PMPCFG13, CSR_PMPCFG14,
	CSR_PMPCFG15, CSR_PMPADDR16, CSR_PMPADDR17, CSR_PMPADDR18,
	CSR_PMPADDR19, CSR_PMPADDR20, CSR_PMPADDR21, CSR_PMPADDR22,
	CSR_PMPADDR23, CSR_PMPADDR24, CSR_PMPADDR25, CSR_PMPADDR26,
	CSR_PMPADDR27, CSR_PMPADDR28, CSR_PMPADDR29, CSR_PMPADDR30,
	CSR_PMPADDR31, CSR_PMPADDR32, CSR_PMPADDR33, CSR_PMPADDR34,
	CSR_PMPADDR35, CSR_PMPADDR36, CSR_PMPADDR37, CSR_PMPADDR38,
	CSR_PMPADDR39, CSR_PMPADDR40, CSR_PMPADDR41, CSR_PMPADDR42,
	CSR_PMPADDR43, CSR_PMPADDR44, CSR_PMPADDR45, CSR_PMPADDR46,
	CSR_PMPADDR47, CSR_PMPADDR48, CSR_PMPADDR49, CSR_PMPADDR50,
	CSR_PMPADDR51, CSR_PMPADDR52, CSR_PMPADDR53, CSR_PMPADDR54,
	CSR_PMPADDR55, CSR_PMPADDR56, CSR_PMPADDR57, CSR_PMPADDR58,
	CSR_PMPADDR59, CSR_PMPADDR60, CSR_PMPADDR61, CSR_PMPADDR62,
	CSR_PMPADDR63): New CSR macros.

gas/ChangeLog:

	* testsuite/gas/riscv/csr-dw-regnums.s: Add new CSRs.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr.s: Add new CSRs.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.
2022-02-23 14:45:44 +08:00
Tsukasa OI
7379729c7d RISC-V: Reorganize testcases for CFI directives
This commit reorganizes and adds some CSRs to csr-dw-regnums.[sd] to
make it test the same CSRs as csr.s.

gas/ChangeLog:

	* testsuite/gas/riscv/csr-dw-regnums.s: Reorganize and add
	defined CSRs tested in csr.s.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
2022-02-23 14:45:34 +08:00