From patchwork Wed Nov 9 20:21:29 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: 17804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp542953wru; Wed, 9 Nov 2022 12:21:44 -0800 (PST) X-Google-Smtp-Source: AMsMyM4e/eCDVDBeTVP+eADkuXbtj5rC/06kK2M79LzaEV0i/qMyZ5xj8WWbC9O37g+MDjBx1PFk X-Received: by 2002:a17:907:2c72:b0:7a5:47da:5893 with SMTP id ib18-20020a1709072c7200b007a547da5893mr57402930ejc.612.1668025304744; Wed, 09 Nov 2022 12:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668025304; cv=none; d=google.com; s=arc-20160816; b=Vz0ewA/A9zmMpgeLJCFEkdj4hs00/FzyGJUydElISHbJgTmAjY+gRqJnQzKImCu41q 3T/tL5rc1M5pFpdnJZtskwAAm2/e818vK3u97+q76P2mnbR03sEjTBxWR74A0aJVL/Em T4zS1Zs6RWGIjdAiFpacZUsYhk27C8xgT2SrBn90M1lMCyFE55xnu2nN6B+o7ERK44TJ prhrIRdakqVJn71Jh6uvEkuJ666l5vbPFlfOWeNoYShNkuFtD/FVBHTdwslvhGTW/J/y MOaqq5fTBYJSmHffE9C4aQsUi6HXfDCh2B+i41MWGlWS36tnGUaqbCmuQwATTOsh4uCS AMeA== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=6rikpEr2dTidSpT0j8O4L1E6h40Tt5AI5e63GtE2YQI=; b=QqZRkMsq6N0Q4s7jwyFaPnUzC/2JQLlo5GTLqoNfjev5PoJIBi2w5URKqJRP5nIBB8 W5Venh2ZJXZfDe3FJrv8yk3vHdPP59p/1pvEL/7m20HmObe/u5MNLPRvKmkR7f66wOHk dbN9BP2VNfyWFjHMXu61tZI3xdOi82izYgec+rTnMipYsF6E/zdKrToKjQDV9rZvo7dy Uu85VtgArAk3bfjUNz1qxmW5zGJkXwyDFXy7Oq2A7f+T6h3H1rySHjbm3kKL7j+jgKRj wxXzAcXn1PkSP60P5oB2Q2Es4r4PZY3Iow4C7MVSWu78jG2A0pknLDQAHU/gyLMxeRfj OS9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=N+0Rl5Rg; 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 og37-20020a1709071de500b0078bec673145si13179243ejc.519.2022.11.09.12.21.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:21:44 -0800 (PST) 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=N+0Rl5Rg; 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 893EA3858C27 for ; Wed, 9 Nov 2022 20:21:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 893EA3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668025303; bh=6rikpEr2dTidSpT0j8O4L1E6h40Tt5AI5e63GtE2YQI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=N+0Rl5RgOme9+1LSzZHwiLNqUl6LeqPMtnwCP+/kGsAazDzdiKKqCSrCnbr4u6OiH pLJ3I++a62bFqHRQYBzyznwiGW0f4zPfs68waoNafRovBGZD98ehRVW3wqf69O/5y1 J7i+4N6aAWM8oks0VY3ai+SGeUTh9UF47h5mdYkY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id E6C273858D28 for ; Wed, 9 Nov 2022 20:21:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6C273858D28 Received: by mail-pl1-x62f.google.com with SMTP id j12so18146527plj.5 for ; Wed, 09 Nov 2022 12:21:33 -0800 (PST) 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:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6rikpEr2dTidSpT0j8O4L1E6h40Tt5AI5e63GtE2YQI=; b=KMIsLvKKIQd9n6eolUNjQAsld/rBvK9JFpUF37Ex8RwtVfGDyy+anNW0e2dZpjE+Yl H90yNM+VxK1bBXCqz++JI8+60aIVdFYikzdqrJXrOanRG0lVkVCr2XauDj8K7DcF+OcA L+KrRKXYdhvuWh8kGy2rq03yukjwQIJdpvCs7WyC9j6N+4EzsjoVL4RlbArxIqs5dzmc DuvY8hdUXi9vgFjP+ynLPhH3Vl6QKWjaNnvbfkcWW1/4Gqtp6/vAMK2MnW8Gw9JUOFSC bmu/pYCFGgpdHCQg0hBgnGa//CdYoa61odyMOQz+NNpDYoC8q47TpEC2qHkS5cOd2xe7 zTiQ== X-Gm-Message-State: ACrzQf08mRq1kt21zEZaSI8wdwqahos9DHQ/8Bn9wwo89G2R1JBq1Lek x6SJPewx7hITzCUh9fFa1ypTwbBtSYs= X-Received: by 2002:a17:90b:1948:b0:214:1ae7:a511 with SMTP id nk8-20020a17090b194800b002141ae7a511mr44847988pjb.89.1668025292082; Wed, 09 Nov 2022 12:21:32 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.56.31.252]) by smtp.gmail.com with ESMTPSA id t3-20020a170902b20300b00186a8beec78sm9514869plr.52.2022.11.09.12.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:21:31 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 334A5C044E; Wed, 9 Nov 2022 12:21:29 -0800 (PST) To: binutils@sourceware.org Cc: Jan Beulich Subject: [PATCH v2] i386: Check invalid (%dx) usage Date: Wed, 9 Nov 2022 12:21:29 -0800 Message-Id: <20221109202129.475283-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3026.2 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?1749051301853178338?= X-GMAIL-MSGID: =?utf-8?q?1749051301853178338?= (%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 | 16 ++++++++++++++++ gas/testsuite/gas/i386/inval.l | 9 +++++++++ gas/testsuite/gas/i386/inval.s | 5 +++++ gas/testsuite/gas/i386/x86-64-inval.l | 9 +++++++++ gas/testsuite/gas/i386/x86-64-inval.s | 5 +++++ 5 files changed, 44 insertions(+) diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index da005c5d61d..142b937423e 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 { @@ -5045,6 +5049,17 @@ 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 + || i.tm.opcode_modifier.opcodespace != SPACE_BASE)) + { + 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 (); @@ -11752,6 +11767,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 5d520f0e8e7..f66142ab171 100644 --- a/gas/testsuite/gas/i386/inval.l +++ b/gas/testsuite/gas/i386/inval.l @@ -99,6 +99,10 @@ .*:115: Error: .* .*:116: Error: .* .*:117: Error: .* +.*:119: Error: .* +.*:120: Error: .* +.*:121: Error: .* +.*:122: Error: .* [ ]*1[ ]+\.text [ ]*2[ ]+\.allow_index_reg [ ]*3[ ]+\# All the following should be illegal @@ -216,4 +220,9 @@ [ ]*[1-9][0-9]*[ ]+inb %dx, %ax [ ]*[1-9][0-9]*[ ]+outb %ax, %dx [ ]*[1-9][0-9]*[ ]+movb %ax, %bx +[ ]*[1-9][0-9]*[ ]+ +[ ]*[1-9][0-9]*[ ]+incl \(%dx\) +[ ]*[1-9][0-9]*[ ]+incw \(%dx\) +[ ]*[1-9][0-9]*[ ]+mov \(%dx\), %ax +[ ]*[1-9][0-9]*[ ]+mov %ax, \(%dx\) #pass diff --git a/gas/testsuite/gas/i386/inval.s b/gas/testsuite/gas/i386/inval.s index 4e9f751c61f..4e9a90de904 100644 --- a/gas/testsuite/gas/i386/inval.s +++ b/gas/testsuite/gas/i386/inval.s @@ -115,3 +115,8 @@ movnti word ptr [eax], ax inb %dx, %ax outb %ax, %dx movb %ax, %bx + + incl (%dx) + incw (%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..14b267421c4 100644 --- a/gas/testsuite/gas/i386/x86-64-inval.l +++ b/gas/testsuite/gas/i386/x86-64-inval.l @@ -111,6 +111,10 @@ .*:117: Error: .* .*:118: Error: .* .*:121: Error: .* +.*:123: Error: .* +.*:124: Error: .* +.*:125: Error: .* +.*:126: Error: .* GAS LISTING .* @@ -241,3 +245,8 @@ 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]*[ ]+incw \(%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..7705ef1cccb 100644 --- a/gas/testsuite/gas/i386/x86-64-inval.s +++ b/gas/testsuite/gas/i386/x86-64-inval.s @@ -119,3 +119,8 @@ movnti word ptr [rax], ax .att_syntax prefix movsd (%rsi), %ss:(%rdi), %ss:(%rax) + + incl (%dx) + incw (%dx) + mov (%dx), %ax + mov %ax, (%dx)