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)
#if SIZEOF_VOID_P == 8
assert((mcode >> 16) == 0x6739);
-#else
+#else
assert((mcode >> 16) == 0x2739);
#endif
}
+/* 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
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/