public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Cooper Qu <cooper.qu@linux.alibaba.com>,
	Lifang Xia <lifang_xia@c-sky.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] CSKY: Add objdump option -M abi-names.
Date: Fri, 25 Sep 2020 22:48:37 +0930	[thread overview]
Message-ID: <20200925131837.GO5452@bubble.grove.modra.org> (raw)
In-Reply-To: <e8f6d6cc-bad1-5ee8-0ae9-97cb1d91fd8a@c-sky.com>

On Wed, Sep 23, 2020 at 11:50:35PM +0800, Lifang Xia wrote:
> On 2020/9/17 14:30, Cooper Qu wrote:
> > Add option parser for disassembler, and refine the codes of
> > parse register operand and disassemble register operand.
> > While strengthen the operands legality check of some instructions.
> >
> > Co-Authored-By: Lifang Xia <lifang_xia@c-sky.com>
> >
> > gas/
> > 	* config/tc-csky.c (parse_type_ctrlreg): Use function
> > 	csky_get_control_regno to operand.
> > 	(csky_get_reg_val): Likewise.
> > 	(is_reg_sp_with_bracket): Use function csky_get_reg_val
> > 	to parse operand.
> > 	(is_reg_sp): Refine.
> > 	(is_oimm_within_range): Fix, report error when operand
> > 	is not constant.
> > 	(parse_type_cpreg): Refine.
> > 	(parse_type_cpcreg): Refine.
> > 	(get_operand_value): Add handle of OPRND_TYPE_IMM5b_LS.
> > 	(md_assemble): Fix no error reporting somtimes when
> > 	operands number are not fit.
> > 	(csky_addc64): Refine.
> > 	(csky_subc64): Refine.
> > 	(csky_or64): Refine.
> > 	(v1_work_fpu_fo): Refine.
> > 	(v1_work_fpu_read): Refine.
> > 	(v1_work_fpu_writed): Refine.
> > 	(v1_work_fpu_readd): Refine.
> > 	(v2_work_addc): New function, strengthen the operands legality
> > 	check of addc.
> > 	* gas/testsuite/gas/csky/all.d : Use register number format when
> > 	disassemble register name by default.
> > 	* gas/testsuite/gas/csky/cskyv2_all.d : Likewise.
> > 	* gas/testsuite/gas/csky/trust.d: Likewise.
> > 	* gas/testsuite/gas/csky/cskyv2_ck860.d : Fix.
> > 	* gas/testsuite/gas/csky/trust.s : Fix.
> >
> > opcodes/
> > 	* csky-dis.c (using_abi): New.
> > 	(parse_csky_dis_options): New function.
> > 	(get_gr_name): New function.
> > 	(get_cr_name): New function.
> > 	(csky_output_operand): Use get_gr_name and get_cr_name to
> > 	disassemble and add handle of OPRND_TYPE_IMM5b_LS.
> > 	(print_insn_csky): Parse disassembler options.
> > 	* opcodes/csky-opc.h (OPRND_TYPE_IMM5b_LS): New enum.
> > 	(GENARAL_REG_BANK): Define.
> > 	(REG_SUPPORT_ALL): Define.
> > 	(REG_SUPPORT_ALL): New.
> > 	(ASH): Define.
> > 	(REG_SUPPORT_A): Define.
> > 	(REG_SUPPORT_B): Define.
> > 	(REG_SUPPORT_C): Define.
> > 	(REG_SUPPORT_D): Define.
> > 	(REG_SUPPORT_E): Define.
> > 	(csky_abiv1_general_regs): New.
> > 	(csky_abiv1_control_regs): New.
> > 	(csky_abiv2_general_regs): New.
> > 	(csky_abiv2_control_regs): New.
> > 	(get_register_name): New function.
> > 	(get_register_number): New function.
> > 	(csky_get_general_reg_name): New function.
> > 	(csky_get_general_regno): New function.
> > 	(csky_get_control_reg_name): New function.
> > 	(csky_get_control_regno): New function.
> > 	(csky_v2_opcodes): Prefer two oprerans format for bclri and
> > 	bseti, strengthen the operands legality check of addc, zext
> > 	and sext.

This patch results in ubsan errors, for example
opcodes/csky-opc.h:929 shift exponent 536870912 is too large

I took a look at what I think the code is trying to do, and came up
with the following fix.  Please check that this is correct.

