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 * 3. 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
32 #include <machine/asmacros.h>
33 #include <machine/cputypes.h>
34 #include <machine/pmap.h>
35 #include <machine/specialreg.h>
45 * void bzero(void *buf, u_int len)
71 * The loop takes 14 bytes. Ensure that it doesn't cross a 16-byte
136 /* fillw(pat, base, cnt) */
149 * memmove(dst, src, cnt) (return dst)
150 * bcopy(src, dst, cnt)
151 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
173 cmpl %ecx,%eax /* overlapping && src < dst? */
176 shrl $2,%ecx /* copy by 32-bit words */
180 andl $3,%ecx /* any bytes left? */
185 movl 8(%ebp),%eax /* return dst for memmove */
191 addl %ecx,%edi /* copy backwards */
195 andl $3,%ecx /* any fractional bytes? */
199 movl 16(%ebp),%ecx /* copy remainder by 32-bit words */
208 movl 8(%ebp),%eax /* return dst for memmove */
214 * Note: memcpy does not support overlapping copies
223 shrl $2,%ecx /* copy by 32-bit words */
227 andl $3,%ecx /* any bytes left? */
236 * copystr(from, to, maxlen, int *lencopied) - MP SAFE
242 movl 12(%esp),%esi /* %esi = from */
243 movl 16(%esp),%edi /* %edi = to */
244 movl 20(%esp),%edx /* %edx = maxlen */
254 /* Success -- 0 byte reached */
259 /* edx is zero -- return ENAMETOOLONG */
260 movl $ENAMETOOLONG,%eax
263 /* set *lencopied and return %eax */
302 * Handling of special 386 registers and descriptor tables etc
304 /* void lgdt(struct region_descriptor *rdp); */
306 /* reload the descriptor table */
310 /* flush the prefetch q */
314 /* reload "stale" selectors */
323 /* reload code selector by turning return into intersegmental return */
331 /* ssdtosd(*ssdp,*sdp) */
353 /* void reset_dbregs() */
356 movl %eax,%dr7 /* disable all breakpoints first */
365 /*****************************************************************************/
366 /* setjump, longjump */
367 /*****************************************************************************/
371 movl %ebx,(%eax) /* save ebx */
372 movl %esp,4(%eax) /* save esp */
373 movl %ebp,8(%eax) /* save ebp */
374 movl %esi,12(%eax) /* save esi */
375 movl %edi,16(%eax) /* save edi */
376 movl (%esp),%edx /* get rta */
377 movl %edx,20(%eax) /* save eip */
378 xorl %eax,%eax /* return(0); */
384 movl (%eax),%ebx /* restore ebx */
385 movl 4(%eax),%esp /* restore esp */
386 movl 8(%eax),%ebp /* restore ebp */
387 movl 12(%eax),%esi /* restore esi */
388 movl 16(%eax),%edi /* restore edi */
389 movl 20(%eax),%edx /* get rta */
390 movl %edx,(%esp) /* put in return frame */
391 xorl %eax,%eax /* return(1); */
397 * Support for reading MSRs in the safe manner. (Instead of panic on #gp,
401 /* int rdmsr_safe(u_int msr, uint64_t *data) */
402 movl PCPU(CURPCB),%ecx
403 movl $msr_onfault,PCB_ONFAULT(%ecx)
412 movl PCPU(CURPCB),%ecx
413 movl %eax,PCB_ONFAULT(%ecx)
418 * Support for writing MSRs in the safe manner. (Instead of panic on #gp,
422 /* int wrmsr_safe(u_int msr, uint64_t data) */
423 movl PCPU(CURPCB),%ecx
424 movl $msr_onfault,PCB_ONFAULT(%ecx)
432 movl PCPU(CURPCB),%ecx
433 movl %eax,PCB_ONFAULT(%ecx)
438 * MSR operations fault handler
442 movl PCPU(CURPCB),%ecx
443 movl $0,PCB_ONFAULT(%ecx)
447 ENTRY(handle_ibrs_entry)
448 cmpb $0,hw_ibrs_active
450 movl $MSR_IA32_SPEC_CTRL,%ecx
452 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
453 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
455 movb $1,PCPU(IBPB_SET)
457 * i386 does not implement SMEP, but the 4/4 split makes this not
461 END(handle_ibrs_entry)
463 ENTRY(handle_ibrs_exit)
464 cmpb $0,PCPU(IBPB_SET)
467 movl $MSR_IA32_SPEC_CTRL,%ecx
469 andl $~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
470 andl $~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
473 movb $0,PCPU(IBPB_SET)
475 END(handle_ibrs_exit)