--- np2/i386c/ia32/exception.c 2004/02/20 16:09:04 1.12 +++ np2/i386c/ia32/exception.c 2005/03/12 12:32:54 1.19 @@ -1,4 +1,4 @@ -/* $Id: exception.c,v 1.12 2004/02/20 16:09:04 monaka Exp $ */ +/* $Id: exception.c,v 1.19 2005/03/12 12:32:54 monaka Exp $ */ /* * Copyright (c) 2003 NONAKA Kimihiro @@ -12,8 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -72,6 +70,11 @@ exception(int num, int error_code) __ASSERT((unsigned int)num < EXCEPTION_NUM); +#if 0 + iptrace_out(); + debugwriteseg("execption.bin", &CPU_STAT_SREG(CPU_CS_INDEX), CPU_PREV_EIP & 0xffff0000, 0x10000); +#endif + VERBOSE(("exception: -------------------------------------------------------------- start")); VERBOSE(("exception: %s, error_code = %x at %04x:%08x", exception_str[num], error_code, CPU_CS, CPU_PREV_EIP)); VERBOSE(("%s", cpu_reg2str())); @@ -85,12 +88,19 @@ exception(int num, int error_code) switch (num) { case DE_EXCEPTION: /* (F) 除算エラー */ + case DB_EXCEPTION: /* (F/T) デバッグ */ case BR_EXCEPTION: /* (F) BOUND の範囲外 */ case UD_EXCEPTION: /* (F) 無効オペコード */ case NM_EXCEPTION: /* (F) デバイス使用不可 (FPU が無い) */ + case MF_EXCEPTION: /* (F) 浮動小数点エラー */ +#if CPU_FAMILY >= 5 + case MC_EXCEPTION: /* (A) マシンチェック */ +#endif +#if CPU_FAMILY >= 6 + case XF_EXCEPTION: /* (F) ストリーミング SIMD 拡張命令 */ +#endif CPU_EIP = CPU_PREV_EIP; /*FALLTHROUGH*/ - case DB_EXCEPTION: /* (F/T) デバッグ */ case NMI_EXCEPTION: /* (I) NMI 割り込み */ case BP_EXCEPTION: /* (T) ブレークポイント */ case OF_EXCEPTION: /* (T) オーバーフロー */ @@ -116,25 +126,6 @@ exception(int num, int error_code) errorp = 1; break; - case MF_EXCEPTION: /* (F) 浮動小数点エラー */ - CPU_EIP = CPU_PREV_EIP; - errorp = 0; - break; - -#if CPU_FAMILY >= 5 - case MC_EXCEPTION: /* (A) マシンチェック */ - CPU_EIP = CPU_PREV_EIP; - errorp = 0; - break; -#endif - -#if CPU_FAMILY >= 6 - case XF_EXCEPTION: /* (F) ストリーミング SIMD 拡張命令 */ - CPU_EIP = CPU_PREV_EIP; - errorp = 0; - break; -#endif - default: ia32_panic("exception: unknown exception (%d)", num); break; @@ -143,6 +134,8 @@ exception(int num, int error_code) if (CPU_STAT_EXCEPTION_COUNTER >= 2) { if (dftable[exctype[CPU_STAT_PREV_EXCEPTION]][exctype[num]]) { num = DF_EXCEPTION; + errorp = 1; + error_code = 0; } } CPU_STAT_PREV_EXCEPTION = num; @@ -150,6 +143,17 @@ exception(int num, int error_code) VERBOSE(("exception: ---------------------------------------------------------------- end")); INTERRUPT(num, 0, errorp, error_code); +#if defined(IA32_SUPPORT_DEBUG_REGISTER) + if (num != BP_EXCEPTION) { + if (CPU_INST_OP32) { +#if defined(IA32_DONT_USE_SET_EFLAGS_FUNCTION) + CPU_EFLAG |= RF_FLAG; +#else + set_eflags(REAL_EFLAGREG|RF_FLAG, RF_FLAG); +#endif + } + } +#endif CPU_STAT_EXCEPTION_COUNTER_CLEAR(); siglongjmp(exec_1step_jmpbuf, 1); } @@ -210,8 +214,8 @@ exception(int num, int error_code) * D : ゲートのサイズ.0 = 16 bit, 1 = 32 bit */ -static void interrupt_task_gate(descriptor_t *gd, int softintp, int errorp, int error_code); -static void interrupt_intr_or_trap(descriptor_t *gd, int softintp, int errorp, int error_code); +static void interrupt_task_gate(const descriptor_t *gd, int softintp, int errorp, int error_code); +static void interrupt_intr_or_trap(const descriptor_t *gd, int softintp, int errorp, int error_code); void interrupt(int num, int softintp, int errorp, int error_code) @@ -327,7 +331,7 @@ interrupt(int num, int softintp, int err } static void -interrupt_task_gate(descriptor_t *gd, int softintp, int errorp, int error_code) +interrupt_task_gate(const descriptor_t *gd, int softintp, int errorp, int error_code) { selector_t task_sel; int rv; @@ -372,7 +376,7 @@ interrupt_task_gate(descriptor_t *gd, in } static void -interrupt_intr_or_trap(descriptor_t *gd, int softintp, int errorp, int error_code) +interrupt_intr_or_trap(const descriptor_t *gd, int softintp, int errorp, int error_code) { selector_t cs_sel, ss_sel; UINT stacksize; @@ -390,26 +394,27 @@ interrupt_intr_or_trap(descriptor_t *gd, old_cs = CPU_CS; old_ip = CPU_EIP; old_sp = CPU_ESP; - new_flags = old_flags = REAL_EFLAGREG; + old_flags = REAL_EFLAGREG; + new_flags = REAL_EFLAGREG & ~(T_FLAG|RF_FLAG|NT_FLAG|VM_FLAG); + mask = T_FLAG|RF_FLAG|NT_FLAG|VM_FLAG; switch (gd->type) { case CPU_SYSDESC_TYPE_INTR_16: case CPU_SYSDESC_TYPE_INTR_32: VERBOSE(("interrupt: INTERRUPT-GATE")); new_flags &= ~I_FLAG; - mask = I_FLAG; + mask |= I_FLAG; break; case CPU_SYSDESC_TYPE_TRAP_16: case CPU_SYSDESC_TYPE_TRAP_32: VERBOSE(("interrupt: TRAP-GATE")); + break; default: - mask = 0; + ia32_panic("interrupt: gate descriptor type is invalid (type = %d)", gd->type); break; } - new_flags &= ~(T_FLAG|RF_FLAG|NT_FLAG|VM_FLAG); - mask |= T_FLAG|RF_FLAG|NT_FLAG|VM_FLAG; rv = parse_selector(&cs_sel, gd->u.gate.selector); if (rv < 0) { @@ -500,7 +505,7 @@ interrupt_intr_or_trap(descriptor_t *gd, } /* check stack room size */ - CHECK_STACK_PUSH(&ss_sel.desc, new_sp, stacksize); + STACK_PUSH_CHECK(ss_sel.idx, &ss_sel.desc, new_sp, stacksize); /* out of range */ if (new_ip > cs_sel.desc.u.seg.limit) { @@ -557,8 +562,6 @@ interrupt_intr_or_trap(descriptor_t *gd, } break; } - - set_eflags(new_flags, mask); } else { if (CPU_STAT_VM86) { VERBOSE(("interrupt: VM86")); @@ -583,7 +586,7 @@ interrupt_intr_or_trap(descriptor_t *gd, } else { sp = CPU_SP; } - CHECK_STACK_PUSH(&CPU_STAT_SREG(CPU_SS_INDEX), sp, stacksize); + STACK_PUSH_CHECK(CPU_REGS_SREG(CPU_SS_INDEX), &CPU_STAT_SREG(CPU_SS_INDEX), sp, stacksize); /* out of range */ if (new_ip > cs_sel.desc.u.seg.limit) { @@ -615,9 +618,21 @@ interrupt_intr_or_trap(descriptor_t *gd, } break; } - - set_eflags(new_flags, mask); } +#if defined(IA32_DONT_USE_SET_EFLAGS_FUNCTION) + CPU_EFLAG = new_flags; + CPU_OV = CPU_FLAG & O_FLAG; + CPU_TRAP = (CPU_FLAG & (I_FLAG|T_FLAG)) == (I_FLAG|T_FLAG); + if ((old_flags ^ CPU_EFLAG) & VM_FLAG) { + if (CPU_EFLAG & VM_FLAG) { + change_vm(1); + } else { + change_vm(0); + } + } +#else + set_eflags(new_flags, mask); +#endif - VERBOSE(("interrupt: new EIP = %04x:%08x, new ESP = %04x:%08x", CPU_CS, CPU_EIP, CPU_SS, CPU_ESP)); + VERBOSE(("interrupt: new EIP = %04x:%08x, ESP = %04x:%08x", CPU_CS, CPU_EIP, CPU_SS, CPU_ESP)); }