From 95968a8292e7c252369c94cc428730e70983e19e Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Tue, 17 Jan 2006 05:05:35 +0000 Subject: [PATCH] * Add more documented flags from ks386.inc to asm.h * Isolate and clean-up the VMWare hack; the shared trap exit macro can now be implemented. svn path=/trunk/; revision=20933 --- reactos/include/ndk/asm.h | 5 ++- reactos/ntoskrnl/ke/i386/syscall.S | 59 +++++++++---------------- reactos/ntoskrnl/ke/i386/usercall_asm.S | 20 ++------- 3 files changed, 28 insertions(+), 56 deletions(-) diff --git a/reactos/include/ndk/asm.h b/reactos/include/ndk/asm.h index a42a82e4436..34928b269ba 100644 --- a/reactos/include/ndk/asm.h +++ b/reactos/include/ndk/asm.h @@ -354,10 +354,13 @@ Author: #define CBSTACK_RESULT_LENGTH 0x24 // -// NTSTATUS Codes +// NTSTATUS and Bugcheck Codes // #ifdef __ASM__ #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C +#define STATUS_NO_CALLBACK_ACTIVE 0xC0000258 +#define APC_INDEX_MISMATCH 1 +#define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A #endif // diff --git a/reactos/ntoskrnl/ke/i386/syscall.S b/reactos/ntoskrnl/ke/i386/syscall.S index 10033e7f888..427f61315a6 100644 --- a/reactos/ntoskrnl/ke/i386/syscall.S +++ b/reactos/ntoskrnl/ke/i386/syscall.S @@ -7,8 +7,6 @@ #include #include -#define APC_INDEX_MISMATCH 1 -#define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A .globl _KiServiceExit .globl _KiServiceExit2 @@ -18,7 +16,7 @@ .intel_syntax noprefix /* - * There are 3 main types of Trap Entries: + * There are 3 main types of Trap Entries: <= Move this to asmmacro.S * * - System Calls * - TODO @@ -31,7 +29,7 @@ */ /* - * There are 3 main types of Trap Exits: + * There are 3 main types of Trap Exits: <= Correct some things and move to asmmacro.S * * - KiServiceExit * - Clear interrupt flag @@ -66,17 +64,10 @@ * All these are exemplified by the 3 trap exits shown above */ -/* - * There is also common Debug Code present in the common exit code, which - * in turn calls common code to save the debug registers - */ - /* * FIXMEs: - * - Dig in trap code and see why we need to push/pop the segments, - * which -shouldn't- be needed on syscalls; one of the things - * missing for this to work is lazy loading in the GPF handler, - * but there are other things to consider. + * - Figure out why ES/DS gets messed up in VMWare, when doing KiServiceExit only, + * and only when called from user-mode, and returning to user-mode. * - Use macros and merge with trap.s nicely */ @@ -159,14 +150,12 @@ _KiFastCallEntry: /* Push previous mode */ push UserMode -.att_syntax - /* Save other registers */ - sub $0xC, %esp // + 0x70 - pushl $KGDT_R3_DATA + RPL_MASK // + 0x40 - pushl $KGDT_R3_DATA + RPL_MASK // + 0x44 - pushl $0 // + 0x48 - sub $0x30, %esp // + 0x70 -.intel_syntax noprefix + /* Skip the other registers */ + sub esp, 0x48 + + /* Hack: it seems that on VMWare someone damages ES/DS on exit. Investigate! */ + mov dword ptr [esp+KTRAP_FRAME_DS], KGDT_R3_DATA + RPL_MASK + mov dword ptr [esp+KTRAP_FRAME_ES], KGDT_R3_DATA + RPL_MASK /* Make space for us on the stack */ sub ebp, 0x29C @@ -216,15 +205,13 @@ _KiSystemService: /* Save the old previous mode */ push ss:[esi+KTHREAD_PREVIOUS_MODE] - -.att_syntax - /* Save other registers */ - sub $0xC, %esp // + 0x70 - pushl %ds // + 0x40 - pushl %es // + 0x44 - pushl %gs // + 0x48 - sub $0x30, %esp // + 0x70 -.intel_syntax noprefix + + /* Skip the other registers */ + sub esp, 0x48 + + /* Hack: it seems that on VMWare someone damages ES/DS on exit. Investigate! */ + mov [esp+KTRAP_FRAME_DS], ds + mov [esp+KTRAP_FRAME_ES], es /* Set the new previous mode based on the saved CS selector */ mov ebx, [esp+0x6C] @@ -424,6 +411,10 @@ _KiServiceExit: /* Check for, and deliver, User-Mode APCs if needed */ CHECK_FOR_APC_DELIVER 1 + /* Hack for VMWare: Sometimes ES/DS seem to be invalid when returning to user-mode. Investigate! */ + mov es, [ebp+KTRAP_FRAME_ES] + mov ds, [ebp+KTRAP_FRAME_DS] + // ========================= COMMON TRAP EXIT CODE ===================// #ifdef DBG /* Assert the flags */ @@ -515,14 +506,6 @@ ModeOk: jz CommonStackClean // ==================== END IF FULL RESTORE NEEDED ====================// -//badbadbad - add esp, 0x30 - pop gs - pop es - pop ds - add esp, 0x14 -//badbadbad - /* Restore FS */ RestoreFs: lea esp, [ebp+KTRAP_FRAME_FS] diff --git a/reactos/ntoskrnl/ke/i386/usercall_asm.S b/reactos/ntoskrnl/ke/i386/usercall_asm.S index 277803a2f4c..512cad0eed4 100644 --- a/reactos/ntoskrnl/ke/i386/usercall_asm.S +++ b/reactos/ntoskrnl/ke/i386/usercall_asm.S @@ -9,17 +9,9 @@ /* INCLUDES ******************************************************************/ #include -//#include -#define APC_INDEX_MISMATCH 1 -#define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A -#define STATUS_NO_CALLBACK_ACTIVE 0xC0000258 +#include .intel_syntax noprefix -// This file is a work in progress. Most of the code is currently disabled. - -/* GLOBALS ****************************************************************/ -.extern PVOID _KeUserCallbackDispatcher - /* FUNCTIONS ****************************************************************/ .globl _KiGetUserModeStackAddress@0 @@ -186,8 +178,7 @@ DontBias: lea esi, [edx+KTRAP_FRAME_FS] rep movsd - /* TODO: Ugly hack because of some missing logic in syscall.s */ - mov dword ptr [esp+KTRAP_FRAME_GS], 0 + /* VMWARE Hack because ES/DS sometimes gets smashed when returning to User-Mode. Investigate! */ mov dword ptr [esp+KTRAP_FRAME_DS], KGDT_R3_DATA + RPL_MASK mov dword ptr [esp+KTRAP_FRAME_ES], KGDT_R3_DATA + RPL_MASK @@ -209,12 +200,7 @@ DontBias: sti /* Write the debug data */ - mov edi, [ebp+KTRAP_FRAME_EBP] - mov edx, [ebp+KTRAP_FRAME_EIP] - 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 + SET_TF_DEBUG_HEADER /* Exit to user-mode */ jmp _KiServiceExit