1*a47a12beSStefan Roese/* 2*a47a12beSStefan Roese * (C) Copyright 2000, 2001 3*a47a12beSStefan Roese * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. 4*a47a12beSStefan Roese * base on code by 5*a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 6*a47a12beSStefan Roese * 7*a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 8*a47a12beSStefan Roese * project. 9*a47a12beSStefan Roese * 10*a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 11*a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 12*a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 13*a47a12beSStefan Roese * the License, or (at your option) any later version. 14*a47a12beSStefan Roese * 15*a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 16*a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*a47a12beSStefan Roese * GNU General Public License for more details. 19*a47a12beSStefan Roese * 20*a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 21*a47a12beSStefan Roese * along with this program; if not, write to the Free Software 22*a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 23*a47a12beSStefan Roese * MA 02111-1307 USA 24*a47a12beSStefan Roese */ 25*a47a12beSStefan Roese 26*a47a12beSStefan Roese#include <ppc_asm.tmpl> 27*a47a12beSStefan Roese#include <ppc_defs.h> 28*a47a12beSStefan Roese#include <config.h> 29*a47a12beSStefan Roese#include <watchdog.h> 30*a47a12beSStefan Roese 31*a47a12beSStefan Roese/* 32*a47a12beSStefan Roese * unsigned long long get_ticks(void); 33*a47a12beSStefan Roese * 34*a47a12beSStefan Roese * read timebase as "long long" 35*a47a12beSStefan Roese */ 36*a47a12beSStefan Roese .globl get_ticks 37*a47a12beSStefan Roeseget_ticks: 38*a47a12beSStefan Roese1: mftbu r3 39*a47a12beSStefan Roese mftb r4 40*a47a12beSStefan Roese mftbu r5 41*a47a12beSStefan Roese cmp 0,r3,r5 42*a47a12beSStefan Roese bne 1b 43*a47a12beSStefan Roese blr 44*a47a12beSStefan Roese 45*a47a12beSStefan Roese/* 46*a47a12beSStefan Roese * Delay for a number of ticks 47*a47a12beSStefan Roese */ 48*a47a12beSStefan Roese .globl wait_ticks 49*a47a12beSStefan Roesewait_ticks: 50*a47a12beSStefan Roese mflr r8 /* save link register */ 51*a47a12beSStefan Roese mr r7, r3 /* save tick count */ 52*a47a12beSStefan Roese bl get_ticks /* Get start time */ 53*a47a12beSStefan Roese 54*a47a12beSStefan Roese /* Calculate end time */ 55*a47a12beSStefan Roese addc r7, r4, r7 /* Compute end time lower */ 56*a47a12beSStefan Roese addze r6, r3 /* and end time upper */ 57*a47a12beSStefan Roese 58*a47a12beSStefan Roese WATCHDOG_RESET /* Trigger watchdog, if needed */ 59*a47a12beSStefan Roese1: bl get_ticks /* Get current time */ 60*a47a12beSStefan Roese subfc r4, r4, r7 /* Subtract current time from end time */ 61*a47a12beSStefan Roese subfe. r3, r3, r6 62*a47a12beSStefan Roese bge 1b /* Loop until time expired */ 63*a47a12beSStefan Roese 64*a47a12beSStefan Roese mtlr r8 /* restore link register */ 65*a47a12beSStefan Roese blr 66