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.inc" 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 52END(futex_xchgl) 53 54ENTRY(futex_addl) 55 movq PCPU(CURPCB),%r8 56 movq $futex_fault,PCB_ONFAULT(%r8) 57 movq $VM_MAXUSER_ADDRESS-4,%rax 58 cmpq %rax,%rsi 59 ja futex_fault 60#ifdef SMP 61 lock 62#endif 63 xaddl %edi,(%rsi) 64 movl %edi,(%rdx) 65 xorl %eax,%eax 66 movq %rax,PCB_ONFAULT(%r8) 67 ret 68END(futex_addl) 69 70ENTRY(futex_orl) 71 movq PCPU(CURPCB),%r8 72 movq $futex_fault,PCB_ONFAULT(%r8) 73 movq $VM_MAXUSER_ADDRESS-4,%rax 74 cmpq %rax,%rsi 75 ja futex_fault 76 movl (%rsi),%eax 771: movl %eax,%ecx 78 orl %edi,%ecx 79#ifdef SMP 80 lock 81#endif 82 cmpxchgl %ecx,(%rsi) 83 jnz 1b 84 movl %eax,(%rdx) 85 xorl %eax,%eax 86 movq %rax,PCB_ONFAULT(%r8) 87 ret 88END(futex_orl) 89 90ENTRY(futex_andl) 91 movq PCPU(CURPCB),%r8 92 movq $futex_fault,PCB_ONFAULT(%r8) 93 movq $VM_MAXUSER_ADDRESS-4,%rax 94 cmpq %rax,%rsi 95 ja futex_fault 96 movl (%rsi),%eax 971: movl %eax,%ecx 98 andl %edi,%ecx 99#ifdef SMP 100 lock 101#endif 102 cmpxchgl %ecx,(%rsi) 103 jnz 1b 104 movl %eax,(%rdx) 105 xorl %eax,%eax 106 movq %rax,PCB_ONFAULT(%r8) 107 ret 108END(futex_andl) 109 110ENTRY(futex_xorl) 111 movq PCPU(CURPCB),%r8 112 movq $futex_fault,PCB_ONFAULT(%r8) 113 movq $VM_MAXUSER_ADDRESS-4,%rax 114 cmpq %rax,%rsi 115 ja futex_fault 116 movl (%rsi),%eax 1171: movl %eax,%ecx 118 xorl %edi,%ecx 119#ifdef SMP 120 lock 121#endif 122 cmpxchgl %ecx,(%rsi) 123 jnz 1b 124 movl %eax,(%rdx) 125 xorl %eax,%eax 126 movq %rax,PCB_ONFAULT(%r8) 127 ret 128END(futex_xorl) 129