From b0d5ad495e9263e995ac725a15a12359a0937bd3 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Fri, 14 Feb 2025 14:49:45 +0800 Subject: [PATCH] Support referring to FCSRs as Signed-off-by: Peng Fan --- 0001-FCSR-fcsrX.patch | 188 ++++++++++++++++++++++++++++++++++++++++++ binutils.spec | 7 +- 2 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 0001-FCSR-fcsrX.patch diff --git a/0001-FCSR-fcsrX.patch b/0001-FCSR-fcsrX.patch new file mode 100644 index 0000000..5280078 --- /dev/null +++ b/0001-FCSR-fcsrX.patch @@ -0,0 +1,188 @@ +From e478fec4688b28ae5feb65fbbdc1f8fecc39958e Mon Sep 17 00:00:00 2001 +From: cailulu +Date: Mon, 1 Jul 2024 11:32:07 +0800 +Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B0=86FCSR=E5=AF=84?= + =?UTF-8?q?=E5=AD=98=E5=99=A8=E5=90=8D=E5=BC=95=E7=94=A8=E4=B8=BA$fcsrX?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +以前,FCSR寄存器名称被引用为$rX,这看起来很奇怪。 +添加修改支持使用$fcsrX作为寄存器名称,这也能确保与 LLVM IAS 兼容。 + +Change-Id: Ia4448e39de582bb17332fefd4378e6ac3a21c3bd +--- + gas/config/tc-loongarch.c | 23 ++++++++++++++++++++++- + gas/testsuite/gas/loongarch/fcsr.d | 11 +++++++++++ + gas/testsuite/gas/loongarch/fcsr.s | 2 ++ + include/opcode/loongarch.h | 2 ++ + opcodes/loongarch-dis.c | 11 ++++++++++- + opcodes/loongarch-opc.c | 14 ++++++++++++-- + 6 files changed, 59 insertions(+), 4 deletions(-) + create mode 100644 gas/testsuite/gas/loongarch/fcsr.d + create mode 100644 gas/testsuite/gas/loongarch/fcsr.s + +diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c +index 236ad51f..38f81a13 100644 +--- a/gas/config/tc-loongarch.c ++++ b/gas/config/tc-loongarch.c +@@ -188,6 +188,8 @@ md_parse_option (int c, const char *arg) + + static struct hash_control *r_htab = NULL; + static struct hash_control *f_htab = NULL; ++static struct hash_control *fc_htab = NULL; ++static struct hash_control *fcn_htab = NULL; + static struct hash_control *c_htab = NULL; + static struct hash_control *cr_htab = NULL; + static struct hash_control *v_htab = NULL; +@@ -211,6 +213,10 @@ loongarch_after_parse_args () + r_htab = hash_new (), hash_insert (r_htab, "", 0); + if (!f_htab) + f_htab = hash_new (), hash_insert (f_htab, "", 0); ++ if (!fc_htab) ++ fc_htab = hash_new (), hash_insert (fc_htab, "", 0); ++ if (!fcn_htab) ++ fcn_htab = hash_new (), hash_insert (fcn_htab, "", 0); + if (!c_htab) + c_htab = hash_new (), hash_insert (c_htab, "", 0); + if (!cr_htab) +@@ -224,6 +230,10 @@ loongarch_after_parse_args () + hash_insert (r_htab, loongarch_r_normal_name[i], (void *) (i + 1)); + for (i = 0; i < ARRAY_SIZE (loongarch_f_normal_name); i++) + hash_insert (f_htab, loongarch_f_normal_name[i], (void *) (i + 1)); ++ for (i = 0; i < ARRAY_SIZE (loongarch_fc_normal_name); i++) ++ hash_insert (fc_htab, loongarch_fc_normal_name[i], (void *) (i + 1)); ++ for (i = 0; i < ARRAY_SIZE (loongarch_fc_numeric_name); i++) ++ hash_insert (fcn_htab, loongarch_fc_numeric_name[i], (void *) (i + 1)); + for (i = 0; i < ARRAY_SIZE (loongarch_c_normal_name); i++) + hash_insert (c_htab, loongarch_c_normal_name[i], (void *) (i + 1)); + for (i = 0; i < ARRAY_SIZE (loongarch_cr_normal_name); i++) +@@ -635,7 +645,18 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, + ret = imm - 1; + break; + case 'f': +- imm = (offsetT) hash_find (f_htab, arg); ++ switch (esc_ch2) ++ { ++ case 'c': ++ imm = (offsetT) hash_find (fc_htab, arg); ++ if (0 >= imm) ++ { ++ imm = (offsetT) hash_find (fcn_htab, arg); ++ } ++ break; ++ default: ++ imm = (offsetT) hash_find (f_htab, arg); ++ } + ip->match_now = 0 < imm; + ret = imm - 1; + break; +diff --git a/gas/testsuite/gas/loongarch/fcsr.d b/gas/testsuite/gas/loongarch/fcsr.d +new file mode 100644 +index 00000000..342b7cbc +--- /dev/null ++++ b/gas/testsuite/gas/loongarch/fcsr.d +@@ -0,0 +1,11 @@ ++#as: ++#objdump: -dr ++ ++.*: file format .* ++ ++ ++Disassembly of section .text: ++ ++0* <.text>: ++ 0: 0114c0a0 movgr2fcsr \$fcsr0,\$r5 ++ 4: 0114c804 movfcsr2gr \$r4,\$fcsr0 +diff --git a/gas/testsuite/gas/loongarch/fcsr.s b/gas/testsuite/gas/loongarch/fcsr.s +new file mode 100644 +index 00000000..5484fc54 +--- /dev/null ++++ b/gas/testsuite/gas/loongarch/fcsr.s +@@ -0,0 +1,2 @@ ++movgr2fcsr $fcsr0,$r5 ++movfcsr2gr $r4,$fcsr0 +diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h +index 94973cbd..de3642a8 100644 +--- a/include/opcode/loongarch.h ++++ b/include/opcode/loongarch.h +@@ -179,6 +179,8 @@ extern const char * const loongarch_r_lp64_name1[32]; + extern const char * const loongarch_f_normal_name[32]; + extern const char * const loongarch_f_lp64_name[32]; + extern const char * const loongarch_f_lp64_name1[32]; ++extern const char * const loongarch_fc_normal_name[4]; ++extern const char * const loongarch_fc_numeric_name[4]; + extern const char * const loongarch_c_normal_name[8]; + extern const char * const loongarch_cr_normal_name[4]; + extern const char * const loongarch_v_normal_name[32]; +diff --git a/opcodes/loongarch-dis.c b/opcodes/loongarch-dis.c +index b34847be..9a45660b 100644 +--- a/opcodes/loongarch-dis.c ++++ b/opcodes/loongarch-dis.c +@@ -43,6 +43,7 @@ get_loongarch_opcode_by_binfmt (insn_t insn) + + static const char * const *loongarch_r_disname = NULL; + static const char * const *loongarch_f_disname = NULL; ++static const char * const *loongarch_fc_disname = NULL; + static const char * const *loongarch_c_disname = NULL; + static const char * const *loongarch_cr_disname = NULL; + static const char * const *loongarch_v_disname = NULL; +@@ -61,6 +62,7 @@ set_default_loongarch_dis_options (void) + + loongarch_r_disname = loongarch_r_normal_name; + loongarch_f_disname = loongarch_f_normal_name; ++ loongarch_fc_disname = loongarch_fc_normal_name; + loongarch_c_disname = loongarch_c_normal_name; + loongarch_cr_disname = loongarch_cr_normal_name; + loongarch_v_disname = loongarch_v_normal_name; +@@ -120,7 +122,14 @@ dis_one_arg (char esc1, char esc2, const char *bit_field, + info->fprintf_func (info->stream, "%s", loongarch_r_disname[u_imm]); + break; + case 'f': +- info->fprintf_func (info->stream, "%s", loongarch_f_disname[u_imm]); ++ switch (esc2) ++ { ++ case 'c': ++ info->fprintf_func (info->stream, "%s", loongarch_fc_disname[u_imm]); ++ break; ++ default: ++ info->fprintf_func (info->stream, "%s", loongarch_f_disname[u_imm]); ++ } + break; + case 'c': + switch (esc2) +diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c +index 1e251e3d..687e5a6f 100644 +--- a/opcodes/loongarch-opc.c ++++ b/opcodes/loongarch-opc.c +@@ -75,6 +75,16 @@ const char * const loongarch_f_lp64_name1[32] = + "", "", "", "", "", "", "", "", + }; + ++const char *const loongarch_fc_normal_name[4] = ++{ ++ "$fcsr0", "$fcsr1", "$fcsr2", "$fcsr3", ++}; ++ ++const char *const loongarch_fc_numeric_name[4] = ++{ ++ "$r0", "$r1", "$r2", "$r3", ++}; ++ + const char * const loongarch_c_normal_name[8] = + { + "$fcc0", "$fcc1", "$fcc2", "$fcc3", "$fcc4", "$fcc5", "$fcc6", "$fcc7", +@@ -413,8 +423,8 @@ static struct loongarch_opcode loongarch_float_opcodes[] = { + {0x0114b400, 0xfffffc00, "movfr2gr.s", "r0:5,f5:5", 0, 0, 0, 0}, + {0x0114b800, 0xfffffc00, "movfr2gr.d", "r0:5,f5:5", 0, 0, 0, 0}, + {0x0114bc00, 0xfffffc00, "movfrh2gr.s", "r0:5,f5:5", 0, 0, 0, 0}, +-{0x0114c000, 0xfffffc00, "movgr2fcsr", "r0:5,r5:5", 0, 0, 0, 0}, +-{0x0114c800, 0xfffffc00, "movfcsr2gr", "r0:5,r5:5", 0, 0, 0, 0}, ++{0x0114c000, 0xfffffc1c, "movgr2fcsr", "fc0:2,r5:5", 0, 0, 0, 0}, ++{0x0114c800, 0xffffff80, "movfcsr2gr", "r0:5,fc5:2", 0, 0, 0, 0}, + {0x0114d000, 0xfffffc18, "movfr2cf", "c0:3,f5:5", 0, 0, 0, 0}, + {0x0114d400, 0xffffff00, "movcf2fr", "f0:5,c5:3", 0, 0, 0, 0}, + {0x0114d800, 0xfffffc18, "movgr2cf", "c0:3,r5:5", 0, 0, 0, 0}, +-- +2.33.0 + diff --git a/binutils.spec b/binutils.spec index d7754c1..11e729d 100644 --- a/binutils.spec +++ b/binutils.spec @@ -24,7 +24,7 @@ # /usr/bin/aarch64-linux-gnu-ar # /usr/bin/aarch64-linux-gnu-as # [etc] -%define anolis_release .0.1 +%define anolis_release .0.2 %if 0%{!?binutils_target:1} @@ -684,6 +684,7 @@ Patch1010: Add-missing-opcode-and-3A6000.patch Patch1011: Some-testsuite-fix.patch Patch1012: Always-allocate-a-new-pointer-for-section-name-that-.patch Patch1013: binutils-Remove-ABI_XLP32-related-code.patch +Patch1014: 0001-FCSR-fcsrX.patch #end #---------------------------------------------------------------------------- @@ -950,6 +951,7 @@ using libelf instead of BFD. %patch1011 -p1 %patch1012 -p1 %patch1013 -p1 +%patch1014 -p1 # We cannot run autotools as there is an exact requirement of autoconf-2.59. # FIXME - this is no longer true. Maybe try reinstating autotool use ? @@ -1399,6 +1401,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Fri Feb 14 2025 Peng Fan - 2.30-125.0.2 +- LoongArch: Support referring to FCSRs as $fcsrX. + * Mon Nov 18 2024 Xue haolin - 2.30-125.0.1 - Rebrand to Anolis OS. - Add loongarch support. (lixing@loongson.cn) -- Gitee