public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 1/2] x86: move get<N>() disassembler helper functions
Date: Fri, 5 May 2023 13:12:44 +0200	[thread overview]
Message-ID: <52d14c6e-e232-efe3-d486-06cda1c19fdf@suse.com> (raw)
In-Reply-To: <9369c14f-ce90-61ac-c2fd-8588c82b35a5@suse.com>

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


  reply	other threads:[~2023-05-05 11:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 11:11 [PATCH 0/2] x86: move a few " Jan Beulich
2023-05-05 11:12 ` Jan Beulich [this message]
2023-05-05 11:13 ` [PATCH 2/2] x86: move a few more " Jan Beulich

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=52d14c6e-e232-efe3-d486-06cda1c19fdf@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.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).