Changeset View
Changeset View
Standalone View
Standalone View
sys/i386/i386/copyout_fast.s
- This file was added.
/*- | |||||
* Copyright (c) 1993 The Regents of the University of California. | |||||
* All rights reserved. | |||||
* Copyright (c) 2018 The FreeBSD Foundation | |||||
* All rights reserved. | |||||
* | |||||
* Portions of this software were developed by Konstantin Belousov | |||||
* <kib@FreeBSD.org> under sponsorship from the FreeBSD Foundation. | |||||
* | |||||
* 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. | |||||
* 3. 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: head/sys/i386/i386/support.s 331254 2018-03-20 17:58:51Z emaste $ | |||||
*/ | |||||
#include <machine/asmacros.h> | |||||
#include <machine/cputypes.h> | |||||
#include <machine/pmap.h> | |||||
#include <machine/specialreg.h> | |||||
#include "assym.inc" | |||||
.text | |||||
ENTRY(copyout_fast) | |||||
movl PCPU(CURPCB),%eax | |||||
movl $copyout_fault,PCB_ONFAULT(%eax) | |||||
pushl %esi | |||||
pushl %edi | |||||
pushl %ebx | |||||
movl 16(%esp),%esi | |||||
movl 20(%esp),%edi | |||||
movl 24(%esp),%ebx | |||||
testl %ebx,%ebx /* anything to do? */ | |||||
jz done_copyout | |||||
/* | |||||
* Check explicitly for non-user addresses. This check is essential | |||||
* because it prevents usermode from writing into the kernel. We do | |||||
* not verify anywhere else that the user did not specify a rogue | |||||
* address. | |||||
*/ | |||||
/* | |||||
* First, prevent address wrapping. | |||||
*/ | |||||
movl %edi,%eax | |||||
addl %ebx,%eax | |||||
jc copyout_fault | |||||
cmpl $VM_MAXUSER_ADDRESS,%eax | |||||
ja copyout_fault | |||||
/* bcopy(%esi, %edi, %ebx) */ | |||||
movl %ebx,%ecx | |||||
shrl $2,%ecx | |||||
rep | |||||
movsl | |||||
movb %bl,%cl | |||||
andb $3,%cl | |||||
rep | |||||
movsb | |||||
done_copyout: | |||||
popl %ebx | |||||
popl %edi | |||||
popl %esi | |||||
xorl %eax,%eax | |||||
movl PCPU(CURPCB),%edx | |||||
movl %eax,PCB_ONFAULT(%edx) | |||||
ret | |||||
END(copyout_fast) | |||||
ALIGN_TEXT | |||||
copyout_fault: | |||||
popl %ebx | |||||
popl %edi | |||||
popl %esi | |||||
movl PCPU(CURPCB),%edx | |||||
movl $0,PCB_ONFAULT(%edx) | |||||
movl $EFAULT,%eax | |||||
ret | |||||
/* | |||||
* copyin(from_user, to_kernel, len) - MP SAFE | |||||
*/ | |||||
ENTRY(copyin_fast) | |||||
movl PCPU(CURPCB),%eax | |||||
movl $copyin_fault,PCB_ONFAULT(%eax) | |||||
pushl %esi | |||||
pushl %edi | |||||
movl 12(%esp),%esi /* caddr_t from */ | |||||
movl 16(%esp),%edi /* caddr_t to */ | |||||
movl 20(%esp),%ecx /* size_t len */ | |||||
/* | |||||
* make sure address is valid | |||||
*/ | |||||
movl %esi,%edx | |||||
addl %ecx,%edx | |||||
jc copyin_fault | |||||
cmpl $VM_MAXUSER_ADDRESS,%edx | |||||
ja copyin_fault | |||||
movb %cl,%al | |||||
shrl $2,%ecx /* copy longword-wise */ | |||||
rep | |||||
movsl | |||||
movb %al,%cl | |||||
andb $3,%cl /* copy remaining bytes */ | |||||
rep | |||||
movsb | |||||
popl %edi | |||||
popl %esi | |||||
xorl %eax,%eax | |||||
movl PCPU(CURPCB),%edx | |||||
movl %eax,PCB_ONFAULT(%edx) | |||||
ret | |||||
END(copyin_fast) | |||||
ALIGN_TEXT | |||||
copyin_fault: | |||||
popl %edi | |||||
popl %esi | |||||
movl PCPU(CURPCB),%edx | |||||
movl $0,PCB_ONFAULT(%edx) | |||||
movl $EFAULT,%eax | |||||
ret | |||||
/* | |||||
* casueword. Compare and set user word. Returns -1 on fault, | |||||
* 0 on non-faulting access. The current value is in *oldp. | |||||
*/ | |||||
ALTENTRY(casueword32_fast) | |||||
ENTRY(casueword_fast) | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $fusufault,PCB_ONFAULT(%ecx) | |||||
movl 4(%esp),%edx /* dst */ | |||||
movl 8(%esp),%eax /* old */ | |||||
movl 16(%esp),%ecx /* new */ | |||||
cmpl $VM_MAXUSER_ADDRESS-4,%edx /* verify address is valid */ | |||||
ja fusufault | |||||
#ifdef SMP | |||||
lock | |||||
#endif | |||||
cmpxchgl %ecx,(%edx) /* Compare and set. */ | |||||
/* | |||||
* The old value is in %eax. If the store succeeded it will be the | |||||
* value we expected (old) from before the store, otherwise it will | |||||
* be the current value. | |||||
*/ | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $0,PCB_ONFAULT(%ecx) | |||||
movl 12(%esp),%edx /* oldp */ | |||||
movl %eax,(%edx) | |||||
xorl %eax,%eax | |||||
ret | |||||
END(casueword32_fast) | |||||
END(casueword_fast) | |||||
/* | |||||
* Fetch (load) a 32-bit word, a 16-bit word, or an 8-bit byte from user | |||||
* memory. | |||||
*/ | |||||
ALTENTRY(fueword32_fast) | |||||
ENTRY(fueword_fast) | |||||
pushl %ebp | |||||
movl %esp,%ebp | |||||
pushl %ebx | |||||
pushl %esi | |||||
movl 8(%ebp),%edx /* from */ | |||||
movl PCPU(CURPCB),%eax | |||||
movl PCB_CR3(%eax),%eax | |||||
movl $fusufault,%ecx | |||||
movl 16(%ebp),%ebx | |||||
movl %esp,%esi | |||||
cli | |||||
movl PCPU(TRAMPSTK),%esp | |||||
movl %eax,%cr3 | |||||
movl (%edx),%eax | |||||
movl %ebx,%cr3 | |||||
movl %esi,%esp | |||||
sti | |||||
movl 12(%ebp),%edx | |||||
movl %eax,(%edx) | |||||
xorl %eax,%eax | |||||
popl %esi | |||||
popl %ebx | |||||
leave | |||||
ret | |||||
END(fueword32_fast) | |||||
END(fueword_fast) | |||||
ENTRY(fuword16_fast) | |||||
pushl %ebp | |||||
movl %esp,%ebp | |||||
pushl %ebx | |||||
pushl %esi | |||||
movl 8(%ebp),%edx /* from */ | |||||
movl PCPU(CURPCB),%eax | |||||
movl PCB_CR3(%eax),%eax | |||||
movl $fusufault,%ecx | |||||
movl 12(%ebp),%ebx | |||||
movl %esp,%esi | |||||
cli | |||||
movl PCPU(TRAMPSTK),%esp | |||||
movl %eax,%cr3 | |||||
movzwl (%edx),%eax | |||||
movl %ebx,%cr3 | |||||
movl %esi,%esp | |||||
sti | |||||
popl %esi | |||||
popl %ebx | |||||
leave | |||||
ret | |||||
END(fuword16_fast) | |||||
ENTRY(fubyte_fast) | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $fusufault,PCB_ONFAULT(%ecx) /* not in trampoline */ | |||||
movl 4(%esp),%edx | |||||
cmpl $VM_MAXUSER_ADDRESS-1,%edx | |||||
ja fusufault | |||||
movzbl (%edx),%eax | |||||
movl $0,PCB_ONFAULT(%ecx) | |||||
ret | |||||
END(fubyte_fast) | |||||
ALIGN_TEXT | |||||
fusufault: | |||||
movl %esi,%esp | |||||
sti | |||||
xorl %eax,%eax | |||||
decl %eax | |||||
popl %esi | |||||
popl %ebx | |||||
leave | |||||
ret | |||||
/* | |||||
* Store a 32-bit word, a 16-bit word, or an 8-bit byte to user memory. | |||||
* All these functions are MPSAFE. | |||||
*/ | |||||
ALTENTRY(suword32_fast) | |||||
ENTRY(suword_fast) | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $fusufault,PCB_ONFAULT(%ecx) | |||||
movl 4(%esp),%edx | |||||
cmpl $VM_MAXUSER_ADDRESS-4,%edx /* verify address validity */ | |||||
ja fusufault | |||||
movl 8(%esp),%eax | |||||
movl %eax,(%edx) | |||||
xorl %eax,%eax | |||||
movl PCPU(CURPCB),%ecx | |||||
movl %eax,PCB_ONFAULT(%ecx) | |||||
ret | |||||
END(suword32_fast) | |||||
END(suword_fast) | |||||
ENTRY(suword16_fast) | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $fusufault,PCB_ONFAULT(%ecx) | |||||
movl 4(%esp),%edx | |||||
cmpl $VM_MAXUSER_ADDRESS-2,%edx /* verify address validity */ | |||||
ja fusufault | |||||
movw 8(%esp),%ax | |||||
movw %ax,(%edx) | |||||
xorl %eax,%eax | |||||
movl PCPU(CURPCB),%ecx /* restore trashed register */ | |||||
movl %eax,PCB_ONFAULT(%ecx) | |||||
ret | |||||
END(suword16_fast) | |||||
ENTRY(subyte_fast) | |||||
movl PCPU(CURPCB),%ecx | |||||
movl $fusufault,PCB_ONFAULT(%ecx) | |||||
movl 4(%esp),%edx | |||||
cmpl $VM_MAXUSER_ADDRESS-1,%edx /* verify address validity */ | |||||
ja fusufault | |||||
movb 8(%esp),%al | |||||
movb %al,(%edx) | |||||
xorl %eax,%eax | |||||
movl PCPU(CURPCB),%ecx /* restore trashed register */ | |||||
movl %eax,PCB_ONFAULT(%ecx) | |||||
ret | |||||
END(subyte_fast) |