From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JvCXK-00058Z-P6 for qemu-devel@nongnu.org; Sun, 11 May 2008 10:28:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JvCXI-00057Q-LF for qemu-devel@nongnu.org; Sun, 11 May 2008 10:28:26 -0400 Received: from [199.232.76.173] (port=47678 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JvCXI-00057J-Ci for qemu-devel@nongnu.org; Sun, 11 May 2008 10:28:24 -0400 Received: from savannah.gnu.org ([199.232.41.3]:33683 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JvCXI-00038i-CN for qemu-devel@nongnu.org; Sun, 11 May 2008 10:28:24 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1JvCXE-0007Mv-PA for qemu-devel@nongnu.org; Sun, 11 May 2008 14:28:21 +0000 Received: from edgar_igl by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1JvCXC-0007MX-3A for qemu-devel@nongnu.org; Sun, 11 May 2008 14:28:19 +0000 MIME-Version: 1.0 Errors-To: edgar_igl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: "Edgar E. Iglesias" Message-Id: Date: Sun, 11 May 2008 14:28:18 +0000 Subject: [Qemu-devel] [4425] CRIS: Add support for the pseudo randomized set that the mmu provides with TLB refill faults . 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 Revision: 4425 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4425 Author: edgar_igl Date: 2008-05-11 14:28:14 +0000 (Sun, 11 May 2008) Log Message: ----------- CRIS: Add support for the pseudo randomized set that the mmu provides with TLB refill faults. This makes linux guests use the four way TLB set associativty. Modified Paths: -------------- trunk/target-cris/cpu.h trunk/target-cris/mmu.c Modified: trunk/target-cris/cpu.h =================================================================== --- trunk/target-cris/cpu.h 2008-05-11 12:22:01 UTC (rev 4424) +++ trunk/target-cris/cpu.h 2008-05-11 14:28:14 UTC (rev 4425) @@ -153,6 +153,11 @@ */ uint32_t sregs[4][16]; + /* Linear feedback shift reg in the mmu. Used to provide pseudo + randomness for the 'hint' the mmu gives to sw for chosing valid + sets on TLB refills. */ + uint32_t mmu_rand_lfsr; + /* * We just store the stores to the tlbset here for later evaluation * when the hw needs access to them. Modified: trunk/target-cris/mmu.c =================================================================== --- trunk/target-cris/mmu.c 2008-05-11 12:22:01 UTC (rev 4424) +++ trunk/target-cris/mmu.c 2008-05-11 14:28:14 UTC (rev 4425) @@ -32,6 +32,24 @@ #define D(x) +void cris_mmu_init(CPUState *env) +{ + env->mmu_rand_lfsr = 0xcccc; +} + +#define SR_POLYNOM 0x8805 +static inline unsigned int compute_polynom(unsigned int sr) +{ + unsigned int i; + unsigned int f; + + f = 0; + for (i = 0; i < 16; i++) + f += ((SR_POLYNOM >> i) & 1) & ((sr >> i) & 1); + + return f; +} + static inline int cris_mmu_enabled(uint32_t rw_gc_cfg) { return (rw_gc_cfg & 12) != 0; @@ -152,11 +170,14 @@ hi = env->tlbsets[mmu][set][idx].hi; tlb_vpn = EXTRACT_FIELD(hi, 13, 31); + tlb_pid = EXTRACT_FIELD(hi, 0, 7); tlb_pfn = EXTRACT_FIELD(lo, 13, 31); + tlb_g = EXTRACT_FIELD(lo, 4, 4); D(printf("TLB[%d][%d] v=%x vpage=%x -> pfn=%x lo=%x hi=%x\n", i, idx, tlb_vpn, vpage, tlb_pfn, lo, hi)); - if (tlb_vpn == vpage) { + if ((tlb_g || (tlb_pid == (env->pregs[PR_PID] & 0xff))) + && tlb_vpn == vpage) { match = 1; break; } @@ -169,9 +190,7 @@ cfg_x = EXTRACT_FIELD(r_cfg, 17, 17); cfg_v = EXTRACT_FIELD(r_cfg, 16, 16); - tlb_pid = EXTRACT_FIELD(hi, 0, 7); tlb_pfn = EXTRACT_FIELD(lo, 13, 31); - tlb_g = EXTRACT_FIELD(lo, 4, 4); tlb_v = EXTRACT_FIELD(lo, 3, 3); tlb_k = EXTRACT_FIELD(lo, 2, 2); tlb_w = EXTRACT_FIELD(lo, 1, 1); @@ -187,13 +206,7 @@ set_exception_vector(0x0a, d_mmu_access); set_exception_vector(0x0b, d_mmu_write); */ - if (!tlb_g - && tlb_pid != (env->pregs[PR_PID] & 0xff)) { - D(printf ("tlb: wrong pid %x %x pc=%x\n", - tlb_pid, env->pregs[PR_PID], env->pc)); - match = 0; - res->bf_vec = vect_base; - } else if (cfg_k && tlb_k && usermode) { + if (cfg_k && tlb_k && usermode) { D(printf ("tlb: kernel protected %x lo=%x pc=%x\n", vaddr, lo, env->pc)); match = 0; @@ -229,17 +242,27 @@ env->sregs[SFR_RW_MM_TLB_HI] = hi; env->sregs[SFR_RW_MM_TLB_LO] = lo; + } else { + /* If refill, provide a randomized set. */ + set = env->mmu_rand_lfsr & 3; } if (!match) { - /* miss. */ + unsigned int f; + + /* Update lfsr at every fault. */ + f = compute_polynom(env->mmu_rand_lfsr); + env->mmu_rand_lfsr >>= 1; + env->mmu_rand_lfsr |= (f << 15); + env->mmu_rand_lfsr &= 0xffff; + + /* Compute index. */ idx = vpage & 15; - set = 0; /* Update RW_MM_TLB_SEL. */ env->sregs[SFR_RW_MM_TLB_SEL] = 0; set_field(&env->sregs[SFR_RW_MM_TLB_SEL], idx, 0, 4); - set_field(&env->sregs[SFR_RW_MM_TLB_SEL], set, 4, 5); + set_field(&env->sregs[SFR_RW_MM_TLB_SEL], set, 4, 2); /* Update RW_MM_CAUSE. */ set_field(&r_cause, rwcause, 8, 2);