Skip to content

Commit 4acd941

Browse files
a4lgartemiy-volkov
authored andcommitted
RISC-V: Add 'Smrnmi' extension and its CSRs
Forward-ported from https://sourceware.org/pipermail/binutils/2023-September/129442.html (there is no difference between 0.4 and 1.0 of the Smrnmi spec). Replace by the upstream version when the MNRET insn is available. ==================================================================== [DO NOT MERGE] Until 'Smrnmi' extension is frozen/ratified and final version number is determined, this patch should not be merged upstream. This commit uses unratified version 0.4 as in the documentation (instead of possible 1.0 after ratification). This commit adds "mnret" instruction and RNMI-related CSRs from the Resumable Non-Maskable Interrupts ('Smrnmi') extension. This is based on: <riscv/riscv-isa-manual@28b46de>, latest 'Smrnmi' change on the master branch of the RISC-V ISA Manual as of this writing. bfd/ChangeLog: * elfxx-riscv.c (riscv_implicit_subsets): Make 'Smrnmi' to imply 'Zicsr' extension. (riscv_multi_subset_supports): Add new instruction class handling. (riscv_multi_subset_supports_ext): Likewise. gas/ChangeLog: * config/tc-riscv.c (enum riscv_csr_class): Add new CSR class. (riscv_csr_address): Add new CSR class handling. * testsuite/gas/riscv/csr.s: Add new CSR test. * testsuite/gas/riscv/csr-dw-regnums.s: Likewise. * testsuite/gas/riscv/csr-dw-regnums.d: Likewise. * 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. * testsuite/gas/riscv/smrnmi.s: New test for mnret instruction. * testsuite/gas/riscv/smrnmi.d: Likewise. * testsuite/gas/riscv/smrnmi-noarch.d: New test for architecture failure. * testsuite/gas/riscv/smrnmi-noarch.l: Likewise. include/ChangeLog: * opcode/riscv-opc.h (MATCH_MNRET, MASK_MNRET, CSR_MNSCRATCH, CSR_MNEPC, CSR_MNCAUSE, CSR_MNSTATUS): New. * opcode/riscv.h (enum riscv_insn_class): Add new instruction class. opcodes/ChangeLog: * riscv-opc.c (riscv_opcodes): Add 'mnret' instruction.
1 parent cd49885 commit 4acd941

18 files changed

+133
-0
lines changed

bfd/elfxx-riscv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
12751275
{"smcntrpmf", "+zicsr", check_implicit_always},
12761276
{"smstateen", "+ssstateen", check_implicit_always},
12771277
{"smepmp", "+zicsr", check_implicit_always},
1278+
{"smrnmi", "+zicsr", check_implicit_always},
12781279

