From nobody Wed Feb 11 05:11:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516837627213185.42995286166536; Wed, 24 Jan 2018 15:47:07 -0800 (PST) Received: from localhost ([::1]:54579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeUl0-00044Y-BJ for importer@patchew.org; Wed, 24 Jan 2018 18:47:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeURU-0004eB-Pu for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeURS-0001n3-To for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:56 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:38598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeURS-0001m1-M5 for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:54 -0500 Received: by mail-pf0-x244.google.com with SMTP id k19so4360186pfj.5 for ; Wed, 24 Jan 2018 15:26:54 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id z19sm9760028pfh.185.2018.01.24.15.26.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jan 2018 15:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=cNMWduwd/imEbozb8k3aw4xPmG54EEtG552lqHT79mQ=; b=K/Kd1IwDo7MruYUuTKUvO1GNRiDwCKcp0Ptt6hxHWwFr5Kt3/WarRLVvj+74jpIfJn rMKl9ZBy6kxTq8RurgbaSWY2TX9yM+2vmCpVTE2RVDBPTaWKhQWp2OJmKRUsNHvCj0zd FYwdEckaqgGdv2+ri3Ku64Glt6Lbb8K4MOa3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cNMWduwd/imEbozb8k3aw4xPmG54EEtG552lqHT79mQ=; b=UrCl3vflTv549B6cyinUemwoQKwxAWN4ELyEJbk55pe3wifjd6DH3LfP4oicr87kXz lTxnCdDRU/n2d3oyqgPnt8sitwmQ5Om3b2phoqHaiEBgkN70EACnMmiA+BnMOgal6Vt4 MmNehuJyMvZ/4jLj9Y/LqYVZ9swn12pNhAU3C3/BP0tMf9YOfOQ4SCV93IebiYrYf/sZ +wdM/4jfTyqoPwquSewJL8KceowOP7sKwAk35Z09bEpx3Vu/hb/4WM22WbeTCYCVxLcj +NJV7Cg30sET78A8COjiagJWLhwmVsaMVoYizgAk+X/83L8FEePGSEHTae2aFDiI2QkM Sblg== X-Gm-Message-State: AKwxyte3czS3vyJEvdcAm6sEB0RlHGolNrqBKsxIEL7KztJrfPV+GBlP 7VomqlirQWG3PKiEOJ6KeHSRY3yLtng= X-Google-Smtp-Source: AH8x227B8xL4jrd1KtVxW2VIlD9F35hnrt9DRoHQPOkMvYQmcUjcjbix8gjiRpRZKNpr5trDT/aCFA== X-Received: by 2002:a17:902:7f0b:: with SMTP id d11-v6mr5407673plm.70.1516836413291; Wed, 24 Jan 2018 15:26:53 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 24 Jan 2018 15:25:57 -0800 Message-Id: <20180124232625.30105-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180124232625.30105-1-richard.henderson@linaro.org> References: <20180124232625.30105-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v3 17/45] target/hppa: Implement 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" However since HPPA has a software-managed TLB, and the relevant TLB manipulation instructions are not implemented, this does not actually do anything. Signed-off-by: Richard Henderson --- target/hppa/cpu.h | 29 ++++++++- target/hppa/int_helper.c | 15 ++++- target/hppa/mem_helper.c | 151 +++++++++++++++++++++++++++++++++++++++++++= ++-- 3 files changed, 188 insertions(+), 7 deletions(-) diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index d583ea43dd..c7a2fb5b20 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -165,6 +165,22 @@ typedef int64_t target_sreg; #define TREG_FMT_ld "%"PRId64 #endif =20 +typedef struct { + uint64_t va_b; + uint64_t va_e; + target_ureg pa; + unsigned u : 1; + unsigned t : 1; + unsigned d : 1; + unsigned b : 1; + unsigned page_size : 4; + unsigned ar_type : 3; + unsigned ar_pl1 : 2; + unsigned ar_pl2 : 2; + unsigned entry_valid : 1; + unsigned access_id : 16; +} hppa_tlb_entry; + struct CPUHPPAState { target_ureg gr[32]; uint64_t fr[32]; @@ -198,6 +214,12 @@ struct CPUHPPAState { =20 /* Those resources are used only in QEMU core */ CPU_COMMON + + /* ??? The number of entries isn't specified by the architecture. */ + /* ??? Implement a unified itlb/dtlb for the moment. */ + /* ??? We should use a more intelligent data structure. */ + hppa_tlb_entry tlb[256]; + uint32_t tlb_last; }; =20 /** @@ -307,12 +329,17 @@ void cpu_hppa_loaded_fr0(CPUHPPAState *env); #define cpu_signal_handler cpu_hppa_signal_handler =20 int cpu_hppa_signal_handler(int host_signum, void *pinfo, void *puc); -int hppa_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw, int mi= dx); hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr); int hppa_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void hppa_cpu_do_interrupt(CPUState *cpu); bool hppa_cpu_exec_interrupt(CPUState *cpu, int int_req); void hppa_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function, int); +#ifdef CONFIG_USER_ONLY +int hppa_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw, int mi= dx); +#else +int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx, + MMUAccessType type, hwaddr *pphys, int *ppro= t); +#endif =20 #endif /* HPPA_CPU_H */ diff --git a/target/hppa/int_helper.c b/target/hppa/int_helper.c index 02963b80c6..5ae5233a96 100644 --- a/target/hppa/int_helper.c +++ b/target/hppa/int_helper.c @@ -79,12 +79,25 @@ void hppa_cpu_do_interrupt(CPUState *cs) { /* Avoid reading directly from the virtual address, lest we raise another exception from some sort of TLB issue. */ + /* ??? An alternate fool-proof method would be to store the + instruction data into the unwind info. That's probably + a bit too much in the way of extra storage required. */ vaddr vaddr; hwaddr paddr; =20 paddr =3D vaddr =3D iaoq_f & -4; if (old_psw & PSW_C) { - vaddr =3D hppa_form_gva_psw(old_psw, iasq_f, iaoq_f & = -4); + int prot, t; + + vaddr =3D hppa_form_gva_psw(old_psw, iasq_f, vaddr); + t =3D hppa_get_physical_address(env, vaddr, 0, + MMU_INST_FETCH, + &paddr, &prot); + if (t >=3D 0) { + /* We can't re-load the instruction. */ + env->cr[CR_IIR] =3D 0; + break; + } } env->cr[CR_IIR] =3D ldl_phys(cs->as, paddr); } diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c index 1afaf89539..08ab19aacf 100644 --- a/target/hppa/mem_helper.c +++ b/target/hppa/mem_helper.c @@ -36,18 +36,159 @@ int hppa_cpu_handle_mmu_fault(CPUState *cs, vaddr addr= ess, return 1; } #else +static hppa_tlb_entry *hppa_find_tlb(CPUHPPAState *env, vaddr addr) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(env->tlb); ++i) { + hppa_tlb_entry *ent =3D &env->tlb[i]; + if (ent->va_b <=3D addr && addr <=3D ent->va_e && ent->entry_valid= ) { + return ent; + } + } + return NULL; +} + +int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx, + MMUAccessType type, hwaddr *pphys, int *ppro= t) +{ + hwaddr phys; + int prot, ret, r_prot, w_prot, x_prot, a_prot; + bool ifetch =3D type =3D=3D MMU_INST_FETCH; + hppa_tlb_entry *ent; + + /* Virtual translation disabled. Direct map virtual to physical. */ + if (mmu_idx =3D=3D MMU_PHYS_IDX) { + phys =3D addr; + prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + ret =3D -1; + goto egress; + } + + /* Find a valid tlb entry that matches the virtual address. */ + ent =3D hppa_find_tlb(env, addr); + if (ent =3D=3D NULL) { + phys =3D 0; + prot =3D 0; + ret =3D (ifetch ? EXCP_ITLB_MISS : EXCP_DTLB_MISS); + goto egress; + } + + /* We now know the physical address. */ + phys =3D ent->pa + (addr & ~TARGET_PAGE_MASK); + + /* Map TLB access_rights field to QEMU protection. */ + r_prot =3D (mmu_idx <=3D ent->ar_pl1 ? PROT_READ : 0); + w_prot =3D (mmu_idx <=3D ent->ar_pl2 ? PROT_WRITE : 0); + x_prot =3D (ent->ar_pl2 <=3D mmu_idx && mmu_idx <=3D ent->ar_pl1 ? PRO= T_EXEC : 0); + switch (ent->ar_type) { + case 0: /* read-only: data page */ + prot =3D r_prot; + break; + case 1: /* read/write: dynamic data page */ + prot =3D r_prot | w_prot; + break; + case 2: /* read/execute: normal code page */ + prot =3D r_prot | x_prot; + break; + case 3: /* read/write/execute: dynamic code page */ + prot =3D r_prot | w_prot | x_prot; + break; + default: /* execute: promote to privilege level type & 3 */ + prot =3D x_prot; + } + + /* ??? Check PSW_P and ent->access_prot. This can remove PROT_WRITE. = */ + + /* Map MMUAccessType to QEMU protection. */ + if (ifetch) { + a_prot =3D PROT_EXEC; + } else if (type =3D=3D MMU_DATA_STORE) { + a_prot =3D PROT_WRITE; + } else { + a_prot =3D PROT_READ; + } + + if (unlikely(!(prot & a_prot))) { + /* The access isn't allowed -- Inst/Data Memory Protection Fault. = */ + ret =3D (ifetch ? EXCP_IMP : EXCP_DMP); + goto egress; + } + + /* In reverse priority order, check for conditions which raise faults. + As we go, remove PROT bits that cover the condition we want to chec= k. + In this way, the resulting PROT will force a re-check of the + architectural TLB entry for the next access. */ + ret =3D -1; + if (unlikely(!ent->d)) { + if (type =3D=3D MMU_DATA_STORE) { + /* The D bit is not set -- TLB Dirty Bit Fault. */ + ret =3D EXCP_TLB_DIRTY; + } + prot &=3D PROT_READ | PROT_EXEC; + } + if (unlikely(ent->b)) { + if (type =3D=3D MMU_DATA_STORE) { + /* The B bit is set -- Data Memory Break Fault. */ + ret =3D EXCP_DMB; + } + prot &=3D PROT_READ | PROT_EXEC; + } + if (unlikely(ent->t)) { + if (!ifetch) { + /* The T bit is set -- Page Reference Fault. */ + ret =3D EXCP_PAGE_REF; + } + prot &=3D PROT_EXEC; + } + + egress: + *pphys =3D phys; + *pprot =3D prot; + return ret; +} + hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) { - /* Stub */ - return addr; + HPPACPU *cpu =3D HPPA_CPU(cs); + hwaddr phys; + int prot, excp; + + /* If the (data) mmu is disabled, bypass translation. */ + /* ??? We really ought to know if the code mmu is disabled too, + in order to get the correct debugging dumps. */ + if (!(cpu->env.psw & PSW_D)) { + return addr; + } + + excp =3D hppa_get_physical_address(&cpu->env, addr, MMU_KERNEL_IDX, + MMU_DATA_LOAD, &phys, &prot); + + /* Since we're translating for debugging, the only error that is a + hard error is no translation at all. Otherwise, while a real cpu + access might not have permission, the debugger does. */ + return excp =3D=3D EXCP_DTLB_MISS ? -1 : phys; } =20 void tlb_fill(CPUState *cs, target_ulong addr, MMUAccessType type, int mmu_idx, uintptr_t retaddr) { - /* Stub */ - int prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; - hwaddr phys =3D addr; + HPPACPU *cpu =3D HPPA_CPU(cs); + int prot, excp; + hwaddr phys; + + excp =3D hppa_get_physical_address(&cpu->env, addr, mmu_idx, + type, &phys, &prot); + if (unlikely(excp >=3D 0)) { + /* Failure. Raise the indicated exception. */ + cs->exception_index =3D excp; + if (cpu->env.psw & PSW_Q) { + /* ??? Needs tweaking for hppa64. */ + cpu->env.cr[CR_IOR] =3D addr; + cpu->env.cr[CR_ISR] =3D addr >> 32; + } + cpu_loop_exit_restore(cs, retaddr); + } =20 /* Success! Store the translation into the QEMU TLB. */ tlb_set_page(cs, addr & TARGET_PAGE_MASK, phys & TARGET_PAGE_MASK, --=20 2.14.3