Diff for /np2/i386c/ia32/exception.c between versions 1.21 and 1.28

version 1.21, 2008/03/22 04:03:07 version 1.28, 2011/12/21 16:25:52
Line 1 Line 1
 /*      $Id$    */  
   
 /*  /*
  * Copyright (c) 2003 NONAKA Kimihiro   * Copyright (c) 2003 NONAKA Kimihiro
  * All rights reserved.   * All rights reserved.
Line 94  exception(int num, int error_code) Line 92  exception(int num, int error_code)
         case NM_EXCEPTION:      /* (F) デバイス使用不可 (FPU が無い) */          case NM_EXCEPTION:      /* (F) デバイス使用不可 (FPU が無い) */
         case MF_EXCEPTION:      /* (F) 浮動小数点エラー */          case MF_EXCEPTION:      /* (F) 浮動小数点エラー */
                 CPU_EIP = CPU_PREV_EIP;                  CPU_EIP = CPU_PREV_EIP;
                   if (CPU_STATSAVE.cpu_stat.backout_sp)
                           CPU_ESP = CPU_PREV_ESP;
                 /*FALLTHROUGH*/                  /*FALLTHROUGH*/
         case NMI_EXCEPTION:     /* (I) NMI 割り込み */          case NMI_EXCEPTION:     /* (I) NMI 割り込み */
         case BP_EXCEPTION:      /* (T) ブレークポイント */          case BP_EXCEPTION:      /* (T) ブレークポイント */
Line 115  exception(int num, int error_code) Line 115  exception(int num, int error_code)
         case GP_EXCEPTION:      /* (F) 一般保護例外 (errcode) */          case GP_EXCEPTION:      /* (F) 一般保護例外 (errcode) */
         case PF_EXCEPTION:      /* (F) ページフォルト (errcode) */          case PF_EXCEPTION:      /* (F) ページフォルト (errcode) */
                 CPU_EIP = CPU_PREV_EIP;                  CPU_EIP = CPU_PREV_EIP;
                   if (CPU_STATSAVE.cpu_stat.backout_sp)
                           CPU_ESP = CPU_PREV_ESP;
                 errorp = 1;                  errorp = 1;
                 break;                  break;
   
