* src/vm/jit/trap.cpp (trap_handle): Further generalized trap handling and
[cacao.git] / src / vm / jit / x86_64 / md-trap.h
index 6493e3559c089bf6333168e9bab0529a2b586943..8b09e3c6e8d50a0e5b2fa21e493d78c5cf4f6ec7 100644 (file)
@@ -58,9 +58,29 @@ enum {
        /* Don't use 8 (could be a normal load offset). */
 
        TRAP_COMPILER                       = 9,
+       TRAP_COUNTDOWN                      = 10,
        TRAP_END
 };
 
+
+/**
+ * Macro to fixup a compiler stub.
+ * PV : The PV from the compiler stub is equal to the XPC.
+ * RA : We use a framesize of zero here because the call pushed
+ *      the return addres onto the stack.
+ * SP : Skip the RA on the stack.
+ * XPC: The XPC is the RA minus 1, because the RA points to the
+ *      instruction after the call.
+ */
+#define MD_TRAP_COMPILER_FIXUP(xpc, ra, sp, pv) \
+       do { \
+               (pv)  = (xpc); \
+               (ra)  = md_stacktrace_get_returnaddress((sp), 0); \
+               (sp)  = (void*) (((uintptr_t) (sp)) + 1 * SIZEOF_VOID_P); \
+               (xpc) = (void*) (((uintptr_t) (ra)) - 3); \
+       } while(0)
+
+
 #endif /* _MD_TRAP_H */