Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port; Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX); Finished the 586MC1; Added 8087 emulation; Moved Cyrix 6x86'es to the Dev branch; Sanitized/cleaned up memregs.c/h and intel.c/h; Split the chipsets from machines and sanitized Port 92 emulation; Added support for the 15bpp mode to the Compaq ATI 28800; Moved the MR 386DX and 486 machines to the Dev branch; Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00; Ported the new timer code from PCem; Cleaned up the CPU table of unused stuff and better optimized its structure; Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch; Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem; Added the AHA-1540A and the BusTek BT-542B; Moved the Sumo SCSI-AT to the Dev branch; Minor IDE, FDC, and floppy drive code clean-ups; Made NCR 5380/53C400-based cards' BIOS address configurable; Got rid of the legacy romset variable; Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit; Added the Amstead PPC512 per PCem patch by John Elliott; Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages); Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing; Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem; Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit; Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement; Amstrad MegaPC does now works correctly with non-internal graphics card; The SLiRP code no longer casts a packed struct type to a non-packed struct type; The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present; The S3 Virge on BeOS is no longer broken (was broken by build #1591); OS/2 2.0 build 6.167 now sees key presses again; Xi8088 now work on CGA again; 86F images converted from either the old or new variants of the HxC MFM format now work correctly; Hardware interrupts with a vector of 0xFF are now handled correctly; OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct; Fixed VNC keyboard input bugs; Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver; Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly; Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4; Compaq Portable now works with all graphics cards; Fixed various MDSI Genius bugs; Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly; Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355; OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400. Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391. Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389. Fixed a minor IDE timing bug, fixes #388. Fixed Toshiba T1000 RAM issues, fixes #379. Fixed EGA/(S)VGA overscan border handling, fixes #378; Got rid of the now long useless IDE channel 2 auto-removal, fixes #370; Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366; Ported the Unicode CD image file name fix from VARCem, fixes #365; Fixed high density floppy disks on the Xi8088, fixes #359; Fixed some bugs in the Hercules emulation, fixes #346, fixes #358; Fixed the SCSI hard disk mode sense pages, fixes #356; Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349; Fixed bugs in the serial mouse emulation, fixes #344; Compiled 86Box binaries now include all the required .DLL's, fixes #341; Made some combo boxes in the Settings dialog slightly wider, fixes #276.
This commit is contained in:
331
src/cpu/x86seg.c
331
src/cpu/x86seg.c
@@ -27,11 +27,12 @@
|
||||
#include "../86box.h"
|
||||
#include "cpu.h"
|
||||
#include "../device.h"
|
||||
#include "../timer.h"
|
||||
#include "../machine/machine.h"
|
||||
#include "../mem.h"
|
||||
#include "../nvr.h"
|
||||
#include "x86.h"
|
||||
#include "386.h"
|
||||
#include "x86_flags.h"
|
||||
#include "386_common.h"
|
||||
|
||||
|
||||
@@ -80,13 +81,14 @@ x86seg_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
void x86abort(const char *format, ...)
|
||||
void x86abort(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vfprintf(stdlog, format, ap);
|
||||
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
fflush(stdlog);
|
||||
|
||||
nvr_save();
|
||||
#ifdef ENABLE_808X_LOG
|
||||
dumpregs(1);
|
||||
@@ -103,7 +105,7 @@ static void seg_reset(x86seg *s)
|
||||
s->limit = 0xFFFF;
|
||||
s->limit_low = 0;
|
||||
s->limit_high = 0xffff;
|
||||
if(s == &_cs)
|
||||
if(s == &cpu_state.seg_cs)
|
||||
{
|
||||
// TODO - When the PC is reset, initialization of the CS descriptor must be like the annotated line below.
|
||||
//s->base = AT ? (cpu_16bitbus ? 0xFF0000 : 0xFFFF0000) : 0xFFFF0;
|
||||
@@ -120,19 +122,19 @@ static void seg_reset(x86seg *s)
|
||||
|
||||
void x86seg_reset()
|
||||
{
|
||||
seg_reset(&_cs);
|
||||
seg_reset(&_ds);
|
||||
seg_reset(&_es);
|
||||
seg_reset(&_fs);
|
||||
seg_reset(&_gs);
|
||||
seg_reset(&_ss);
|
||||
seg_reset(&cpu_state.seg_cs);
|
||||
seg_reset(&cpu_state.seg_ds);
|
||||
seg_reset(&cpu_state.seg_es);
|
||||
seg_reset(&cpu_state.seg_fs);
|
||||
seg_reset(&cpu_state.seg_gs);
|
||||
seg_reset(&cpu_state.seg_ss);
|
||||
}
|
||||
|
||||
void x86_doabrt(int x86_abrt)
|
||||
{
|
||||
CS = oldcs;
|
||||
cpu_state.pc = cpu_state.oldpc;
|
||||
_cs.access = (oldcpl << 5) | 0x80;
|
||||
cpu_state.seg_cs.access = (oldcpl << 5) | 0x80;
|
||||
|
||||
if (msw & 1)
|
||||
pmodeint(x86_abrt, 0);
|
||||
@@ -141,22 +143,22 @@ void x86_doabrt(int x86_abrt)
|
||||
uint32_t addr = (x86_abrt << 2) + idt.base;
|
||||
if (stack32)
|
||||
{
|
||||
writememw(ss,ESP-2,flags);
|
||||
writememw(ss,ESP-2,cpu_state.flags);
|
||||
writememw(ss,ESP-4,CS);
|
||||
writememw(ss,ESP-6,cpu_state.pc);
|
||||
ESP-=6;
|
||||
}
|
||||
else
|
||||
{
|
||||
writememw(ss,((SP-2)&0xFFFF),flags);
|
||||
writememw(ss,((SP-2)&0xFFFF),cpu_state.flags);
|
||||
writememw(ss,((SP-4)&0xFFFF),CS);
|
||||
writememw(ss,((SP-6)&0xFFFF),cpu_state.pc);
|
||||
SP-=6;
|
||||
}
|
||||
|
||||
flags&=~I_FLAG;
|
||||
flags&=~T_FLAG;
|
||||
oxpc=cpu_state.pc;
|
||||
cpu_state.flags&=~I_FLAG;
|
||||
cpu_state.flags&=~T_FLAG;
|
||||
oxpc=cpu_state.pc;
|
||||
cpu_state.pc=readmemw(0,addr);
|
||||
loadcs(readmemw(0,addr+2));
|
||||
return;
|
||||
@@ -257,14 +259,14 @@ void do_seg_load(x86seg *s, uint16_t *segdat)
|
||||
s->limit_low = s->limit + 1;
|
||||
}
|
||||
|
||||
if (s == &_ds)
|
||||
if (s == &cpu_state.seg_ds)
|
||||
{
|
||||
if (s->base == 0 && s->limit_low == 0 && s->limit_high == 0xffffffff)
|
||||
cpu_cur_status &= ~CPU_STATUS_NOTFLATDS;
|
||||
else
|
||||
cpu_cur_status |= CPU_STATUS_NOTFLATDS;
|
||||
}
|
||||
if (s == &_ss)
|
||||
if (s == &cpu_state.seg_ss)
|
||||
{
|
||||
if (s->base == 0 && s->limit_low == 0 && s->limit_high == 0xffffffff)
|
||||
cpu_cur_status &= ~CPU_STATUS_NOTFLATSS;
|
||||
@@ -331,11 +333,11 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
uint32_t addr;
|
||||
int dpl;
|
||||
|
||||
if (msw&1 && !(eflags&VM_FLAG))
|
||||
if (msw&1 && !(cpu_state.eflags&VM_FLAG))
|
||||
{
|
||||
if (!(seg&~3))
|
||||
{
|
||||
if (s==&_ss)
|
||||
if (s==&cpu_state.seg_ss)
|
||||
{
|
||||
x86ss(NULL,0);
|
||||
return;
|
||||
@@ -343,14 +345,18 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
s->seg=0;
|
||||
s->access = 0x80;
|
||||
s->base=-1;
|
||||
if (s == &_ds)
|
||||
if (s == &cpu_state.seg_ds)
|
||||
cpu_cur_status |= CPU_STATUS_NOTFLATDS;
|
||||
return;
|
||||
}
|
||||
addr=seg&~7;
|
||||
if (seg&4)
|
||||
{
|
||||
#if 0
|
||||
if (addr>=ldt.limit)
|
||||
#else
|
||||
if ((addr+7)>ldt.limit)
|
||||
#endif
|
||||
{
|
||||
x86gpf("loadseg(): Bigger than LDT limit",seg&~3);
|
||||
return;
|
||||
@@ -359,7 +365,11 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
if (addr>=gdt.limit)
|
||||
#else
|
||||
if ((addr+7)>gdt.limit)
|
||||
#endif
|
||||
{
|
||||
x86gpf("loadseg(): Bigger than GDT limit",seg&~3);
|
||||
return;
|
||||
@@ -372,7 +382,7 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
segdat[2]=readmemw(0,addr+4);
|
||||
segdat[3]=readmemw(0,addr+6); cpl_override=0; if (cpu_state.abrt) return;
|
||||
dpl=(segdat[2]>>13)&3;
|
||||
if (s==&_ss)
|
||||
if (s==&cpu_state.seg_ss)
|
||||
{
|
||||
if (!(seg&~3))
|
||||
{
|
||||
@@ -399,7 +409,7 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
}
|
||||
set_stack32((segdat[3] & 0x40) ? 1 : 0);
|
||||
}
|
||||
else if (s!=&_cs)
|
||||
else if (s!=&cpu_state.seg_cs)
|
||||
{
|
||||
x86seg_log("Seg data %04X %04X %04X %04X\n", segdat[0], segdat[1], segdat[2], segdat[3]);
|
||||
x86seg_log("Seg type %03X\n",segdat[2]&0x1F00);
|
||||
@@ -431,7 +441,7 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
do_seg_load(s, segdat);
|
||||
|
||||
#ifndef CS_ACCESSED
|
||||
if (s != &_cs)
|
||||
if (s != &cpu_state.seg_cs)
|
||||
{
|
||||
#endif
|
||||
#ifdef SEL_ACCESSED
|
||||
@@ -444,9 +454,9 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
#endif
|
||||
s->checked = 0;
|
||||
#ifdef USE_DYNAREC
|
||||
if (s == &_ds)
|
||||
if (s == &cpu_state.seg_ds)
|
||||
codegen_flat_ds = 0;
|
||||
if (s == &_ss)
|
||||
if (s == &cpu_state.seg_ss)
|
||||
codegen_flat_ss = 0;
|
||||
#endif
|
||||
}
|
||||
@@ -455,25 +465,25 @@ void loadseg(uint16_t seg, x86seg *s)
|
||||
s->access = (3 << 5) | 2 | 0x80;
|
||||
s->base = seg << 4;
|
||||
s->seg = seg;
|
||||
if (s == &_ss)
|
||||
set_stack32(0);
|
||||
s->checked = 1;
|
||||
#ifdef USE_DYNAREC
|
||||
if (s == &_ds)
|
||||
if (s == &cpu_state.seg_ds)
|
||||
codegen_flat_ds = 0;
|
||||
if (s == &_ss)
|
||||
if (s == &cpu_state.seg_ss)
|
||||
codegen_flat_ss = 0;
|
||||
#endif
|
||||
if (s == &cpu_state.seg_ss && (cpu_state.eflags & VM_FLAG))
|
||||
set_stack32(0);
|
||||
}
|
||||
|
||||
if (s == &_ds)
|
||||
if (s == &cpu_state.seg_ds)
|
||||
{
|
||||
if (s->base == 0 && s->limit_low == 0 && s->limit_high == 0xffffffff)
|
||||
cpu_cur_status &= ~CPU_STATUS_NOTFLATDS;
|
||||
else
|
||||
cpu_cur_status |= CPU_STATUS_NOTFLATDS;
|
||||
}
|
||||
if (s == &_ss)
|
||||
if (s == &cpu_state.seg_ss)
|
||||
{
|
||||
if (s->base == 0 && s->limit_low == 0 && s->limit_high == 0xffffffff)
|
||||
cpu_cur_status &= ~CPU_STATUS_NOTFLATSS;
|
||||
@@ -491,7 +501,7 @@ void loadcs(uint16_t seg)
|
||||
uint16_t segdat[4];
|
||||
uint32_t addr;
|
||||
x86seg_log("Load CS %04X\n",seg);
|
||||
if (msw&1 && !(eflags&VM_FLAG))
|
||||
if (msw&1 && !(cpu_state.eflags&VM_FLAG))
|
||||
{
|
||||
if (!(seg&~3))
|
||||
{
|
||||
@@ -549,10 +559,10 @@ void loadcs(uint16_t seg)
|
||||
}
|
||||
set_use32(segdat[3] & 0x40);
|
||||
CS=(seg&~3)|CPL;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
use32=(segdat[3]&0x40)?0x300:0;
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
|
||||
|
||||
#ifdef CS_ACCESSED
|
||||
cpl_override = 1;
|
||||
writememw(0, addr+4, segdat[2] | 0x100); /*Set accessed bit*/
|
||||
@@ -576,24 +586,24 @@ void loadcs(uint16_t seg)
|
||||
}
|
||||
else
|
||||
{
|
||||
_cs.base=seg<<4;
|
||||
_cs.limit=0xFFFF;
|
||||
_cs.limit_low = 0;
|
||||
_cs.limit_high = 0xffff;
|
||||
cpu_state.seg_cs.base=seg<<4;
|
||||
cpu_state.seg_cs.limit=0xFFFF;
|
||||
cpu_state.seg_cs.limit_low = 0;
|
||||
cpu_state.seg_cs.limit_high = 0xffff;
|
||||
CS=seg & 0xFFFF;
|
||||
if (eflags&VM_FLAG) _cs.access=(3<<5) | 2 | 0x80;
|
||||
else _cs.access=(0<<5) | 2 | 0x80;
|
||||
if (cpu_state.eflags&VM_FLAG) cpu_state.seg_cs.access=(3<<5) | 2 | 0x80;
|
||||
else cpu_state.seg_cs.access=(0<<5) | 2 | 0x80;
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
}
|
||||
}
|
||||
|
||||
void loadcsjmp(uint16_t seg, uint32_t oxpc)
|
||||
void loadcsjmp(uint16_t seg, uint32_t old_pc)
|
||||
{
|
||||
uint16_t segdat[4];
|
||||
uint32_t addr;
|
||||
uint16_t type,seg2;
|
||||
uint32_t newpc;
|
||||
if (msw&1 && !(eflags&VM_FLAG))
|
||||
if (msw&1 && !(cpu_state.eflags&VM_FLAG))
|
||||
{
|
||||
if (!(seg&~3))
|
||||
{
|
||||
@@ -661,7 +671,7 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc)
|
||||
CS = (seg & ~3) | CPL;
|
||||
segdat[2] = (segdat[2] & ~(3 << (5+8))) | (CPL << (5+8));
|
||||
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
cycles -= timing_jmp_pm;
|
||||
}
|
||||
@@ -757,8 +767,9 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc)
|
||||
}
|
||||
case 0x1C00: case 0x1D00: case 0x1E00: case 0x1F00: /*Conforming*/
|
||||
CS=seg2;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
|
||||
set_use32(segdat[3]&0x40);
|
||||
cpu_state.pc=newpc;
|
||||
|
||||
@@ -779,11 +790,11 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc)
|
||||
|
||||
case 0x100: /*286 Task gate*/
|
||||
case 0x900: /*386 Task gate*/
|
||||
cpu_state.pc=oxpc;
|
||||
cpu_state.pc=old_pc;
|
||||
optype=JMP;
|
||||
cpl_override=1;
|
||||
taskswitch286(seg,segdat,segdat[2]&0x800);
|
||||
flags &= ~NT_FLAG;
|
||||
cpu_state.flags &= ~NT_FLAG;
|
||||
cpl_override=0;
|
||||
return;
|
||||
|
||||
@@ -795,13 +806,13 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc)
|
||||
}
|
||||
else
|
||||
{
|
||||
_cs.base=seg<<4;
|
||||
_cs.limit=0xFFFF;
|
||||
_cs.limit_low = 0;
|
||||
_cs.limit_high = 0xffff;
|
||||
cpu_state.seg_cs.base=seg<<4;
|
||||
cpu_state.seg_cs.limit=0xFFFF;
|
||||
cpu_state.seg_cs.limit_low = 0;
|
||||
cpu_state.seg_cs.limit_high = 0xffff;
|
||||
CS=seg;
|
||||
if (eflags&VM_FLAG) _cs.access=(3<<5) | 2 | 0x80;
|
||||
else _cs.access=(0<<5) | 2 | 0x80;
|
||||
if (cpu_state.eflags&VM_FLAG) cpu_state.seg_cs.access=(3<<5) | 2 | 0x80;
|
||||
else cpu_state.seg_cs.access=(0<<5) | 2 | 0x80;
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
cycles -= timing_jmp_rm;
|
||||
}
|
||||
@@ -885,7 +896,7 @@ void loadcscall(uint16_t seg)
|
||||
|
||||
int csout = output;
|
||||
|
||||
if (msw&1 && !(eflags&VM_FLAG))
|
||||
if (msw&1 && !(cpu_state.eflags&VM_FLAG))
|
||||
{
|
||||
if (csout) x86seg_log("Protected mode CS load! %04X\n",seg);
|
||||
if (!(seg&~3))
|
||||
@@ -964,8 +975,9 @@ void loadcscall(uint16_t seg)
|
||||
else /*On non-conforming segments, set RPL = CPL*/
|
||||
seg = (seg & ~3) | CPL;
|
||||
CS=seg;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
|
||||
if (csout) x86seg_log("Complete\n");
|
||||
cycles -= timing_call_pm;
|
||||
}
|
||||
@@ -1080,7 +1092,11 @@ void loadcscall(uint16_t seg)
|
||||
addr=newss&~7;
|
||||
if (newss&4)
|
||||
{
|
||||
#if 0
|
||||
if (addr>=ldt.limit)
|
||||
#else
|
||||
if ((addr+7)>ldt.limit)
|
||||
#endif
|
||||
{
|
||||
x86abort("Bigger than LDT limit %04X %08X %04X CSC SS\n",newss,addr,ldt.limit);
|
||||
x86ts(NULL,newss&~3);
|
||||
@@ -1090,7 +1106,11 @@ void loadcscall(uint16_t seg)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
if (addr>=gdt.limit)
|
||||
#else
|
||||
if ((addr+7)>gdt.limit)
|
||||
#endif
|
||||
{
|
||||
x86abort("Bigger than GDT limit %04X %04X CSC\n",newss,gdt.limit);
|
||||
x86ts(NULL,newss&~3);
|
||||
@@ -1126,7 +1146,7 @@ void loadcscall(uint16_t seg)
|
||||
if (stack32) ESP=newsp;
|
||||
else SP=newsp;
|
||||
|
||||
do_seg_load(&_ss, segdat2);
|
||||
do_seg_load(&cpu_state.seg_ss, segdat2);
|
||||
|
||||
x86seg_log("Set access 1\n");
|
||||
|
||||
@@ -1137,8 +1157,9 @@ void loadcscall(uint16_t seg)
|
||||
#endif
|
||||
|
||||
CS=seg2;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
|
||||
set_use32(segdat[3]&0x40);
|
||||
cpu_state.pc=newpc;
|
||||
|
||||
@@ -1216,7 +1237,7 @@ void loadcscall(uint16_t seg)
|
||||
}
|
||||
case 0x1C00: case 0x1D00: case 0x1E00: case 0x1F00: /*Conforming*/
|
||||
CS=seg2;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat[3]&0x40);
|
||||
cpu_state.pc=newpc;
|
||||
@@ -1251,13 +1272,13 @@ void loadcscall(uint16_t seg)
|
||||
}
|
||||
else
|
||||
{
|
||||
_cs.base=seg<<4;
|
||||
_cs.limit=0xFFFF;
|
||||
_cs.limit_low = 0;
|
||||
_cs.limit_high = 0xffff;
|
||||
cpu_state.seg_cs.base=seg<<4;
|
||||
cpu_state.seg_cs.limit=0xFFFF;
|
||||
cpu_state.seg_cs.limit_low = 0;
|
||||
cpu_state.seg_cs.limit_high = 0xffff;
|
||||
CS=seg;
|
||||
if (eflags&VM_FLAG) _cs.access=(3<<5) | 2 | 0x80;
|
||||
else _cs.access=(0<<5) | 2 | 0x80;
|
||||
if (cpu_state.eflags&VM_FLAG) cpu_state.seg_cs.access=(3<<5) | 2 | 0x80;
|
||||
else cpu_state.seg_cs.access=(0<<5) | 2 | 0x80;
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
}
|
||||
}
|
||||
@@ -1269,7 +1290,7 @@ void pmoderetf(int is32, uint16_t off)
|
||||
uint32_t addr, oaddr;
|
||||
uint16_t segdat[4],segdat2[4],seg,newss;
|
||||
uint32_t oldsp=ESP;
|
||||
x86seg_log("RETF %i %04X:%04X %08X %04X\n",is32,CS,cpu_state.pc,cr0,eflags);
|
||||
x86seg_log("RETF %i %04X:%04X %08X %04X\n",is32,CS,cpu_state.pc,cr0,cpu_state.eflags);
|
||||
if (is32)
|
||||
{
|
||||
newpc=POPL();
|
||||
@@ -1367,8 +1388,8 @@ void pmoderetf(int is32, uint16_t off)
|
||||
if (segdat[2] & 0x400)
|
||||
segdat[2] = (segdat[2] & ~(3 << (5+8))) | ((seg & 3) << (5+8));
|
||||
CS = seg;
|
||||
do_seg_load(&_cs, segdat);
|
||||
_cs.access = (_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat[3] & 0x40);
|
||||
|
||||
@@ -1481,7 +1502,7 @@ void pmoderetf(int is32, uint16_t off)
|
||||
set_stack32((segdat2[3] & 0x40) ? 1 : 0);
|
||||
if (stack32) ESP=newsp;
|
||||
else SP=newsp;
|
||||
do_seg_load(&_ss, segdat2);
|
||||
do_seg_load(&cpu_state.seg_ss, segdat2);
|
||||
|
||||
#ifdef SEL_ACCESSED
|
||||
cpl_override = 1;
|
||||
@@ -1498,24 +1519,24 @@ void pmoderetf(int is32, uint16_t off)
|
||||
|
||||
cpu_state.pc=newpc;
|
||||
CS=seg;
|
||||
do_seg_load(&_cs, segdat);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat[3] & 0x40);
|
||||
|
||||
if (stack32) ESP+=off;
|
||||
else SP+=off;
|
||||
|
||||
check_seg_valid(&_ds);
|
||||
check_seg_valid(&_es);
|
||||
check_seg_valid(&_fs);
|
||||
check_seg_valid(&_gs);
|
||||
check_seg_valid(&cpu_state.seg_ds);
|
||||
check_seg_valid(&cpu_state.seg_es);
|
||||
check_seg_valid(&cpu_state.seg_fs);
|
||||
check_seg_valid(&cpu_state.seg_gs);
|
||||
cycles -= timing_retf_pm_outer;
|
||||
}
|
||||
}
|
||||
|
||||
void restore_stack()
|
||||
{
|
||||
ss=oldss; _ss.limit=oldsslimit;
|
||||
ss=oldss; cpu_state.seg_ss.limit=oldsslimit;
|
||||
}
|
||||
|
||||
void pmodeint(int num, int soft)
|
||||
@@ -1529,7 +1550,7 @@ void pmodeint(int num, int soft)
|
||||
uint16_t seg = 0;
|
||||
int new_cpl;
|
||||
|
||||
if (eflags&VM_FLAG && IOPL!=3 && soft)
|
||||
if (cpu_state.eflags&VM_FLAG && IOPL!=3 && soft)
|
||||
{
|
||||
x86seg_log("V86 banned int\n");
|
||||
x86gpf(NULL,0);
|
||||
@@ -1628,7 +1649,7 @@ void pmodeint(int num, int soft)
|
||||
x86np("Int gate CS not present\n", segdat[1] & 0xfffc);
|
||||
return;
|
||||
}
|
||||
if ((eflags&VM_FLAG) && DPL2)
|
||||
if ((cpu_state.eflags&VM_FLAG) && DPL2)
|
||||
{
|
||||
x86gpf(NULL,segdat[1]&0xFFFC);
|
||||
return;
|
||||
@@ -1698,7 +1719,7 @@ void pmodeint(int num, int soft)
|
||||
set_stack32((segdat3[3] & 0x40) ? 1 : 0);
|
||||
if (stack32) ESP=newsp;
|
||||
else SP=newsp;
|
||||
do_seg_load(&_ss, segdat3);
|
||||
do_seg_load(&cpu_state.seg_ss, segdat3);
|
||||
|
||||
#ifdef CS_ACCESSED
|
||||
cpl_override = 1;
|
||||
@@ -1710,20 +1731,20 @@ void pmodeint(int num, int soft)
|
||||
cpl_override=1;
|
||||
if (type>=0x800)
|
||||
{
|
||||
if (eflags & VM_FLAG)
|
||||
if (cpu_state.eflags & VM_FLAG)
|
||||
{
|
||||
PUSHL(GS);
|
||||
PUSHL(FS);
|
||||
PUSHL(DS);
|
||||
PUSHL(ES); if (cpu_state.abrt) return;
|
||||
loadseg(0,&_ds);
|
||||
loadseg(0,&_es);
|
||||
loadseg(0,&_fs);
|
||||
loadseg(0,&_gs);
|
||||
loadseg(0,&cpu_state.seg_ds);
|
||||
loadseg(0,&cpu_state.seg_es);
|
||||
loadseg(0,&cpu_state.seg_fs);
|
||||
loadseg(0,&cpu_state.seg_gs);
|
||||
}
|
||||
PUSHL(oldss);
|
||||
PUSHL(oldsp);
|
||||
PUSHL(flags|(eflags<<16));
|
||||
PUSHL(cpu_state.flags|(cpu_state.eflags<<16));
|
||||
PUSHL(CS);
|
||||
PUSHL(cpu_state.pc); if (cpu_state.abrt) return;
|
||||
}
|
||||
@@ -1731,12 +1752,12 @@ void pmodeint(int num, int soft)
|
||||
{
|
||||
PUSHW(oldss);
|
||||
PUSHW(oldsp);
|
||||
PUSHW(flags);
|
||||
PUSHW(cpu_state.flags);
|
||||
PUSHW(CS);
|
||||
PUSHW(cpu_state.pc); if (cpu_state.abrt) return;
|
||||
}
|
||||
cpl_override=0;
|
||||
_cs.access=0 | 0x80;
|
||||
cpu_state.seg_cs.access=0 | 0x80;
|
||||
cycles -= timing_int_pm_outer - timing_int_pm;
|
||||
break;
|
||||
}
|
||||
@@ -1751,20 +1772,20 @@ void pmodeint(int num, int soft)
|
||||
x86np("Int gate CS not present\n", segdat[1] & 0xfffc);
|
||||
return;
|
||||
}
|
||||
if ((eflags & VM_FLAG) && DPL2<CPL)
|
||||
if ((cpu_state.eflags & VM_FLAG) && DPL2<CPL)
|
||||
{
|
||||
x86gpf(NULL,seg&~3);
|
||||
return;
|
||||
}
|
||||
if (type>0x800)
|
||||
{
|
||||
PUSHL(flags|(eflags<<16));
|
||||
PUSHL(cpu_state.flags|(cpu_state.eflags<<16));
|
||||
PUSHL(CS);
|
||||
PUSHL(cpu_state.pc); if (cpu_state.abrt) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
PUSHW(flags);
|
||||
PUSHW(cpu_state.flags);
|
||||
PUSHW(CS);
|
||||
PUSHW(cpu_state.pc); if (cpu_state.abrt) return;
|
||||
}
|
||||
@@ -1774,9 +1795,9 @@ void pmodeint(int num, int soft)
|
||||
x86gpf(NULL,seg&~3);
|
||||
return;
|
||||
}
|
||||
do_seg_load(&_cs, segdat2);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat2);
|
||||
CS = (seg & ~3) | new_cpl;
|
||||
_cs.access = (_cs.access & ~(3 << 5)) | (new_cpl << 5);
|
||||
cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~(3 << 5)) | (new_cpl << 5);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
if (type>0x800) cpu_state.pc=segdat[0]|(segdat[3]<<16);
|
||||
else cpu_state.pc=segdat[0];
|
||||
@@ -1788,13 +1809,13 @@ void pmodeint(int num, int soft)
|
||||
cpl_override = 0;
|
||||
#endif
|
||||
|
||||
eflags&=~VM_FLAG;
|
||||
cpu_state.eflags&=~VM_FLAG;
|
||||
cpu_cur_status &= ~CPU_STATUS_V86;
|
||||
if (!(type&0x100))
|
||||
{
|
||||
flags&=~I_FLAG;
|
||||
cpu_state.flags&=~I_FLAG;
|
||||
}
|
||||
flags&=~(T_FLAG|NT_FLAG);
|
||||
cpu_state.flags&=~(T_FLAG|NT_FLAG);
|
||||
cycles -= timing_int_pm;
|
||||
break;
|
||||
|
||||
@@ -1853,14 +1874,14 @@ void pmodeiret(int is32)
|
||||
uint16_t seg;
|
||||
uint32_t addr, oaddr;
|
||||
uint32_t oldsp=ESP;
|
||||
if (is386 && (eflags&VM_FLAG))
|
||||
if (is386 && (cpu_state.eflags&VM_FLAG))
|
||||
{
|
||||
if (IOPL!=3)
|
||||
{
|
||||
x86gpf(NULL,0);
|
||||
return;
|
||||
}
|
||||
oxpc=cpu_state.pc;
|
||||
oxpc=cpu_state.pc;
|
||||
if (is32)
|
||||
{
|
||||
newpc=POPL();
|
||||
@@ -1873,19 +1894,19 @@ void pmodeiret(int is32)
|
||||
seg=POPW();
|
||||
tempflags=POPW(); if (cpu_state.abrt) return;
|
||||
}
|
||||
cpu_state.pc=newpc;
|
||||
_cs.base=seg<<4;
|
||||
_cs.limit=0xFFFF;
|
||||
_cs.limit_low = 0;
|
||||
_cs.limit_high = 0xffff;
|
||||
_cs.access |= 0x80;
|
||||
cpu_state.pc = newpc;
|
||||
cpu_state.seg_cs.base=seg<<4;
|
||||
cpu_state.seg_cs.limit=0xFFFF;
|
||||
cpu_state.seg_cs.limit_low = 0;
|
||||
cpu_state.seg_cs.limit_high = 0xffff;
|
||||
cpu_state.seg_cs.access |= 0x80;
|
||||
CS=seg;
|
||||
flags=(flags&0x3000)|(tempflags&0xCFD5)|2;
|
||||
cpu_state.flags=(cpu_state.flags&0x3000)|(tempflags&0xCFD5)|2;
|
||||
cycles -= timing_iret_rm;
|
||||
return;
|
||||
}
|
||||
|
||||
if (flags&NT_FLAG)
|
||||
if (cpu_state.flags&NT_FLAG)
|
||||
{
|
||||
seg=readmemw(tr.base,0);
|
||||
addr=seg&~7;
|
||||
@@ -1913,7 +1934,7 @@ void pmodeiret(int is32)
|
||||
cpl_override=0;
|
||||
return;
|
||||
}
|
||||
oxpc=cpu_state.pc;
|
||||
oxpc=cpu_state.pc;
|
||||
flagmask=0xFFFF;
|
||||
if (CPL) flagmask&=~0x3000;
|
||||
if (IOPL<CPL) flagmask&=~0x200;
|
||||
@@ -1930,34 +1951,34 @@ void pmodeiret(int is32)
|
||||
segs[1]=POPL();
|
||||
segs[2]=POPL();
|
||||
segs[3]=POPL(); if (cpu_state.abrt) { ESP = oldsp; return; }
|
||||
eflags=tempflags>>16;
|
||||
cpu_state.eflags=tempflags>>16;
|
||||
cpu_cur_status |= CPU_STATUS_V86;
|
||||
loadseg(segs[0],&_es);
|
||||
do_seg_v86_init(&_es);
|
||||
loadseg(segs[1],&_ds);
|
||||
do_seg_v86_init(&_ds);
|
||||
loadseg(segs[0],&cpu_state.seg_es);
|
||||
do_seg_v86_init(&cpu_state.seg_es);
|
||||
loadseg(segs[1],&cpu_state.seg_ds);
|
||||
do_seg_v86_init(&cpu_state.seg_ds);
|
||||
cpu_cur_status |= CPU_STATUS_NOTFLATDS;
|
||||
loadseg(segs[2],&_fs);
|
||||
do_seg_v86_init(&_fs);
|
||||
loadseg(segs[3],&_gs);
|
||||
do_seg_v86_init(&_gs);
|
||||
loadseg(segs[2],&cpu_state.seg_fs);
|
||||
do_seg_v86_init(&cpu_state.seg_fs);
|
||||
loadseg(segs[3],&cpu_state.seg_gs);
|
||||
do_seg_v86_init(&cpu_state.seg_gs);
|
||||
|
||||
cpu_state.pc=newpc;
|
||||
_cs.base=seg<<4;
|
||||
_cs.limit=0xFFFF;
|
||||
_cs.limit_low = 0;
|
||||
_cs.limit_high = 0xffff;
|
||||
cpu_state.seg_cs.base=seg<<4;
|
||||
cpu_state.seg_cs.limit=0xFFFF;
|
||||
cpu_state.seg_cs.limit_low = 0;
|
||||
cpu_state.seg_cs.limit_high = 0xffff;
|
||||
CS=seg;
|
||||
_cs.access=(3<<5) | 2 | 0x80;
|
||||
cpu_state.seg_cs.access=(3<<5) | 2 | 0x80;
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
|
||||
|
||||
ESP=newsp;
|
||||
loadseg(newss,&_ss);
|
||||
do_seg_v86_init(&_ss);
|
||||
loadseg(newss,&cpu_state.seg_ss);
|
||||
do_seg_v86_init(&cpu_state.seg_ss);
|
||||
cpu_cur_status |= CPU_STATUS_NOTFLATSS;
|
||||
use32=0;
|
||||
cpu_cur_status &= ~CPU_STATUS_USE32;
|
||||
flags=(tempflags&0xFFD5)|2;
|
||||
cpu_state.flags=(tempflags&0xFFD5)|2;
|
||||
cycles -= timing_iret_v86;
|
||||
return;
|
||||
}
|
||||
@@ -2040,8 +2061,8 @@ void pmodeiret(int is32)
|
||||
if ((seg&3) == CPL)
|
||||
{
|
||||
CS=seg;
|
||||
do_seg_load(&_cs, segdat);
|
||||
_cs.access = (_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat[3]&0x40);
|
||||
|
||||
@@ -2129,7 +2150,7 @@ void pmodeiret(int is32)
|
||||
set_stack32((segdat2[3] & 0x40) ? 1 : 0);
|
||||
if (stack32) ESP=newsp;
|
||||
else SP=newsp;
|
||||
do_seg_load(&_ss, segdat2);
|
||||
do_seg_load(&cpu_state.seg_ss, segdat2);
|
||||
|
||||
#ifdef SEL_ACCESSED
|
||||
cpl_override = 1;
|
||||
@@ -2145,20 +2166,20 @@ void pmodeiret(int is32)
|
||||
segdat[2] = (segdat[2] & ~(3 << (5+8))) | ((seg & 3) << (5+8));
|
||||
|
||||
CS=seg;
|
||||
do_seg_load(&_cs, segdat);
|
||||
_cs.access = (_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat);
|
||||
cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~(3 << 5)) | ((CS & 3) << 5);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat[3] & 0x40);
|
||||
|
||||
check_seg_valid(&_ds);
|
||||
check_seg_valid(&_es);
|
||||
check_seg_valid(&_fs);
|
||||
check_seg_valid(&_gs);
|
||||
check_seg_valid(&cpu_state.seg_ds);
|
||||
check_seg_valid(&cpu_state.seg_es);
|
||||
check_seg_valid(&cpu_state.seg_fs);
|
||||
check_seg_valid(&cpu_state.seg_gs);
|
||||
cycles -= timing_iret_pm_outer;
|
||||
}
|
||||
cpu_state.pc=newpc;
|
||||
flags=(flags&~flagmask)|(tempflags&flagmask&0xFFD5)|2;
|
||||
if (is32) eflags=tempflags>>16;
|
||||
cpu_state.flags=(cpu_state.flags&~flagmask)|(tempflags&flagmask&0xFFD5)|2;
|
||||
if (is32) cpu_state.eflags=tempflags>>16;
|
||||
}
|
||||
|
||||
void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
@@ -2205,12 +2226,12 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
}
|
||||
if (cpu_state.abrt) return;
|
||||
|
||||
if (optype==IRET) flags&=~NT_FLAG;
|
||||
if (optype==IRET) cpu_state.flags&=~NT_FLAG;
|
||||
|
||||
cpu_386_flags_rebuild();
|
||||
writememl(tr.base,0x1C,cr3);
|
||||
writememl(tr.base,0x20,cpu_state.pc);
|
||||
writememl(tr.base,0x24,flags|(eflags<<16));
|
||||
writememl(tr.base,0x24,cpu_state.flags|(cpu_state.eflags<<16));
|
||||
|
||||
writememl(tr.base,0x28,EAX);
|
||||
writememl(tr.base,0x2C,ECX);
|
||||
@@ -2276,8 +2297,8 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
flushmmucache();
|
||||
|
||||
cpu_state.pc=new_pc;
|
||||
flags=new_flags;
|
||||
eflags=new_flags>>16;
|
||||
cpu_state.flags=new_flags;
|
||||
cpu_state.eflags=new_flags>>16;
|
||||
cpu_386_flags_extract();
|
||||
|
||||
ldt.seg=new_ldt;
|
||||
@@ -2290,7 +2311,7 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
}
|
||||
ldt.base=(readmemw(0,templ+2))|(readmemb(0,templ+4)<<16)|(readmemb(0,templ+7)<<24);
|
||||
|
||||
if (eflags & VM_FLAG)
|
||||
if (cpu_state.eflags & VM_FLAG)
|
||||
{
|
||||
loadcs(new_cs);
|
||||
set_use32(0);
|
||||
@@ -2353,7 +2374,7 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
}
|
||||
|
||||
CS=new_cs;
|
||||
do_seg_load(&_cs, segdat2);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat2);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(segdat2[3] & 0x40);
|
||||
cpu_cur_status &= ~CPU_STATUS_V86;
|
||||
@@ -2368,11 +2389,11 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
ESI=new_esi;
|
||||
EDI=new_edi;
|
||||
|
||||
loadseg(new_es,&_es);
|
||||
loadseg(new_ss,&_ss);
|
||||
loadseg(new_ds,&_ds);
|
||||
loadseg(new_fs,&_fs);
|
||||
loadseg(new_gs,&_gs);
|
||||
loadseg(new_es,&cpu_state.seg_es);
|
||||
loadseg(new_ss,&cpu_state.seg_ss);
|
||||
loadseg(new_ds,&cpu_state.seg_ds);
|
||||
loadseg(new_fs,&cpu_state.seg_fs);
|
||||
loadseg(new_gs,&cpu_state.seg_gs);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2393,11 +2414,11 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
}
|
||||
if (cpu_state.abrt) return;
|
||||
|
||||
if (optype==IRET) flags&=~NT_FLAG;
|
||||
if (optype==IRET) cpu_state.flags&=~NT_FLAG;
|
||||
|
||||
cpu_386_flags_rebuild();
|
||||
writememw(tr.base,0x0E,cpu_state.pc);
|
||||
writememw(tr.base,0x10,flags);
|
||||
writememw(tr.base,0x10,cpu_state.flags);
|
||||
|
||||
writememw(tr.base,0x12,AX);
|
||||
writememw(tr.base,0x14,CX);
|
||||
@@ -2454,7 +2475,7 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
msw |= 8;
|
||||
|
||||
cpu_state.pc=new_pc;
|
||||
flags=new_flags;
|
||||
cpu_state.flags=new_flags;
|
||||
cpu_386_flags_extract();
|
||||
|
||||
ldt.seg=new_ldt;
|
||||
@@ -2526,7 +2547,7 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
}
|
||||
|
||||
CS=new_cs;
|
||||
do_seg_load(&_cs, segdat2);
|
||||
do_seg_load(&cpu_state.seg_cs, segdat2);
|
||||
if (CPL==3 && oldcpl!=3) flushmmucache_cr3();
|
||||
set_use32(0);
|
||||
|
||||
@@ -2539,13 +2560,13 @@ void taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
|
||||
ESI=new_esi | 0xFFFF0000;
|
||||
EDI=new_edi | 0xFFFF0000;
|
||||
|
||||
loadseg(new_es,&_es);
|
||||
loadseg(new_ss,&_ss);
|
||||
loadseg(new_ds,&_ds);
|
||||
loadseg(new_es,&cpu_state.seg_es);
|
||||
loadseg(new_ss,&cpu_state.seg_ss);
|
||||
loadseg(new_ds,&cpu_state.seg_ds);
|
||||
if (is386)
|
||||
{
|
||||
loadseg(0,&_fs);
|
||||
loadseg(0,&_gs);
|
||||
loadseg(0,&cpu_state.seg_fs);
|
||||
loadseg(0,&cpu_state.seg_gs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user