From patchwork Thu Jan 24 15:25:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mats_K=C3=A4rrman?= X-Patchwork-Id: 215365 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 952822C0084 for ; Fri, 25 Jan 2013 02:25:51 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3AE234A092; Thu, 24 Jan 2013 16:25:49 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 iw2pmp3qzEfa; Thu, 24 Jan 2013 16:25:49 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5A8974A098; Thu, 24 Jan 2013 16:25:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5B3C14A098 for ; Thu, 24 Jan 2013 16:25:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 1-fVoHLvZ6mj for ; Thu, 24 Jan 2013 16:25:43 +0100 (CET) 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 tritech.se (tritech.se [46.59.120.190]) by theia.denx.de (Postfix) with ESMTP id 68A5E4A092 for ; Thu, 24 Jan 2013 16:25:41 +0100 (CET) Received: from post.tritech.se (post.tritech.se [10.75.60.100]) by tritech.se (8.14.3/8.14.3) with ESMTP id r0OFPalj013901 for ; Thu, 24 Jan 2013 16:25:41 +0100 Received: from POST.tritech.se ([fe80::b4fc:968e:bbef:54cb]) by post.tritech.se ([fe80::b4fc:968e:bbef:54cb%10]) with mapi id 14.02.0318.001; Thu, 24 Jan 2013 16:25:36 +0100 From: =?iso-8859-1?Q?Mats_K=E4rrman?= To: "u-boot@lists.denx.de" Thread-Topic: [RFC] powerpc/lib: unsafe register handling in wait_ticks Thread-Index: Ac36RSOLE2bA3qOcQ/GfzVsKq7OaaQ== Date: Thu, 24 Jan 2013 15:25:35 +0000 Message-ID: Accept-Language: en-US, sv-SE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [194.132.137.82] MIME-Version: 1.0 Subject: [U-Boot] [RFC] powerpc/lib: unsafe register handling in wait_ticks X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hi, If watchdog is enabled, the arch/powerpc/lib/ticks.S::wait_ticks() function calls the function specified by the WATCHDOG_RESET macro. The wait_ticks function depends on the registers r0, r6 and r7 being preserved however that is not guaranteed if the reset function is a C function. The following patch changes to using r14+r15 instead of r6+r7 and saves all necessary registers on the stack. As I'm quite fresh to PowerPC assembly language I would appreciate any feedback on the implementation. On a side note, one could wonder why this function is not written in C language to start with. Best regards, Mats Kärrman Acked-by: Joakim Tjernlund --- a/arch/powerpc/lib/ticks.S +++ b/arch/powerpc/lib/ticks.S @@ -50,19 +50,24 @@ wait_ticks: stwu r1, -16(r1) mflr r0 /* save link register */ stw r0, 20(r1) /* Use r0 or GDB will be unhappy */ - mr r7, r3 /* save tick count */ + stw r14, 12(r1) /* save used registers */ + stw r15, 8(r1) + mr r14, r3 /* save tick count */ bl get_ticks /* Get start time */ /* Calculate end time */ - addc r7, r4, r7 /* Compute end time lower */ - addze r6, r3 /* and end time upper */ + addc r14, r4, r14 /* Compute end time lower */ + addze r15, r3 /* and end time upper */ WATCHDOG_RESET /* Trigger watchdog, if needed */ 1: bl get_ticks /* Get current time */ - subfc r4, r4, r7 /* Subtract current time from end time */ - subfe. r3, r3, r6 + subfc r4, r4, r14 /* Subtract current time from end time */ + subfe. r3, r3, r15 bge 1b /* Loop until time expired */ - mtlr r0 /* restore link register */ + lwz r15, 8(r1) /* restore saved registers */ + lwz r14, 12(r1) + lwz r0, 20(r1) addi r1,r1,16 + mtlr r0 blr