blob: 285beacfadfc8b0abf95c387eeb295d4d3c14a0e [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
Elliott Hughes5eccb962013-12-20 16:58:06 -080029#include <private/bionic_asm.h>
Raghu Gandham405b8022012-07-25 18:16:42 -070030
31#define FUTEX_WAIT 0
32#define FUTEX_WAKE 1
33
Elliott Hughes5eccb962013-12-20 16:58:06 -080034// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
Raghu Gandham405b8022012-07-25 18:16:42 -070035 .type __futex_wait, @function
36 .global __futex_wait
37 .align 4
38 .ent __futex_wait
39__futex_wait:
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080040 subu sp,4*6
41 sw $0,20(sp) /* val3 */
42 sw $0,16(sp) /* addr2 */
43 move a3,a2 /* timespec */
44 move a2,a1 /* val */
45 li a1,FUTEX_WAIT /* op */
46# move a0,a0 /* ftx */
47 li v0,__NR_futex
Raghu Gandham405b8022012-07-25 18:16:42 -070048 syscall
49 .set noreorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080050 bnez a3, 1f /* Check for error */
51 neg v0 /* Negate error number if it's valid */
52 move v0,$0 /* Otherwise return 0 */
Raghu Gandham405b8022012-07-25 18:16:42 -0700531:
54 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080055 addu sp,4*6
56 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -070057 .end __futex_wait
58
Elliott Hughes5eccb962013-12-20 16:58:06 -080059// int __futex_wake(volatile void* ftx, int count)
Raghu Gandham405b8022012-07-25 18:16:42 -070060 .type __futex_wake, @function
61 .globl __futex_wake
62 .align 4
63 .ent __futex_wake
64__futex_wake:
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080065 subu sp,4*6
66 sw $0,20(sp) /* val3 */
67 sw $0,16(sp) /* addr2 */
68 move a3,$0 /* timespec */
69 move a2,a1 /* val */
70 li a1,FUTEX_WAKE /* op */
71# move a0,a0 /* ftx */
72 li v0,__NR_futex
Raghu Gandham405b8022012-07-25 18:16:42 -070073 syscall
74 .set noreorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080075 bnez a3, 1f /* Check for error */
76 neg v0 /* Negate error number if it's valid */
77 move v0,$0 /* Otherwise return 0 */
Raghu Gandham405b8022012-07-25 18:16:42 -0700781:
79 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080080 addu sp,4*6
81 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -070082 .end __futex_wake
83
Elliott Hughes5eccb962013-12-20 16:58:06 -080084// int __futex_syscall3(volatile void* ftx, int op, int count)
Raghu Gandham405b8022012-07-25 18:16:42 -070085 .type __futex_syscall3, @function
86 .global __futex_syscall3
87 .align 4
88 .ent __futex_syscall3
89__futex_syscall3:
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080090 subu sp,4*6
91 sw $0,20(sp) /* val3 */
92 sw $0,16(sp) /* addr2 */
93 move a3,$0 /* timespec */
94# move a2,a2 /* val */
95# li a1,a1 /* op */
96# move a0,a0 /* ftx */
97 li v0,__NR_futex
Raghu Gandham405b8022012-07-25 18:16:42 -070098 syscall
99 .set noreorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800100 bnez a3, 1f /* Check for error */
101 neg v0 /* Negate error number if it's valid */
102 move v0,$0 /* Otherwise return 0 */
Raghu Gandham405b8022012-07-25 18:16:42 -07001031:
104 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800105 addu sp,4*6
106 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -0700107 .end __futex_syscall3
108
Elliott Hughes5eccb962013-12-20 16:58:06 -0800109// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
Raghu Gandham405b8022012-07-25 18:16:42 -0700110 .type __futex_syscall4, @function
111 .global __futex_syscall4
112 .align 4
113 .ent __futex_syscall4
114__futex_syscall4:
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800115 subu sp,4*6
116 sw $0,20(sp) /* val3 */
117 sw $0,16(sp) /* addr2 */
118# move a3,a3 /* timespec */
119# move a2,a2 /* val */
120# li a1,a1 /* op */
121# move a0,a0 /* ftx */
122 li v0,__NR_futex
Raghu Gandham405b8022012-07-25 18:16:42 -0700123 syscall
124 .set noreorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800125 bnez a3, 1f /* Check for error */
126 neg v0 /* Negate error number if it's valid */
127 move v0,$0 /* Otherwise return 0 */
Raghu Gandham405b8022012-07-25 18:16:42 -07001281:
129 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800130 addu sp,4*6
131 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -0700132 .end __futex_syscall4