github.com/primecitizens/pcz/std@v0.2.1/core/reflect/call_386.s (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2018 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 //go:build pcz && 386 9 10 #include "textflag.h" 11 #include "funcdata.h" // for NO_LOCAL_POINTERS 12 13 // reflectcall: call a function with the given argument list 14 // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). 15 // we don't have variable-sized frames, so we use a small number 16 // of constant-sized-frame functions to encode a few bits of size in the pc. 17 // Caution: ugly multiline assembly macros in your future! 18 19 #define DISPATCH(NAME,MAXSIZE) \ 20 CMPL CX, $MAXSIZE; \ 21 JA 3(PC); \ 22 MOVL $NAME(SB), AX; \ 23 JMP AX 24 // Note: can't just "JMP NAME(SB)" - bad inlining results. 25 26 TEXT ·Call(SB), NOSPLIT, $0-28 27 MOVL frameSize+20(FP), CX 28 DISPATCH(·call16, 16) 29 DISPATCH(·call32, 32) 30 DISPATCH(·call64, 64) 31 DISPATCH(·call128, 128) 32 DISPATCH(·call256, 256) 33 DISPATCH(·call512, 512) 34 DISPATCH(·call1024, 1024) 35 DISPATCH(·call2048, 2048) 36 DISPATCH(·call4096, 4096) 37 DISPATCH(·call8192, 8192) 38 DISPATCH(·call16384, 16384) 39 DISPATCH(·call32768, 32768) 40 DISPATCH(·call65536, 65536) 41 DISPATCH(·call131072, 131072) 42 DISPATCH(·call262144, 262144) 43 DISPATCH(·call524288, 524288) 44 DISPATCH(·call1048576, 1048576) 45 DISPATCH(·call2097152, 2097152) 46 DISPATCH(·call4194304, 4194304) 47 DISPATCH(·call8388608, 8388608) 48 DISPATCH(·call16777216, 16777216) 49 DISPATCH(·call33554432, 33554432) 50 DISPATCH(·call67108864, 67108864) 51 DISPATCH(·call134217728, 134217728) 52 DISPATCH(·call268435456, 268435456) 53 DISPATCH(·call536870912, 536870912) 54 DISPATCH(·call1073741824, 1073741824) 55 MOVL $·badreflectcall(SB), AX 56 JMP AX 57 58 #define CALLFN(NAME,MAXSIZE) \ 59 TEXT NAME(SB), WRAPPER, $MAXSIZE-28; \ 60 NO_LOCAL_POINTERS; \ 61 /* copy arguments to stack */ \ 62 MOVL stackArgs+8(FP), SI; \ 63 MOVL stackArgsSize+12(FP), CX; \ 64 MOVL SP, DI; \ 65 REP;MOVSB; \ 66 /* call function */ \ 67 MOVL f+4(FP), DX; \ 68 MOVL (DX), AX; \ 69 PCDATA $PCDATA_StackMapIndex, $0; \ 70 CALL AX; \ 71 /* copy return values back */ \ 72 MOVL stackArgsType+0(FP), DX; \ 73 MOVL stackArgs+8(FP), DI; \ 74 MOVL stackArgsSize+12(FP), CX; \ 75 MOVL stackRetOffset+16(FP), BX; \ 76 MOVL SP, SI; \ 77 ADDL BX, DI; \ 78 ADDL BX, SI; \ 79 SUBL BX, CX; \ 80 CALL callRet<>(SB); \ 81 RET 82 83 // callRet copies return values back at the end of call*. This is a 84 // separate function so it can allocate stack space for the arguments 85 // to reflectcallmove. It does not follow the Go ABI; it expects its 86 // arguments in registers. 87 TEXT callRet<>(SB), NOSPLIT, $20-0 88 MOVL DX, 0(SP) 89 MOVL DI, 4(SP) 90 MOVL SI, 8(SP) 91 MOVL CX, 12(SP) 92 MOVL $0, 16(SP) 93 CALL ·reflectcallmove(SB) 94 RET 95 96 CALLFN(·call16, 16) 97 CALLFN(·call32, 32) 98 CALLFN(·call64, 64) 99 CALLFN(·call128, 128) 100 CALLFN(·call256, 256) 101 CALLFN(·call512, 512) 102 CALLFN(·call1024, 1024) 103 CALLFN(·call2048, 2048) 104 CALLFN(·call4096, 4096) 105 CALLFN(·call8192, 8192) 106 CALLFN(·call16384, 16384) 107 CALLFN(·call32768, 32768) 108 CALLFN(·call65536, 65536) 109 CALLFN(·call131072, 131072) 110 CALLFN(·call262144, 262144) 111 CALLFN(·call524288, 524288) 112 CALLFN(·call1048576, 1048576) 113 CALLFN(·call2097152, 2097152) 114 CALLFN(·call4194304, 4194304) 115 CALLFN(·call8388608, 8388608) 116 CALLFN(·call16777216, 16777216) 117 CALLFN(·call33554432, 33554432) 118 CALLFN(·call67108864, 67108864) 119 CALLFN(·call134217728, 134217728) 120 CALLFN(·call268435456, 268435456) 121 CALLFN(·call536870912, 536870912) 122 CALLFN(·call1073741824, 1073741824)