src/emu/cpu/i386/i386op16.c
| r6358 | r6359 | |
| 1137 | 1137 | CYCLES(cpustate,CYCLES_LEA); |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | static 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 | |
| 1140 | 1170 | static void I386OP(leave16)(i386_state *cpustate) // Opcode 0xc9 |
| 1141 | 1171 | { |
| 1142 | | REG16(SP) = REG16(BP); |
| 1172 | if(!STACK_32BIT) |
| 1173 | REG16(SP) = REG16(BP); |
| 1174 | else |
| 1175 | REG32(ESP) = REG32(EBP); |
| 1143 | 1176 | REG16(BP) = POP16(cpustate); |
| 1144 | 1177 | CYCLES(cpustate,CYCLES_LEAVE); |
| 1145 | 1178 | } |
src/emu/cpu/i386/i386ops.h
| r6358 | r6359 | |
| 220 | 220 | { 0xC5, OP_I386, I386OP(lds16), I386OP(lds32), }, |
| 221 | 221 | { 0xC6, OP_I386, I386OP(mov_rm8_i8), I386OP(mov_rm8_i8), }, |
| 222 | 222 | { 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), }, |
| 224 | 224 | { 0xC9, OP_I386, I386OP(leave16), I386OP(leave32), }, |
| 225 | 225 | { 0xCA, OP_I386, I386OP(retf_i16), I386OP(retf_i32), }, |
| 226 | 226 | { 0xCB, OP_I386, I386OP(retf16), I386OP(retf32), }, |
src/emu/cpu/i386/i386.c
| r6358 | r6359 | |
| 90 | 90 | f |= cpustate->IF << 9; |
| 91 | 91 | f |= cpustate->DF << 10; |
| 92 | 92 | f |= cpustate->OF << 11; |
| 93 | f |= cpustate->IOP1 << 12; |
| 94 | f |= cpustate->IOP2 << 13; |
| 95 | f |= cpustate->NT << 14; |
| 93 | 96 | return (cpustate->eflags & 0xFFFF0000) | (f & 0xFFFF); |
| 94 | 97 | } |
| 95 | 98 | |
| r6358 | r6359 | |
| 104 | 107 | cpustate->IF = (f & 0x200) ? 1 : 0; |
| 105 | 108 | cpustate->DF = (f & 0x400) ? 1 : 0; |
| 106 | 109 | 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; |
| 107 | 113 | } |
| 108 | 114 | |
| 109 | 115 | static void sib_byte(i386_state *cpustate,UINT8 mod, UINT32* out_ea, UINT8* out_segment) |
| r6358 | r6359 | |
| 275 | 281 | UINT32 v1, v2; |
| 276 | 282 | UINT32 offset; |
| 277 | 283 | UINT16 segment; |
| 278 | | int entry = irq * (cpustate->sreg[CS].d ? 8 : 4); |
| 284 | int entry = irq * (PROTECTED_MODE ? 8 : 4); |
| 279 | 285 | |
| 280 | 286 | /* Check if IRQ is out of IDTR's bounds */ |
| 281 | 287 | if( entry > cpustate->idtr.limit ) { |
| 282 | 288 | fatalerror("I386 Interrupt: IRQ out of IDTR bounds (IRQ: %d, IDTR Limit: %d)", irq, cpustate->idtr.limit); |
| 283 | 289 | } |
| 284 | 290 | |
| 285 | | if( !cpustate->sreg[CS].d ) |
| 291 | if( !(PROTECTED_MODE) ) |
| 286 | 292 | { |
| 287 | 293 | /* 16-bit */ |
| 288 | 294 | PUSH16(cpustate, get_flags(cpustate) & 0xffff ); |
| r6358 | r6359 | |
| 306 | 312 | { |
| 307 | 313 | int type; |
| 308 | 314 | /* 32-bit */ |
| 309 | | PUSH32(cpustate, get_flags(cpustate) & 0x00fcffff ); |
| 310 | | PUSH32(cpustate, cpustate->sreg[CS].selector ); |
| 311 | | PUSH32(cpustate, cpustate->eip ); |
| 312 | 315 | |
| 313 | 316 | v1 = READ32(cpustate, cpustate->idtr.base + entry ); |
| 314 | 317 | v2 = READ32(cpustate, cpustate->idtr.base + entry + 4 ); |
| r6358 | r6359 | |
| 316 | 319 | segment = (v1 >> 16) & 0xffff; |
| 317 | 320 | type = (v2>>8) & 0x1F; |
| 318 | 321 | |
| 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 | |
| 319 | 335 | cpustate->sreg[CS].selector = segment; |
| 320 | 336 | cpustate->eip = offset; |
| 321 | 337 | |
src/emu/cpu/i386/i386op32.c
| r6358 | r6359 | |
| 998 | 998 | CYCLES(cpustate,CYCLES_LEA); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | static 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 | |
| 1001 | 1030 | static void I386OP(leave32)(i386_state *cpustate) // Opcode 0xc9 |
| 1002 | 1031 | { |
| 1003 | | REG32(ESP) = REG32(EBP); |
| 1032 | if(!STACK_32BIT) |
| 1033 | REG16(SP) = REG16(BP); |
| 1034 | else |
| 1035 | REG32(ESP) = REG32(EBP); |
| 1004 | 1036 | REG32(EBP) = POP32(cpustate); |
| 1005 | 1037 | CYCLES(cpustate,CYCLES_LEAVE); |
| 1006 | 1038 | } |