* Add more PSDK defintions to asm.h
* Use these new definitions instead of constants in syscall.S
* Document the macros using doxygen-compatible format, and convert SET_TF_DEBUG_HEADER to as macro instead of CPP macro.
* Use SET_TF_DEBUG_HEADER in system call handlers instead of duplicating the code.
Modified: trunk/reactos/include/ndk/asm.h
Modified: trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S

Modified: trunk/reactos/include/ndk/asm.h
--- trunk/reactos/include/ndk/asm.h	2006-01-17 01:22:21 UTC (rev 20929)
+++ trunk/reactos/include/ndk/asm.h	2006-01-17 03:00:21 UTC (rev 20930)
@@ -361,6 +361,20 @@
 #endif
 
 //
+// System Call Table definitions
+//
+#define NUMBER_SERVICE_TABLES                   0x0002
+#define SERVICE_NUMBER_MASK                     0x0FFF
+#define SERVICE_TABLE_SHIFT                     0x0008
+#define SERVICE_TABLE_MASK                      0x0010
+#define SERVICE_TABLE_TEST                      0x0010
+#define SERVICE_DESCRIPTOR_BASE                 0x0000
+#define SERVICE_DESCRIPTOR_COUNT                0x0004
+#define SERVICE_DESCRIPTOR_LIMIT                0x0008
+#define SERVICE_DESCRIPTOR_NUMBER               0x000C
+#define SERVICE_DESCRIPTOR_LENGTH               0x0010
+
+//
 // Generic Definitions
 //
 #define MAXIMUM_IDTVECTOR                       0xFF

Modified: trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
--- trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S	2006-01-17 01:22:21 UTC (rev 20929)
+++ trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S	2006-01-17 03:00:21 UTC (rev 20930)
@@ -46,30 +46,40 @@
 #endif
 
 //
-// SET_TF_DEBUG_HEADER
+// @name SET_TF_DEBUG_HEADER
+//
 // This macro sets up the debug header in the trap frame.
-// Assumptions:
-// ebp = PKTRAP_FRAME
-// edi/ebx = Have been saved and can be used
 //
-#define SET_TF_DEBUG_HEADER \
-    /* Get the Debug Trap Frame EBP/EIP */ \
-    mov ebx, [ebp+KTRAP_FRAME_EBP]; \
-    mov edi, [ebp+KTRAP_FRAME_EIP]; \
-\
-    /* Write the debug data */ \
-    mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx; \
-    mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00; \
-    mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx; \
-    mov [ebp+KTRAP_FRAME_DEBUGEIP], edi;
+// @param None.
+//
+// @remark ebp = PKTRAP_FRAME.
+//         edi/ebx = Have been saved and can be used.
+//
+.macro SET_TF_DEBUG_HEADER
+    /* Get the Debug Trap Frame EBP/EIP */
+    mov ebx, [ebp+KTRAP_FRAME_EBP]
+    mov edi, [ebp+KTRAP_FRAME_EIP]
 
+    /* Write the debug data */
+    mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
+    mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
+    mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
+    mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
+.endm
+
 //
-// These macros help with USer-Mode APC delivery after exiting a trap.
-//
-// CHECK_FOR_APC_DELIVER
+// @name CHECK_FOR_APC_DELIVER
+// 
 // This macro checks if the trapframe indicates a return to user-mode,
 // and, if so, checks if user-mode APCs should be delivered.
 //
+// @param PreserveEax
+//        Determines if EAX should be preserved. Implies that the segment
+//        registers will also be saved.
+//
+// @remark ebp = PKTRAP_FRAME.
+//         ebx = Saved and will be used.
+//
 .macro CHECK_FOR_APC_DELIVER PreserveEax
     /* Check for V86 mode */
     test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
@@ -129,26 +139,28 @@
 2:
 .endm
 
-
 //
-// These macros control common execution paths for Traps and System Call Code
-//
-// TRAP_PROLOG
+// @name TRAP_PROLOG
+// 
 // This macro creates a standard trap entry prologue.
 // It should be used for entry into any kernel trap (KiTrapXx), but not for
 // system calls, which require special handling.
 //
-// Use as follows:
-// _KiTrap00:
-// /* Push fake error code */
-// push 0
+// @param Label
+//        Identifying name of the caller function; will be used to append
+//        to the name V86 and DR helper functions, which must already exist.
 //
-// /* Enter common prologue */
-// TRAP_PROLOG(0)
+// @remark Use as follows:
+//          _KiTrap00:
+//              /* Push fake error code */
+//              push 0
 //
