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>
51 * The loop takes 14 bytes. Ensure that it doesn't cross a 16-byte
116 /* fillw(pat, base, cnt) */
129 * memmove(dst, src, cnt) (return dst)
130 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
144 cmpl %ecx,%eax /* overlapping && src < dst? */
147 shrl $2,%ecx /* copy by 32-bit words */
151 andl $3,%ecx /* any bytes left? */
156 movl 8(%ebp),%eax /* return dst for memmove */
162 addl %ecx,%edi /* copy backwards */
166 andl $3,%ecx /* any fractional bytes? */
170 movl 16(%ebp),%ecx /* copy remainder by 32-bit words */
179 movl 8(%ebp),%eax /* return dst for memmove */
185 * Note: memcpy does not support overlapping copies
194 shrl $2,%ecx /* copy by 32-bit words */
198 andl $3,%ecx /* any bytes left? */
207 * Handling of special 386 registers and descriptor tables etc
209 /* void lgdt(struct region_descriptor *rdp); */
211 /* reload the descriptor table */
215 /* flush the prefetch q */
219 /* reload "stale" selectors */
228 /* reload code selector by turning return into intersegmental return */
235 /* ssdtosd(*ssdp,*sdp) */
257 /* void reset_dbregs() */
260 movl %eax,%dr7 /* disable all breakpoints first */
269 /*****************************************************************************/
270 /* setjump, longjump */
271 /*****************************************************************************/
275 movl %ebx,(%eax) /* save ebx */
276 movl %esp,4(%eax) /* save esp */
277 movl %ebp,8(%eax) /* save ebp */
278 movl %esi,12(%eax) /* save esi */
279 movl %edi,16(%eax) /* save edi */
280 movl (%esp),%edx /* get rta */
281 movl %edx,20(%eax) /* save eip */
282 xorl %eax,%eax /* return(0); */
288 movl (%eax),%ebx /* restore ebx */
289 movl 4(%eax),%esp /* restore esp */
290 movl 8(%eax),%ebp /* restore ebp */
291 movl 12(%eax),%esi /* restore esi */
292 movl 16(%eax),%edi /* restore edi */
293 movl 20(%eax),%edx /* get rta */
294 movl %edx,(%esp) /* put in return frame */
295 xorl %eax,%eax /* return(1); */
301 * Support for reading MSRs in the safe manner. (Instead of panic on #gp,
305 /* int rdmsr_safe(u_int msr, uint64_t *data) */
306 movl PCPU(CURPCB),%ecx
307 movl $msr_onfault,PCB_ONFAULT(%ecx)
316 movl PCPU(CURPCB),%ecx
317 movl %eax,PCB_ONFAULT(%ecx)
322 * Support for writing MSRs in the safe manner. (Instead of panic on #gp,
326 /* int wrmsr_safe(u_int msr, uint64_t data) */
327 movl PCPU(CURPCB),%ecx
328 movl $msr_onfault,PCB_ONFAULT(%ecx)
336 movl PCPU(CURPCB),%ecx
337 movl %eax,PCB_ONFAULT(%ecx)
342 * MSR operations fault handler
346 movl PCPU(CURPCB),%ecx
347 movl $0,PCB_ONFAULT(%ecx)
352 .macro rsb_seq_label l
355 .macro rsb_call_label l
373 ENTRY(handle_ibrs_entry)
374 cmpb $0,hw_ibrs_ibpb_active
376 movl $MSR_IA32_SPEC_CTRL,%ecx
378 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
379 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
381 movb $1,PCPU(IBPB_SET)
383 * i386 does not implement SMEP.
386 END(handle_ibrs_entry)
388 ENTRY(handle_ibrs_exit)
389 cmpb $0,PCPU(IBPB_SET)
391 movl $MSR_IA32_SPEC_CTRL,%ecx
393 andl $~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
394 andl $~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
396 movb $0,PCPU(IBPB_SET)
398 END(handle_ibrs_exit)
400 ENTRY(mds_handler_void)
402 END(mds_handler_void)
404 ENTRY(mds_handler_verw)
410 END(mds_handler_verw)
412 ENTRY(mds_handler_ivb)
417 1: movl PCPU(MDS_BUF), %edx
418 movdqa %xmm0, PCPU(MDS_TMP)
427 2: movntdq %xmm0, (%edx)
433 movdqa PCPU(MDS_TMP),%xmm0
440 ENTRY(mds_handler_bdw)
445 1: movl PCPU(MDS_BUF), %ebx
446 movdqa %xmm0, PCPU(MDS_TMP)
452 2: movntdq %xmm0, (%ebx)
461 movdqa PCPU(MDS_TMP),%xmm0
468 ENTRY(mds_handler_skl_sse)
473 1: movl PCPU(MDS_BUF), %edi
474 movl PCPU(MDS_BUF64), %edx
475 movdqa %xmm0, PCPU(MDS_TMP)
482 2: clflushopt 5376(%edi, %eax, 8)
492 movdqa PCPU(MDS_TMP), %xmm0
497 END(mds_handler_skl_sse)
499 ENTRY(mds_handler_skl_avx)
504 1: movl PCPU(MDS_BUF), %edi
505 movl PCPU(MDS_BUF64), %edx
506 vmovdqa %ymm0, PCPU(MDS_TMP)
507 vpxor %ymm0, %ymm0, %ymm0
510 vorpd (%edx), %ymm0, %ymm0
511 vorpd (%edx), %ymm0, %ymm0
513 2: clflushopt 5376(%edi, %eax, 8)
523 vmovdqa PCPU(MDS_TMP), %ymm0
528 END(mds_handler_skl_avx)
530 ENTRY(mds_handler_skl_avx512)
535 1: movl PCPU(MDS_BUF), %edi
536 movl PCPU(MDS_BUF64), %edx
537 vmovdqa64 %zmm0, PCPU(MDS_TMP)
538 vpxord %zmm0, %zmm0, %zmm0
541 vorpd (%edx), %zmm0, %zmm0
542 vorpd (%edx), %zmm0, %zmm0
544 2: clflushopt 5376(%edi, %eax, 8)
554 vmovdqa64 PCPU(MDS_TMP), %zmm0
559 END(mds_handler_skl_avx512)
561 ENTRY(mds_handler_silvermont)
566 1: movl PCPU(MDS_BUF), %edx
567 movdqa %xmm0, PCPU(MDS_TMP)
571 2: movntdq %xmm0, (%edx)
577 movdqa PCPU(MDS_TMP),%xmm0
582 END(mds_handler_silvermont)