2 * x86 semaphore implementation.
4 * (C) Copyright 1999 Linus Torvalds
6 * Portions Copyright 1999 Red Hat, Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * rw semaphores implemented November 1999 by Benjamin LaHaise <bcrl@kvack.org>
16 #include <linux/linkage.h>
17 #include <asm/alternative-asm.h>
18 #include <asm/frame.h>
20 #define __ASM_HALF_REG(reg) __ASM_SEL(reg, e##reg)
21 #define __ASM_HALF_SIZE(inst) __ASM_SEL(inst##w, inst##l)
26 * The semaphore operations have a special calling sequence that
27 * allow us to do a simpler in-line version of them. These routines
28 * need to convert that sequence back into the C sequence when
29 * there is contention on the semaphore.
31 * %eax contains the semaphore pointer on entry. Save the C-clobbered
32 * registers (%eax, %edx and %ecx) except %eax which is either a return
33 * value or just gets clobbered. Same is true for %edx so make sure GCC
34 * reloads it after the slow path, by making it hold a temporary, for
35 * example see ____down_write().
38 #define save_common_regs \
41 #define restore_common_regs \
44 /* Avoid uglifying the argument copying x86-64 needs to do. */
51 * x86-64 rwsem wrappers
53 * This interfaces the inline asm code to the slow-path
54 * C routines. We need to save the call-clobbered regs
55 * that the asm does not mark as clobbered, and move the
56 * argument from %rax to %rdi.
58 * NOTE! We don't need to save %rax, because the functions
59 * will always return the semaphore pointer in %rax (which
60 * is also the input argument to these helpers)
62 * The following can clobber %rdx because the asm clobbers it:
63 * call_rwsem_down_write_failed
65 * but %rdi, %rsi, %rcx, %r8-r11 always need saving.
68 #define save_common_regs \
77 #define restore_common_regs \
88 /* Fix up special calling conventions */
89 ENTRY(call_rwsem_down_read_failed)
92 __ASM_SIZE(push,) %__ASM_REG(dx)
94 call rwsem_down_read_failed
95 __ASM_SIZE(pop,) %__ASM_REG(dx)
99 ENDPROC(call_rwsem_down_read_failed)
101 ENTRY(call_rwsem_down_write_failed)
105 call rwsem_down_write_failed
109 ENDPROC(call_rwsem_down_write_failed)
111 ENTRY(call_rwsem_down_write_failed_killable)
115 call rwsem_down_write_failed_killable
119 ENDPROC(call_rwsem_down_write_failed_killable)
121 ENTRY(call_rwsem_wake)
123 /* do nothing if still outstanding active readers */
124 __ASM_HALF_SIZE(dec) %__ASM_HALF_REG(dx)
132 ENDPROC(call_rwsem_wake)
134 ENTRY(call_rwsem_downgrade_wake)
137 __ASM_SIZE(push,) %__ASM_REG(dx)
139 call rwsem_downgrade_wake
140 __ASM_SIZE(pop,) %__ASM_REG(dx)
144 ENDPROC(call_rwsem_downgrade_wake)