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