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