* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / include / asm-arm / proc-armv / semaphore.h
blob45ceaa3f1099328dd7abab17e8dfa9c05d3ab58c
1 /*
2 * linux/include/asm-arm/semaphore.h
3 */
4 #ifndef __ASM_PROC_SEMAPHORE_H
5 #define __ASM_PROC_SEMAPHORE_H
7 /*
8 * This is ugly, but we want the default case to fall through.
9 * "__down" is the actual routine that waits...
11 extern inline void down(struct semaphore * sem)
13 unsigned int cpsr, temp;
15 __asm__ __volatile__ ("
16 @ atomic down operation
17 mrs %0, cpsr
18 orr %1, %0, #128 @ disable IRQs
19 msr cpsr, %1
20 ldr %1, [%2]
21 bic %0, %0, #0x80000000 @ clear N
22 subs %1, %1, #1
23 str %1, [%2]
24 orrmi %0, %0, #0x80000000 @ set N
25 msr cpsr, %0
26 movmi r0, %2
27 blmi " SYMBOL_NAME_STR(__down_failed)
28 : "=&r" (cpsr), "=&r" (temp)
29 : "r" (sem)
30 : "r0", "lr", "cc");
34 * This is ugly, but we want the default case to fall through.
35 * "__down_interruptible" is the actual routine that waits...
37 extern inline int down_interruptible (struct semaphore * sem)
39 unsigned int cpsr, temp;
41 __asm__ __volatile__ ("
42 @ atomic down interruptible operation
43 mrs %0, cpsr
44 orr %1, %0, #128 @ disable IRQs
45 msr cpsr, %1
46 ldr %1, [%2]
47 bic %0, %0, #0x80000000 @ clear N
48 subs %1, %1, #1
49 str %1, [%2]
50 orrmi %0, %0, #0x80000000 @ set N
51 msr cpsr, %0
52 movmi r0, %2
53 movpl r0, #0
54 blmi " SYMBOL_NAME_STR(__down_interruptible_failed) "
55 mov %1, r0"
56 : "=&r" (cpsr), "=&r" (temp)
57 : "r" (sem)
58 : "r0", "lr", "cc");
60 return temp;
63 extern inline int down_trylock(struct semaphore *sem)
65 unsigned int cpsr, temp;
67 __asm__ __volatile__ ("
68 @ atomic down try lock operation
69 mrs %0, cpsr
70 orr %1, %0, #128 @ disable IRQs
71 msr cpsr, %1
72 ldr %1, [%2]
73 bic %0, %0, #0x80000000 @ clear N
74 subs %1, %1, #1
75 str %1, [%2]
76 orrmi %0, %0, #0x80000000 @ set N
77 msr cpsr, %0
78 movmi r0, %2
79 movpl r0, #0
80 blmi " SYMBOL_NAME_STR(__down_trylock_failed) "
81 mov %1, r0"
82 : "=&r" (cpsr), "=&r" (temp)
83 : "r" (sem)
84 : "r0", "lr", "cc");
86 return temp;
90 * Note! This is subtle. We jump to wake people up only if
91 * the semaphore was negative (== somebody was waiting on it).
92 * The default case (no contention) will result in NO
93 * jumps for both down() and up().
95 extern inline void up(struct semaphore * sem)
97 unsigned int cpsr, temp;
99 __asm__ __volatile__ ("
100 @ atomic up operation
101 mrs %0, cpsr
102 orr %1, %0, #128 @ disable IRQs
103 msr cpsr, %1
104 ldr %1, [%2]
105 bic %0, %0, #0x80000000 @ clear N
106 adds %1, %1, #1
107 str %1, [%2]
108 orrle %0, %0, #0x80000000 @ set N
109 msr cpsr, %0
110 movmi r0, %2
111 blmi " SYMBOL_NAME_STR(__up_wakeup)
112 : "=&r" (cpsr), "=&r" (temp)
113 : "r" (sem)
114 : "r0", "lr", "cc");
117 #endif