gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/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|NOFRAME,$0 23 NO_LOCAL_POINTERS 24 MOVQ $39, AX // getpid 25 SYSCALL 26 RET 27 28 // func AddrOfGetpid() uintptr 29 TEXT ·AddrOfGetpid(SB), $0-8 30 MOVQ $·Getpid(SB), AX 31 MOVQ AX, ret+0(FP) 32 RET 33 34 TEXT ·touch(SB),NOSPLIT|NOFRAME,$0 35 start: 36 MOVQ 0(AX), BX // deref AX 37 MOVQ $39, AX // getpid 38 SYSCALL 39 JMP start 40 41 // func AddrOfTouch() uintptr 42 TEXT ·AddrOfTouch(SB), $0-8 43 MOVQ $·touch(SB), AX 44 MOVQ AX, ret+0(FP) 45 RET 46 47 TEXT ·syscallLoop(SB),NOSPLIT|NOFRAME,$0 48 start: 49 SYSCALL 50 JMP start 51 52 // func AddrOfSyscallLoop() uintptr 53 TEXT ·AddrOfSyscallLoop(SB), $0-8 54 MOVQ $·syscallLoop(SB), AX 55 MOVQ AX, ret+0(FP) 56 RET 57 58 TEXT ·spinLoop(SB),NOSPLIT|NOFRAME,$0 59 start: 60 JMP start 61 62 // func AddrOfSpinLoop() uintptr 63 TEXT ·AddrOfSpinLoop(SB), $0-8 64 MOVQ $·spinLoop(SB), AX 65 MOVQ AX, ret+0(FP) 66 RET 67 68 TEXT ·FloatingPointWorks(SB),NOSPLIT|NOFRAME,$0 69 NO_LOCAL_POINTERS 70 MOVQ $1, AX 71 MOVQ AX, X0 72 MOVQ $39, AX // getpid 73 SYSCALL 74 MOVQ X0, AX 75 CMPQ AX, $1 76 SETEQ ret+0(FP) 77 RET 78 79 #define TWIDDLE_REGS() \ 80 NOTQ R15; \ 81 NOTQ R14; \ 82 NOTQ R13; \ 83 NOTQ R12; \ 84 NOTQ BP; \ 85 NOTQ BX; \ 86 NOTQ R11; \ 87 NOTQ R10; \ 88 NOTQ R9; \ 89 NOTQ R8; \ 90 NOTQ AX; \ 91 NOTQ CX; \ 92 NOTQ DX; \ 93 NOTQ SI; \ 94 NOTQ DI; \ 95 NOTQ SP; 96 97 TEXT ·twiddleRegsSyscall(SB),NOSPLIT|NOFRAME,$0 98 TWIDDLE_REGS() 99 SYSCALL 100 RET // never reached 101 102 // func AddrOfTwiddleRegsSyscall() uintptr 103 TEXT ·AddrOfTwiddleRegsSyscall(SB), $0-8 104 MOVQ $·twiddleRegsSyscall(SB), AX 105 MOVQ AX, ret+0(FP) 106 RET 107 108 TEXT ·twiddleRegsFault(SB),NOSPLIT|NOFRAME,$0 109 TWIDDLE_REGS() 110 JMP AX // must fault 111 RET // never reached 112 113 // func AddrOfTwiddleRegsFault() uintptr 114 TEXT ·AddrOfTwiddleRegsFault(SB), $0-8 115 MOVQ $·twiddleRegsFault(SB), AX 116 MOVQ AX, ret+0(FP) 117 RET 118 119 #define READ_FS() BYTE $0x64; BYTE $0x48; BYTE $0x8b; BYTE $0x00; 120 #define READ_GS() BYTE $0x65; BYTE $0x48; BYTE $0x8b; BYTE $0x00; 121 122 TEXT ·twiddleSegments(SB),NOSPLIT|NOFRAME,$0 123 MOVQ $0x0, AX 124 READ_GS() 125 MOVQ AX, BX 126 MOVQ $0x0, AX 127 READ_FS() 128 SYSCALL 129 RET // never reached 130 131 // func AddrOfTwiddleSegments() uintptr 132 TEXT ·AddrOfTwiddleSegments(SB), $0-8 133 MOVQ $·twiddleSegments(SB), AX 134 MOVQ AX, ret+0(FP) 135 RET