From d3ffd7f77654adafe5f1989bdfdbe4a337ff2e8b Mon Sep 17 00:00:00 2001 From: Nelson Chu Date: Fri, 19 Nov 2021 17:11:06 +0800 Subject: RISC-V: Support new .option arch directive. https://github.com/riscv/riscv-asm-manual/pull/67 Format: .option arch, +, ... .option arch, - .option arch, = The new direcitve is used to enable/disable extensions for the specific code region. For example, .attribute arch, "rv64ic" # arch = rv64i2p0_c2p0 .option push .option arch, +d2p0, -c # arch = rv64i2p0_f2p0_d2p0, f is added implied .option arch, =rv32gc # arch = rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0 .option pop # arch = rv64i2p0_c2p0 Note that, 1. ".option rvc/norvc" have the same behavior as ".option arch +c/-c". 2. ".option arch -i" is illegal, since we cannot remove base i extension. 3. If arch=rv64i2p0, then ".option arch, +i3p0" will update the i's version from 2.0 to 3.0. 4. If arch=rv64i3p0, then ".option arch, +i" will update the i's version from 2.0 to the default one according to the chosen isa spec. bfd/ * elfxx-riscv.c (riscv_add_subset): If the subset is already added, and the new versions are not RISCV_UNKNOWN_VERSION, then update the versions to the subset list. (riscv_copy_subset): New function. Copy the subset from list. (riscv_copy_subset_list): New function. Return the new copyed list. (riscv_update_subset): Updated to make .option arch directives workable. * elfxx-riscv.h: Updated. gas/ * config/tc-riscv.c (riscv_subsets): Defined as a pointer. (riscv_rps_as): Init the subset_list to NULL, we will set it later once riscv_opts_stack is created or updated. (struct riscv_option_stack, riscv_opts_stack): Moved forward. (riscv_set_arch): Updated. (s_riscv_option): Support new .option arch directive, to add, remove or update subsets for the specific code region. (riscv_write_out_attrs): Updated. * doc/c-riscv.texi: Added document for new .option arch directive. * testsuite/gas/riscv/option-arch-01a.d: New testcase. * testsuite/gas/riscv/option-arch-01b.d: Likewise. * testsuite/gas/riscv/option-arch-01.s: Likewise.. * testsuite/gas/riscv/option-arch-02.d: Likewise. * testsuite/gas/riscv/option-arch-02.s: Likewise. * testsuite/gas/riscv/option-arch-fail.d: Likewise. * testsuite/gas/riscv/option-arch-fail.l: Likewise. * testsuite/gas/riscv/option-arch-fail.s: Likewise. --- gas/doc/c-riscv.texi | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'gas/doc') diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi index bfbf61d..697be3a 100644 --- a/gas/doc/c-riscv.texi +++ b/gas/doc/c-riscv.texi @@ -194,7 +194,7 @@ command-line options are respected for the bulk of the file being assembled. @itemx norvc Enables or disables the generation of compressed instructions. Instructions are opportunistically compressed by the RISC-V assembler when possible, but -sometimes this behavior is not desirable. +sometimes this behavior is not desirable, especially when handling alignments. @item pic @itemx nopic @@ -212,6 +212,19 @@ desirable. @itemx no-csr-check Enables or disables the CSR checking. +@item arch, @var{+extension[version]} [,...,@var{+extension_n[version_n]}] +@itemx arch, @var{-extension} [,...,@var{-extension_n}] +@itemx arch, @var{=ISA} +Enables or disables the extensions for specific code region. For example, +@samp{.option arch, +m2p0} means add m extension with version 2.0, and +@samp{.option arch, -f, -d} means remove extensions, f and d, from the +architecture string. Note that, @samp{.option arch, +c, -c} have the same +behavior as @samp{.option rvc, norvc}. However, they are also undesirable +sometimes. Besides, @samp{.option arch, -i} is illegal, since we cannot +remove the base i extension anytime. If you want to reset the whole ISA +string, you can also use @samp{.option arch, =rv32imac} to overwrite the +previous settings. + @cindex INSN directives @item .insn @var{type}, @var{operand} [,...,@var{operand_n}] @itemx .insn @var{insn_length}, @var{value} -- cgit v1.1