Commit 30246557 authored by Luca Barbieri's avatar Luca Barbieri Committed by H. Peter Anvin

x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

The old code didn't work on binutils 2.12 because setting a symbol to
a register apparently requires a fairly recent version.

This commit refactors the code to use the C preprocessor instead, and
in the process makes the whole code a bit easier to understand.

The object code produced is unchanged as expected.

This fixes kernel bugzilla 16506.
Reported-by: default avatarDieter Stussy <kd6lvw+software@kd6lvw.ampr.org>
Signed-off-by: default avatarLuca Barbieri <luca@luca-barbieri.com>
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
Cc: <stable@kernel.org> 2.6.35
LKML-Reference: <tip-*@git.kernel.org>
parent 8fd49936
...@@ -25,150 +25,170 @@ ...@@ -25,150 +25,170 @@
CFI_ADJUST_CFA_OFFSET -4 CFI_ADJUST_CFA_OFFSET -4
.endm .endm
.macro BEGIN func reg #define BEGIN(op) \
$v = \reg .macro END; \
CFI_ENDPROC; \
ENTRY(atomic64_\func\()_386) ENDPROC(atomic64_##op##_386); \
CFI_STARTPROC .purgem END; \
LOCK $v .endm; \
ENTRY(atomic64_##op##_386); \
.macro RETURN CFI_STARTPROC; \
UNLOCK $v LOCK v;
#define RET \
UNLOCK v; \
ret ret
.endm
.macro END_
CFI_ENDPROC
ENDPROC(atomic64_\func\()_386)
.purgem RETURN
.purgem END_
.purgem END
.endm
.macro END
RETURN
END_
.endm
.endm
BEGIN read %ecx
movl ($v), %eax
movl 4($v), %edx
END
BEGIN set %esi
movl %ebx, ($v)
movl %ecx, 4($v)
END
BEGIN xchg %esi
movl ($v), %eax
movl 4($v), %edx
movl %ebx, ($v)
movl %ecx, 4($v)
END
BEGIN add %ecx
addl %eax, ($v)
adcl %edx, 4($v)
END
BEGIN add_return %ecx #define RET_END \
addl ($v), %eax RET; \
adcl 4($v), %edx END
movl %eax, ($v)
movl %edx, 4($v) #define v %ecx
END BEGIN(read)
movl (v), %eax
BEGIN sub %ecx movl 4(v), %edx
subl %eax, ($v) RET_END
sbbl %edx, 4($v) #undef v
END
#define v %esi
BEGIN sub_return %ecx 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)
negl %edx negl %edx
negl %eax negl %eax
sbbl $0, %edx sbbl $0, %edx
addl ($v), %eax addl (v), %eax
adcl 4($v), %edx adcl 4(v), %edx
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
END RET_END
#undef v
BEGIN inc %esi
addl $1, ($v) #define v %esi
adcl $0, 4($v) BEGIN(inc)
END addl $1, (v)
adcl $0, 4(v)
BEGIN inc_return %esi RET_END
movl ($v), %eax #undef v
movl 4($v), %edx
#define v %esi
BEGIN(inc_return)
movl (v), %eax
movl 4(v), %edx
addl $1, %eax addl $1, %eax
adcl $0, %edx adcl $0, %edx
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
END RET_END
#undef v
BEGIN dec %esi
subl $1, ($v) #define v %esi
sbbl $0, 4($v) BEGIN(dec)
END subl $1, (v)
sbbl $0, 4(v)
BEGIN dec_return %esi RET_END
movl ($v), %eax #undef v
movl 4($v), %edx
#define v %esi
BEGIN(dec_return)
movl (v), %eax
movl 4(v), %edx
subl $1, %eax subl $1, %eax
sbbl $0, %edx sbbl $0, %edx
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
END RET_END
#undef v
BEGIN add_unless %ecx #define v %ecx
BEGIN(add_unless)
addl %eax, %esi addl %eax, %esi
adcl %edx, %edi adcl %edx, %edi
addl ($v), %eax addl (v), %eax
adcl 4($v), %edx adcl 4(v), %edx
cmpl %eax, %esi cmpl %eax, %esi
je 3f je 3f
1: 1:
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
movl $1, %eax movl $1, %eax
2: 2:
RETURN RET
3: 3:
cmpl %edx, %edi cmpl %edx, %edi
jne 1b jne 1b
xorl %eax, %eax xorl %eax, %eax
jmp 2b jmp 2b
END_ END
#undef v
BEGIN inc_not_zero %esi #define v %esi
movl ($v), %eax BEGIN(inc_not_zero)
movl 4($v), %edx movl (v), %eax
movl 4(v), %edx
testl %eax, %eax testl %eax, %eax
je 3f je 3f
1: 1:
addl $1, %eax addl $1, %eax
adcl $0, %edx adcl $0, %edx
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
movl $1, %eax movl $1, %eax
2: 2:
RETURN RET
3: 3:
testl %edx, %edx testl %edx, %edx
jne 1b jne 1b
jmp 2b jmp 2b
END_ END
#undef v
BEGIN dec_if_positive %esi #define v %esi
movl ($v), %eax BEGIN(dec_if_positive)
movl 4($v), %edx movl (v), %eax
movl 4(v), %edx
subl $1, %eax subl $1, %eax
sbbl $0, %edx sbbl $0, %edx
js 1f js 1f
movl %eax, ($v) movl %eax, (v)
movl %edx, 4($v) movl %edx, 4(v)
1: 1:
END RET_END
#undef v
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment