]> git.kernelconcepts.de Git - karo-tx-uboot.git/commit
mips: Use unsigned int when reading c0 registers
authorChris Packham <judge.packham@gmail.com>
Tue, 14 Jul 2015 10:54:41 +0000 (22:54 +1200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 08:30:32 +0000 (10:30 +0200)
commit3b22679a7601206e2a9f33afa52f8da884737809
treede8fb8ab0db64be814f46013f1cdfe5c23f71b73
parent16b5df66827d304e4801e3fd6b73891a20fe1a1b
mips: Use unsigned int when reading c0 registers

In commit a18a477 (MIPS: use common code from lib/time.c) MIPS platforms
started using common the common timer functions which are based around
the fact that many platforms have a 32-bit free running counter register
that can be used see commit 8dfafdd (Introduce common timer functions).

Even MIPS64 has such a 32-bit register (some have an additional 64-bit free
running counter, but that's something for another time).

The problem is that in __read_32bit_c0_register() we read the value from
this register into an _signed_ int and as it's returned up the call
chain to timer_read_counter() it gets assigned to an unsigned long. On a
32-bit system there is no problem. On a 64-bit system odd things happen,
sign extension seems to kick in and all of a sudden if the counter
register happens to have the MSb (i.e. the sign bit) set the negative
int gets sign extended into a very large unsigned long value. This in
turn throws out things from get_ticks() up.

Update __read_32bit_c0_register() and __read_32bit_c0_ctrl_register() to
use "unsigned int res;" instead of "int res;". There seems to be little
reason to treat these register values as signed. They are either
counters (which by definition are unsigned) or are made up of various
bit fields to be interpreted as per the CPU datasheet.

Reported-by: Sachin Surendran <sachin.surendran@alliedtelesis.co.nz>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
arch/mips/include/asm/mipsregs.h