Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * atomic64_t for 386/486 |
| 3 | * |
| 4 | * Copyright © 2010 Luca Barbieri |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/linkage.h> |
| 13 | #include <asm/alternative-asm.h> |
| 14 | #include <asm/dwarf2.h> |
| 15 | |
| 16 | /* if you want SMP support, implement these with real spinlocks */ |
| 17 | .macro LOCK reg |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 18 | pushfl_cfi |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 19 | cli |
| 20 | .endm |
| 21 | |
| 22 | .macro UNLOCK reg |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 23 | popfl_cfi |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 24 | .endm |
| 25 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 26 | #define BEGIN(op) \ |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 27 | .macro endp; \ |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 28 | CFI_ENDPROC; \ |
| 29 | ENDPROC(atomic64_##op##_386); \ |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 30 | .purgem endp; \ |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 31 | .endm; \ |
| 32 | ENTRY(atomic64_##op##_386); \ |
| 33 | CFI_STARTPROC; \ |
| 34 | LOCK v; |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 35 | |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 36 | #define ENDP endp |
| 37 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 38 | #define RET \ |
| 39 | UNLOCK v; \ |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 40 | ret |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 41 | |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 42 | #define RET_ENDP \ |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 43 | RET; \ |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 44 | ENDP |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 45 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 46 | #define v %ecx |
| 47 | BEGIN(read) |
| 48 | movl (v), %eax |
| 49 | movl 4(v), %edx |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 50 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 51 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 52 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 53 | #define v %esi |
| 54 | BEGIN(set) |
| 55 | movl %ebx, (v) |
| 56 | movl %ecx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 57 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 58 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 59 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 60 | #define v %esi |
| 61 | BEGIN(xchg) |
| 62 | movl (v), %eax |
| 63 | movl 4(v), %edx |
| 64 | movl %ebx, (v) |
| 65 | movl %ecx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 66 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 67 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 68 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 69 | #define v %ecx |
| 70 | BEGIN(add) |
| 71 | addl %eax, (v) |
| 72 | adcl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 73 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 74 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 75 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 76 | #define v %ecx |
| 77 | BEGIN(add_return) |
| 78 | addl (v), %eax |
| 79 | adcl 4(v), %edx |
| 80 | movl %eax, (v) |
| 81 | movl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 82 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 83 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 84 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 85 | #define v %ecx |
| 86 | BEGIN(sub) |
| 87 | subl %eax, (v) |
| 88 | sbbl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 89 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 90 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 91 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 92 | #define v %ecx |
| 93 | BEGIN(sub_return) |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 94 | negl %edx |
| 95 | negl %eax |
| 96 | sbbl $0, %edx |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 97 | addl (v), %eax |
| 98 | adcl 4(v), %edx |
| 99 | movl %eax, (v) |
| 100 | movl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 101 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 102 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 103 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 104 | #define v %esi |
| 105 | BEGIN(inc) |
| 106 | addl $1, (v) |
| 107 | adcl $0, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 108 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 109 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 110 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 111 | #define v %esi |
| 112 | BEGIN(inc_return) |
| 113 | movl (v), %eax |
| 114 | movl 4(v), %edx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 115 | addl $1, %eax |
| 116 | adcl $0, %edx |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 117 | movl %eax, (v) |
| 118 | movl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 119 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 120 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 121 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 122 | #define v %esi |
| 123 | BEGIN(dec) |
| 124 | subl $1, (v) |
| 125 | sbbl $0, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 126 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 127 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 128 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 129 | #define v %esi |
| 130 | BEGIN(dec_return) |
| 131 | movl (v), %eax |
| 132 | movl 4(v), %edx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 133 | subl $1, %eax |
| 134 | sbbl $0, %edx |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 135 | movl %eax, (v) |
| 136 | movl %edx, 4(v) |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 137 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 138 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 139 | |
Jan Beulich | cb8095b | 2012-01-20 16:22:04 +0000 | [diff] [blame] | 140 | #define v %esi |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 141 | BEGIN(add_unless) |
Jan Beulich | cb8095b | 2012-01-20 16:22:04 +0000 | [diff] [blame] | 142 | addl %eax, %ecx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 143 | adcl %edx, %edi |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 144 | addl (v), %eax |
| 145 | adcl 4(v), %edx |
Jan Beulich | cb8095b | 2012-01-20 16:22:04 +0000 | [diff] [blame] | 146 | cmpl %eax, %ecx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 147 | je 3f |
| 148 | 1: |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 149 | movl %eax, (v) |
| 150 | movl %edx, 4(v) |
Luca Barbieri | 6e6104f | 2010-03-01 19:55:46 +0100 | [diff] [blame] | 151 | movl $1, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 152 | 2: |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 153 | RET |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 154 | 3: |
| 155 | cmpl %edx, %edi |
| 156 | jne 1b |
Luca Barbieri | 6e6104f | 2010-03-01 19:55:46 +0100 | [diff] [blame] | 157 | xorl %eax, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 158 | jmp 2b |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 159 | ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 160 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 161 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 162 | #define v %esi |
| 163 | BEGIN(inc_not_zero) |
| 164 | movl (v), %eax |
| 165 | movl 4(v), %edx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 166 | testl %eax, %eax |
| 167 | je 3f |
| 168 | 1: |
| 169 | addl $1, %eax |
| 170 | adcl $0, %edx |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 171 | movl %eax, (v) |
| 172 | movl %edx, 4(v) |
Luca Barbieri | f3e8313 | 2010-03-01 19:55:49 +0100 | [diff] [blame] | 173 | movl $1, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 174 | 2: |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 175 | RET |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 176 | 3: |
| 177 | testl %edx, %edx |
| 178 | jne 1b |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 179 | jmp 2b |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 180 | ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 181 | #undef v |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 182 | |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 183 | #define v %esi |
| 184 | BEGIN(dec_if_positive) |
| 185 | movl (v), %eax |
| 186 | movl 4(v), %edx |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 187 | subl $1, %eax |
| 188 | sbbl $0, %edx |
| 189 | js 1f |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 190 | movl %eax, (v) |
| 191 | movl %edx, 4(v) |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 192 | 1: |
Luca Barbieri | 417484d | 2010-08-12 07:00:35 -0700 | [diff] [blame] | 193 | RET_ENDP |
Luca Barbieri | 3024655 | 2010-08-06 04:04:38 +0200 | [diff] [blame] | 194 | #undef v |