public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] i386: Don't add 0x66 prefix to IRET for .code16gcc
@ 2019-04-26 17:22 H.J. Lu
  2019-04-29  7:01 ` Jan Beulich
  0 siblings, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2019-04-26 17:22 UTC (permalink / raw)
  To: binutils

The .code16gcc directive supports 16bit mode with 32-bit address.  Since
IRET (opcode 0xcf) in 16bit mode returns from an interrupt in 16bit mode,
we shouldn't add 0x66 prefix for IRET.

	PR gas/24485
	* config/tc-i386.c (process_suffix): Don't add DATA_PREFIX_OPCODE
	to IRET for .code16gcc.
	* testsuite/gas/i386/jump16.s: Add IRET tests.
	* testsuite/gas/i386/jump16.d: Updated.
---
 gas/ChangeLog                   | 8 ++++++++
 gas/config/tc-i386.c            | 6 ++++++
 gas/testsuite/gas/i386/jump16.d | 2 ++
 gas/testsuite/gas/i386/jump16.s | 6 ++++++
 4 files changed, 22 insertions(+)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 8558ecd7b4..c94ffdda0b 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,11 @@
+2019-04-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/24485
+	* config/tc-i386.c (process_suffix): Don't add DATA_PREFIX_OPCODE
+	to IRET for .code16gcc.
+	* testsuite/gas/i386/jump16.s: Add IRET tests.
+	* testsuite/gas/i386/jump16.d: Updated.
+
 2019-04-25  Alexandre Oliva  <aoliva@redhat.com>
 	    Alan Modra  <amodra@gmail.com>
 
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 5eb6c4c269..032b1d3081 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -6352,7 +6352,13 @@ process_suffix (void)
 	    if (!add_prefix (ADDR_PREFIX_OPCODE))
 	      return 0;
 	}
+      /* stackop_size is set to LONG_MNEM_SUFFIX for the .code16gcc
+	 directive to support 16bit mode with 32-bit address.  Since
+	 IRET (opcode 0xcf) in 16bit mode returns from an interrupt
+	 in 16bit mode, we shouldn't add DATA_PREFIX_OPCODE here.  */
       else if (i.suffix != QWORD_MNEM_SUFFIX
+	       && (stackop_size != LONG_MNEM_SUFFIX
+		   || i.tm.base_opcode != 0xcf)
 	       && !i.tm.opcode_modifier.ignoresize
 	       && !i.tm.opcode_modifier.floatmf
 	       && !i.tm.opcode_modifier.vex
diff --git a/gas/testsuite/gas/i386/jump16.d b/gas/testsuite/gas/i386/jump16.d
index a83bad6157..7a1dc7661e 100644
--- a/gas/testsuite/gas/i386/jump16.d
+++ b/gas/testsuite/gas/i386/jump16.d
@@ -67,4 +67,6 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	ea 10 10 90 90       	ljmp   \$0x9090,\$0x1010
 [ 	]*[a-f0-9]+:	ea 00 00 90 90       	ljmp   \$0x9090,\$0x0	ed: (R_386_)?16	xxx
 [ 	]*[a-f0-9]+:	ea 00 00 90 90       	ljmp   \$0x9090,\$0x0	f2: (R_386_)?16	xxx
+[ 	]*[a-f0-9]+:	cf                   	iret   
+[ 	]*[a-f0-9]+:	cf                   	iret   
 #pass
diff --git a/gas/testsuite/gas/i386/jump16.s b/gas/testsuite/gas/i386/jump16.s
index f8bc0ea5b4..aff5665720 100644
--- a/gas/testsuite/gas/i386/jump16.s
+++ b/gas/testsuite/gas/i386/jump16.s
@@ -71,3 +71,9 @@
 	jmp	0x9090:0x1010
 	jmp	0x9090,xxx
 	jmp	0x9090:xxx
+
+.code16gcc
+	iret
+
+.code16
+	iret
-- 
2.20.1

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

end of thread, other threads:[~2019-05-02  7:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 17:22 [PATCH] i386: Don't add 0x66 prefix to IRET for .code16gcc H.J. Lu
2019-04-29  7:01 ` Jan Beulich
2019-04-29 15:09   ` H.J. Lu
2019-04-29 15:25     ` Jan Beulich
2019-04-29 16:03       ` H.J. Lu
2019-04-29 16:11         ` Jan Beulich
2019-04-29 17:13           ` H.J. Lu
2019-04-30  6:44             ` Jan Beulich
2019-04-30 15:49               ` H.J. Lu
2019-05-02  7:43                 ` 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).