| 1 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
#include "go_asm.h" |
| 6 |
#include "textflag.h" |
| 7 |
|
| 8 |
// Offsets into Thread Environment Block (pointer in R18) |
| 9 |
#define TEB_error 0x68 |
| 10 |
|
| 11 |
TEXT ·StdCall<ABIInternal>(SB),NOSPLIT,$0 |
| 12 |
B ·asmstdcall(SB) |
| 13 |
|
| 14 |
TEXT ·asmstdcall(SB),NOSPLIT,$16 |
| 15 |
STP (R19, R20), 16(RSP) // save old R19, R20 |
| 16 |
MOVD R0, R19 // save fn pointer |
| 17 |
MOVD RSP, R20 // save stack pointer |
| 18 |
|
| 19 |
// SetLastError(0) |
| 20 |
MOVD $0, TEB_error(R18_PLATFORM) |
| 21 |
MOVD StdCallInfo_Args(R19), R12 |
| 22 |
|
| 23 |
// Do we have more than 8 arguments? |
| 24 |
MOVD StdCallInfo_N(R19), R0 |
| 25 |
CMP $0, R0; BEQ _0args |
| 26 |
CMP $1, R0; BEQ _1args |
| 27 |
CMP $2, R0; BEQ _2args |
| 28 |
CMP $3, R0; BEQ _3args |
| 29 |
CMP $4, R0; BEQ _4args |
| 30 |
CMP $5, R0; BEQ _5args |
| 31 |
CMP $6, R0; BEQ _6args |
| 32 |
CMP $7, R0; BEQ _7args |
| 33 |
CMP $8, R0; BEQ _8args |
| 34 |
|
| 35 |
// Reserve stack space for remaining args |
| 36 |
SUB $8, R0, R2 |
| 37 |
ADD $1, R2, R3 // make even number of words for stack alignment |
| 38 |
AND $~1, R3 |
| 39 |
LSL $3, R3 |
| 40 |
SUB R3, RSP |
| 41 |
|
| 42 |
// R4: size of stack arguments (n-8)*8 |
| 43 |
// R5: &args[8] |
| 44 |
// R6: loop counter, from 0 to (n-8)*8 |
| 45 |
// R7: scratch |
| 46 |
// R8: copy of RSP - (R2)(RSP) assembles as (R2)(ZR) |
| 47 |
SUB $8, R0, R4 |
| 48 |
LSL $3, R4 |
| 49 |
ADD $(8*8), R12, R5 |
| 50 |
MOVD $0, R6 |
| 51 |
MOVD RSP, R8 |
| 52 |
stackargs: |
| 53 |
MOVD (R6)(R5), R7 |
| 54 |
MOVD R7, (R6)(R8) |
| 55 |
ADD $8, R6 |
| 56 |
CMP R6, R4 |
| 57 |
BNE stackargs |
| 58 |
|
| 59 |
_8args: |
| 60 |
MOVD (7*8)(R12), R7 |
| 61 |
_7args: |
| 62 |
MOVD (6*8)(R12), R6 |
| 63 |
_6args: |
| 64 |
MOVD (5*8)(R12), R5 |
| 65 |
_5args: |
| 66 |
MOVD (4*8)(R12), R4 |
| 67 |
_4args: |
| 68 |
MOVD (3*8)(R12), R3 |
| 69 |
_3args: |
| 70 |
MOVD (2*8)(R12), R2 |
| 71 |
_2args: |
| 72 |
MOVD (1*8)(R12), R1 |
| 73 |
_1args: |
| 74 |
MOVD (0*8)(R12), R0 |
| 75 |
_0args: |
| 76 |
|
| 77 |
MOVD StdCallInfo_Fn(R19), R12 |
| 78 |
BL (R12) |
| 79 |
|
| 80 |
MOVD R20, RSP // free stack space |
| 81 |
MOVD R0, StdCallInfo_R1(R19) // save return value |
| 82 |
// TODO(rsc) floating point like amd64 in StdCallInfo_R2? |
| 83 |
|
| 84 |
// GetLastError |
| 85 |
MOVD TEB_error(R18_PLATFORM), R0 |
| 86 |
MOVD R0, StdCallInfo_Err(R19) |
| 87 |
|
| 88 |
// Restore callee-saved registers. |
| 89 |
LDP 16(RSP), (R19, R20) |
| 90 |
RET |