Index: src/target/mips32.c
===================================================================
--- src/target/mips32.c	(revision 1836)
+++ src/target/mips32.c	(working copy)
@@ -420,3 +420,41 @@
 	
 	return ERROR_OK;
 }
+
+int mips32_enable_interrupts(struct target_s *target, int enable)
+{
+	int retval;
+	int update = 0;
+	u32 dcr;
+	
+	/* read debug control register */
+	if ((retval = target_read_u32(target, EJTAG_DCR, &dcr)) != ERROR_OK)
+		return retval;
+	
+	if (enable)
+	{
+		if (!(dcr & (1<<4)))
+		{
+			/* enable interrupts */
+			dcr |= (1<<4);
+			update = 1;
+		}
+	}
+	else
+	{
+		if (dcr & (1<<4))
+		{
+			/* disable interrupts */
+			dcr &= ~(1<<4);
+			update = 1;
+		}
+	}
+	
+	if (update)
+	{
+		if ((retval = target_write_u32(target, EJTAG_DCR, dcr)) != ERROR_OK)
+			return retval;
+	}
+	
+	return ERROR_OK;
+}
Index: src/target/mips32.h
===================================================================
--- src/target/mips32.h	(revision 1836)
+++ src/target/mips32.h	(working copy)
@@ -131,6 +131,7 @@
 extern reg_cache_t *mips32_build_reg_cache(target_t *target);
 extern int mips32_run_algorithm(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_params, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info);
 extern int mips32_configure_break_unit(struct target_s *target);
+extern int mips32_enable_interrupts(struct target_s *target, int enable);
 extern int mips32_examine(struct target_s *target);
 
 extern int mips32_register_commands(struct command_context_s *cmd_ctx);
Index: src/target/mips_ejtag.c
===================================================================
--- src/target/mips_ejtag.c	(revision 1836)
+++ src/target/mips_ejtag.c	(working copy)
@@ -216,13 +216,11 @@
 	return ERROR_OK;
 }
 
-int mips_ejtag_exit_debug(mips_ejtag_t *ejtag_info, int enable_interrupts)
+int mips_ejtag_exit_debug(mips_ejtag_t *ejtag_info)
 {
 	u32 inst;
 	inst = MIPS32_DRET;
-
-	/* TODO : enable/disable interrrupts */
-
+	
 	/* execute our dret instruction */
 	mips32_pracc_exec(ejtag_info, 1, &inst, 0, NULL, 0, NULL, 0);
 
Index: src/target/mips_ejtag.h
===================================================================
--- src/target/mips_ejtag.h	(revision 1836)
+++ src/target/mips_ejtag.h	(working copy)
@@ -108,7 +108,7 @@
 
 extern int mips_ejtag_set_instr(mips_ejtag_t *ejtag_info, int new_instr, void *delete_me_and_submit_patch);
 extern int mips_ejtag_enter_debug(mips_ejtag_t *ejtag_info);
-extern int mips_ejtag_exit_debug(mips_ejtag_t *ejtag_info, int enable_interrupts);
+extern int mips_ejtag_exit_debug(mips_ejtag_t *ejtag_info);
 extern int mips_ejtag_get_impcode(mips_ejtag_t *ejtag_info, u32 *impcode, in_handler_t handler);
 extern int mips_ejtag_get_idcode(mips_ejtag_t *ejtag_info, u32 *idcode, in_handler_t handler);
 extern int mips_ejtag_drscan_32(mips_ejtag_t *ejtag_info, u32 *data);
Index: src/target/mips_m4k.c
===================================================================
--- src/target/mips_m4k.c	(revision 1836)
+++ src/target/mips_m4k.c	(working copy)
@@ -344,8 +344,11 @@
 	/* configure single step mode */
 	mips_ejtag_config_step(ejtag_info, 1);
 
+	/* disable interrupts while stepping */
+	mips32_enable_interrupts(target, 0);
+	
 	/* exit debug mode */
-	mips_ejtag_exit_debug(ejtag_info, 1);
+	mips_ejtag_exit_debug(ejtag_info);
 
 	mips_m4k_debug_entry(target);
 
@@ -397,8 +400,11 @@
 		}
 	}
 
-	/* exit debug mode - enable interrupts if required */
-	mips_ejtag_exit_debug(ejtag_info, !debug_execution);
+	/* enable interrupts if we are running */
+	mips32_enable_interrupts(target, !debug_execution);
+	
+	/* exit debug mode */
+	mips_ejtag_exit_debug(ejtag_info);
 	target->debug_reason = DBG_REASON_NOTHALTED;
 
 	/* registers are now invalid */
@@ -452,8 +458,11 @@
 
 	target_call_event_callbacks(target, TARGET_EVENT_RESUMED);
 
+	/* disable interrupts while stepping */
+	mips32_enable_interrupts(target, 0);
+		
 	/* exit debug mode */
-	mips_ejtag_exit_debug(ejtag_info, 1);
+	mips_ejtag_exit_debug(ejtag_info);
 
 	/* registers are now invalid */
 	mips32_invalidate_core_regs(target);

