public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] x86: move a few disassembler helper functions
@ 2023-05-05 11:11 Jan Beulich
  2023-05-05 11:12 ` [PATCH 1/2] x86: move get<N>() " Jan Beulich
  2023-05-05 11:13 ` [PATCH 2/2] x86: move a few more " Jan Beulich
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2023-05-05 11:11 UTC (permalink / raw)
  To: Binutils; +Cc: H.J. Lu

Let's try to avoid the need for forward decls when easily possible.

1: move get<N>() disassembler helper functions
2: move a few more disassembler helper functions

Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] x86: move get<N>() disassembler helper functions
  2023-05-05 11:11 [PATCH 0/2] x86: move a few disassembler helper functions Jan Beulich
@ 2023-05-05 11:12 ` Jan Beulich
  2023-05-05 11:13 ` [PATCH 2/2] x86: move a few more " Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2023-05-05 11:12 UTC (permalink / raw)
  To: Binutils; +Cc: H.J. Lu

... such that none of them would need forward declarations anymore.

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -47,10 +47,6 @@ static void oappend_with_style (instr_in
 				enum disassembler_style);
 static void oappend (instr_info *, const char *);
 static void append_seg (instr_info *);
-static bool get32s (instr_info *, bfd_vma *);
-static bool get16 (instr_info *, bfd_vma *);
-static bool get16s (instr_info *, bfd_vma *);
-static bool get8s (instr_info *, bfd_vma *);
 static void set_op (instr_info *, bfd_vma, bool);
 
 static bool OP_E (instr_info *, int, int);
@@ -11715,6 +11711,77 @@ print_register (instr_info *ins, unsigne
 }
 
 static bool
+get8s (instr_info *ins, bfd_vma *res)
+{
+  if (!fetch_code (ins->info, ins->codep + 1))
+    return false;
+  *res = (((bfd_vma) *ins->codep++ & 0xff) ^ 0x80) - 0x80;
+  return true;
+}
+
+static bool
+get16 (instr_info *ins, bfd_vma *res)
+{
+  if (!fetch_code (ins->info, ins->codep + 2))
+    return false;
+  *res = (bfd_vma) *ins->codep++ & 0xff;
+  *res |= ((bfd_vma) *ins->codep++ & 0xff) << 8;
+  return true;
+}
+
+static bool
+get16s (instr_info *ins, bfd_vma *res)
+{
+  if (!get16 (ins, res))
+    return false;
+  *res = (*res ^ 0x8000) - 0x8000;
+  return true;
+}
+
+static bool
+get32 (instr_info *ins, bfd_vma *res)
+{
+  if (!fetch_code (ins->info, ins->codep + 4))
+    return false;
+  *res = *ins->codep++ & (bfd_vma) 0xff;
+  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 8;
+  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 16;
+  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 24;
+  return true;
+}
+
+static bool
+get32s (instr_info *ins, bfd_vma *res)
+{
+  if (!get32 (ins, res))
+    return false;
+
+  *res = (*res ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31);
+
+  return true;
+}
+
+static bool
+get64 (instr_info *ins, uint64_t *res)
+{
+  unsigned int a;
+  unsigned int b;
+
+  if (!fetch_code (ins->info, ins->codep + 8))
+    return false;
+  a = *ins->codep++ & 0xff;
+  a |= (*ins->codep++ & 0xff) << 8;
+  a |= (*ins->codep++ & 0xff) << 16;
+  a |= (*ins->codep++ & 0xffu) << 24;
+  b = *ins->codep++ & 0xff;
+  b |= (*ins->codep++ & 0xff) << 8;
+  b |= (*ins->codep++ & 0xff) << 16;
+  b |= (*ins->codep++ & 0xffu) << 24;
+  *res = a + ((uint64_t) b << 32);
+  return true;
+}
+
+static bool
 OP_E_memory (instr_info *ins, int bytemode, int sizeflag)
 {
   int add = (ins->rex & REX_B) ? 8 : 0;
@@ -12249,77 +12316,6 @@ OP_G (instr_info *ins, int bytemode, int
   return true;
 }
 
-static bool
-get64 (instr_info *ins, uint64_t *res)
-{
-  unsigned int a;
-  unsigned int b;
-
-  if (!fetch_code (ins->info, ins->codep + 8))
-    return false;
-  a = *ins->codep++ & 0xff;
-  a |= (*ins->codep++ & 0xff) << 8;
-  a |= (*ins->codep++ & 0xff) << 16;
-  a |= (*ins->codep++ & 0xffu) << 24;
-  b = *ins->codep++ & 0xff;
-  b |= (*ins->codep++ & 0xff) << 8;
-  b |= (*ins->codep++ & 0xff) << 16;
-  b |= (*ins->codep++ & 0xffu) << 24;
-  *res = a + ((uint64_t) b << 32);
-  return true;
-}
-
-static bool
-get32 (instr_info *ins, bfd_vma *res)
-{
-  if (!fetch_code (ins->info, ins->codep + 4))
-    return false;
-  *res = *ins->codep++ & (bfd_vma) 0xff;
-  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 8;
-  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 16;
-  *res |= (*ins->codep++ & (bfd_vma) 0xff) << 24;
-  return true;
-}
-
-static bool
-get32s (instr_info *ins, bfd_vma *res)
-{
-  if (!get32 (ins, res))
-    return false;
-
-  *res = (*res ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31);
-
-  return true;
-}
-
-static bool
-get16 (instr_info *ins, bfd_vma *res)
-{
-  if (!fetch_code (ins->info, ins->codep + 2))
-    return false;
-  *res = (bfd_vma) *ins->codep++ & 0xff;
-  *res |= ((bfd_vma) *ins->codep++ & 0xff) << 8;
-  return true;
-}
-
-static bool
-get16s (instr_info *ins, bfd_vma *res)
-{
-  if (!get16 (ins, res))
-    return false;
-  *res = (*res ^ 0x8000) - 0x8000;
-  return true;
-}
-
-static bool
-get8s (instr_info *ins, bfd_vma *res)
-{
-  if (!fetch_code (ins->info, ins->codep + 1))
-    return false;
-  *res = (((bfd_vma) *ins->codep++ & 0xff) ^ 0x80) - 0x80;
-  return true;
-}
-
 static void
 set_op (instr_info *ins, bfd_vma op, bool riprel)
 {


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] x86: move a few more disassembler helper functions
  2023-05-05 11:11 [PATCH 0/2] x86: move a few disassembler helper functions Jan Beulich
  2023-05-05 11:12 ` [PATCH 1/2] x86: move get<N>() " Jan Beulich
@ 2023-05-05 11:13 ` Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2023-05-05 11:13 UTC (permalink / raw)
  To: Binutils; +Cc: H.J. Lu

... such that they wouldn't need forward declarations anymore. Note that
append_seg() already was suitably placed.

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -45,9 +45,6 @@ static bool dofloat (instr_info *, int);
 static int putop (instr_info *, const char *, int);
 static void oappend_with_style (instr_info *, const char *,
 				enum disassembler_style);
-static void oappend (instr_info *, const char *);
-static void append_seg (instr_info *);
-static void set_op (instr_info *, bfd_vma, bool);
 
 static bool OP_E (instr_info *, int, int);
 static bool OP_E_memory (instr_info *, int, int);
@@ -90,8 +87,6 @@ static bool OP_0f07 (instr_info *, int,
 static bool OP_Monitor (instr_info *, int, int);
 static bool OP_Mwait (instr_info *, int, int);
 
-static bool BadOp (instr_info *);
-
 static bool PCLMUL_Fixup (instr_info *, int, int);
 static bool VPCMP_Fixup (instr_info *, int, int);
 static bool VPCOM_Fixup (instr_info *, int, int);
@@ -9504,7 +9499,15 @@ get_sib (instr_info *ins, int sizeflag)
   return true;
 }
 
-/* Like oappend (below), but S is a string starting with '%'.  In
+/* Like oappend_with_style (below) but always with text style.  */
+
+static void
+oappend (instr_info *ins, const char *s)
+{
+  oappend_with_style (ins, s, dis_style_text);
+}
+
+/* Like oappend (above), but S is a string starting with '%'.  In
    Intel syntax, the '%' is elided.  */
 
 static void
@@ -11201,14 +11204,6 @@ oappend_with_style (instr_info *ins, con
   ins->obufp = stpcpy (ins->obufp, s);
 }
 
-/* Like oappend_with_style but always with text style.  */
-
-static void
-oappend (instr_info *ins, const char *s)
-{
-  oappend_with_style (ins, s, dis_style_text);
-}
-
 /* Add a single character C to the buffer pointer to by INS->obufp, marking
    the style for the character as STYLE.  */
 
@@ -11781,6 +11776,26 @@ get64 (instr_info *ins, uint64_t *res)
   return true;
 }
 
