- Merge from trunk up to r45543
[reactos.git] / ntoskrnl / include / internal / i386 / asmmacro.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/include/i386/asmmacro.S
5 * PURPOSE: Assembly Macros for Spinlocks and common Trap Code
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ndk/asm.h>
12
13 // Arguments for idt
14 #define INT_32_DPL0 0x8E00
15 #define INT_32_DPL3 0xEE00
16
17 .intel_syntax noprefix
18
19 //
20 // These macros are inlined equivalents of KiAcquire/ReleaseSpinlock, that is,
21 // they will not be compiled into non-SMP builds. Usage is as follows:
22 //
23 // .BeginYourFunction
24 // mov reg, lockaddr
25 // ACQUIRE_SPINLOCK(reg, .spin)
26 // <thread-safe code here>
27 // RELEASE_SPINLOCK(reg)
28 // <misc code here>
29 // retn
30 // #IFDEF CONFIG_SMP
31 // .spin
32 // <any necessary steps to be able to jump back safely>
33 / SPIN_ON_LOCK(reg, .BeginYourFunction)
34 // #ENDIF
35 //
36 #ifdef CONFIG_SMP
37 #define LOCK lock
38 #define ACQUIRE_SPINLOCK(x, y) \
39 lock bts dword ptr [x], 0; \
40 jb y
41 #define RELEASE_SPINLOCK(x) mov byte ptr [x], 0
42 #define SPIN_ON_LOCK(x, y) \
43 1: \
44 test dword ptr [x], 1; \
45 jz y; \
46 pause; \
47 jmp 1b
48 #else
49 #define LOCK
50 #define ACQUIRE_SPINLOCK(x, y)
51 #define RELEASE_SPINLOCK(x)
52 #endif
53
54 //
55 // @name IDT
56 //
57 // This macro creates an IDT entry for the given handler
58 //
59 // @param Handler
60 // Pointer to the IDT handler
61 //
62 // @param Bits
63 // Descriptor Bits to associate
64 //
65 // @remark None.
66 //
67 .macro idt Handler, Bits
68 .long \Handler
69 .short \Bits
70 .short KGDT_R0_CODE
71 .endm
72
73 //
74 // @name GENERATE_IDT_STUB
75 //
76 // This macro creates an IDT entry for an unexpected interrupt handler.
77 //
78 // @param None.
79 //
80 // @remark None.
81 //
82 .macro GENERATE_IDT_STUB Number
83 idt _KiUnexpectedInterrupt&Number, INT_32_DPL0
84 .endm
85
86 //
87 // @name GENERATE_IDT_STUBS
88 //
89 // This macro creates unexpected interrupt IDT entries.
90 //
91 // @param None.
92 //
93 // @remark None.
94 //
95 .altmacro
96 .macro GENERATE_IDT_STUBS
97 .set i, 0
98 .rept 208
99 GENERATE_IDT_STUB %i
100 .set i, i + 1
101 .endr
102 .endm
103
104 //
105 // @name GENERATE_INT_HANDLER
106 //
107 // This macro creates an unexpected interrupt handler.
108 //
109 // @param None.
110 //
111 // @remark None.
112 //
113 .macro GENERATE_INT_HANDLER Number
114 .func KiUnexpectedInterrupt&Number
115 _KiUnexpectedInterrupt&Number:
116 mov eax, PRIMARY_VECTOR_BASE + Number
117 jmp _KiEndUnexpectedRange@0
118 .endfunc
119 .endm
120
121 //
122 // @name GENERATE_INT_HANDLERS
123 //
124 // This macro creates the unexpected interrupt handlers.
125 //
126 // @param None.
127 //
128 // @remark None.
129 //
130 .altmacro
131 .macro GENERATE_INT_HANDLERS
132 .set i, 0
133 .rept 208
134 GENERATE_INT_HANDLER %i
135 .set i, i + 1
136 .endr
137 .endm