1/*
2 * PROJECT:         ReactOS Source Development Kit (SDK)
3 * LICENSE:         BSD - See COPYING.ARM in the top level directory
4 * FILE:            ntoskrnl/include/internal/i386/callconv.s
5 * PURPOSE:         x86 Calling Convention Helpers
6 * PROGRAMMERS:     ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11//
12// @name CountArg
13//
14// This macro counts the number of arguments in the ArgList and returns
15// the value in cCount.
16//
17// @param cCount - Count of arguments
18// @param ArgList - Argument list
19//
20// @remark None.
21//
22.macro CountArg cCount:req,ArgList:vararg
23
24	cCount = 0
25
26	.ifnb \ArgList
27    	.irp arg, \ArgList
28			cCount = cCount+1
29		.endr
30	.endif
31.endm
32
33//
34// @name RevPush
35//
36// This macro pushes the arguments in ArgList in the reverse order
37// and returns the number of arguments in cCount
38//
39// @param cCount - Count of arguments
40// @param ArgList - Argument list
41//
42// @remark None.
43//
44.macro RevPush cCount:req,ArgList:vararg
45	LOCAL index, x
46
47	CountArg cCount, ArgList
48
49	index = cCount
50	.rept cCount
51		x = 0
52		.irp arg,ArgList
53			x=x+1
54			.ifeq index-x
55				push arg
56				.exitm
57			.endif
58		.endr
59
60		index = index-1
61	.endr
62.endm
63
64//
65// @name stdCallCall
66//
67// This macro performs a function call using the STDCALL convention and applies
68// the correct name decoration required based on the stack bytes
69//
70// @param Func - Function name
71// @param N - Number of stack bytes for arguments
72//
73// @remark None.
74//
75.macro stdCallCall Func:req,N:req
76	.ifdef __imp_&Func&@&N
77    	call dword ptr [__imp_&Func&@&N]
78	.else
79    	call Func&@&N
80	.endif
81.endm
82
83//
84// @name stdCall
85//
86// This macro pushes the arguments required for a function call using the
87// STDCALL convention and then issues the call
88//
89// @param Func - Function name
90// @param ArgList - Argument list
91//
92// @remark None.
93//
94.macro stdCall Func:req,ArgList:vararg
95	LOCAL Bytes
96
97	RevPush Bytes,ArgList
98	Bytes = Bytes*4
99
100	stdCallCall Func, %(Bytes)
101.endm
102