...
Run Format

Text file src/internal/runtime/syscall/windows/asm_windows_amd64.s

Documentation: internal/runtime/syscall/windows

     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
     8TEXT ·StdCall<ABIInternal>(SB),NOSPLIT,$0
     9	MOVQ	AX, CX
    10	JMP	·asmstdcall(SB)
    11
    12TEXT ·asmstdcall(SB),NOSPLIT,$16
    13	MOVQ	SP, AX
    14	ANDQ	$~15, SP	// alignment as per Windows requirement
    15	MOVQ	AX, 8(SP)
    16	MOVQ	CX, 0(SP)	// asmcgocall will put first argument into CX.
    17
    18	MOVQ	StdCallInfo_Fn(CX), AX
    19	MOVQ	StdCallInfo_Args(CX), SI
    20	MOVQ	StdCallInfo_N(CX), CX
    21
    22	// SetLastError(0).
    23	MOVQ	0x30(GS), DI
    24	MOVL	$0, 0x68(DI)
    25
    26	SUBQ	$(const_MaxArgs*8), SP	// room for args
    27
    28	// Fast version, do not store args on the stack.
    29	CMPL	CX, $0;	JE	_0args
    30	CMPL	CX, $1;	JE	_1args
    31	CMPL	CX, $2;	JE	_2args
    32	CMPL	CX, $3;	JE	_3args
    33	CMPL	CX, $4;	JE	_4args
    34
    35	// Check we have enough room for args.
    36	CMPL	CX, $const_MaxArgs
    37	JLE	2(PC)
    38	INT	$3			// not enough room -> crash
    39
    40	// Copy args to the stack.
    41	MOVQ	SP, DI
    42	CLD
    43	REP; MOVSQ
    44	MOVQ	SP, SI
    45
    46	// Load first 4 args into correspondent registers.
    47	// Floating point arguments are passed in the XMM
    48	// registers. Set them here in case any of the arguments
    49	// are floating point values. For details see
    50	//	https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170
    51_4args:
    52	MOVQ	24(SI), R9
    53	MOVQ	R9, X3
    54_3args:
    55	MOVQ	16(SI), R8
    56	MOVQ	R8, X2
    57_2args:
    58	MOVQ	8(SI), DX
    59	MOVQ	DX, X1
    60_1args:
    61	MOVQ	0(SI), CX
    62	MOVQ	CX, X0
    63_0args:
    64
    65	// Call stdcall function.
    66	CALL	AX
    67
    68	ADDQ	$(const_MaxArgs*8), SP
    69
    70	// Return result.
    71	MOVQ	0(SP), CX
    72	MOVQ	8(SP), SP
    73	MOVQ	AX, StdCallInfo_R1(CX)
    74	// Floating point return values are returned in XMM0. Setting r2 to this
    75	// value in case this call returned a floating point value. For details,
    76	// see https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention
    77	MOVQ    X0, StdCallInfo_R2(CX)
    78
    79	// GetLastError().
    80	MOVQ	0x30(GS), DI
    81	MOVL	0x68(DI), AX
    82	MOVQ	AX, StdCallInfo_Err(CX)
    83
    84	RET

View as plain text