Diff for /np2/i386c/ia32/cpu_mem.c between versions 1.30 and 1.31

version 1.30, 2012/01/08 11:36:47 version 1.31, 2012/01/08 18:26:10
Line 334  cpu_stack_push_check(UINT16 s, descripto Line 334  cpu_stack_push_check(UINT16 s, descripto
         return;          return;
   
 exc:  exc:
         VERBOSE(("cpu_stack_push_check: check failure: selector = %04x, sp = 0x%08x, len = %d", s, sp, len));          VERBOSE(("cpu_stack_push_check: check failure: selector = 0x%04x, sp = 0x%08x, len = %d", s, sp, len));
 #if defined(DEBUG)  #if defined(DEBUG)
         segdesc_dump(sdp);          segdesc_dump(sdp);
 #endif  #endif
Line 361  cpu_stack_pop_check(UINT16 s, descriptor Line 361  cpu_stack_pop_check(UINT16 s, descriptor
         return;          return;
   
 exc:  exc:
         VERBOSE(("cpu_stack_pop_check: check failure: selector = %04x, sp = 0x%08x, len = %d", s, sp, len));          VERBOSE(("cpu_stack_pop_check: check failure: selector = 0x%04x, sp = 0x%08x, len = %d", s, sp, len));
 #if defined(DEBUG)  #if defined(DEBUG)
         segdesc_dump(sdp);          segdesc_dump(sdp);
 #endif  #endif
Line 372  exc: Line 372  exc:
 /*  /*
  * code fetch   * code fetch
  */   */
 #define ucrw    (CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE)  
   
 UINT8 MEMCALL  UINT8 MEMCALL
 cpu_codefetch(UINT32 offset)  cpu_codefetch(UINT32 offset)
 {  {
           const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
         descriptor_t *sdp;          descriptor_t *sdp;
         UINT32 addr;          UINT32 addr;
         TLB_ENTRY_T *ep;  
   
         sdp = &CPU_CS_DESC;          sdp = &CPU_CS_DESC;
         if (offset <= sdp->u.seg.limit) {          addr = sdp->u.seg.segbase + offset;
                 addr = sdp->u.seg.segbase + offset;  
                 if (!CPU_STAT_PAGING)          if (!CPU_STAT_PM)
                         return cpu_memoryread(addr);                  return cpu_memoryread(addr);
                 ep = tlb_lookup(addr, ucrw);          if (offset <= sdp->u.seg.limit)
                 if (ep != NULL && ep->memp != NULL) {                  return cpu_lmemoryread(addr, ucrw);
                         return ep->memp[addr & 0xfff];  
                 }  
                 return cpu_linear_memory_read_b(addr, ucrw);  
         }  
         EXCEPTION(GP_EXCEPTION, 0);          EXCEPTION(GP_EXCEPTION, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
Line 399  cpu_codefetch(UINT32 offset) Line 394  cpu_codefetch(UINT32 offset)
 UINT16 MEMCALL  UINT16 MEMCALL
 cpu_codefetch_w(UINT32 offset)  cpu_codefetch_w(UINT32 offset)
 {  {
           const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
         descriptor_t *sdp;          descriptor_t *sdp;
         UINT32 addr;          UINT32 addr;
         TLB_ENTRY_T *ep;  
         UINT16 value;  
   
         sdp = &CPU_CS_DESC;          sdp = &CPU_CS_DESC;
         if (offset <= sdp->u.seg.limit - 1) {          addr = sdp->u.seg.segbase + offset;
                 addr = sdp->u.seg.segbase + offset;  
                 if (!CPU_STAT_PAGING)          if (!CPU_STAT_PM)
                         return cpu_memoryread_w(addr);                  return cpu_memoryread_w(addr);
                 ep = tlb_lookup(addr, ucrw);          if (offset <= sdp->u.seg.limit - 1)
                 if (ep != NULL && ep->memp != NULL) {                  return cpu_lmemoryread_w(addr, ucrw);
                         if ((addr + 1) & 0x00000fff) {  
                                 return LOADINTELWORD(ep->memp + (addr & 0xfff));  
                         }  
                         value = ep->memp[0xfff];  
                         ep = tlb_lookup(addr + 1, ucrw);  
                         if (ep != NULL && ep->memp != NULL) {  
                                 value += (UINT16)ep->memp[0] << 8;  
                                 return value;  
                         }  
                 }  
                 return cpu_linear_memory_read_w(addr, ucrw);  
         }  
         EXCEPTION(GP_EXCEPTION, 0);          EXCEPTION(GP_EXCEPTION, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
Line 430  cpu_codefetch_w(UINT32 offset) Line 413  cpu_codefetch_w(UINT32 offset)
 UINT32 MEMCALL  UINT32 MEMCALL
 cpu_codefetch_d(UINT32 offset)  cpu_codefetch_d(UINT32 offset)
 {  {
           const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
         descriptor_t *sdp;          descriptor_t *sdp;
         UINT32 addr;          UINT32 addr;
         TLB_ENTRY_T *ep[2];  
         UINT32 value;  
         UINT remain;  
   
         sdp = &CPU_CS_DESC;          sdp = &CPU_CS_DESC;
         if (offset <= sdp->u.seg.limit - 3) {          addr = sdp->u.seg.segbase + offset;
                 addr = sdp->u.seg.segbase + offset;  
                 if (!CPU_STAT_PAGING)          if (!CPU_STAT_PM)
                         return cpu_memoryread_d(addr);                  return cpu_memoryread_d(addr);
                 ep[0] = tlb_lookup(addr, ucrw);  
                 if (ep[0] != NULL && ep[0]->memp != NULL) {          if (offset <= sdp->u.seg.limit - 3)
                         remain = 0x1000 - (addr & 0xfff);                  return cpu_lmemoryread_d(addr, ucrw);
                         if (remain >= 4) {  
                                 return LOADINTELDWORD(ep[0]->memp + (addr & 0xfff));  
                         }  
                         ep[1] = tlb_lookup(addr + remain, ucrw);  
                         if (ep[1] != NULL && ep[1]->memp != NULL) {  
                                 switch (remain) {  
                                 case 3:  
                                         value = ep[0]->memp[0xffd];  
                                         value += (UINT32)LOADINTELWORD(ep[0]->memp + 0xffe) << 8;  
                                         value += (UINT32)ep[1]->memp[0] << 24;  
                                         break;  
   
                                 case 2:  
                                         value = LOADINTELWORD(ep[0]->memp + 0xffe);  
                                         value += (UINT32)LOADINTELWORD(ep[1]->memp + 0) << 16;  
                                         break;  
   
                                 case 1:  
                                         value = ep[0]->memp[0xfff];  
                                         value += (UINT32)LOADINTELWORD(ep[1]->memp + 0) << 8;  
                                         value += (UINT32)ep[1]->memp[2] << 24;  
                                         break;  
   
                                 default:  
                                         ia32_panic("cpu_codefetch_d(): out of range. (remain = %d)\n", remain);  
                                         return (UINT32)-1;  
                                 }  
                                 return value;  
                         }  
                 }  
                 return cpu_linear_memory_read_d(addr, ucrw);  
         }  
         EXCEPTION(GP_EXCEPTION, 0);          EXCEPTION(GP_EXCEPTION, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
 }  }
   
 #undef  ucrw  
   
 /*  /*
  * additional physical address memory access functions   * additional physical address memory access functions
  */   */
Line 529  cpu_memorywrite_f(UINT32 paddr, const RE Line 477  cpu_memorywrite_f(UINT32 paddr, const RE
 /*  /*
  * virtual address memory access functions   * virtual address memory access functions
  */   */
   #define CHOOSE_EXCEPTION(sreg) \
           (((sreg) == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION)
   
 #include "cpu_mem.mcr"  #include "cpu_mem.mcr"
   
 VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(b, UINT8, 1)  VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(b, UINT8, 1)
Line 545  cpu_vmemoryread_q(int idx, UINT32 offset Line 496  cpu_vmemoryread_q(int idx, UINT32 offset
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
   
         sdp = &CPU_STAT_SREG(idx);          sdp = &CPU_STAT_SREG(idx);
           addr = sdp->u.seg.segbase + offset;
   
           if (!CPU_STAT_PM)
                   return cpu_memoryread_q(addr);
   
         if (!SEG_IS_VALID(sdp)) {          if (!SEG_IS_VALID(sdp)) {
                 exc = GP_EXCEPTION;                  exc = GP_EXCEPTION;
                 goto err;                  goto err;
         }          }
   
         if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) {          if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) {
                 cpu_memoryread_check(sdp, offset, 8,                  cpu_memoryread_check(sdp, offset, 8, CHOOSE_EXCEPTION(idx));
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {          } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {
                 if (!check_limit_upstairs(sdp, offset, 8))                  if (!check_limit_upstairs(sdp, offset, 8))
                         goto range_failure;                          goto range_failure;
         }           } 
         addr = sdp->u.seg.segbase + offset;          return cpu_lmemoryread_q(addr, CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE);
         if (!CPU_STAT_PAGING)  
                 return cpu_memoryread_q(addr);  
         return cpu_linear_memory_read_q(addr, CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE);  
   
 range_failure:  range_failure:
         VERBOSE(("cpu_vmemoryread_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));          VERBOSE(("cpu_vmemoryread_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));
         exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION;          exc = CHOOSE_EXCEPTION(idx);
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
Line 580  cpu_vmemorywrite_q(int idx, UINT32 offse Line 531  cpu_vmemorywrite_q(int idx, UINT32 offse
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
   
         sdp = &CPU_STAT_SREG(idx);          sdp = &CPU_STAT_SREG(idx);
           addr = sdp->u.seg.segbase + offset;
   
           if (!CPU_STAT_PM) {
                   cpu_memorywrite_q(addr, value);
                   return;
           }
   
         if (!SEG_IS_VALID(sdp)) {          if (!SEG_IS_VALID(sdp)) {
                 exc = GP_EXCEPTION;                  exc = GP_EXCEPTION;
                 goto err;                  goto err;
         }          }
   
         if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) {          if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) {
                 cpu_memorywrite_check(sdp, offset, 8,                  cpu_memorywrite_check(sdp, offset, 8, CHOOSE_EXCEPTION(idx));
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {          } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {
                 if (!check_limit_upstairs(sdp, offset, 8))                  if (!check_limit_upstairs(sdp, offset, 8))
                         goto range_failure;                          goto range_failure;
         }          }
         addr = sdp->u.seg.segbase + offset;  
         if (!CPU_STAT_PAGING) {          if (!CPU_STAT_PAGING) {
                 cpu_memorywrite_q(addr, value);                  cpu_memorywrite_q(addr, value);
         } else {          } else {
Line 602  cpu_vmemorywrite_q(int idx, UINT32 offse Line 557  cpu_vmemorywrite_q(int idx, UINT32 offse
   
 range_failure:  range_failure:
         VERBOSE(("cpu_vmemorywrite_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));          VERBOSE(("cpu_vmemorywrite_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));
         exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION;          exc = CHOOSE_EXCEPTION(idx);
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
 }  }
Line 617  cpu_vmemoryread_f(int idx, UINT32 offset Line 572  cpu_vmemoryread_f(int idx, UINT32 offset
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
   
         sdp = &CPU_STAT_SREG(idx);          sdp = &CPU_STAT_SREG(idx);
           addr = sdp->u.seg.segbase + offset;
   
           if (!CPU_STAT_PM)
                   return cpu_memoryread_f(addr);
   
         if (!SEG_IS_VALID(sdp)) {          if (!SEG_IS_VALID(sdp)) {
                 exc = GP_EXCEPTION;                  exc = GP_EXCEPTION;
                 goto err;                  goto err;
         }          }
   
         if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) {          if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) {
                 cpu_memoryread_check(sdp, offset, 10,                  cpu_memoryread_check(sdp, offset, 10, CHOOSE_EXCEPTION(idx));
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {          } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {
                 if (!check_limit_upstairs(sdp, offset, 10))                  if (!check_limit_upstairs(sdp, offset, 10))
                         goto range_failure;                          goto range_failure;
         }           } 
         addr = sdp->u.seg.segbase + offset;  
         if (!CPU_STAT_PAGING)          if (!CPU_STAT_PAGING)
                 return cpu_memoryread_f(addr);                  return cpu_memoryread_f(addr);
         return cpu_linear_memory_read_f(addr, CPU_PAGE_READ_DATA | CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE);          return cpu_linear_memory_read_f(addr, CPU_PAGE_READ_DATA | CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE);
   
 range_failure:  range_failure:
         VERBOSE(("cpu_vmemoryread_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));          VERBOSE(("cpu_vmemoryread_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));
         exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION;          exc = CHOOSE_EXCEPTION(idx);
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
         {          {
Line 656  cpu_vmemorywrite_f(int idx, UINT32 offse Line 613  cpu_vmemorywrite_f(int idx, UINT32 offse
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);          __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);
   
         sdp = &CPU_STAT_SREG(idx);          sdp = &CPU_STAT_SREG(idx);
           addr = sdp->u.seg.segbase + offset;
   
           if (!CPU_STAT_PM) {
                   cpu_memorywrite_f(addr, value);
                   return;
           }
   
         if (!SEG_IS_VALID(sdp)) {          if (!SEG_IS_VALID(sdp)) {
                 exc = GP_EXCEPTION;                  exc = GP_EXCEPTION;
                 goto err;                  goto err;
         }          }
   
         if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) {          if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) {
                 cpu_memorywrite_check(sdp, offset, 10,                  cpu_memorywrite_check(sdp, offset, 10, CHOOSE_EXCEPTION(idx));
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {          } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) {
                 if (!check_limit_upstairs(sdp, offset, 10))                  if (!check_limit_upstairs(sdp, offset, 10))
                         goto range_failure;                          goto range_failure;
         }          }
         addr = sdp->u.seg.segbase + offset;  
         if (!CPU_STAT_PAGING) {          if (!CPU_STAT_PAGING) {
                 cpu_memorywrite_f(addr, value);                  cpu_memorywrite_f(addr, value);
         } else {          } else {
Line 678  cpu_vmemorywrite_f(int idx, UINT32 offse Line 639  cpu_vmemorywrite_f(int idx, UINT32 offse
   
 range_failure:  range_failure:
         VERBOSE(("cpu_vmemorywrite_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));          VERBOSE(("cpu_vmemorywrite_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit));
         exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION;          exc = CHOOSE_EXCEPTION(idx);
 err:  err:
         EXCEPTION(exc, 0);          EXCEPTION(exc, 0);
 }  }

Removed from v.1.30  
changed lines
  Added in v.1.31


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