1
- `include "emulator/module/clock.v"
2
- `include "emulator/seq/register.v"
1
+ `include "emulator/com/mux.v"
3
2
`include "emulator/com/stage0.v"
4
3
`include "emulator/com/stage1.v"
5
-
4
+ `include "emulator/com/stage2.v"
5
+ `include "emulator/com/stage3.v"
6
+ `include "emulator/com/input_devices.v"
7
+ `include "emulator/com/rom.v"
8
+ `include "emulator/seq/clock.v"
9
+ `include "emulator/seq/register.v"
10
+ `include "emulator/seq/output_devices.v"
11
+ `include "emulator/seq/ram.v"
6
12
7
13
module CHIPSET (
8
- input reset,
9
- input [31 :0 ] ram_value,
10
- output [31 :0 ] ram_address,
11
- output ram_is_write,
12
- );
13
-
14
- reg is_powered_on;
15
- reg flag_execute_from_ram;
16
- reg flag_last_zero;
17
- reg [15 :0 ] pc, pc_next;
14
+ output is_powered_on,
15
+ output [15 :0 ] pc,
16
+ output flag_execute_from_ram,
17
+ input reset_button);
18
+ // wire is_powered_on;
19
+ // wire flag_execute_from_ram;
20
+ wire flag_last_zero;
21
+ // wire[15:0] pc;
18
22
19
23
// Clock
20
24
wire [0 :3 ] clk;
25
+ wire [1 :0 ] clk_stage;
21
26
CLOCK clock (
22
- .clk(clk[0 :3 ]));
27
+ .clk(clk[0 :3 ]),
28
+ .clk_stage(clk_stage));
23
29
24
30
// BROM
25
31
wire [15 :0 ] brom_address;
26
32
wire [31 :0 ] brom_value;
27
33
ROM_BOOT brom (.out(brom_value), .address(brom_address));
28
34
29
35
// RAM
30
- reg ram_is_write;
36
+ wire ram_is_write;
31
37
wire [15 :0 ] ram_address;
32
- reg [31 :0 ] ram_in;
38
+ wire [31 :0 ] ram_in;
33
39
wire [31 :0 ] ram_value;
34
40
RAM_32bit_16aline ram (
35
41
.out(ram_value),
@@ -38,39 +44,45 @@ module CHIPSET(
38
44
.is_write(ram_is_write),
39
45
.clk(clk[3 ]));
40
46
41
-
42
47
wire [15 :0 ] ram_address_stage0;
43
48
wire [15 :0 ] ram_address_stage1;
49
+ wire [15 :0 ] ram_address_stage2;
50
+ wire [15 :0 ] ram_address_stage3;
51
+ MUX_2_16b ram_address_selector (
52
+ .value(ram_address),
53
+ .A0(ram_address_stage0),
54
+ .A1(ram_address_stage1),
55
+ .A2(ram_address_stage2),
56
+ .A3(ram_address_stage3),
57
+ .S(clk_stage));
58
+
44
59
// TODO: Updated ram_address
45
60
assign ram_address = ram_address_stage0;
46
61
47
62
// Input Devices
48
63
wire [7 :0 ] input_devices_address;
49
- reg [31 :0 ] input_devices_value;
50
- // TODO: add devices modules
51
-
52
- // Boot Sequence
53
- //
54
- // When the device have power supply but `is_powered_on` is off. The pc_eval
55
- // forces `program_counter_next` to be 0 and `execute_from_brom` to True.
56
- // If we keep the `is_powered_on` button in off stage for at-least 4 cycles
57
- // then at "stage3 posedge" program_counter should get updated to 0.
58
- // After that for every "stage0 posedge" till is_powered_on is off,
59
- // program_counter:0 along with execute_from_brom:True will be used to pull
60
- // up and execute first instruction from BROM.
61
- //
62
- // Assumption: No stateful IO devices are connected.
63
- // TODO: Implement `execute_from_brom` update implementation.
64
-
65
- // Operates on clk[3] down
66
- BOOT_CONTROL boot_control (
67
- .is_powered_on(is_powered_on),
68
- .pc_next(pc_next),
69
- .flags(flags),
70
- .reset(reset),
71
- .clk(clk[3 ]),
64
+ wire [31 :0 ] input_devices_value;
65
+
66
+ InputDevices idevices (
67
+ .value(input_devices_value),
68
+ .address(input_devices_address)
69
+ // .device0_values(2),
70
+ // .device1_values(3)
72
71
);
73
72
73
+ // Output Devices
74
+ wire [31 :0 ] output_devices_value;
75
+ wire [7 :0 ] output_devices_address;
76
+ wire output_is_write;
77
+
78
+ OutputDevices odevices (
79
+ // .device0_values(device0_values),
80
+ // .device1_values(device1_values),
81
+ .address(output_devices_address),
82
+ .value(output_devices_value),
83
+ .is_write(output_is_write),
84
+ .clk(clk[3 ]));
85
+
74
86
// STAGE0
75
87
wire [31 :0 ] _instruction_binary;
76
88
STAGE0 stage0 (
@@ -84,14 +96,18 @@ module CHIPSET(
84
96
85
97
// STAGE1
86
98
wire [31 :0 ] instruction_binary;
87
- REGISTER_up_16b r_ins_bin (
88
- .out(instruction_binary),
89
- .in(_instruction_binary),
99
+ REGISTER_up_16b stage1_r0 (
100
+ .out(instruction_binary[31 :16 ]),
101
+ .in(_instruction_binary[31 :16 ]),
102
+ .clk(clk[1 ]));
103
+ REGISTER_up_16b stage1_r1 (
104
+ .out(instruction_binary[15 :0 ]),
105
+ .in(_instruction_binary[15 :0 ]),
90
106
.clk(clk[1 ]));
91
107
92
108
wire [3 :0 ] mblock_alu_op = instruction_binary[3 :0 ];
93
- wire [3 :0 ] mblock_s1 = instruction_binary[5 :4 ];
94
- wire [1 :0 ] mblock_s2 = instruction_binary[8 :6 ];
109
+ wire [1 :0 ] mblock_s1 = instruction_binary[5 :4 ];
110
+ wire [2 :0 ] mblock_s2 = instruction_binary[8 :6 ];
95
111
wire [2 :0 ] mblock_s3 = instruction_binary[11 :9 ];
96
112
wire [7 :0 ] vrw_source = instruction_binary[23 :16 ];
97
113
wire [7 :0 ] vr_source = instruction_binary[31 :24 ];
@@ -108,40 +124,113 @@ module CHIPSET(
108
124
109
125
// STAGE2
110
126
wire [31 :0 ] vr_value;
111
- REGISTER_up_16b r_ins_bin (
112
- .out(_vr_value),
113
- .in(_instruction_binary),
127
+ REGISTER_up_16b stage2_r0 (
128
+ .out(vr_value[31 :16 ]),
129
+ .in(_vr_value[31 :16 ]),
130
+ .clk(clk[2 ]));
131
+ REGISTER_up_16b stage2_r1 (
132
+ .out(vr_value[15 :0 ]),
133
+ .in(_vr_value[15 :0 ]),
114
134
.clk(clk[2 ]));
115
135
116
- // TODO: Ensure MBLOCK supplies expectations.
117
- // MBLOCK_MUX is expected to fetch MBLOCK based on v0_source and
118
- // instruction_op breakdowns and redirect the value into v0.
119
-
120
- // @stage2 posedge following should freeze.
121
- wire [31 :0 ] vrw_value;
122
- FETCH_AND_STORE stage2 (
136
+ wire [31 :0 ] _vrw_value;
137
+ wire [31 :0 ] _vw_value;
138
+ wire _alu_is_zero;
139
+ STAGE2 stage2 (
123
140
.vrw_value(vrw_value),
124
- .is_powered_on(is_powered_on),
141
+ .vw_value(vw_value),
142
+ .ram_address(ram_address_stage2),
143
+ .alu_is_zero(alu_is_zero),
144
+ .mblock_s2(mblock_s2),
125
145
.vr_source(vr_source),
126
146
.vr_value(vr_value),
127
- .vrw_source(vr_source),
128
- .mblock_s2(mblock_s2),
129
- .clk(clk2));
147
+ .vrw_source(vrw_source),
148
+ .alu_op(mblock_alu_op),
149
+ .pc(pc),
150
+ .ram_value(ram_value));
130
151
152
+ // STAGE3
153
+ wire [31 :0 ] vrw_value;
131
154
wire [31 :0 ] vw_value;
132
- ALU alu (
133
- .out(vw_value),
134
- .is_zero(flags[FLAGS_BIT_VW_ZERO]),
135
- .vr_value(vr_value),
136
- .vrw_value(vrw_value),
137
- .op(mblock_alu_op));
155
+ wire alu_is_zero;
156
+ REGISTER_up_16b stage3_r0a (
157
+ .out(vrw_value[31 :16 ]),
158
+ .in(_vrw_value[31 :16 ]),
159
+ .clk(clk[3 ]));
160
+ REGISTER_up_16b stage3_r0b (
161
+ .out(vrw_value[15 :0 ]),
162
+ .in(_vrw_value[15 :0 ]),
163
+ .clk(clk[3 ]));
164
+ REGISTER_up_16b stage3_r1a (
165
+ .out(vw_value[31 :16 ]),
166
+ .in(_vw_value[31 :16 ]),
167
+ .clk(clk[3 ]));
168
+ REGISTER_up_16b stage3_r1b (
169
+ .out(vw_value[15 :0 ]),
170
+ .in(_vw_value[15 :0 ]),
171
+ .clk(clk[3 ]));
172
+ wire [14 :0 ] unused0;
173
+ REGISTER_up_16b stage3_r2 (
174
+ .out({unused0, alu_is_zero}),
175
+ .in({15'bzzzzzzzzzzzzzzz , _alu_is_zero}),
176
+ .clk(clk[3 ]));
138
177
139
- // @stage3 posedge following should freeze.
140
- FETCH_AND_STORE stage2 (
141
- .vw_value(vw_value),
178
+
179
+ wire execute_from_ram_new;
180
+ wire is_powered_on_new;
181
+ wire [15 :0 ] pc_next;
182
+
183
+ STAGE3 stage3 (
184
+ .output_devices_value(output_devices_value),
185
+ .output_devices_address(output_devices_address),
186
+ .ram_address(ram_address_stage3),
187
+ .ram_in(ram_in),
188
+ .ram_is_write(ram_is_write),
189
+ .output_is_write(output_is_write),
190
+ .pc_next(pc_next),
191
+ .execute_from_ram_new(execute_from_ram_new),
192
+ .is_powered_on_new(is_powered_on_new),
193
+ .mblock_s3(mblock_s3),
142
194
.vrw_value(vrw_value),
195
+ .vw_value(vw_value),
143
196
.vrw_source(vrw_source),
144
- .mblock_s3(mblock_s3),
145
- .clk(clk3));
197
+ .pc(pc),
198
+ .is_powered_on(is_powered_on),
199
+ .flag_last_zero(flag_last_zero),
200
+ .execute_from_ram(flag_execute_from_ram),
201
+ .reset_button(reset_button));
202
+
203
+ wire [12 :0 ] unused1;
204
+ REGISTER_down_16b stage3_r3 (
205
+ .out({unused1, flag_last_zero, is_powered_on, flag_execute_from_ram}),
206
+ .in({13'bzzzzzzzzzzzzz , alu_is_zero, is_powered_on_new, execute_from_ram_new}),
207
+ .clk(clk[3 ]));
208
+
209
+ REGISTER_down_16b stage3_r4 (
210
+ .out(pc),
211
+ .in(pc_next),
212
+ .clk(clk[3 ]));
213
+
214
+ always @(negedge clk[0 ]) begin
215
+ $display ("Stage0: power=%b pc=%b ins=%b eram=%b" ,
216
+ is_powered_on_new, pc, _instruction_binary, flag_execute_from_ram);
217
+ end
218
+ always @(negedge clk[1 ]) begin
219
+ $display ("Stage1: alu=%b s1=%b s2=%b s3=%b vrw_source=%b vr_source=%b" ,
220
+ mblock_alu_op, mblock_s1, mblock_s2, mblock_s3, vrw_source, vr_source);
221
+ end
222
+ always @(negedge clk[2 ]) begin
223
+ $display ("Stage2: vr_value=%b" ,
224
+ vr_value);
225
+ end
226
+ always @(negedge clk[3 ]) begin
227
+ $display ("Stage3: vrw_value=%b, vw_value=%b is_zero=%b" ,
228
+ vrw_value, vw_value, alu_is_zero);
229
+ end
230
+ always @(posedge clk[0 ]) begin
231
+ $display ("StageE: power=%b, f_zero=%b, f_eram=%b pc=%b" ,
232
+ is_powered_on, flag_last_zero, flag_execute_from_ram, pc);
233
+ end
234
+
146
235
147
236
endmodule
0 commit comments