From patchwork Sat Jan 13 11:14:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 860334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJcZT6wPHz9t42 for ; Sat, 13 Jan 2018 22:19:13 +1100 (AEDT) Received: from localhost ([::1]:58405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eaJqB-0002l1-Tw for incoming@patchwork.ozlabs.org; Sat, 13 Jan 2018 06:19:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eaJlr-0008QY-4L for qemu-devel@nongnu.org; Sat, 13 Jan 2018 06:14:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eaJlp-0007Gi-JU for qemu-devel@nongnu.org; Sat, 13 Jan 2018 06:14:43 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:64032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eaJlp-0007Fu-92 for qemu-devel@nongnu.org; Sat, 13 Jan 2018 06:14:41 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MTKL8-1eT4GH0lVe-00S3xT; Sat, 13 Jan 2018 12:14:39 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sat, 13 Jan 2018 12:14:27 +0100 Message-Id: <20180113111428.7066-7-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180113111428.7066-1-laurent@vivier.eu> References: <20180113111428.7066-1-laurent@vivier.eu> X-Provags-ID: V03:K0:awx4lW3cz9eI9dJfGkqG6MtQv7JTz1i5kBJYHnsbjPJ2nyDHquL SA6n8hBmRu8CNk1XUx4sMkf3/IeBf0E7vBCr7Cc8+y+6kYKmc3G1Lw6RRneSpKnAZqgTtMk zIHhYEBNgLuNLaFkvWIq7NCqP2fFRqt/uy797Zb5LRaw1GKPagoZv+n6o9YWGa7tHX6FhE+ tiOCZD5qVIgqdzLyUNN5A== X-UI-Out-Filterresults: notjunk:1; V01:K0:f7dBGrPrfEQ=:5lS31/13QWhrM+YTIIpv15 2/ZBpbpGSnQzSu2CPGtxxbKV8RKCR9odfbpwu2pTi//l5SAIrAPinghs97u0ttVR7NkpHrjym r/vwlSNOA1BkAK/nCq+OWrvQfbrE8ZYbHSvPhKc0ZDTBXKPoHj2MbmpfI4Y6Bcy9b53A1VhM6 biqU4brmRL6bkWGymzTQRl8K+MRnVV9jqgKxPhPKR9W4UgD+nNiKJ6Eoe1o0q0/khtFcO6hmo XoijXS79U2fjYIGxqN4h2YLVTYkq6hwN6bHQhpDbICCOnebuk4oy6yY9ZrKRsV6tKDE6OZE8+ ZKS1dQBr1HBjML6HAbIFeYJ7JoKG8/aNsqxIulHtc4+NI8y0WAkgFqtBe2rnJ0X8f7j10qnt1 i9L0vqBxNqNzydbf85bmy2zEQ+WD6QJ8iRo2a5MF5rftjtn1ZXPmaWhhmmDMVwZY1uHS3OEBn Ods2vJ0OwZT1eKZpmcbED7IvRTtyhQiCO8v4ms6v8/pqWpqPdyWW3HqBmZSXmx76iwn9nIPIJ 4n8w6GL7Elsyc1ZuA2g5oPalpQbTFI71yC7GhtKOwCAT4xjtogGw7CoTgZDl8NPK7yFNbjI/+ 8OIy5rbVihn41/naeFC8o1YCvt5p7ylFsaFzbraaVPHvx77XqiQJXZvfWKlff9wkg81TYxRft vp+auHJMvjlOWAOIQtgag8T1qjJBUHk6JJHU/jYik9TDPSXM0kM2qlewtehwR+OPxPZMyP/Ae sRxkIrJiF94xwnNeBE7OZC4/sPT7Qrge/9h70w== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.133 Subject: [Qemu-devel] [PATCH v3 6/7] target/m68k: add pflush/ptest 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: Thomas Huth , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- v2: change ACCESS_PTEST value because of new ACCESS_DEBUG use -page_size to mask address instead of TARGET_PAGE_MASK target/m68k/cpu.h | 3 +++ target/m68k/helper.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.h | 2 ++ target/m68k/monitor.c | 1 + target/m68k/op_helper.c | 1 + target/m68k/translate.c | 33 +++++++++++++++++++++++ 6 files changed, 112 insertions(+) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index af24f061f5..1655875dbb 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -131,6 +131,7 @@ typedef struct CPUM68KState { uint32_t srp; bool fault; uint32_t ttr[4]; + uint32_t mmusr; } mmu; /* Control registers. */ @@ -510,6 +511,8 @@ enum { ACCESS_STORE = 0x02, /* 1 bit to indicate debug access */ ACCESS_DEBUG = 0x04, + /* PTEST instruction */ + ACCESS_PTEST = 0x08, /* Type of instruction that generated the access */ ACCESS_CODE = 0x10, /* Code fetch access */ ACCESS_DATA = 0x20, /* Data load/store access */ diff --git a/target/m68k/helper.c b/target/m68k/helper.c index c1bd0e9681..6950c03ada 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -221,6 +221,9 @@ void HELPER(m68k_movec_to)(CPUM68KState *env, uint32_t reg, uint32_t val) case M68K_CR_TC: env->mmu.tcr = val; return; + case M68K_CR_MMUSR: + env->mmu.mmusr = val; + return; case M68K_CR_SRP: env->mmu.srp = val; return; @@ -272,6 +275,8 @@ uint32_t HELPER(m68k_movec_from)(CPUM68KState *env, uint32_t reg) /* MC680[34]0 */ case M68K_CR_TC: return env->mmu.tcr; + case M68K_CR_MMUSR: + return env->mmu.mmusr; case M68K_CR_SRP: return env->mmu.srp; case M68K_CR_USP: @@ -434,6 +439,10 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical, for (i = 0; i < M68K_MAX_TTR; i++) { if (check_TTR(env->mmu.TTR(access_type, i), prot, address, access_type)) { + if (access_type & ACCESS_PTEST) { + /* Transparent Translation Register bit */ + env->mmu.mmusr = M68K_MMU_T_040 | M68K_MMU_R_040; + } *physical = address; *page_size = TARGET_PAGE_SIZE; return 0; @@ -462,6 +471,9 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical, stl_phys(cs->as, entry, next | M68K_DESC_USED); } if (next & M68K_DESC_WRITEPROT) { + if (access_type & ACCESS_PTEST) { + env->mmu.mmusr |= M68K_MMU_WP_040; + } *prot &= ~PAGE_WRITE; if (access_type & ACCESS_STORE) { return -1; @@ -479,6 +491,9 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical, stl_phys(cs->as, entry, next | M68K_DESC_USED); } if (next & M68K_DESC_WRITEPROT) { + if (access_type & ACCESS_PTEST) { + env->mmu.mmusr |= M68K_MMU_WP_040; + } *prot &= ~PAGE_WRITE; if (access_type & ACCESS_STORE) { return -1; @@ -526,6 +541,12 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical, page_offset = address & ~page_mask; *physical = (next & page_mask) + page_offset; + if (access_type & ACCESS_PTEST) { + env->mmu.mmusr |= next & M68K_MMU_SR_MASK_040; + env->mmu.mmusr |= *physical & 0xfffff000; + env->mmu.mmusr |= M68K_MMU_R_040; + } + if (next & M68K_DESC_WRITEPROT) { *prot &= ~PAGE_WRITE; if (access_type & ACCESS_STORE) { @@ -1079,6 +1100,57 @@ void HELPER(set_mac_extu)(CPUM68KState *env, uint32_t val, uint32_t acc) } #if defined(CONFIG_SOFTMMU) +void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) +{ + M68kCPU *cpu = m68k_env_get_cpu(env); + CPUState *cs = CPU(cpu); + hwaddr physical; + int access_type; + int prot; + int ret; + target_ulong page_size; + + access_type = ACCESS_PTEST; + if (env->dfc & 4) { + access_type |= ACCESS_SUPER; + } + if ((env->dfc & 3) == 2) { + access_type |= ACCESS_CODE; + } + if (!is_read) { + access_type |= ACCESS_STORE; + } + + env->mmu.mmusr = 0; + env->mmu.ssw = 0; + ret = get_physical_address(env, &physical, &prot, addr, + access_type, &page_size); + if (ret == 0) { + tlb_set_page(cs, addr & -page_size, + physical & -page_size, + prot, access_type & ACCESS_SUPER ? + MMU_KERNEL_IDX : MMU_USER_IDX, page_size); + } +} + +void HELPER(pflush)(CPUM68KState *env, uint32_t addr, uint32_t opmode) +{ + M68kCPU *cpu = m68k_env_get_cpu(env); + + switch (opmode) { + case 0: /* Flush page entry if not global */ + case 1: /* Flush page entry */ + tlb_flush_page(CPU(cpu), addr); + break; + case 2: /* Flush all except global entries */ + tlb_flush(CPU(cpu)); + break; + case 3: /* Flush all entries */ + tlb_flush(CPU(cpu)); + break; + } +} + void HELPER(reset)(CPUM68KState *env) { /* FIXME: reset all except CPU */ diff --git a/target/m68k/helper.h b/target/m68k/helper.h index 57f210aa14..7f400f0def 100644 --- a/target/m68k/helper.h +++ b/target/m68k/helper.h @@ -101,5 +101,7 @@ DEF_HELPER_3(chk, void, env, s32, s32) DEF_HELPER_4(chk2, void, env, s32, s32, s32) #if defined(CONFIG_SOFTMMU) +DEF_HELPER_3(ptest, void, env, i32, i32) +DEF_HELPER_3(pflush, void, env, i32, i32) DEF_HELPER_FLAGS_1(reset, TCG_CALL_NO_RWG, void, env) #endif diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c index c31feb4b02..486213cd8b 100644 --- a/target/m68k/monitor.c +++ b/target/m68k/monitor.c @@ -39,6 +39,7 @@ static const MonitorDef monitor_defs[] = { { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) }, { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) }, { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) }, + { "mmusr", offsetof(CPUM68KState, mmu.mmusr) }, { NULL }, }; diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 4609caa546..ffea9693fc 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -466,6 +466,7 @@ void m68k_cpu_unassigned_access(CPUState *cs, hwaddr addr, bool is_write, } if (m68k_feature(env, M68K_FEATURE_M68040)) { + env->mmu.mmusr = 0; env->mmu.ssw |= M68K_ATC_040; /* FIXME: manage MMU table access error */ env->mmu.ssw &= ~M68K_TM_040; diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 694de43106..f75bf32390 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -4675,6 +4675,35 @@ DISAS_INSN(cinv) /* Invalidate cache line. Implement as no-op. */ } +#if defined(CONFIG_SOFTMMU) +DISAS_INSN(pflush) +{ + TCGv opmode; + + if (IS_USER(s)) { + gen_exception(s, s->insn_pc, EXCP_PRIVILEGE); + return; + } + + opmode = tcg_const_i32((insn >> 3) & 3); + gen_helper_pflush(cpu_env, AREG(insn, 0), opmode); + tcg_temp_free(opmode); +} + +DISAS_INSN(ptest) +{ + TCGv is_read; + + if (IS_USER(s)) { + gen_exception(s, s->insn_pc, EXCP_PRIVILEGE); + return; + } + is_read = tcg_const_i32((insn >> 5) & 1); + gen_helper_ptest(cpu_env, AREG(insn, 0), is_read); + tcg_temp_free(is_read); +} +#endif + DISAS_INSN(wddata) { gen_exception(s, s->insn_pc, EXCP_PRIVILEGE); @@ -5868,6 +5897,8 @@ void register_m68k_insns (CPUM68KState *env) INSN(cpushl, f428, ff38, CF_ISA_A); INSN(cpush, f420, ff20, M68040); INSN(cinv, f400, ff20, M68040); + INSN(pflush, f500, ffe0, M68040); + INSN(ptest, f548, ffd8, M68040); INSN(wddata, fb00, ff00, CF_ISA_A); INSN(wdebug, fbc0, ffc0, CF_ISA_A); #endif @@ -6075,6 +6106,8 @@ void m68k_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, cpu_fprintf(f, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n", env->mmu.ttr[M68K_DTTR0], env->mmu.ttr[M68K_DTTR1], env->mmu.ttr[M68K_ITTR0], env->mmu.ttr[M68K_ITTR1]); + cpu_fprintf(f, "MMUSR %08x, fault at %08x\n", + env->mmu.mmusr, env->mmu.ar); #endif }