public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* kvx_dis_init
@ 2023-08-22  0:05 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-08-22  0:05 UTC (permalink / raw)
  To: binutils

kvx_dis_init currently always returns true, but error conditions do so
by "return -1" which converts to true.  The return status is ignored
anyway, and it doesn't make much sense to error on unexpected arch or
mach:  If print_insn_kvx is called then the atch is known to be kvx,
and it's better to choose some default for a user passing an unknown
mach value rather than segfaulting in decode_insn when env.opc_table
is NULL.

I've chosen the default mach to be bfd_mach_kv3_1, the default in
bfd/cpu-kvx.c, not that it matters very much.  In normal objdump/gdb
usage, info->mach won't be an unexpected value.

	* kvx-dis.c (kvx_dis_init): Return void.  Don't error on
	unexpected arch or mach.  Default to bfd_mach_kv3_1 for
	unknown mach.  Don't clear info->disassembler_options.

diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
index eabef4af171..d7b86791c30 100644
--- a/opcodes/kvx-dis.c
+++ b/opcodes/kvx-dis.c
@@ -207,15 +207,9 @@ static struct kvx_dis_env env = {
   .kvx_max_dec_registers = 0
 };
 
-static bool
+static void
 kvx_dis_init (struct disassemble_info *info)
 {
-  if (info->arch != bfd_arch_kvx)
-    {
-      (*info->fprintf_func) (info->stream, "error: Unknown architecture\n");
-      return -1;
-    }
-
   env.kvx_arch_size = 32;
   switch (info->mach)
     {
@@ -224,6 +218,7 @@ kvx_dis_init (struct disassemble_info *info)
       /* fallthrough */
     case bfd_mach_kv3_1_usr:
     case bfd_mach_kv3_1:
+    default:
       env.opc_table = kvx_kv3_v1_optab;
       env.kvx_regfiles = kvx_kv3_v1_regfiles;
       env.kvx_registers = kvx_kv3_v1_registers;
@@ -252,26 +247,14 @@ kvx_dis_init (struct disassemble_info *info)
       env.kvx_modifiers = kvx_kv4_v1_modifiers;
       env.kvx_dec_registers = kvx_kv4_v1_dec_registers;
       break;
-
-    default:
-      /* Core not supported.  */
-      (*info->fprintf_func) (info->stream, "disassembling not supported for "
-			     "this KVX core! (core:%d)", (int) info->mach);
-      return -1;
     }
 
   env.kvx_max_dec_registers = env.kvx_regfiles[KVX_REGFILE_DEC_REGISTERS];
 
   if (info->disassembler_options)
-    {
-      parse_kvx_dis_options (info->disassembler_options);
+    parse_kvx_dis_options (info->disassembler_options);
 
-      /* To avoid repeated parsing of these options, we remove them here.  */
-      info->disassembler_options = NULL;
-    }
   env.initialized_p = 1;
-
-  return env.initialized_p;
 }
 
 static int

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-22  0:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22  0:05 kvx_dis_init Alan Modra

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).