Skip to content

Commit 6a45bed

Browse files
committed
Verilog jmp to program from bootsequence complete
1 parent 5c4ca00 commit 6a45bed

24 files changed

+640
-198
lines changed

emulator/chipset.v

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
`include "emulator/com/stage1.v"
44
`include "emulator/com/stage2.v"
55
`include "emulator/com/stage3.v"
6-
`include "emulator/com/input_devices.v"
76
`include "emulator/com/rom.v"
87
`include "emulator/seq/clock.v"
98
`include "emulator/seq/register.v"
10-
`include "emulator/seq/output_devices.v"
9+
`include "emulator/seq/io_devices.v"
1110
`include "emulator/seq/ram.v"
1211

1312
module CHIPSET(
@@ -30,7 +29,8 @@ module CHIPSET(
3029
// BROM
3130
wire[15:0] brom_address;
3231
wire[31:0] brom_value;
33-
ROM_BOOT brom(.out(brom_value), .address(brom_address));
32+
ROM_BOOT #(.filename("output/programs/boot_sequence.bin"))
33+
brom(.out(brom_value), .address(brom_address));
3434

3535
// RAM
3636
wire ram_is_write;
@@ -55,34 +55,33 @@ module CHIPSET(
5555
.A2(ram_address_stage2),
5656
.A3(ram_address_stage3),
5757
.S(clk_stage));
58-
59-
// TODO: Updated ram_address
60-
assign ram_address = ram_address_stage0;
61-
62-
// Input Devices
63-
wire[7:0] input_devices_address;
58+
// always @(ram_address, ram_address_stage0, ram_address_stage1, ram_address_stage2, ram_address_stage3, clk_stage)
59+
// begin
60+
// $display("add:%b, s0:%b, s1:%b, s2:%b, s3:%b, stage:%b", ram_address, ram_address_stage0, ram_address_stage1, ram_address_stage2, ram_address_stage3, clk_stage);
61+
// end
62+
63+
// IO Devices
64+
wire[7:0] io_device_id_s1;
65+
wire[7:0] io_device_id_s3;
66+
wire[7:0] io_device_id;
6467
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)
71-
);
72-
73-
// Output Devices
7468
wire[31:0] output_devices_value;
75-
wire[7:0] output_devices_address;
7669
wire output_is_write;
7770

