gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/platform/kvm/testutil/testutil_arm64.s (about)

     1  // Copyright 2019 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 arm64
    16  
    17  // test_util_arm64.s provides ARM64 test functions.
    18  
    19  #include "funcdata.h"
    20  #include "textflag.h"
    21  
    22  #define SYS_GETPID 172
    23  
    24  // This function simulates the getpid syscall.
    25  TEXT ·Getpid(SB),NOSPLIT,$0
    26  	NO_LOCAL_POINTERS
    27  	MOVD $SYS_GETPID, R8
    28  	SVC
    29  	RET
    30  
    31  TEXT ·AddrOfGetpid(SB),NOSPLIT,$0-8
    32  	MOVD $·Getpid(SB), R0
    33  	MOVD R0, ret+0(FP)
    34  	RET
    35  
    36  TEXT ·touch(SB),NOSPLIT,$0
    37  start:
    38  	MOVD 0(R8), R1
    39  	MOVD $SYS_GETPID, R8   // getpid
    40  	SVC
    41  	B start
    42  
    43  TEXT ·AddrOfTouch(SB),NOSPLIT,$0-8
    44  	MOVD $·touch(SB), R0
    45  	MOVD R0, ret+0(FP)
    46  	RET
    47  
    48  TEXT ·haltLoop(SB),NOSPLIT,$0
    49  start:
    50  	HLT
    51  	B start
    52  
    53  TEXT ·AddrOfHaltLoop(SB),NOSPLIT,$0-8
    54  	MOVD $·haltLoop(SB), R0
    55  	MOVD R0, ret+0(FP)
    56  	RET
    57  
    58  // This function simulates a loop of syscall.
    59  TEXT ·syscallLoop(SB),NOSPLIT,$0
    60  start:
    61  	SVC
    62  	B start
    63  
    64  TEXT ·AddrOfSyscallLoop(SB),NOSPLIT,$0-8
    65  	MOVD $·syscallLoop(SB), R0
    66  	MOVD R0, ret+0(FP)
    67  	RET
    68  
    69  TEXT ·spinLoop(SB),NOSPLIT,$0
    70  start:
    71  	B start
    72  
    73  TEXT ·AddrOfSpinLoop(SB),NOSPLIT,$0-8
    74  	MOVD $·spinLoop(SB), R0
    75  	MOVD R0, ret+0(FP)
    76  	RET
    77  
    78  TEXT ·TLSWorks(SB),NOSPLIT,$0
    79          NO_LOCAL_POINTERS
    80          MOVD $0x6789, R5
    81          MSR R5, TPIDR_EL0
    82          MOVD $SYS_GETPID, R8 // getpid
    83          SVC
    84          MRS TPIDR_EL0, R6
    85          CMP R5, R6
    86          BNE isNaN
    87          MOVD $1, R0
    88          MOVD R0, ret+0(FP)
    89          RET
    90  isNaN:
    91          MOVD $0, ret+0(FP)
    92          RET
    93  
    94  TEXT ·FloatingPointWorks(SB),NOSPLIT,$0
    95  	NO_LOCAL_POINTERS
    96  	// gc will touch fpsimd, so we should test it.
    97  	// such as in <runtime.deductSweepCredit>.
    98  	FMOVD $(9.9), F0
    99  	MOVD $SYS_GETPID, R8 // getpid
   100  	SVC
   101  	FMOVD $(9.9), F1
   102  	FCMPD F0, F1
   103  	BNE isNaN
   104  	MOVD $1, R0
   105  	MOVD R0, ret+0(FP)
   106  	RET
   107  isNaN:
   108  	MOVD $0, ret+0(FP)
   109  	RET
   110  
   111  // MVN: bitwise logical NOT
   112  // This case simulates an application that modified R0-R30.
   113  #define TWIDDLE_REGS() \
   114          MVN R0, R0; \
   115          MVN R1, R1; \
   116          MVN R2, R2; \
   117          MVN R3, R3; \
   118          MVN R4, R4; \
   119          MVN R5, R5; \
   120          MVN R6, R6; \
   121          MVN R7, R7; \
   122          MVN R8, R8; \
   123          MVN R9, R9; \
   124          MVN R10, R10; \
   125          MVN R11, R11; \
   126          MVN R12, R12; \
   127          MVN R13, R13; \
   128          MVN R14, R14; \
   129          MVN R15, R15; \
   130          MVN R16, R16; \
   131          MVN R17, R17; \
   132          MVN R18_PLATFORM, R18_PLATFORM; \
   133          MVN R19, R19; \
   134          MVN R20, R20; \
   135          MVN R21, R21; \
   136          MVN R22, R22; \
   137          MVN R23, R23; \
   138          MVN R24, R24; \
   139          MVN R25, R25; \
   140          MVN R26, R26; \
   141          MVN R27, R27; \
   142          MVN g, g; \
   143          MVN R29, R29; \
   144          MVN R30, R30;
   145  
   146  TEXT ·twiddleRegsSyscall(SB),NOSPLIT,$0
   147  	TWIDDLE_REGS()
   148  	MSR R10, TPIDR_EL0
   149  	// Trapped in el0_svc.
   150  	SVC
   151  	RET // never reached
   152  
   153  TEXT ·AddrOfTwiddleRegsSyscall(SB),NOSPLIT,$0-8
   154  	MOVD $·twiddleRegsSyscall(SB), R0
   155  	MOVD R0, ret+0(FP)
   156  	RET
   157  
   158  TEXT ·twiddleRegsFault(SB),NOSPLIT,$0
   159  	TWIDDLE_REGS()
   160  	MSR R10, TPIDR_EL0
   161  	// Trapped in el0_ia.
   162  	// Branch to Register branches unconditionally to an address in <Rn>.
   163  	JMP (R6) // <=> br x6, must fault
   164  	RET // never reached
   165  
   166  TEXT ·AddrOfTwiddleRegsFault(SB),NOSPLIT,$0-8
   167  	MOVD $·twiddleRegsFault(SB), R0
   168  	MOVD R0, ret+0(FP)
   169  	RET