--- np2/i386c/ia32/exception.c 2012/01/08 11:36:06 1.35 +++ np2/i386c/ia32/exception.c 2012/06/18 14:33:38 1.39 @@ -147,7 +147,7 @@ exception(int num, int error_code) VERBOSE(("exception: ---------------------------------------------------------------- end")); - interrupt(num, INTR_TYPE_EXTINTR, errorp, error_code); + interrupt(num, INTR_TYPE_EXCEPTION, errorp, error_code); CPU_STAT_EXCEPTION_COUNTER_CLEAR(); siglongjmp(exec_1step_jmpbuf, 1); } @@ -220,7 +220,7 @@ interrupt(int num, int intrtype, int err UINT16 new_cs; int exc_errcode; - VERBOSE(("interrupt: num = 0x%02x, intrtype = %s, errorp = %s, error_code = %08x", num, intrtype ? "on" : "off", errorp ? "on" : "off", error_code)); + VERBOSE(("interrupt: num = 0x%02x, intrtype = %s, errorp = %s, error_code = %08x", num, (intrtype == INTR_TYPE_EXTINTR) ? "external" : (intrtype == INTR_TYPE_EXCEPTION ? "exception" : "softint"), errorp ? "on" : "off", error_code)); CPU_SET_PREV_ESP(); @@ -302,8 +302,8 @@ interrupt(int num, int intrtype, int err } /* 5.10.1.1. 例外/割り込みハンドラ・プロシージャの保護 */ - if ((intrtype != INTR_TYPE_EXTINTR) && (gsd.dpl < CPU_STAT_CPL)) { - VERBOSE(("interrupt: intrtype(%d) && DPL(%d) < CPL(%d)", intrtype, gsd.dpl, CPU_STAT_CPL)); + if ((intrtype == INTR_TYPE_SOFTINTR) && (gsd.dpl < CPU_STAT_CPL)) { + VERBOSE(("interrupt: intrtype(softint) && DPL(%d) < CPL(%d)", gsd.dpl, CPU_STAT_CPL)); EXCEPTION(GP_EXCEPTION, exc_errcode); } @@ -382,7 +382,12 @@ interrupt_task_gate(const descriptor_t * CPU_SET_PREV_ESP(); if (errorp) { - XPUSH0(error_code); + VERBOSE(("interrupt: push error code (%08x)", error_code)); + if (task_sel.desc.type == CPU_SYSDESC_TYPE_TSS_32) { + PUSH0_32(error_code); + } else { + PUSH0_16(error_code); + } } /* out of range */ @@ -404,6 +409,7 @@ interrupt_intr_or_trap(const descriptor_ UINT32 new_ip, new_sp; UINT32 old_ip, old_sp; UINT16 old_cs, old_ss, new_ss; + BOOL is32bit; int exc_errcode; int rv; @@ -466,6 +472,7 @@ interrupt_intr_or_trap(const descriptor_ EXCEPTION(NP_EXCEPTION, exc_errcode); } + is32bit = gsdp->type & CPU_SYSDESC_TYPE_32BIT; if (!SEG_IS_CONFORMING_CODE(&cs_sel.desc) && (cs_sel.desc.dpl < CPU_STAT_CPL)) { stacksize = errorp ? 12 : 10; if (!CPU_STAT_VM86) { @@ -480,7 +487,7 @@ interrupt_intr_or_trap(const descriptor_ } stacksize += 8; } - if (gsdp->type & CPU_SYSDESC_TYPE_32BIT) { + if (is32bit) { stacksize *= 2; } @@ -531,7 +538,7 @@ interrupt_intr_or_trap(const descriptor_ } /* check stack room size */ - cpu_stack_push_check(ss_sel.idx, &ss_sel.desc, new_sp, stacksize); + cpu_stack_push_check(ss_sel.idx, &ss_sel.desc, new_sp, stacksize, ss_sel.desc.d); /* out of range */ if (new_ip > cs_sel.desc.u.seg.limit) { @@ -545,7 +552,7 @@ interrupt_intr_or_trap(const descriptor_ load_cs(cs_sel.selector, &cs_sel.desc, cs_sel.desc.dpl); CPU_EIP = new_ip; - if (gsdp->type & CPU_SYSDESC_TYPE_32BIT) { + if (is32bit) { if (CPU_STAT_VM86) { PUSH0_32(CPU_GS); PUSH0_32(CPU_FS); @@ -595,7 +602,7 @@ interrupt_intr_or_trap(const descriptor_ VERBOSE(("interrupt: INTRA-PRIVILEGE-LEVEL-INTERRUPT")); stacksize = errorp ? 8 : 6; - if (gsdp->type & CPU_SYSDESC_TYPE_32BIT) { + if (is32bit) { stacksize *= 2; } @@ -605,7 +612,15 @@ interrupt_intr_or_trap(const descriptor_ } else { sp = CPU_SP; } - SS_PUSH_CHECK(sp, stacksize); + /* + * 17.1 + * コールゲート、割り込みゲート、またはトラップゲートを通じて + * プログラムの制御を他のコード・セグメントに移行するときは、 + * 移行中に使用されるオペランド・サイズは使用されるゲートの + * タイプ(16 ビットまたは32 ビット)によって決まる(移行命 + * 令のD フラグ、プリフィックスのいずれにもよらない)。 + */ + SS_PUSH_CHECK1(sp, stacksize, is32bit); /* out of range */ if (new_ip > cs_sel.desc.u.seg.limit) { @@ -616,7 +631,7 @@ interrupt_intr_or_trap(const descriptor_ load_cs(cs_sel.selector, &cs_sel.desc, CPU_STAT_CPL); CPU_EIP = new_ip; - if (gsdp->type & CPU_SYSDESC_TYPE_32BIT) { + if (is32bit) { PUSH0_32(old_flags); PUSH0_32(old_cs); PUSH0_32(old_ip);