daily update
[external/binutils.git] / sim / arm / armvirt.c
index f9ac453..969085d 100644 (file)
@@ -13,7 +13,7 @@
  
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
 
 /* This file contains a complete ARMulator memory model, modelling a
 "virtual memory" system. A much simpler model can be found in armfast.c,
@@ -24,6 +24,7 @@ freed as they might be needed again. A single area of memory may be
 defined to generate aborts. */
 
 #include "armopts.h"
+#include "armos.h"
 #include "armdefs.h"
 #include "ansidecl.h"
 
@@ -49,18 +50,23 @@ defined to generate aborts. */
 #define PAGEBITS 16
 #define OFFSETBITS 0xffff
 
+int SWI_vector_installed = FALSE;
+
 /***************************************************************************\
 *        Get a Word from Virtual Memory, maybe allocating the page          *
 \***************************************************************************/
 
 static ARMword
-GetWord (ARMul_State * state, ARMword address)
+GetWord (ARMul_State * state, ARMword address, int check)
 {
   ARMword page;
   ARMword offset;
   ARMword **pagetable;
   ARMword *pageptr;
 
+  if (check && state->is_XScale)
+    XScale_check_memacc (state, &address, 0);
+
   page = address >> PAGEBITS;
   offset = (address & OFFSETBITS) >> 2;
   pagetable = (ARMword **) state->MemDataPtr;
@@ -87,13 +93,16 @@ GetWord (ARMul_State * state, ARMword address)
 \***************************************************************************/
 
 static void
-PutWord (ARMul_State * state, ARMword address, ARMword data)
+PutWord (ARMul_State * state, ARMword address, ARMword data, int check)
 {
   ARMword page;
   ARMword offset;
   ARMword **pagetable;
   ARMword *pageptr;
 
+  if (check && state->is_XScale)
+    XScale_check_memacc (state, &address, 1);
+
   page = address >> PAGEBITS;
   offset = (address & OFFSETBITS) >> 2;
   pagetable = (ARMword **) state->MemDataPtr;
@@ -111,6 +120,9 @@ PutWord (ARMul_State * state, ARMword address, ARMword data)
       *(pagetable + page) = pageptr;
     }
 
+  if (address == 0x8)
+    SWI_vector_installed = TRUE;
+
   *(pageptr + offset) = data;
 }
 
@@ -127,7 +139,7 @@ ARMul_MemoryInit (ARMul_State * state, unsigned long initmemsize)
   if (initmemsize)
     state->MemSize = initmemsize;
 
-  pagetable = (ARMword **) malloc (sizeof (ARMword) * NUMPAGES);
+  pagetable = (ARMword **) malloc (sizeof (ARMword *) * NUMPAGES);
 
   if (pagetable == NULL)
     return FALSE;
@@ -186,8 +198,8 @@ ARMul_ReLoadInstr (ARMul_State * state, ARMword address, ARMword isize)
   if ((isize == 2) && (address & 0x2))
     {
       /* We return the next two halfwords: */
-      ARMword lo = GetWord (state, address);
-      ARMword hi = GetWord (state, address + 4);
+      ARMword lo = GetWord (state, address, FALSE);
+      ARMword hi = GetWord (state, address + 4, FALSE);
 
       if (state->bigendSig == HIGH)
        return (lo << 16) | (hi >> 16);
@@ -195,7 +207,7 @@ ARMul_ReLoadInstr (ARMul_State * state, ARMword address, ARMword isize)
        return ((hi & 0xFFFF) << 16) | (lo >> 16);
     }
 
-  return GetWord (state, address);
+  return GetWord (state, address, TRUE);
 }
 
 /***************************************************************************\
@@ -245,7 +257,7 @@ ARMword ARMul_ReadWord (ARMul_State * state, ARMword address)
     }
 #endif
 
-  return GetWord (state, address);
+  return GetWord (state, address, TRUE);
 }
 
 /***************************************************************************\
@@ -330,7 +342,7 @@ ARMul_WriteWord (ARMul_State * state, ARMword address, ARMword data)
     }
 #endif
 
-  PutWord (state, address, data);
+  PutWord (state, address, data, TRUE);
 }
 
 /***************************************************************************\
@@ -383,7 +395,8 @@ ARMul_StoreHalfWord (ARMul_State * state, ARMword address, ARMword data)
   offset = (((ARMword) state->bigendSig * 2) ^ (address & 2)) << 3;    /* bit offset into the word */
 
   PutWord (state, address,
-          (temp & ~(0xffffL << offset)) | ((data & 0xffffL) << offset));
+          (temp & ~(0xffffL << offset)) | ((data & 0xffffL) << offset),
+          TRUE);
 }
 
 /***************************************************************************\
@@ -399,7 +412,8 @@ ARMul_WriteByte (ARMul_State * state, ARMword address, ARMword data)
   offset = (((ARMword) state->bigendSig * 3) ^ (address & 3)) << 3;    /* bit offset into the word */
 
   PutWord (state, address,
-          (temp & ~(0xffL << offset)) | ((data & 0xffL) << offset));
+          (temp & ~(0xffL << offset)) | ((data & 0xffL) << offset),
+          TRUE);
 }
 
 /***************************************************************************\
@@ -439,7 +453,7 @@ ARMword ARMul_SwapWord (ARMul_State * state, ARMword address, ARMword data)
 
   state->NumNcycles++;
 
-  PutWord (state, address, data);
+  PutWord (state, address, data, TRUE);
 
   return temp;
 }
@@ -479,3 +493,30 @@ ARMul_Ccycles (ARMul_State * state, unsigned number, ARMword address ATTRIBUTE_U
   state->NumCcycles += number;
   ARMul_CLEARABORT;
 }
+
+
+/* Read a byte.  Do not check for alignment or access errors.  */
+
+ARMword
+ARMul_SafeReadByte (ARMul_State * state, ARMword address)
+{
+  ARMword temp, offset;
+
+  temp = GetWord (state, address, FALSE);
+  offset = (((ARMword) state->bigendSig * 3) ^ (address & 3)) << 3;
+
+  return (temp >> offset & 0xffL);
+}
+
+void
+ARMul_SafeWriteByte (ARMul_State * state, ARMword address, ARMword data)
+{
+  ARMword temp, offset;
+
+  temp = GetWord (state, address, FALSE);
+  offset = (((ARMword) state->bigendSig * 3) ^ (address & 3)) << 3;
+
+  PutWord (state, address,
+          (temp & ~(0xffL << offset)) | ((data & 0xffL) << offset),
+          FALSE);
+}