Previous 15994 Revisions Next

r6359 Wednesday 11th November, 2009 at 06:42:36 UTC by Barry Rodewald
[I386] Adding extra i386 flags to the flags register, implemented LEAVE instruction, improving protected mode interrupts (has been accepted for MAME).
[src/emu/cpu/i386]i386.c i386op16.c i386op32.c i386ops.h i386priv.h

src/emu/cpu/i386/i386op16.c
r6358r6359
11371137   CYCLES(cpustate,CYCLES_LEA);
11381138}
11391139
1140static void I386OP(enter16)(i386_state *cpustate)         // Opcode 0xc8
1141{
1142   UINT16 framesize = FETCH16(cpustate);
1143   UINT8 level = FETCH(cpustate) % 32;
1144   UINT8 x;
1145   UINT16 frameptr;
1146   PUSH16(cpustate,REG16(BP));
1147   
1148   if(!STACK_32BIT)
1149      frameptr = REG16(SP);
1150   else
1151      frameptr = REG32(ESP);
1152   
1153   if(level > 0)
1154   {
1155      for(x=1;x<level-1;x++)
1156      {
1157         REG16(BP) -= 2;
1158         PUSH16(cpustate,READ16(cpustate,REG16(BP)));
1159      }
1160      PUSH16(cpustate,frameptr);
1161   }
1162   REG16(BP) = frameptr;
1163   if(!STACK_32BIT)
1164      REG16(SP) -= framesize;
1165   else
1166      REG32(ESP) -= framesize;
1167   CYCLES(cpustate,CYCLES_ENTER);
1168}
1169
11401170static void I386OP(leave16)(i386_state *cpustate)         // Opcode 0xc9
11411171{
1142   REG16(SP) = REG16(BP);
1172   if(!STACK_32BIT)
1173      REG16(SP) = REG16(BP);
1174   else
1175      REG32(ESP) = REG32(EBP);
11431176   REG16(BP) = POP16(cpustate);
11441177   CYCLES(cpustate,CYCLES_LEAVE);
11451178}
src/emu/cpu/i386/i386priv.h
r6358r6359
197197   UINT8 AF;
198198   UINT8 IF;
199199   UINT8 TF;
200   UINT8 IOP1;
201   UINT8 IOP2;
202   UINT8 NT;
200203
201204   UINT8 performed_intersegment_jump;
202205
src/emu/cpu/i386/i386ops.h
r6358r6359
220220   { 0xC5,      OP_I386,               I386OP(lds16),               I386OP(lds32),            },
221221   { 0xC6,      OP_I386,               I386OP(mov_rm8_i8),            I386OP(mov_rm8_i8),         },
222222   { 0xC7,      OP_I386,               I386OP(mov_rm16_i16),         I386OP(mov_rm32_i32),      },
223   { 0xC8,      OP_I386,               I386OP(unimplemented),         I386OP(unimplemented),      },
223   { 0xC8,      OP_I386,               I386OP(enter16),            I386OP(enter32),         },
224224   { 0xC9,      OP_I386,               I386OP(leave16),            I386OP(leave32),         },
225225   { 0xCA,      OP_I386,               I386OP(retf_i16),            I386OP(retf_i32),         },
226226   { 0xCB,      OP_I386,               I386OP(retf16),               I386OP(retf32),            },
src/emu/cpu/i386/i386.c
r6358r6359
9090   f |= cpustate->IF << 9;
9191   f |= cpustate->DF << 10;
9292   f |= cpustate->OF << 11;
93   f |= cpustate->IOP1 << 12;
94   f |= cpustate->IOP2 << 13;
95   f |= cpustate->NT << 14;
9396   return (cpustate->eflags & 0xFFFF0000) | (f & 0xFFFF);
9497}
9598
r6358r6359
104107   cpustate->IF = (f & 0x200) ? 1 : 0;
105108   cpustate->DF = (f & 0x400) ? 1 : 0;
106109   cpustate->OF = (f & 0x800) ? 1 : 0;
110   cpustate->IOP1 = (f & 0x1000) ? 1 : 0;
111   cpustate->IOP2 = (f & 0x2000) ? 1 : 0;
112   cpustate->NT = (f & 0x4000) ? 1 : 0;
107113}
108114
109115static void sib_byte(i386_state *cpustate,UINT8 mod, UINT32* out_ea, UINT8* out_segment)
r6358r6359
275281   UINT32 v1, v2;
276282   UINT32 offset;
277283   UINT16 segment;
278   int entry = irq * (cpustate->sreg[CS].d ? 8 : 4);
284   int entry = irq * (PROTECTED_MODE ? 8 : 4);
279285
280286   /* Check if IRQ is out of IDTR's bounds */
281287   if( entry > cpustate->idtr.limit ) {
282288      fatalerror("I386 Interrupt: IRQ out of IDTR bounds (IRQ: %d, IDTR Limit: %d)", irq, cpustate->idtr.limit);
283289   }
284290
285   if( !cpustate->sreg[CS].d )
291   if( !(PROTECTED_MODE) )
286292   {
287293      /* 16-bit */
288294      PUSH16(cpustate, get_flags(cpustate) & 0xffff );
r6358r6359
306312   {
307313      int type;
308314      /* 32-bit */
309      PUSH32(cpustate, get_flags(cpustate) & 0x00fcffff );
310      PUSH32(cpustate, cpustate->sreg[CS].selector );
311      PUSH32(cpustate, cpustate->eip );
312315
313316      v1 = READ32(cpustate, cpustate->idtr.base + entry );
314317      v2 = READ32(cpustate, cpustate->idtr.base + entry + 4 );
r6358r6359
316319      segment = (v1 >> 16) & 0xffff;
317320      type = (v2>>8) & 0x1F;
318321
322      if(type != 0x0e && type != 0x0f)  // if not 386 interrupt or trap gate
323      {
324         PUSH16(cpustate, get_flags(cpustate) & 0xffff );
325         PUSH16(cpustate, cpustate->sreg[CS].selector );
326         PUSH16(cpustate, cpustate->eip );
327      }
328      else
329      {
330         PUSH32(cpustate, get_flags(cpustate) & 0x00fcffff );
331         PUSH32(cpustate, cpustate->sreg[CS].selector );
332         PUSH32(cpustate, cpustate->eip );
333      }
334
319335      cpustate->sreg[CS].selector = segment;
320336      cpustate->eip = offset;
321337
src/emu/cpu/i386/i386op32.c
r6358r6359
998998   CYCLES(cpustate,CYCLES_LEA);
999999}
10001000
1001static void I386OP(enter32)(i386_state *cpustate)         // Opcode 0xc8
1002{
1003   UINT16 framesize = FETCH16(cpustate);
1004   UINT8 level = FETCH(cpustate) % 32;
1005   UINT8 x;
1006   UINT32 frameptr;
1007   PUSH32(cpustate,REG32(EBP));
1008   if(!STACK_32BIT)
1009      frameptr = REG16(SP);
1010   else
1011      frameptr = REG32(ESP);
1012   
1013   if(level > 0)
1014   {
1015      for(x=1;x<level-1;x++)
1016      {
1017         REG32(EBP) -= 4;
1018         PUSH32(cpustate,READ32(cpustate,REG32(EBP)));
1019      }
1020      PUSH32(cpustate,frameptr);
1021   }
1022   REG32(EBP) = frameptr;
1023   if(!STACK_32BIT)
1024      REG16(SP) -= framesize;
1025   else
1026      REG32(ESP) -= framesize;
1027   CYCLES(cpustate,CYCLES_ENTER);
1028}
1029
10011030static void I386OP(leave32)(i386_state *cpustate)         // Opcode 0xc9
10021031{
1003   REG32(ESP) = REG32(EBP);
1032   if(!STACK_32BIT)
1033      REG16(SP) = REG16(BP);
1034   else
1035      REG32(ESP) = REG32(EBP);
10041036   REG32(EBP) = POP32(cpustate);
10051037   CYCLES(cpustate,CYCLES_LEAVE);
10061038}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team