diff m68k_to_x86.c @ 175:7504200cac86

Fix order of SR and PC saved in an exception stack frame
author Mike Pavone <pavone@retrodev.com>
date Sun, 06 Jan 2013 20:49:42 -0800
parents a1c3ecb4823f
children e2918b5208eb
line wrap: on
line diff
--- a/m68k_to_x86.c	Sun Jan 06 18:31:17 2013 -0800
+++ b/m68k_to_x86.c	Sun Jan 06 20:49:42 2013 -0800
@@ -3334,15 +3334,12 @@
 		break;
 	case M68K_RTE:
 		//TODO: Trap if not in system mode
-		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
-		dst = call(dst, (uint8_t *)m68k_read_long_scratch1);
-		dst = push_r(dst, SCRATCH1);
-		dst = add_ir(dst, 4, opts->aregs[7], SZ_D);
+		//Read saved SR
 		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
 		dst = call(dst, (uint8_t *)m68k_read_word_scratch1);
 		dst = add_ir(dst, 2, opts->aregs[7], SZ_D);
 		dst = call(dst, (uint8_t *)set_sr);
-		dst = pop_r(dst, SCRATCH1);
+		//Check if we've switched to user mode and swap stack pointers if needed
 		dst = bt_irdisp8(dst, 5, CONTEXT, offsetof(m68k_context, status), SZ_B);
 		end_off = dst+1;
 		dst = jcc(dst, CC_C, dst+2);
@@ -3350,20 +3347,26 @@
 		dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, opts->aregs[7], SZ_D);
 		dst = mov_rrdisp8(dst, SCRATCH2, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, SZ_D);
 		*end_off = dst - (end_off+1);
+		//Read saved PC
+		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
+		dst = call(dst, (uint8_t *)m68k_read_long_scratch1);
+		dst = add_ir(dst, 4, opts->aregs[7], SZ_D);
+		//Get native address, sync components, recalculate integer points and jump to returned address
 		dst = call(dst, (uint8_t *)m68k_native_addr_and_sync);
 		dst = jmp_r(dst, SCRATCH1);
 		break;
 	case M68K_RTR:
-		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
-		dst = call(dst, (uint8_t *)m68k_read_long_scratch1);
-		dst = push_r(dst, SCRATCH1);
-		dst = add_ir(dst, 4, opts->aregs[7], SZ_D);
+		//Read saved CCR
 		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
 		dst = call(dst, (uint8_t *)m68k_read_word_scratch1);
 		dst = add_ir(dst, 2, opts->aregs[7], SZ_D);
 		dst = call(dst, (uint8_t *)set_ccr);
-		dst = pop_r(dst, SCRATCH1);
-		dst = call(dst, (uint8_t *)m68k_native_addr_and_sync);
+		//Read saved PC
+		dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D);
+		dst = call(dst, (uint8_t *)m68k_read_long_scratch1);
+		dst = add_ir(dst, 4, opts->aregs[7], SZ_D);
+		//Get native address and jump to it
+		dst = call(dst, (uint8_t *)m68k_native_addr);
 		dst = jmp_r(dst, SCRATCH1);
 		break;
 	/*case M68K_SBCD: