From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id D1674385841A for ; Fri, 4 Nov 2022 20:55:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D1674385841A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x531.google.com with SMTP id b5so5367340pgb.6 for ; Fri, 04 Nov 2022 13:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=f8oxaTX81SdRBjA1PZWEwS3fxLZ1BZxizL2cM82jCRA=; b=MtA30nFhtPsgZ9cIS0M7ymzEQVW84keAP3wfW8DV9Mo42XOhT1vnrxGGCbawZvnL+9 bUZaHHrdNQ3boM5jiFDSl6mDJ5vH72W7rVn1/MERBiWOGBPZ7zppPKJRLc9JGdIsNn78 kb+/TcSIIWxxbMnin+qOF5ffZoAF9Rh4IvLllYJ7RKrzLHobvfdw+cVACi2IQ48r0TG6 AJpQVMdfnYdcw0cHKm7PBLh032ziXjWF/2KlBApFMG/Xkh9Y76zYoTqPs79fB4ihX1s3 7stEknPTTpYX4KgMU10USHaxHBE5gj0L08KeBOE+NSXALG2MR1xyMJt14AhIo7/esjv5 obdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f8oxaTX81SdRBjA1PZWEwS3fxLZ1BZxizL2cM82jCRA=; b=rrkQBj6wN6vwTEJA1rBdoy21IvMWo3+TiqzILxAys0hhuVuo4DxKAO9P3gXnoTrJEG v6JsnJakJ2wWRx2i2lmU/JOcvHd7hiD2jUthbCvT6M8z4vW5TaZA+K0HPfJgU49kmUFZ O94vHes/BYqZrPX0uRfYVXKzVVWioCO9L1bbbGGQAq6yEHtQOCql5GyxZhgVy8NNZc/W r7/2KeV8ztEJju5ZF2STPn5VdsPILVp73ANB64EVCab+llvwMB5D3wrH7VxbamxsPsCR KLNtX6ftcRthQOWQuOWXNLeP2PlV70ufoNEFJTeAiQtZMD9BSkyG6gzgwhOLq8hDYups Zt+w== X-Gm-Message-State: ACrzQf1N1hOjwpaimEPuPQ/aN4QA/QR9yrlLf146Sg0SIy+f+xeL40iA 1PGV1BQvtLQWP1fFnR43Rb3BeHrs1ww= X-Google-Smtp-Source: AMsMyM7CqWSyKpcSMdEwhG4ZsWNRp0R3I+EkNxbHKRUSutqN6fqkfIRiHxiFBH0zS+vEgyqpsR+VHA== X-Received: by 2002:a63:5a44:0:b0:458:6031:ba1 with SMTP id k4-20020a635a44000000b0045860310ba1mr387435pgm.524.1667595349288; Fri, 04 Nov 2022 13:55:49 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.56.31.252]) by smtp.gmail.com with ESMTPSA id b5-20020a170902650500b00180cf894b67sm181577plk.130.2022.11.04.13.55.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 13:55:48 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 5A5E9C02B3 for ; Fri, 4 Nov 2022 13:55:47 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] i386: Check invalid (%dx) usage Date: Fri, 4 Nov 2022 13:55:47 -0700 Message-Id: <20221104205547.3728827-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3026.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: (%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 .* GAS 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