78-
OutputDevices odevices(
79-
// .device0_values(device0_values),
80-
// .device1_values(device1_values),
81-
.address(output_devices_address),
82-
.value(output_devices_value),
71+
IODevices io_devices(
72+
.value_out(input_devices_value),
73+
.device_id(io_device_id),
74+
.value_in(output_devices_value),
8375
.is_write(output_is_write),
8476
.clk(clk[3]));
8577

78+
wire[7:0] unused2;
79+
MUX_1_16b io_device_id_selector(
80+
.value({unused2, io_device_id}),
81+
.A0({unused2, io_device_id_s1}),
82+
.A1({unused2, io_device_id_s3}),
83+
.S(clk_stage[1]));
84+
8685
// STAGE0
8786
wire[31:0] _instruction_binary;
8887
STAGE0 stage0(
@@ -115,8 +114,8 @@ module CHIPSET(
115114
wire[31:0] _vr_value;
116115
STAGE1 stage1(
117116
.vr_value(_vr_value),
118-
.input_devices_address(input_devices_address),
119-
.ram_address(ram_address),
117+
.io_device_id(io_device_id_s1),
118+
.ram_address(ram_address_stage1),
120119
.mblock_s1(mblock_s1),
121120
.vr_source(vr_source),
122121
.input_devices_value(input_devices_value),
@@ -137,10 +136,10 @@ module CHIPSET(
137136
wire[31:0] _vw_value;
138137
wire _alu_is_zero;
139138
STAGE2 stage2(
140-
.vrw_value(vrw_value),
141-
.vw_value(vw_value),
139+
.vrw_value(_vrw_value),
140+
.vw_value(_vw_value),
142141
.ram_address(ram_address_stage2),
143-
.alu_is_zero(alu_is_zero),
142+
.alu_is_zero(_alu_is_zero),
144143
.mblock_s2(mblock_s2),
145144
.vr_source(vr_source),
146145
.vr_value(vr_value),
@@ -182,7 +181,7 @@ module CHIPSET(
182181

183182
STAGE3 stage3(
184183
.output_devices_value(output_devices_value),
185-
.output_devices_address(output_devices_address),
184+
.io_device_id(io_device_id_s3),
186185
.ram_address(ram_address_stage3),
187186
.ram_in(ram_in),
188187
.ram_is_write(ram_is_write),
@@ -211,26 +210,24 @@ module CHIPSET(
211210
.in(pc_next),
212211
.clk(clk[3]));
213212

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-
235-
213+
// always @(negedge clk[0]) begin
214+
// $display("Stage0: power=%b pc=%x ins=%b eram=%b",
215+
// is_powered_on_new, pc, _instruction_binary, flag_execute_from_ram);
216+
// end
217+
// always @(negedge clk[1]) begin
218+
// $display("Stage1: alu=%b s1=%b s2=%b s3=%b vrw_source=%x vr_source=%x",
219+
// mblock_alu_op, mblock_s1, mblock_s2, mblock_s3, vrw_source, vr_source);
220+
// end
221+
// always @(negedge clk[2]) begin
222+
// $display("Stage2: vr_value=%x",
223+
// vr_value);
224+
// end
225+
// always @(negedge clk[3]) begin
226+
// $display("Stage3: vrw_value=%x, vw_value=%x is_zero=%b",
227+
// vrw_value, vw_value, alu_is_zero);
228+
// end
229+
// always @(posedge clk[0]) begin
230+
// $display("StageE: power=%b, f_zero=%b, f_eram=%b pc=%x write_ram=%b wrire_io=%b",
231+
// is_powered_on, flag_last_zero, flag_execute_from_ram, pc, ram_is_write, output_is_write);
232+
// end
236233
endmodule

emulator/chipset_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module chipset_test;
1818
reset_button = 1;
1919
# 80
2020
reset_button = 0;
21-
# 100
21+
# 200000
2222
if (reset_button !== 0) begin
2323
$error("chipset failed");
2424
$fatal(1);

emulator/com/alu.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module ALU (
1313
always @(op, in_r, in_rw) begin
1414
case(op)
1515
4'b0000: mem = in_r+in_rw;
16-
4'b0001: mem = in_r-in_rw;
17-
4'b0010: mem = (in_r<<in_rw);
18-
4'b0011: mem = (in_r>>in_rw);
16+
4'b0001: mem = in_rw-in_r;
17+
4'b0010: mem = (in_rw<<in_r);
18+
4'b0011: mem = (in_rw>>in_r);
1919
4'b0100: mem = (in_r);
2020
4'b0101: mem = (in_rw);
2121
4'b0110: mem = (in_r&in_rw);

emulator/com/alu_test.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module alu_test;
2727

2828
// SUB
2929
op = 4'b0001;
30-
in_r = 2536;
31-
in_rw = 113;
30+
in_r = 113;
31+
in_rw = 2536;
3232
# 10
3333
$display("ALU_TEST: op=%b in_r=%b in_rw=%b", op, in_r, in_rw);
3434
if (out !== 2423 || is_zero !== 0) begin
@@ -38,8 +38,8 @@ module alu_test;
3838

3939
// LSR
4040
op = 4'b0010;
41-
in_r = 2536;
42-
in_rw = 2;
41+
in_r = 2;
42+
in_rw = 2536;
4343
# 10
4444
$display("ALU_TEST: op=%b in_r=%b in_rw=%b", op, in_r, in_rw);
4545
if (out !== 10144 || is_zero !== 0) begin
@@ -49,8 +49,8 @@ module alu_test;
4949

5050
// RSR
5151
op = 4'b0011;
52-
in_r = 2536;
53-
in_rw = 4;
52+
in_r = 4;
53+
in_rw = 2536;
5454
# 10
5555
$display("ALU_TEST: op=%b in_r=%b in_rw=%b", op, in_r, in_rw);
5656
if (out !== 158 || is_zero !== 0) begin

emulator/com/input_devices.v

Lines changed: 0 additions & 15 deletions
This file was deleted.

emulator/com/input_devices_test.v

Lines changed: 0 additions & 35 deletions
This file was deleted.

emulator/com/mux.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module MUX_1_16b(
66
input [15:0] A0, A1,
77
input S);
88

9-
always @(*) begin
9+
always @(S, A0, A1) begin
1010
if (S) begin
1111
value = A1;
1212
end else begin
@@ -20,7 +20,7 @@ module MUX_2_16b(
2020
input [15:0] A0, A1, A2, A3,
2121
input [1:0] S);
2222

23-
always @(*) begin
23+
always @(S, A0, A1, A2, A3) begin
2424
case (S)
2525
2'b00: value = A0;
2626
2'b01: value = A1;

emulator/com/rom.v

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
`ifndef INCLUDED_ROM
2+
`define INCLUDED_ROM
3+
14
module _ROM_32bit_16aline(
25
output[31:0] out,
36
input[15:0] address);
@@ -19,12 +22,23 @@ endmodule
1922
module ROM_BOOT(
2023
output[31:0] out,
2124
input[15:0] address);
22-
// 4 * 64KB ROM
25+
parameter filename = "emulator/com/rom_boot.bin";
2326
reg[15:0] eaddress;
2427
always @(address) begin
2528
eaddress = address - 'h40;
2629
end
27-
_ROM_32bit_16aline #(.filename("emulator/com/rom_boot.bin"))
28-
dut(.out(out),
30+
_ROM_32bit_16aline #(.filename(filename))
31+
_rom(.out(out),
2932
.address(eaddress));
3033
endmodule
34+
35+
module ROM_PINGPONG(
36+
output[31:0] out,
37+
input[15:0] address);
38+
parameter filename = "output/programs/ping_pong.bin";
39+
_ROM_32bit_16aline #(.filename(filename))
40+
_rom(.out(out),
41+
.address(address));
42+
endmodule
43+
44+
`endif

emulator/com/stage1.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module STAGE1(
44
output[31:0] vr_value,
5-
output[7:0] input_devices_address,
5+
output[7:0] io_device_id,
66
output[15:0] ram_address,
77
input[1:0] mblock_s1,
88
input[7:0] vr_source,
@@ -11,7 +11,7 @@ module STAGE1(
1111

1212
wire[31:0] _const_value;
1313

14-
assign input_devices_address = vr_source;
14+
assign io_device_id = vr_source;
1515
assign _const_value[7:0] = vr_source;
1616
assign _const_value[31:8] = 24'b000000000000000000000000;
1717
assign ram_address[7:0] = vr_source;

emulator/com/stage1_test.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module stage1_test;
44
wire[31:0] vr_value;
5-
wire[7:0] input_devices_address;
5+
wire[7:0] io_device_id;
66
wire[15:0] ram_address;
77

88
reg[1:0] mblock_s1;
@@ -12,7 +12,7 @@ module stage1_test;
1212

1313
STAGE1 dut(
1414
.vr_value(vr_value),
15-
.input_devices_address(input_devices_address),
15+
.io_device_id(io_device_id),
1616
.ram_address(ram_address),
1717
.mblock_s1(mblock_s1),
1818
.vr_source(vr_source),
@@ -34,8 +34,8 @@ module stage1_test;
3434
# 10
3535
mblock_s1 = 2;
3636
# 10
37-
$display("STAGE1_TEST: vr_value=%b input_devices_address=%b", vr_value, input_devices_address);
38-
if (vr_value !== 22 || input_devices_address !== 33) begin
37+
$display("STAGE1_TEST: vr_value=%b io_device_id=%b", vr_value, io_device_id);
38+
if (vr_value !== 22 || io_device_id !== 33) begin
3939
$error("stage1 failed");
4040
$fatal(1);
4141
end

0 commit comments

Comments
 (0)