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 | |
| 28 | .macro BEGIN func reg |
| 29 | $v = \reg |
| 30 | |
| 31 | ENTRY(atomic64_\func\()_386) |
| 32 | CFI_STARTPROC |
| 33 | LOCK $v |
| 34 | |
| 35 | .macro RETURN |
| 36 | UNLOCK $v |
| 37 | ret |
| 38 | .endm |
| 39 | |
| 40 | .macro END_ |
| 41 | CFI_ENDPROC |
| 42 | ENDPROC(atomic64_\func\()_386) |
| 43 | .purgem RETURN |
| 44 | .purgem END_ |
| 45 | .purgem END |
| 46 | .endm |
| 47 | |
| 48 | .macro END |
| 49 | RETURN |
| 50 | END_ |
| 51 | .endm |
| 52 | .endm |
| 53 | |
| 54 | BEGIN read %ecx |
| 55 | movl ($v), %eax |
| 56 | movl 4($v), %edx |
| 57 | END |
| 58 | |
| 59 | BEGIN set %esi |
| 60 | movl %ebx, ($v) |
| 61 | movl %ecx, 4($v) |
| 62 | END |
| 63 | |
| 64 | BEGIN xchg %esi |
| 65 | movl ($v), %eax |
| 66 | movl 4($v), %edx |
| 67 | movl %ebx, ($v) |
| 68 | movl %ecx, 4($v) |
| 69 | END |
| 70 | |
| 71 | BEGIN add %ecx |
| 72 | addl %eax, ($v) |
| 73 | adcl %edx, 4($v) |
| 74 | END |
| 75 | |
| 76 | BEGIN add_return %ecx |
| 77 | addl ($v), %eax |
| 78 | adcl 4($v), %edx |
| 79 | movl %eax, ($v) |
| 80 | movl %edx, 4($v) |
| 81 | END |
| 82 | |
| 83 | BEGIN sub %ecx |
| 84 | subl %eax, ($v) |
| 85 | sbbl %edx, 4($v) |
| 86 | END |
| 87 | |
| 88 | BEGIN sub_return %ecx |
| 89 | negl %edx |
| 90 | negl %eax |
| 91 | sbbl $0, %edx |
| 92 | addl ($v), %eax |
| 93 | adcl 4($v), %edx |
| 94 | movl %eax, ($v) |
| 95 | movl %edx, 4($v) |
| 96 | END |
| 97 | |
| 98 | BEGIN inc %esi |
| 99 | addl $1, ($v) |
| 100 | adcl $0, 4($v) |
| 101 | END |
| 102 | |
| 103 | BEGIN inc_return %esi |
| 104 | movl ($v), %eax |
| 105 | movl 4($v), %edx |
| 106 | addl $1, %eax |
| 107 | adcl $0, %edx |
| 108 | movl %eax, ($v) |
| 109 | movl %edx, 4($v) |
| 110 | END |
| 111 | |
| 112 | BEGIN dec %esi |
| 113 | subl $1, ($v) |
| 114 | sbbl $0, 4($v) |
| 115 | END |
| 116 | |
| 117 | BEGIN dec_return %esi |
| 118 | movl ($v), %eax |
| 119 | movl 4($v), %edx |
| 120 | subl $1, %eax |
| 121 | sbbl $0, %edx |
| 122 | movl %eax, ($v) |
| 123 | movl %edx, 4($v) |
| 124 | END |
| 125 | |
| 126 | BEGIN add_unless %ecx |
| 127 | addl %eax, %esi |
| 128 | adcl %edx, %edi |
| 129 | addl ($v), %eax |
| 130 | adcl 4($v), %edx |
| 131 | cmpl %eax, %esi |
| 132 | je 3f |
| 133 | 1: |
| 134 | movl %eax, ($v) |
| 135 | movl %edx, 4($v) |
Luca Barbieri | 6e6104f | 2010-03-01 19:55:46 +0100 | [diff] [blame] | 136 | movl $1, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 137 | 2: |
| 138 | RETURN |
| 139 | 3: |
| 140 | cmpl %edx, %edi |
| 141 | jne 1b |
Luca Barbieri | 6e6104f | 2010-03-01 19:55:46 +0100 | [diff] [blame] | 142 | xorl %eax, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 143 | jmp 2b |
| 144 | END_ |
| 145 | |
| 146 | BEGIN inc_not_zero %esi |
| 147 | movl ($v), %eax |
| 148 | movl 4($v), %edx |
| 149 | testl %eax, %eax |
| 150 | je 3f |
| 151 | 1: |
| 152 | addl $1, %eax |
| 153 | adcl $0, %edx |
| 154 | movl %eax, ($v) |
| 155 | movl %edx, 4($v) |
Luca Barbieri | f3e8313 | 2010-03-01 19:55:49 +0100 | [diff] [blame^] | 156 | movl $1, %eax |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 157 | 2: |
| 158 | RETURN |
| 159 | 3: |
| 160 | testl %edx, %edx |
| 161 | jne 1b |
Luca Barbieri | a7e926a | 2010-02-24 10:54:25 +0100 | [diff] [blame] | 162 | jmp 2b |
| 163 | END_ |
| 164 | |
| 165 | BEGIN dec_if_positive %esi |
| 166 | movl ($v), %eax |
| 167 | movl 4($v), %edx |
| 168 | subl $1, %eax |
| 169 | sbbl $0, %edx |
| 170 | js 1f |
| 171 | movl %eax, ($v) |
| 172 | movl %edx, 4($v) |
| 173 | 1: |
| 174 | END |