github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/ring0/lib_amd64.s (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #include "funcdata.h"
    16  #include "textflag.h"
    17  
    18  // fxrstor loads floating point state.
    19  //
    20  // The code corresponds to:
    21  //
    22  //     fxrstor64 (%rbx)
    23  //
    24  TEXT ·fxrstor(SB),NOSPLIT,$0-8
    25  	MOVQ addr+0(FP), BX
    26  	MOVL $0xffffffff, AX
    27  	MOVL $0xffffffff, DX
    28  	BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0x0b;
    29  	RET
    30  
    31  // xrstor loads floating point state.
    32  //
    33  // The code corresponds to:
    34  //
    35  //     xrstor (%rdi)
    36  //
    37  TEXT ·xrstor(SB),NOSPLIT,$0-8
    38  	MOVQ addr+0(FP), DI
    39  	MOVL $0xffffffff, AX
    40  	MOVL $0xffffffff, DX
    41  	BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0x2f;
    42  	RET
    43  
    44  // fxsave saves floating point state.
    45  //
    46  // The code corresponds to:
    47  //
    48  //     fxsave64 (%rbx)
    49  //
    50  TEXT ·fxsave(SB),NOSPLIT,$0-8
    51  	MOVQ addr+0(FP), BX
    52  	MOVL $0xffffffff, AX
    53  	MOVL $0xffffffff, DX
    54  	BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0x03;
    55  	RET
    56  
    57  // xsave saves floating point state.
    58  //
    59  // The code corresponds to:
    60  //
    61  //     xsave (%rdi)
    62  //
    63  TEXT ·xsave(SB),NOSPLIT,$0-8
    64  	MOVQ addr+0(FP), DI
    65  	MOVL $0xffffffff, AX
    66  	MOVL $0xffffffff, DX
    67  	BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0x27;
    68  	RET
    69  
    70  // xsaveopt saves floating point state.
    71  //
    72  // The code corresponds to:
    73  //
    74  //     xsaveopt (%rdi)
    75  //
    76  TEXT ·xsaveopt(SB),NOSPLIT,$0-8
    77  	MOVQ addr+0(FP), DI
    78  	MOVL $0xffffffff, AX
    79  	MOVL $0xffffffff, DX
    80  	BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0x37;
    81  	RET
    82  
    83  // wrfsbase writes to the FS base.
    84  //
    85  // The code corresponds to:
    86  //
    87  // 	wrfsbase %rax
    88  //
    89  TEXT ·wrfsbase(SB),NOSPLIT,$0-8
    90  	MOVQ addr+0(FP), AX
    91  	BYTE $0xf3; BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0xd0;
    92  	RET
    93  
    94  // wrfsmsr writes to the FSBASE MSR.
    95  //
    96  // The code corresponds to:
    97  //
    98  // 	wrmsr (writes EDX:EAX to the MSR in ECX)
    99  //
   100  TEXT ·wrfsmsr(SB),NOSPLIT,$0-8
   101  	MOVQ addr+0(FP), AX
   102  	MOVQ AX, DX
   103  	SHRQ $32, DX
   104  	MOVQ $0xc0000100, CX // MSR_FS_BASE
   105  	BYTE $0x0f; BYTE $0x30;
   106  	RET
   107  
   108  // wrgsbase writes to the GS base.
   109  //
   110  // The code corresponds to:
   111  //
   112  // 	wrgsbase %rax
   113  //
   114  TEXT ·wrgsbase(SB),NOSPLIT,$0-8
   115  	MOVQ addr+0(FP), AX
   116  	BYTE $0xf3; BYTE $0x48; BYTE $0x0f; BYTE $0xae; BYTE $0xd8;
   117  	RET
   118  
   119  // wrgsmsr writes to the GSBASE MSR.
   120  //
   121  // See wrfsmsr.
   122  TEXT ·wrgsmsr(SB),NOSPLIT,$0-8
   123  	MOVQ addr+0(FP), AX
   124  	MOVQ AX, DX
   125  	SHRQ $32, DX
   126  	MOVQ $0xc0000101, CX     // MSR_GS_BASE
   127  	BYTE $0x0f; BYTE $0x30;  // WRMSR
   128  	RET
   129  
   130  // readCR2 reads the current CR2 value.
   131  //
   132  // The code corresponds to:
   133  //
   134  // 	mov %cr2, %rax
   135  //
   136  TEXT ·readCR2(SB),NOSPLIT,$0-8
   137  	BYTE $0x0f; BYTE $0x20; BYTE $0xd0;
   138  	MOVQ AX, ret+0(FP)
   139  	RET
   140  
   141  // fninit initializes the floating point unit.
   142  //
   143  // The code corresponds to:
   144  //
   145  // 	fninit
   146  TEXT ·fninit(SB),NOSPLIT,$0
   147  	BYTE $0xdb; BYTE $0xe3;
   148  	RET
   149  
   150  // xsetbv writes to an extended control register.
   151  //
   152  // The code corresponds to:
   153  //
   154  // 	xsetbv
   155  //
   156  TEXT ·xsetbv(SB),NOSPLIT,$0-16
   157  	MOVL reg+0(FP), CX
   158  	MOVL value+8(FP), AX
   159  	MOVL value+12(FP), DX
   160  	BYTE $0x0f; BYTE $0x01; BYTE $0xd1;
   161  	RET
   162  
   163  // xgetbv reads an extended control register.
   164  //
   165  // The code corresponds to:
   166  //
   167  // 	xgetbv
   168  //
   169  TEXT ·xgetbv(SB),NOSPLIT,$0-16
   170  	MOVL reg+0(FP), CX
   171  	BYTE $0x0f; BYTE $0x01; BYTE $0xd0;
   172  	MOVL AX, ret+8(FP)
   173  	MOVL DX, ret+12(FP)
   174  	RET
   175  
   176  // wrmsr writes to a control register.
   177  //
   178  // The code corresponds to:
   179  //
   180  // 	wrmsr
   181  //
   182  TEXT ·wrmsr(SB),NOSPLIT,$0-16
   183  	MOVL reg+0(FP), CX
   184  	MOVL value+8(FP), AX
   185  	MOVL value+12(FP), DX
   186  	BYTE $0x0f; BYTE $0x30;
   187  	RET
   188  
   189  // rdmsr reads a control register.
   190  //
   191  // The code corresponds to:
   192  //
   193  // 	rdmsr
   194  //
   195  TEXT ·rdmsr(SB),NOSPLIT,$0-16
   196  	MOVL reg+0(FP), CX
   197  	BYTE $0x0f; BYTE $0x32;
   198  	MOVL AX, ret+8(FP)
   199  	MOVL DX, ret+12(FP)
   200  	RET
   201  
   202  // stmxcsr reads the MXCSR control and status register.
   203  TEXT ·stmxcsr(SB),NOSPLIT,$0-8
   204  	MOVQ addr+0(FP), SI
   205  	STMXCSR (SI)
   206  	RET
   207  
   208  // ldmxcsr writes to the MXCSR control and status register.
   209  TEXT ·ldmxcsr(SB),NOSPLIT,$0-8
   210  	MOVQ addr+0(FP), SI
   211  	LDMXCSR (SI)
   212  	RET