Update of /cvsroot/arcem/arcem/arch
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv26947/arch

Modified Files:
      Tag: jit
        armarc.c armarc.h fastmap.c filecommon.c 
Log Message:
WIP ARM-on-ARM JIT engine
This is the beginnings of an ARM-on-ARM JIT engine, designed to be used by 
emulators like ArcEm and RPCEmu
Main functionality issues to resolve:
* Currently it's only functional for RISC OS hosts. But it should be fairly 
striaghtforward to get it working on other host OS's
* Not all instructions are supported yet; unsupported instructions will be 
interpreted
* The simplified interpreter loop which the JIT is invoked from doesn't 
implement the instruction prefetch pipeline; this will eventually need fixing 
(e.g. make the loop smart enough to stay in interpreter mode until the 
prefetched instructions match what's in memory, i.e. the CPU has left the 
self-modifying code sequence)
* The JIT will update the cycle counter but won't actually trigger any events 
until the end of the JIT code block is reached, this may cause issues with some 
software
* However the biggest problem is likely to be that the single-pass code 
generation results in sub-optimal handling of complex instructions like 
LDR/STR. So future development is likely to focus on experimenting with more 
complex code generation techniques, e.g. compiler-style code graphs



Index: fastmap.c
===================================================================
RCS file: /cvsroot/arcem/arcem/arch/fastmap.c,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -d -r1.5 -r1.5.2.1
--- fastmap.c   30 Jul 2012 21:26:24 -0000      1.5
+++ fastmap.c   27 May 2017 20:54:06 -0000      1.5.2.1
@@ -102,7 +102,7 @@
        {
                ARMword *phy = FastMap_Log2Phy(entry,address&~UINT32_C(3));
                *phy = data;
-               *(FastMap_Phy2Func(state,phy)) = FASTMAP_CLOBBEREDFUNC; 
+               FastMap_PhyClobberFunc(state,phy); 
        }
        else if(FASTMAP_RESULT_FUNC(res))
        {
@@ -141,7 +141,7 @@
 #endif
                ARMword *phy = FastMap_Log2Phy(entry,address);
                *((uint8_t *)phy) = data;
-               
*(FastMap_Phy2Func(state,(ARMword*)(((FastMapUInt)phy)&~((FastMapUInt)3)))) = 
FASTMAP_CLOBBEREDFUNC;
+               
FastMap_PhyClobberFunc(state,(ARMword*)(((FastMapUInt)phy)&~((FastMapUInt)3)));
        }
        else if(FASTMAP_RESULT_FUNC(res))
        {
@@ -180,7 +180,7 @@
                ARMword *phy = FastMap_Log2Phy(entry,address&~UINT32_C(3));
                temp = *phy;
                *phy = data;
-               *(FastMap_Phy2Func(state,phy)) = FASTMAP_CLOBBEREDFUNC;
+               FastMap_PhyClobberFunc(state,phy);
                return temp;
        }
        else if(FASTMAP_RESULT_FUNC(res))
@@ -228,7 +228,7 @@
                ARMword *phy = FastMap_Log2Phy(entry,address);
                temp = *((uint8_t *)phy);
                *((uint8_t *)phy) = data;
-               
*(FastMap_Phy2Func(state,(ARMword*)(((FastMapUInt)phy)&~((FastMapUInt)3)))) = 
FASTMAP_CLOBBEREDFUNC;
+               
FastMap_PhyClobberFunc(state,(ARMword*)(((FastMapUInt)phy)&~((FastMapUInt)3)));
                return temp;
        }
        else if(FASTMAP_RESULT_FUNC(res))

Index: armarc.h
===================================================================
RCS file: /cvsroot/arcem/arcem/arch/armarc.h,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -d -r1.16 -r1.16.2.1
--- armarc.h    6 Mar 2013 19:07:30 -0000       1.16
+++ armarc.h    27 May 2017 20:54:06 -0000      1.16.2.1
@@ -8,6 +8,9 @@
 #ifdef SOUND_SUPPORT
 #include "sound.h"
 #endif
