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

version 1.11, 2004/02/20 16:09:04 version 1.18, 2004/06/15 13:50:13
Line 1 Line 1
 /*      $Id$    */  /*      $Id$    */
   
 /*  /*
  * Copyright (c) 2002-2003 NONAKA Kimihiro   * Copyright (c) 2002-2004 NONAKA Kimihiro
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
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);
                           }
                   }
           }
   }
   
   #if defined(IA32_SUPPORT_DEBUG_REGISTER)
   INLINE static void
   check_memory_break_point(UINT32 address, UINT length, UINT rw)
   {
           int i;
   
           if (CPU_STAT_BP && !(CPU_EFLAG & RF_FLAG)) {
                   for (i = 0; i < CPU_DEBUG_REG_INDEX_NUM; i++) {
                           if ((CPU_STAT_BP & (1 << i))
                            && (CPU_DR7_GET_RW(i) & rw)
   
                            && ((address <= CPU_DR(i) && address + length > CPU_DR(i))
                             || (address > CPU_DR(i) && address < CPU_DR(i) + CPU_DR7_GET_LEN(i)))) {
                                   CPU_STAT_BP_EVENT |= CPU_STAT_BP_EVENT_B(i);
                           }
                 }                  }
         }          }
         return TRUE;  
 }  }
   #else
   #define check_memory_break_point(address, length, rw)
   #endif
   
   
 /*  /*
  * 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)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         UINT32 addr;          UINT32 addr;
   #if defined(IA32_SUPPORT_TLB)
           TLB_ENTRY_T *ep;
   #endif
   
         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) {
                 addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset;                  addr = sd->u.seg.segbase + offset;
                 if (!CPU_STAT_PM)                  if (!CPU_STAT_PAGING)
                         return cpu_memoryread(addr);                          return cpu_memoryread(addr);
                 return cpu_lcmemoryread(addr);  #if defined(IA32_SUPPORT_TLB)
                   ep = tlb_lookup(addr, ucrw);
                   if (ep != NULL && ep->memp != NULL) {
                           return ep->memp[addr & 0xfff];
                   }
   #endif
                   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 254  cpu_codefetch_w(UINT32 offset) Line 311  cpu_codefetch_w(UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         UINT32 addr;          UINT32 addr;
   #if defined(IA32_SUPPORT_TLB)
           TLB_ENTRY_T *ep;
           UINT16 value;
   #endif
   
         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) {
                 addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset;                  addr = sd->u.seg.segbase + offset;
                 if (!CPU_STAT_PM)                  if (!CPU_STAT_PAGING)
                         return cpu_memoryread_w(addr);                          return cpu_memoryread_w(addr);
                 return cpu_lcmemoryread_w(addr);  #if defined(IA32_SUPPORT_TLB)
                   ep = tlb_lookup(addr, ucrw);
                   if (ep != NULL && ep->memp != NULL) {
                           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;
                           }
                   }
   #endif
                   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 271  cpu_codefetch_d(UINT32 offset) Line 346  cpu_codefetch_d(UINT32 offset)
 {  {
         descriptor_t *sd;          descriptor_t *sd;
         UINT32 addr;          UINT32 addr;
   #if defined(IA32_SUPPORT_TLB)
           TLB_ENTRY_T *ep[2];
           UINT32 value;
           UINT remain;
   #endif
   
         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) {
                 addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset;                  addr = sd->u.seg.segbase + offset;
                 if (!CPU_STAT_PM)                  if (!CPU_STAT_PAGING)
                         return cpu_memoryread_d(addr);                          return cpu_memoryread_d(addr);
                 return cpu_lcmemoryread_d(addr);  #if defined(IA32_SUPPORT_TLB)
                   ep[0] = tlb_lookup(addr, ucrw);
                   if (ep[0] != NULL && ep[0]->memp != NULL) {
                           remain = 0x1000 - (addr & 0xfff);
                           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;
                           }
                   }
   #endif
                   return cpu_linear_memory_read_d(addr, ucrw);
         }          }
         EXCEPTION(GP_EXCEPTION, 0);          EXCEPTION(GP_EXCEPTION, 0);
         return 0;       /* compiler happy */          return 0;       /* compiler happy */