12791280
{"ssaia", "+zicsr", check_implicit_always},
12801281
{"sscsrind", "+zicsr", check_implicit_always},
@@ -1460,6 +1461,7 @@ static struct riscv_supported_ext riscv_supported_std_s_ext[] =
14601461
{"smcsrind", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
14611462
{"smcntrpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
14621463
{"smepmp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1464+
{"smrnmi", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
14631465
{"smstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
14641466
{"ssaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
14651467
{"ssccptr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
@@ -2732,6 +2734,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
27322734
case INSN_CLASS_ZCB_AND_ZMMUL:
27332735
return (riscv_subset_supports (rps, "zcb")
27342736
&& riscv_subset_supports (rps, "zmmul"));
2737+
case INSN_CLASS_SMRNMI:
2738+
return riscv_subset_supports (rps, "smrnmi");
27352739
case INSN_CLASS_ZCMP:
27362740
return riscv_subset_supports (rps, "zcmp");
27372741
case INSN_CLASS_SVINVAL:
@@ -3006,6 +3010,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
30063010
return _("zcb' and `zbb");
30073011
case INSN_CLASS_ZCB_AND_ZMMUL:
30083012
return _("zcb' and `zmmul', or `zcb' and `m");
3013+
case INSN_CLASS_SMRNMI:
3014+
return "smrnmi";
30093015
case INSN_CLASS_ZCMP:
30103016
return "zcmp";
30113017
case INSN_CLASS_SVINVAL:

gas/config/tc-riscv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ enum riscv_csr_class
8181
CSR_CLASS_SMCSRIND, /* Smcsrind */
8282
CSR_CLASS_SMCNTRPMF, /* Smcntrpmf */
8383
CSR_CLASS_SMCNTRPMF_32, /* Smcntrpmf, rv32 only */
84+
CSR_CLASS_SMRNMI, /* Smrnmi only */
8485
CSR_CLASS_SMSTATEEN, /* Smstateen only */
8586
CSR_CLASS_SMSTATEEN_32, /* Smstateen RV32 only */
8687
CSR_CLASS_SSAIA, /* Ssaia */
@@ -1078,6 +1079,9 @@ riscv_csr_address (const char *csr_name,
10781079
need_check_version = true;
10791080
extension = "smcntrpmf";
10801081
break;
1082+
case CSR_CLASS_SMRNMI:
1083+
extension = "smrnmi";
1084+
break;
10811085
case CSR_CLASS_SMSTATEEN_32:
10821086
is_rv32_only = true;
10831087
/* Fall through. */

gas/testsuite/gas/riscv/csr-dw-regnums.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ Contents of the .* section:
328328
DW_CFA_offset_extended_sf: r4898 \(minstretcfg\) at cfa\+3208
329329
DW_CFA_offset_extended_sf: r5921 \(mcyclecfgh\) at cfa\+7300
330330
DW_CFA_offset_extended_sf: r5922 \(minstretcfgh\) at cfa\+7304
331+
DW_CFA_offset_extended_sf: r5952 \(mnscratch\) at cfa\+7424
332+
DW_CFA_offset_extended_sf: r5953 \(mnepc\) at cfa\+7428
333+
DW_CFA_offset_extended_sf: r5954 \(mncause\) at cfa\+7432
334+
DW_CFA_offset_extended_sf: r5956 \(mnstatus\) at cfa\+7440
331335
DW_CFA_offset_extended_sf: r4876 \(mstateen0\) at cfa\+3120
332336
DW_CFA_offset_extended_sf: r4877 \(mstateen1\) at cfa\+3124
333337
DW_CFA_offset_extended_sf: r4878 \(mstateen2\) at cfa\+3128

gas/testsuite/gas/riscv/csr-dw-regnums.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ _start:
326326
.cfi_offset minstretcfg, 3208
327327
.cfi_offset mcyclecfgh, 7300
328328
.cfi_offset minstretcfgh, 7304
329+
# Smrnmi extension
330+
.cfi_offset mnscratch, 7424
331+
.cfi_offset mnepc, 7428
332+
.cfi_offset mncause, 7432
333+
.cfi_offset mnstatus, 7440
329334
# Smstateen extension
330335
.cfi_offset mstateen0, 3120
331336
.cfi_offset mstateen1, 3124

gas/testsuite/gas/riscv/csr-version-1p10.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ Disassembly of section .text:
645645
[ ]+[0-9a-f]+:[ ]+72159073[ ]+csrw[ ]+mcyclecfgh,a1
646646
[ ]+[0-9a-f]+:[ ]+72202573[ ]+csrr[ ]+a0,minstretcfgh
647647
[ ]+[0-9a-f]+:[ ]+72259073[ ]+csrw[ ]+minstretcfgh,a1
648+
[ ]+[0-9a-f]+:[ ]+74002573[ ]+csrr[ ]+a0,mnscratch
649+
[ ]+[0-9a-f]+:[ ]+74059073[ ]+csrw[ ]+mnscratch,a1
650+
[ ]+[0-9a-f]+:[ ]+74102573[ ]+csrr[ ]+a0,mnepc
651+
[ ]+[0-9a-f]+:[ ]+74159073[ ]+csrw[ ]+mnepc,a1
652+
[ ]+[0-9a-f]+:[ ]+74202573[ ]+csrr[ ]+a0,mncause
653+
[ ]+[0-9a-f]+:[ ]+74259073[ ]+csrw[ ]+mncause,a1
654+
[ ]+[0-9a-f]+:[ ]+74402573[ ]+csrr[ ]+a0,mnstatus
655+
[ ]+[0-9a-f]+:[ ]+74459073[ ]+csrw[ ]+mnstatus,a1
648656
[ ]+[0-9a-f]+:[ ]+30c02573[ ]+csrr[ ]+a0,mstateen0
649657
[ ]+[0-9a-f]+:[ ]+30c59073[ ]+csrw[ ]+mstateen0,a1
650658
[ ]+[0-9a-f]+:[ ]+30d02573[ ]+csrr[ ]+a0,mstateen1

gas/testsuite/gas/riscv/csr-version-1p10.l

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,22 @@
941941
.*Info: macro .*
942942
.*Warning: invalid CSR `minstretcfgh', needs `smcntrpmf' extension
943943
.*Info: macro .*
944+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
945+
.*Info: macro .*
946+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
947+
.*Info: macro .*
948+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
949+
.*Info: macro .*
950+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
951+
.*Info: macro .*
952+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
953+
.*Info: macro .*
954+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
955+
.*Info: macro .*
956+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
957+
.*Info: macro .*
958+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
959+
.*Info: macro .*
944960
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension
945961
.*Info: macro .*
946962
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension

gas/testsuite/gas/riscv/csr-version-1p11.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ Disassembly of section .text:
645645
[ ]+[0-9a-f]+:[ ]+72159073[ ]+csrw[ ]+mcyclecfgh,a1
646646
[ ]+[0-9a-f]+:[ ]+72202573[ ]+csrr[ ]+a0,minstretcfgh
647647
[ ]+[0-9a-f]+:[ ]+72259073[ ]+csrw[ ]+minstretcfgh,a1
648+
[ ]+[0-9a-f]+:[ ]+74002573[ ]+csrr[ ]+a0,mnscratch
649+
[ ]+[0-9a-f]+:[ ]+74059073[ ]+csrw[ ]+mnscratch,a1
650+
[ ]+[0-9a-f]+:[ ]+74102573[ ]+csrr[ ]+a0,mnepc
651+
[ ]+[0-9a-f]+:[ ]+74159073[ ]+csrw[ ]+mnepc,a1
652+
[ ]+[0-9a-f]+:[ ]+74202573[ ]+csrr[ ]+a0,mncause
653+
[ ]+[0-9a-f]+:[ ]+74259073[ ]+csrw[ ]+mncause,a1
654+
[ ]+[0-9a-f]+:[ ]+74402573[ ]+csrr[ ]+a0,mnstatus
655+
[ ]+[0-9a-f]+:[ ]+74459073[ ]+csrw[ ]+mnstatus,a1
648656
[ ]+[0-9a-f]+:[ ]+30c02573[ ]+csrr[ ]+a0,mstateen0
649657
[ ]+[0-9a-f]+:[ ]+30c59073[ ]+csrw[ ]+mstateen0,a1
650658
[ ]+[0-9a-f]+:[ ]+30d02573[ ]+csrr[ ]+a0,mstateen1

gas/testsuite/gas/riscv/csr-version-1p11.l

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,22 @@
937937
.*Info: macro .*
938938
.*Warning: invalid CSR `minstretcfgh', needs `smcntrpmf' extension
939939
.*Info: macro .*
940+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
941+
.*Info: macro .*
942+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
943+
.*Info: macro .*
944+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
945+
.*Info: macro .*
946+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
947+
.*Info: macro .*
948+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
949+
.*Info: macro .*
950+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
951+
.*Info: macro .*
952+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
953+
.*Info: macro .*
954+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
955+
.*Info: macro .*
940956
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension
941957
.*Info: macro .*
942958
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension

gas/testsuite/gas/riscv/csr-version-1p12.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ Disassembly of section .text:
645645
[ ]+[0-9a-f]+:[ ]+72159073[ ]+csrw[ ]+mcyclecfgh,a1
646646
[ ]+[0-9a-f]+:[ ]+72202573[ ]+csrr[ ]+a0,minstretcfgh
647647
[ ]+[0-9a-f]+:[ ]+72259073[ ]+csrw[ ]+minstretcfgh,a1
648+
[ ]+[0-9a-f]+:[ ]+74002573[ ]+csrr[ ]+a0,mnscratch
649+
[ ]+[0-9a-f]+:[ ]+74059073[ ]+csrw[ ]+mnscratch,a1
650+
[ ]+[0-9a-f]+:[ ]+74102573[ ]+csrr[ ]+a0,mnepc
651+
[ ]+[0-9a-f]+:[ ]+74159073[ ]+csrw[ ]+mnepc,a1
652+
[ ]+[0-9a-f]+:[ ]+74202573[ ]+csrr[ ]+a0,mncause
653+
[ ]+[0-9a-f]+:[ ]+74259073[ ]+csrw[ ]+mncause,a1
654+
[ ]+[0-9a-f]+:[ ]+74402573[ ]+csrr[ ]+a0,mnstatus
655+
[ ]+[0-9a-f]+:[ ]+74459073[ ]+csrw[ ]+mnstatus,a1
648656
[ ]+[0-9a-f]+:[ ]+30c02573[ ]+csrr[ ]+a0,mstateen0
649657
[ ]+[0-9a-f]+:[ ]+30c59073[ ]+csrw[ ]+mstateen0,a1
650658
[ ]+[0-9a-f]+:[ ]+30d02573[ ]+csrr[ ]+a0,mstateen1

gas/testsuite/gas/riscv/csr-version-1p12.l

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,22 @@
661661
.*Info: macro .*
662662
.*Warning: invalid CSR `minstretcfgh', needs `smcntrpmf' extension
663663
.*Info: macro .*
664+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
665+
.*Info: macro .*
666+
.*Warning: invalid CSR `mnscratch', needs `smrnmi' extension
667+
.*Info: macro .*
668+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
669+
.*Info: macro .*
670+
.*Warning: invalid CSR `mnepc', needs `smrnmi' extension
671+
.*Info: macro .*
672+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
673+
.*Info: macro .*
674+
.*Warning: invalid CSR `mncause', needs `smrnmi' extension
675+
.*Info: macro .*
676+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
677+
.*Info: macro .*
678+
.*Warning: invalid CSR `mnstatus', needs `smrnmi' extension
679+
.*Info: macro .*
664680
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension
665681
.*Info: macro .*
666682
.*Warning: invalid CSR `mstateen0', needs `smstateen' extension

0 commit comments

Comments
 (0)