blob: 48e44f7ed76eea5befac0f984e5efe82950e574e [file] [log] [blame]
Andi Kleenecaf45e2006-09-26 10:52:29 +02001/*
2 * i386 semaphore implementation.
3 *
4 * (C) Copyright 1999 Linus Torvalds
5 *
6 * Portions Copyright 1999 Red Hat, Inc.
7 *
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.
12 *
13 * rw semaphores implemented November 1999 by Benjamin LaHaise <bcrl@kvack.org>
14 */
15
Andi Kleenecaf45e2006-09-26 10:52:29 +020016#include <linux/linkage.h>
17#include <asm/rwlock.h>
Adrian Bunk7e02cb92007-10-17 18:04:38 +020018#include <asm/alternative-asm.h>
19#include <asm/frame.h>
Andi Kleenecaf45e2006-09-26 10:52:29 +020020#include <asm/dwarf2.h>
21
22/*
23 * The semaphore operations have a special calling sequence that
24 * allow us to do a simpler in-line version of them. These routines
25 * need to convert that sequence back into the C sequence when
26 * there is contention on the semaphore.
27 *
28 * %eax contains the semaphore pointer on entry. Save the C-clobbered
29 * registers (%eax, %edx and %ecx) except %eax whish is either a return
30 * value or just clobbered..
31 */
Sam Ravnborgc6c2d7a2008-01-30 13:33:37 +010032 .section .sched.text, "ax"
Andi Kleenecaf45e2006-09-26 10:52:29 +020033
34/*
35 * rw spinlock fallbacks
36 */
37#ifdef CONFIG_SMP
38ENTRY(__write_lock_failed)
39 CFI_STARTPROC simple
40 FRAME
412: LOCK_PREFIX
42 addl $ RW_LOCK_BIAS,(%eax)
431: rep; nop
44 cmpl $ RW_LOCK_BIAS,(%eax)
45 jne 1b
46 LOCK_PREFIX
47 subl $ RW_LOCK_BIAS,(%eax)
48 jnz 2b
49 ENDFRAME
50 ret
51 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +010052 ENDPROC(__write_lock_failed)
Andi Kleenecaf45e2006-09-26 10:52:29 +020053
54ENTRY(__read_lock_failed)
55 CFI_STARTPROC
56 FRAME
572: LOCK_PREFIX
58 incl (%eax)
591: rep; nop
60 cmpl $1,(%eax)
61 js 1b
62 LOCK_PREFIX
63 decl (%eax)
64 js 2b
65 ENDFRAME
66 ret
67 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +010068 ENDPROC(__read_lock_failed)
Andi Kleenecaf45e2006-09-26 10:52:29 +020069
70#endif
Andi Kleenadd659b2006-09-26 10:52:31 +020071
Ingo Molnar88271e92006-10-05 18:47:22 +020072#ifdef CONFIG_RWSEM_XCHGADD_ALGORITHM
73
Andi Kleenadd659b2006-09-26 10:52:31 +020074/* Fix up special calling conventions */
75ENTRY(call_rwsem_down_read_failed)
76 CFI_STARTPROC
Jan Beulich60cf6372011-02-28 15:54:40 +000077 pushl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +020078 CFI_REL_OFFSET ecx,0
Jan Beulich60cf6372011-02-28 15:54:40 +000079 pushl_cfi %edx
Andi Kleenadd659b2006-09-26 10:52:31 +020080 CFI_REL_OFFSET edx,0
81 call rwsem_down_read_failed
Jan Beulich60cf6372011-02-28 15:54:40 +000082 popl_cfi %edx
83 popl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +020084 ret
85 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +010086 ENDPROC(call_rwsem_down_read_failed)
Andi Kleenadd659b2006-09-26 10:52:31 +020087
88ENTRY(call_rwsem_down_write_failed)
89 CFI_STARTPROC
Jan Beulich60cf6372011-02-28 15:54:40 +000090 pushl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +020091 CFI_REL_OFFSET ecx,0
92 calll rwsem_down_write_failed
Jan Beulich60cf6372011-02-28 15:54:40 +000093 popl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +020094 ret
95 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +010096 ENDPROC(call_rwsem_down_write_failed)
Andi Kleenadd659b2006-09-26 10:52:31 +020097
98ENTRY(call_rwsem_wake)
99 CFI_STARTPROC
100 decw %dx /* do nothing if still outstanding active readers */
101 jnz 1f
Jan Beulich60cf6372011-02-28 15:54:40 +0000102 pushl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +0200103 CFI_REL_OFFSET ecx,0
104 call rwsem_wake
Jan Beulich60cf6372011-02-28 15:54:40 +0000105 popl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +02001061: ret
107 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +0100108 ENDPROC(call_rwsem_wake)
Andi Kleenadd659b2006-09-26 10:52:31 +0200109
110/* Fix up special calling conventions */
111ENTRY(call_rwsem_downgrade_wake)
112 CFI_STARTPROC
Jan Beulich60cf6372011-02-28 15:54:40 +0000113 pushl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +0200114 CFI_REL_OFFSET ecx,0
Jan Beulich60cf6372011-02-28 15:54:40 +0000115 pushl_cfi %edx
Andi Kleenadd659b2006-09-26 10:52:31 +0200116 CFI_REL_OFFSET edx,0
117 call rwsem_downgrade_wake
Jan Beulich60cf6372011-02-28 15:54:40 +0000118 popl_cfi %edx
119 popl_cfi %ecx
Andi Kleenadd659b2006-09-26 10:52:31 +0200120 ret
121 CFI_ENDPROC
John Reiser6b8be6d2008-01-30 13:33:13 +0100122 ENDPROC(call_rwsem_downgrade_wake)
Andi Kleenadd659b2006-09-26 10:52:31 +0200123
Ingo Molnar88271e92006-10-05 18:47:22 +0200124#endif