David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 1 | /* bitops.S: Sparc64 atomic bit operations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 3 | * Copyright (C) 2000, 2007 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 6 | #include <linux/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <asm/asi.h> |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 8 | #include <asm/backoff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 10 | .text |
| 11 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 12 | ENTRY(test_and_set_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 13 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | srlx %o0, 6, %g1 |
| 15 | mov 1, %o2 |
| 16 | sllx %g1, 3, %g3 |
| 17 | and %o0, 63, %g2 |
| 18 | sllx %o2, %g2, %o2 |
| 19 | add %o1, %g3, %o1 |
| 20 | 1: ldx [%o1], %g7 |
| 21 | or %g7, %o2, %g1 |
| 22 | casx [%o1], %g7, %g1 |
| 23 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 24 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 27 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 29 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 30 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 31 | ENDPROC(test_and_set_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 33 | ENTRY(test_and_clear_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 34 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | srlx %o0, 6, %g1 |
| 36 | mov 1, %o2 |
| 37 | sllx %g1, 3, %g3 |
| 38 | and %o0, 63, %g2 |
| 39 | sllx %o2, %g2, %o2 |
| 40 | add %o1, %g3, %o1 |
| 41 | 1: ldx [%o1], %g7 |
| 42 | andn %g7, %o2, %g1 |
| 43 | casx [%o1], %g7, %g1 |
| 44 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 45 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 48 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 50 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 51 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 52 | ENDPROC(test_and_clear_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 54 | ENTRY(test_and_change_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 55 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | srlx %o0, 6, %g1 |
| 57 | mov 1, %o2 |
| 58 | sllx %g1, 3, %g3 |
| 59 | and %o0, 63, %g2 |
| 60 | sllx %o2, %g2, %o2 |
| 61 | add %o1, %g3, %o1 |
| 62 | 1: ldx [%o1], %g7 |
| 63 | xor %g7, %o2, %g1 |
| 64 | casx [%o1], %g7, %g1 |
| 65 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 66 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 69 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 71 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 72 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 73 | ENDPROC(test_and_change_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 75 | ENTRY(set_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 76 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | srlx %o0, 6, %g1 |
| 78 | mov 1, %o2 |
| 79 | sllx %g1, 3, %g3 |
| 80 | and %o0, 63, %g2 |
| 81 | sllx %o2, %g2, %o2 |
| 82 | add %o1, %g3, %o1 |
| 83 | 1: ldx [%o1], %g7 |
| 84 | or %g7, %o2, %g1 |
| 85 | casx [%o1], %g7, %g1 |
| 86 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 87 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | nop |
| 89 | retl |
| 90 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 91 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 92 | ENDPROC(set_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 94 | ENTRY(clear_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 95 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | srlx %o0, 6, %g1 |
| 97 | mov 1, %o2 |
| 98 | sllx %g1, 3, %g3 |
| 99 | and %o0, 63, %g2 |
| 100 | sllx %o2, %g2, %o2 |
| 101 | add %o1, %g3, %o1 |
| 102 | 1: ldx [%o1], %g7 |
| 103 | andn %g7, %o2, %g1 |
| 104 | casx [%o1], %g7, %g1 |
| 105 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 106 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | nop |
| 108 | retl |
| 109 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 110 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 111 | ENDPROC(clear_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 113 | ENTRY(change_bit) /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 114 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | srlx %o0, 6, %g1 |
| 116 | mov 1, %o2 |
| 117 | sllx %g1, 3, %g3 |
| 118 | and %o0, 63, %g2 |
| 119 | sllx %o2, %g2, %o2 |
| 120 | add %o1, %g3, %o1 |
| 121 | 1: ldx [%o1], %g7 |
| 122 | xor %g7, %o2, %g1 |
| 123 | casx [%o1], %g7, %g1 |
| 124 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 125 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | nop |
| 127 | retl |
| 128 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 129 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 130 | ENDPROC(change_bit) |