Skip to content

Commit 5c4ca00

Browse files
committed
Verilog basic chipset ready
1 parent a7b9f82 commit 5c4ca00

28 files changed

+327
-477
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OUTPUT_DIR=output
44

55
.PHONY: clean test all run_ping_pong all_programs_binary all_programs_resolved
66

7-
all: all_programs_binary all_programs_resolved
7+
all: all_programs_binary all_programs_resolved verilog_modules
88

99
clean:
1010
rm -rf $(BUILD_DIR)

emulator/Makefile.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
BUILD_EMULATOR = $(BUILD_DIR)/emulator
22
SRC_EMULATOR = $(SRC_DIR)/emulator
33

4-
.PHONY: test_verilog_modules
4+
.PHONY: verilog_modules test_verilog_modules
55

66
$(BUILD_EMULATOR)/%_test: $(SRC_EMULATOR)/%_test.v
77
mkdir -p $(dir $@)
88
iverilog -o $@ $^
99

10+
verilog_modules: $(patsubst $(SRC_EMULATOR)/%_test.v, $(BUILD_EMULATOR)/%_test, $(shell find $(SRC_EMULATOR) -name '*_test.v'))
11+
1012
test_verilog_modules: $(patsubst $(SRC_EMULATOR)/%_test.v, $(BUILD_EMULATOR)/%_test, $(shell find $(SRC_EMULATOR) -name '*_test.v'))
1113
$(foreach test_name, $^, echo "Executing $(test_name)" && ./$(test_name))

emulator/chipset.v

Lines changed: 159 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
`include "emulator/module/clock.v"
2-
`include "emulator/seq/register.v"
1+
`include "emulator/com/mux.v"
32
`include "emulator/com/stage0.v"
43
`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"
612

713
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;
1822

1923
// Clock
2024
wire[0:3] clk;
25+
wire[1:0] clk_stage;
2126
CLOCK clock(
22-
.clk(clk[0:3]));
27+
.clk(clk[0:3]),
28+
.clk_stage(clk_stage));
2329

2430
// BROM
2531
wire[15:0] brom_address;
2632
wire[31:0] brom_value;
2733
ROM_BOOT brom(.out(brom_value), .address(brom_address));
2834

2935
// RAM
30-
reg ram_is_write;
36+
wire ram_is_write;
3137
wire[15:0] ram_address;
32-
reg[31:0] ram_in;
38+
wire[31:0] ram_in;
3339
wire[31:0] ram_value;
3440
RAM_32bit_16aline ram(
3541
.out(ram_value),
@@ -38,39 +44,45 @@ module CHIPSET(
3844
.is_write(ram_is_write),
3945
.clk(clk[3]));
4046

41-
4247
wire[15:0] ram_address_stage0;
4348
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+
4459
// TODO: Updated ram_address
4560
assign ram_address = ram_address_stage0;
4661

4762
// Input Devices
4863
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)
7271
);
7372

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+
7486
// STAGE0
7587
wire[31:0] _instruction_binary;
7688
STAGE0 stage0(
@@ -84,14 +96,18 @@ module CHIPSET(
8496

8597
// STAGE1
8698
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]),
90106
.clk(clk[1]));
91107

92108
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];
95111
wire[2:0] mblock_s3 = instruction_binary[11:9];
96112
wire[7:0] vrw_source = instruction_binary[23:16];
97113
wire[7:0] vr_source = instruction_binary[31:24];
@@ -108,40 +124,113 @@ module CHIPSET(
108124

109125
// STAGE2
110126
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]),
114134
.clk(clk[2]));
115135

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(
123140
.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),
125145
.vr_source(vr_source),
126146
.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));
130151

152+
// STAGE3
153+
wire[31:0] vrw_value;
131154
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]));
138177

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),
142194
.vrw_value(vrw_value),
195+
.vw_value(vw_value),
143196
.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+
146235

147236
endmodule

emulator/chipset_test.v

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
// `include "emulator/chipset.v"
1+
`include "emulator/chipset.v"
22

33
module chipset_test;
4-
// wire reset; // reset button
5-
// CHIPSET dut(.reset(reset));
4+
reg reset_button;
65

7-
// initial begin
8-
// assign reset = 0; // button is never pressed.
9-
// end
6+
wire is_powered_on;
7+
wire flag_execute_from_ram;
8+
wire[15:0] pc;
9+
CHIPSET dut(
10+
.reset_button(reset_button),
11+
.pc(pc),
12+
.is_powered_on(is_powered_on),
13+
.flag_execute_from_ram(flag_execute_from_ram));
14+
15+
initial begin
16+
reset_button = 0;
17+
# 80
18+
reset_button = 1;
19+
# 80
20+
reset_button = 0;
21+
# 100
22+
if (reset_button !== 0) begin
23+
$error("chipset failed");
24+
$fatal(1);
25+
end
26+
$finish();
27+
end
1028
endmodule

emulator/com/input_devices.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module InputDevices(
22
output[31:0] value,
3-
input[15:0] address,
3+
input[7:0] address,
44
input[31:0] device0_values,
55
input[31:0] device1_values);
66

emulator/com/input_devices_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module InputDevices_test;
66

77
reg[31:0] device0_values = INPUT1;
88
reg[31:0] device1_values = INPUT2;
9-
reg[15:0] address;
9+
reg[7:0] address;
1010

1111
wire[31:0] value;
1212

emulator/com/mux.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
`ifndef INCLUDED_MUX
2+
`define INCLUDED_MUX
3+
14
module MUX_1_16b(
25
output reg [15:0] value,
36
input [15:0] A0, A1,
@@ -26,3 +29,4 @@ module MUX_2_16b(
2629
endcase
2730
end
2831
endmodule
32+
`endif

0 commit comments

Comments
 (0)