From patchwork Wed May 19 18:30:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 442460 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1579661jac; Wed, 19 May 2021 11:31:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznqgIqaD1otMo0KNp/sBcEfStLoYTjFSL1XTYz0TCfuIM9nsh0rT8K2r5ND8A92Ya/iwV/ X-Received: by 2002:a6b:7d03:: with SMTP id c3mr963884ioq.2.1621449098124; Wed, 19 May 2021 11:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449098; cv=none; d=google.com; s=arc-20160816; b=vsemU4jaOhsUCnlQYNABRAEJesaDjmSb222EMmy15ftOB9FHcpOuZvQtaf+I3Kn1Fz /AVey+a7FsvBzYoGQZiAA8b/dDeUHeAXQH4DL8+Q+C3ogt8xE4ntCQhNRJiEm2vlZbXw qVDY4vnVciOtQ2RhVSeG8RFSpH48hiBhohk/RIUOvXL4D7v1/lfrLw0WmaKct5yJlbXU 2sUqbd+wHKDlYuGa7vyppLSjzr4YwVruw36UPRwYJIoxb6HfDG1Ac8l4ExWAhjUc477c X7F0HVvyShop4Inpq9ns35ESmXikbboFGpmR6D9vzpSLvxbB52TT8thpYh4SupIMdNjU 2DrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=0LXm7FUdAyY78wIi1+bFyfLTZfZQ4+PVm0Qu4rWwa4U=; b=jbGPr3KSMHK5qYAw7gJ6+bwzHl/iT01X9RIZ/m8NfpCpIsyeniCPBhrpK/Jkp2fDgs WNu7Y1VCvj3I/lInty1unRjpT6bjScRmNRUEBHyLz5IBRVGMKE6T3pwXCc0F3CPuKrvU tTlWT417PMZqyMkMcbVdF4KnFziiu1tUTotHywlaJy8QSRKR6fxkVlO6OOIQH3GvLhDA php0e33RimI1mG7QcxwqTnEhs1o/DZBbUCD7Ff6wwqfMsfocLHGqaKBDvMSgJjHAdnfS nJMBePPOEy8K/nCQ+HY9oMvQ4MOYYDeXyMWFuHSQq+zsS36+YncOK7zLVN0az6ALBUe7 UmCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xdAI+HU1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m3si392351ilj.111.2021.05.19.11.31.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 May 2021 11:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xdAI+HU1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljQyn-0003PS-BM for patch@linaro.org; Wed, 19 May 2021 14:31:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljQyE-0003OQ-8y for qemu-devel@nongnu.org; Wed, 19 May 2021 14:31:02 -0400 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]:34684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljQy9-0005Wm-Tm for qemu-devel@nongnu.org; Wed, 19 May 2021 14:31:02 -0400 Received: by mail-ot1-x32c.google.com with SMTP id u25-20020a0568302319b02902ac3d54c25eso12655795ote.1 for ; Wed, 19 May 2021 11:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0LXm7FUdAyY78wIi1+bFyfLTZfZQ4+PVm0Qu4rWwa4U=; b=xdAI+HU1BdrDvizhT7524k7QQvH31zYzQvBpsDJN5d50sp0sl6WxJctB1ZPYemEzSm ra/rLm1YlXg5lRM2sgNsTthGwyIsmqGrnoypDPWysTSvP1Cmk56fLZI5dVo3MoDlWVGP 143wu+oL8K1mSUwgrg4QGNgAwgZvsvQ1qxLMHblXJleVU88YDXAUz6d7EZsfSI3tGJUe F1wKkoYpsswkkhwk7J3SibNU41EenzL1Bds0pU7eBikpmtIOpmOqz5JTE+PVR0CLhWdw GocAWsCixkLVQCP9aGwsFe+ZP7eDdnPQSuwGj/RfloPv4SDmwxXUJUb5l6vAw8rcGOmQ SRCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0LXm7FUdAyY78wIi1+bFyfLTZfZQ4+PVm0Qu4rWwa4U=; b=ZXN6GXOz7wqbEZIedTFtABhKJu21eD1t66YBtp4XjeNMoYWH02dATy+aMACgHtEM9b ZhXvo3nw8dKBncBH5aEEAaAlOV6fnMo+cn8FuJHWMOmKtbPgNg+xxslZTz9icmhgiPkb /OwDt7LEBC5pUzORJK6JYkz+9n1vWsnKU/rzmYioP0DZ2N983Qta+VFeLt4PHrjCbvio LTu/Ac3uEcf3rW9voTAIKD8OitKlkqMPsxthDOEyecFfmjD18UB/5tRZ4bCqV9MdN0dS HJ2/XWOV6eddwYpkX667FEELkwp1rbUG/eWGs8sNkPmJnOBqy5pc2Acj5fN8WiHctPbU sODw== X-Gm-Message-State: AOAM5332Jh3hlPpDd2elkSTj2wMCHOcQ4RD+cKInzf2QeXXJtDHrJW3e bYXR8L0Me1cg/FJDl45ZLeqNjgmr60B+qiBq X-Received: by 2002:a9d:be2:: with SMTP id 89mr630942oth.269.1621449056818; Wed, 19 May 2021 11:30:56 -0700 (PDT) Received: from localhost.localdomain ([45.235.253.15]) by smtp.gmail.com with ESMTPSA id l9sm28428oou.43.2021.05.19.11.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 11:30:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/50] target/i386: Split out check_vm86_iopl Date: Wed, 19 May 2021 13:30:04 -0500 Message-Id: <20210519183050.875453-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210519183050.875453-1-richard.henderson@linaro.org> References: <20210519183050.875453-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson Reviewed-by: Paolo Bonzini Message-Id: <20210514151342.384376-5-richard.henderson@linaro.org> --- target/i386/tcg/translate.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) -- 2.25.1 diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 0a15662949..74f6024f82 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1292,6 +1292,16 @@ static bool check_cpl0(DisasContext *s) return false; } +/* If vm86, check for iopl == 3; if not, raise #GP and return false. */ +static bool check_vm86_iopl(DisasContext *s) +{ + if (!s->vm86 || s->iopl == 3) { + return true; + } + gen_exception_gpf(s); + return false; +} + /* if d == OR_TMP0, it means memory operand (address in A0) */ static void gen_op(DisasContext *s1, int op, MemOp ot, int d) { @@ -6579,8 +6589,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_svm_check_intercept(s, pc_start, SVM_EXIT_IRET); if (!s->pe || s->vm86) { /* real mode or vm86 mode */ - if (s->vm86 && s->iopl != 3) { - gen_exception_gpf(s); + if (!check_vm86_iopl(s)) { break; } gen_helper_iret_real(cpu_env, tcg_const_i32(dflag - 1)); @@ -6700,9 +6709,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) /* flags */ case 0x9c: /* pushf */ gen_svm_check_intercept(s, pc_start, SVM_EXIT_PUSHF); - if (s->vm86 && s->iopl != 3) { - gen_exception_gpf(s); - } else { + if (check_vm86_iopl(s)) { gen_update_cc_op(s); gen_helper_read_eflags(s->T0, cpu_env); gen_push_v(s, s->T0); @@ -6710,9 +6717,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0x9d: /* popf */ gen_svm_check_intercept(s, pc_start, SVM_EXIT_POPF); - if (s->vm86 && s->iopl != 3) { - gen_exception_gpf(s); - } else { + if (check_vm86_iopl(s)) { ot = gen_pop_T0(s); if (s->cpl == 0) { if (dflag != MO_16) { @@ -7072,9 +7077,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0xcd: /* int N */ val = x86_ldub_code(env, s); - if (s->vm86 && s->iopl != 3) { - gen_exception_gpf(s); - } else { + if (check_vm86_iopl(s)) { gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base); } break;