Serban Constantinescu | e210488 | 2013-09-26 11:37:10 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #include <linux/err.h> |
| 31 | #include <machine/asm.h> |
| 32 | |
| 33 | #define FUTEX_WAIT 0 |
| 34 | #define FUTEX_WAKE 1 |
| 35 | |
| 36 | /* |
| 37 | * Syscall interface for fast userspace locks |
| 38 | * |
| 39 | * int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout); |
| 40 | * int __futex_wake(volatile void *ftx, int count); |
| 41 | * int __futex_syscall3(volatile void *ftx, int op, int val); |
| 42 | * int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout); |
| 43 | */ |
| 44 | |
| 45 | ENTRY(__futex_syscall4) |
| 46 | /* create AArch64 PCS frame pointer */ |
| 47 | stp x29, x30, [sp, #-16]! |
| 48 | mov x29, sp |
| 49 | |
| 50 | /* store x8 */ |
| 51 | str x8, [sp, #-16]! |
| 52 | |
| 53 | /* syscall No. in x8 */ |
| 54 | mov x8, __NR_futex |
| 55 | svc #0 |
| 56 | |
| 57 | /* restore x8 */ |
| 58 | ldr x8, [sp], #16 |
| 59 | ldp x29, x30, [sp], #16 |
| 60 | |
| 61 | /* check if syscall returned successfully */ |
| 62 | cmn x0, #(MAX_ERRNO + 1) |
| 63 | cneg x0, x0, hi |
| 64 | b.hi __set_errno |
| 65 | |
| 66 | ret |
| 67 | END(__futex_syscall4) |
| 68 | |
| 69 | ENTRY(__futex_syscall3) |
| 70 | /* __futex_syscall4 but with fewer arguments */ |
| 71 | b __futex_syscall4 |
| 72 | END(__futex_syscall3) |
| 73 | |
| 74 | ENTRY(__futex_wait) |
| 75 | /* create AArch64 PCS frame pointer */ |
| 76 | stp x29, x30, [sp, #-16]! |
| 77 | mov x29, sp |
| 78 | |
| 79 | /* store x8 */ |
| 80 | str x8, [sp, #-16]! |
| 81 | |
| 82 | /* arange arguments as expected in the kernel side */ |
| 83 | mov x3, x2 |
| 84 | mov w2, w1 |
| 85 | mov w1, #FUTEX_WAIT |
| 86 | |
| 87 | /* syscall No. in X8 */ |
| 88 | mov x8, __NR_futex |
| 89 | svc #0 |
| 90 | |
| 91 | /* restore x8 */ |
| 92 | ldr x8, [sp], #16 |
| 93 | ldp x29, x30, [sp], #16 |
| 94 | |
| 95 | /* check if syscall returned successfully */ |
| 96 | cmn x0, #(MAX_ERRNO + 1) |
| 97 | cneg x0, x0, hi |
| 98 | b.hi __set_errno |
| 99 | |
| 100 | ret |
| 101 | END(__futex_wait) |
| 102 | |
| 103 | ENTRY(__futex_wake) |
| 104 | /* create AArch64 PCS frame pointer */ |
| 105 | stp x29, x30, [sp, #-16]! |
| 106 | mov x29, sp |
| 107 | |
| 108 | /* store x8 */ |
| 109 | str x8, [sp, #-16]! |
| 110 | |
| 111 | /* arange arguments as expected in the kernel side */ |
| 112 | mov w2, w1 |
| 113 | mov w1, #FUTEX_WAIT |
| 114 | |
| 115 | /* syscall No. in X8 */ |
| 116 | mov x8, __NR_futex |
| 117 | svc #0 |
| 118 | |
| 119 | /* restore x8 */ |
| 120 | ldr x8, [sp], #16 |
| 121 | ldp x29, x30, [sp], #16 |
| 122 | |
| 123 | /* check if syscall returned successfully */ |
| 124 | cmn x0, #(MAX_ERRNO + 1) |
| 125 | cneg x0, x0, hi |
| 126 | b.hi __set_errno |
| 127 | |
| 128 | ret |
| 129 | END(__futex_wake) |