From patchwork Fri Nov 4 20:55:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 15792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp633222wru; Fri, 4 Nov 2022 13:56:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7q0mBwOPLG2uL1LITBGPok8v7OBGvJQDH60qZgTEo38HnJVxR5iriP/tUnDZHvPcY38XNb X-Received: by 2002:a17:907:75f7:b0:7ad:bc7e:3fb6 with SMTP id jz23-20020a17090775f700b007adbc7e3fb6mr31943486ejc.550.1667595361909; Fri, 04 Nov 2022 13:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667595361; cv=none; d=google.com; s=arc-20160816; b=NQYRl+XSUDQmS/Vq4u+URPSO5Q83o+7dSK3+NJKFTKxdjocoBswvSe6CPAlWp8oM01 mCSCV5A39L5lJ1mPwIezwVLQY1O6tYoc81gcnpXtv56GaDEXANKxaMhvsu+A7Oe9lZNK UwjMyV2buOX+J9bjT4Sm/cA85jKKS2urG1gJY43oi20xok5ldIjeof6TtRVHtYQHKjZc riRJoT+fWr5DeVEm0L4TgPlZlZKDZ5gPFna5QP5Rl+g2ywMN92RqNoGzRwGLqyM17PVv txi7H0KPcgTGB2jNzVypws6EG7UAmrV/qSRQ0XVC/e98cGSH2HWY0rlA8yc9MXElT4OK Xrpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=f8oxaTX81SdRBjA1PZWEwS3fxLZ1BZxizL2cM82jCRA=; b=ARCl+GzVzXB/MHSTUiNI+m0sp4frvmj1dbq6fRcqWIsOE9R5ymrL8FWxbL3qzRKQDC 4vvYN8DJUZavtHlYhpWdDzQYNmE7+YnIFzbDAALb7jmQlIAH2lYhUcoX4Sp4xIXp/5nD QHZBorSe/KfOZXS/1vIiSi+KPKL95rIbl/XAVq2l39wxZeweVg/Mf2i6Yufq711+hvTN idm4lR/3VRO32gMH4WNiaNAtMRohrV7dzhoXtzUNxvlubH92prHyxAylR0g7kpXqOhPW oSIESbVHDSPszTb+L3h5rcrRBJkpRr4JXnHsCX3ilzjya9QdmQ8NX6MDM/MI3nqQMlPG qn2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=D1puhOJ5; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ca2-20020a170906a3c200b0078d3b940ec5si50746ejb.373.2022.11.04.13.56.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 13:56:01 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=D1puhOJ5; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F6D6385842C for ; Fri, 4 Nov 2022 20:56:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F6D6385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667595360; bh=f8oxaTX81SdRBjA1PZWEwS3fxLZ1BZxizL2cM82jCRA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=D1puhOJ5Ajs6yUqtI9qD17w08zQw3MiDzoq/HV1YHzZDDHa0NYkPfFVVvq3WhVElz jmUBFJ8j6GCZVUfgqMWMi1pLlwybdXmowrZ8Qs+W8wDIww8CboygkSH4e6MHgqsE3p kW1M+8dcrAvysPT9U9lzqBqZSQua32Q5itJ/UcVY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-pg1-x531.google.com with SMTP id b5so5367340pgb.6 for ; Fri, 04 Nov 2022 13:55:50 -0700 (PDT) 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-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) 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748600474330400362?= X-GMAIL-MSGID: =?utf-8?q?1748600474330400362?= (%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)