summary refs log tree commit diff stats
path: root/hw/mips/cputimer.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2015-09-18 12:55:27 +0100
committerPeter Maydell <peter.maydell@linaro.org>2015-09-18 12:55:27 +0100
commit3bf1f5ec6a7ec8ee06c95bf308d213ebaa129ee0 (patch)
tree30c2e51a383243a8d135465729a43b0c2745d94f /hw/mips/cputimer.c
parent16a1b6e97c2a2919fd296db4bea2f9da2ad3cc4d (diff)
parent9c708c7f9fbb813a3fac02f2728e51e62f2f5ffc (diff)
downloadfocaccia-qemu-3bf1f5ec6a7ec8ee06c95bf308d213ebaa129ee0.tar.gz
focaccia-qemu-3bf1f5ec6a7ec8ee06c95bf308d213ebaa129ee0.zip
Merge remote-tracking branch 'remotes/lalrae/tags/mips-20150918' into staging
MIPS patches 2015-09-18

Changes:
* fixes for rdhwr, tlbwr, mtc0, recip.fmt, rsqrt.fmt and daui instructions
* removal of MIPS_DEBUG code
* use tcg_gen_extrh_i64_i32()
* improve random tlb index generation in cpu_mips_get_random()
* exception handling improvements to correctly restore icount

# gpg: Signature made Fri 18 Sep 2015 12:15:28 BST using RSA key ID 0B29DA6B
# gpg: Good signature from "Leon Alrae <leon.alrae@imgtec.com>"

* remotes/lalrae/tags/mips-20150918:
  target-mips: improve exception handling
  target-mips: correct MTC0 instruction on MIPS64
  target-mips: add missing restriction in DAUI instruction
  target-mips: fix corner case in TLBWR causing QEMU to hang
  pic32: use LCG algorithm for generated random index of TLBWR instruction
  target-mips: get rid of MIPS_DEBUG_SIGN_EXTENSIONS
  target-mips: get rid of MIPS_DEBUG
  target-mips: Fix RDHWR on CP0.Count
  target-mips: remove wrong checks for recip.fmt and rsqrt.fmt
  target-mips: Use tcg_gen_extrh_i64_i32

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/mips/cputimer.c')
-rw-r--r--hw/mips/cputimer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/hw/mips/cputimer.c b/hw/mips/cputimer.c
index 577c9aeab8..ba9264b415 100644
--- a/hw/mips/cputimer.c
+++ b/hw/mips/cputimer.c
@@ -30,13 +30,21 @@
 /* XXX: do not use a global */
 uint32_t cpu_mips_get_random (CPUMIPSState *env)
 {
-    static uint32_t lfsr = 1;
+    static uint32_t seed = 1;
     static uint32_t prev_idx = 0;
     uint32_t idx;
+    uint32_t nb_rand_tlb = env->tlb->nb_tlb - env->CP0_Wired;
+
+    if (nb_rand_tlb == 1) {
+        return env->tlb->nb_tlb - 1;
+    }
+
     /* 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;
+        /* Use a simple algorithm of Linear Congruential Generator
+         * from ISO/IEC 9899 standard. */
+        seed = 1103515245 * seed + 12345;
+        idx = (seed >> 16) % nb_rand_tlb + env->CP0_Wired;
     } while (idx == prev_idx);
     prev_idx = idx;
     return idx;