Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L3ebz-0004dQ-QS for qemu-devel@nongnu.org; Fri, 21 Nov 2008 17:36:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L3ebz-0004d4-9X for qemu-devel@nongnu.org; Fri, 21 Nov 2008 17:36:27 -0500 Received: from [199.232.76.173] (port=35977 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L3eby-0004cw-TY for qemu-devel@nongnu.org; Fri, 21 Nov 2008 17:36:26 -0500 Received: from hall.aurel32.net ([88.191.82.174]:58172) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L3eby-0001Sw-B8 for qemu-devel@nongnu.org; Fri, 21 Nov 2008 17:36:26 -0500 Received: from volta-wlan.aurel32.net ([2002:52e8:2fb:ffff:21d:e0ff:fe49:1047] helo=volta.aurel32.net) by hall.aurel32.net with esmtpsa (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1L3ebw-00036i-6J for qemu-devel@nongnu.org; Fri, 21 Nov 2008 23:36:24 +0100 Received: from aurel32 by volta.aurel32.net with local (Exim 4.69) (envelope-from ) id 1L3ebv-0001QT-Lg for qemu-devel@nongnu.org; Fri, 21 Nov 2008 23:36:23 +0100 Date: Fri, 21 Nov 2008 23:36:23 +0100 From: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH] SH: Fix TLB/MMU detection of code accesses. Message-ID: <20081121223623.GB4884@volta.aurel32.net> References: <200810240004.41414.vladimir@codesourcery.com> <49130D60.5090503@juno.dti.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <49130D60.5090503@juno.dti.ne.jp> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On Fri, Nov 07, 2008 at 12:29:36AM +0900, Shin-ichiro KAWASAKI wrote: > Vladimir Prus wrote: > > Current SH4 TLB emulation does strange thing about code accesses. For > > code accesses, tlb_fill will have 2 passed for is_write parameter. > > In SH case, tlb_fill calls cpu_sh4_handle_mmu_fault, which treats > > data read and code read identically -- that is, the same value is > > passed for the 'rw' parameter for get_physical_address. The latter > > function then calls get_mmu_address -- which tries to figure if we're > > doing code address or not -- by comparing env->pc with the address > > being accessed. The code comment say "Hack", and in fact this sometimes > > gets wrong results, which causes random crashes in the simulated program. > > > > This patch fixes this, by stopping cpu_sh4_handle_mmu_fault from > > erasing the data read/code read distinction. > > I found that this patch still can be applied to the trunk HEAD, rev 5639, > and it really stabilizes SH-Linux system emulation : some segmentation > fault disappears. Thanks. > > > > @@ -406,11 +404,11 @@ static int get_mmu_address(CPUState * env, target_ulong * physical, > > case 3: /* 011 */ > > case 6: /* 110 */ > > case 7: /* 111 */ > > - *prot = rw & (PAGE_READ | PAGE_WRITE); > > + *prot = (rw == 1)? PAGE_WRITE : PAGE_READ; > > break; > > } > > } else if (n == MMU_DTLB_MISS) { > > - n = (rw & PAGE_WRITE) ? MMU_DTLB_MISS_WRITE : > > + n = (rw == 1) ? MMU_DTLB_MISS_WRITE : > > MMU_DTLB_MISS_READ; > > } > > } > > I think one more replace needed in get_mmu_address(), like following. > Isn't it? > > if (n >= 0) { > *physical = ((matching->ppn << 10) & ~(matching->size - 1)) | > (address & (matching->size - 1)); > - if ((rw & PAGE_WRITE) & !matching->d) > + if ((rw == 1) & !matching->d) > n = MMU_DTLB_INITIAL_WRITE; > else > n = MMU_OK; > > > > @@ -436,8 +434,12 @@ int get_physical_address(CPUState * env, target_ulong * physical, > > && (address < 0xe0000000 || address > 0xe4000000)) { > > /* Unauthorized access in user mode (only store queues are available) */ > > fprintf(stderr, "Unauthorized access\n"); > > - return (rw & PAGE_WRITE) ? MMU_DTLB_MISS_WRITE : > > - MMU_DTLB_MISS_READ; > > + if (rw == 0) > > + return MMU_DTLB_MISS_READ; > > + else if (rw == 1) > > + return MMU_DTLB_MISS_WRITE; > > + else > > + return MMU_ITLB_MISS; > > To be more precise, these cases should not invoke TLB miss error exceptions > but address error exceptions, whose exception codes are 0x0e0, or 0x100, I guess. > It might be another small patch. Yes, this is what written in the SH manual. I have fixed that in the patch I have just committed. -- .''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' aurel32@debian.org | aurelien@aurel32.net `- people.debian.org/~aurel32 | www.aurel32.net