-// /* Handle trap */
-// <Your Trap Code Here>
+//              /* Enter common prologue */
+//              TRAP_PROLOG(0)
 //
+//              /* Handle trap */
+//              <Your Trap Code Here>
+//
 #define TRAP_PROLOG(Label) \
     /* Just to be safe, clear out the HIWORD, since it's reserved */ \
     mov word ptr [esp+2], 0; \

Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
--- trunk/reactos/ntoskrnl/ke/i386/syscall.S	2006-01-17 01:22:21 UTC (rev 20929)
+++ trunk/reactos/ntoskrnl/ke/i386/syscall.S	2006-01-17 03:00:21 UTC (rev 20930)
@@ -238,24 +238,20 @@
     mov ebx, [esi+KTHREAD_TRAP_FRAME]
     mov [ebp+KTRAP_FRAME_EDX], ebx
 
-// ==================== COMMON DR SAVE CHECK.AND DEBUG FRAME SETUP ============//
     /* Flush DR7 */
     and dword ptr [ebp+KTRAP_FRAME_DR7], 0
 
     /* Check if the thread was being debugged */
     test byte ptr [esi+KTHREAD_DEBUG_ACTIVE], 0xFF
-    cld
     //jnz Dr_kss_a
 
-    /* Save a pointer to the trap frame in the TCB */
 SharedCode:
     mov [esi+KTHREAD_TRAP_FRAME], ebp
 
-    /* Get the Debug Trap Frame EBP/EIP */
-    mov ebx, [ebp+KTRAP_FRAME_EBP]
-    mov edi, [ebp+KTRAP_FRAME_EIP]
+    /* Set the trap frame debug header */
+    SET_TF_DEBUG_HEADER
 
-#ifdef DBG
+#ifdef DBG // FIXME: Is this for GDB? Can it be moved in the stub?
     /*
      * We want to know the address from where the syscall stub was called.
      * If PrevMode is KernelMode, that address is stored in our own (kernel)
@@ -269,15 +265,9 @@
     jz PrevWasKernelMode
     mov edi, [edi+4]
 PrevWasKernelMode:
+    mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
 #endif
 
-    /* Write the debug data */
-    mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
-    mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
-    mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
-    mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
-
-// ============= END OF COMMON DR SAVE CHECK.AND DEBUG FRAME SETUP ============//
     /* Enable interrupts */
     sti
 
@@ -288,8 +278,8 @@
      * The offset is related to the Table Index as such: Offset = TableIndex x 10
      */
     mov edi, eax
-    shr edi, 8
-    and edi, 0x10
+    shr edi, SERVICE_TABLE_SHIFT
+    and edi, SERVICE_TABLE_MASK
     mov ecx, edi
 
     /* Now add the thread's base system table to the offset */
@@ -297,8 +287,8 @@
 
     /* Get the true syscall ID and check it */
     mov ebx, eax
-    and eax, 0xFFF
-    cmp eax, [edi+8]
+    and eax, SERVICE_NUMBER_MASK
+    cmp eax, [edi+SERVICE_DESCRIPTOR_LIMIT]
 
     /* Invalid ID, try to load Win32K Table */
     jnb KiBBTUnexpectedRange
@@ -307,7 +297,7 @@
       // <== We don't have a KeGdiFlushUserBatch callback yet (needs to be
       //     sent through the PsInitializeWin32Callouts structure)
     /* Check if this was Win32K */
-    cmp ecx, 0x10
+    cmp ecx, SERVICE_TABLE_TEST
     jnz NotWin32K
 
     /* Get the TEB */
@@ -332,7 +322,7 @@
 
 #ifdef DBG
     /* Increase per-syscall count */
-    mov ecx, [edi+4]
+    mov ecx, [edi+SERVICE_DESCRIPTOR_COUNT]
     jecxz NoCountTable
     inc dword ptr [ecx+eax*4]
 #endif
@@ -342,12 +332,12 @@
     mov esi, edx
 
     /* Allocate room for argument list from kernel stack */
-    mov ebx, [edi+12]
+    mov ebx, [edi+SERVICE_DESCRIPTOR_NUMBER]
     xor ecx, ecx
     mov cl, [eax+ebx]
 
     /* Get pointer to function */
-    mov edi, [edi]
+    mov edi, [edi+SERVICE_DESCRIPTOR_BASE]
     mov ebx, [edi+eax*4]
 
     /* Allocate space on our stack */