From patchwork Wed Apr 3 03:43:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 161660 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2516310jan; Tue, 2 Apr 2019 20:53:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXyjlY8MluVvGRNFROioIlwAe/dUqGaz4S5QPcLjSMmtVyvcjmYxvctQY2JXZ3mUkLvKrZ X-Received: by 2002:a25:c0c2:: with SMTP id c185mr2491688ybf.436.1554263609508; Tue, 02 Apr 2019 20:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554263609; cv=none; d=google.com; s=arc-20160816; b=lt27KJyqHOp3B0jF/+jpBNuuY4othFMvJYJ0sUAmWAX5u5veD4PjOc9KpANz3AkbAz I9bzGTWrc1b/48ysQyOFUxJ9Z1ElieUjbmS9Phc4JiBgDThApzGErFlPdjwmBLU6Cg3i wq0xKOlmfaPDr4sJJGqaxgmko+uvuBX8BSP42aC2ZhxDTou6n8xS5hMOK0NdYjx7KF5N u7BnU8KB1jyNqlpAksNasI9SBwTvpqOhYax3rDMkEwu/OP8aP8u8cjnnO/9/H9Il5JwK koEOeQELh7VetGjFUQKZCYQbogE6EJ34xmndPBCC2hG7bKOY1cHQWRFSFnD68i2MeaHT +woQ== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=RvZL9Bk1/BL1xpfiQMAt2J0TEi4VsVh2Sx8xG9Gdt3Q=; b=yVQoFe6gVtJEC2YmI4ntBU6PFBtGohxy6r6m1U5YHYIxtffPpiWr+8LoboPfFOZr0G 0bRdJrmQJmOGTx4zfjTyv9xMJrnY/vPUaKwx435iIpJsL2mxGhLITntq/D+jTwqGJpxj JYWZG1MTKfqhk7thrMlPVHH/TQb3/y8qLWlYAp0JtFEK1CVm4n5U8eFZoO9UOyyUXWid tYUJnzA7WGqF9lWmnP2/2iktkJUYOHOkk3H+tzxsyq91TeTHOhOWFcfqt+7ZYOJAGIXz L9cIOXxxw1xFU6ONlIiphjD3i/kQJ43u3E2TrT/TnpAGgyC8OxlCN47LsXix7szG9ags StEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=la5zkhz+; 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=fail (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 62si8788225ybv.364.2019.04.02.20.53.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 02 Apr 2019 20:53:29 -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=fail header.i=@linaro.org header.s=google header.b=la5zkhz+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWxs-0002Eh-Vx for patch@linaro.org; Tue, 02 Apr 2019 23:53:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWp6-0002qx-Q5 for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBWp5-0008JO-Br for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:24 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:41862) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hBWp5-0008Ii-0K for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:23 -0400 Received: by mail-pf1-x442.google.com with SMTP id 188so7431706pfd.8 for ; Tue, 02 Apr 2019 20:44:22 -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; bh=RvZL9Bk1/BL1xpfiQMAt2J0TEi4VsVh2Sx8xG9Gdt3Q=; b=la5zkhz+hbRZKlFXVn4uGAisD9zjVNxoAsDOX+FA67ZAp+IapQZqjlMex1xGd3HqaS x09HGzj6nMOx7sTCW+IV0hpX0aFpxU4CsorPqiqFslAaQhn7ULJ1fkFB62OdRzjvUpAO PLWdz2owvuctluyRdU776zNjlpy5htVFnebMqHxq4ioUzPvQ8mxsVwxiEclhP+qDHl2z ErjiwctCIYwQcfNeBQX0y4dCf0G5DlZIKdYHPU8u9mvGsDUxZVjLEeRG5eDxYTz5nniD J1f4iy+imZmPNSeV9nvcX71c4MpizIZtTTyS/0uFgXPev0AD4/DDvkY3kAt7LoUVkgm8 YHtQ== 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; bh=RvZL9Bk1/BL1xpfiQMAt2J0TEi4VsVh2Sx8xG9Gdt3Q=; b=m+clZh41QzfayJL/hm7Y3yntWvjwG2HwAN5JnBb9nImT2Gl83eDaAvoAKZyAqCcZ0p ktbLHO9TYcHz9wvAYNm/Zu5oUK1MN+pE7K76pGax8yvM8n/snjCX8S5ZM8Eoy/SKZlDo K0Nm63N1kG5OiCFvuOokJUNS3fBSX3so2bE9BtcXX8ltepYau8631KCm8Qnwj14eBYZg qCPPrb0rIhCzmS3IimowkM/Le7QhJj3amEIZgxD7KrDROxEzi5S4Ihphh1yCkFKhqqkc iL7er3wqRhIk04hubWXBXVOAVUGX8PJKfva4XCXR6bFKC0hueiFTBTd1n+e/4CleN+H/ sA1Q== X-Gm-Message-State: APjAAAXBDXa+EuZl0jv0KhP0p9UMMVQbIituEKEsLdowuHwQMdV8uDyd jVIl91xRNl4JmkrxuuRwzdJpZI1WDlxRPA== X-Received: by 2002:a63:e051:: with SMTP id n17mr69999158pgj.19.1554263061663; Tue, 02 Apr 2019 20:44:21 -0700 (PDT) Received: from cloudburst.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id z6sm26753214pgo.31.2019.04.02.20.44.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 20:44:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 3 Apr 2019 10:43:42 +0700 Message-Id: <20190403034358.21999-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190403034358.21999-1-richard.henderson@linaro.org> References: <20190403034358.21999-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH 10/26] target/microblaze: Convert to CPUClass::tlb_fill 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: "Edgar E . Iglesias" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Edgar E. Iglesias Signed-off-by: Richard Henderson --- target/microblaze/cpu.h | 5 +- target/microblaze/cpu.c | 5 +- target/microblaze/helper.c | 142 +++++++++++++++++----------------- target/microblaze/op_helper.c | 19 ----- 4 files changed, 78 insertions(+), 93 deletions(-) -- 2.17.1 diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index 792bbc97c7..8660c7673b 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -375,8 +375,9 @@ static inline int cpu_mmu_index (CPUMBState *env, bool ifetch) return MMU_KERNEL_IDX; } -int mb_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw, - int mmu_idx); +bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); #include "exec/cpu-all.h" diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 5596cd5485..0ea549910b 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -304,9 +304,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = mb_cpu_set_pc; cc->gdb_read_register = mb_cpu_gdb_read_register; cc->gdb_write_register = mb_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = mb_cpu_handle_mmu_fault; -#else + cc->tlb_fill = mb_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_transaction_failed = mb_cpu_transaction_failed; cc->get_phys_page_debug = mb_cpu_get_phys_page_debug; #endif diff --git a/target/microblaze/helper.c b/target/microblaze/helper.c index bc753793ec..2d1d10e6cf 100644 --- a/target/microblaze/helper.c +++ b/target/microblaze/helper.c @@ -26,7 +26,78 @@ #define D(x) -#if defined(CONFIG_USER_ONLY) +bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr) +{ + MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); + CPUMBState *env = &cpu->env; + +#ifndef CONFIG_USER_ONLY + uint32_t vaddr, paddr; + struct microblaze_mmu_lookup lu; + unsigned int hit; + int prot; + + if (mmu_idx == MMU_NOMMU_IDX) { + /* MMU disabled or not available. */ + address &= TARGET_PAGE_MASK; + prot = PAGE_BITS; + tlb_set_page(cs, address, address, prot, mmu_idx, TARGET_PAGE_SIZE); + return true; + } + + hit = mmu_translate(&env->mmu, &lu, address, access_type, mmu_idx); + if (likely(hit)) { + vaddr = address & TARGET_PAGE_MASK; + paddr = lu.paddr + vaddr - lu.vaddr; + + qemu_log_mask(CPU_LOG_MMU, "MMU map mmu=%d v=%x p=%x prot=%x\n", + mmu_idx, vaddr, paddr, lu.prot); + tlb_set_page(cs, vaddr, paddr, lu.prot, mmu_idx, TARGET_PAGE_SIZE); + return true; + } + + /* TLB miss. */ + if (probe) { + return false; + } + + qemu_log_mask(CPU_LOG_MMU, "mmu=%d miss v=%" VADDR_PRIx "\n", + mmu_idx, address); + + switch (lu.err) { + case ERR_PROT: + env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ? 17 : 16; + env->sregs[SR_ESR] |= (access_type == MMU_DATA_STORE) << 10; + break; + case ERR_MISS: + env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ? 19 : 18; + env->sregs[SR_ESR] |= (access_type == MMU_DATA_STORE) << 10; + break; + default: + g_assert_not_reached(); + } + + if (cs->exception_index == EXCP_MMU) { + cpu_abort(cs, "recursive faults\n"); + } +#endif + + env->sregs[SR_EAR] = address; + cs->exception_index = EXCP_MMU; + cpu_loop_exit_restore(cs, retaddr); +} + +#ifndef CONFIG_USER_ONLY +void tlb_fill(CPUState *cs, target_ulong addr, int size, + MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) +{ + mb_cpu_tlb_fill(cs, addr, size, access_type, mmu_idx, false, retaddr); +} +#endif + +#ifdef CONFIG_USER_ONLY void mb_cpu_do_interrupt(CPUState *cs) { @@ -38,74 +109,7 @@ void mb_cpu_do_interrupt(CPUState *cs) env->regs[14] = env->sregs[SR_PC]; } -int mb_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, - int mmu_idx) -{ - cs->exception_index = 0xaa; - cpu_dump_state(cs, stderr, fprintf, 0); - return 1; -} - -#else /* !CONFIG_USER_ONLY */ - -int mb_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, - int mmu_idx) -{ - MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); - CPUMBState *env = &cpu->env; - unsigned int hit; - int r = 1; - int prot; - - /* Translate if the MMU is available and enabled. */ - if (mmu_idx != MMU_NOMMU_IDX) { - uint32_t vaddr, paddr; - struct microblaze_mmu_lookup lu; - - hit = mmu_translate(&env->mmu, &lu, address, rw, mmu_idx); - if (hit) { - vaddr = address & TARGET_PAGE_MASK; - paddr = lu.paddr + vaddr - lu.vaddr; - - qemu_log_mask(CPU_LOG_MMU, "MMU map mmu=%d v=%x p=%x prot=%x\n", - mmu_idx, vaddr, paddr, lu.prot); - tlb_set_page(cs, vaddr, paddr, lu.prot, mmu_idx, TARGET_PAGE_SIZE); - r = 0; - } else { - env->sregs[SR_EAR] = address; - qemu_log_mask(CPU_LOG_MMU, "mmu=%d miss v=%" VADDR_PRIx "\n", - mmu_idx, address); - - switch (lu.err) { - case ERR_PROT: - env->sregs[SR_ESR] = rw == 2 ? 17 : 16; - env->sregs[SR_ESR] |= (rw == 1) << 10; - break; - case ERR_MISS: - env->sregs[SR_ESR] = rw == 2 ? 19 : 18; - env->sregs[SR_ESR] |= (rw == 1) << 10; - break; - default: - abort(); - break; - } - - if (cs->exception_index == EXCP_MMU) { - cpu_abort(cs, "recursive faults\n"); - } - - /* TLB miss. */ - cs->exception_index = EXCP_MMU; - } - } else { - /* MMU disabled or not available. */ - address &= TARGET_PAGE_MASK; - prot = PAGE_BITS; - tlb_set_page(cs, address, address, prot, mmu_idx, TARGET_PAGE_SIZE); - r = 0; - } - return r; -} +#else void mb_cpu_do_interrupt(CPUState *cs) { diff --git a/target/microblaze/op_helper.c b/target/microblaze/op_helper.c index e23dcfdc20..b5dbb90d05 100644 --- a/target/microblaze/op_helper.c +++ b/target/microblaze/op_helper.c @@ -28,25 +28,6 @@ #define D(x) -#if !defined(CONFIG_USER_ONLY) - -/* Try to fill the TLB and return an exception if error. If retaddr is - * NULL, it means that the function was called in C code (i.e. not - * from generated code or from helper.c) - */ -void tlb_fill(CPUState *cs, target_ulong addr, int size, - MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) -{ - int ret; - - ret = mb_cpu_handle_mmu_fault(cs, addr, size, access_type, mmu_idx); - if (unlikely(ret)) { - /* now we have a real cpu fault */ - cpu_loop_exit_restore(cs, retaddr); - } -} -#endif - void helper_put(uint32_t id, uint32_t ctrl, uint32_t data) { int test = ctrl & STREAM_TEST;