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