ticks.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
  4. * base on code by
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <ppc_asm.tmpl>
  10. #include <ppc_defs.h>
  11. #include <config.h>
  12. #include <watchdog.h>
  13. /*
  14. * unsigned long long get_ticks(void);
  15. *
  16. * read timebase as "long long"
  17. */
  18. .globl get_ticks
  19. get_ticks:
  20. 1: mftbu r3
  21. mftb r4
  22. mftbu r5
  23. cmp 0,r3,r5
  24. bne 1b
  25. blr
  26. /*
  27. * Delay for a number of ticks
  28. */
  29. .globl wait_ticks
  30. wait_ticks:
  31. stwu r1, -16(r1)
  32. mflr r0 /* save link register */
  33. stw r0, 20(r1) /* Use r0 or GDB will be unhappy */
  34. stw r14, 12(r1) /* save used registers */
  35. stw r15, 8(r1)
  36. mr r14, r3 /* save tick count */
  37. bl get_ticks /* Get start time */
  38. /* Calculate end time */
  39. addc r14, r4, r14 /* Compute end time lower */
  40. addze r15, r3 /* and end time upper */
  41. WATCHDOG_RESET /* Trigger watchdog, if needed */
  42. 1: bl get_ticks /* Get current time */
  43. subfc r4, r4, r14 /* Subtract current time from end time */
  44. subfe. r3, r3, r15
  45. bge 1b /* Loop until time expired */
  46. lwz r15, 8(r1) /* restore saved registers */
  47. lwz r14, 12(r1)
  48. lwz r0, 20(r1)
  49. addi r1,r1,16
  50. mtlr r0
  51. blr