From 0e0f29420279642b21b4f848ba214ef5feeee4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Mon, 4 Jul 2005 20:20:19 +0000 Subject: [PATCH] better compatibility while in v86-mode (Strike Commander etc.) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2228 --- include/cpu.h | 4 ++- src/cpu/core_normal/prefix_0f.h | 6 ++-- src/cpu/cpu.cpp | 56 +++++++++++++++++++++++++-------- src/dos/dos_execute.cpp | 11 ++++--- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/include/cpu.h b/include/cpu.h index ac6b6489..01783145 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -63,8 +63,10 @@ void CPU_ARPL(Bitu & dest_sel,Bitu src_sel); void CPU_LAR(Bitu selector,Bitu & ar); void CPU_LSL(Bitu selector,Bitu & limit); -bool CPU_SET_CRX(Bitu cr,Bitu value); +void CPU_SET_CRX(Bitu cr,Bitu value); +bool CPU_WRITE_CRX(Bitu cr,Bitu value); Bitu CPU_GET_CRX(Bitu cr); +bool CPU_READ_CRX(Bitu cr,Bit32u & retvalue); void CPU_SMSW(Bitu & word); Bitu CPU_LMSW(Bitu word); diff --git a/src/cpu/core_normal/prefix_0f.h b/src/cpu/core_normal/prefix_0f.h index ca5c7d58..4b5103cf 100644 --- a/src/cpu/core_normal/prefix_0f.h +++ b/src/cpu/core_normal/prefix_0f.h @@ -128,7 +128,9 @@ Bitu which=(rm >> 3) & 7; if (rm >= 0xc0 ) { GetEArd; - *eard=CPU_GET_CRX(which); + Bit32u crx_value; + if (CPU_READ_CRX(which,crx_value)) RUNEXCEPTION(); + *eard=crx_value; } else { GetEAa; LOG(LOG_CPU,LOG_ERROR)("MOV XXX,CR%d with non-register",which); @@ -153,7 +155,7 @@ Bitu which=(rm >> 3) & 7; if (rm >= 0xc0 ) { GetEArd; - if (CPU_SET_CRX(which,*eard)) RUNEXCEPTION(); + if (CPU_WRITE_CRX(which,*eard)) RUNEXCEPTION(); } else goto illegal_opcode; } break; diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index 61e53db5..ea886505 100644 --- a/src/cpu/cpu.cpp +++ b/src/cpu/cpu.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: cpu.cpp,v 1.70 2005-04-25 19:01:11 qbix79 Exp $ */ +/* $Id: cpu.cpp,v 1.71 2005-07-04 20:20:18 c2woody Exp $ */ #include #include "dosbox.h" @@ -82,7 +82,7 @@ void CPU_Core_Dyn_X86_Init(void); } #elif defined(CPU_CHECK_EXCEPT) #define CPU_CHECK_COND(cond,msg,exc,sel) { \ - if (cond) { + if (cond) { \ CPU_Exception(exc,sel); \ return; \ } \ @@ -158,10 +158,14 @@ bool CPU_STI(void) { } bool CPU_POPF(Bitu use32) { - if ((reg_flags & FLAG_VM) && (GETFLAG(IOPL)!=FLAG_IOPL)) + if (cpu.pmode && GETFLAG(VM) && (GETFLAG(IOPL)!=FLAG_IOPL)) { + /* Not enough privileges to execute POPF */ return CPU_PrepareException(EXCEPTION_GP,0); - Bitu mask=cpu.cpl ? FMASK_NORMAL : FMASK_ALL; - if ((GETFLAG_IOPL0)) mask &= (~FLAG_IOPL); + if (cpu.pmode && !GETFLAG(VM) && (GETFLAG_IOPL #include @@ -131,7 +131,7 @@ bool DOS_Terminate(bool tsr) { /* Set the CS:IP stored in int 0x22 back on the stack */ mem_writew(SegPhys(ss)+reg_sp+0,RealOff(old22)); mem_writew(SegPhys(ss)+reg_sp+2,RealSeg(old22)); - mem_writew(SegPhys(ss)+reg_sp+4,0x200); //stack isn't preserved + mem_writew(SegPhys(ss)+reg_sp+4,reg_flags&(~FLAG_CF)); // Free memory owned by process if (!tsr) DOS_FreeProcessMemory(mempsp); DOS_UpdatePSPName(); @@ -376,10 +376,13 @@ bool DOS_Execute(char * name,PhysPt block_pt,Bit8u flags) { reg_sp-=6; mem_writew(SegPhys(ss)+reg_sp+0,RealOff(csip)); mem_writew(SegPhys(ss)+reg_sp+2,RealSeg(csip)); - mem_writew(SegPhys(ss)+reg_sp+4,0x200); + /* DOS starts programs with a RETF, so our IRET + should not modify the flags (e.g. IOPL in v86 mode) */ + mem_writew(SegPhys(ss)+reg_sp+4,reg_flags&(~FLAG_CF)); /* Setup the rest of the registers */ reg_ax=0;reg_si=0x100; - reg_cx=reg_dx=reg_bx=reg_di=reg_bp=0; + reg_cx=reg_dx=reg_bx=reg_di=0; + reg_bp=0x91c; /* DOS internal stack begin relict */ SegSet16(ds,pspseg);SegSet16(es,pspseg); #if C_DEBUG /* Started from debug.com, then set breakpoint at start */