blob: 2a953caf048ad3d2b04ad1bf2b183bad94358f7f [file] [log] [blame]
Raghu Gandham405b8022012-07-25 18:16:42 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <asm/unistd.h>
30
31#define FUTEX_WAIT 0
32#define FUTEX_WAKE 1
33
34/*
35 * __futex_wait(*ftx, val, *timespec)
36 * futex_syscall(*ftx, op, val, *timespec, *addr2, val3)
37 */
38 .type __futex_wait, @function
39 .global __futex_wait
40 .align 4
41 .ent __futex_wait
42__futex_wait:
43 subu $sp,4*6
44 sw $0,20($sp) /* val3 */
45 sw $0,16($sp) /* addr2 */
46 move $a3,$a2 /* timespec */
47 move $a2,$a1 /* val */
48 li $a1,FUTEX_WAIT /* op */
49# move $a0,$a0 /* ftx */
50 li $v0,__NR_futex
51 syscall
52 .set noreorder
53 bnez $a3, 1f /* Check for error */
54 neg $v0 /* Negate error number if it's valid */
55 move $v0,$0 /* Otherwise return 0 */
561:
57 .set reorder
58 addu $sp,4*6
59 j $ra
60 .end __futex_wait
61
62/*
63 * int __futex_wake(volatile void *ftx, int count)
64 * int futex_syscall(*ftx, op, val, *timespec, *addr2, val3)
65 */
66 .type __futex_wake, @function
67 .globl __futex_wake
68 .align 4
69 .ent __futex_wake
70__futex_wake:
71 subu $sp,4*6
72 sw $0,20($sp) /* val3 */
73 sw $0,16($sp) /* addr2 */
74 move $a3,$0 /* timespec */
75 move $a2,$a1 /* val */
76 li $a1,FUTEX_WAKE /* op */
77# move $a0,$a0 /* ftx */
78 li $v0,__NR_futex
79 syscall
80 .set noreorder
81 bnez $a3, 1f /* Check for error */
82 neg $v0 /* Negate error number if it's valid */
83 move $v0,$0 /* Otherwise return 0 */
841:
85 .set reorder
86 addu $sp,4*6
87 j $ra
88 .end __futex_wake
89
90/* __futex_syscall3(*ftx, op, val)
91 * futex_syscall(*ftx, op, val, *timespec, *addr2, val3)
92 */
93 .type __futex_syscall3, @function
94 .global __futex_syscall3
95 .align 4
96 .ent __futex_syscall3
97__futex_syscall3:
98 subu $sp,4*6
99 sw $0,20($sp) /* val3 */
100 sw $0,16($sp) /* addr2 */
101 move $a3,$0 /* timespec */
102# move $a2,$a2 /* val */
103# li $a1,$a1 /* op */
104# move $a0,$a0 /* ftx */
105 li $v0,__NR_futex
106 syscall
107 .set noreorder
108 bnez $a3, 1f /* Check for error */
109 neg $v0 /* Negate error number if it's valid */
110 move $v0,$0 /* Otherwise return 0 */
1111:
112 .set reorder
113 addu $sp,4*6
114 j $ra
115 .end __futex_syscall3
116
117/* __futex_syscall4(*ftx, op, val)
118 * futex_syscall(*ftx, op, val, *timespec, *addr2, val3)
119 */
120 .type __futex_syscall4, @function
121 .global __futex_syscall4
122 .align 4
123 .ent __futex_syscall4
124__futex_syscall4:
125 subu $sp,4*6
126 sw $0,20($sp) /* val3 */
127 sw $0,16($sp) /* addr2 */
128# move $a3,$a3 /* timespec */
129# move $a2,$a2 /* val */
130# li $a1,$a1 /* op */
131# move $a0,$a0 /* ftx */
132 li $v0,__NR_futex
133 syscall
134 .set noreorder
135 bnez $a3, 1f /* Check for error */
136 neg $v0 /* Negate error number if it's valid */
137 move $v0,$0 /* Otherwise return 0 */
1381:
139 .set reorder
140 addu $sp,4*6
141 j $ra
142 .end __futex_syscall4