test_ahb_arb_asm.S 848 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. This little bit of code is executed in-place by one CPU, but copied to a different memory region
  3. by the other CPU. Make sure it stays position-independent.
  4. */
  5. .text
  6. .align 4
  7. .global test_s32c1i_lock
  8. .type test_s32c1i_lock,@function
  9. //Args:
  10. //a2 - lock addr
  11. //a3 - val to lock with
  12. //a4 - val to unlock with
  13. //a5 - addr to increase
  14. test_s32c1i_lock:
  15. entry a1, 64
  16. wsr a4, SCOMPARE1
  17. lockloop:
  18. mov a6, a3
  19. s32c1i a6, a2, 0
  20. bne a4, a6, lockloop
  21. l32i a6, a5, 0
  22. //Give other CPU the time to mess up the inc if the lock somehow malfunctions
  23. nop
  24. nop
  25. nop
  26. nop
  27. nop
  28. nop
  29. nop
  30. nop
  31. nop
  32. nop
  33. nop
  34. nop
  35. nop
  36. nop
  37. nop
  38. nop
  39. addi a6, a6, 1
  40. s32i a6, a5, 0
  41. //No need to actually let this loop but hey, a hang indicates an error, right?
  42. wsr a3, SCOMPARE1
  43. unlockloop:
  44. mov a6, a4
  45. s32c1i a6, a2, 0
  46. bne a3, a6, unlockloop
  47. retw