--- np2/i386c/ia32/ctrlxfer.c 2004/01/27 15:55:49 1.5 +++ np2/i386c/ia32/ctrlxfer.c 2004/02/05 16:43:44 1.8 @@ -1,4 +1,4 @@ -/* $Id: ctrlxfer.c,v 1.5 2004/01/27 15:55:49 monaka Exp $ */ +/* $Id: ctrlxfer.c,v 1.8 2004/02/05 16:43:44 monaka Exp $ */ /* * Copyright (c) 2003 NONAKA Kimihiro @@ -560,37 +560,33 @@ static void CALLfar_pm_call_gate_same_privilege(selector_t *callgate_sel, selector_t *cs_sel) { DWORD sp; - DWORD old_eip; - WORD old_cs; + DWORD new_ip; VERBOSE(("CALLfar_pm: SAME-PRIVILEGE")); - /* save register */ - old_cs = CPU_CS; - old_eip = CPU_EIP; - if (CPU_STAT_SS32) { sp = CPU_ESP; } else { sp = CPU_SP; } + new_ip = callgate_sel->desc.u.gate.offset; if (callgate_sel->desc.type == CPU_SYSDESC_TYPE_CALL_32) { CHECK_STACK_PUSH(&CPU_STAT_SREG(CPU_SS_INDEX), sp, 8); - load_cs(cs_sel->selector, &cs_sel->desc, CPU_STAT_CPL); - SET_EIP(callgate_sel->desc.u.gate.offset); + PUSH0_32(CPU_CS); + PUSH0_32(CPU_EIP); - PUSH0_32(old_cs); - PUSH0_32(old_eip); + load_cs(cs_sel->selector, &cs_sel->desc, CPU_STAT_CPL); + SET_EIP(new_ip); } else { CHECK_STACK_PUSH(&CPU_STAT_SREG(CPU_SS_INDEX), sp, 4); - load_cs(cs_sel->selector, &cs_sel->desc, CPU_STAT_CPL); - SET_EIP(callgate_sel->desc.u.gate.offset); + PUSH0_16(CPU_CS); + PUSH0_16(CPU_IP); - PUSH0_16(old_cs); - PUSH0_16(old_eip); + load_cs(cs_sel->selector, &cs_sel->desc, CPU_STAT_CPL); + SET_EIP(new_ip); } } @@ -678,7 +674,11 @@ CALLfar_pm_call_gate_more_privilege(sele } load_ss(ss_sel.selector, &ss_sel.desc, ss_sel.desc.dpl); - CPU_ESP = tss_esp; + if (CPU_STAT_SS32) { + CPU_ESP = tss_esp; + } else { + CPU_SP = (WORD)tss_esp; + } load_cs(cs_sel->selector, &cs_sel->desc, cs_sel->desc.dpl); SET_EIP(callgate_sel->desc.u.gate.offset); @@ -704,7 +704,11 @@ CALLfar_pm_call_gate_more_privilege(sele } load_ss(ss_sel.selector, &ss_sel.desc, ss_sel.desc.dpl); - CPU_ESP = tss_esp; + if (CPU_STAT_SS32) { + CPU_ESP = tss_esp; + } else { + CPU_SP = (WORD)tss_esp; + } load_cs(cs_sel->selector, &cs_sel->desc, cs_sel->desc.dpl); SET_EIP(callgate_sel->desc.u.gate.offset); @@ -980,7 +984,11 @@ RETfar_pm(DWORD nbytes) SET_EIP(new_ip); load_ss(ss_sel.selector, &ss_sel.desc, ret_sel.rpl); - CPU_ESP = new_sp + nbytes; + if (CPU_STAT_SS32) { + CPU_ESP = new_sp + nbytes; + } else { + CPU_SP = new_sp + nbytes; + } /* check segment register */ for (i = 0; i < CPU_SEGREG_NUM; i++) { @@ -1034,14 +1042,9 @@ RETfar_pm(DWORD nbytes) /*------------------------------------------------------------------------------ * IRET_pm */ - -#define IA32_RETURN_FROM_VM86 - static void IRET_pm_nested_task(void); static void IRET_pm_return_to_vm86(DWORD new_ip, DWORD new_cs, DWORD new_flags); -#if defined(IA32_RETURN_FROM_VM86) static void IRET_pm_return_from_vm86(DWORD new_ip, DWORD new_cs, DWORD new_flags); -#endif /* IA32_RETURN_FROM_VM86 */ void IRET_pm(void) @@ -1085,7 +1088,6 @@ IRET_pm(void) } VERBOSE(("IRET_pm: new_ip = %08x, new_cs = %04x, new_eflags = %08x", new_ip, new_cs, new_flags)); -#ifdef IA32_RETURN_FROM_VM86 if (CPU_EFLAG & VM_FLAG) { /* RETURN-FROM-VIRTUAL-8086-MODE */ IRET_pm_return_from_vm86(new_ip, new_cs, new_flags); @@ -1093,7 +1095,6 @@ IRET_pm(void) CPU_STAT_NERROR = 0; return; } -#endif /* IA32_RETURN_FROM_VM86 */ if (new_flags & VM_FLAG) { /* RETURN-TO-VIRTUAL-8086-MODE */ @@ -1210,12 +1211,6 @@ IRET_pm(void) EXCEPTION(GP_EXCEPTION, 0); } - /* set new register */ - old_cpl = CPU_STAT_CPL; - load_cs(iret_sel.selector, &iret_sel.desc, iret_sel.rpl); - SET_EIP(new_ip); - - /* set new eflags */ mask = 0; if (CPU_INST_OP32) mask |= RF_FLAG; @@ -1227,13 +1222,22 @@ IRET_pm(void) mask |= VM_FLAG|VIF_FLAG|VIP_FLAG; } } + + /* set new register */ + old_cpl = CPU_STAT_CPL; + load_cs(iret_sel.selector, &iret_sel.desc, iret_sel.rpl); + SET_EIP(new_ip); set_eflags(new_flags, mask); if (iret_sel.rpl > old_cpl) { /* RETURN-OUTER-PRIVILEGE-LEVEL */ load_ss(ss_sel.selector, &ss_sel.desc, iret_sel.rpl); - CPU_ESP = new_sp; + if (CPU_STAT_SS32) { + CPU_ESP = new_sp; + } else { + CPU_SP = new_sp; + } /* check segment register */ for (i = 0; i < CPU_SEGREG_NUM; i++) { @@ -1267,26 +1271,26 @@ IRET_pm(void) static void IRET_pm_nested_task(void) { - selector_t iret_sel; + selector_t tss_sel; int rv; - WORD new_cs; + WORD new_tss; VERBOSE(("IRET_pm: TASK-RETURN: PE=1, VM=0, NT=1")); - new_cs = get_link_selector_from_tss(); - rv = parse_selector(&iret_sel, new_cs); - if (rv < 0 || iret_sel.ldt) { - VERBOSE(("IRET_pm: parse_selector (selector = %04x, rv = %d)", iret_sel.selector, rv)); - EXCEPTION(GP_EXCEPTION, iret_sel.idx); + new_tss = get_link_selector_from_tss(); + rv = parse_selector(&tss_sel, new_tss); + if (rv < 0 || tss_sel.ldt) { + VERBOSE(("IRET_pm: parse_selector (selector = %04x, rv = %d, %cDT)", tss_sel.selector, rv, tss_sel.ldt ? 'L' : 'G')); + EXCEPTION(GP_EXCEPTION, tss_sel.idx); } /* check system segment */ - if (iret_sel.desc.s) { - VERBOSE(("IRET_pm: task segment is %d segment", iret_sel.desc.u.seg.c ? "code" : "data")); - EXCEPTION(GP_EXCEPTION, iret_sel.idx); + if (tss_sel.desc.s) { + VERBOSE(("IRET_pm: task segment is %d segment", tss_sel.desc.u.seg.c ? "code" : "data")); + EXCEPTION(GP_EXCEPTION, tss_sel.idx); } - switch (iret_sel.desc.type) { + switch (tss_sel.desc.type) { case CPU_SYSDESC_TYPE_TSS_BUSY_16: case CPU_SYSDESC_TYPE_TSS_BUSY_32: break; @@ -1296,18 +1300,18 @@ IRET_pm_nested_task(void) VERBOSE(("IRET_pm: task is not busy")); /*FALLTHROUGH*/ default: - VERBOSE(("IRET_pm: invalid descriptor type (type = %d)", iret_sel.desc.type)); - EXCEPTION(GP_EXCEPTION, iret_sel.idx); + VERBOSE(("IRET_pm: invalid descriptor type (type = %d)", tss_sel.desc.type)); + EXCEPTION(GP_EXCEPTION, tss_sel.idx); break; } /* not present */ - if (selector_is_not_present(&iret_sel)) { + if (selector_is_not_present(&tss_sel)) { VERBOSE(("IRET_pm: tss segment is not present")); - EXCEPTION(NP_EXCEPTION, iret_sel.idx); + EXCEPTION(NP_EXCEPTION, tss_sel.idx); } - task_switch(&iret_sel, TASK_SWITCH_IRET); + task_switch(&tss_sel, TASK_SWITCH_IRET); } /*--- @@ -1355,7 +1359,6 @@ IRET_pm_return_to_vm86(DWORD new_ip, DWO SET_EIP(new_ip); } -#ifdef IA32_RETURN_FROM_VM86 /*--- * IRET_pm: VM_FLAG */ @@ -1388,4 +1391,3 @@ IRET_pm_return_from_vm86(DWORD new_ip, D VERBOSE(("IRET_pm: trap to virtual-8086 monitor: VM=1, IOPL<3")); EXCEPTION(GP_EXCEPTION, 0); } -#endif /* IA32_RETURN_FROM_VM86 */