ticks.S 1.2 KB

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