xref: /reactos/sdk/include/asm/syscalls.inc (revision c2c66aff)
1
2#ifdef _M_ARM
3
4#include <ksarm.h>
5
6    GBLA SyscallId
7
8SyscallId SETA 0
9
10	MACRO
11	STUB_K $Name
12	LCLS ZwFuncName
13	LCLS ZwFuncEndName
14ZwFuncName    SETS "Zw$Name"
15ZwFuncEndName 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
32NtFuncName    SETS "Nt$Name"
33NtFuncEndName SETS "$NtFuncName":CC:"_end"
34ZwFuncName    SETS "Zw$Name"
35ZwFuncEndName 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
53SyscallId = 0
54
55#ifdef _M_IX86
56#define KUSER_SHARED_SYSCALL HEX(7ffe0300)
57#define KGDT_R0_CODE 8
58MACRO(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
65ENDM
66MACRO(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
75ENDM
76#elif defined(_M_AMD64)
77MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
78    .ENDPROLOG
79    mov eax, SyscallId
80    mov r10, rcx
81    syscall
82    ret
83ENDM
84MACRO(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
90ENDM
91#elif defined(_M_PPC)
92MACRO(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
102ENDM
103#define STUBCODE_K STUBCODE_U
104#elif defined(_M_MIPS)
105MACRO(STUBCODE_U, Name, SyscallId, ArgCount)
106    li $8, KUSER_SHARED_SYSCALL
107    lw $8,0($8)
108    j $8
109    nop
110ENDM
111MACRO(STUBCODE_K, Name, SyscallId, ArgCount)
112    j KiSystemService
113    nop
114ENDM
115#else
116#error unsupported architecture
117#endif
118
119#ifdef _M_IX86
120MACRO(MAKE_LABEL, Name, StackBytes)
121    PUBLIC _&Name&@&StackBytes
122    _&Name&@&StackBytes:
123ENDM
124MACRO(START_PROC, Name, StackBytes)
125    PUBLIC _&Name&@&StackBytes
126    .PROC _&Name&@&StackBytes
127ENDM
128#else
129MACRO(MAKE_LABEL, Name, StackBytes)
130    PUBLIC &Name
131    &Name:
132ENDM
133MACRO(START_PROC, Name, StackBytes)
134    PUBLIC &Name
135    .PROC &Name
136ENDM
137#endif
138
139MACRO(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
145ENDM
146
147MACRO(STUB_K, Name, ArgCount)
148    START_PROC Zw&Name, %ArgCount * 4
149    STUBCODE_K Name, SyscallId, %ArgCount
150    .ENDP
151    SyscallId = SyscallId + 1
152ENDM
153
154#endif
155