OpenCores
Issue List
Bug caused by cp2en for JMP instructions #10
Open Marco.Gunia opened this issue over 8 years ago
Marco.Gunia commented over 8 years ago

Hi,

I am using this AVR core for some time in a working system and I have found a serious bug (sometimes the CPU restarts or hangs).

I could trace it back to the cp2en signal, mostly affecting the logic in pm_fetch_dec.v. If you have a jmp instruction (opcode 16'h940C) the cp2en signal can cause the Jump instruction either to jump to the opcode as a target address (i.e. address 940C) or either not jump at all. This depends on the concrete cycle, when the cp2en appears.

If have build a testbench (or a comple Xilinx project) illustrating the bug.

Best, Marco

Marco.Gunia commented over 8 years ago

Hi,

I have fixed the bug. If anybody is interested, the fix is as follows. You need to edit the pm_fetch_dec.v and

1) Create a two new processes

reg 15:0 lastInst;

reg dontFetch; always @(posedge cp2) begin if (ireset == 1'b0) begin dontFetch <= 1'b0; end else begin dontFetch <= cpuwait | ~cp2en; end end

always @(posedge cp2) begin if (ireset == 1'b0) begin lastInst <= 16'b0; end else begin if (dontFetch == 1'b0) begin lastInst <= inst; end end end

2) Go to the sequential process (the one with "always @(posedge cp2") and just after the "else begin" insert a

if (cp2en) begin

and put an end at the very end of this process.

3) Go to the next process (it is a combinational one with "always @* begin: main_comb" and remove "if (cp2en) begin" and also the "end" at the end of the process.

4) In this process add at the position, where you have removed the "if (cp2en) begin the following code

if (!dontFetch)
	instruction_reg_next = inst;
else
	instruction_reg_next = lastInst;

That's it! Your are good to go!

Have fun!

Best, Marco


Assignee
No one
Labels
Request