ICache, Fetch: Re-pipe things such that the icache now has a one-cycle latency. ...
[firearm.git] / Terminal.v
1 module Terminal(
2         input clk,
3         
4         input cp_req,
5         input [31:0] cp_insn,
6         output reg cp_ack,
7         output reg cp_busy,
8         input cp_rnw,
9         output reg [31:0] cp_read = 0,
10         input [31:0] cp_write
11 `ifdef verilator
12 `else
13         , output reg [8:0] sys_odata = 0,
14         input [8:0] sys_idata,
15         output reg sys_tookdata = 0
16 `endif
17 );
18         
19         /* Terminal pretends to be cp5. */
20         reg towrite = 0;
21         reg [7:0] data = 0;
22         reg [8:0] indata = 0;   /* High bit is if data is present. */
23         reg didread = 0;
24         
25         always @(*)
26         begin
27                 towrite = 0;
28                 data = 8'hxx;
29                 cp_ack = 0;
30                 cp_busy = 0;
31                 cp_read = 0;
32                 didread = 0;
33                 if (cp_req && (cp_rnw == 0) && (cp_insn[27:24] == 4'b1110) && (cp_insn[19:16] == 4'b0000) && (cp_insn[11:8] == 4'h5))
34                 begin
35                         towrite = 1;
36                         data = cp_write[7:0];
37                         cp_ack = 1;
38                 end else if (cp_req && (cp_rnw == 1) && (cp_insn[27:24] == 4'b1110) && (cp_insn[19:16] == 4'b0001) && (cp_insn[11:8] == 4'h5))
39                 begin
40                         cp_read = {23'h0, indata[8:0]};
41                         cp_ack = 1;
42                         didread = cp_insn[7:5] == 1;
43                 end
44         end
45 `ifdef verilator        
46         always @(posedge clk)
47                 if (towrite)
48                         $c("{extern void term_output(unsigned char d); term_output(",data,");}");
49                 else if (didread || !indata[8])
50                         indata <= $c("({extern unsigned int term_input(); term_input();})");
51 `else
52         always @(posedge clk)
53         begin
54                 sys_odata <= {towrite,data};
55                 if (didread || !indata[8])
56                 begin
57                         indata <= sys_idata;
58                         sys_tookdata <= 1;
59                 end else
60                         sys_tookdata <= 0;
61         end
62 `endif
63 endmodule
This page took 0.022002 seconds and 4 git commands to generate.