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 2/4] x86/Intel: drop LONG_DOUBLE_MNEM_SUFFIX
Date: Wed, 30 Nov 2022 09:55:11 +0100	[thread overview]
Message-ID: <934cece1-77ed-b4ee-a61d-451d71680a9e@suse.com> (raw)
In-Reply-To: <b309d824-01de-72fd-6eaf-f82475acfc02@suse.com>

With the removal of its use for FPU insns the suffix is now finally
properly misnamed. Drop its use altogether, replacing it by a separate
boolean instead.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -80,9 +80,6 @@
 #define SHORT_MNEM_SUFFIX 's'
 #define LONG_MNEM_SUFFIX  'l'
 #define QWORD_MNEM_SUFFIX  'q'
-/* Intel Syntax.  Use a non-ascii letter since since it never appears
-   in instructions.  */
-#define LONG_DOUBLE_MNEM_SUFFIX '\1'
 
 #define END_OF_INSN '\0'
 
@@ -313,6 +310,9 @@ struct _i386_insn
     /* The operand to a branch insn indicates an absolute branch.  */
     bool jumpabsolute;
 
+    /* The operand to a branch insn indicates a far branch.  */
+    bool far_branch;
+
     /* There is a memory operand of (%dx) which should be only used
        with input/output instructions.  */
     bool input_output_operand;
@@ -6494,14 +6494,6 @@ match_template (char mnem_suffix)
     case QWORD_MNEM_SUFFIX:
       suffix_check.no_qsuf = 1;
       break;
-    default:
-      /* NB: In Intel syntax, normally we can check for memory operand
-	 size when there is no mnemonic suffix.  But jmp and call have
-	 2 different encodings with Dword memory operand size, one with
-	 No_ldSuf and the other without.  i.suffix is set to
-	 LONG_DOUBLE_MNEM_SUFFIX to skip the one with No_ldSuf.  */
-      if (i.suffix == LONG_DOUBLE_MNEM_SUFFIX)
-	suffix_check.no_ldsuf = 1;
     }
 
   for (t = current_templates->start; t < current_templates->end; t++)
@@ -6555,8 +6547,7 @@ match_template (char mnem_suffix)
 	  || (t->opcode_modifier.no_wsuf && suffix_check.no_wsuf)
 	  || (t->opcode_modifier.no_lsuf && suffix_check.no_lsuf)
 	  || (t->opcode_modifier.no_ssuf && suffix_check.no_ssuf)
-	  || (t->opcode_modifier.no_qsuf && suffix_check.no_qsuf)
-	  || (t->opcode_modifier.no_ldsuf && suffix_check.no_ldsuf))
+	  || (t->opcode_modifier.no_qsuf && suffix_check.no_qsuf))
 	continue;
 
       specific_error = progress (operand_size_mismatch);
@@ -6574,6 +6565,15 @@ match_template (char mnem_suffix)
       if (i.jumpabsolute && t->opcode_modifier.jump != JUMP_ABSOLUTE)
 	continue;
 
+      /* In Intel syntax, normally we can check for memory operand size when
+	 there is no mnemonic suffix.  But jmp and call have 2 different
+	 encodings with Dword memory operand size.  Skip the "near" one
+	 (permitting a register operand) when "far" was requested.  */
+      if (i.far_branch
+	  && t->opcode_modifier.jump == JUMP_ABSOLUTE
+	  && t->operand_types[0].bitfield.class == Reg)
+	continue;
+
       for (j = 0; j < MAX_OPERANDS; j++)
 	operand_types[j] = t->operand_types[j];
 
--- a/gas/config/tc-i386-intel.c
+++ b/gas/config/tc-i386-intel.c
@@ -715,8 +715,10 @@ i386_intel_operand (char *operand_string
 		   && (current_templates->start->opcode_modifier.jump == JUMP
 		       || current_templates->start->opcode_modifier.jump
 			  == JUMP_DWORD))
-	    suffix = flag_code == CODE_16BIT ? LONG_DOUBLE_MNEM_SUFFIX
-					     : WORD_MNEM_SUFFIX;
+	    {
+	      i.far_branch = true;
+	      suffix = WORD_MNEM_SUFFIX;
+	    }
 	  else if (got_a_float == 1)	/* "f..." */
 	    suffix = SHORT_MNEM_SUFFIX;
 	  else