+static void
+set_op (instr_info *ins, bfd_vma op, bool riprel)
+{
+  ins->op_index[ins->op_ad] = ins->op_ad;
+  if (ins->address_mode == mode_64bit)
+    ins->op_address[ins->op_ad] = op;
+  else /* Mask to get a 32-bit address.  */
+    ins->op_address[ins->op_ad] = op & 0xffffffff;
+  ins->op_riprel[ins->op_ad] = riprel;
+}
+
+static bool
+BadOp (instr_info *ins)
+{
+  /* Throw away prefixes and 1st. opcode byte.  */
+  ins->codep = ins->insn_codep + 1;
+  ins->obufp = stpcpy (ins->obufp, "(bad)");
+  return true;
+}
+
 static bool
 OP_E_memory (instr_info *ins, int bytemode, int sizeflag)
 {
@@ -12316,17 +12331,6 @@ OP_G (instr_info *ins, int bytemode, int
   return true;
 }
 
-static void
-set_op (instr_info *ins, bfd_vma op, bool riprel)
-{
-  ins->op_index[ins->op_ad] = ins->op_ad;
-  if (ins->address_mode == mode_64bit)
-    ins->op_address[ins->op_ad] = op;
-  else /* Mask to get a 32-bit address.  */
-    ins->op_address[ins->op_ad] = op & 0xffffffff;
-  ins->op_riprel[ins->op_ad] = riprel;
-}
-
 static bool
 OP_REG (instr_info *ins, int code, int sizeflag)
 {
@@ -13350,15 +13354,6 @@ OP_Monitor (instr_info *ins, int bytemod
   return true;
 }
 
-static bool
-BadOp (instr_info *ins)
-{
-  /* Throw away prefixes and 1st. opcode byte.  */
-  ins->codep = ins->insn_codep + 1;
-  ins->obufp = stpcpy (ins->obufp, "(bad)");
-  return true;
-}
-
 static bool
 REP_Fixup (instr_info *ins, int bytemode, int sizeflag)
 {


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-05 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 11:11 [PATCH 0/2] x86: move a few disassembler helper functions Jan Beulich
2023-05-05 11:12 ` [PATCH 1/2] x86: move get<N>() " Jan Beulich
2023-05-05 11:13 ` [PATCH 2/2] x86: move a few more " Jan Beulich

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