Index: or1200_cpu.v
===================================================================
--- or1200_cpu.v	(révision 864)
+++ or1200_cpu.v	(copie de travail)
@@ -66,7 +66,7 @@
 	id_void, id_insn, ex_void, 
 	ex_insn, ex_freeze, wb_insn, wb_freeze, id_pc, ex_pc, wb_pc, branch_op,
 	spr_dat_npc, rf_dataw, ex_flushpipe, 
-	du_stall, du_addr, du_dat_du, du_read, du_write, du_except_stop, du_flush_pipe,
+	du_stall, du_addr, du_dat_du, du_read, du_write, du_except_stop, du_flush_pipe, save_npc,
 	du_except_trig, du_dsr, du_dmr1, du_hwbkpt, du_hwbkpt_ls_r, du_dat_cpu,
 	du_lsu_store_dat, du_lsu_load_dat, 
 	abort_mvspr, abort_ex,
@@ -154,6 +154,7 @@
 output	[dw-1:0]		du_lsu_store_dat;
 output	[dw-1:0]		du_lsu_load_dat;
 input				du_flush_pipe;
+input				save_npc;
 
 //
 // Data (DC) interface
@@ -445,6 +446,7 @@
 	.no_more_dslot(no_more_dslot),
 	.lsu_stall(lsu_stall),
 	.du_flush_pipe(du_flush_pipe),
+	.save_npc(save_npc),
 	.spr_dat_npc(spr_dat_npc)
 );
 
Index: or1200_du.v
===================================================================
--- or1200_du.v	(révision 864)
+++ or1200_du.v	(copie de travail)
@@ -64,7 +64,7 @@
 	ex_freeze, branch_op, ex_insn, id_pc,
 	spr_dat_npc, rf_dataw,
 	du_dsr, du_dmr1, du_stall, du_addr, du_dat_i, du_dat_o,
-	du_read, du_write, du_except_stop, du_hwbkpt, du_flush_pipe,
+	du_read, du_write, du_except_stop, du_hwbkpt, du_flush_pipe, save_npc,
 	spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
 
 	// External Debug Interface
@@ -107,6 +107,7 @@
 input	[13:0]			du_except_stop;	// Exception masked by DSR
 output				du_hwbkpt;	// Cause trap exception (HW Breakpoints)
 output				du_flush_pipe;	// Cause pipeline flush and pc<-npc
+output				save_npc;	// Tells genpc to save the npc
 input				spr_cs;		// SPR Chip Select
 input				spr_write;	// SPR Read/Write
 input	[aw-1:0]		spr_addr;	// SPR Address
@@ -173,23 +174,30 @@
 
 reg du_flush_pipe_r;
 reg dbg_stall_i_r;
+reg save_npc_r;
 
 assign du_flush_pipe = du_flush_pipe_r;
+assign save_npc = save_npc_r;
 
 //
-// Register du_flush_pipe
+// Generate du_flush_pipe and save_npc
 //
 always @(posedge clk or `OR1200_RST_EVENT rst) begin
 	if (rst == `OR1200_RST_VALUE) begin
 		du_flush_pipe_r   <=  1'b0;
+		save_npc_r        <=  1'b0;
 	end
 	else begin
+		// npc is saved on the dbg_stall rising edge.
+		save_npc_r        <=  (!dbg_stall_i_r && dbg_stall_i);
+		// The pipe will be flushed on an unstall condition
+		// (dbg_stall_i falling edge) plus a trap condition.
 		du_flush_pipe_r   <=  (dbg_stall_i_r && !dbg_stall_i && |du_except_stop);
 	end
 end
 
 //
-// Detect dbg_stall falling edge
+// Detect dbg_stall edges
 //
 always @(posedge clk or `OR1200_RST_EVENT rst) begin
 	if (rst == `OR1200_RST_VALUE) begin
Index: or1200_genpc.v
===================================================================
--- or1200_genpc.v	(révision 864)
+++ or1200_genpc.v	(copie de travail)
@@ -64,7 +64,7 @@
 	id_branch_addrtarget, ex_branch_addrtarget, muxed_b, operand_b, 
 	flag, flagforw, ex_branch_taken, except_start,
 	epcr, spr_dat_i, spr_pc_we, genpc_refetch,
-	genpc_freeze, no_more_dslot, lsu_stall, du_flush_pipe, spr_dat_npc
+	genpc_freeze, no_more_dslot, lsu_stall, du_flush_pipe, save_npc, spr_dat_npc
 );
 
 //
@@ -111,6 +111,7 @@
 input				no_more_dslot;
 input				lsu_stall;
 input				du_flush_pipe;
+input				save_npc;
 
 parameter boot_adr = `OR1200_BOOT_ADR;
 //
@@ -124,6 +125,8 @@
 reg				ex_branch_taken;
 reg				genpc_refetch_r;
 reg				wait_lsu;
+// Saved npc
+reg	[31:0]			saved_npc;
 
    //
    // Address of insn to be fecthed
@@ -140,6 +143,15 @@
    assign icpu_tag_o = `OR1200_ITAG_NI;
 
    //
+   // save_npc
+   //
+   always @(posedge clk or `OR1200_RST_EVENT rst)
+     if (rst == `OR1200_RST_VALUE)
+       saved_npc <=  32'b0;
+     else if (save_npc)
+       saved_npc <=  spr_dat_npc;
+
+   //
    // wait_lsu
    //
    always @(posedge clk or `OR1200_RST_EVENT rst)
@@ -250,7 +262,7 @@
 	     $display("Reload breaked ins at : %h.", spr_dat_npc);
 	     // synopsys translate_on
 `endif
-	     pc = spr_dat_npc;
+	     pc = saved_npc;
 	     ex_branch_taken = 1'b1;
 	  end
 	  {3'b001, 3'b???}: begin
Index: or1200_top.v
===================================================================
--- or1200_top.v	(révision 864)
+++ or1200_top.v	(copie de travail)
@@ -390,6 +390,7 @@
 wire	[dw-1:0]	du_dat_cpu;
 wire	[dw-1:0]	du_lsu_store_dat;
 wire	[dw-1:0]	du_lsu_load_dat;
+wire			save_npc;
 wire			du_hwbkpt;
 wire			du_hwbkpt_ls_r = 1'b0;
 wire			flushpipe;
@@ -666,6 +667,7 @@
 	.abort_mvspr(abort_mvspr),
 	.abort_ex(abort_ex),
 	.du_flush_pipe(du_flush_pipe),
+	.save_npc(save_npc),
 
 	// Connection IMMU and CPU internally
 	.immu_en(immu_en),
@@ -928,6 +930,7 @@
 	.du_dsr(du_dsr),
 	.du_dmr1(du_dmr1),
 	.du_flush_pipe(du_flush_pipe),
+	.save_npc(save_npc),
 
 	// For Trace buffer
 	.spr_dat_npc(spr_dat_npc),
