+/*
+ * mono_arch_get_static_rgctx_trampoline:
+ *
+ * Create a trampoline which sets RGCTX_REG to MRGCTX, then jumps to ADDR.
+ */
+gpointer
+mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
+{
+ guint8 *code, *start;
+ int buf_len;
+
+ MonoDomain *domain = mono_domain_get ();
+
+#ifdef MONO_ARCH_NOMAP32BIT
+ buf_len = 32;
+#else
+ /* AOTed code could still have a non-32 bit address */
+ if ((((guint64)addr) >> 32) == 0)
+ buf_len = 16;
+ else
+ buf_len = 30;
+#endif
+
+ start = code = mono_domain_code_reserve (domain, buf_len);
+
+ amd64_mov_reg_imm (code, MONO_ARCH_RGCTX_REG, mrgctx);
+ amd64_jump_code (code, addr);
+ g_assert ((code - start) < buf_len);
+
+ mono_arch_flush_icache (start, code - start);
+
+ return start;
+}
+
+gpointer
+mono_arch_get_llvm_imt_trampoline (MonoDomain *domain, MonoMethod *m, int vt_offset)
+{
+ guint8 *code, *start;
+ int buf_len;
+ int this_reg;
+
+ buf_len = 32;
+
+ start = code = mono_domain_code_reserve (domain, buf_len);
+
+ this_reg = mono_arch_get_this_arg_reg (mono_method_signature (m), NULL, NULL);
+
+ /* Set imt arg */
+ amd64_mov_reg_imm (code, MONO_ARCH_IMT_REG, m);
+ /* Load vtable address */
+ amd64_mov_reg_membase (code, AMD64_RAX, this_reg, 0, 8);
+ amd64_jump_membase (code, AMD64_RAX, vt_offset);
+ amd64_ret (code);
+
+ g_assert ((code - start) < buf_len);
+
+ mono_arch_flush_icache (start, code - start);
+
+ return start;
+}
+