]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/i386/kernel/semaphore.c
Merge branch 'master'
[mirror_ubuntu-jammy-kernel.git] / arch / i386 / kernel / semaphore.c
1 /*
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 #include <linux/config.h>
16 #include <asm/semaphore.h>
17
18 /*
19 * The semaphore operations have a special calling sequence that
20 * allow us to do a simpler in-line version of them. These routines
21 * need to convert that sequence back into the C sequence when
22 * there is contention on the semaphore.
23 *
24 * %eax contains the semaphore pointer on entry. Save the C-clobbered
25 * registers (%eax, %edx and %ecx) except %eax whish is either a return
26 * value or just clobbered..
27 */
28 asm(
29 ".section .sched.text\n"
30 ".align 4\n"
31 ".globl __down_failed\n"
32 "__down_failed:\n\t"
33 #if defined(CONFIG_FRAME_POINTER)
34 "pushl %ebp\n\t"
35 "movl %esp,%ebp\n\t"
36 #endif
37 "pushl %edx\n\t"
38 "pushl %ecx\n\t"
39 "call __down\n\t"
40 "popl %ecx\n\t"
41 "popl %edx\n\t"
42 #if defined(CONFIG_FRAME_POINTER)
43 "movl %ebp,%esp\n\t"
44 "popl %ebp\n\t"
45 #endif
46 "ret"
47 );
48
49 asm(
50 ".section .sched.text\n"
51 ".align 4\n"
52 ".globl __down_failed_interruptible\n"
53 "__down_failed_interruptible:\n\t"
54 #if defined(CONFIG_FRAME_POINTER)
55 "pushl %ebp\n\t"
56 "movl %esp,%ebp\n\t"
57 #endif
58 "pushl %edx\n\t"
59 "pushl %ecx\n\t"
60 "call __down_interruptible\n\t"
61 "popl %ecx\n\t"
62 "popl %edx\n\t"
63 #if defined(CONFIG_FRAME_POINTER)
64 "movl %ebp,%esp\n\t"
65 "popl %ebp\n\t"
66 #endif
67 "ret"
68 );
69
70 asm(
71 ".section .sched.text\n"
72 ".align 4\n"
73 ".globl __down_failed_trylock\n"
74 "__down_failed_trylock:\n\t"
75 #if defined(CONFIG_FRAME_POINTER)
76 "pushl %ebp\n\t"
77 "movl %esp,%ebp\n\t"
78 #endif
79 "pushl %edx\n\t"
80 "pushl %ecx\n\t"
81 "call __down_trylock\n\t"
82 "popl %ecx\n\t"
83 "popl %edx\n\t"
84 #if defined(CONFIG_FRAME_POINTER)
85 "movl %ebp,%esp\n\t"
86 "popl %ebp\n\t"
87 #endif
88 "ret"
89 );
90
91 asm(
92 ".section .sched.text\n"
93 ".align 4\n"
94 ".globl __up_wakeup\n"
95 "__up_wakeup:\n\t"
96 "pushl %edx\n\t"
97 "pushl %ecx\n\t"
98 "call __up\n\t"
99 "popl %ecx\n\t"
100 "popl %edx\n\t"
101 "ret"
102 );
103
104 /*
105 * rw spinlock fallbacks
106 */
107 #if defined(CONFIG_SMP)
108 asm(
109 ".section .sched.text\n"
110 ".align 4\n"
111 ".globl __write_lock_failed\n"
112 "__write_lock_failed:\n\t"
113 LOCK "addl $" RW_LOCK_BIAS_STR ",(%eax)\n"
114 "1: rep; nop\n\t"
115 "cmpl $" RW_LOCK_BIAS_STR ",(%eax)\n\t"
116 "jne 1b\n\t"
117 LOCK "subl $" RW_LOCK_BIAS_STR ",(%eax)\n\t"
118 "jnz __write_lock_failed\n\t"
119 "ret"
120 );
121
122 asm(
123 ".section .sched.text\n"
124 ".align 4\n"
125 ".globl __read_lock_failed\n"
126 "__read_lock_failed:\n\t"
127 LOCK "incl (%eax)\n"
128 "1: rep; nop\n\t"
129 "cmpl $1,(%eax)\n\t"
130 "js 1b\n\t"
131 LOCK "decl (%eax)\n\t"
132 "js __read_lock_failed\n\t"
133 "ret"
134 );
135 #endif