Previous 15994 Revisions Next

r12162 Wednesday 6th July, 2011 at 03:22:33 UTC by Barry Rodewald
i386: Various fixes. [Barry Rodewald]
- Load LDT before segment registers when switching tasks,
- Set IF after the instruction following STI,
- Reset IF after MOV SS or POP SS for one instruction,
- Fixed LSL instruction when modrm < 0xc0.
[src/emu/cpu/i386]i386.c i386op16.c i386op32.c i386ops.c i386ops.h i386priv.h

src/emu/cpu/i386/i386op16.c
r12161r12162
15691569
15701570static void I386OP(pop_ss16)(i386_state *cpustate)         // Opcode 0x17
15711571{
1572   if(cpustate->IF != 0) // if external interrupts are enabled
1573   {
1574      cpustate->IF = 0;  // reset IF for the next instruction
1575      cpustate->delayed_interrupt_enable = 1;
1576   }
1577
15721578   cpustate->sreg[SS].selector = POP16(cpustate);
15731579   if( PROTECTED_MODE ) {
15741580      i386_load_segment_descriptor(cpustate,SS);
r12161r12162
33273333   if(PROTECTED_MODE)
33283334   {
33293335      memset(&seg, 0, sizeof(seg));
3330      seg.selector = LOAD_RM16(modrm);
3336      if(modrm >= 0xc0)
3337      {
3338         seg.selector = LOAD_RM16(modrm);
3339      }
3340      else
3341      {
3342         UINT32 ea = GetEA(cpustate,modrm);
3343         seg.selector = READ16(cpustate,ea);
3344      }
33313345      if(seg.selector == 0)
33323346      {
33333347         SetZF(0);  // not a valid segment
src/emu/cpu/i386/i386priv.h
r12161r12162
229229   UINT8 CPL;  // current privilege level
230230
231231   UINT8 performed_intersegment_jump;
232   UINT8 delayed_interrupt_enable;
232233
233234   UINT32 cr[5];      // Control registers
234235   UINT32 dr[8];      // Debug registers
src/emu/cpu/i386/i386ops.h
r12161r12162
290290   { 0x02,      OP_2BYTE|OP_I386,         I386OP(lar_r16_rm16),         I386OP(lar_r32_rm32),      },
291291   { 0x03,      OP_2BYTE|OP_I386,         I386OP(lsl_r16_rm16),         I386OP(lsl_r32_rm32),      },
292292   { 0x06,      OP_2BYTE|OP_I386,         I386OP(clts),               I386OP(clts),            },
293   { 0x07,      OP_2BYTE|OP_I386,         I386OP(loadall),            I386OP(loadall),         },
293294   { 0x08,      OP_2BYTE|OP_I486,         I486OP(invd),               I486OP(invd),            },
294295   { 0x09,      OP_2BYTE|OP_I486,         I486OP(wbinvd),               I486OP(wbinvd),            },
295296   { 0x0B,      OP_2BYTE|OP_I386,         I386OP(unimplemented),         I386OP(unimplemented),      },
src/emu/cpu/i386/i386.c
r12161r12162
790790
791791   /* Load incoming task state from the new task's TSS */
792792   tss = cpustate->task.base;
793   cpustate->ldtr.segment = READ16(cpustate,tss+0x2a) & 0xffff;
794   seg.selector = cpustate->ldtr.segment;
795   i386_load_protected_mode_segment(cpustate,&seg);
796   cpustate->ldtr.limit = seg.limit;
797   cpustate->ldtr.base = seg.base;
798   cpustate->ldtr.flags = seg.flags;
793799   cpustate->eip = READ16(cpustate,tss+0x0e);
794800   set_flags(cpustate,READ16(cpustate,tss+0x10));
795801   REG16(AX) = READ16(cpustate,tss+0x12);
r12161r12162
808814   i386_load_segment_descriptor(cpustate, SS);
809815   cpustate->sreg[DS].selector = READ16(cpustate,tss+0x28) & 0xffff;
810816   i386_load_segment_descriptor(cpustate, DS);
811   cpustate->ldtr.segment = READ16(cpustate,tss+0x2a) & 0xffff;
812   seg.selector = cpustate->ldtr.segment;
813   i386_load_protected_mode_segment(cpustate,&seg);
814   cpustate->ldtr.limit = seg.limit;
815   cpustate->ldtr.base = seg.base;
816   cpustate->ldtr.flags = seg.flags;
817817
818818   /* Set the busy bit in the new task's descriptor */
819819   if(selector & 0x0004)
r12161r12162
900900
901901   /* Load incoming task state from the new task's TSS */
902902   tss = cpustate->task.base;
903   cpustate->ldtr.segment = READ32(cpustate,tss+0x60) & 0xffff;
904   seg.selector = cpustate->ldtr.segment;
905   i386_load_protected_mode_segment(cpustate,&seg);
906   cpustate->ldtr.limit = seg.limit;
907   cpustate->ldtr.base = seg.base;
908   cpustate->ldtr.flags = seg.flags;
903909   cpustate->cr[3] = READ32(cpustate,tss+0x1c);  // CR3 (PDBR)
904910   cpustate->eip = READ32(cpustate,tss+0x20);
905911   set_flags(cpustate,READ32(cpustate,tss+0x24));
r12161r12162
923929   i386_load_segment_descriptor(cpustate, FS);
924930   cpustate->sreg[GS].selector = READ32(cpustate,tss+0x5c) & 0xffff;
925931   i386_load_segment_descriptor(cpustate, GS);
926   cpustate->ldtr.segment = READ32(cpustate,tss+0x60) & 0xffff;
927   seg.selector = cpustate->ldtr.segment;
928   i386_load_protected_mode_segment(cpustate,&seg);
929   cpustate->ldtr.limit = seg.limit;
930   cpustate->ldtr.base = seg.base;
931   cpustate->ldtr.flags = seg.flags;
932932
933933   /* Set the busy bit in the new task's descriptor */
934934   if(selector & 0x0004)
r12161r12162
10551055      {
10561056         switch(desc.flags & 0x000f)
10571057         {
1058         case 0x01:  // 286 Available TSS
10581059         case 0x09:  // 386 Available TSS
1059            popmessage("JMP: Available TSS.");
1060            logerror("JMP: Available 386 TSS at %08x\n",cpustate->pc);
10601061            memset(&desc, 0, sizeof(desc));
10611062            desc.selector = segment;
10621063            i386_load_protected_mode_segment(cpustate,&desc);
r12161r12162
10841085            break;
10851086         case 0x04:  // 286 Call Gate
10861087         case 0x0c:  // 386 Call Gate
1087            popmessage("JMP: Call gate.");
1088            logerror("JMP: Call gate at %08x\n",cpustate->pc);
10881089            SetRPL = 1;
10891090            memset(&call_gate, 0, sizeof(call_gate));
10901091            call_gate.segment = segment;
r12161r12162
11671168            offset = call_gate.offset;
11681169            break;
11691170         case 0x05:  // Task Gate
1170            popmessage("JMP: Task gate.");
1171            logerror("JMP: Task gate at %08x\n",cpustate->pc);
11711172            memset(&call_gate, 0, sizeof(call_gate));
11721173            call_gate.segment = segment;
11731174            i386_load_call_gate(cpustate,&call_gate);
r12161r12162
12051206                  FAULT(FAULT_GP,call_gate.selector & 0xfffc)
12061207               }
12071208            }
1208            if((call_gate.ar & 0x000f) == 0x0009)
1209            if((call_gate.ar & 0x000f) == 0x0009 || (call_gate.ar & 0x000f) == 0x0001)
12091210            {
12101211               logerror("JMP: Task Gate TSS: Segment is not an available TSS.\n");
12111212               FAULT(FAULT_GP,call_gate.selector & 0xfffc)
r12161r12162
13441345      {
13451346         switch(desc.flags & 0x000f)
13461347         {
1348         case 0x01:  // Available 286 TSS
13471349         case 0x09:  // Available 386 TSS
1348            logerror("CALL: Available TSS (386) at %08x\n",cpustate->pc);
1350            logerror("CALL: Available TSS at %08x\n",cpustate->pc);
13491351            if(DPL < CPL)
13501352            {
13511353               logerror("CALL: TSS: DPL is less than CPL.\n");
r12161r12162
25792581
25802582   cpustate->a20_mask = ~0;
25812583
2582   cpustate->cr[0] = 0x7ffffff0; // reserved bits set to 1
2584   cpustate->cr[0] = 0x7fffffe0; // reserved bits set to 1
25832585   cpustate->eflags = 0;
25842586   cpustate->eflags_mask = 0x00030000;
25852587   cpustate->eip = 0xfff0;
r12161r12162
26572659      debugger_instruction_hook(device, cpustate->pc);
26582660
26592661      i386_check_irq_line(cpustate);
2662      if(cpustate->delayed_interrupt_enable != 0)
2663      {
2664         cpustate->IF = 1;
2665         cpustate->delayed_interrupt_enable = 0;
2666      }
26602667      I386OP(decode_opcode)(cpustate);
26612668   }
26622669   cpustate->tsc += (cycles - cpustate->cycles);
src/emu/cpu/i386/i386ops.c
r12161r12162
753753      selector = READ16(cpustate,ea);
754754      CYCLES(cpustate,CYCLES_MOV_MEM_SREG);
755755   }
756
757   if(s == SS)
758   {
759      if(cpustate->IF != 0) // if external interrupts are enabled
760      {
761         cpustate->IF = 0;  // reset IF for the next instruction
762         cpustate->delayed_interrupt_enable = 1;
763      }
764   }
765
756766   cpustate->sreg[s].selector = selector;
757767   i386_load_segment_descriptor(cpustate, s );
758768}
r12161r12162
947957      break;
948958   }
949959
950   REG32(EDI) += ((cpustate->DF) ? -1 : 1) * size;
960   if(cpustate->address_size)
961      REG32(EDI) += ((cpustate->DF) ? -1 : 1) * size;
962   else
963      REG16(DI) += ((cpustate->DF) ? -1 : 1) * size;
951964   CYCLES(cpustate,CYCLES_INS);   // TODO: Confirm this value
952965}
953966
r12161r12162
9941007      break;
9951008   }
9961009
997   REG32(ESI) += ((cpustate->DF) ? -1 : 1) * size;
1010   if(cpustate->address_size)
1011      REG32(ESI) += ((cpustate->DF) ? -1 : 1) * size;
1012   else
1013      REG16(SI) += ((cpustate->DF) ? -1 : 1) * size;
9981014   CYCLES(cpustate,CYCLES_OUTS);   // TODO: Confirm this value
9991015}
10001016
r12161r12162
15501566
15511567static void I386OP(sti)(i386_state *cpustate)            // Opcode 0xfb
15521568{
1553   cpustate->IF = 1;
1569   cpustate->delayed_interrupt_enable = 1;  // IF is set after the next instruction.
15541570   CYCLES(cpustate,CYCLES_STI);
15551571}
15561572
r12161r12162
23362352
23372353static void I386OP(clts)(i386_state *cpustate)            // Opcode 0x0f 0x06
23382354{
2339   // TODO: #GP(0) is executed
2355   // Privileged instruction, CPL must be zero.  Can be used in real or v86 mode.
2356   if(PROTECTED_MODE && cpustate->CPL != 0)
2357      FAULT(FAULT_GP,0)
23402358   cpustate->cr[0] &= ~0x08;   /* clear TS bit */
23412359   CYCLES(cpustate,CYCLES_CLTS);
23422360}
r12161r12162
23642382   CYCLES(cpustate,1);      // TODO: correct cycle count
23652383}
23662384
2385static void I386OP(loadall)(i386_state *cpustate)      // Opcode 0x0f 0x07 (0x0f 0x05 on 80286), undocumented
2386{
2387   popmessage("LOADALL instruction hit!");
2388   CYCLES(cpustate,1);      // TODO: correct cycle count
2389}
2390
23672391static void I386OP(unimplemented)(i386_state *cpustate)
23682392{
23692393   fatalerror("i386: Unimplemented opcode %02X at %08X", cpustate->opcode, cpustate->pc - 1 );
src/emu/cpu/i386/i386op32.c
r12161r12162
14451445
14461446static void I386OP(pop_ss32)(i386_state *cpustate)         // Opcode 0x17
14471447{
1448   if(cpustate->IF != 0) // if external interrupts are enabled
1449   {
1450      cpustate->IF = 0;  // reset IF for the next instruction
1451      cpustate->delayed_interrupt_enable = 1;
1452   }
1453
14481454   cpustate->sreg[SS].selector = POP32(cpustate);
14491455   if( PROTECTED_MODE ) {
14501456      i386_load_segment_descriptor(cpustate,SS);
r12161r12162
31443150   if(PROTECTED_MODE)
31453151   {
31463152      memset(&seg, 0, sizeof(seg));
3147      seg.selector = LOAD_RM32(modrm);
3153      if(modrm >= 0xc0)
3154      {
3155         seg.selector = LOAD_RM32(modrm);
3156      }
3157      else
3158      {
3159         UINT32 ea = GetEA(cpustate,modrm);
3160         seg.selector = READ32(cpustate,ea);
3161      }
31483162      if(seg.selector == 0)
31493163      {
31503164         SetZF(0);  // not a valid segment

Previous 15994 Revisions Next


© 1998-2018 The MESS Team