[OPENGL32]
[reactos.git] / sdk / include / asm / syscalls.inc
1
2 #ifdef _M_ARM
3
4 #include <ksarm.h>
5
6 GBLA SyscallId
7
8 SyscallId SETA 0
9
10 MACRO
11 STUB_K $Name
12 LCLS ZwFuncName
13 LCLS ZwFuncEndName
14 ZwFuncName SETS "Zw$Name"
15 ZwFuncEndName SETS "$ZwFuncName":CC:"_end"
16 ALIGN 2
17 EXPORT $ZwFuncName [FUNC]
18 $ZwFuncName
19 ROUT
20 mov r12, #SyscallId
21 svc #1
22 bx lr
23 $ZwFuncEndName
24 MEND
25
26 MACRO
27 STUB_U $Name
28 LCLS NtFuncName
29 LCLS NtFuncEndName
30 LCLS ZwFuncName
31 LCLS ZwFuncEndName
32 NtFuncName SETS "Nt$Name"
33 NtFuncEndName SETS "$NtFuncName":CC:"_end"
34 ZwFuncName SETS "Zw$Name"
35 ZwFuncEndName SETS "$ZwFuncName":CC:"_end"
36 ALIGN 2
37 EXPORT $NtFuncName [FUNC]
38 $NtFuncName
39 EXPORT $ZwFuncName [FUNC]
40 $ZwFuncName
41 ROUT
42 mov r12, #SyscallId
43 svc #1
44 bx lr
45 $NtFuncEndName
46 $ZwFuncEndName
47 MEND
48
49 #else
50
51 #include <asm.inc>
52
53 SyscallId = 0
54
55 #ifdef _M_IX86
56 #define KUSER_SHARED_SYSCALL HEX(7ffe0300)
57 #define KGDT_R0_CODE 8
58 MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
59 StackBytes = 4 * ArgCount
60 FPO 0, 0, 0, 0, 0, FRAME_FPO
61 mov eax, SyscallId
62 mov edx, KUSER_SHARED_SYSCALL
63 call dword ptr [edx]
64 ret StackBytes
65 ENDM
66 MACRO(STUBCODE_K, Name, SyscallId, ArgCount)
67 StackBytes = 4 * &ArgCount
68 FPO 0, 0, 0, 0, 0, FRAME_FPO
69 mov eax, SyscallId
70 lea edx, [esp + 4]
71 pushfd
72 push KGDT_R0_CODE
73 call _KiSystemService
74 ret StackBytes
75 ENDM
76 #elif defined(_M_AMD64)
77 MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
78 .ENDPROLOG
79 mov eax, SyscallId
80 mov r10, rcx
81 syscall
82 ret
83 ENDM
84 MACRO(STUBCODE_K, Name, SyscallId, ArgCount)
85 .ENDPROLOG
86 EXTERN Nt&Name:PROC
87 lea rax, Nt&Name[rip]
88 mov r10, ArgCount * 8
89 jmp KiZwSystemService
90 ENDM
91 #elif defined(_M_PPC)
92 MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
93 stwu 1,-16(1)
94 mflr 0
95 stw 0,0(1)
96 li 0, SyscallId
97 sc
98 lwz 0,0(1)
99 mtlr 0
100 addi 1,1,16
101 blr
102 ENDM
103 #define STUBCODE_K STUBCODE_U
104 #elif defined(_M_MIPS)
105 MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
106 li $8, KUSER_SHARED_SYSCALL
107 lw $8,0($8)
108 j $8
109 nop
110 ENDM
111 MACRO(STUBCODE_K, Name, SyscallId, ArgCount)
112 j KiSystemService
113 nop
114 ENDM
115 #else
116 #error unsupported architecture
117 #endif
118
119 #ifdef _M_IX86
120 MACRO(MAKE_LABEL, Name, StackBytes)
121 PUBLIC _&Name&@&StackBytes
122 _&Name&@&StackBytes:
123 ENDM
124 MACRO(START_PROC, Name, StackBytes)
125 PUBLIC _&Name&@&StackBytes
126 .PROC _&Name&@&StackBytes
127 ENDM
128 #else
129 MACRO(MAKE_LABEL, Name, StackBytes)
130 PUBLIC &Name
131 &Name:
132 ENDM
133 MACRO(START_PROC, Name, StackBytes)
134 PUBLIC &Name
135 .PROC &Name
136 ENDM
137 #endif
138
139 MACRO(STUB_U, Name, ArgCount)
140 MAKE_LABEL Zw&Name, %ArgCount * 4
141 START_PROC Nt&Name, %ArgCount * 4
142 STUBCODE_U Name, SyscallId, %ArgCount
143 .ENDP
144 SyscallId = SyscallId + 1
145 ENDM
146
147 MACRO(STUB_K, Name, ArgCount)
148 START_PROC Zw&Name, %ArgCount * 4
149 STUBCODE_K Name, SyscallId, %ArgCount
150 .ENDP
151 SyscallId = SyscallId + 1
152 ENDM
153
154 #endif