src/emu/cpu/i86/instr286.c
| r11586 | r11587 | |
| 248 | 248 | if (!IDX(gatesel)||(gatesel>cpustate->gdtr.limit)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel)); |
| 249 | 249 | addr = cpustate->gdtr.base+IDX(gatesel); |
| 250 | 250 | } |
| 251 | | addr = cpustate->gdtr.base+IDX(gatesel); |
| 252 | 251 | gatedesc[0] = ReadWord(addr); |
| 253 | 252 | gatedesc[1] = ReadWord(addr+2); |
| 254 | 253 | gatedesc[2] = ReadWord(addr+4); |
| r11586 | r11587 | |
| 260 | 259 | |
| 261 | 260 | if (!CONF(r)&&(DPL(r)<CPL)) { // inner call |
| 262 | 261 | UINT16 ssdesc[3]; |
| 263 | | UINT16 tss_ss,tss_sp, oldss, oldsp; |
| 264 | | int oldsp_phy, ssr, i; |
| 262 | UINT16 tss_ss, tss_sp, oldss, oldsp; |
| 263 | UINT32 oldstk; |
| 264 | UINT8 ssr; |
| 265 | int i; |
| 265 | 266 | if(gate == 1) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel)); // can't jmp to inner |
| 266 | 267 | tss_ss = ReadWord(cpustate->tr.base+TSS_SS0+(DPL(r)*4)); |
| 267 | 268 | tss_sp = ReadWord(cpustate->tr.base+TSS_SP0+(DPL(r)*4)); |
| r11586 | r11587 | |
| 278 | 279 | ssdesc[1] = ReadWord(addr+2); |
| 279 | 280 | ssdesc[2] = ReadWord(addr+4); |
| 280 | 281 | ssr = RIGHTS(ssdesc); |
| 281 | | if ((RPL(tss_ss) != DPL(r)) || DPL(ssr) != DPL(r)) TRAP(INVALID_TSS,IDXTBL(tss_ss)); |
| 282 | if ((RPL(tss_ss) != DPL(r)) || (DPL(ssr) != DPL(r))) TRAP(INVALID_TSS,IDXTBL(tss_ss)); |
| 282 | 283 | if (!RW(ssr) || !PRES(ssr)) throw TRAP(INVALID_TSS,IDXTBL(tss_ss)); |
| 283 | 284 | oldss = cpustate->sregs[SS]; |
| 284 | 285 | oldsp = cpustate->regs.w[SP]; |
| 285 | | oldsp_phy = cpustate->base[SS]+oldsp+(GATECNT(desc)*2); |
| 286 | oldstk = cpustate->base[SS]+oldsp; |
| 286 | 287 | cpustate->sregs[SS]=tss_ss; |
| 287 | 288 | cpustate->limit[SS]=LIMIT(ssdesc); |
| 288 | 289 | cpustate->base[SS]=BASE(ssdesc); |
| 289 | 290 | cpustate->rights[SS]=RIGHTS(ssdesc); |
| 291 | cpustate->regs.w[SP] = tss_sp; |
| 290 | 292 | PUSH(oldss); |
| 291 | 293 | PUSH(oldsp); |
| 292 | | for (i = 0; i < GATECNT(desc); i++) |
| 293 | | PUSH(ReadWord(oldsp_phy-(i*2))); |
| 294 | for (i = GATECNT(desc)-1; i >= 0; i--) |
| 295 | PUSH(ReadWord(oldstk+(i*2))); |
| 294 | 296 | } |
| 295 | 297 | cpustate->sregs[CS]=IDXTBL(gatesel) | DPL(r); |
| 296 | 298 | cpustate->limit[CS]=LIMIT(gatedesc); |
| r11586 | r11587 | |
| 384 | 386 | cpustate->limit[SS]=LIMIT(ssdesc); |
| 385 | 387 | cpustate->base[SS]=BASE(ssdesc); |
| 386 | 388 | cpustate->rights[SS]=RIGHTS(ssdesc); |
| 389 | cpustate->regs.w[SP] = tss_sp; |
| 387 | 390 | PUSH(oldss); |
| 388 | 391 | PUSH(oldsp); |
| 389 | 392 | } |
| r11586 | r11587 | |
| 479 | 482 | cpustate->ZeroVal=0; |
| 480 | 483 | else if (CODE(r) && CONF(r)) |
| 481 | 484 | cpustate->ZeroVal=1; |
| 482 | | else if ((DPL(r)<CPL) || (DPL(r)<RPL(tmp))) |
| 485 | else if (DPL(r)<PMAX(CPL,RPL(tmp))) |
| 483 | 486 | cpustate->ZeroVal=0; |
| 484 | 487 | else cpustate->ZeroVal=1; |
| 485 | 488 | } |
| r11586 | r11587 | |
| 498 | 501 | r = RIGHTS(desc); |
| 499 | 502 | if (!SEGDESC(r) || CODE(r)) |
| 500 | 503 | cpustate->ZeroVal=0; |
| 501 | | else if ((DPL(r)<CPL) || (DPL(r)<RPL(tmp))) |
| 504 | else if (DPL(r)<PMAX(CPL,RPL(tmp))) |
| 502 | 505 | cpustate->ZeroVal=0; |
| 503 | 506 | else cpustate->ZeroVal=1; |
| 504 | 507 | } |
| r11586 | r11587 | |
| 539 | 542 | case 0x30: /* lmsw */ |
| 540 | 543 | if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0); |
| 541 | 544 | msw = GetRMWord(ModRM); |
| 542 | | if (!PM&(msw&1)) cpustate->sregs[CS] = IDX(cpustate->sregs[CS]); // cheat and set cpl to 0 |
| 545 | if (!PM&&(msw&1)) cpustate->sregs[CS] = IDX(cpustate->sregs[CS]); // cheat and set cpl to 0 |
| 543 | 546 | cpustate->msw=(cpustate->msw&1)|msw; |
| 544 | 547 | break; |
| 545 | 548 | default: |
| r11586 | r11587 | |
| 619 | 622 | |
| 620 | 623 | case 6: /* clts */ |
| 621 | 624 | if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0); |
| 622 | | cpustate->msw=~8; |
| 625 | cpustate->msw&=~8; |
| 623 | 626 | break; |
| 624 | 627 | default: |
| 625 | 628 | throw TRAP(ILLEGAL_INSTRUCTION,-1); |
src/emu/cpu/i86/instr86.c
| r11586 | r11587 | |
| 435 | 435 | break; |
| 436 | 436 | #ifndef I8086 |
| 437 | 437 | case 0x6c: /* REP INSB */ |
| 438 | #ifdef I80286 |
| 439 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 440 | #endif |
| 438 | 441 | if (!cpustate->rep_in_progress) |
| 439 | 442 | ICOUNT -= timing.rep_ins8_base; |
| 440 | 443 | cpustate->rep_in_progress = FALSE; |
| r11586 | r11587 | |
| 448 | 451 | cpustate->regs.w[CX]=count; |
| 449 | 452 | break; |
| 450 | 453 | case 0x6d: /* REP INSW */ |
| 454 | #ifdef I80286 |
| 455 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 456 | #endif |
| 451 | 457 | if (!cpustate->rep_in_progress) |
| 452 | 458 | ICOUNT -= timing.rep_ins16_base; |
| 453 | 459 | cpustate->rep_in_progress = FALSE; |
| r11586 | r11587 | |
| 461 | 467 | cpustate->regs.w[CX]=count; |
| 462 | 468 | break; |
| 463 | 469 | case 0x6e: /* REP OUTSB */ |
| 470 | #ifdef I80286 |
| 471 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 472 | #endif |
| 464 | 473 | if (!cpustate->rep_in_progress) |
| 465 | 474 | ICOUNT -= timing.rep_outs8_base; |
| 466 | 475 | cpustate->rep_in_progress = FALSE; |
| r11586 | r11587 | |
| 474 | 483 | cpustate->regs.w[CX]=count; |
| 475 | 484 | break; |
| 476 | 485 | case 0x6f: /* REP OUTSW */ |
| 486 | #ifdef I80286 |
| 487 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 488 | #endif |
| 477 | 489 | if (!cpustate->rep_in_progress) |
| 478 | 490 | ICOUNT -= timing.rep_outs16_base; |
| 479 | 491 | cpustate->rep_in_progress = FALSE; |
| r11586 | r11587 | |
| 2519 | 2531 | |
| 2520 | 2532 | static void PREFIX86(_inal)(i8086_state *cpustate) /* Opcode 0xe4 */ |
| 2521 | 2533 | { |
| 2522 | | unsigned port = FETCH; |
| 2534 | unsigned port; |
| 2535 | #ifdef I80286 |
| 2536 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2537 | #endif |
| 2538 | port = FETCH; |
| 2523 | 2539 | |
| 2524 | 2540 | ICOUNT -= timing.in_imm8; |
| 2525 | 2541 | cpustate->regs.b[AL] = read_port_byte(port); |
| r11586 | r11587 | |
| 2527 | 2543 | |
| 2528 | 2544 | static void PREFIX86(_inax)(i8086_state *cpustate) /* Opcode 0xe5 */ |
| 2529 | 2545 | { |
| 2530 | | unsigned port = FETCH; |
| 2546 | unsigned port; |
| 2547 | #ifdef I80286 |
| 2548 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2549 | #endif |
| 2550 | port = FETCH; |
| 2531 | 2551 | |
| 2532 | 2552 | ICOUNT -= timing.in_imm16; |
| 2533 | 2553 | cpustate->regs.w[AX] = read_port_word(port); |
| r11586 | r11587 | |
| 2535 | 2555 | |
| 2536 | 2556 | static void PREFIX86(_outal)(i8086_state *cpustate) /* Opcode 0xe6 */ |
| 2537 | 2557 | { |
| 2538 | | unsigned port = FETCH; |
| 2558 | unsigned port; |
| 2559 | #ifdef I80286 |
| 2560 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2561 | #endif |
| 2562 | port = FETCH; |
| 2539 | 2563 | |
| 2540 | 2564 | ICOUNT -= timing.out_imm8; |
| 2541 | 2565 | write_port_byte(port, cpustate->regs.b[AL]); |
| r11586 | r11587 | |
| 2543 | 2567 | |
| 2544 | 2568 | static void PREFIX86(_outax)(i8086_state *cpustate) /* Opcode 0xe7 */ |
| 2545 | 2569 | { |
| 2546 | | unsigned port = FETCH; |
| 2570 | unsigned port; |
| 2571 | #ifdef I80286 |
| 2572 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2573 | #endif |
| 2574 | port = FETCH; |
| 2547 | 2575 | |
| 2548 | 2576 | ICOUNT -= timing.out_imm16; |
| 2549 | 2577 | write_port_word(port, cpustate->regs.w[AX]); |
| r11586 | r11587 | |
| 2605 | 2633 | |
| 2606 | 2634 | static void PREFIX86(_inaldx)(i8086_state *cpustate) /* Opcode 0xec */ |
| 2607 | 2635 | { |
| 2636 | #ifdef I80286 |
| 2637 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2638 | #endif |
| 2608 | 2639 | ICOUNT -= timing.in_dx8; |
| 2609 | 2640 | cpustate->regs.b[AL] = read_port_byte(cpustate->regs.w[DX]); |
| 2610 | 2641 | } |
| r11586 | r11587 | |
| 2612 | 2643 | static void PREFIX86(_inaxdx)(i8086_state *cpustate) /* Opcode 0xed */ |
| 2613 | 2644 | { |
| 2614 | 2645 | unsigned port = cpustate->regs.w[DX]; |
| 2615 | | |
| 2646 | #ifdef I80286 |
| 2647 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2648 | #endif |
| 2616 | 2649 | ICOUNT -= timing.in_dx16; |
| 2617 | 2650 | cpustate->regs.w[AX] = read_port_word(port); |
| 2618 | 2651 | } |
| 2619 | 2652 | |
| 2620 | 2653 | static void PREFIX86(_outdxal)(i8086_state *cpustate) /* Opcode 0xee */ |
| 2621 | 2654 | { |
| 2655 | #ifdef I80286 |
| 2656 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2657 | #endif |
| 2622 | 2658 | ICOUNT -= timing.out_dx8; |
| 2623 | 2659 | write_port_byte(cpustate->regs.w[DX], cpustate->regs.b[AL]); |
| 2624 | 2660 | } |
| r11586 | r11587 | |
| 2626 | 2662 | static void PREFIX86(_outdxax)(i8086_state *cpustate) /* Opcode 0xef */ |
| 2627 | 2663 | { |
| 2628 | 2664 | unsigned port = cpustate->regs.w[DX]; |
| 2629 | | |
| 2665 | #ifdef I80286 |
| 2666 | if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0); |
| 2667 | #endif |
| 2630 | 2668 | ICOUNT -= timing.out_dx16; |
| 2631 | 2669 | write_port_word(port, cpustate->regs.w[AX]); |
| 2632 | 2670 | } |
| r11586 | r11587 | |
| 2634 | 2672 | /* I think thats not a V20 instruction...*/ |
| 2635 | 2673 | static void PREFIX86(_lock)(i8086_state *cpustate) /* Opcode 0xf0 */ |
| 2636 | 2674 | { |
| 2675 | #ifdef I80286 |
| 2676 | if(PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT,0); |
| 2677 | #endif |
| 2637 | 2678 | ICOUNT -= timing.nop; |
| 2638 | 2679 | PREFIX(_instruction)[FETCHOP](cpustate); /* un-interruptible */ |
| 2639 | 2680 | } |