/* * mono_arch_get_restore_context: * * Returns a pointer to a method which restores a previously saved MonoContext. * The first argument in a0 is the pointer to the MonoContext. */ gpointer mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot) { int i; guint8 *code; static guint8 start [512]; static int inited = 0; guint32 iregs_to_restore; g_assert (!aot); if (info) *info = NULL; if (inited) return start; inited = 1; code = start; mips_move (code, mips_at, mips_a0); iregs_to_restore = (MONO_ARCH_CALLEE_SAVED_REGS \ | (1 << mips_sp) | (1 << mips_ra)); for (i = 0; i < MONO_SAVED_GREGS; ++i) { //if (iregs_to_restore & (1 << i)) { if (i != mips_zero && i != mips_at) { MIPS_LW (code, i, mips_at, G_STRUCT_OFFSET (MonoContext, sc_regs[i])); } } /* Get the address to return to */ mips_lw (code, mips_t9, mips_at, G_STRUCT_OFFSET (MonoContext, sc_pc)); /* jump to the saved IP */ mips_jr (code, mips_t9); mips_nop (code); /* never reached */ mips_break (code, 0xff); g_assert ((code - start) < sizeof(start)); mono_arch_flush_icache (start, code - start); if (mono_profiler_events & MONO_PROFILE_JIT_COMPILATION) mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING, NULL); return start; }
/* * mono_arch_get_restore_context: * * Returns a pointer to a method which restores a previously saved MonoContext. * The first argument in a0 is the pointer to the MonoContext. */ gpointer mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot) { int i; guint8 *code; static guint8 start [128]; static int inited = 0; guint32 iregs_to_restore; g_assert (!aot); if (info) *info = NULL; if (inited) return start; inited = 1; code = start; iregs_to_restore = (MONO_ARCH_CALLEE_SAVED_REGS \ | (1 << mips_sp) | (1 << mips_ra)); for (i = 0; i < MONO_SAVED_GREGS; ++i) { if (iregs_to_restore & (1 << i)) { MIPS_LW (code, i, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[i])); } } /* Get the address to return to */ mips_lw (code, mips_t9, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_pc)); /* jump to the saved IP */ mips_jr (code, mips_t9); mips_nop (code); /* never reached */ mips_break (code, 0xff); g_assert ((code - start) < sizeof(start)); mono_arch_flush_icache (start, code - start); return start; }
/* * mono_arch_get_call_filter: * * Returns a pointer to a method which calls an exception filter. We * also use this function to call finally handlers (we pass NULL as * @exc object in this case). * * This function is invoked as * call_handler (MonoContext *ctx, handler) * * Where 'handler' is a function to be invoked as: * handler (void) */ gpointer mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) { static guint8 start [320]; static int inited = 0; guint8 *code; int alloc_size; int offset; g_assert (!aot); if (info) *info = NULL; if (inited) return start; inited = 1; code = start; alloc_size = 64; g_assert ((alloc_size & (MIPS_STACK_ALIGNMENT-1)) == 0); mips_addiu (code, mips_sp, mips_sp, -alloc_size); mips_sw (code, mips_ra, mips_sp, alloc_size + MIPS_RET_ADDR_OFFSET); /* Save global registers on stack (s0 - s7) */ offset = 16; MIPS_SW (code, mips_s0, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s1, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s2, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s3, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s4, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s5, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s6, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_s7, mips_sp, offset); offset += IREG_SIZE; MIPS_SW (code, mips_fp, mips_sp, offset); offset += IREG_SIZE; /* Restore global registers from MonoContext, including the frame pointer */ MIPS_LW (code, mips_s0, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s0])); MIPS_LW (code, mips_s1, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s1])); MIPS_LW (code, mips_s2, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s2])); MIPS_LW (code, mips_s3, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s3])); MIPS_LW (code, mips_s4, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s4])); MIPS_LW (code, mips_s5, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s5])); MIPS_LW (code, mips_s6, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s6])); MIPS_LW (code, mips_s7, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_s7])); MIPS_LW (code, mips_fp, mips_a0, G_STRUCT_OFFSET (MonoContext, sc_regs[mips_fp])); /* a1 is the handler to call */ mips_move (code, mips_t9, mips_a1); /* jump to the saved IP */ mips_jalr (code, mips_t9, mips_ra); mips_nop (code); /* restore all regs from the stack */ offset = 16; MIPS_LW (code, mips_s0, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s1, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s2, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s3, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s4, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s5, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s6, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_s7, mips_sp, offset); offset += IREG_SIZE; MIPS_LW (code, mips_fp, mips_sp, offset); offset += IREG_SIZE; /* epilog */ mips_lw (code, mips_ra, mips_sp, alloc_size + MIPS_RET_ADDR_OFFSET); mips_addiu (code, mips_sp, mips_sp, alloc_size); mips_jr (code, mips_ra); mips_nop (code); g_assert ((code - start) < sizeof(start)); mono_arch_flush_icache (start, code - start); return start; }