bitops.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #if __LINUX_ARM_ARCH__ >= 6
  2. .macro bitop, instr
  3. ands ip, r1, #3
  4. strneb r1, [ip] @ assert word-aligned
  5. mov r2, #1
  6. and r3, r0, #31 @ Get bit offset
  7. mov r0, r0, lsr #5
  8. add r1, r1, r0, lsl #2 @ Get word offset
  9. mov r3, r2, lsl r3
  10. 1: ldrex r2, [r1]
  11. \instr r2, r2, r3
  12. strex r0, r2, [r1]
  13. cmp r0, #0
  14. bne 1b
  15. bx lr
  16. .endm
  17. .macro testop, instr, store
  18. ands ip, r1, #3
  19. strneb r1, [ip] @ assert word-aligned
  20. mov r2, #1
  21. and r3, r0, #31 @ Get bit offset
  22. mov r0, r0, lsr #5
  23. add r1, r1, r0, lsl #2 @ Get word offset
  24. mov r3, r2, lsl r3 @ create mask
  25. smp_dmb
  26. 1: ldrex r2, [r1]
  27. ands r0, r2, r3 @ save old value of bit
  28. \instr r2, r2, r3 @ toggle bit
  29. strex ip, r2, [r1]
  30. cmp ip, #0
  31. bne 1b
  32. smp_dmb
  33. cmp r0, #0
  34. movne r0, #1
  35. 2: bx lr
  36. .endm
  37. #else
  38. .macro bitop, instr
  39. ands ip, r1, #3
  40. strneb r1, [ip] @ assert word-aligned
  41. and r2, r0, #31
  42. mov r0, r0, lsr #5
  43. mov r3, #1
  44. mov r3, r3, lsl r2
  45. save_and_disable_irqs ip
  46. ldr r2, [r1, r0, lsl #2]
  47. \instr r2, r2, r3
  48. str r2, [r1, r0, lsl #2]
  49. restore_irqs ip
  50. mov pc, lr
  51. .endm
  52. /**
  53. * testop - implement a test_and_xxx_bit operation.
  54. * @instr: operational instruction
  55. * @store: store instruction
  56. *
  57. * Note: we can trivially conditionalise the store instruction
  58. * to avoid dirtying the data cache.
  59. */
  60. .macro testop, instr, store
  61. ands ip, r1, #3
  62. strneb r1, [ip] @ assert word-aligned
  63. and r3, r0, #31
  64. mov r0, r0, lsr #5
  65. save_and_disable_irqs ip
  66. ldr r2, [r1, r0, lsl #2]!
  67. mov r0, #1
  68. tst r2, r0, lsl r3
  69. \instr r2, r2, r0, lsl r3
  70. \store r2, [r1]
  71. moveq r0, #0
  72. restore_irqs ip
  73. mov pc, lr
  74. .endm
  75. #endif