Line 123  exception(int num, int error_code) Line 125  exception(int num, int error_code)
                 break;                  break;
         }          }
   
         if (CPU_STATSAVE.cpu_stat.backout_sp) {  
                 VERBOSE(("exception: restore stack pointer."));  
                 CPU_ESP = CPU_PREV_ESP;  
         }  
         CPU_STATSAVE.cpu_stat.backout_sp = 0;  
   
         if (CPU_STAT_EXCEPTION_COUNTER >= 2) {          if (CPU_STAT_EXCEPTION_COUNTER >= 2) {
                 if (dftable[exctype[CPU_STAT_PREV_EXCEPTION]][exctype[num]]) {                  if (dftable[exctype[CPU_STAT_PREV_EXCEPTION]][exctype[num]]) {
                         num = DF_EXCEPTION;                          num = DF_EXCEPTION;
Line 140  exception(int num, int error_code) Line 136  exception(int num, int error_code)
   
         VERBOSE(("exception: ---------------------------------------------------------------- end"));          VERBOSE(("exception: ---------------------------------------------------------------- end"));
   
         interrupt(num, 0, errorp, error_code);          interrupt(num, INTR_TYPE_EXTINTR, errorp, error_code);
 #if defined(IA32_SUPPORT_DEBUG_REGISTER)  #if defined(IA32_SUPPORT_DEBUG_REGISTER)
         if (num != BP_EXCEPTION) {          if (num != BP_EXCEPTION) {
                 if (CPU_INST_OP32) {                  if (CPU_INST_OP32) {
Line 222  interrupt(int num, int intrtype, int err Line 218  interrupt(int num, int intrtype, int err
   
         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 ? "on" : "off", errorp ? "on" : "off", error_code));
   
           CPU_SET_PREV_ESP();
   
         if (!CPU_STAT_PM) {          if (!CPU_STAT_PM) {
                 /* real mode */                  /* real mode */
                 CPU_WORKCLOCK(20);                  CPU_WORKCLOCK(20);
Line 233  interrupt(int num, int intrtype, int err Line 231  interrupt(int num, int intrtype, int err
                 }                  }
   
                 if ((intrtype == INTR_TYPE_EXTINTR) && CPU_STAT_HLT) {                  if ((intrtype == INTR_TYPE_EXTINTR) && CPU_STAT_HLT) {
                           VERBOSE(("interrupt: reset HTL in real mode"));
                         CPU_EIP++;                          CPU_EIP++;
                         CPU_STAT_HLT = 0;                          CPU_STAT_HLT = 0;
                 }                  }
Line 258  interrupt(int num, int intrtype, int err Line 257  interrupt(int num, int intrtype, int err
 #if defined(DEBUG)  #if defined(DEBUG)
                 if (num == 0x80) {                  if (num == 0x80) {
                         /* Linux, FreeBSD, NetBSD, OpenBSD system call */                          /* Linux, FreeBSD, NetBSD, OpenBSD system call */
                         VERBOSE(("interrupt: syscall no = %d\n%s", CPU_EAX, cpu_reg2str()));                          VERBOSE(("interrupt: syscall# = %d\n%s", CPU_EAX, cpu_reg2str()));
                 }                  }
 #endif  #endif
   
Line 279  interrupt(int num, int intrtype, int err Line 278  interrupt(int num, int intrtype, int err
                         VERBOSE(("interrupt: gate descripter is invalid."));                          VERBOSE(("interrupt: gate descripter is invalid."));
                         EXCEPTION(GP_EXCEPTION, exc_errcode);                          EXCEPTION(GP_EXCEPTION, exc_errcode);
                 }                  }
                 if (!SEG_IS_PRESENT(&gsd)) {  
                         VERBOSE(("interrupt: gate descriptor is not present."));  
                         EXCEPTION(GP_EXCEPTION, exc_errcode);  
                 }  
                 if (!SEG_IS_SYSTEM(&gsd)) {                  if (!SEG_IS_SYSTEM(&gsd)) {
                         VERBOSE(("interrupt: gate descriptor is not system segment."));                          VERBOSE(("interrupt: gate descriptor is not system segment."));
                         EXCEPTION(GP_EXCEPTION, exc_errcode);                          EXCEPTION(GP_EXCEPTION, exc_errcode);
Line 302  interrupt(int num, int intrtype, int err Line 297  interrupt(int num, int intrtype, int err
                         break;                          break;
                 }                  }
   
                 if (gsd.dpl < CPU_STAT_CPL) {  
                         VERBOSE(("interrupt: gate DPL(%d) < CPL(%d)", gsd.dpl, CPU_STAT_CPL));  
                         EXCEPTION(GP_EXCEPTION, exc_errcode);  
                 }  
   
                 /* 5.10.1.1. 例外/割り込みハンドラ・プロシージャの保護 */                  /* 5.10.1.1. 例外/割り込みハンドラ・プロシージャの保護 */
                 if ((intrtype != INTR_TYPE_EXTINTR) && (gsd.dpl < CPU_STAT_CPL)) {                  if ((intrtype != INTR_TYPE_EXTINTR) && (gsd.dpl < CPU_STAT_CPL)) {
                         VERBOSE(("interrupt: intrtype && DPL(%d) < CPL(%d)", gsd.dpl, CPU_STAT_CPL));                          VERBOSE(("interrupt: intrtype(%d) && DPL(%d) < CPL(%d)", intrtype, gsd.dpl, CPU_STAT_CPL));
                         EXCEPTION(GP_EXCEPTION, exc_errcode);                          EXCEPTION(GP_EXCEPTION, exc_errcode);
                 }                  }
   
                 if (!intrtype && CPU_STAT_HLT) {                  if (!SEG_IS_PRESENT(&gsd)) {
                           VERBOSE(("interrupt: gate descriptor is not present."));
                           EXCEPTION(NP_EXCEPTION, exc_errcode);
                   }
   
                   if ((intrtype == INTR_TYPE_EXTINTR) && CPU_STAT_HLT) {
                           VERBOSE(("interrupt: reset HTL in protected mode"));
                         CPU_EIP++;                          CPU_EIP++;
                         CPU_STAT_HLT = 0;                          CPU_STAT_HLT = 0;
                 }                  }
Line 337  interrupt(int num, int intrtype, int err Line 333  interrupt(int num, int intrtype, int err
   
                 VERBOSE(("interrupt: ---------------------------------------------------------------- end"));                  VERBOSE(("interrupt: ---------------------------------------------------------------- end"));
         }          }
   
           CPU_CLEAR_PREV_ESP();
 }  }
   
 static void  static void
Line 347  interrupt_task_gate(const descriptor_t * Line 345  interrupt_task_gate(const descriptor_t *
   
         VERBOSE(("interrupt: TASK-GATE"));          VERBOSE(("interrupt: TASK-GATE"));
   
         (void)intrtype;  
   
         rv = parse_selector(&task_sel, gsdp->u.gate.selector);          rv = parse_selector(&task_sel, gsdp->u.gate.selector);
         if (rv < 0 || task_sel.ldt || !SEG_IS_SYSTEM(&task_sel.desc)) {          if (rv < 0 || task_sel.ldt || !SEG_IS_SYSTEM(&task_sel.desc)) {
                 VERBOSE(("interrupt: parse_selector (selector = %04x, rv = %d, %cDT, type = %s)", gsdp->u.gate.selector, rv, task_sel.ldt ? 'L' : 'G', task_sel.desc.s ? "code/data" : "system"));                  VERBOSE(("interrupt: parse_selector (selector = %04x, rv = %d, %cDT, type = %s)", gsdp->u.gate.selector, rv, task_sel.ldt ? 'L' : 'G', task_sel.desc.s ? "code/data" : "system"));
Line 379  interrupt_task_gate(const descriptor_t * Line 375  interrupt_task_gate(const descriptor_t *
   
         task_switch(&task_sel, TASK_SWITCH_INTR);          task_switch(&task_sel, TASK_SWITCH_INTR);
   
           CPU_SET_PREV_ESP();
   
         if (errorp) {          if (errorp) {
                 XPUSH0(error_code);                  XPUSH0(error_code);
         }          }
   
           /* out of range */
           if (CPU_EIP > CPU_STAT_CS_LIMIT) {
                   VERBOSE(("interrupt: new_ip is out of range. new_ip = %08x, limit = %08x", CPU_EIP, CPU_STAT_CS_LIMIT));
                   EXCEPTION(GP_EXCEPTION, 0);
           }
 }  }
   
 static void  static void
Line 426  interrupt_intr_or_trap(const descriptor_ Line 430  interrupt_intr_or_trap(const descriptor_
                 break;                  break;
         }          }
   
         exc_errcode = cs_sel.idx;          exc_errcode = gsdp->u.gate.selector & ~3;
         if (intrtype == INTR_TYPE_EXTINTR)          if (intrtype == INTR_TYPE_EXTINTR)
                 exc_errcode++;                  exc_errcode++;
   

Removed from v.1.21  
changed lines
  Added in v.1.28


RetroPC.NET-CVS <cvs@retropc.net>