1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2007 Konstantin Belousov 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31#include "linux_assym.h" /* system definitions */ 32#include <machine/asmacros.h> /* miscellaneous asm macros */ 33 34#include "assym.s" 35 36futex_fault: 37 movq $0,PCB_ONFAULT(%r8) 38 movl $-EFAULT,%eax 39 ret 40 41ENTRY(futex_xchgl) 42 movq PCPU(CURPCB),%r8 43 movq $futex_fault,PCB_ONFAULT(%r8) 44 movq $VM_MAXUSER_ADDRESS-4,%rax 45 cmpq %rax,%rsi 46 ja futex_fault 47 xchgl %edi,(%rsi) 48 movl %edi,(%rdx) 49 xorl %eax,%eax 50 movq %rax,PCB_ONFAULT(%r8) 51 ret 52 53ENTRY(futex_addl) 54 movq PCPU(CURPCB),%r8 55 movq $futex_fault,PCB_ONFAULT(%r8) 56 movq $VM_MAXUSER_ADDRESS-4,%rax 57 cmpq %rax,%rsi 58 ja futex_fault 59#ifdef SMP 60 lock 61#endif 62 xaddl %edi,(%rsi) 63 movl %edi,(%rdx) 64 xorl %eax,%eax 65 movq %rax,PCB_ONFAULT(%r8) 66 ret 67 68ENTRY(futex_orl) 69 movq PCPU(CURPCB),%r8 70 movq $futex_fault,PCB_ONFAULT(%r8) 71 movq $VM_MAXUSER_ADDRESS-4,%rax 72 cmpq %rax,%rsi 73 ja futex_fault 74 movl (%rsi),%eax 751: movl %eax,%ecx 76 orl %edi,%ecx 77#ifdef SMP 78 lock 79#endif 80 cmpxchgl %ecx,(%rsi) 81 jnz 1b 82 movl %eax,(%rdx) 83 xorl %eax,%eax 84 movq %rax,PCB_ONFAULT(%r8) 85 ret 86 87ENTRY(futex_andl) 88 movq PCPU(CURPCB),%r8 89 movq $futex_fault,PCB_ONFAULT(%r8) 90 movq $VM_MAXUSER_ADDRESS-4,%rax 91 cmpq %rax,%rsi 92 ja futex_fault 93 movl (%rsi),%eax 941: movl %eax,%ecx 95 andl %edi,%ecx 96#ifdef SMP 97 lock 98#endif 99 cmpxchgl %ecx,(%rsi) 100 jnz 1b 101 movl %eax,(%rdx) 102 xorl %eax,%eax 103 movq %rax,PCB_ONFAULT(%r8) 104 ret 105 106ENTRY(futex_xorl) 107 movq PCPU(CURPCB),%r8 108 movq $futex_fault,PCB_ONFAULT(%r8) 109 movq $VM_MAXUSER_ADDRESS-4,%rax 110 cmpq %rax,%rsi 111 ja futex_fault 112 movl (%rsi),%eax 1131: movl %eax,%ecx 114 xorl %edi,%ecx 115#ifdef SMP 116 lock 117#endif 118 cmpxchgl %ecx,(%rsi) 119 jnz 1b 120 movl %eax,(%rdx) 121 xorl %eax,%eax 122 movq %rax,PCB_ONFAULT(%r8) 123 ret 124