diff options
author | kib <kib@FreeBSD.org> | 2007-05-23 08:33:06 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2007-05-23 08:33:06 +0000 |
commit | cdee790df9aefa589048c813a730fb95c714bd3a (patch) | |
tree | 9e0211f55a99ffc4fef4f84e9c3b74e63cc9cbc6 /sys/i386 | |
parent | 253a9fb8b6b9af702912dffa3b9addcd79d4618b (diff) | |
download | FreeBSD-src-cdee790df9aefa589048c813a730fb95c714bd3a.zip FreeBSD-src-cdee790df9aefa589048c813a730fb95c714bd3a.tar.gz |
Move futex support code from <arch>/support.s into linux compat directory.
Implement all futex atomic operations in assembler to not depend on the
fuword() that does not allow to distinguish between -1 and failure return.
Correctly return 0 from atomic operations on success.
In collaboration with: rdivacky
Tested by: Scot Hetzel <swhetzel gmail com>, Milos Vyletel <mvyletel mzm cz>
Sponsored by: Google SoC 2007
Diffstat (limited to 'sys/i386')
-rw-r--r-- | sys/i386/i386/support.s | 45 | ||||
-rw-r--r-- | sys/i386/linux/linux_support.s | 127 |
2 files changed, 127 insertions, 45 deletions
diff --git a/sys/i386/i386/support.s b/sys/i386/i386/support.s index 7d49f01..0f34525 100644 --- a/sys/i386/i386/support.s +++ b/sys/i386/i386/support.s @@ -1513,51 +1513,6 @@ ENTRY(longjmp) incl %eax ret -/*****************************************************************************/ -/* linux_futex support */ -/*****************************************************************************/ - -futex_fault: - movl $0,PCB_ONFAULT(%ecx) - movl $-EFAULT,%eax - ret - -ENTRY(futex_xchgl) - movl PCPU(CURPCB),%ecx - movl $futex_fault,PCB_ONFAULT(%ecx) - movl 4(%esp),%eax - movl 8(%esp),%edx - cmpl $VM_MAXUSER_ADDRESS-4,%edx - ja futex_fault - -#ifdef SMP - lock -#endif - xchgl %eax,(%edx) - movl 12(%esp),%edx - movl %eax,(%edx) - xorl %eax,%eax - movl $0,PCB_ONFAULT(%ecx) - ret - -ENTRY(futex_addl) - movl PCPU(CURPCB),%ecx - movl $futex_fault,PCB_ONFAULT(%ecx) - movl 4(%esp),%eax - movl 8(%esp),%edx - cmpl $VM_MAXUSER_ADDRESS-4,%edx - ja futex_fault - -#ifdef SMP - lock -#endif - xaddl %eax,(%edx) - movl 12(%esp),%edx - movl %eax,(%edx) - xorl %eax,%eax - movl $0,PCB_ONFAULT(%ecx) - ret - /* * Support for BB-profiling (gcc -a). The kernbb program will extract * the data from the kernel. diff --git a/sys/i386/linux/linux_support.s b/sys/i386/linux/linux_support.s new file mode 100644 index 0000000..171d6e7 --- /dev/null +++ b/sys/i386/linux/linux_support.s @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2006,2007 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include "linux_assym.h" /* system definitions */ +#include <machine/asmacros.h> /* miscellaneous asm macros */ + +#include "assym.s" + +futex_fault_decx: + movl PCPU(CURPCB),%ecx +futex_fault: + movl $0,PCB_ONFAULT(%ecx) + movl $-EFAULT,%eax + ret + +ENTRY(futex_xchgl) + movl PCPU(CURPCB),%ecx + movl $futex_fault,PCB_ONFAULT(%ecx) + movl 4(%esp),%eax + movl 8(%esp),%edx + cmpl $VM_MAXUSER_ADDRESS-4,%edx + ja futex_fault + xchgl %eax,(%edx) + movl 12(%esp),%edx + movl %eax,(%edx) + xorl %eax,%eax + movl %eax,PCB_ONFAULT(%ecx) + ret + +ENTRY(futex_addl) + movl PCPU(CURPCB),%ecx + movl $futex_fault,PCB_ONFAULT(%ecx) + movl 4(%esp),%eax + movl 8(%esp),%edx + cmpl $VM_MAXUSER_ADDRESS-4,%edx + ja futex_fault +#ifdef SMP + lock +#endif + xaddl %eax,(%edx) + movl 12(%esp),%edx + movl %eax,(%edx) + xorl %eax,%eax + movl %eax,PCB_ONFAULT(%ecx) + ret + +ENTRY(futex_orl) + movl PCPU(CURPCB),%ecx + movl $futex_fault_decx,PCB_ONFAULT(%ecx) + movl 8(%esp),%edx + cmpl $VM_MAXUSER_ADDRESS-4,%edx + ja futex_fault + movl (%edx),%eax +1: movl %eax,%ecx + orl 4(%esp),%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%edx) + jnz 1b +futex_tail: + movl 12(%esp),%edx + movl %eax,(%edx) + xorl %eax,%eax + movl PCPU(CURPCB),%ecx + movl %eax,PCB_ONFAULT(%ecx) + ret + +ENTRY(futex_andl) + movl PCPU(CURPCB),%ecx + movl $futex_fault_decx,PCB_ONFAULT(%ecx) + movl 8(%esp),%edx + cmpl $VM_MAXUSER_ADDRESS-4,%edx + ja futex_fault + movl (%edx),%eax +1: movl %eax,%ecx + andl 4(%esp),%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%edx) + jnz 1b + jmp futex_tail + +ENTRY(futex_xorl) + movl PCPU(CURPCB),%ecx + movl $futex_fault_decx,PCB_ONFAULT(%ecx) + movl 8(%esp),%edx + cmpl $VM_MAXUSER_ADDRESS-4,%edx + ja futex_fault + movl (%edx),%eax +1: movl %eax,%ecx + xorl 4(%esp),%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%edx) + jnz 1b + jmp futex_tail |