Diff for /np2/i386c/ia32/cpu_mem.c between versions 1.10 and 1.11

version 1.10, 2004/02/05 16:41:32 version 1.11, 2004/02/20 16:09:04
Line 36 Line 36
  * memory access check   * memory access check
  */   */
 void  void
 cpu_memoryread_check(descriptor_t* sd, DWORD offset, DWORD length, int e)  cpu_memoryread_check(descriptor_t *sd, UINT32 offset, UINT length, int e)
 {  {
         DWORD uplimit;          UINT32 uplimit;
   
         if (CPU_STAT_PM) {          if (CPU_STAT_PM) {
                 /* invalid */                  /* invalid */
Line 52  cpu_memoryread_check(descriptor_t* sd, D Line 52  cpu_memoryread_check(descriptor_t* sd, D
                         VERBOSE(("cpu_memoryread_check: not present"));                          VERBOSE(("cpu_memoryread_check: not present"));
                         EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                 }                  }
           }
   
                 switch (sd->type) {          switch (sd->type) {
                 case 0:  case 1:        /* ro */          case 0:  case 1:        /* ro */
                 case 2:  case 3:        /* rw */          case 2:  case 3:        /* rw */
                 case 10: case 11:       /* rx */          case 10: case 11:       /* rx */
                 case 14: case 15:       /* rxc */          case 14: case 15:       /* rxc */
                         if (offset > sd->u.seg.limit - length + 1) {                  if (offset > sd->u.seg.limit - length + 1) {
                                 VERBOSE(("cpu_memoryread_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length));                          VERBOSE(("cpu_memoryread_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length));
                                 EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         }                  }
                         if (length - 1 > sd->u.seg.limit) {                  if (length - 1 > sd->u.seg.limit) {
                                 VERBOSE(("cpu_memoryread_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit));                          VERBOSE(("cpu_memoryread_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit));
                                 EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         }                  }
                         break;                  break;
   
                 case 4:  case 5:        /* ro (expand down) */  
                 case 6:  case 7:        /* rw (expand down) */  
                         uplimit = sd->d ? 0xffffffff : 0x0000ffff;  
                         if (offset <= sd->u.seg.limit) {  
                                 VERBOSE(("cpu_memoryread_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit));  
                                 EXCEPTION(e, 0);  
                         }  
                         if (offset > uplimit) {  
                                 VERBOSE(("cpu_memoryread_check: offset(%08x) > uplimit(%08x)", offset, uplimit));  
                                 EXCEPTION(e, 0);  
                         }  
                         if (uplimit - offset < length - 1) {  
                                 VERBOSE(("cpu_memoryread_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length));  
                                 EXCEPTION(e, 0);  
                         }  
                         break;  
   
                 default:          case 4:  case 5:        /* ro (expand down) */
                         VERBOSE(("cpu_memoryread_check: invalid type (type = %d)", sd->type));          case 6:  case 7:        /* rw (expand down) */
                   uplimit = sd->d ? 0xffffffff : 0x0000ffff;
                   if (offset <= sd->u.seg.limit) {
                           VERBOSE(("cpu_memoryread_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit));
                           EXCEPTION(e, 0);
                   }
                   if (offset > uplimit) {
                           VERBOSE(("cpu_memoryread_check: offset(%08x) > uplimit(%08x)", offset, uplimit));
                         EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         break;  
                 }                  }
                   if (uplimit - offset < length - 1) {
                           VERBOSE(("cpu_memoryread_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length));
                           EXCEPTION(e, 0);
                   }
                   break;
   
           default:
                   VERBOSE(("cpu_memoryread_check: invalid type (type = %d)", sd->type));
                   EXCEPTION(e, 0);
                   break;
         }          }
         sd->flag |= CPU_DESC_FLAG_READABLE;          sd->flag |= CPU_DESC_FLAG_READABLE;
 }  }
   
 void  void
 cpu_memorywrite_check(descriptor_t* sd, DWORD offset, DWORD length, int e)  cpu_memorywrite_check(descriptor_t *sd, UINT32 offset, UINT length, int e)
 {  {
         DWORD uplimit;          UINT32 uplimit;
   
         if (CPU_STAT_PM) {          if (CPU_STAT_PM) {
                 /* invalid */                  /* invalid */
Line 116  cpu_memorywrite_check(descriptor_t* sd,  Line 116  cpu_memorywrite_check(descriptor_t* sd, 
                         VERBOSE(("cpu_memorywrite_check: system segment"));                          VERBOSE(("cpu_memorywrite_check: system segment"));
                         EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                 }                  }
           }
   
                 switch (sd->type) {          switch (sd->type) {
                 case 2: case 3: /* rw */          case 2: case 3: /* rw */
                         if (offset > sd->u.seg.limit - length + 1) {                  if (offset > sd->u.seg.limit - length + 1) {
                                 VERBOSE(("cpu_memorywrite_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length));                          VERBOSE(("cpu_memorywrite_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length));
                                 EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         }                  }
                         if (length - 1 > sd->u.seg.limit) {                  if (length - 1 > sd->u.seg.limit) {
                                 VERBOSE(("cpu_memorywrite_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit));                          VERBOSE(("cpu_memorywrite_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit));
                                 EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         }                  }
                         break;                  break;
   
                 case 6: case 7: /* rw (expand down) */  
                         uplimit = sd->d ? 0xffffffff : 0x0000ffff;  
                         if (offset <= sd->u.seg.limit) {  
                                 VERBOSE(("cpu_memorywrite_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit));  
                                 EXCEPTION(e, 0);  
                         }  
                         if (offset > uplimit) {  
                                 VERBOSE(("cpu_memorywrite_check: offset(%08x) > uplimit(%08x)", offset, uplimit));  
                                 EXCEPTION(e, 0);  
                         }  
                         if (uplimit - offset < length - 1) {  
                                 VERBOSE(("cpu_memorywrite_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length));  
                                 EXCEPTION(e, 0);  
                         }  
                         break;  
   
                 default:          case 6: case 7: /* rw (expand down) */
                         VERBOSE(("cpu_memorywrite_check: invalid type (type = %d)", sd->type));                  uplimit = sd->d ? 0xffffffff : 0x0000ffff;
                   if (offset <= sd->u.seg.limit) {
                           VERBOSE(("cpu_memorywrite_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit));
                           EXCEPTION(e, 0);
                   }
                   if (offset > uplimit) {
                           VERBOSE(("cpu_memorywrite_check: offset(%08x) > uplimit(%08x)", offset, uplimit));
                         EXCEPTION(e, 0);                          EXCEPTION(e, 0);
                         break;  
                 }                  }
                   if (uplimit - offset < length - 1) {
                           VERBOSE(("cpu_memorywrite_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length));
                           EXCEPTION(e, 0);
                   }
                   break;
   
           default:
                   VERBOSE(("cpu_memorywrite_check: invalid type (type = %d)", sd->type));
                   EXCEPTION(e, 0);
                   break;
         }          }
         sd->flag |= CPU_DESC_FLAG_WRITABLE;          sd->flag |= CPU_DESC_FLAG_WRITABLE;
 }  }
   
 BOOL  BOOL
 cpu_stack_push_check(descriptor_t* sdp, DWORD esp, DWORD length)  cpu_stack_push_check(descriptor_t *sd, UINT32 esp, UINT length)
 {  {
         DWORD limit;          UINT32 limit;
   
         if (!CPU_STAT_PM)          if (CPU_STAT_PM) {
                 return TRUE;                  if (!sd->valid || !sd->p)
   
         if (!sdp->valid || !sdp->p)  
                 return FALSE;  
         if (!sdp->s || sdp->u.seg.c || !sdp->u.seg.wr)  
                 return FALSE;  
   
         if (!sdp->d) {  
                 esp &= 0xffff;  
                 limit = 0xffff;  
         } else {  
                 limit = 0xffffffff;  
         }  
         if (sdp->u.seg.ec) {  
                 /* expand-down stack */  
                 if ((esp == 0)  
                  || (esp < length)  
                  || (esp - length <= sdp->u.seg.limit)  
                  || (esp > limit))  
                         return FALSE;                          return FALSE;
         } else {                  if (!sd->s || sd->u.seg.c || !sd->u.seg.wr)
                 /* expand-up stack */                          return FALSE;
                 if (esp == 0) {  
                         if ((sdp->d && (sdp->u.seg.segend != 0xffffffff))                  if (!sd->d) {
                          || (!sdp->d && (sdp->u.seg.segend != 0xffff)))                          esp &= 0xffff;
                                 return FALSE;                          limit = 0xffff;
                 } else {                  } else {
                         if ((esp < length)                          limit = 0xffffffff;
                          || (esp - 1 > sdp->u.seg.limit))                  }
                   if (sd->u.seg.ec) {
                           /* expand-down stack */
                           if ((esp == 0)
                            || (esp < length)
                            || (esp - length <= sd->u.seg.limit)
                            || (esp > limit))
                                 return FALSE;                                  return FALSE;
                   } else {
                           /* expand-up stack */
                           if (esp == 0) {
                                   if ((sd->d && (sd->u.seg.segend != 0xffffffff))
                                    || (!sd->d && (sd->u.seg.segend != 0xffff)))
                                           return FALSE;
                           } else {
                                   if ((esp < length)
                                    || (esp - 1 > sd->u.seg.limit))
                                           return FALSE;
                           }
                 }                  }
         }          }
         return TRUE;          return TRUE;
 }  }
   
 BOOL  BOOL
 cpu_stack_pop_check(descriptor_t* sdp, DWORD esp, DWORD length)  cpu_stack_pop_check(descriptor_t *sd, UINT32 esp, UINT length)
 {  {
         DWORD limit;          UINT32 limit;
   
         if (!CPU_STAT_PM)  
                 return TRUE;  
   
         if (!sdp->valid || !sdp->p)          if (CPU_STAT_PM) {
                 return FALSE;                  if (!sd->valid || !sd->p)
         if (!sdp->s || sdp->u.seg.c || !sdp->u.seg.wr)  
                 return FALSE;  
   
         if (!sdp->d) {  
                 esp &= 0xffff;  
                 limit = 0xffff;  
         } else {  
                 limit = 0xffffffff;  
         }  
         if (sdp->u.seg.ec) {  
                 /* expand-down stack */  
                 if ((esp == limit)  
                  || ((limit - esp) + 1 < length))  
                         return FALSE;                          return FALSE;
         } else {                  if (!sd->s || sd->u.seg.c || !sd->u.seg.wr)
                 /* expand-up stack */  
                 if ((esp == limit)  
                  || (sdp->u.seg.segend == 0)  
                  || (esp > sdp->u.seg.limit)  
                  || ((sdp->u.seg.limit - esp) + 1 < length))  
                         return FALSE;                          return FALSE;
   
                   if (!sd->d) {
                           esp &= 0xffff;
                           limit = 0xffff;
                   } else {
                           limit = 0xffffffff;
                   }
                   if (sd->u.seg.ec) {
                           /* expand-down stack */
                           if ((esp == limit)
                            || ((limit - esp) + 1 < length))
                                   return FALSE;
                   } else {
                           /* expand-up stack */
                           if ((esp == limit)
                            || (sd->u.seg.segend == 0)
                            || (esp > sd->u.seg.limit)
                            || ((sd->u.seg.limit - esp) + 1 < length))
                                   return FALSE;
                   }
         }          }
         return TRUE;          return TRUE;
 }  }
Line 234  cpu_stack_pop_check(descriptor_t* sdp, D Line 232  cpu_stack_pop_check(descriptor_t* sdp, D
 /*  /*
  * code fetch   * code fetch
  */   */
 BYTE MEMCALL  UINT8 MEMCALL
 cpu_codefetch(DWORD offset)  cpu_codefetch(UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
   
         sd = &CPU_STAT_SREG(CPU_CS_INDEX);          sd = &CPU_STAT_SREG(CPU_CS_INDEX);
         if (offset <= sd->u.seg.limit) {          if (offset <= sd->u.seg.limit) {
Line 251  cpu_codefetch(DWORD offset) Line 249  cpu_codefetch(DWORD offset)
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
   
 WORD MEMCALL  UINT16 MEMCALL
 cpu_codefetch_w(DWORD offset)  cpu_codefetch_w(UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
   
         sd = &CPU_STAT_SREG(CPU_CS_INDEX);          sd = &CPU_STAT_SREG(CPU_CS_INDEX);
         if (offset <= sd->u.seg.limit - 1) {          if (offset <= sd->u.seg.limit - 1) {
Line 268  cpu_codefetch_w(DWORD offset) Line 266  cpu_codefetch_w(DWORD offset)
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
   
 DWORD MEMCALL  UINT32 MEMCALL
 cpu_codefetch_d(DWORD offset)  cpu_codefetch_d(UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
   
         sd = &CPU_STAT_SREG(CPU_CS_INDEX);          sd = &CPU_STAT_SREG(CPU_CS_INDEX);
         if (offset <= sd->u.seg.limit - 3) {          if (offset <= sd->u.seg.limit - 3) {
Line 289  cpu_codefetch_d(DWORD offset) Line 287  cpu_codefetch_d(DWORD offset)
 /*  /*
  * virtual address -> linear address   * virtual address -> linear address
  */   */
 BYTE MEMCALL  UINT8 MEMCALL
 cpu_vmemoryread(int idx, DWORD offset)  cpu_vmemoryread(int idx, UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
Line 340  err: Line 338  err:
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
   
 WORD MEMCALL  UINT16 MEMCALL
 cpu_vmemoryread_w(int idx, DWORD offset)  cpu_vmemoryread_w(int idx, UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
Line 391  err: Line 389  err:
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
   
 DWORD MEMCALL  UINT32 MEMCALL
 cpu_vmemoryread_d(int idx, DWORD offset)  cpu_vmemoryread_d(int idx, UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
Line 444  err: Line 442  err:
   
 /* vaddr memory write */  /* vaddr memory write */
 void MEMCALL  void MEMCALL
 cpu_vmemorywrite(int idx, DWORD offset, BYTE val)  cpu_vmemorywrite(int idx, UINT32 offset, UINT8 val)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
Line 499  err: Line 497  err:
 }  }
   
 void MEMCALL  void MEMCALL
 cpu_vmemorywrite_w(int idx, DWORD offset, WORD val)  cpu_vmemorywrite_w(int idx, UINT32 offset, UINT16 val)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
Line 554  err: Line 552  err:
 }  }
   
 void MEMCALL  void MEMCALL
 cpu_vmemorywrite_d(int idx, DWORD offset, DWORD val)  cpu_vmemorywrite_d(int idx, UINT32 offset, UINT32 val)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         DWORD addr;          UINT32 addr;
         int exc;          int exc;
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);

Removed from v.1.10  
changed lines
  Added in v.1.11


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