From patchwork Wed Jul 8 05:38:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 492731 X-Patchwork-Delegate: daniel.schwierzeck@googlemail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B7C721401AF for ; Wed, 8 Jul 2015 15:38:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=SomISHf1; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0CCB14B9B5; Wed, 8 Jul 2015 07:38:38 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LlHoQ2aJdQrK; Wed, 8 Jul 2015 07:38:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 934EF4B95C; Wed, 8 Jul 2015 07:38:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5B3084B9CC for ; Wed, 8 Jul 2015 07:38:35 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fucLPkSqGACU for ; Wed, 8 Jul 2015 07:38:35 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by theia.denx.de (Postfix) with ESMTPS id 45C504B9BC for ; Wed, 8 Jul 2015 07:38:29 +0200 (CEST) Received: by pdbdz6 with SMTP id dz6so44498138pdb.0 for ; Tue, 07 Jul 2015 22:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OQgCef+EBm/1w2LCAloWrC740KCwl6KZ7R+sV6PJ9xw=; b=SomISHf1AZh0ALkn369ofulBdo4X+34BmMl6TWeDV9UTKhVpAhpK8cZBncoZNUSlrX 83P2nU/sWTvh33gz+mMtMn/XwoYrVcz7h2DCp9fECHsLgjRcRr5kToRJDT7C+CMf8PG7 r09UQv13ga1TarV5nZtvjMvjgPDYSw/lAvbc0dHRknX0NfRMr+CO0HGLy2Z+D90elQik /smGKFqUGf3JLiD6+H0QnHpnXh8XNLxlq2HoSIlNj9OjJNrqeRogD9i+PrCTHBewEokj 3ArRpFlvnDV7/LfTyk4Dj55OSYsPd5iC4MAB7xqBVPlzACKqsMaH5aIFbTiPD2I+KYbI S9LA== X-Received: by 10.66.181.197 with SMTP id dy5mr16605964pac.87.1436333907950; Tue, 07 Jul 2015 22:38:27 -0700 (PDT) Received: from chrisp-dl.ws.atlnz.lc (2-163-36-202-static.alliedtelesis.co.nz. [202.36.163.2]) by smtp.gmail.com with ESMTPSA id cu8sm1000725pad.1.2015.07.07.22.38.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jul 2015 22:38:27 -0700 (PDT) From: Chris Packham To: u-boot@lists.denx.de Date: Wed, 8 Jul 2015 17:38:06 +1200 Message-Id: <1436333886-1047-2-git-send-email-judge.packham@gmail.com> X-Mailer: git-send-email 2.5.0.rc0 In-Reply-To: <1436333886-1047-1-git-send-email-judge.packham@gmail.com> References: <1436333886-1047-1-git-send-email-judge.packham@gmail.com> Cc: Tom Rini , Rob Herring , Thomas Langer , Sachin Surendran , Chris Packham Subject: [U-Boot] [RFC PATCH v1] mips: Use unsigned int when reading c0 registers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Signed-off-by: Chris Packham --- arch/mips/include/asm/mipsregs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h index 3571e4f..c7a0849 100644 --- a/arch/mips/include/asm/mipsregs.h +++ b/arch/mips/include/asm/mipsregs.h @@ -594,7 +594,7 @@ do { \ */ #define __read_32bit_c0_register(source, sel) \ -({ int __res; \ +({ unsigned int __res; \ if (sel == 0) \ __asm__ __volatile__( \ "mfc0\t%0, " #source "\n\t" \ @@ -676,7 +676,7 @@ do { \ * On RM7000/RM9000 these are uses to access cop0 set 1 registers */ #define __read_32bit_c0_ctrl_register(source) \ -({ int __res; \ +({ unsigned int __res; \ __asm__ __volatile__( \ "cfc0\t%0, " #source "\n\t" \ : "=r" (__res)); \