From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9ni1-00032u-Le for qemu-devel@nongnu.org; Tue, 30 Jun 2015 01:03:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9nhx-0001kF-K4 for qemu-devel@nongnu.org; Tue, 30 Jun 2015 01:03:49 -0400 Received: from mail-yk0-f177.google.com ([209.85.160.177]:36626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9nhx-0001kB-Fe for qemu-devel@nongnu.org; Tue, 30 Jun 2015 01:03:45 -0400 Received: by ykdr198 with SMTP id r198so134139383ykd.3 for ; Mon, 29 Jun 2015 22:03:44 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 29 Jun 2015 22:03:44 -0700 Message-ID: From: Serge Vakulenko Content-Type: text/plain; charset=UTF-8 Subject: [Qemu-devel] [PATCH pic32 3/7] Fixed random index generation for TLBWR instruction. It was not quite random and did not skip Wired entries. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Leon Alrae , Aurelien Jarno Signed-off-by: Serge Vakulenko --- hw/mips/cputimer.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/hw/mips/cputimer.c b/hw/mips/cputimer.c index 3d23c1b..ec0cffa 100644 --- a/hw/mips/cputimer.c +++ b/hw/mips/cputimer.c @@ -25,21 +25,13 @@ #include "qemu/timer.h" #include "sysemu/kvm.h" -#define TIMER_FREQ 100 * 1000 * 1000 - -/* XXX: do not use a global */ +/* Generate a random TLB index. + * Skip wired entries. */ uint32_t cpu_mips_get_random (CPUMIPSState *env) { - static uint32_t lfsr = 1; - static uint32_t prev_idx = 0; - uint32_t idx; - /* Don't return same value twice, so get another value */ - do { - lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xd0000001u); - idx = lfsr % (env->tlb->nb_tlb - env->CP0_Wired) + env->CP0_Wired; - } while (idx == prev_idx); - prev_idx = idx; - return idx; + env->CP0_Random = env->CP0_Wired + + random() % (env->tlb->nb_tlb - env->CP0_Wired); + return env->CP0_Random; } /* MIPS R4K timer */ -- 1.9.1