From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH] i386: Check invalid (%dx) usage
Date: Fri, 4 Nov 2022 13:55:47 -0700 [thread overview]
Message-ID: <20221104205547.3728827-1-hjl.tools@gmail.com> (raw)
(%dx) isn't a valid memory address in any modes. It is used as a special
memory operand for input/output port address in AT&T syntax and should
only be used with input/output instructions. Update i386_att_operand to
set i.input_output_operand to true for (%dx) and issue an error if (%dx)
is used with non-input/output instructions.
PR gas/29751
* config/tc-i386.c (_i386_insn): Add input_output_operand.
(md_assemble): Issue an error if input/output memory operand is
used with non-input/output instructions.
(i386_att_operand): Set i.input_output_operand to true for
(%dx).
* testsuite/gas/i386/inval.l: Updated.
* testsuite/gas/i386/x86-64-inval.l: Likewise.
* testsuite/gas/i386/inval.s: Add tests for invalid (%dx) usage.
* testsuite/gas/i386/x86-64-inval.s: Likewise.
---
gas/config/tc-i386.c | 14 ++++++++++++++
gas/testsuite/gas/i386/inval.l | 7 +++++++
gas/testsuite/gas/i386/inval.s | 4 ++++
gas/testsuite/gas/i386/x86-64-inval.l | 7 +++++++
gas/testsuite/gas/i386/x86-64-inval.s | 4 ++++
5 files changed, 36 insertions(+)
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index a846b9e8653..42c12bb3d55 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -311,6 +311,10 @@ struct _i386_insn
/* The operand to a branch insn indicates an absolute branch. */
bool jumpabsolute;
+ /* There is a memory operand of (%dx) which should be only used
+ with input/output instructions. */
+ bool input_output_operand;
+
/* Extended states. */
enum
{
@@ -5043,6 +5047,15 @@ md_assemble (char *line)
i.disp_operands = 0;
}
+ /* The memory operand of (%dx) should be only used with input/output
+ instructions (base opcodes: 0x6c, 0x6e, 0xec, 0xee). */
+ if (i.input_output_operand && (i.tm.base_opcode | 0x82) != 0xee)
+ {
+ as_bad (_("input/output port address isn't allowed with `%s'"),
+ i.tm.name);
+ return;
+ }
+
if (optimize && !i.no_optimize && i.tm.opcode_modifier.optimize)
optimize_encoding ();
@@ -11750,6 +11763,7 @@ i386_att_operand (char *operand_string)
&& !operand_type_check (i.types[this_operand], disp))
{
i.types[this_operand] = i.base_reg->reg_type;
+ i.input_output_operand = true;
return 1;
}
diff --git a/gas/testsuite/gas/i386/inval.l b/gas/testsuite/gas/i386/inval.l
index abe220620b7..bd1017c7bee 100644
--- a/gas/testsuite/gas/i386/inval.l
+++ b/gas/testsuite/gas/i386/inval.l
@@ -97,6 +97,9 @@
.*:112: Error: .*
.*:113: Error: .*
.*:114: Error: .*
+.*:116: Error: .*
+.*:117: Error: .*
+.*:118: Error: .*
GAS LISTING .*
@@ -220,3 +223,7 @@ GAS LISTING .*
\fGAS LISTING .*
+[ ]*[1-9][0-9]*[ ]+
+[ ]*[1-9][0-9]*[ ]+incl \(%dx\)
+[ ]*[1-9][0-9]*[ ]+mov \(%dx\), %ax
+[ ]*[1-9][0-9]*[ ]+mov %ax, \(%dx\)
diff --git a/gas/testsuite/gas/i386/inval.s b/gas/testsuite/gas/i386/inval.s
index 7adfec64600..7e9a778f74f 100644
--- a/gas/testsuite/gas/i386/inval.s
+++ b/gas/testsuite/gas/i386/inval.s
@@ -112,3 +112,7 @@ movnti word ptr [eax], ax
inb %dx, %ax
outb %ax, %dx
movb %ax, %bx
+
+ incl (%dx)
+ mov (%dx), %ax
+ mov %ax, (%dx)
diff --git a/gas/testsuite/gas/i386/x86-64-inval.l b/gas/testsuite/gas/i386/x86-64-inval.l
index bbb8ba295cb..688bcd90894 100644
--- a/gas/testsuite/gas/i386/x86-64-inval.l
+++ b/gas/testsuite/gas/i386/x86-64-inval.l
@@ -111,6 +111,9 @@
.*:117: Error: .*
.*:118: Error: .*
.*:121: Error: .*
+.*:123: Error: .*
+.*:124: Error: .*
+.*:125: Error: .*
GAS LISTING .*
@@ -241,3 +244,7 @@ GAS LISTING .*
[ ]*[1-9][0-9]*[ ]+
[ ]*[1-9][0-9]*[ ]+\.att_syntax prefix
[ ]*[1-9][0-9]*[ ]+movsd \(%rsi\), %ss:\(%rdi\), %ss:\(%rax\)
+[ ]*[1-9][0-9]*[ ]+
+[ ]*[1-9][0-9]*[ ]+incl \(%dx\)
+[ ]*[1-9][0-9]*[ ]+mov \(%dx\), %ax
+[ ]*[1-9][0-9]*[ ]+mov %ax, \(%dx\)
diff --git a/gas/testsuite/gas/i386/x86-64-inval.s b/gas/testsuite/gas/i386/x86-64-inval.s
index 85c3582d4b2..16622a41c95 100644
--- a/gas/testsuite/gas/i386/x86-64-inval.s
+++ b/gas/testsuite/gas/i386/x86-64-inval.s
@@ -119,3 +119,7 @@ movnti word ptr [rax], ax
.att_syntax prefix
movsd (%rsi), %ss:(%rdi), %ss:(%rax)
+
+ incl (%dx)
+ mov (%dx), %ax
+ mov %ax, (%dx)
--
2.37.3
next reply other threads:[~2022-11-04 20:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 20:55 H.J. Lu [this message]
2022-11-07 9:55 ` Jan Beulich
2022-11-07 11:44 ` Jan Beulich
2022-11-07 19:58 ` H.J. Lu
2022-11-08 7:34 ` Jan Beulich
2022-11-08 21:06 ` H.J. Lu
2022-11-09 7:21 ` Jan Beulich
2022-11-09 20:24 ` H.J. Lu
2022-11-10 7:21 ` Jan Beulich
2022-11-10 17:22 ` H.J. Lu
2022-11-11 7:55 ` 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=20221104205547.3728827-1-hjl.tools@gmail.com \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
/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).