@@ -733,7 +735,7 @@ i386_intel_operand (char *operand_string
 	    {
 	      if (flag_code == CODE_16BIT)
 		add_prefix (DATA_PREFIX_OPCODE);
-	      suffix = LONG_DOUBLE_MNEM_SUFFIX;
+	      i.far_branch = true;
 	    }
 	  break;
 
@@ -774,7 +776,7 @@ i386_intel_operand (char *operand_string
 	  break;
 
 	case O_far_ptr:
-	  suffix = LONG_DOUBLE_MNEM_SUFFIX;
+	  i.far_branch = true;
 	  /* FALLTHROUGH */
 	case O_near_ptr:
 	  if (current_templates->start->opcode_modifier.jump != JUMP
@@ -833,10 +835,6 @@ i386_intel_operand (char *operand_string
 		  if (t->opcode_modifier.no_ssuf)
 		    continue;
 		  break;
-		case LONG_DOUBLE_MNEM_SUFFIX:
-		  if (t->opcode_modifier.no_ldsuf)
-		    continue;
-		  break;
 		default:
 		  abort ();
 		}
@@ -916,7 +914,11 @@ i386_intel_operand (char *operand_string
 		return 0;
 	      }
 	    else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
-	      jumpabsolute = true;
+	      {
+		jumpabsolute = true;
+		if (intel_state.op_modifier == O_far_ptr)
+		  i.far_branch = true;
+	      }
 	    else
 	      {
 		i386_operand_type types;
@@ -943,8 +945,6 @@ i386_intel_operand (char *operand_string
 		    this_operand = i.operands++;
 		    i.types[this_operand].bitfield.unspecified = 1;
 		  }
-		if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
-		  i.suffix = 0;
 		intel_state.seg = NULL;
 		intel_state.is_mem = 0;
 	      }
--- a/opcodes/i386-opc.tbl
+++ b/opcodes/i386-opc.tbl
@@ -434,7 +434,7 @@ call, 0xff, 2, Cpu64, Amd64|Modrm|JumpAb
 call, 0xff, 2, Cpu64, Intel64|Modrm|JumpAbsolute|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_ldSuf|NoRex64|BNDPrefixOk|NoTrackPrefixOk, { Reg64|Unspecified|BaseIndex }
 // Intel Syntax remaining call instances.
 call, 0x9a, None, CpuNo64, JumpInterSegment|DefaultSize|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Imm16, Imm16|Imm32 }
-call, 0xff, 3, 0, Amd64|Modrm|JumpAbsolute|DefaultSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf, { Dword|Fword|BaseIndex }
+call, 0xff, 3, 0, Amd64|Modrm|JumpAbsolute|DefaultSize|NoSuf, { Dword|Fword|BaseIndex }
 call, 0xff, 3, Cpu64, Intel64|Modrm|JumpAbsolute|NoSuf, { Dword|Fword|Tbyte|BaseIndex }
 lcall, 0x9a, None, CpuNo64, JumpInterSegment|DefaultSize|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Imm16, Imm16|Imm32 }
 lcall, 0xff, 3, 0, Amd64|Modrm|JumpAbsolute|DefaultSize|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Unspecified|BaseIndex }
@@ -447,7 +447,7 @@ jmp, 0xff, 4, Cpu64, Amd64|Modrm|JumpAbs
 jmp, 0xff, 4, Cpu64, Intel64|Modrm|JumpAbsolute|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_ldSuf|NoRex64|BNDPrefixOk|NoTrackPrefixOk, { Reg64|Unspecified|BaseIndex }
 // Intel Syntax remaining jmp instances.
 jmp, 0xea, None, CpuNo64, JumpInterSegment|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Imm16, Imm16|Imm32 }
-jmp, 0xff, 5, 0, Amd64|Modrm|JumpAbsolute|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf, { Dword|Fword|BaseIndex }
+jmp, 0xff, 5, 0, Amd64|Modrm|JumpAbsolute|NoSuf, { Dword|Fword|BaseIndex }
 jmp, 0xff, 5, Cpu64, Intel64|Modrm|JumpAbsolute|NoSuf, { Dword|Fword|Tbyte|BaseIndex }
 ljmp, 0xea, None, CpuNo64, JumpInterSegment|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Imm16, Imm16|Imm32 }
 ljmp, 0xff, 5, 0, Amd64|Modrm|JumpAbsolute|No_bSuf|No_sSuf|No_qSuf|No_ldSuf, { Unspecified|BaseIndex }


  parent reply	other threads:[~2022-11-30  8:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30  8:53 [PATCH 0/4] x86: get rid of LONG_DOUBLE_MNEM_SUFFIX and No_ldSuf Jan Beulich
2022-11-30  8:54 ` [PATCH 1/4] x86/Intel: restrict use of LONG_DOUBLE_MNEM_SUFFIX Jan Beulich
2022-11-30  8:55 ` Jan Beulich [this message]
2022-11-30  8:55 ` [PATCH 3/4] x86: drop No_ldSuf Jan Beulich
2022-11-30  8:56 ` [PATCH 4/4] x86: rework of match_template()'s suffix checking Jan Beulich
2022-11-30 22:25 ` [PATCH 0/4] x86: get rid of LONG_DOUBLE_MNEM_SUFFIX and No_ldSuf H.J. Lu

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=934cece1-77ed-b4ee-a61d-451d71680a9e@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).