- Cleanup assembly files and create a header for the macros added and new ones that...
[reactos.git] / reactos / ntoskrnl / include / internal / i386 / asmmacro.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnlinclude/i386/asmmacro.S
5 * PURPOSE: Assembly Macros for Spinlocks and common Trap Code (TODO)
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include <ndk/asm.h>
11 .intel_syntax noprefix
12
13 //
14 // These macros are inlined equivalents of KiAcquire/ReleaseSpinlock, that is,
15 // they will not be compiled into non-SMP builds. Usage is as follows:
16 //
17 // .BeginYourFunction
18 // mov reg, lockaddr
19 // ACQUIRE_SPINLOCK(reg, .spin)
20 // <thread-safe code here>
21 // RELEASE_SPINLOCK(reg)
22 // <misc code here>
23 // retn
24 // #IFDEF CONFIG_SMP
25 // .spin
26 // <any necessary steps to be able to jump back safely>
27 / SPIN_ON_LOCK(reg, .BeginYourFunction)
28 // #ENDIF
29 //
30 #ifdef CONFIG_SMP
31 #define LOCK lock
32 #define ACQUIRE_SPINLOCK(x, y) \
33 lock bts dword ptr [x], 0; \
34 jb y
35 #define RELEASE_SPINLOCK(x) mov byte ptr [x], 0
36 #define SPIN_ON_LOCK(x, y) \
37 1: \
38 test dword ptr [x], 1; \
39 jz y; \
40 pause; \
41 jmp 1b
42 #else
43 #define LOCK
44 #define ACQUIRE_SPINLOCK(x, y)
45 #define RELEASE_SPINLOCK(x)
46 #endif
47
48 //
49 // These macros control common execution paths for Traps and System Call Code
50 // TODO
51 //
52