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