bitops.h 1.9 KB

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