summaryrefslogtreecommitdiff
path: root/rtl/core/porch/porch.sv
blob: 2eec43842b40df70c42cf9f351c56568457e53d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
`include "core/uarch.sv"

module core_porch
(
	input  logic       clk,
	                   rst_n,
	                   flush,
	                   stall,
	input  psr_flags   flags,

	input  word        fetch_insn,
	input  ptr         fetch_insn_pc,
	input  insn_decode fetch_dec,

	output word        insn,
	output ptr         insn_pc,
	output insn_decode dec
);

	logic execute, conditional, undefined;
	insn_decode nop, hold_dec;

	core_porch_conds conds
	(
		.*
	);

	assign nop.ctrl.execute = 0;
	assign nop.ctrl.undefined = 0;
	assign nop.ctrl.conditional = 0;

	always_comb begin
		dec = hold_dec;
		dec.ctrl.execute = !flush && dec.ctrl.execute && execute;
		dec.ctrl.undefined = !flush && (dec.ctrl.undefined || undefined);
		dec.ctrl.conditional = !flush && (dec.ctrl.conditional || conditional);
	end

	always_ff @(posedge clk or negedge rst_n)
		if(!rst_n) begin
			insn <= `NOP;
			insn_pc <= 0;
			hold_dec <= nop;
		end else if(!stall) begin
			insn <= fetch_insn;
			hold_dec <= fetch_dec;

			if(!flush)
				insn_pc <= fetch_insn_pc;
		end

endmodule