Line 285  cpu_codefetch_d(UINT32 offset) Line 400  cpu_codefetch_d(UINT32 offset)
   
   
 /*  /*
  * virtual address -> linear address   * virtual address memory access functions
  */   */
 UINT8 MEMCALL  #include "cpu_mem.mcr"
 cpu_vmemoryread(int idx, UINT32 offset)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  
         if (!sd->valid) {  
                 exc = GP_EXCEPTION;  
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_READABLE)) {  
                 cpu_memoryread_check(sd, offset, 1,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 4: case 5: case 6: case 7:  
                         if (offset <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }  
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM)  
                 return cpu_memoryread(addr);  
         return cpu_lmemoryread(addr, CPU_STAT_USER_MODE);  
   
 err:  
         EXCEPTION(exc, 0);  
         return 0;       /* compiler happy */  
 }  
   
 UINT16 MEMCALL  
 cpu_vmemoryread_w(int idx, UINT32 offset)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  
         if (!sd->valid) {  
                 exc = GP_EXCEPTION;  
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_READABLE)) {  
                 cpu_memoryread_check(sd, offset, 2,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 4: case 5: case 6: case 7:  
                         if (offset - 1 <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit - 1) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }   
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM)  
                 return cpu_memoryread_w(addr);  
         return cpu_lmemoryread_w(addr, CPU_STAT_USER_MODE);  
   
 err:  
         EXCEPTION(exc, 0);  
         return 0;       /* compiler happy */  
 }  
   
 UINT32 MEMCALL  
 cpu_vmemoryread_d(int idx, UINT32 offset)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(b, UINT8, 1)
         if (!sd->valid) {  VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(w, UINT16, 2)
                 exc = GP_EXCEPTION;  VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(d, UINT32, 4)
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_READABLE)) {  
                 cpu_memoryread_check(sd, offset, 4,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 4: case 5: case 6: case 7:  
                         if (offset - 3 <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit - 3) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }  
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM)  
                 return cpu_memoryread_d(addr);  
         return cpu_lmemoryread_d(addr, CPU_STAT_USER_MODE);  
   
 err:  
         EXCEPTION(exc, 0);  
         return 0;       /* compiler happy */  
 }  
   
 /* vaddr memory write */  
 void MEMCALL  
 cpu_vmemorywrite(int idx, UINT32 offset, UINT8 val)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  
         if (!sd->valid) {  
                 exc = GP_EXCEPTION;  
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) {  
                 cpu_memorywrite_check(sd, offset, 1,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 6: case 7:  
                         if (offset <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }  
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM) {  
                 /* real mode */  
                 cpu_memorywrite(addr, val);  
         } else {  
                 /* protected mode */  
                 cpu_lmemorywrite(addr, val, CPU_STAT_USER_MODE);  
         }  
         return;  
   
 err:  
         EXCEPTION(exc, 0);  
 }  
   
 void MEMCALL  
 cpu_vmemorywrite_w(int idx, UINT32 offset, UINT16 val)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  
         if (!sd->valid) {  
                 exc = GP_EXCEPTION;  
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) {  
                 cpu_memorywrite_check(sd, offset, 2,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 6: case 7:  
                         if (offset - 1 <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit - 1) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }  
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM) {  
                 /* real mode */  
                 cpu_memorywrite_w(addr, val);  
         } else {  
                 /* protected mode */  
                 cpu_lmemorywrite_w(addr, val, CPU_STAT_USER_MODE);  
         }  
         return;  
   
 err:  
         EXCEPTION(exc, 0);  
 }  
   
 void MEMCALL  
 cpu_vmemorywrite_d(int idx, UINT32 offset, UINT32 val)  
 {  
         descriptor_t *sd;  
         UINT32 addr;  
         int exc;  
   
         __ASSERT((unsigned int)idx < CPU_SEGREG_NUM);  
   
         sd = &CPU_STAT_SREG(idx);  
         if (!sd->valid) {  
                 exc = GP_EXCEPTION;  
                 goto err;  
         }  
   
         if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) {  
                 cpu_memorywrite_check(sd, offset, 4,  
                     (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION);  
         } else {  
                 switch (sd->type) {  
                 case 6: case 7:  
                         if (offset - 3 <= sd->u.seg.limit) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
   
                 default:  
                         if (offset > sd->u.seg.limit - 3) {  
                                 if (idx == CPU_SS_INDEX)  
                                         exc = SS_EXCEPTION;  
                                 else  
                                         exc = GP_EXCEPTION;  
                                 goto err;  
                         }  
                         break;  
                 }  
         }  
         addr = CPU_STAT_SREGBASE(idx) + offset;  
         if (!CPU_STAT_PM) {  
                 /* real mode */  
                 cpu_memorywrite_d(addr, val);  
         } else {  
                 /* protected mode */  
                 cpu_lmemorywrite_d(addr, val, CPU_STAT_USER_MODE);  
         }  
         return;  
   
 err:  
         EXCEPTION(exc, 0);  
 }  

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


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