* src/vm/jit/code.c (code_get_stack_frame_size): Implement stack alignment
[cacao.git] / src / vm / jit / mips / md.c
index ccfb4b11fee7586d4a01a025a78e83d42e655c09..06daee023d6f7fb7a84eecade1b314a5ac469569 100644 (file)
@@ -26,9 +26,9 @@
 
    Authors: Christian Thalinger
 
-   Changes: 
+   Changes: Edwin Steiner
 
-   $Id: md.c 4498 2006-02-12 23:43:09Z twisti $
+   $Id: md.c 4654 2006-03-19 19:46:11Z edwin $
 
 */
 
 #include "config.h"
 
 #include <assert.h>
-#include <sys/mman.h>
 #include <unistd.h>
+#include <sys/cachectl.h>
+#include <sys/mman.h>
 
 #include "vm/types.h"
 
 #include "toolbox/logging.h"
 #include "vm/global.h"
 #include "vm/jit/stacktrace.h"
+#include "vm/options.h" /* XXX debug */
+#include "vm/jit/disass.h" /* XXX debug */
 
 
 void docacheflush(u1 *p, long bytelen)
@@ -192,7 +195,7 @@ u1 *md_codegen_findmethod(u1 *ra)
 
 #if SIZEOF_VOID_P == 8
                assert((mcode >> 16) == 0x6739);
-#else  
+#else
                assert((mcode >> 16) == 0x2739);
 #endif
 
@@ -220,6 +223,73 @@ u1 *md_codegen_findmethod(u1 *ra)
 }
 
 
+/* md_cacheflush ***************************************************************
+
+   Calls the system's function to flush the instruction and data
+   cache.
+
+*******************************************************************************/
+
+void md_cacheflush(u1 *addr, s4 nbytes)
+{
+       cacheflush(addr, nbytes, BCACHE);
+}
+
+
+/* md_icacheflush **************************************************************
+
+   Calls the system's function to flush the instruction cache.
+
+*******************************************************************************/
+
+void md_icacheflush(u1 *addr, s4 nbytes)
+{
+       cacheflush(addr, nbytes, ICACHE);
+}
+
+
+/* md_dcacheflush **************************************************************
+
+   Calls the system's function to flush the data cache.
+
+*******************************************************************************/
+
+void md_dcacheflush(u1 *addr, s4 nbytes)
+{
+       cacheflush(addr, nbytes, DCACHE);
+}
+
+
+/* md_patch_replacement_point **************************************************
+
+   Patch the given replacement point.
+
+*******************************************************************************/
+
+void md_patch_replacement_point(rplpoint *rp)
+{
+    u8 mcode;
+
+       /* save the current machine code */
+       mcode = *(u8*)rp->pc;
+
+       /* write the new machine code */
+    *(u8*)(rp->pc) = rp->mcode;
+
+       /* store saved mcode */
+       rp->mcode = mcode;
+
+       {
+               u1* u1ptr = rp->pc;
+               DISASSINSTR(u1ptr);
+               DISASSINSTR(u1ptr);
+               fflush(stdout);
+       }
+
+       /* flush instruction cache */
+    md_icacheflush(rp->pc,2*4);
+}
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
@@ -231,4 +301,5 @@ u1 *md_codegen_findmethod(u1 *ra)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */