1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright 2019 Joyent, Inc.
  28  */
  29 
  30 #include <sys/asm_linkage.h>
  31 #include <sys/asm_misc.h>
  32 #include <sys/regset.h>
  33 #include <sys/panic.h>
  34 #include <sys/ontrap.h>
  35 #include <sys/privregs.h>
  36 #include <sys/segments.h>
  37 #include <sys/trap.h>
  38 
  39 #include "assym.h"
  40 
  41         ENTRY_NP(rd_idtr)
  42         sidt    (%rdi)
  43         ret
  44         SET_SIZE(rd_idtr)
  45 
  46         ENTRY_NP(wr_idtr)
  47         lidt    (%rdi)
  48         ret
  49         SET_SIZE(wr_idtr)
  50 
  51         ENTRY_NP(rd_gdtr)
  52         pushq   %rbp
  53         movq    %rsp, %rbp
  54         sgdt    (%rdi)
  55         leave
  56         ret
  57         SET_SIZE(rd_gdtr)
  58 
  59         ENTRY_NP(wr_gdtr)
  60         pushq   %rbp
  61         movq    %rsp, %rbp
  62         lgdt    (%rdi)
  63         jmp     1f
  64         nop
  65 1:
  66         leave
  67         ret
  68         SET_SIZE(wr_gdtr)
  69 
  70         /*
  71          * loads zero selector for ds and es.
  72          */
  73         ENTRY_NP(load_segment_registers)
  74         pushq   %rbp
  75         movq    %rsp, %rbp
  76         pushq   %rdi
  77         pushq   $.newcs
  78         lretq
  79 .newcs:
  80         /*
  81          * zero %ds and %es - they're ignored anyway
  82          */
  83         xorl    %eax, %eax
  84         movw    %ax, %ds
  85         movw    %ax, %es
  86         movl    %esi, %eax
  87         movw    %ax, %fs
  88         movl    %edx, %eax
  89         movw    %ax, %gs
  90         movl    %ecx, %eax
  91         movw    %ax, %ss
  92         leave
  93         ret
  94         SET_SIZE(load_segment_registers)
  95 
  96         ENTRY_NP(get_cs_register)
  97         movq    %cs, %rax
  98         ret
  99         SET_SIZE(get_cs_register)
 100 
 101         ENTRY_NP(wr_ldtr)
 102         movq    %rdi, %rax
 103         lldt    %ax
 104         ret
 105         SET_SIZE(wr_ldtr)
 106 
 107         ENTRY_NP(rd_ldtr)
 108         xorl    %eax, %eax
 109         sldt    %ax
 110         ret
 111         SET_SIZE(rd_ldtr)
 112 
 113         ENTRY_NP(wr_tsr)
 114         movq    %rdi, %rax
 115         ltr     %ax
 116         ret
 117         SET_SIZE(wr_tsr)
 118