/*1* atomic64_t for 386/4862*3* Copyright © 2010 Luca Barbieri4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*/1011#include <linux/linkage.h>12#include <asm/alternative-asm.h>13#include <asm/dwarf2.h>1415/* if you want SMP support, implement these with real spinlocks */16.macro LOCK reg17pushfl_cfi18cli19.endm2021.macro UNLOCK reg22popfl_cfi23.endm2425#define BEGIN(op) \26.macro endp; \27CFI_ENDPROC; \28ENDPROC(atomic64_##op##_386); \29.purgem endp; \30.endm; \31ENTRY(atomic64_##op##_386); \32CFI_STARTPROC; \33LOCK v;3435#define ENDP endp3637#define RET \38UNLOCK v; \39ret4041#define RET_ENDP \42RET; \43ENDP4445#define v %ecx46BEGIN(read)47movl (v), %eax48movl 4(v), %edx49RET_ENDP50#undef v5152#define v %esi53BEGIN(set)54movl %ebx, (v)55movl %ecx, 4(v)56RET_ENDP57#undef v5859#define v %esi60BEGIN(xchg)61movl (v), %eax62movl 4(v), %edx63movl %ebx, (v)64movl %ecx, 4(v)65RET_ENDP66#undef v6768#define v %ecx69BEGIN(add)70addl %eax, (v)71adcl %edx, 4(v)72RET_ENDP73#undef v7475#define v %ecx76BEGIN(add_return)77addl (v), %eax78adcl 4(v), %edx79movl %eax, (v)80movl %edx, 4(v)81RET_ENDP82#undef v8384#define v %ecx85BEGIN(sub)86subl %eax, (v)87sbbl %edx, 4(v)88RET_ENDP89#undef v9091#define v %ecx92BEGIN(sub_return)93negl %edx94negl %eax95sbbl $0, %edx96addl (v), %eax97adcl 4(v), %edx98movl %eax, (v)99movl %edx, 4(v)100RET_ENDP101#undef v102103#define v %esi104BEGIN(inc)105addl $1, (v)106adcl $0, 4(v)107RET_ENDP108#undef v109110#define v %esi111BEGIN(inc_return)112movl (v), %eax113movl 4(v), %edx114addl $1, %eax115adcl $0, %edx116movl %eax, (v)117movl %edx, 4(v)118RET_ENDP119#undef v120121#define v %esi122BEGIN(dec)123subl $1, (v)124sbbl $0, 4(v)125RET_ENDP126#undef v127128#define v %esi129BEGIN(dec_return)130movl (v), %eax131movl 4(v), %edx132subl $1, %eax133sbbl $0, %edx134movl %eax, (v)135movl %edx, 4(v)136RET_ENDP137#undef v138139#define v %ecx140BEGIN(add_unless)141addl %eax, %esi142adcl %edx, %edi143addl (v), %eax144adcl 4(v), %edx145cmpl %eax, %esi146je 3f1471:148movl %eax, (v)149movl %edx, 4(v)150movl $1, %eax1512:152RET1533:154cmpl %edx, %edi155jne 1b156xorl %eax, %eax157jmp 2b158ENDP159#undef v160161#define v %esi162BEGIN(inc_not_zero)163movl (v), %eax164movl 4(v), %edx165testl %eax, %eax166je 3f1671:168addl $1, %eax169adcl $0, %edx170movl %eax, (v)171movl %edx, 4(v)172movl $1, %eax1732:174RET1753:176testl %edx, %edx177jne 1b178jmp 2b179ENDP180#undef v181182#define v %esi183BEGIN(dec_if_positive)184movl (v), %eax185movl 4(v), %edx186subl $1, %eax187sbbl $0, %edx188js 1f189movl %eax, (v)190movl %edx, 4(v)1911:192RET_ENDP193#undef v194195196