Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* rwsem.S: RW semaphore assembler. |
| 2 | * |
| 3 | * Written by David S. Miller (davem@redhat.com), 2001. |
| 4 | * Derived from asm-i386/rwsem.h |
| 5 | */ |
| 6 | |
| 7 | #include <asm/rwsem-const.h> |
| 8 | |
Sam Ravnborg | c6d64c1 | 2008-01-28 21:06:23 -0800 | [diff] [blame] | 9 | .section .sched.text, "ax" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
| 11 | .globl __down_read |
| 12 | __down_read: |
| 13 | 1: lduw [%o0], %g1 |
| 14 | add %g1, 1, %g7 |
| 15 | cas [%o0], %g1, %g7 |
| 16 | cmp %g1, %g7 |
| 17 | bne,pn %icc, 1b |
| 18 | add %g7, 1, %g7 |
| 19 | cmp %g7, 0 |
| 20 | bl,pn %icc, 3f |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 21 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | 2: |
| 23 | retl |
| 24 | nop |
| 25 | 3: |
| 26 | save %sp, -192, %sp |
| 27 | call rwsem_down_read_failed |
| 28 | mov %i0, %o0 |
| 29 | ret |
| 30 | restore |
| 31 | .size __down_read, .-__down_read |
| 32 | |
| 33 | .globl __down_read_trylock |
| 34 | __down_read_trylock: |
| 35 | 1: lduw [%o0], %g1 |
| 36 | add %g1, 1, %g7 |
| 37 | cmp %g7, 0 |
| 38 | bl,pn %icc, 2f |
| 39 | mov 0, %o1 |
| 40 | cas [%o0], %g1, %g7 |
| 41 | cmp %g1, %g7 |
| 42 | bne,pn %icc, 1b |
| 43 | mov 1, %o1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | 2: retl |
| 45 | mov %o1, %o0 |
| 46 | .size __down_read_trylock, .-__down_read_trylock |
| 47 | |
| 48 | .globl __down_write |
| 49 | __down_write: |
| 50 | sethi %hi(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 51 | or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 52 | 1: |
| 53 | lduw [%o0], %g3 |
| 54 | add %g3, %g1, %g7 |
| 55 | cas [%o0], %g3, %g7 |
| 56 | cmp %g3, %g7 |
| 57 | bne,pn %icc, 1b |
| 58 | cmp %g7, 0 |
| 59 | bne,pn %icc, 3f |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 60 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | 2: retl |
| 62 | nop |
| 63 | 3: |
| 64 | save %sp, -192, %sp |
| 65 | call rwsem_down_write_failed |
| 66 | mov %i0, %o0 |
| 67 | ret |
| 68 | restore |
| 69 | .size __down_write, .-__down_write |
| 70 | |
| 71 | .globl __down_write_trylock |
| 72 | __down_write_trylock: |
| 73 | sethi %hi(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 74 | or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 75 | 1: |
| 76 | lduw [%o0], %g3 |
| 77 | cmp %g3, 0 |
| 78 | bne,pn %icc, 2f |
| 79 | mov 0, %o1 |
| 80 | add %g3, %g1, %g7 |
| 81 | cas [%o0], %g3, %g7 |
| 82 | cmp %g3, %g7 |
| 83 | bne,pn %icc, 1b |
| 84 | mov 1, %o1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 2: retl |
| 86 | mov %o1, %o0 |
| 87 | .size __down_write_trylock, .-__down_write_trylock |
| 88 | |
| 89 | .globl __up_read |
| 90 | __up_read: |
| 91 | 1: |
| 92 | lduw [%o0], %g1 |
| 93 | sub %g1, 1, %g7 |
| 94 | cas [%o0], %g1, %g7 |
| 95 | cmp %g1, %g7 |
| 96 | bne,pn %icc, 1b |
| 97 | cmp %g7, 0 |
| 98 | bl,pn %icc, 3f |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 99 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | 2: retl |
| 101 | nop |
| 102 | 3: sethi %hi(RWSEM_ACTIVE_MASK), %g1 |
| 103 | sub %g7, 1, %g7 |
| 104 | or %g1, %lo(RWSEM_ACTIVE_MASK), %g1 |
| 105 | andcc %g7, %g1, %g0 |
| 106 | bne,pn %icc, 2b |
| 107 | nop |
| 108 | save %sp, -192, %sp |
| 109 | call rwsem_wake |
| 110 | mov %i0, %o0 |
| 111 | ret |
| 112 | restore |
| 113 | .size __up_read, .-__up_read |
| 114 | |
| 115 | .globl __up_write |
| 116 | __up_write: |
| 117 | sethi %hi(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 118 | or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1 |
| 119 | 1: |
| 120 | lduw [%o0], %g3 |
| 121 | sub %g3, %g1, %g7 |
| 122 | cas [%o0], %g3, %g7 |
| 123 | cmp %g3, %g7 |
| 124 | bne,pn %icc, 1b |
| 125 | sub %g7, %g1, %g7 |
| 126 | cmp %g7, 0 |
| 127 | bl,pn %icc, 3f |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 128 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | 2: |
| 130 | retl |
| 131 | nop |
| 132 | 3: |
| 133 | save %sp, -192, %sp |
| 134 | call rwsem_wake |
| 135 | mov %i0, %o0 |
| 136 | ret |
| 137 | restore |
| 138 | .size __up_write, .-__up_write |
| 139 | |
| 140 | .globl __downgrade_write |
| 141 | __downgrade_write: |
| 142 | sethi %hi(RWSEM_WAITING_BIAS), %g1 |
| 143 | or %g1, %lo(RWSEM_WAITING_BIAS), %g1 |
| 144 | 1: |
| 145 | lduw [%o0], %g3 |
| 146 | sub %g3, %g1, %g7 |
| 147 | cas [%o0], %g3, %g7 |
| 148 | cmp %g3, %g7 |
| 149 | bne,pn %icc, 1b |
| 150 | sub %g7, %g1, %g7 |
| 151 | cmp %g7, 0 |
| 152 | bl,pn %icc, 3f |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 153 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | 2: |
| 155 | retl |
| 156 | nop |
| 157 | 3: |
| 158 | save %sp, -192, %sp |
| 159 | call rwsem_downgrade_wake |
| 160 | mov %i0, %o0 |
| 161 | ret |
| 162 | restore |
| 163 | .size __downgrade_write, .-__downgrade_write |