From patchwork Fri Apr 20 15:50:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 133900 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp439269ljf; Fri, 20 Apr 2018 08:53:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx48M+u5mAy0j2gIUB/226QGSN/GeZVY9QvNeqTurVR9Tocfb1bD1+X2C1J5TX8WpXTAxR7PO X-Received: by 2002:a81:a1d2:: with SMTP id y201-v6mr4251847ywg.330.1524239632567; Fri, 20 Apr 2018 08:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524239632; cv=none; d=google.com; s=arc-20160816; b=G+xWDCCBuT29WYcMKa7y/CUjwMPChJIGiFceJdydfazTDGnRc0YgdNexIKSLKrut9Y +nHRxsVhEWcXHB2mCxDHSCylE9uhr0HXtUvytkTvbki60bmyCCk66/4jaKsqYspV2ma6 G39RSC1yo5uOFwC3FSY96hP2egy6PydWX/9BucqoEW7VqvkDSR+0VcFj2kVGCWAvdkL1 CJLxKDYjqXF2e3mxUk5rv1LpK316vhTOgVTUQwjOF5Vd8Z4bgB+RUBgR3dWc/mDhwRwi KqDpmILIPk+Vt0dfVk4tOCYf3/srJDGueF685aMUU0Nx+vIxTdeWT1sVwx4dmgL/CNdh 337A== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=uaMjiWujckEaCec6HwgcVvqvj2iyAdax4PlRwxIMGc4=; b=fkYj1cuBv/LYOrbWnbHKglPEzqLzEYLTTh36t64OMHFQX/NlkcG3BA9rNnQHzwIGeN O0q6jRc1GBavTGfMCwKAleB6Q0ilFer9kkKL7P4ExUjYQ/DG8JRP1+cLyd4XU2iOhXFS 0dgShoqTIwGNBzUUISdKgBbfZcsEeYRRsrGUJjl6tmZ2eEmeizDQNUg9h1i4I1tbB0xc RRTxcIOHYa1/QrWgZi0aye8mebPy6tMQvt49EDvdFZiT6gZjwZdvg5qpfhX15LNEfVhk 9cnbEKyCNY3UQ6f1d6u4S4mSvp3W9sckicg9C0Z/XWBnhenc9KHVDQN/rjeb/WmA+tGV 2x4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cJrtiz9D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p73si2809580uap.259.2018.04.20.08.53.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Apr 2018 08:53:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cJrtiz9D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9YMB-0007Cg-WE for patch@linaro.org; Fri, 20 Apr 2018 11:53:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9YJI-0005vf-UF for qemu-devel@nongnu.org; Fri, 20 Apr 2018 11:50:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9YJH-0005rh-FP for qemu-devel@nongnu.org; Fri, 20 Apr 2018 11:50:52 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:37853) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f9YJH-0005qb-4a for qemu-devel@nongnu.org; Fri, 20 Apr 2018 11:50:51 -0400 Received: by mail-wr0-x242.google.com with SMTP id f14-v6so24222277wre.4 for ; Fri, 20 Apr 2018 08:50:50 -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=uaMjiWujckEaCec6HwgcVvqvj2iyAdax4PlRwxIMGc4=; b=cJrtiz9Dip6YfmWuTRoKhbs1gPxt77XC41NKOdNFW0KkB3GnskWub7PQcmUTdg4N28 gCRguwMPhDVl2LpTWZE+XA01LEtdR+DeS5+du8GhIAZGk5A7P80HW+xgC7s/u74S2fy3 XM9vxP7pwMfnYDvcBtgHEpemTdzZe3LgaamMs= 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=uaMjiWujckEaCec6HwgcVvqvj2iyAdax4PlRwxIMGc4=; b=qNHoTSEVpN56YOy5R9Dz3gs6w54ou3veXXAqrDER4VuKsQwZL/xEwNq1DAh3OOoJNl sGNJ2Osj50hmnkjjoIQixa8MvBnu0ep0d/Do+mnP5eu9Qkn4XJjMD3udCBMqsDbaWRuX wie1F1G8eOhy7qcIRAV8rrdSCNIzfP42mNXlN5zi3QuCvuG/+e2K9NB2FICahk5llWkO FN68SIN19+511ZAS5Q0Bmr8Joho5ZcK0ajiV159GMt8R3qlmyv3d6tgkg2aCNtSYf/ok 3ivE4YSq+vUKlNQCoUgsb2CZ3OwSeJpzDTtkUl5KTvh+XZ1sxPNnmJarLbHXKnZ0Ijgc +L0w== X-Gm-Message-State: ALQs6tAvRzd70EWVOLMnsmbA484LutW6TFJDvhneFUwPY5pKtMq6u+AE yDd2qonWv3zAwsTXJWjLhp1OMw== X-Received: by 10.28.13.205 with SMTP id 196mr2421837wmn.73.1524239449827; Fri, 20 Apr 2018 08:50:49 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o17-v6sm10079693wrc.71.2018.04.20.08.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Apr 2018 08:50:46 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4F4E83E0342; Fri, 20 Apr 2018 16:50:45 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 20 Apr 2018 16:50:41 +0100 Message-Id: <20180420155045.18862-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180420155045.18862-1-alex.bennee@linaro.org> References: <20180420155045.18862-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [RFC PATCH 2/6] accel/tcg: new softmmu.c with DATA_SIZE=1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Peter Crosthwaite , richard.henderson@linaro.org, pbonzini@redhat.com, =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Expand the results of softmmu-template.h with DATA_SIZE 1. Currently there are no changes and areas will get dead-coded away. This is going to form the basis of the re-factoring. Signed-off-by: Alex Bennée --- accel/tcg/Makefile.objs | 1 + accel/tcg/cputlb.c | 6 - accel/tcg/softmmu.c | 255 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 6 deletions(-) create mode 100644 accel/tcg/softmmu.c -- 2.17.0 diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index d381a02f34..6b0b96633d 100644 --- a/accel/tcg/Makefile.objs +++ b/accel/tcg/Makefile.objs @@ -1,5 +1,6 @@ obj-$(CONFIG_SOFTMMU) += tcg-all.o obj-$(CONFIG_SOFTMMU) += cputlb.o +obj-$(CONFIG_SOFTMMU) += softmmu.o obj-y += tcg-runtime.o tcg-runtime-gvec.o obj-y += cpu-exec.o cpu-exec-common.o translate-all.o obj-y += translator.o diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 43a89d3010..7104bacc0f 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1032,9 +1032,6 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, #define MMUSUFFIX _mmu -#define DATA_SIZE 1 -#include "softmmu_template.h" - #define DATA_SIZE 2 #include "softmmu_template.h" @@ -1109,9 +1106,6 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, #define GETPC() ((uintptr_t)0) #define SOFTMMU_CODE_ACCESS -#define DATA_SIZE 1 -#include "softmmu_template.h" - #define DATA_SIZE 2 #include "softmmu_template.h" diff --git a/accel/tcg/softmmu.c b/accel/tcg/softmmu.c new file mode 100644 index 0000000000..f09aff453a --- /dev/null +++ b/accel/tcg/softmmu.c @@ -0,0 +1,255 @@ +/* + * Software MMU support + * + * Originally this was a set of generated helpers using macro magic. + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "cputlb.h" +#include "exec/exec-all.h" +#include "tcg/tcg.h" + +/* Macro to call the above, with local variables from the use context. */ +#define VICTIM_TLB_HIT(TY, ADDR) \ + victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ + (ADDR) & TARGET_PAGE_MASK) + +/* For the benefit of TCG generated code, we want to avoid the complication + of ABI-specific return type promotion and always return a value extended + to the register size of the host. This is tcg_target_long, except in the + case of a 32-bit host and 64-bit data, and for that we always have + uint64_t. Don't bother with this widened value for SOFTMMU_CODE_ACCESS. */ +static inline uint8_t io_readb(CPUArchState *env, + size_t mmu_idx, size_t index, + target_ulong addr, + uintptr_t retaddr) +{ + CPUIOTLBEntry *iotlbentry = &env->iotlb[mmu_idx][index]; + return io_readx(env, iotlbentry, mmu_idx, addr, retaddr, 1); +} + + +tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr, + TCGMemOpIdx oi, uintptr_t retaddr) +{ + unsigned mmu_idx = get_mmuidx(oi); + int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_read; + unsigned a_bits = get_alignment_bits(get_memop(oi)); + uintptr_t haddr; + uint8_t res; + + if (addr & ((1 << a_bits) - 1)) { + cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_LOAD, + mmu_idx, retaddr); + } + + /* If the TLB entry is for a different page, reload and try again. */ + if ((addr & TARGET_PAGE_MASK) + != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { + if (!VICTIM_TLB_HIT(addr_read, addr)) { + tlb_fill(ENV_GET_CPU(env), addr, 1, MMU_DATA_LOAD, + mmu_idx, retaddr); + } + tlb_addr = env->tlb_table[mmu_idx][index].addr_read; + } + + /* Handle an IO access. */ + if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { + if ((addr & (1 - 1)) != 0) { + goto do_unaligned_access; + } + + /* ??? Note that the io helpers always read data in the target + byte ordering. We should push the LE/BE request down into io. */ + res = io_readb(env, mmu_idx, index, addr, retaddr); + res = (res); + return res; + } + + /* Handle slow unaligned access (it spans two pages or IO). */ + if (1 > 1 + && unlikely((addr & ~TARGET_PAGE_MASK) + 1 - 1 + >= TARGET_PAGE_SIZE)) { + target_ulong addr1, addr2; + uint8_t res1, res2; + unsigned shift; + do_unaligned_access: + addr1 = addr & ~(1 - 1); + addr2 = addr1 + 1; + res1 = helper_ret_ldub_mmu(env, addr1, oi, retaddr); + res2 = helper_ret_ldub_mmu(env, addr2, oi, retaddr); + shift = (addr & (1 - 1)) * 8; + + /* Little-endian combine. */ + res = (res1 >> shift) | (res2 << ((1 * 8) - shift)); + return res; + } + + haddr = addr + env->tlb_table[mmu_idx][index].addend; + + res = ldub_p((uint8_t *)haddr); + + + + return res; +} +/* Provide signed versions of the load routines as well. We can of course + avoid this for 64-bit data, or for 32-bit data on 32-bit host. */ +static inline void io_writeb(CPUArchState *env, + size_t mmu_idx, size_t index, + uint8_t val, + target_ulong addr, + uintptr_t retaddr) +{ + CPUIOTLBEntry *iotlbentry = &env->iotlb[mmu_idx][index]; + return io_writex(env, iotlbentry, mmu_idx, val, addr, retaddr, 1); +} + +void helper_ret_stb_mmu(CPUArchState *env, target_ulong addr, uint8_t val, + TCGMemOpIdx oi, uintptr_t retaddr) +{ + unsigned mmu_idx = get_mmuidx(oi); + int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write; + unsigned a_bits = get_alignment_bits(get_memop(oi)); + uintptr_t haddr; + + if (addr & ((1 << a_bits) - 1)) { + cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, + mmu_idx, retaddr); + } + + /* If the TLB entry is for a different page, reload and try again. */ + if ((addr & TARGET_PAGE_MASK) + != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { + if (!VICTIM_TLB_HIT(addr_write, addr)) { + tlb_fill(ENV_GET_CPU(env), addr, 1, MMU_DATA_STORE, + mmu_idx, retaddr); + } + tlb_addr = env->tlb_table[mmu_idx][index].addr_write & ~TLB_INVALID_MASK; + } + + /* Handle an IO access. */ + if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { + if ((addr & (1 - 1)) != 0) { + goto do_unaligned_access; + } + + /* ??? Note that the io helpers always read data in the target + byte ordering. We should push the LE/BE request down into io. */ + val = (val); + io_writeb(env, mmu_idx, index, val, addr, retaddr); + return; + } + + /* Handle slow unaligned access (it spans two pages or IO). */ + if (1 > 1 + && unlikely((addr & ~TARGET_PAGE_MASK) + 1 - 1 + >= TARGET_PAGE_SIZE)) { + int i, index2; + target_ulong page2, tlb_addr2; + do_unaligned_access: + /* Ensure the second page is in the TLB. Note that the first page + is already guaranteed to be filled, and that the second page + cannot evict the first. */ + page2 = (addr + 1) & TARGET_PAGE_MASK; + index2 = (page2 >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + tlb_addr2 = env->tlb_table[mmu_idx][index2].addr_write; + if (page2 != (tlb_addr2 & (TARGET_PAGE_MASK | TLB_INVALID_MASK)) + && !VICTIM_TLB_HIT(addr_write, page2)) { + tlb_fill(ENV_GET_CPU(env), page2, 1, MMU_DATA_STORE, + mmu_idx, retaddr); + } + + /* XXX: not efficient, but simple. */ + /* This loop must go in the forward direction to avoid issues + with self-modifying code in Windows 64-bit. */ + for (i = 0; i < 1; ++i) { + /* Little-endian extract. */ + uint8_t val8 = val >> (i * 8); + helper_ret_stb_mmu(env, addr + i, val8, + oi, retaddr); + } + return; + } + + haddr = addr + env->tlb_table[mmu_idx][index].addend; + + stb_p((uint8_t *)haddr, val); + + + +} + +/* For the benefit of TCG generated code, we want to avoid the complication + of ABI-specific return type promotion and always return a value extended + to the register size of the host. This is tcg_target_long, except in the + case of a 32-bit host and 64-bit data, and for that we always have + uint64_t. Don't bother with this widened value for SOFTMMU_CODE_ACCESS. */ +uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr, + TCGMemOpIdx oi, uintptr_t retaddr) +{ + unsigned mmu_idx = get_mmuidx(oi); + int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_code; + unsigned a_bits = get_alignment_bits(get_memop(oi)); + uintptr_t haddr; + uint8_t res; + + if (addr & ((1 << a_bits) - 1)) { + cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_INST_FETCH, + mmu_idx, retaddr); + } + + /* If the TLB entry is for a different page, reload and try again. */ + if ((addr & TARGET_PAGE_MASK) + != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { + if (!VICTIM_TLB_HIT(addr_code, addr)) { + tlb_fill(ENV_GET_CPU(env), addr, 1, MMU_INST_FETCH, + mmu_idx, retaddr); + } + tlb_addr = env->tlb_table[mmu_idx][index].addr_code; + } + + /* Handle an IO access. */ + if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { + if ((addr & (1 - 1)) != 0) { + goto do_unaligned_access; + } + + /* ??? Note that the io helpers always read data in the target + byte ordering. We should push the LE/BE request down into io. */ + res = io_readb(env, mmu_idx, index, addr, retaddr); + res = (res); + return res; + } + + /* Handle slow unaligned access (it spans two pages or IO). */ + if (1 > 1 + && unlikely((addr & ~TARGET_PAGE_MASK) + 1 - 1 + >= TARGET_PAGE_SIZE)) { + target_ulong addr1, addr2; + uint8_t res1, res2; + unsigned shift; + do_unaligned_access: + addr1 = addr & ~(1 - 1); + addr2 = addr1 + 1; + res1 = helper_ret_ldb_cmmu(env, addr1, oi, retaddr); + res2 = helper_ret_ldb_cmmu(env, addr2, oi, retaddr); + shift = (addr & (1 - 1)) * 8; + + /* Little-endian combine. */ + res = (res1 >> shift) | (res2 << ((1 * 8) - shift)); + return res; + } + + haddr = addr + env->tlb_table[mmu_idx][index].addend; + + res = ldub_p((uint8_t *)haddr); + + + + return res; +}