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