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)
9 /* INCLUDES ******************************************************************/
14 #define INT_32_DPL0 0x8E00
15 #define INT_32_DPL3 0xEE00
17 .intel_syntax noprefix
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:
25 // ACQUIRE_SPINLOCK(reg, .spin)
26 // <thread-safe code here>
27 // RELEASE_SPINLOCK(reg)
32 // <any necessary steps to be able to jump back safely>
33 / SPIN_ON_LOCK(reg, .BeginYourFunction)
38 #define ACQUIRE_SPINLOCK(x, y) \
39 lock bts dword ptr [x], 0; \
41 #define RELEASE_SPINLOCK(x) mov byte ptr [x], 0
42 #define SPIN_ON_LOCK(x, y) \
44 test dword ptr [x], 1; \
50 #define ACQUIRE_SPINLOCK(x, y)
51 #define RELEASE_SPINLOCK(x)
57 // This macro creates an IDT entry for the given handler
60 // Pointer to the IDT handler
63 // Descriptor Bits to associate
67 .macro idt Handler, Bits
74 // @name GENERATE_IDT_STUB
76 // This macro creates an IDT entry for an unexpected interrupt handler.
82 .macro GENERATE_IDT_STUB Number
83 idt _KiUnexpectedInterrupt&Number, INT_32_DPL0
87 // @name GENERATE_IDT_STUBS
89 // This macro creates unexpected interrupt IDT entries.
96 .macro GENERATE_IDT_STUBS
105 // @name GENERATE_INT_HANDLER
107 // This macro creates an unexpected interrupt handler.
113 .macro GENERATE_INT_HANDLER Number
114 .func KiUnexpectedInterrupt&Number
115 _KiUnexpectedInterrupt&Number:
116 mov eax, PRIMARY_VECTOR_BASE + Number
117 jmp _KiEndUnexpectedRange@0
122 // @name GENERATE_INT_HANDLERS
124 // This macro creates the unexpected interrupt handlers.
131 .macro GENERATE_INT_HANDLERS
134 GENERATE_INT_HANDLER %i