2 * Copyright (c) 1993 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <machine/asmacros.h>
35 #include <machine/cputypes.h>
36 #include <machine/intr_machdep.h>
37 #include <machine/pmap.h>
38 #include <machine/specialreg.h>
46 .globl intrcnt, eintrcnt
48 .space INTRCNT_COUNT * 4
51 .globl intrnames, eintrnames
53 .space INTRCNT_COUNT * (MAXCOMLEN + 1)
60 * void bzero(void *buf, u_int len)
146 /* fillw(pat, base, cnt) */
167 cmpl %ecx,%eax /* overlapping && src < dst? */
169 cld /* nope, copy forwards */
178 addl %ecx,%edi /* copy backwards. */
192 * bcopy(src, dst, cnt)
193 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
204 cmpl %ecx,%eax /* overlapping && src < dst? */
207 shrl $2,%ecx /* copy by 32-bit words */
208 cld /* nope, copy forwards */
212 andl $3,%ecx /* any bytes left? */
221 addl %ecx,%edi /* copy backwards */
225 andl $3,%ecx /* any fractional bytes? */
229 movl 20(%esp),%ecx /* copy remainder by 32-bit words */
242 * Note: memcpy does not support overlapping copies
251 shrl $2,%ecx /* copy by 32-bit words */
252 cld /* nope, copy forwards */
256 andl $3,%ecx /* any bytes left? */
264 /*****************************************************************************/
265 /* copyout and fubyte family */
266 /*****************************************************************************/
268 * Access user memory from inside the kernel. These routines and possibly
269 * the math- and DOS emulators should be the only places that do this.
271 * We have to access the memory with user's permissions, so use a segment
272 * selector with RPL 3. For writes to user space we have to additionally
273 * check the PTE for write permission, because the 386 does not check
274 * write permissions when we are executing with EPL 0. The 486 does check
275 * this if the WP bit is set in CR0, so we can use a simpler version here.
277 * These routines set curpcb->onfault for the time they execute. When a
278 * protection violation occurs inside the functions, the trap handler
279 * returns to *curpcb->onfault instead of the function.
283 * copyout(from_kernel, to_user, len) - MP SAFE
286 movl PCPU(CURPCB),%eax
287 movl $copyout_fault,PCB_ONFAULT(%eax)
294 testl %ebx,%ebx /* anything to do? */
298 * Check explicitly for non-user addresses. If 486 write protection
299 * is being used, this check is essential because we are in kernel
300 * mode so the h/w does not provide any protection against writing
305 * First, prevent address wrapping.
311 * XXX STOP USING VM_MAXUSER_ADDRESS.
312 * It is an end address, not a max, so every time it is used correctly it
313 * looks like there is an off by one error, and of course it caused an off
314 * by one error in several places.
316 cmpl $VM_MAXUSER_ADDRESS,%eax
319 /* bcopy(%esi, %edi, %ebx) */
336 movl PCPU(CURPCB),%edx
337 movl %eax,PCB_ONFAULT(%edx)
346 movl PCPU(CURPCB),%edx
347 movl $0,PCB_ONFAULT(%edx)
352 * copyin(from_user, to_kernel, len) - MP SAFE
355 movl PCPU(CURPCB),%eax
356 movl $copyin_fault,PCB_ONFAULT(%eax)
359 movl 12(%esp),%esi /* caddr_t from */
360 movl 16(%esp),%edi /* caddr_t to */
361 movl 20(%esp),%ecx /* size_t len */
364 * make sure address is valid
369 cmpl $VM_MAXUSER_ADDRESS,%edx
373 shrl $2,%ecx /* copy longword-wise */
378 andb $3,%cl /* copy remaining bytes */
385 movl PCPU(CURPCB),%edx
386 movl %eax,PCB_ONFAULT(%edx)
394 movl PCPU(CURPCB),%edx
395 movl $0,PCB_ONFAULT(%edx)
400 * casuword. Compare and set user word. Returns -1 or the current value.
405 movl PCPU(CURPCB),%ecx
406 movl $fusufault,PCB_ONFAULT(%ecx)
407 movl 4(%esp),%edx /* dst */
408 movl 8(%esp),%eax /* old */
409 movl 12(%esp),%ecx /* new */
411 cmpl $VM_MAXUSER_ADDRESS-4,%edx /* verify address is valid */
417 cmpxchgl %ecx,(%edx) /* Compare and set. */
420 * The old value is in %eax. If the store succeeded it will be the
421 * value we expected (old) from before the store, otherwise it will
422 * be the current value.
425 movl PCPU(CURPCB),%ecx
426 movl $fusufault,PCB_ONFAULT(%ecx)
427 movl $0,PCB_ONFAULT(%ecx)
433 * Fetch (load) a 32-bit word, a 16-bit word, or an 8-bit byte from user
434 * memory. All these functions are MPSAFE.
439 movl PCPU(CURPCB),%ecx
440 movl $fusufault,PCB_ONFAULT(%ecx)
441 movl 4(%esp),%edx /* from */
443 cmpl $VM_MAXUSER_ADDRESS-4,%edx /* verify address is valid */
447 movl $0,PCB_ONFAULT(%ecx)
453 * fuswintr() and suswintr() are specialized variants of fuword16() and
454 * suword16(), respectively. They are called from the profiling code,
455 * potentially at interrupt time. If they fail, that's okay; good things
456 * will happen later. They always fail for now, until the trap code is
457 * able to deal with this.
467 movl PCPU(CURPCB),%ecx
468 movl $fusufault,PCB_ONFAULT(%ecx)
471 cmpl $VM_MAXUSER_ADDRESS-2,%edx
475 movl $0,PCB_ONFAULT(%ecx)
480 movl PCPU(CURPCB),%ecx
481 movl $fusufault,PCB_ONFAULT(%ecx)
484 cmpl $VM_MAXUSER_ADDRESS-1,%edx
488 movl $0,PCB_ONFAULT(%ecx)
494 movl PCPU(CURPCB),%ecx
496 movl %eax,PCB_ONFAULT(%ecx)
501 * Store a 32-bit word, a 16-bit word, or an 8-bit byte to user memory.
502 * All these functions are MPSAFE.
507 movl PCPU(CURPCB),%ecx
508 movl $fusufault,PCB_ONFAULT(%ecx)
511 cmpl $VM_MAXUSER_ADDRESS-4,%edx /* verify address validity */
517 movl PCPU(CURPCB),%ecx
518 movl %eax,PCB_ONFAULT(%ecx)
524 movl PCPU(CURPCB),%ecx
525 movl $fusufault,PCB_ONFAULT(%ecx)
528 cmpl $VM_MAXUSER_ADDRESS-2,%edx /* verify address validity */
534 movl PCPU(CURPCB),%ecx /* restore trashed register */
535 movl %eax,PCB_ONFAULT(%ecx)
540 movl PCPU(CURPCB),%ecx
541 movl $fusufault,PCB_ONFAULT(%ecx)
544 cmpl $VM_MAXUSER_ADDRESS-1,%edx /* verify address validity */
550 movl PCPU(CURPCB),%ecx /* restore trashed register */
551 movl %eax,PCB_ONFAULT(%ecx)
556 * copyinstr(from, to, maxlen, int *lencopied) - MP SAFE
558 * copy a string from from to to, stop when a 0 character is reached.
559 * return ENAMETOOLONG if string is longer than maxlen, and
560 * EFAULT on protection violations. If lencopied is non-zero,
561 * return the actual length in *lencopied.
566 movl PCPU(CURPCB),%ecx
567 movl $cpystrflt,PCB_ONFAULT(%ecx)
569 movl 12(%esp),%esi /* %esi = from */
570 movl 16(%esp),%edi /* %edi = to */
571 movl 20(%esp),%edx /* %edx = maxlen */
573 movl $VM_MAXUSER_ADDRESS,%eax
575 /* make sure 'from' is within bounds */
579 /* restrict maxlen to <= VM_MAXUSER_ADDRESS-from */
597 /* Success -- 0 byte reached */
602 /* edx is zero - return ENAMETOOLONG or EFAULT */
603 cmpl $VM_MAXUSER_ADDRESS,%esi
606 movl $ENAMETOOLONG,%eax
613 /* set *lencopied and return %eax */
614 movl PCPU(CURPCB),%ecx
615 movl $0,PCB_ONFAULT(%ecx)
629 * copystr(from, to, maxlen, int *lencopied) - MP SAFE
635 movl 12(%esp),%esi /* %esi = from */
636 movl 16(%esp),%edi /* %edi = to */
637 movl 20(%esp),%edx /* %edx = maxlen */
648 /* Success -- 0 byte reached */
653 /* edx is zero -- return ENAMETOOLONG */
654 movl $ENAMETOOLONG,%eax
657 /* set *lencopied and return %eax */
679 cld /* compare forwards */
697 * Handling of special 386 registers and descriptor tables etc
699 /* void lgdt(struct region_descriptor *rdp); */
702 /* reload the descriptor table */
707 /* flush the prefetch q */
711 /* reload "stale" selectors */
720 /* reload code selector by turning return into intersegmental return */
728 /* ssdtosd(*ssdp,*sdp) */
750 /* void reset_dbregs() */
753 movl %eax,%dr7 /* disable all breapoints first */
762 /*****************************************************************************/
763 /* setjump, longjump */
764 /*****************************************************************************/
768 movl %ebx,(%eax) /* save ebx */
769 movl %esp,4(%eax) /* save esp */
770 movl %ebp,8(%eax) /* save ebp */
771 movl %esi,12(%eax) /* save esi */
772 movl %edi,16(%eax) /* save edi */
773 movl (%esp),%edx /* get rta */
774 movl %edx,20(%eax) /* save eip */
775 xorl %eax,%eax /* return(0); */
781 movl (%eax),%ebx /* restore ebx */
782 movl 4(%eax),%esp /* restore esp */
783 movl 8(%eax),%ebp /* restore ebp */
784 movl 12(%eax),%esi /* restore esi */
785 movl 16(%eax),%edi /* restore edi */
786 movl 20(%eax),%edx /* get rta */
787 movl %edx,(%esp) /* put in return frame */
788 xorl %eax,%eax /* return(1); */
794 * Support for BB-profiling (gcc -a). The kernbb program will extract
795 * the data from the kernel.
805 NON_GPROF_ENTRY(__bb_init_func)
814 * Support for reading MSRs in the safe manner.
817 /* int rdmsr_safe(u_int msr, uint64_t *data) */
818 movl PCPU(CURPCB),%ecx
819 movl $msr_onfault,PCB_ONFAULT(%ecx)
828 movl PCPU(CURPCB),%ecx
829 movl %eax,PCB_ONFAULT(%ecx)
834 * Support for writing MSRs in the safe manner.
837 /* int wrmsr_safe(u_int msr, uint64_t data) */
838 movl PCPU(CURPCB),%ecx
839 movl $msr_onfault,PCB_ONFAULT(%ecx)
847 movl PCPU(CURPCB),%ecx
848 movl %eax,PCB_ONFAULT(%ecx)
853 * MSR operations fault handler
857 movl PCPU(CURPCB),%ecx
858 movl $0,PCB_ONFAULT(%ecx)