2010-02-24 17:54:25 +08:00
|
|
|
/*
|
|
|
|
* atomic64_t for 386/486
|
|
|
|
*
|
|
|
|
* Copyright © 2010 Luca Barbieri
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <asm/alternative-asm.h>
|
|
|
|
#include <asm/dwarf2.h>
|
|
|
|
|
|
|
|
/* if you want SMP support, implement these with real spinlocks */
|
|
|
|
.macro LOCK reg
|
|
|
|
pushfl
|
|
|
|
CFI_ADJUST_CFA_OFFSET 4
|
|
|
|
cli
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro UNLOCK reg
|
|
|
|
popfl
|
|
|
|
CFI_ADJUST_CFA_OFFSET -4
|
|
|
|
.endm
|
|
|
|
|
2010-08-06 10:04:38 +08:00
|
|
|
#define BEGIN(op) \
|
|
|
|
.macro END; \
|
|
|
|
CFI_ENDPROC; \
|
|
|
|
ENDPROC(atomic64_##op##_386); \
|
|
|
|
.purgem END; \
|
|
|
|
.endm; \
|
|
|
|
ENTRY(atomic64_##op##_386); \
|
|
|
|
CFI_STARTPROC; \
|
|
|
|
LOCK v;
|
|
|
|
|
|
|
|
#define RET \
|
|
|
|
UNLOCK v; \
|
2010-02-24 17:54:25 +08:00
|
|
|
ret
|
|
|
|
|
2010-08-06 10:04:38 +08:00
|
|
|
#define RET_END \
|
|
|
|
RET; \
|
|
|
|
END
|
|
|
|
|
|
|
|
#define v %ecx
|
|
|
|
BEGIN(read)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(set)
|
|
|
|
movl %ebx, (v)
|
|
|
|
movl %ecx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(xchg)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
|
|
|
movl %ebx, (v)
|
|
|
|
movl %ecx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %ecx
|
|
|
|
BEGIN(add)
|
|
|
|
addl %eax, (v)
|
|
|
|
adcl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %ecx
|
|
|
|
BEGIN(add_return)
|
|
|
|
addl (v), %eax
|
|
|
|
adcl 4(v), %edx
|
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %ecx
|
|
|
|
BEGIN(sub)
|
|
|
|
subl %eax, (v)
|
|
|
|
sbbl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %ecx
|
|
|
|
BEGIN(sub_return)
|
2010-02-24 17:54:25 +08:00
|
|
|
negl %edx
|
|
|
|
negl %eax
|
|
|
|
sbbl $0, %edx
|
2010-08-06 10:04:38 +08:00
|
|
|
addl (v), %eax
|
|
|
|
adcl 4(v), %edx
|
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(inc)
|
|
|
|
addl $1, (v)
|
|
|
|
adcl $0, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(inc_return)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
2010-02-24 17:54:25 +08:00
|
|
|
addl $1, %eax
|
|
|
|
adcl $0, %edx
|
2010-08-06 10:04:38 +08:00
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(dec)
|
|
|
|
subl $1, (v)
|
|
|
|
sbbl $0, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
|
|
|
|
|
|
|
#define v %esi
|
|
|
|
BEGIN(dec_return)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
2010-02-24 17:54:25 +08:00
|
|
|
subl $1, %eax
|
|
|
|
sbbl $0, %edx
|
2010-08-06 10:04:38 +08:00
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
|
|
|
RET_END
|
|
|
|
#undef v
|
2010-02-24 17:54:25 +08:00
|
|
|
|
2010-08-06 10:04:38 +08:00
|
|
|
#define v %ecx
|
|
|
|
BEGIN(add_unless)
|
2010-02-24 17:54:25 +08:00
|
|
|
addl %eax, %esi
|
|
|
|
adcl %edx, %edi
|
2010-08-06 10:04:38 +08:00
|
|
|
addl (v), %eax
|
|
|
|
adcl 4(v), %edx
|
2010-02-24 17:54:25 +08:00
|
|
|
cmpl %eax, %esi
|
|
|
|
je 3f
|
|
|
|
1:
|
2010-08-06 10:04:38 +08:00
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
2010-03-02 02:55:46 +08:00
|
|
|
movl $1, %eax
|
2010-02-24 17:54:25 +08:00
|
|
|
2:
|
2010-08-06 10:04:38 +08:00
|
|
|
RET
|
2010-02-24 17:54:25 +08:00
|
|
|
3:
|
|
|
|
cmpl %edx, %edi
|
|
|
|
jne 1b
|
2010-03-02 02:55:46 +08:00
|
|
|
xorl %eax, %eax
|
2010-02-24 17:54:25 +08:00
|
|
|
jmp 2b
|
2010-08-06 10:04:38 +08:00
|
|
|
END
|
|
|
|
#undef v
|
2010-02-24 17:54:25 +08:00
|
|
|
|
2010-08-06 10:04:38 +08:00
|
|
|
#define v %esi
|
|
|
|
BEGIN(inc_not_zero)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
2010-02-24 17:54:25 +08:00
|
|
|
testl %eax, %eax
|
|
|
|
je 3f
|
|
|
|
1:
|
|
|
|
addl $1, %eax
|
|
|
|
adcl $0, %edx
|
2010-08-06 10:04:38 +08:00
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
2010-03-02 02:55:49 +08:00
|
|
|
movl $1, %eax
|
2010-02-24 17:54:25 +08:00
|
|
|
2:
|
2010-08-06 10:04:38 +08:00
|
|
|
RET
|
2010-02-24 17:54:25 +08:00
|
|
|
3:
|
|
|
|
testl %edx, %edx
|
|
|
|
jne 1b
|
|
|
|
jmp 2b
|
2010-08-06 10:04:38 +08:00
|
|
|
END
|
|
|
|
#undef v
|
2010-02-24 17:54:25 +08:00
|
|
|
|
2010-08-06 10:04:38 +08:00
|
|
|
#define v %esi
|
|
|
|
BEGIN(dec_if_positive)
|
|
|
|
movl (v), %eax
|
|
|
|
movl 4(v), %edx
|
2010-02-24 17:54:25 +08:00
|
|
|
subl $1, %eax
|
|
|
|
sbbl $0, %edx
|
|
|
|
js 1f
|
2010-08-06 10:04:38 +08:00
|
|
|
movl %eax, (v)
|
|
|
|
movl %edx, 4(v)
|
2010-02-24 17:54:25 +08:00
|
|
|
1:
|
2010-08-06 10:04:38 +08:00
|
|
|
RET_END
|
|
|
|
#undef v
|