+#ifdef JIT
+#include "jit/jit.h"
+#endif
 
 /* Memory map locations */
 #define MEMORY_0x3800000_R_ROM_HIGH   0x3800000  /* Some sections of the 
memory map    */
@@ -35,6 +38,7 @@
   ARMword *PhysRam;
   ARMword RAMSize;
   ARMword RAMMask;
+  ARMword ROMRAMChunkSize;    /* Size of the combined ROM+RAM memory chunk, 
guaranteed to be 4KB multiple */
 
   int32_t PageTable[512]; /* Good old fashioned MEMC1 page table */
   ARMword ControlReg;
@@ -62,7 +66,9 @@
 
   /* Fastmap memory block pointers */
   void *ROMRAMChunk;
+#ifdef ARMUL_INSTR_FUNC_CACHE
   void *EmuFuncChunk;
+#endif
 };
 
 
@@ -111,6 +117,7 @@
        return (ARMword*)(((FastMapUInt)addr)+(entry->FlagsAndData<<8));
 }
 
+#ifdef ARMUL_INSTR_FUNC_CACHE
 static inline ARMEmuFunc *FastMap_Phy2Func(ARMul_State *state,ARMword *addr)
 {
        /* Return ARMEmuFunc * for an address returned by Log2Phy */
@@ -121,6 +128,17 @@
        return (ARMEmuFunc*)(((FastMapUInt)addr)+state->FastMapInstrFuncOfs);
 #endif
 }
