blob: 1a249a724655dab542e961c76913f2ef8d3e4f85 [file] [log] [blame]
Chris Dearman645d0312014-02-05 18:51:43 -08001/*
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 <machine/asm.h>
30#include <private/bionic_asm.h>
31
32#define FUTEX_WAIT 0
33#define FUTEX_WAKE 1
34
35#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
36FRAMESZ = MKFSIZ(NARGSAVE+2,0)
37FRAME_A4 = 4*REGSZ
38FRAME_A5 = 5*REGSZ
39#else
40FRAMESZ = 0
41#endif
42
43// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
44LEAF(__futex_wait, FRAMESZ)
45#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
46 PTR_SUBU sp, FRAMESZ
47 REG_S $0,FRAME_A5(sp) /* val3 */
48 REG_S $0,FRAME_A4(sp) /* addr2 */
49#else
50 move a5,$0 /* val3 */
51 move a4,$0 /* addr2 */
52#endif
53 move a3,a2 /* timespec */
54 move a2,a1 /* val */
55 LI a1,FUTEX_WAIT /* op */
56# move a0,a0 /* ftx */
57 LI v0,__NR_futex
58 syscall
59 neg v0 /* Negate errno */
60 bnez a3,1f /* Check for error */
61 move v0,$0 /* Return 0 if no error */
621:
63#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
64 PTR_ADDU sp,FRAMESZ
65#endif
66 j ra
67 END(__futex_wait)
68
69// int __futex_wake(volatile void* ftx, int count)
70LEAF(__futex_wake,FRAMESZ)
71#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
72 PTR_SUBU sp, FRAMESZ
73 REG_S $0,FRAME_A5(sp) /* val3 */
74 REG_S $0,FRAME_A4(sp) /* addr2 */
75#else
76 move a5,$0 /* val3 */
77 move a4,$0 /* addr2 */
78#endif
79 move a3,$0 /* timespec */
80 move a2,a1 /* val */
81 LI a1,FUTEX_WAKE /* op */
82# move a0,a0 /* ftx */
83 LI v0,__NR_futex
84 syscall
85 neg v0 /* Negate errno */
86 bnez a3,1f /* Check for error */
87 move v0,$0 /* Return 0 if no error */
881:
89#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
90 PTR_ADDU sp,FRAMESZ
91#endif
92 j ra
93 END(__futex_wake)
94
95// int __futex_syscall3(volatile void* ftx, int op, int count)
96LEAF(__futex_syscall3,FRAMESZ)
97#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
98 PTR_SUBU sp, FRAMESZ
99 REG_S $0,FRAME_A5(sp) /* val3 */
100 REG_S $0,FRAME_A4(sp) /* addr2 */
101#else
102 move a5,$0 /* val3 */
103 move a4,$0 /* addr2 */
104#endif
105 move a3,$0 /* timespec */
106# move a2,a2 /* val */
107# move a1,a1 /* op */
108# move a0,a0 /* ftx */
109 LI v0,__NR_futex
110 syscall
111 neg v0 /* Negate errno */
112 bnez a3,1f /* Check for error */
113 move v0,$0 /* Return 0 if no error */
1141:
115#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
116 PTR_ADDU sp,FRAMESZ
117#endif
118 j ra
119 END(__futex_syscall3)
120
121// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
122LEAF(__futex_syscall4,FRAMESZ)
123#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
124 PTR_SUBU sp, FRAMESZ
125 REG_S $0,FRAME_A5(sp) /* val3 */
126 REG_S $0,FRAME_A4(sp) /* addr2 */
127#else
128 move a5,$0 /* val3 */
129 move a4,$0 /* addr2 */
130#endif
131# move a3,a3 /* timespec */
132# move a2,a2 /* val */
133# move a1,a1 /* op */
134# move a0,a0 /* ftx */
135 LI v0,__NR_futex
136 syscall
137 neg v0 /* Negate errno */
138 bnez a3,1f /* Check for error */
139 move v0,$0 /* Return 0 if no error */
1401:
141#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
142 PTR_ADDU sp,FRAMESZ
143#endif
144 j ra
145 END(__futex_syscall4)