- _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP1] = (intptr_t) p;
- _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP2_XPC] = (intptr_t) xpc;
- _mc->gregs[R_PC] = (intptr_t) asm_handle_exception;
+ _mc->gregs[R_SP] = sp; /* remove RA from stack */
+
+ _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP1] = (uintptr_t) o;
+ _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP2_XPC] = (uintptr_t) xpc;
+ _mc->gregs[R_PC] = (uintptr_t) asm_handle_exception;
+ }
+ else {
+ /* compilation ok, execute */
+ _mc->gregs[R_PC] = p;
+ }
+ break;
+
+ case TRAP_PATCHER:
+ if (p == NULL) {
+ /* No exception while patching, continue. */
+ _mc->gregs[R_PC] = xpc;
+ return;
+ }
+ /* fall-through in case of exception */
+
+ default:
+ /* a normal exception with normal expcetion handling */
+ _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP1] = (uintptr_t) p;
+ _mc->gregs[GREGS_ADRREG_OFF + REG_ATMP2_XPC] = (uintptr_t) xpc;
+ _mc->gregs[R_PC] = (uintptr_t) asm_handle_exception;
+ }