src/emu/cpu/i386/i386op16.c
| r15214 | r15215 | |
| 1601 | 1601 | CYCLES(cpustate,CYCLES_POP_REG_SHORT); |
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | | static void I386OP(pop_ds16)(i386_state *cpustate) // Opcode 0x1f |
| 1604 | static bool I386OP(pop_seg16)(i386_state *cpustate, int segment) |
| 1605 | 1605 | { |
| 1606 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1606 | UINT32 ea, offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1607 | UINT16 value; |
| 1608 | bool fault; |
| 1607 | 1609 | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1608 | 1610 | { |
| 1609 | | cpustate->sreg[DS].selector = POP16(cpustate); |
| 1610 | | if( PROTECTED_MODE ) { |
| 1611 | | i386_load_segment_descriptor(cpustate,DS); |
| 1612 | | } else { |
| 1613 | | i386_load_segment_descriptor(cpustate,DS); |
| 1614 | | } |
| 1611 | ea = i386_translate(cpustate, SS, offset, 0); |
| 1612 | value = READ16(cpustate, ea); |
| 1613 | i386_sreg_load(cpustate,value, segment, &fault); |
| 1614 | if(fault) return false; |
| 1615 | if(STACK_32BIT) |
| 1616 | REG32(ESP) = offset + 2; |
| 1617 | else |
| 1618 | REG16(SP) = offset + 2; |
| 1615 | 1619 | } |
| 1616 | 1620 | else |
| 1617 | | FAULT(FAULT_SS,0) |
| 1621 | { |
| 1622 | cpustate->ext = 1; |
| 1623 | i386_trap_with_error(cpustate,FAULT_SS,0,0,0); |
| 1624 | return false; |
| 1625 | } |
| 1618 | 1626 | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1627 | return true; |
| 1619 | 1628 | } |
| 1620 | 1629 | |
| 1630 | static void I386OP(pop_ds16)(i386_state *cpustate) // Opcode 0x1f |
| 1631 | { |
| 1632 | I386OP(pop_seg16)(cpustate, DS); |
| 1633 | } |
| 1634 | |
| 1621 | 1635 | static void I386OP(pop_es16)(i386_state *cpustate) // Opcode 0x07 |
| 1622 | 1636 | { |
| 1623 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1624 | | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1625 | | { |
| 1626 | | cpustate->sreg[ES].selector = POP16(cpustate); |
| 1627 | | if( PROTECTED_MODE ) { |
| 1628 | | i386_load_segment_descriptor(cpustate,ES); |
| 1629 | | } else { |
| 1630 | | i386_load_segment_descriptor(cpustate,ES); |
| 1631 | | } |
| 1632 | | } |
| 1633 | | else |
| 1634 | | FAULT(FAULT_SS,0) |
| 1635 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1637 | I386OP(pop_seg16)(cpustate, ES); |
| 1636 | 1638 | } |
| 1637 | 1639 | |
| 1638 | 1640 | static void I386OP(pop_fs16)(i386_state *cpustate) // Opcode 0x0f a1 |
| 1639 | 1641 | { |
| 1640 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1641 | | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1642 | | { |
| 1643 | | cpustate->sreg[FS].selector = POP16(cpustate); |
| 1644 | | if( PROTECTED_MODE ) { |
| 1645 | | i386_load_segment_descriptor(cpustate,FS); |
| 1646 | | } else { |
| 1647 | | i386_load_segment_descriptor(cpustate,FS); |
| 1648 | | } |
| 1649 | | } |
| 1650 | | else |
| 1651 | | FAULT(FAULT_SS,0) |
| 1652 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1642 | I386OP(pop_seg16)(cpustate, FS); |
| 1653 | 1643 | } |
| 1654 | 1644 | |
| 1655 | 1645 | static void I386OP(pop_gs16)(i386_state *cpustate) // Opcode 0x0f a9 |
| 1656 | 1646 | { |
| 1657 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1658 | | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1659 | | { |
| 1660 | | cpustate->sreg[GS].selector = POP16(cpustate); |
| 1661 | | if( PROTECTED_MODE ) { |
| 1662 | | i386_load_segment_descriptor(cpustate,GS); |
| 1663 | | } else { |
| 1664 | | i386_load_segment_descriptor(cpustate,GS); |
| 1665 | | } |
| 1666 | | } |
| 1667 | | else |
| 1668 | | FAULT(FAULT_SS,0) |
| 1669 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1647 | I386OP(pop_seg16)(cpustate, GS); |
| 1670 | 1648 | } |
| 1671 | 1649 | |
| 1672 | 1650 | static void I386OP(pop_ss16)(i386_state *cpustate) // Opcode 0x17 |
| 1673 | 1651 | { |
| 1674 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1652 | if(!I386OP(pop_seg16)(cpustate, SS)) return; |
| 1675 | 1653 | if(cpustate->IF != 0) // if external interrupts are enabled |
| 1676 | 1654 | { |
| 1677 | 1655 | cpustate->IF = 0; // reset IF for the next instruction |
| 1678 | 1656 | cpustate->delayed_interrupt_enable = 1; |
| 1679 | 1657 | } |
| 1680 | | |
| 1681 | | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1682 | | { |
| 1683 | | cpustate->sreg[SS].selector = POP16(cpustate); |
| 1684 | | if( PROTECTED_MODE ) { |
| 1685 | | i386_load_segment_descriptor(cpustate,SS); |
| 1686 | | } else { |
| 1687 | | i386_load_segment_descriptor(cpustate,SS); |
| 1688 | | } |
| 1689 | | } |
| 1690 | | else |
| 1691 | | FAULT(FAULT_SS,0) |
| 1692 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1693 | 1658 | } |
| 1694 | 1659 | |
| 1695 | 1660 | static void I386OP(pop_rm16)(i386_state *cpustate) // Opcode 0x8f |
| 1696 | 1661 | { |
| 1697 | 1662 | UINT8 modrm = FETCH(cpustate); |
| 1698 | 1663 | UINT16 value; |
| 1699 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1664 | UINT32 ea, offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1700 | 1665 | |
| 1701 | 1666 | if(i386_limit_check(cpustate,SS,offset+1) == 0) |
| 1702 | 1667 | { |
| 1668 | UINT32 temp_sp = REG32(ESP); |
| 1703 | 1669 | value = POP16(cpustate); |
| 1704 | 1670 | |
| 1705 | 1671 | if( modrm >= 0xc0 ) { |
| 1706 | 1672 | STORE_RM16(modrm, value); |
| 1707 | 1673 | } else { |
| 1708 | | UINT32 ea = GetEA(cpustate,modrm,1); |
| 1709 | | WRITE16(cpustate,ea, value); |
| 1674 | ea = GetEA(cpustate,modrm,1); |
| 1675 | try |
| 1676 | { |
| 1677 | WRITE16(cpustate,ea, value); |
| 1678 | } |
| 1679 | catch(UINT64 e) |
| 1680 | { |
| 1681 | REG32(ESP) = temp_sp; |
| 1682 | throw e; |
| 1683 | } |
| 1710 | 1684 | } |
| 1711 | 1685 | } |
| 1712 | 1686 | else |
| r15214 | r15215 | |
| 3719 | 3693 | UINT32 ea = GetEA(cpustate,modrm,0); |
| 3720 | 3694 | STORE_REG16(modrm, READ16(cpustate,ea + 0)); |
| 3721 | 3695 | selector = READ16(cpustate,ea + 2); |
| 3722 | | if(PROTECTED_MODE && !(V8086_MODE)) |
| 3723 | | i386_protected_mode_sreg_load(cpustate,selector,s); |
| 3724 | | else |
| 3725 | | { |
| 3726 | | cpustate->sreg[s].selector = selector; |
| 3727 | | i386_load_segment_descriptor(cpustate, s ); |
| 3728 | | } |
| 3696 | i386_sreg_load(cpustate,selector,s,NULL); |
| 3729 | 3697 | } |
| 3730 | 3698 | } |
| 3731 | 3699 | |
src/emu/cpu/i386/i386priv.h
| r15214 | r15215 | |
| 401 | 401 | if(i386_limit_check(cpustate, segment, ip)) |
| 402 | 402 | FAULT_THROW((segment==SS)?FAULT_SS:FAULT_GP, 0); |
| 403 | 403 | if((rwn == 0) && ((cpustate->sreg[segment].flags & 8) && !(cpustate->sreg[segment].flags & 2))) |
| 404 | | FAULT_THROW((segment==SS)?FAULT_SS:FAULT_GP, 0); |
| 404 | FAULT_THROW(FAULT_GP, 0); |
| 405 | 405 | if((rwn == 1) && ((cpustate->sreg[segment].flags & 8) || !(cpustate->sreg[segment].flags & 2))) |
| 406 | | FAULT_THROW((segment==SS)?FAULT_SS:FAULT_GP, 0); |
| 406 | FAULT_THROW(FAULT_GP, 0); |
| 407 | 407 | } |
| 408 | 408 | return cpustate->sreg[segment].base + ip; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | | // rwn; read = 0, write = 1, none = -1 |
| 411 | // rwn; read = 0, write = 1, none = -1, read at PL 0 = -2 |
| 412 | 412 | INLINE int translate_address(i386_state *cpustate, int rwn, UINT32 *address, UINT32 *error) |
| 413 | 413 | { |
| 414 | 414 | UINT32 a = *address; |
| r15214 | r15215 | |
| 418 | 418 | UINT32 offset = a & 0xfff; |
| 419 | 419 | UINT32 page_entry; |
| 420 | 420 | UINT32 ret = 1; |
| 421 | | bool user = (cpustate->CPL == 3); |
| 421 | bool user = (cpustate->CPL == 3) && (rwn >= 0); |
| 422 | 422 | *error = 0; |
| 423 | 423 | |
| 424 | 424 | // TODO: cr0 wp bit, 486 and higher |
| r15214 | r15215 | |
| 675 | 675 | } |
| 676 | 676 | return value; |
| 677 | 677 | } |
| 678 | INLINE UINT8 READ8PL0(i386_state *cpustate,UINT32 ea) |
| 679 | { |
| 680 | UINT32 address = ea, error; |
| 678 | 681 | |
| 682 | if (cpustate->cr[0] & 0x80000000) // page translation enabled |
| 683 | { |
| 684 | if(!translate_address(cpustate,-2,&address,&error)) |
| 685 | PF_THROW(error); |
| 686 | } |
| 687 | |
| 688 | address &= cpustate->a20_mask; |
| 689 | return cpustate->program->read_byte(address); |
| 690 | } |
| 691 | INLINE UINT16 READ16PL0(i386_state *cpustate,UINT32 ea) |
| 692 | { |
| 693 | UINT16 value; |
| 694 | UINT32 address = ea, error; |
| 695 | |
| 696 | if( ea & 0x1 ) { /* Unaligned read */ |
| 697 | value = (READ8PL0( cpustate, address+0 ) << 0) | |
| 698 | (READ8PL0( cpustate, address+1 ) << 8); |
| 699 | } else { |
| 700 | if (cpustate->cr[0] & 0x80000000) // page translation enabled |
| 701 | { |
| 702 | if(!translate_address(cpustate,-2,&address,&error)) |
| 703 | PF_THROW(error); |
| 704 | } |
| 705 | |
| 706 | address &= cpustate->a20_mask; |
| 707 | value = cpustate->program->read_word( address ); |
| 708 | } |
| 709 | return value; |
| 710 | } |
| 711 | INLINE UINT32 READ32PL0(i386_state *cpustate,UINT32 ea) |
| 712 | { |
| 713 | UINT32 value; |
| 714 | UINT32 address = ea, error; |
| 715 | |
| 716 | if( ea & 0x3 ) { /* Unaligned read */ |
| 717 | value = (READ8PL0( cpustate, address+0 ) << 0) | |
| 718 | (READ8PL0( cpustate, address+1 ) << 8) | |
| 719 | (READ8PL0( cpustate, address+2 ) << 16) | |
| 720 | (READ8PL0( cpustate, address+3 ) << 24); |
| 721 | } else { |
| 722 | if (cpustate->cr[0] & 0x80000000) // page translation enabled |
| 723 | { |
| 724 | if(!translate_address(cpustate,-2,&address,&error)) |
| 725 | PF_THROW(error); |
| 726 | } |
| 727 | |
| 728 | address &= cpustate->a20_mask; |
| 729 | value = cpustate->program->read_dword( address ); |
| 730 | } |
| 731 | return value; |
| 732 | } |
| 733 | |
| 679 | 734 | INLINE void WRITE_TEST(i386_state *cpustate,UINT32 ea) |
| 680 | 735 | { |
| 681 | 736 | UINT32 address = ea, error; |
| r15214 | r15215 | |
| 1080 | 1135 | FAULT_THROW(FAULT_GP,0); |
| 1081 | 1136 | |
| 1082 | 1137 | address = cpustate->task.base; |
| 1083 | | IOPB = READ16(cpustate, address+0x66); |
| 1084 | | if((IOPB+(port/8)) >= cpustate->task.limit) |
| 1138 | IOPB = READ16PL0(cpustate, address+0x66); |
| 1139 | if((IOPB+(port/8)) > cpustate->task.limit) |
| 1085 | 1140 | FAULT_THROW(FAULT_GP,0); |
| 1086 | 1141 | |
| 1087 | | map = READ8(cpustate, address+IOPB+(port/8)); |
| 1142 | map = READ8PL0(cpustate, address+IOPB+(port/8)); |
| 1088 | 1143 | map >>= (port%8); |
| 1089 | 1144 | if(map & mask) |
| 1090 | 1145 | FAULT_THROW(FAULT_GP,0); |
src/emu/cpu/i386/i386.c
| r15214 | r15215 | |
| 53 | 53 | if (limit == 0 || entry + 7 > limit) |
| 54 | 54 | return 0; |
| 55 | 55 | |
| 56 | | int cpl = cpustate->CPL; |
| 57 | | cpustate->CPL = 0; |
| 56 | v1 = READ32PL0(cpustate, base + entry ); |
| 57 | v2 = READ32PL0(cpustate, base + entry + 4 ); |
| 58 | 58 | |
| 59 | | v1 = READ32(cpustate, base + entry ); |
| 60 | | v2 = READ32(cpustate, base + entry + 4 ); |
| 61 | | |
| 62 | | cpustate->CPL = cpl; |
| 63 | | |
| 64 | 59 | seg->flags = (v2 >> 8) & 0xf0ff; |
| 65 | 60 | seg->base = (v2 & 0xff000000) | ((v2 & 0xff) << 16) | ((v1 >> 16) & 0xffff); |
| 66 | 61 | seg->limit = (v2 & 0xf0000) | (v1 & 0xffff); |
| r15214 | r15215 | |
| 93 | 88 | if (limit == 0 || entry + 7 > limit) |
| 94 | 89 | return; |
| 95 | 90 | |
| 96 | | int cpl = cpustate->CPL; |
| 97 | | cpustate->CPL = 0; |
| 91 | v1 = READ32PL0(cpustate, base + entry ); |
| 92 | v2 = READ32PL0(cpustate, base + entry + 4 ); |
| 98 | 93 | |
| 99 | | v1 = READ32(cpustate, base + entry ); |
| 100 | | v2 = READ32(cpustate, base + entry + 4 ); |
| 101 | | |
| 102 | | cpustate->CPL = cpl; |
| 103 | | |
| 104 | 94 | /* Note that for task gates, offset and dword_count are not used */ |
| 105 | 95 | gate->selector = (v1 >> 16) & 0xffff; |
| 106 | 96 | gate->offset = (v1 & 0x0000ffff) | (v2 & 0xffff0000); |
| r15214 | r15215 | |
| 110 | 100 | gate->dpl = (gate->ar >> 5) & 0x03; |
| 111 | 101 | } |
| 112 | 102 | |
| 103 | static void i386_set_descriptor_accessed(i386_state *cpustate, UINT16 selector) |
| 104 | { |
| 105 | // assume the selector is valid, we don't need to check it again |
| 106 | UINT32 base, addr, error; |
| 107 | UINT8 rights; |
| 108 | if ( selector & 0x4 ) |
| 109 | base = cpustate->ldtr.base; |
| 110 | else |
| 111 | base = cpustate->gdtr.base; |
| 112 | |
| 113 | addr = base + (selector & ~7) + 5; |
| 114 | translate_address(cpustate, -2, &addr, &error); |
| 115 | rights = cpustate->program->read_byte(addr); |
| 116 | // Should a fault be thrown if the table is read only? |
| 117 | cpustate->program->write_byte(addr, rights | 1); |
| 118 | } |
| 119 | |
| 113 | 120 | static void i386_load_segment_descriptor(i386_state *cpustate, int segment ) |
| 114 | 121 | { |
| 115 | 122 | if (PROTECTED_MODE) |
| 116 | 123 | { |
| 117 | 124 | if (!V8086_MODE) |
| 125 | { |
| 118 | 126 | i386_load_protected_mode_segment(cpustate, &cpustate->sreg[segment], NULL ); |
| 127 | i386_set_descriptor_accessed(cpustate, cpustate->sreg[segment].selector); |
| 128 | } |
| 119 | 129 | else |
| 120 | 130 | { |
| 121 | 131 | cpustate->sreg[segment].base = cpustate->sreg[segment].selector << 4; |
| r15214 | r15215 | |
| 143 | 153 | if(privilege >= 3) |
| 144 | 154 | return 0; |
| 145 | 155 | |
| 146 | | int cpl = cpustate->CPL; |
| 147 | | cpustate->CPL = 0; |
| 148 | | |
| 149 | 156 | if(cpustate->task.flags & 8) |
| 150 | | ret = READ32(cpustate,(cpustate->task.base+8) + (8*privilege)); |
| 157 | ret = READ32PL0(cpustate,(cpustate->task.base+8) + (8*privilege)); |
| 151 | 158 | else |
| 152 | | ret = READ16(cpustate,(cpustate->task.base+4) + (4*privilege)); |
| 159 | ret = READ16PL0(cpustate,(cpustate->task.base+4) + (4*privilege)); |
| 153 | 160 | |
| 154 | | cpustate->CPL = cpl; |
| 155 | 161 | return ret; |
| 156 | 162 | } |
| 157 | 163 | |
| r15214 | r15215 | |
| 162 | 168 | if(privilege >= 3) |
| 163 | 169 | return 0; |
| 164 | 170 | |
| 165 | | int cpl = cpustate->CPL; |
| 166 | | cpustate->CPL = 0; |
| 167 | | |
| 168 | 171 | if(cpustate->task.flags & 8) |
| 169 | | ret = READ32(cpustate,(cpustate->task.base+4) + (8*privilege)); |
| 172 | ret = READ32PL0(cpustate,(cpustate->task.base+4) + (8*privilege)); |
| 170 | 173 | else |
| 171 | | ret = READ16(cpustate,(cpustate->task.base+2) + (4*privilege)); |
| 174 | ret = READ16PL0(cpustate,(cpustate->task.base+2) + (4*privilege)); |
| 172 | 175 | |
| 173 | | cpustate->CPL = cpl; |
| 174 | 176 | return ret; |
| 175 | 177 | } |
| 176 | 178 | |
| r15214 | r15215 | |
| 439 | 441 | return 0; |
| 440 | 442 | } |
| 441 | 443 | |
| 442 | | static void i386_protected_mode_sreg_load(i386_state *cpustate, UINT16 selector, UINT8 reg) |
| 444 | static void i386_sreg_load(i386_state *cpustate, UINT16 selector, UINT8 reg, bool *fault) |
| 443 | 445 | { |
| 444 | 446 | // Checks done when MOV changes a segment register in protected mode |
| 445 | 447 | UINT8 CPL,RPL,DPL; |
| r15214 | r15215 | |
| 447 | 449 | CPL = cpustate->CPL; |
| 448 | 450 | RPL = selector & 0x0003; |
| 449 | 451 | |
| 452 | if(!PROTECTED_MODE || V8086_MODE) |
| 453 | { |
| 454 | cpustate->sreg[reg].selector = selector; |
| 455 | i386_load_segment_descriptor(cpustate, reg); |
| 456 | if(fault) *fault = false; |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | if(fault) *fault = true; |
| 450 | 461 | if(reg == SS) |
| 451 | 462 | { |
| 452 | 463 | I386_SREG stack; |
| r15214 | r15215 | |
| 506 | 517 | { |
| 507 | 518 | cpustate->sreg[reg].selector = selector; |
| 508 | 519 | i386_load_segment_descriptor(cpustate, reg ); |
| 520 | if(fault) *fault = false; |
| 509 | 521 | return; |
| 510 | 522 | } |
| 511 | 523 | |
| r15214 | r15215 | |
| 532 | 544 | } |
| 533 | 545 | if((desc.flags & 0x0018) != 0x10) |
| 534 | 546 | { |
| 535 | | if(((desc.flags & 0x0002) != 0) && ((desc.flags & 0x0018) != 0x18)) |
| 547 | if((((desc.flags & 0x0002) != 0) && ((desc.flags & 0x0018) != 0x18)) || !(desc.flags & 0x10)) |
| 536 | 548 | { |
| 537 | 549 | logerror("SReg Load (%08x): Segment is not a data segment or readable code segment.\n",cpustate->pc); |
| 538 | 550 | FAULT(FAULT_GP,selector & ~0x03) |
| r15214 | r15215 | |
| 556 | 568 | |
| 557 | 569 | cpustate->sreg[reg].selector = selector; |
| 558 | 570 | i386_load_segment_descriptor(cpustate, reg ); |
| 571 | if(fault) *fault = false; |
| 559 | 572 | } |
| 560 | 573 | |
| 561 | 574 | static void i386_trap(i386_state *cpustate,int irq, int irq_gate, int trap_level) |
| r15214 | r15215 | |
| 581 | 594 | * 0x10 Coprocessor error |
| 582 | 595 | */ |
| 583 | 596 | UINT32 v1, v2; |
| 584 | | UINT32 offset; |
| 597 | UINT32 offset, oldflags = get_flags(cpustate); |
| 585 | 598 | UINT16 segment; |
| 586 | 599 | int entry = irq * (PROTECTED_MODE ? 8 : 4); |
| 587 | 600 | int SetRPL = 0; |
| r15214 | r15215 | |
| 589 | 602 | if( !(PROTECTED_MODE) ) |
| 590 | 603 | { |
| 591 | 604 | /* 16-bit */ |
| 592 | | PUSH16(cpustate, get_flags(cpustate) & 0xffff ); |
| 605 | PUSH16(cpustate, oldflags & 0xffff ); |
| 593 | 606 | PUSH16(cpustate, cpustate->sreg[CS].selector ); |
| 594 | 607 | if(irq == 3 || irq == 4 || irq == 9 || irq_gate == 1) |
| 595 | 608 | PUSH16(cpustate, cpustate->eip ); |
| r15214 | r15215 | |
| 610 | 623 | UINT8 CPL = cpustate->CPL, DPL = 0; //, RPL = 0; |
| 611 | 624 | |
| 612 | 625 | /* 32-bit */ |
| 613 | | cpustate->CPL = 0; |
| 614 | | v1 = READ32(cpustate, cpustate->idtr.base + entry ); |
| 615 | | v2 = READ32(cpustate, cpustate->idtr.base + entry + 4 ); |
| 616 | | cpustate->CPL = CPL; |
| 626 | v1 = READ32PL0(cpustate, cpustate->idtr.base + entry ); |
| 627 | v2 = READ32PL0(cpustate, cpustate->idtr.base + entry + 4 ); |
| 617 | 628 | offset = (v2 & 0xffff0000) | (v1 & 0xffff); |
| 618 | 629 | segment = (v1 >> 16) & 0xffff; |
| 619 | 630 | type = (v2>>8) & 0x1F; |
| r15214 | r15215 | |
| 640 | 651 | /* segment must be interrupt gate, trap gate, or task gate */ |
| 641 | 652 | if(type != 0x05 && type != 0x06 && type != 0x07 && type != 0x0e && type != 0x0f) |
| 642 | 653 | { |
| 643 | | logerror("IRQ#%i (%08x): Vector segment %04x is not an interrupt, trap or task gate.\n",irq,cpustate->pc,segment); |
| 654 | logerror("IRQ#%02x (%08x): Vector segment %04x is not an interrupt, trap or task gate.\n",irq,cpustate->pc,segment); |
| 644 | 655 | FAULT_EXP(FAULT_GP,entry+2) |
| 645 | 656 | } |
| 646 | 657 | |
| r15214 | r15215 | |
| 659 | 670 | FAULT_EXP(FAULT_NP,entry+2) |
| 660 | 671 | } |
| 661 | 672 | |
| 662 | | if(V8086_MODE) |
| 663 | | { |
| 664 | | UINT32 tempflags; |
| 665 | | UINT32 tempESP,tempSS; |
| 666 | | /* Interrupt for a Virtual 8086 task */ |
| 667 | | |
| 668 | | logerror("IRQ (%08x): Interrupt during V8086 task\n",cpustate->pc); |
| 669 | | tempflags = get_flags(cpustate); |
| 670 | | cpustate->VM = 0; |
| 671 | | cpustate->TF = 0; |
| 672 | | cpustate->NT = 0; |
| 673 | | if(type == 0x0e || type == 0x06) |
| 674 | | cpustate->IF = 0; |
| 675 | | tempSS = cpustate->sreg[SS].selector; |
| 676 | | tempESP = REG32(ESP); |
| 677 | | /* Get privilege level 0 stack pointer from TSS */ |
| 678 | | cpustate->sreg[SS].selector = i386_get_stack_segment(cpustate,0); |
| 679 | | REG32(ESP) = i386_get_stack_ptr(cpustate,0); |
| 680 | | cpustate->CPL = segment & 0x03; |
| 681 | | i386_load_segment_descriptor(cpustate,SS); |
| 682 | | PUSH32(cpustate,cpustate->sreg[GS].selector & 0xffff); |
| 683 | | PUSH32(cpustate,cpustate->sreg[FS].selector & 0xffff); |
| 684 | | PUSH32(cpustate,cpustate->sreg[DS].selector & 0xffff); |
| 685 | | PUSH32(cpustate,cpustate->sreg[ES].selector & 0xffff); |
| 686 | | cpustate->sreg[GS].selector = 0; |
| 687 | | cpustate->sreg[FS].selector = 0; |
| 688 | | cpustate->sreg[DS].selector = 0; |
| 689 | | cpustate->sreg[ES].selector = 0; |
| 690 | | i386_load_segment_descriptor(cpustate,GS); |
| 691 | | i386_load_segment_descriptor(cpustate,FS); |
| 692 | | i386_load_segment_descriptor(cpustate,DS); |
| 693 | | i386_load_segment_descriptor(cpustate,ES); |
| 694 | | PUSH32(cpustate,tempSS & 0xffff); |
| 695 | | PUSH32(cpustate,tempESP); |
| 696 | | PUSH32(cpustate,tempflags); |
| 697 | | PUSH32(cpustate,cpustate->sreg[CS].selector & 0xffff); |
| 698 | | if(irq == 3 || irq == 4 || irq == 9 || irq_gate == 1) |
| 699 | | PUSH32(cpustate, cpustate->eip ); |
| 700 | | else |
| 701 | | PUSH32(cpustate, cpustate->prev_eip ); |
| 702 | | |
| 703 | | cpustate->sreg[CS].selector = segment; |
| 704 | | cpustate->eip = offset; |
| 705 | | // CPL set to CS RPL? |
| 706 | | |
| 707 | | i386_load_segment_descriptor(cpustate,CS); |
| 708 | | CHANGE_PC(cpustate,cpustate->eip); |
| 709 | | return; |
| 710 | | } |
| 711 | | |
| 712 | 673 | if(type == 0x05) |
| 713 | 674 | { |
| 714 | 675 | /* Task gate */ |
| r15214 | r15215 | |
| 793 | 754 | I386_SREG stack; |
| 794 | 755 | UINT32 newESP,oldSS,oldESP; |
| 795 | 756 | |
| 757 | if(V8086_MODE && DPL) |
| 758 | { |
| 759 | logerror("IRQ: Gate to CPL>0 from VM86 mode.\n"); |
| 760 | FAULT_EXP(FAULT_GP,segment & ~0x03); |
| 761 | } |
| 796 | 762 | /* Check new stack segment in TSS */ |
| 797 | 763 | memset(&stack, 0, sizeof(stack)); |
| 798 | 764 | stack.selector = i386_get_stack_segment(cpustate,DPL); |
| r15214 | r15215 | |
| 846 | 812 | newESP = i386_get_stack_ptr(cpustate,DPL); |
| 847 | 813 | if(type & 0x08) // 32-bit gate |
| 848 | 814 | { |
| 849 | | if(newESP < 20) |
| 815 | if(newESP < (V8086_MODE?36:20)) |
| 850 | 816 | { |
| 851 | 817 | logerror("IRQ: New stack has no space for return addresses.\n"); |
| 852 | 818 | FAULT_EXP(FAULT_SS,0) |
| r15214 | r15215 | |
| 855 | 821 | else // 16-bit gate |
| 856 | 822 | { |
| 857 | 823 | newESP &= 0xffff; |
| 858 | | if(newESP < 10) |
| 824 | if(newESP < (V8086_MODE?18:10)) |
| 859 | 825 | { |
| 860 | 826 | logerror("IRQ: New stack has no space for return addresses.\n"); |
| 861 | 827 | FAULT_EXP(FAULT_SS,0) |
| r15214 | r15215 | |
| 872 | 838 | WRITE_TEST(cpustate, stack.base+newESP-1); |
| 873 | 839 | /* Load new stack segment descriptor */ |
| 874 | 840 | cpustate->sreg[SS].selector = stack.selector; |
| 875 | | i386_load_segment_descriptor(cpustate,SS); |
| 841 | i386_load_protected_mode_segment(cpustate,&cpustate->sreg[SS],NULL); |
| 842 | i386_set_descriptor_accessed(cpustate, stack.selector); |
| 876 | 843 | if(flags & 0x0008) |
| 877 | 844 | REG32(ESP) = i386_get_stack_ptr(cpustate,DPL); |
| 878 | 845 | else |
| 879 | 846 | REG16(SP) = i386_get_stack_ptr(cpustate,DPL); |
| 847 | if(V8086_MODE) |
| 848 | { |
| 849 | logerror("IRQ (%08x): Interrupt during V8086 task\n",cpustate->pc); |
| 850 | if(type & 0x08) |
| 851 | { |
| 852 | PUSH32(cpustate,cpustate->sreg[GS].selector & 0xffff); |
| 853 | PUSH32(cpustate,cpustate->sreg[FS].selector & 0xffff); |
| 854 | PUSH32(cpustate,cpustate->sreg[DS].selector & 0xffff); |
| 855 | PUSH32(cpustate,cpustate->sreg[ES].selector & 0xffff); |
| 856 | } |
| 857 | else |
| 858 | { |
| 859 | PUSH16(cpustate,cpustate->sreg[GS].selector); |
| 860 | PUSH16(cpustate,cpustate->sreg[FS].selector); |
| 861 | PUSH16(cpustate,cpustate->sreg[DS].selector); |
| 862 | PUSH16(cpustate,cpustate->sreg[ES].selector); |
| 863 | } |
| 864 | cpustate->sreg[GS].selector = 0; |
| 865 | cpustate->sreg[FS].selector = 0; |
| 866 | cpustate->sreg[DS].selector = 0; |
| 867 | cpustate->sreg[ES].selector = 0; |
| 868 | cpustate->VM = 0; |
| 869 | i386_load_segment_descriptor(cpustate,GS); |
| 870 | i386_load_segment_descriptor(cpustate,FS); |
| 871 | i386_load_segment_descriptor(cpustate,DS); |
| 872 | i386_load_segment_descriptor(cpustate,ES); |
| 873 | } |
| 880 | 874 | if(type & 0x08) |
| 881 | 875 | { |
| 882 | 876 | // 32-bit gate |
| r15214 | r15215 | |
| 897 | 891 | if((desc.flags & 0x0004) || (DPL == CPL)) |
| 898 | 892 | { |
| 899 | 893 | /* IRQ to same privilege */ |
| 894 | if(V8086_MODE) |
| 895 | { |
| 896 | logerror("IRQ: Gate to same privilege from VM86 mode.\n"); |
| 897 | FAULT_EXP(FAULT_GP,segment & ~0x03); |
| 898 | } |
| 900 | 899 | if(type == 0x0e || type == 0x0f) // 32-bit gate |
| 901 | 900 | stack_limit = 10; |
| 902 | 901 | else |
| r15214 | r15215 | |
| 924 | 923 | |
| 925 | 924 | if(type != 0x0e && type != 0x0f) // if not 386 interrupt or trap gate |
| 926 | 925 | { |
| 927 | | PUSH16(cpustate, get_flags(cpustate) & 0xffff ); |
| 926 | PUSH16(cpustate, oldflags & 0xffff ); |
| 928 | 927 | PUSH16(cpustate, cpustate->sreg[CS].selector ); |
| 929 | 928 | if(irq == 3 || irq == 4 || irq == 9 || irq_gate == 1) |
| 930 | 929 | PUSH16(cpustate, cpustate->eip ); |
| r15214 | r15215 | |
| 933 | 932 | } |
| 934 | 933 | else |
| 935 | 934 | { |
| 936 | | PUSH32(cpustate, get_flags(cpustate) & 0x00fcffff ); |
| 935 | PUSH32(cpustate, oldflags & 0x00ffffff ); |
| 937 | 936 | PUSH32(cpustate, cpustate->sreg[CS].selector ); |
| 938 | 937 | if(irq == 3 || irq == 4 || irq == 9 || irq_gate == 1) |
| 939 | 938 | PUSH32(cpustate, cpustate->eip ); |
| r15214 | r15215 | |
| 967 | 966 | { |
| 968 | 967 | UINT32 entry = irq * 8; |
| 969 | 968 | UINT32 v2,type; |
| 970 | | int cpl = cpustate->CPL; |
| 971 | | cpustate->CPL = 0; |
| 972 | | v2 = READ32(cpustate, cpustate->idtr.base + entry + 4 ); |
| 969 | v2 = READ32PL0(cpustate, cpustate->idtr.base + entry + 4 ); |
| 973 | 970 | type = (v2>>8) & 0x1F; |
| 974 | 971 | if(type == 5) |
| 975 | 972 | { |
| 976 | | v2 = READ32(cpustate, cpustate->idtr.base + entry); |
| 977 | | v2 = READ32(cpustate, cpustate->gdtr.base + ((v2 >> 16) & 0xfff8) + 4); |
| 973 | v2 = READ32PL0(cpustate, cpustate->idtr.base + entry); |
| 974 | v2 = READ32PL0(cpustate, cpustate->gdtr.base + ((v2 >> 16) & 0xfff8) + 4); |
| 978 | 975 | type = (v2>>8) & 0x1F; |
| 979 | 976 | } |
| 980 | | cpustate->CPL = cpl; |
| 981 | 977 | if(type >= 9) |
| 982 | 978 | PUSH32(cpustate,error); |
| 983 | 979 | else |
| r15214 | r15215 | |
| 1031 | 1027 | WRITE16(cpustate,tss+0x28,cpustate->sreg[DS].selector); |
| 1032 | 1028 | |
| 1033 | 1029 | old_task = cpustate->task.segment; |
| 1034 | | |
| 1030 | |
| 1035 | 1031 | /* Load task register with the selector of the incoming task */ |
| 1036 | 1032 | cpustate->task.segment = selector; |
| 1037 | 1033 | memset(&seg, 0, sizeof(seg)); |
| r15214 | r15215 | |
| 1155 | 1151 | cpustate->cr[0] |= 0x08; |
| 1156 | 1152 | |
| 1157 | 1153 | /* Load incoming task state from the new task's TSS */ |
| 1158 | | cpustate->CPL = 0; |
| 1159 | 1154 | tss = cpustate->task.base; |
| 1160 | 1155 | cpustate->ldtr.segment = READ32(cpustate,tss+0x60) & 0xffff; |
| 1161 | 1156 | seg.selector = cpustate->ldtr.segment; |
| r15214 | r15215 | |
| 2240 | 2235 | logerror("IRET (%08x): Is in Virtual 8086 mode and IOPL != 3.\n",cpustate->pc); |
| 2241 | 2236 | FAULT(FAULT_GP,0) |
| 2242 | 2237 | } |
| 2243 | | /* Is this correct? The 80386 programmers' reference says IRET should always trigger #GP(0) in V86 mode */ |
| 2244 | 2238 | if(operand32 == 0) |
| 2245 | 2239 | { |
| 2246 | 2240 | cpustate->eip = newEIP & 0xffff; |
| r15214 | r15215 | |
| 2299 | 2293 | { |
| 2300 | 2294 | if(newflags & 0x00020000) // if returning to virtual 8086 mode |
| 2301 | 2295 | { |
| 2302 | | // UINT8 SSRPL,SSDPL; |
| 2303 | | if(operand32 == 0) |
| 2304 | | { |
| 2305 | | newESP = READ16(cpustate, ea+6) & 0xffff; |
| 2306 | | newSS = READ16(cpustate, ea+8) & 0xffff; |
| 2307 | | } |
| 2308 | | else |
| 2309 | | { |
| 2310 | | newESP = READ32(cpustate, ea+12); |
| 2311 | | newSS = READ32(cpustate, ea+16) & 0xffff; |
| 2312 | | } |
| 2296 | // 16-bit iret can't reach here |
| 2297 | newESP = READ32(cpustate, ea+12); |
| 2298 | newSS = READ32(cpustate, ea+16) & 0xffff; |
| 2313 | 2299 | memset(&desc, 0, sizeof(desc)); |
| 2314 | 2300 | desc.selector = newCS; |
| 2315 | 2301 | i386_load_protected_mode_segment(cpustate,&desc,NULL); |
| r15214 | r15215 | |
| 2318 | 2304 | memset(&stack, 0, sizeof(stack)); |
| 2319 | 2305 | stack.selector = newSS; |
| 2320 | 2306 | i386_load_protected_mode_segment(cpustate,&stack,NULL); |
| 2321 | | //SSRPL = newSS & 0x03; |
| 2322 | | //SSDPL = (stack.flags >> 5) & 0x03; |
| 2323 | 2307 | |
| 2324 | 2308 | /* Return to v86 mode */ |
| 2325 | 2309 | logerror("IRET (%08x): Returning to Virtual 8086 mode.\n",cpustate->pc); |
| 2326 | | // Should these be done at this point? The 386 programmers' reference is a bit confusing about this |
| 2327 | | /* if(RPL != 3) |
| 2328 | | { |
| 2329 | | logerror("IRET to V86 (%08x): Return CS RPL is not 3\n",cpustate->pc); |
| 2330 | | FAULT(FAULT_GP,newCS); |
| 2331 | | } |
| 2332 | | if(operand32 == 0) |
| 2333 | | { |
| 2334 | | if(REG16(SP)+36 > cpustate->sreg[SS].limit) |
| 2335 | | { |
| 2336 | | logerror("IRET to V86 (%08x): Stack does not have enough room left\n",cpustate->pc); |
| 2337 | | FAULT(FAULT_SS,0); |
| 2338 | | } |
| 2339 | | } |
| 2340 | | else |
| 2341 | | { |
| 2342 | | if(REG32(ESP)+36 > cpustate->sreg[SS].limit) |
| 2343 | | { |
| 2344 | | logerror("IRET to V86 (%08x): Stack does not have enough space left\n",cpustate->pc); |
| 2345 | | FAULT(FAULT_SS,0); |
| 2346 | | } |
| 2347 | | } |
| 2348 | | // code segment checks |
| 2349 | | if((newCS & ~0x07) == 0) |
| 2350 | | { |
| 2351 | | logerror("IRET to V86 (%08x): Return CS selector is null\n",cpustate->pc); |
| 2352 | | FAULT(FAULT_GP,newCS); |
| 2353 | | } |
| 2354 | | if(desc.flags & 0x04) |
| 2355 | | { // LDT |
| 2356 | | if(newCS > cpustate->ldtr.limit) |
| 2357 | | { |
| 2358 | | logerror("IRET to V86 (%08x): Return CS selector is past LDT limit\n",cpustate->pc); |
| 2359 | | FAULT(FAULT_GP,newCS); |
| 2360 | | } |
| 2361 | | } |
| 2362 | | else |
| 2363 | | { // GDT |
| 2364 | | if(newCS > cpustate->gdtr.limit) |
| 2365 | | { |
| 2366 | | logerror("IRET to V86 (%08x): Return CS selector is past GDT limit\n",cpustate->pc); |
| 2367 | | FAULT(FAULT_GP,newCS); |
| 2368 | | } |
| 2369 | | } |
| 2370 | | if((desc.flags & 0x18) != 0x18) |
| 2371 | | { |
| 2372 | | logerror("IRET to V86 (%08x): Return CS segment is not a code segment\n",cpustate->pc); |
| 2373 | | FAULT(FAULT_GP,newCS); |
| 2374 | | } |
| 2375 | | if(DPL != 3) |
| 2376 | | { |
| 2377 | | logerror("IRET to V86 (%08x): Return CS segment does not have a DPL of 3\n",cpustate->pc); |
| 2378 | | FAULT(FAULT_GP,newCS); |
| 2379 | | } |
| 2380 | | if(!(desc.flags & 0x0080)) |
| 2381 | | { |
| 2382 | | logerror("IRET to V86 (%08x): Return CS segment is not present\n",cpustate->pc); |
| 2383 | | FAULT(FAULT_NP,newCS); |
| 2384 | | } |
| 2385 | | // Stack segment checks |
| 2386 | | if((newSS & ~0x07) == 0) |
| 2387 | | { |
| 2388 | | logerror("IRET to V86 (%08x): Return SS segment is null\n",cpustate->pc); |
| 2389 | | FAULT(FAULT_GP,newSS); |
| 2390 | | } |
| 2391 | | if(desc.flags & 0x04) |
| 2392 | | { // LDT |
| 2393 | | if(newSS > cpustate->ldtr.limit) |
| 2394 | | { |
| 2395 | | logerror("IRET to V86 (%08x): Return SS selector is past LDT limit\n",cpustate->pc); |
| 2396 | | FAULT(FAULT_GP,newSS); |
| 2397 | | } |
| 2398 | | } |
| 2399 | | else |
| 2400 | | { // GDT |
| 2401 | | if(newSS > cpustate->gdtr.limit) |
| 2402 | | { |
| 2403 | | logerror("IRET to V86 (%08x): Return SS selector is past GDT limit\n",cpustate->pc); |
| 2404 | | FAULT(FAULT_GP,newSS); |
| 2405 | | } |
| 2406 | | } |
| 2407 | | if(SSRPL != RPL) |
| 2408 | | { |
| 2409 | | logerror("IRET to V86 (%08x): Return SS selector RPL is not equal to CS selector RPL\n",cpustate->pc); |
| 2410 | | FAULT(FAULT_GP,newSS); |
| 2411 | | } |
| 2412 | | if(((stack.flags & 0x0018) != 0x10) && (!(stack.flags & 0x02))) |
| 2413 | | { |
| 2414 | | logerror("IRET to V86 (%08x): Return SS segment is not a writable data segment\n",cpustate->pc); |
| 2415 | | FAULT(FAULT_GP,newSS); |
| 2416 | | } |
| 2417 | | if(SSDPL != RPL) |
| 2418 | | { |
| 2419 | | logerror("IRET to V86 (%08x): Return SS segment DPL is not equal to CS selector RPL\n",cpustate->pc); |
| 2420 | | FAULT(FAULT_GP,newSS); |
| 2421 | | } |
| 2422 | | if(!(stack.flags & 0x0080)) |
| 2423 | | { |
| 2424 | | logerror("IRET to V86 (%08x): Return SS segment is not present\n",cpustate->pc); |
| 2425 | | FAULT(FAULT_NP,newSS); |
| 2426 | | } |
| 2427 | | |
| 2428 | | if(newEIP > desc.limit) |
| 2429 | | { |
| 2430 | | logerror("IRET to V86 (%08x): New EIP is past CS segment limit\n",cpustate->pc); |
| 2431 | | FAULT(FAULT_GP,0); |
| 2432 | | } |
| 2433 | | */ |
| 2434 | 2310 | if(CPL != 0) |
| 2435 | 2311 | { |
| 2436 | 2312 | UINT32 oldflags = get_flags(cpustate); |
| r15214 | r15215 | |
| 2440 | 2316 | cpustate->eip = POP32(cpustate) & 0xffff; // high 16 bits are ignored |
| 2441 | 2317 | cpustate->sreg[CS].selector = POP32(cpustate) & 0xffff; |
| 2442 | 2318 | POP32(cpustate); // already set flags |
| 2443 | | // if(RPL > CPL) |
| 2444 | | { |
| 2445 | | newESP = POP32(cpustate); |
| 2446 | | newSS = POP32(cpustate) & 0xffff; |
| 2447 | | } |
| 2319 | newESP = POP32(cpustate); |
| 2320 | newSS = POP32(cpustate) & 0xffff; |
| 2448 | 2321 | cpustate->sreg[ES].selector = POP32(cpustate) & 0xffff; |
| 2449 | 2322 | cpustate->sreg[DS].selector = POP32(cpustate) & 0xffff; |
| 2450 | 2323 | cpustate->sreg[FS].selector = POP32(cpustate) & 0xffff; |
src/emu/cpu/i386/i386op32.c
| r15214 | r15215 | |
| 1451 | 1451 | CYCLES(cpustate,CYCLES_POP_REG_SHORT); |
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | | static void I386OP(pop_ds32)(i386_state *cpustate) // Opcode 0x1f |
| 1454 | static bool I386OP(pop_seg32)(i386_state *cpustate, int segment) |
| 1455 | 1455 | { |
| 1456 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1456 | UINT32 ea, offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1457 | UINT32 value; |
| 1458 | bool fault; |
| 1457 | 1459 | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1458 | 1460 | { |
| 1459 | | cpustate->sreg[DS].selector = POP32(cpustate); |
| 1460 | | if( PROTECTED_MODE ) { |
| 1461 | | i386_load_segment_descriptor(cpustate,DS); |
| 1462 | | } else { |
| 1463 | | i386_load_segment_descriptor(cpustate,DS); |
| 1464 | | } |
| 1461 | ea = i386_translate(cpustate, SS, offset, 0); |
| 1462 | value = READ32(cpustate, ea); |
| 1463 | i386_sreg_load(cpustate,value, segment, &fault); |
| 1464 | if(fault) return false; |
| 1465 | if(STACK_32BIT) |
| 1466 | REG32(ESP) = offset + 4; |
| 1467 | else |
| 1468 | REG16(SP) = offset + 4; |
| 1465 | 1469 | } |
| 1466 | 1470 | else |
| 1467 | | FAULT(FAULT_SS,0) |
| 1471 | { |
| 1472 | cpustate->ext = 1; |
| 1473 | i386_trap_with_error(cpustate,FAULT_SS,0,0,0); |
| 1474 | return false; |
| 1475 | } |
| 1468 | 1476 | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1477 | return true; |
| 1469 | 1478 | } |
| 1470 | 1479 | |
| 1480 | static void I386OP(pop_ds32)(i386_state *cpustate) // Opcode 0x1f |
| 1481 | { |
| 1482 | I386OP(pop_seg32)(cpustate, DS); |
| 1483 | } |
| 1484 | |
| 1471 | 1485 | static void I386OP(pop_es32)(i386_state *cpustate) // Opcode 0x07 |
| 1472 | 1486 | { |
| 1473 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1474 | | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1475 | | { |
| 1476 | | cpustate->sreg[ES].selector = POP32(cpustate); |
| 1477 | | if( PROTECTED_MODE ) { |
| 1478 | | i386_load_segment_descriptor(cpustate,ES); |
| 1479 | | } else { |
| 1480 | | i386_load_segment_descriptor(cpustate,ES); |
| 1481 | | } |
| 1482 | | } |
| 1483 | | else |
| 1484 | | FAULT(FAULT_SS,0) |
| 1485 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1487 | I386OP(pop_seg32)(cpustate, ES); |
| 1486 | 1488 | } |
| 1487 | 1489 | |
| 1488 | 1490 | static void I386OP(pop_fs32)(i386_state *cpustate) // Opcode 0x0f a1 |
| 1489 | 1491 | { |
| 1490 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1491 | | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1492 | | { |
| 1493 | | cpustate->sreg[FS].selector = POP32(cpustate); |
| 1494 | | if( PROTECTED_MODE ) { |
| 1495 | | i386_load_segment_descriptor(cpustate,FS); |
| 1496 | | } else { |
| 1497 | | i386_load_segment_descriptor(cpustate,FS); |
| 1498 | | } |
| 1499 | | } |
| 1500 | | else |
| 1501 | | FAULT(FAULT_SS,0) |
| 1502 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1492 | I386OP(pop_seg32)(cpustate, FS); |
| 1503 | 1493 | } |
| 1504 | 1494 | |
| 1505 | 1495 | static void I386OP(pop_gs32)(i386_state *cpustate) // Opcode 0x0f a9 |
| 1506 | 1496 | { |
| 1507 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1508 | | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1509 | | { |
| 1510 | | cpustate->sreg[GS].selector = POP32(cpustate); |
| 1511 | | if( PROTECTED_MODE ) { |
| 1512 | | i386_load_segment_descriptor(cpustate,GS); |
| 1513 | | } else { |
| 1514 | | i386_load_segment_descriptor(cpustate,GS); |
| 1515 | | } |
| 1516 | | } |
| 1517 | | else |
| 1518 | | FAULT(FAULT_SS,0) |
| 1519 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1497 | I386OP(pop_seg32)(cpustate, GS); |
| 1520 | 1498 | } |
| 1521 | 1499 | |
| 1522 | 1500 | static void I386OP(pop_ss32)(i386_state *cpustate) // Opcode 0x17 |
| 1523 | 1501 | { |
| 1524 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1502 | if(!I386OP(pop_seg32)(cpustate, SS)) return; |
| 1525 | 1503 | if(cpustate->IF != 0) // if external interrupts are enabled |
| 1526 | 1504 | { |
| 1527 | 1505 | cpustate->IF = 0; // reset IF for the next instruction |
| 1528 | 1506 | cpustate->delayed_interrupt_enable = 1; |
| 1529 | 1507 | } |
| 1530 | | |
| 1531 | | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1532 | | { |
| 1533 | | cpustate->sreg[SS].selector = POP32(cpustate); |
| 1534 | | if( PROTECTED_MODE ) { |
| 1535 | | i386_load_segment_descriptor(cpustate,SS); |
| 1536 | | } else { |
| 1537 | | i386_load_segment_descriptor(cpustate,SS); |
| 1538 | | } |
| 1539 | | } |
| 1540 | | else |
| 1541 | | FAULT(FAULT_SS,0) |
| 1542 | | CYCLES(cpustate,CYCLES_POP_SREG); |
| 1543 | 1508 | } |
| 1544 | 1509 | |
| 1545 | 1510 | static void I386OP(pop_rm32)(i386_state *cpustate) // Opcode 0x8f |
| 1546 | 1511 | { |
| 1547 | 1512 | UINT8 modrm = FETCH(cpustate); |
| 1548 | 1513 | UINT32 value; |
| 1549 | | UINT32 offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1514 | UINT32 ea, offset = (STACK_32BIT ? REG32(ESP) : REG16(SP)); |
| 1550 | 1515 | if(i386_limit_check(cpustate,SS,offset+3) == 0) |
| 1551 | 1516 | { |
| 1517 | // be careful here, if the write references the esp register |
| 1518 | // it expects the post-pop value but esp must be wound back |
| 1519 | // if the write faults |
| 1520 | UINT32 temp_sp = REG32(ESP); |
| 1552 | 1521 | value = POP32(cpustate); |
| 1553 | 1522 | |
| 1554 | 1523 | if( modrm >= 0xc0 ) { |
| 1555 | 1524 | STORE_RM32(modrm, value); |
| 1556 | 1525 | } else { |
| 1557 | | UINT32 ea = GetEA(cpustate,modrm,1); |
| 1558 | | WRITE32(cpustate,ea, value); |
| 1526 | ea = GetEA(cpustate,modrm,1); |
| 1527 | try |
| 1528 | { |
| 1529 | WRITE32(cpustate,ea, value); |
| 1530 | } |
| 1531 | catch(UINT64 e) |
| 1532 | { |
| 1533 | REG32(ESP) = temp_sp; |
| 1534 | throw e; |
| 1535 | } |
| 1559 | 1536 | } |
| 1560 | 1537 | } |
| 1561 | 1538 | else |
| r15214 | r15215 | |
| 3514 | 3491 | UINT32 ea = GetEA(cpustate,modrm,0); |
| 3515 | 3492 | STORE_REG32(modrm, READ32(cpustate,ea + 0)); |
| 3516 | 3493 | selector = READ16(cpustate,ea + 4); |
| 3517 | | if(PROTECTED_MODE && !(V8086_MODE)) |
| 3518 | | i386_protected_mode_sreg_load(cpustate,selector,s); |
| 3519 | | else |
| 3520 | | { |
| 3521 | | cpustate->sreg[s].selector = selector; |
| 3522 | | i386_load_segment_descriptor(cpustate, s ); |
| 3523 | | } |
| 3494 | i386_sreg_load(cpustate,selector,s,NULL); |
| 3524 | 3495 | } |
| 3525 | 3496 | } |
| 3526 | 3497 | |