github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/platform/kvm/testutil/testutil_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  // +build amd64
    16  
    17  // test_util_amd64.s provides AMD64 test functions.
    18  
    19  #include "funcdata.h"
    20  #include "textflag.h"
    21  
    22  TEXT ·Getpid(SB),NOSPLIT,$0
    23  	NO_LOCAL_POINTERS
    24  	MOVQ $39, AX // getpid
    25  	SYSCALL
    26  	RET
    27  
    28  TEXT ·Touch(SB),NOSPLIT,$0
    29  start:
    30  	MOVQ 0(AX), BX // deref AX
    31  	MOVQ $39, AX   // getpid
    32  	SYSCALL
    33  	JMP start
    34  
    35  TEXT ·HaltLoop(SB),NOSPLIT,$0
    36  start:
    37  	HLT
    38  	JMP start
    39  
    40  TEXT ·SyscallLoop(SB),NOSPLIT,$0
    41  start:
    42  	SYSCALL
    43  	JMP start
    44  
    45  TEXT ·SpinLoop(SB),NOSPLIT,$0
    46  start:
    47  	JMP start
    48  
    49  TEXT ·FloatingPointWorks(SB),NOSPLIT,$0-8
    50  	NO_LOCAL_POINTERS
    51  	MOVQ $1, AX
    52  	MOVQ AX, X0
    53  	MOVQ $39, AX // getpid
    54  	SYSCALL
    55  	MOVQ X0, AX
    56  	CMPQ AX, $1
    57  	SETEQ ret+0(FP)
    58  	RET
    59  
    60  #define TWIDDLE_REGS() \
    61  	NOTQ R15; \
    62  	NOTQ R14; \
    63  	NOTQ R13; \
    64  	NOTQ R12; \
    65  	NOTQ BP; \
    66  	NOTQ BX; \
    67  	NOTQ R11; \
    68  	NOTQ R10; \
    69  	NOTQ R9; \
    70  	NOTQ R8; \
    71  	NOTQ AX; \
    72  	NOTQ CX; \
    73  	NOTQ DX; \
    74  	NOTQ SI; \
    75  	NOTQ DI; \
    76  	NOTQ SP;
    77  
    78  TEXT ·TwiddleRegsSyscall(SB),NOSPLIT,$0
    79  	TWIDDLE_REGS()
    80  	SYSCALL
    81  	RET // never reached
    82  
    83  TEXT ·TwiddleRegsFault(SB),NOSPLIT,$0
    84  	TWIDDLE_REGS()
    85  	JMP AX // must fault
    86  	RET // never reached
    87  
    88  #define READ_FS() BYTE $0x64; BYTE $0x48; BYTE $0x8b; BYTE $0x00;
    89  #define READ_GS() BYTE $0x65; BYTE $0x48; BYTE $0x8b; BYTE $0x00;
    90  
    91  TEXT ·TwiddleSegments(SB),NOSPLIT,$0
    92  	MOVQ $0x0, AX
    93  	READ_GS()
    94  	MOVQ AX, BX
    95  	MOVQ $0x0, AX
    96  	READ_FS()
    97  	SYSCALL
    98  	RET // never reached