From 1479aebda3c0a6e40cd9b62279dd14304fba385a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 17 Sep 2003 04:34:31 +0000 Subject: [PATCH] Moved instruction emulation to dlls/kernel. --- dlls/kernel/Makefile.in | 5 +++-- {memory => dlls/kernel}/instr.c | 31 +++++-------------------------- dlls/kernel/wowthunk.c | 13 +++++++++---- dlls/ntdll/Makefile.in | 1 - dlls/ntdll/signal_i386.c | 14 ++++---------- 5 files changed, 21 insertions(+), 43 deletions(-) rename {memory => dlls/kernel}/instr.c (96%) diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index b86a36fb719..41febad51c9 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -31,6 +31,7 @@ C_SRCS = \ file16.c \ format_msg.c \ heap.c \ + instr.c \ kernel_main.c \ lcformat.c \ local16.c \ @@ -48,6 +49,7 @@ C_SRCS = \ stress.c \ string.c \ sync.c \ + system.c \ tape.c \ task.c \ thread.c \ @@ -61,8 +63,7 @@ C_SRCS = \ C_SRCS16 = \ error16.c \ - registry16.c \ - system.c + registry16.c ASM_SRCS = relay16asm.s diff --git a/memory/instr.c b/dlls/kernel/instr.c similarity index 96% rename from memory/instr.c rename to dlls/kernel/instr.c index 0d83ac47f6e..87f006c0d39 100644 --- a/memory/instr.c +++ b/dlls/kernel/instr.c @@ -66,19 +66,6 @@ inline static void *get_stack( CONTEXT86 *context ) } -/*********************************************************************** - * timer_thread - */ -static DWORD CALLBACK timer_thread( void *dummy ) -{ - for (;;) - { - Sleep(55); - DOSMEM_Tick( 0 ); - } - return 0; /* unreached */ -} - /*********************************************************************** * INSTR_ReplaceSelector * @@ -94,13 +81,9 @@ static BOOL INSTR_ReplaceSelector( CONTEXT86 *context, WORD *sel ) { if (*sel == 0x40) { -#if 0 /* hack until this is moved to kernel */ static WORD sys_timer = 0; if (!sys_timer) sys_timer = CreateSystemTimer( 55, DOSMEM_Tick ); -#endif - static HANDLE sys_thread; - if (!sys_thread) sys_thread = CreateThread( NULL, 0, timer_thread, NULL, 0, NULL ); *sel = DOSMEM_BiosDataSeg; return TRUE; } @@ -502,7 +485,8 @@ DWORD INSTR_EmulateInstruction( CONTEXT86 *context ) switch(instr[1]) { case 0x22: /* mov eax, crX */ - switch (instr[2]) { + switch (instr[2]) + { case 0xc0: ERR("mov eax,cr0 at 0x%08lx, EAX=0x%08lx\n", context->Eip,context->Eax ); @@ -513,7 +497,8 @@ DWORD INSTR_EmulateInstruction( CONTEXT86 *context ) } break; /*fallthrough to bad instruction handling */ case 0x20: /* mov crX, eax */ - switch (instr[2]) { + switch (instr[2]) + { case 0xe0: /* mov cr4, eax */ /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs * bit 0: VME Virtual Mode Exception ? @@ -699,13 +684,7 @@ DWORD INSTR_EmulateInstruction( CONTEXT86 *context ) break; /* Unable to emulate it */ case 0xcd: /* int */ - if (IS_SELECTOR_SYSTEM(context->SegCs)) - { - /* Win32 applications cannot use interrupts */ - ret = EXCEPTION_ACCESS_VIOLATION; - break; - } - else if (!Dosvm.EmulateInterruptPM && !DPMI_LoadDosSystem()) + if (!Dosvm.EmulateInterruptPM && !DPMI_LoadDosSystem()) { ERR("could not initialize interrupt handling\n"); } diff --git a/dlls/kernel/wowthunk.c b/dlls/kernel/wowthunk.c index 9a204bffa69..eb2741f763a 100644 --- a/dlls/kernel/wowthunk.c +++ b/dlls/kernel/wowthunk.c @@ -170,16 +170,21 @@ static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RE NtCurrentTeb()->cur_stack = frame32->frame16; _LeaveWin16Lock(); } - else + else if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION || + record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION) { if (IS_SELECTOR_SYSTEM(context->SegCs)) { if (fix_selector( context )) return ExceptionContinueExecution; } - else /* check for Win16 __GP handler */ + else { - SEGPTR gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) ); - if (gpHandler) + SEGPTR gpHandler; + + if (!INSTR_EmulateInstruction( context )) return ExceptionContinueExecution; + + /* check for Win16 __GP handler */ + if ((gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) ))) { WORD *stack = wine_ldt_get_ptr( context->SegSs, context->Esp ); *--stack = context->SegCs; diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index cbaeb13c875..af7ad13590b 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -21,7 +21,6 @@ C_SRCS = \ $(TOPOBJDIR)/memory/environ.c \ $(TOPOBJDIR)/memory/global.c \ $(TOPOBJDIR)/memory/heap.c \ - $(TOPOBJDIR)/memory/instr.c \ $(TOPOBJDIR)/memory/selector.c \ $(TOPOBJDIR)/memory/string.c \ $(TOPOBJDIR)/memory/virtual.c \ diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 57de180a789..54d265deafe 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -407,7 +407,6 @@ typedef struct #include "wine/exception.h" #include "global.h" -#include "miscemu.h" #include "syslevel.h" #include "wine/debug.h" @@ -748,13 +747,6 @@ static inline DWORD get_fpu_code( const CONTEXT *context ) static void do_segv( CONTEXT *context, int trap_code, void *cr2, int err_code ) { EXCEPTION_RECORD rec; - DWORD page_fault_code = EXCEPTION_ACCESS_VIOLATION; - -#ifdef FAULT_ADDRESS - /* we want the page-fault case to be fast */ - if (trap_code == T_PAGEFLT) - if (!(page_fault_code = VIRTUAL_HandleFault( cr2 ))) return; -#endif rec.ExceptionRecord = NULL; rec.ExceptionFlags = EXCEPTION_CONTINUABLE; @@ -778,15 +770,17 @@ static void do_segv( CONTEXT *context, int trap_code, void *cr2, int err_code ) case T_SEGNPFLT: /* Segment not present exception */ case T_PROTFLT: /* General protection fault */ case T_UNKNOWN: /* Unknown fault code */ - if (!(rec.ExceptionCode = INSTR_EmulateInstruction( context ))) return; + rec.ExceptionCode = err_code ? EXCEPTION_ACCESS_VIOLATION : EXCEPTION_PRIV_INSTRUCTION; break; case T_PAGEFLT: /* Page fault */ #ifdef FAULT_ADDRESS + if (!(rec.ExceptionCode = VIRTUAL_HandleFault( cr2 ))) return; rec.NumberParameters = 2; rec.ExceptionInformation[0] = (err_code & 2) != 0; rec.ExceptionInformation[1] = (DWORD)cr2; +#else + rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; #endif - rec.ExceptionCode = page_fault_code; break; case T_ALIGNFLT: /* Alignment check exception */ /* FIXME: pass through exception handler first? */