Diff for /np2/i386c/ia32/cpu_mem.c between versions 1.13 and 1.14

version 1.13, 2004/03/08 12:56:22 version 1.14, 2004/03/12 13:34:08
Line 154  cpu_memorywrite_check(descriptor_t *sd,  Line 154  cpu_memorywrite_check(descriptor_t *sd, 
         sd->flag |= CPU_DESC_FLAG_WRITABLE;          sd->flag |= CPU_DESC_FLAG_WRITABLE;
 }  }
   
 BOOL  void
 cpu_stack_push_check(descriptor_t *sd, UINT32 esp, UINT length)  cpu_stack_push_check(UINT16 s, descriptor_t *sd, UINT32 esp, UINT length)
 {  {
         UINT32 limit;          UINT32 limit;
   
         if (CPU_STAT_PM) {          if (CPU_STAT_PM) {
                 if (!sd->valid || !sd->p)                  if (!sd->valid || !sd->p) {
                         return FALSE;                          VERBOSE(("cpu_stack_push_check: valid = %d, present = %d", sd->valid, sd->p));
                 if (!sd->s || sd->u.seg.c || !sd->u.seg.wr)                          EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                         return FALSE;                  }
                   if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) {
                           VERBOSE(("cpu_stack_push_check: s = %d, c = %d, wr", sd->s, sd->u.seg.c, sd->u.seg.wr));
                           EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                   }
   
                 if (!sd->d) {                  if (!sd->d) {
                         esp &= 0xffff;  
                         limit = 0xffff;                          limit = 0xffff;
                 } else {                  } else {
                         limit = 0xffffffff;                          limit = 0xffffffff;
Line 176  cpu_stack_push_check(descriptor_t *sd, U Line 179  cpu_stack_push_check(descriptor_t *sd, U
                         if ((esp == 0)                          if ((esp == 0)
                          || (esp < length)                           || (esp < length)
                          || (esp - length <= sd->u.seg.limit)                           || (esp - length <= sd->u.seg.limit)
                          || (esp > limit))                           || (esp > limit)) {
                                 return FALSE;                                  VERBOSE(("cpu_stack_push_check: expand-down, esp = %08x, length = %08x", esp, length));
                                   VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit));
                                   VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend));
                                   EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                           }
                 } else {                  } else {
                         /* expand-up stack */                          /* expand-up stack */
                         if (esp == 0) {                          if (esp == 0) {
                                 if ((sd->d && (sd->u.seg.segend != 0xffffffff))                                  if ((sd->d && (sd->u.seg.segend != 0xffffffff))
                                  || (!sd->d && (sd->u.seg.segend != 0xffff)))                                   || (!sd->d && (sd->u.seg.segend != 0xffff))) {
                                         return FALSE;                                          VERBOSE(("cpu_stack_push_check: expand-up, esp = %08x, length = %08x", esp, length));
                                           VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit));
                                           VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend));
                                           EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                                   }
                         } else {                          } else {
                                 if ((esp < length)                                  if ((esp < length)
                                  || (esp - 1 > sd->u.seg.limit))                                   || (esp - 1 > sd->u.seg.limit)) {
                                         return FALSE;                                          VERBOSE(("cpu_stack_push_check: expand-up, esp = %08x, length = %08x", esp, length));
                                           VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit));
                                           VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend));
                                           EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                                   }
                         }                          }
                 }                  }
         }          }
         return TRUE;  
 }  }
   
 BOOL  void
 cpu_stack_pop_check(descriptor_t *sd, UINT32 esp, UINT length)  cpu_stack_pop_check(UINT16 s, descriptor_t *sd, UINT32 esp, UINT length)
 {  {
         UINT32 limit;          UINT32 limit;
   
         if (CPU_STAT_PM) {          if (CPU_STAT_PM) {
                 if (!sd->valid || !sd->p)                  if (!sd->valid || !sd->p) {
                         return FALSE;                          VERBOSE(("cpu_stack_pop_check: valid = %d, present = %d", sd->valid, sd->p));
                 if (!sd->s || sd->u.seg.c || !sd->u.seg.wr)                          EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                         return FALSE;                  }
                   if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) {
                           VERBOSE(("cpu_stack_pop_check: s = %d, c = %d, wr", sd->s, sd->u.seg.c, sd->u.seg.wr));
                           EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                   }
   
                 if (!sd->d) {                  if (!sd->d) {
                         esp &= 0xffff;  
                         limit = 0xffff;                          limit = 0xffff;
                 } else {                  } else {
                         limit = 0xffffffff;                          limit = 0xffffffff;
Line 214  cpu_stack_pop_check(descriptor_t *sd, UI Line 231  cpu_stack_pop_check(descriptor_t *sd, UI
                 if (sd->u.seg.ec) {                  if (sd->u.seg.ec) {
                         /* expand-down stack */                          /* expand-down stack */
                         if ((esp == limit)                          if ((esp == limit)
                          || ((limit - esp) + 1 < length))                           || ((limit - esp) + 1 < length)) {
                                 return FALSE;                                  VERBOSE(("cpu_stack_pop_check: expand-up, esp = %08x, length = %08x", esp, length));
                                   VERBOSE(("cpu_stack_pop_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit));
                                   VERBOSE(("cpu_stack_pop_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend));
                                   EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                           }
                 } else {                  } else {
                         /* expand-up stack */                          /* expand-up stack */
                         if ((esp == limit)                          if ((esp == limit)
                          || (sd->u.seg.segend == 0)                           || (sd->u.seg.segend == 0)
                          || (esp > sd->u.seg.limit)                           || (esp > sd->u.seg.limit)
                          || ((sd->u.seg.limit - esp) + 1 < length))                           || ((sd->u.seg.limit - esp) + 1 < length)) {
                                 return FALSE;                                  VERBOSE(("cpu_stack_pop_check: expand-up, esp = %08x, length = %08x", esp, length));
                                   VERBOSE(("cpu_stack_pop_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit));
                                   VERBOSE(("cpu_stack_pop_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend));
                                   EXCEPTION(SS_EXCEPTION, s & 0xfffc);
                           }
                 }                  }
         }          }
         return TRUE;  
 }  }
   
   
Line 455  cpu_vmemoryread(int idx, UINT32 offset) Line 479  cpu_vmemoryread(int idx, UINT32 offset)
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 4: case 5: case 6: case 7:                  case 4: case 5: case 6: case 7:
                         if (offset <= sd->u.seg.limit) {                          if (offset <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit) {                          if (offset > sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }          }
Line 481  cpu_vmemoryread(int idx, UINT32 offset) Line 495  cpu_vmemoryread(int idx, UINT32 offset)
                 return cpu_memoryread(addr);                  return cpu_memoryread(addr);
         return cpu_lmemoryread(addr, CPU_STAT_USER_MODE);          return cpu_lmemoryread(addr, CPU_STAT_USER_MODE);
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemoryread: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
Line 507  cpu_vmemoryread_w(int idx, UINT32 offset Line 528  cpu_vmemoryread_w(int idx, UINT32 offset
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 4: case 5: case 6: case 7:                  case 4: case 5: case 6: case 7:
                         if (offset - 1 <= sd->u.seg.limit) {                          if (offset - 1 <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit - 1) {                          if (offset > sd->u.seg.limit - 1)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }           } 
Line 533  cpu_vmemoryread_w(int idx, UINT32 offset Line 544  cpu_vmemoryread_w(int idx, UINT32 offset
                 return cpu_memoryread_w(addr);                  return cpu_memoryread_w(addr);
         return cpu_lmemoryread_w(addr, CPU_STAT_USER_MODE);          return cpu_lmemoryread_w(addr, CPU_STAT_USER_MODE);
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemoryread_w: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
Line 559  cpu_vmemoryread_d(int idx, UINT32 offset Line 577  cpu_vmemoryread_d(int idx, UINT32 offset
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 4: case 5: case 6: case 7:                  case 4: case 5: case 6: case 7:
                         if (offset - 3 <= sd->u.seg.limit) {                          if (offset - 3 <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit - 3) {                          if (offset > sd->u.seg.limit - 3)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }          }
Line 585  cpu_vmemoryread_d(int idx, UINT32 offset Line 593  cpu_vmemoryread_d(int idx, UINT32 offset
                 return cpu_memoryread_d(addr);                  return cpu_memoryread_d(addr);
         return cpu_lmemoryread_d(addr, CPU_STAT_USER_MODE);          return cpu_lmemoryread_d(addr, CPU_STAT_USER_MODE);
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemoryread_d: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
Line 612  cpu_vmemorywrite(int idx, UINT32 offset, Line 627  cpu_vmemorywrite(int idx, UINT32 offset,
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 6: case 7:                  case 6: case 7:
                         if (offset <= sd->u.seg.limit) {                          if (offset <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit) {                          if (offset > sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }          }
Line 643  cpu_vmemorywrite(int idx, UINT32 offset, Line 648  cpu_vmemorywrite(int idx, UINT32 offset,
         }          }
         return;          return;
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemorywrite: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
 }  }
Line 668  cpu_vmemorywrite_w(int idx, UINT32 offse Line 680  cpu_vmemorywrite_w(int idx, UINT32 offse
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 6: case 7:                  case 6: case 7:
                         if (offset - 1 <= sd->u.seg.limit) {                          if (offset - 1 <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit - 1) {                          if (offset > sd->u.seg.limit - 1)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }          }
Line 699  cpu_vmemorywrite_w(int idx, UINT32 offse Line 701  cpu_vmemorywrite_w(int idx, UINT32 offse
         }          }
         return;          return;
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemorywrite_w: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
 }  }
Line 724  cpu_vmemorywrite_d(int idx, UINT32 offse Line 733  cpu_vmemorywrite_d(int idx, UINT32 offse
         } else {          } else {
                 switch (sd->type) {                  switch (sd->type) {
                 case 6: case 7:                  case 6: case 7:
                         if (offset - 3 <= sd->u.seg.limit) {                          if (offset - 3 <= sd->u.seg.limit)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
   
                 default:                  default:
                         if (offset > sd->u.seg.limit - 3) {                          if (offset > sd->u.seg.limit - 3)
                                 if (idx == CPU_SS_INDEX)                                  goto range_failure;
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;                          break;
                 }                  }
         }          }
Line 755  cpu_vmemorywrite_d(int idx, UINT32 offse Line 754  cpu_vmemorywrite_d(int idx, UINT32 offse
         }          }
         return;          return;
   
   range_failure:
           if (idx == CPU_SS_INDEX) {
                   exc = SS_EXCEPTION;
           } else {
                   exc = GP_EXCEPTION;
           }
           VERBOSE(("cpu_vmemorywrite_d: type = %d, offset = %08x, limit = %08x", sd->type, offset, sd->u.seg.limit));
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
 }  }

Removed from v.1.13  
changed lines
  Added in v.1.14


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