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 "go_tls.h"
7 #include "textflag.h"
8 #include "time_windows.h"
9
10 TEXT ·StdCall<ABIInternal>(SB),NOSPLIT,$0
11 B ·asmstdcall(SB)
12
13 TEXT ·asmstdcall(SB),NOSPLIT|NOFRAME,$0
14 MOVM.DB.W [R4, R5, R14], (R13) // push {r4, r5, lr}
15 MOVW R0, R4 // put fn * in r4
16 MOVW R13, R5 // save stack pointer in r5
17
18 // SetLastError(0)
19 MOVW $0, R0
20 MRC 15, 0, R1, C13, C0, 2
21 MOVW R0, 0x34(R1)
22
23 MOVW 8(R4), R12 // fn->Args
24
25 // Do we have more than 4 arguments?
26 MOVW 4(R4), R0 // fn->n
27 SUB.S $4, R0, R2
28 BLE loadregs
29
30 // Reserve stack space for remaining args
31 SUB R2<<2, R13
32 BIC $0x7, R13 // alignment for ABI
33
34 // R0: count of arguments
35 // R1:
36 // R2: loop counter, from 0 to (n-4)
37 // R3: scratch
38 // R4: pointer to StdCallInfo struct
39 // R12: fn->args
40 MOVW $0, R2
41 stackargs:
42 ADD $4, R2, R3 // r3 = args[4 + i]
43 MOVW R3<<2(R12), R3
44 MOVW R3, R2<<2(R13) // stack[i] = r3
45
46 ADD $1, R2 // i++
47 SUB $4, R0, R3 // while (i < (n - 4))
48 CMP R3, R2
49 BLT stackargs
50
51 loadregs:
52 CMP $3, R0
53 MOVW.GT 12(R12), R3
54
55 CMP $2, R0
56 MOVW.GT 8(R12), R2
57
58 CMP $1, R0
59 MOVW.GT 4(R12), R1
60
61 CMP $0, R0
62 MOVW.GT 0(R12), R0
63
64 BIC $0x7, R13 // alignment for ABI
65 MOVW 0(R4), R12 // branch to fn->fn
66 BL (R12)
67
68 MOVW R5, R13 // free stack space
69 MOVW R0, 12(R4) // save return value to fn->r1
70 MOVW R1, 16(R4)
71
72 // GetLastError
73 MRC 15, 0, R1, C13, C0, 2
74 MOVW 0x34(R1), R0
75 MOVW R0, 20(R4) // store in fn->err
76
77 MOVM.IA.W (R13), [R4, R5, R15]
78
View as plain text