| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Hughes | 5eccb96 | 2013-12-20 16:58:06 -0800 | [diff] [blame] | 29 | #include <private/bionic_asm.h> | 
| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | #define FUTEX_WAIT 0 | 
|  | 32 | #define FUTEX_WAKE 1 | 
|  | 33 |  | 
| Elliott Hughes | 5eccb96 | 2013-12-20 16:58:06 -0800 | [diff] [blame] | 34 | // int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) | 
| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 35 | .type	__futex_wait, @function | 
|  | 36 | .global	__futex_wait | 
|  | 37 | .align	4 | 
|  | 38 | .ent	__futex_wait | 
|  | 39 | __futex_wait: | 
|  | 40 | 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 | 
|  | 48 | syscall | 
|  | 49 | .set noreorder | 
|  | 50 | bnez	$a3, 1f		/* Check for error */ | 
|  | 51 | neg	$v0		/* Negate error number if it's valid */ | 
|  | 52 | move	$v0,$0		/* Otherwise return 0 */ | 
|  | 53 | 1: | 
|  | 54 | .set reorder | 
|  | 55 | addu	$sp,4*6 | 
|  | 56 | j	$ra | 
|  | 57 | .end	__futex_wait | 
|  | 58 |  | 
| Elliott Hughes | 5eccb96 | 2013-12-20 16:58:06 -0800 | [diff] [blame] | 59 | // int __futex_wake(volatile void* ftx, int count) | 
| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 60 | .type	__futex_wake, @function | 
|  | 61 | .globl	__futex_wake | 
|  | 62 | .align	4 | 
|  | 63 | .ent	__futex_wake | 
|  | 64 | __futex_wake: | 
|  | 65 | 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 | 
|  | 73 | syscall | 
|  | 74 | .set noreorder | 
|  | 75 | bnez	$a3, 1f		/* Check for error */ | 
|  | 76 | neg	$v0		/* Negate error number if it's valid */ | 
|  | 77 | move	$v0,$0		/* Otherwise return 0 */ | 
|  | 78 | 1: | 
|  | 79 | .set reorder | 
|  | 80 | addu	$sp,4*6 | 
|  | 81 | j	$ra | 
|  | 82 | .end	__futex_wake | 
|  | 83 |  | 
| Elliott Hughes | 5eccb96 | 2013-12-20 16:58:06 -0800 | [diff] [blame] | 84 | // int __futex_syscall3(volatile void* ftx, int op, int count) | 
| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 85 | .type	__futex_syscall3, @function | 
|  | 86 | .global	__futex_syscall3 | 
|  | 87 | .align	4 | 
|  | 88 | .ent	__futex_syscall3 | 
|  | 89 | __futex_syscall3: | 
|  | 90 | 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 | 
|  | 98 | syscall | 
|  | 99 | .set noreorder | 
|  | 100 | bnez	$a3, 1f		/* Check for error */ | 
|  | 101 | neg	$v0		/* Negate error number if it's valid */ | 
|  | 102 | move	$v0,$0		/* Otherwise return 0 */ | 
|  | 103 | 1: | 
|  | 104 | .set reorder | 
|  | 105 | addu	$sp,4*6 | 
|  | 106 | j	$ra | 
|  | 107 | .end	__futex_syscall3 | 
|  | 108 |  | 
| Elliott Hughes | 5eccb96 | 2013-12-20 16:58:06 -0800 | [diff] [blame] | 109 | // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) | 
| Raghu Gandham | 405b802 | 2012-07-25 18:16:42 -0700 | [diff] [blame] | 110 | .type	__futex_syscall4, @function | 
|  | 111 | .global	__futex_syscall4 | 
|  | 112 | .align	4 | 
|  | 113 | .ent	__futex_syscall4 | 
|  | 114 | __futex_syscall4: | 
|  | 115 | 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 | 
|  | 123 | syscall | 
|  | 124 | .set noreorder | 
|  | 125 | bnez	$a3, 1f		/* Check for error */ | 
|  | 126 | neg	$v0		/* Negate error number if it's valid */ | 
|  | 127 | move	$v0,$0		/* Otherwise return 0 */ | 
|  | 128 | 1: | 
|  | 129 | .set reorder | 
|  | 130 | addu	$sp,4*6 | 
|  | 131 | j	$ra | 
|  | 132 | .end	__futex_syscall4 |