[NTOSKRNL]
[reactos.git] / ntoskrnl / ke / i386 / usercall_asm.S
index 61a4717..a5ab6c9 100644 (file)
@@ -8,14 +8,20 @@
 
 /* INCLUDES ******************************************************************/
 
-#include <asm.h>
+#include <asm.inc>
+#include <ks386.inc>
 #include <internal/i386/asmmacro.S>
-.intel_syntax noprefix
+
+EXTERN _MmGrowKernelStack@4:PROC
+EXTERN _KeUserCallbackDispatcher:PROC
+EXTERN @KiServiceExit@8:PROC
+EXTERN _KeGetCurrentIrql@0:PROC
+EXTERN _KeBugCheckEx@20:PROC
 
 /* FUNCTIONS ****************************************************************/
+.code
 
-.globl _KiGetUserModeStackAddress@0
-.func KiGetUserModeStackAddress@0
+PUBLIC _KiGetUserModeStackAddress@0
 _KiGetUserModeStackAddress@0:
 
     /* Get the current thread's trapframe and return the esp */
@@ -24,10 +30,9 @@ _KiGetUserModeStackAddress@0:
     lea eax, [eax+KTRAP_FRAME_ESP]
     ret
 
-.endfunc
 
 /*++
- * @name KiCallUserMode 
+ * @name KiCallUserMode
  *
  *     The KiSwitchToUserMode routine sets up a Trap Frame and a Callback stack
  *     for the purpose of switching to user mode. The actual final jump is done
@@ -50,8 +55,7 @@ _KiGetUserModeStackAddress@0:
  *         This call MUST be paired by interrupt 0x2B or NtCallbackReturn.
  *
  *--*/
-.globl _KiCallUserMode@8
-.func KiCallUserMode@8
+PUBLIC _KiCallUserMode@8
 _KiCallUserMode@8:
 
     /* Save volatile registers */
@@ -99,7 +103,7 @@ ApcsEnabled:
 #endif
 
     /* Get the lowest stack limit and check if we can handle it */
-    lea eax, [esp-0x3000]
+    lea eax, [esp-HEX(3000)]
     cmp eax, [ebx+KTHREAD_STACK_LIMIT]
     jnb StackOk
 
@@ -127,7 +131,7 @@ StackOk:
     mov [ebx+KTHREAD_CALLBACK_STACK], esp
 
     /* Align stack on 16-byte boundary */
-    and esp, ~15
+    and esp, NOT 15
     mov edi, esp
 
     /* Set destination and origin NPX Areas */
@@ -178,7 +182,7 @@ DontBias:
 
     /* Copy DR7 */
     mov edi, [edx+KTRAP_FRAME_DR7]
-    test edi, ~DR7_RESERVED_MASK
+    test edi, NOT DR7_RESERVED_MASK
     mov [esp+KTRAP_FRAME_DR7], edi
 
     /* Check if we need to save debug registers */
@@ -200,11 +204,9 @@ SetEip:
     /* Bring interrupts back */
     sti
 
-    /* Write the debug data */
-    SET_TF_DEBUG_HEADER
-
     /* Exit to user-mode */
-    jmp _KiServiceExit
+    mov ecx, esp
+    jmp @KiServiceExit@8
 
 SaveDebug:
 
@@ -225,7 +227,6 @@ GrowFailed:
     /* Return */
     ret 8
 
-.endfunc
 
 /*++
  * @name NtCallbackReturn
@@ -250,8 +251,7 @@ GrowFailed:
  * @remark This call MUST be paired with KeUserModeCallback.
  *
  *--*/
-.globl _NtCallbackReturn@12
-.func NtCallbackReturn@12
+PUBLIC _NtCallbackReturn@12
 _NtCallbackReturn@12:
 
     /* Get the current thread and make sure we have a callback stack */
@@ -315,7 +315,7 @@ CheckDebug:
     and dword ptr [edi+KTRAP_FRAME_DR7], 0
 
     /* Check if debugging was active */
-    test byte ptr [eax+KTHREAD_DEBUG_ACTIVE], 0xFF
+    test byte ptr [eax+KTHREAD_DEBUG_ACTIVE], HEX(0FF)
     jnz RestoreDebug
 
 RestoreStack:
@@ -406,10 +406,9 @@ NoStack:
     /* Return failure */
     mov eax, STATUS_NO_CALLBACK_ACTIVE
     ret 12
-.endfunc
 
 /*++
- * @name KeSwitchKernelStack 
+ * @name KeSwitchKernelStack
  *
  *     The KeSwitchKernelStack routine switches from the current thread's stack
  *     to the new specified base and limit.
@@ -420,16 +419,15 @@ NoStack:
  * @param StackLimit
  *        Pointer to the new Stack Limit of the thread.
  *
- * @return The previous Stack Limit of the thread.
+ * @return The previous Stack Base of the thread.
  *
- * @remark This routine should typically only be used when converting from a 
+ * @remark This routine should typically only be used when converting from a
  *         non-GUI to a GUI Thread. The caller is responsible for freeing the
  *         previous stack. The new stack values MUST be valid before calling
  *         this routine.
  *
  *--*/
-.globl _KeSwitchKernelStack@8
-.func KeSwitchKernelStack@8
+PUBLIC _KeSwitchKernelStack@8
 _KeSwitchKernelStack@8:
 
     /* Save volatiles */
@@ -470,7 +468,7 @@ _KeSwitchKernelStack@8:
     pop edi
 
     /* Save old stack base and get new limit/base */
-    mov eax, [edx+KTHREAD_STACK_LIMIT]
+    mov eax, [edx+KTHREAD_STACK_BASE]
     mov ecx, [esp+12]
     mov esi, [esp+16]
 
@@ -514,4 +512,5 @@ V86Switch:
     pop edi
     pop esi
     ret 8
-.endfunc
+
+END