+#endif
+
+static inline void FastMap_PhyClobberFunc(ARMul_State *state,ARMword *addr)
+{
+#ifdef ARMUL_INSTR_FUNC_CACHE
+       *(FastMap_Phy2Func(state,addr)) = FASTMAP_CLOBBEREDFUNC;
+#elif defined(JIT)
+       JIT_ClobberCode(state,addr);
+#endif
+}
+
 
 static inline ARMword FastMap_LoadFunc(const FastMapEntry *entry,ARMul_State 
*state,ARMword addr)
 {

Index: armarc.c
===================================================================
RCS file: /cvsroot/arcem/arcem/arch/armarc.c,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -u -d -r1.42 -r1.42.2.1
--- armarc.c    6 Mar 2013 19:07:30 -0000       1.42
+++ armarc.c    27 May 2017 20:54:06 -0000      1.42.2.1
@@ -32,6 +32,9 @@
 #include "displaydev.h"
 #include "filecalls.h"
 #include "ControlPane.h"
+#ifdef JIT
+#include "../jit/jit.h"
+#endif
 
 
 #ifdef MACOSX
@@ -298,21 +301,34 @@
 
   /* Now allocate ROMs & RAM in one chunk */
   RAMChunkSize = MAX(MEMC.RAMSize,512*1024); /* Ensure at least 512K RAM 
allocated to avoid any issues caused by DMA pointers going out of range */
-  MEMC.ROMRAMChunk = calloc(RAMChunkSize+MEMC.ROMHighSize+extnrom_size+256,1);
-  MEMC.EmuFuncChunk = 
calloc(RAMChunkSize+MEMC.ROMHighSize+extnrom_size+256,sizeof(FastMapUInt)/4);
-  if((MEMC.ROMRAMChunk == NULL) || (MEMC.EmuFuncChunk == NULL)) {
+  MEMC.ROMRAMChunkSize = RAMChunkSize+MEMC.ROMHighSize+extnrom_size;
+  MEMC.ROMRAMChunk = calloc(MEMC.ROMRAMChunkSize+256,1);
+#ifdef ARMUL_INSTR_FUNC_CACHE
+  MEMC.EmuFuncChunk = calloc(MEMC.ROMRAMChunkSize+256,sizeof(FastMapUInt)/4);
+#endif
+  if((MEMC.ROMRAMChunk == NULL)
+#ifdef ARMUL_INSTR_FUNC_CACHE
+   || (MEMC.EmuFuncChunk == NULL)
+#endif
+   ) {
     ControlPane_Error(3,"Couldn't allocate ROMRAMChunk/EmuFuncChunk\n");
   }
+#ifdef ARMUL_INSTR_FUNC_CACHE
 #ifdef FASTMAP_64
   /* On 64bit systems, ROMRAMChunk needs shifting to account for the shift 
that occurs in FastMap_Phy2Func */
   state->FastMapInstrFuncOfs = 
((FastMapUInt)MEMC.EmuFuncChunk)-(((FastMapUInt)MEMC.ROMRAMChunk)<<1);
 #else
   state->FastMapInstrFuncOfs = 
((FastMapUInt)MEMC.EmuFuncChunk)-((FastMapUInt)MEMC.ROMRAMChunk);
 #endif
+#endif
   /* Get everything 256 byte aligned for FastMap to work */
   MEMC.PhysRam = (ARMword*) ((((FastMapUInt)MEMC.ROMRAMChunk)+255)&~255); /* 
RAM must come first for FastMap_LogRamFunc to work! */
   MEMC.ROMHigh = MEMC.PhysRam + (RAMChunkSize>>2);
 
+#ifdef JIT
+  JIT_Init(&state->jit,(uintptr_t) MEMC.PhysRam,MEMC.ROMRAMChunkSize);
+#endif
+
   dbug(" Loading ROM....\n ");
 
   File_ReadEmu(ROMFile,(uint8_t *) MEMC.ROMHigh,MEMC.ROMHighSize);
@@ -378,7 +394,9 @@
 void ARMul_MemoryExit(ARMul_State *state)
 {
   free(MEMC.ROMRAMChunk);
+#ifdef ARMUL_INSTR_FUNC_CACHE
   free(MEMC.EmuFuncChunk);
+#endif
   free(state->Display);
 }
 
@@ -610,7 +628,7 @@
   if(orig != data)
   {
     *phy = data;
-    *(FastMap_Phy2Func(state,phy)) = FASTMAP_CLOBBEREDFUNC;
+    FastMap_PhyClobberFunc(state,phy);
     /* Convert pointer to physical addr, then update DMA flags */
     addr = (ARMword) (((FastMapUInt)phy)-((FastMapUInt)MEMC.PhysRam));
     FastMap_DMAAbleWrite(addr,data);
@@ -807,7 +825,7 @@
     data |= (*phy) &~ (0xff<<shift);
   }
   *phy = data;
-  *(FastMap_Phy2Func(state,phy)) = FASTMAP_CLOBBEREDFUNC;
+  FastMap_PhyClobberFunc(state,phy);
   if(addr < 512*1024)
     FastMap_DMAAbleWrite(addr,data);
   return 0;
@@ -829,7 +847,7 @@
   if(orig != data)
   {
     *phy = data;
-    *(FastMap_Phy2Func(state,phy)) = FASTMAP_CLOBBEREDFUNC;
+    FastMap_PhyClobberFunc(state,phy);
     /* Update DMA flags */
     FastMap_DMAAbleWrite(addr,data);
   }

Index: filecommon.c
===================================================================
RCS file: /cvsroot/arcem/arcem/arch/filecommon.c,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -d -r1.6 -r1.6.2.1
--- filecommon.c        6 Mar 2013 19:07:30 -0000       1.6
+++ filecommon.c        27 May 2017 20:54:06 -0000      1.6.2.1
@@ -281,7 +281,6 @@
     if(FASTMAP_RESULT_DIRECT(res))
     {
       size_t temp, temp2;
-      ARMEmuFunc *func;
       uint8_t *phy = (uint8_t *) FastMap_Log2Phy(entry,uAddress);
 
       /* Scan ahead to work out the size of this memory block */
@@ -309,11 +308,10 @@
 
       /* Clobber emu funcs for that region */
       temp2 = (temp+(uAddress&3)+3)&~UINT32_C(3);
-      func = FastMap_Phy2Func(state,(ARMword *) (phy-(uAddress&3)));
       while(temp2>0)
       {
-        *func++ = FASTMAP_CLOBBEREDFUNC;
         temp2-=4;
+        FastMap_PhyClobberFunc(state,(ARMword *) (phy-(uAddress&3)+temp2));
       }
 
       /* Update state */


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
-- 
arcem-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/arcem-cvs

Reply via email to