opcodes/
	* csky-opc.h: Formatting.
	(GENERAL_REG_BANK): Correct spelling.  Update use throughout file.
	(get_register_name): Mask arch with CSKY_ARCH_MASK for shift,
	and shift 1u.
	(get_register_number): Likewise.
	* csky-dis.c (get_gr_name, get_cr_name): Don't mask mach_flag.
gas/
	* config/tc-csky.c (parse_type_ctrlreg): Don't mask mach_flag
	for csky_get_control_regno.
	(csky_get_reg_val): Likewise when calling csky_get_general_regno.

diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c
index 60d5aa1f53..569fe2bc85 100644
--- a/gas/config/tc-csky.c
+++ b/gas/config/tc-csky.c
@@ -2565,8 +2565,7 @@ parse_type_ctrlreg (char** oper)
 	}
       else
 	{
-	  crx = csky_get_control_regno (mach_flag & CSKY_ARCH_MASK,
-			  s, &s, &sel);
+	  crx = csky_get_control_regno (mach_flag, s, &s, &sel);
 	  if (crx < 0)
 	    {
 	      SET_ERROR_STRING (ERROR_CREG_ILLEGAL, s);
@@ -2577,8 +2576,7 @@ parse_type_ctrlreg (char** oper)
     }
   else if (i == -1)
     {
-      i = csky_get_control_regno (mach_flag & CSKY_ARCH_MASK,
-				  s, &s, &sel);
+      i = csky_get_control_regno (mach_flag, s, &s, &sel);
       if (i < 0)
 	{
 	  SET_ERROR_STRING (ERROR_CREG_ILLEGAL, s);
@@ -2595,7 +2593,7 @@ csky_get_reg_val (char *str, int *len)
 {
   int regno = 0;
   char *s = str;
-  regno = csky_get_general_regno (mach_flag & CSKY_ARCH_MASK, str, &s);
+  regno = csky_get_general_regno (mach_flag, str, &s);
   *len = (s - str);
   return regno;
 }
diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c
index ce20f58c47..b31b685b90 100644
--- a/opcodes/csky-dis.c
+++ b/opcodes/csky-dis.c
@@ -287,14 +287,14 @@ parse_csky_dis_options (const char *opts_in)
 static const char *
 get_gr_name (int regno)
 {
-  return csky_get_general_reg_name (mach_flag & CSKY_ABI_MASK, regno, using_abi);
+  return csky_get_general_reg_name (mach_flag, regno, using_abi);
 }
 
 /* Get control register name.  */
 static const char *
 get_cr_name (unsigned int regno, int bank)
 {
-  return csky_get_control_reg_name (mach_flag & CSKY_ABI_MASK, bank, regno, using_abi);
+  return csky_get_control_reg_name (mach_flag, bank, regno, using_abi);
 }
 
 static int
diff --git a/opcodes/csky-opc.h b/opcodes/csky-opc.h
index 8cd0d1e2a2..199b891371 100644
--- a/opcodes/csky-opc.h
+++ b/opcodes/csky-opc.h
@@ -653,7 +653,7 @@ const struct psrbit cskyv2_psr_bits[] =
   {0, 0, NULL},
 };
 
-#define GENARAL_REG_BANK      0x80000000
+#define GENERAL_REG_BANK      0x80000000
 #define REG_SUPPORT_ALL 0xffffffff
 
 /* CSKY register description.  */
@@ -698,7 +698,7 @@ struct csky_reg_def
 static struct csky_reg_def csky_abiv1_general_regs[] = 
 {
 #define DECLARE_REG(regno, abi_name, support)		\
-  {GENARAL_REG_BANK, regno, "r"#regno, abi_name, support, NULL}
+  {GENERAL_REG_BANK, regno, "r"#regno, abi_name, support, NULL}
 
   DECLARE_REG (0, "sp", REG_SUPPORT_ALL),
   DECLARE_REG (1, NULL, REG_SUPPORT_ALL),
@@ -769,7 +769,7 @@ static struct csky_reg_def csky_abiv2_general_regs[] =
 #undef DECLARE_REG
 #endif
 #define DECLARE_REG(regno, abi_name, support)		\
-  {GENARAL_REG_BANK, regno, "r"#regno, abi_name, support, NULL}
+  {GENERAL_REG_BANK, regno, "r"#regno, abi_name, support, NULL}
 
   DECLARE_REG (0, "a0", REG_SUPPORT_ALL),
   DECLARE_REG (1, "a1", REG_SUPPORT_ALL),
@@ -926,7 +926,7 @@ get_register_name (struct csky_reg_def *reg_table,
     {
       if (reg_table[i].bank == bank
 	  && reg_table[i].regno == regno
-	  && (reg_table[i].arch_flag & (1 << arch)))
+	  && (reg_table[i].arch_flag & (1u << (arch & CSKY_ARCH_MASK))))
 	{
 	  if (is_abi && reg_table[i].abi_name)
 	    return reg_table[i].abi_name;
@@ -957,7 +957,7 @@ get_register_number (struct csky_reg_def *reg_table,
       len = strlen (reg_table[i].name);
       if ((strncasecmp (reg_table[i].name, s, len) == 0)
 	  && !(ISDIGIT (s[len]))
-	  && (reg_table[i].arch_flag & (1 << arch)))
+	  && (reg_table[i].arch_flag & (1u << (arch & CSKY_ARCH_MASK))))
 	{
 	  *end = s + len;
 	  *bank = reg_table[i].bank;
@@ -973,7 +973,7 @@ get_register_number (struct csky_reg_def *reg_table,
       len = strlen (reg_table[i].abi_name);
       if ((strncasecmp (reg_table[i].abi_name, s, len) == 0)
 	  && !(ISALNUM (s[len]))
-	  && (reg_table[i].arch_flag & (1 << arch)))
+	  && (reg_table[i].arch_flag & (1u << (arch & CSKY_ARCH_MASK))))
 	{
 	  *end = s + len;
 	  *bank = reg_table[i].bank;
@@ -990,23 +990,22 @@ csky_get_general_reg_name (int arch, int regno, int is_abi)
 {
   struct csky_reg_def *reg_table;
 
-  if (IS_CSKY_ARCH_V1(arch))
+  if (IS_CSKY_ARCH_V1 (arch))
     reg_table = csky_abiv1_general_regs;
   else
     reg_table = csky_abiv2_general_regs;
 
-  return get_register_name (reg_table, arch,
-			    GENARAL_REG_BANK, regno, is_abi);
+  return get_register_name (reg_table, arch, GENERAL_REG_BANK, regno, is_abi);
 }
 
 /* Return general register's number.  */
 static inline int
-csky_get_general_regno(int arch, char *s, char **end)
+csky_get_general_regno (int arch, char *s, char **end)
 {
   struct csky_reg_def *reg_table;
   int bank = 0;
 
-  if (IS_CSKY_ARCH_V1(arch))
+  if (IS_CSKY_ARCH_V1 (arch))
     reg_table = csky_abiv1_general_regs;
   else
     reg_table = csky_abiv2_general_regs;
@@ -1020,22 +1019,21 @@ csky_get_control_reg_name (int arch, int bank, int regno, int is_abi)
 {
   struct csky_reg_def *reg_table;
 
-  if (IS_CSKY_ARCH_V1(arch))
+  if (IS_CSKY_ARCH_V1 (arch))
     reg_table = csky_abiv1_control_regs;
   else
     reg_table = csky_abiv2_control_regs;
 
-  return get_register_name (reg_table, arch, bank,
-			    regno, is_abi);
+  return get_register_name (reg_table, arch, bank, regno, is_abi);
 }
 
 /* Return control register's number.  */
 static inline int
-csky_get_control_regno(int arch, char *s, char **end, int *bank)
+csky_get_control_regno (int arch, char *s, char **end, int *bank)
 {
   struct csky_reg_def *reg_table;
 
-  if (IS_CSKY_ARCH_V1(arch))
+  if (IS_CSKY_ARCH_V1 (arch))
     reg_table = csky_abiv1_control_regs;
   else
     reg_table = csky_abiv2_control_regs;


-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2020-09-25 13:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17  6:30 Cooper Qu
2020-09-23 15:50 ` Lifang Xia
2020-09-25 13:18   ` Alan Modra [this message]
2020-09-25 16:45     ` Cooper Qu
2020-09-24 14:14 ` [PUSHED] " Andrew Burgess
2020-09-24  3:14 Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200925131837.GO5452@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=cooper.qu@linux.alibaba.com \
    --cc=lifang_xia@c-sky.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).