Skip to content

Commit 186f92f

Browse files
committed
Move Makefiles rules around, improve verilog IPC
1 parent a54b0be commit 186f92f

File tree

9 files changed

+110
-76
lines changed

9 files changed

+110
-76
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SRC_DIR=.
22
BUILD_DIR=build
33
OUTPUT_DIR=output
44

5-
.PHONY: clean test all run_ping_pong all_programs_binary all_programs_resolved
5+
.PHONY: clean test all run_verilog_io run_ping_pong all_programs_binary all_programs_resolved output_rom_binaries
66

77
all: all_programs_binary all_programs_resolved verilog_modules
88

@@ -19,6 +19,8 @@ test: pytest test_verilog_modules
1919

2020
all_programs_binary: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%.bin, $(shell find programs/ -name '*.asm'))
2121

22+
output_rom_binaries: $(OUTPUT_DIR)/programs/boot_sequence.bin $(OUTPUT_DIR)/programs/ping_pong.bin
23+
2224
$(OUTPUT_DIR)/programs/%.bin: programs/%.asm
2325
mkdir -p $(dir $@)
2426
python3 -m planner asm -b $^ > $@
@@ -31,3 +33,6 @@ $(OUTPUT_DIR)/programs/%_resolved.asm: programs/%.asm
3133

3234
run_ping_pong:
3335
python3 -m planner compile_and_execute ping_pong
36+
37+
run_verilog_io:
38+
python3 -m planner verilog_io

emulator/Makefile.mk

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

4-
.PHONY: verilog_modules test_verilog_modules
4+
.PHONY: verilog_modules test_verilog_modules verilog_data_prerequisites verilog_simulate
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'))
10+
verilog_modules: $(BUILD_EMULATOR)/executable_chipset $(patsubst $(SRC_EMULATOR)/%_test.v, $(BUILD_EMULATOR)/%_test, $(shell find $(SRC_EMULATOR) -name '*_test.v'))
1111
mkdir -p $(BUILD_EMULATOR)/io
1212

13+
verilog_data_prerequisites: output_rom_binaries
14+
1315
test_verilog_modules: $(patsubst $(SRC_EMULATOR)/%_test.v, $(BUILD_EMULATOR)/%_test, $(shell find $(SRC_EMULATOR) -name '*_test.v'))
16+
$(MAKE) verilog_data_prerequisites
1417
$(foreach test_name, $^, echo "Executing $(test_name)" && ./$(test_name))
1518

16-
$(BUILD_EMULATOR)/module/libipc.so: $(SRC_EMULATOR)/module/ipc.cpp
17-
mkdir -p $(dir $@)
18-
g++ -shared -Wl,-soname,libipc.so -o $@ -fPIC $^
19-
20-
$(BUILD_EMULATOR)/module/ipc.py: $(SRC_EMULATOR)/module/ipc.py $(BUILD_EMULATOR)/module/libipc.so
19+
$(BUILD_EMULATOR)/executable_chipset: $(SRC_EMULATOR)/executable_chipset.v
20+
$(MAKE) verilog_data_prerequisites
2121
mkdir -p $(dir $@)
22-
cp -f $< $@
22+
iverilog -o $@ $^
2323

24-
$(BUILD_EMULATOR)/module/ipc.o: $(SRC_EMULATOR)/module/ipc.cpp
25-
mkdir -p $(dir $@)
26-
g++ -o $@ $^
24+
verilog_simulate: $(BUILD_EMULATOR)/executable_chipset
25+
./$^ | $(MAKE) run_verilog_io

emulator/chipset_test.v renamed to emulator/executable_chipset.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ module chipset_test;
2323
$error("chipset failed");
2424
$fatal(1);
2525
end
26-
// $finish();
2726
end
2827
endmodule

emulator/module/ipc.v

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
`define INPUT_FILE "/tmp/ourpc_input"
2+
13
// Handle Inter Process Communication
2-
// We were not able to figure out simpler way to do so.
4+
// We weren't able to figure out simpler way to do so.
35
module IPCOut(
4-
input[15:0] process_id,
6+
input[7:0] device_id,
57
input[31:0] value
68
);
79

810
always @(value) begin
9-
$display("IPC %x %x", process_id, value);
11+
$display("IPC %x %x", device_id, value);
12+
end
13+
endmodule
14+
15+
module IPCIn(
16+
output[31:0] value,
17+
input[7:0] device_id,
18+
input clk);
19+
20+
// device_id to value
21+
reg[31:0] _ipc_input[0:7];
22+
always @(posedge clk) begin
23+
// At some random interval
24+
$readmemb(`INPUT_FILE, _ipc_input);
25+
end
26+
reg[31:0] _value;
27+
always @(*) begin
28+
_value <= _ipc_input[device_id];
1029
end
30+
assign value = _value;
1131
endmodule

emulator/module/ipc_test.v

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,57 @@
11
`include "emulator/module/ipc.v"
22

3-
module ipc_test;
4-
reg[15:0] process_id;
3+
module ipc_out_test;
4+
reg[7:0] device_id;
55
reg[31:0] value;
66

7-
IPCOut dut(.process_id(process_id[15:0]), .value(value[31:0]));
7+
IPCOut dut(.device_id(device_id[7:0]), .value(value[31:0]));
88

99
initial begin
1010
# 5
11-
process_id = 10;
11+
device_id = 10;
1212
# 1
1313
value = 20;
14+
// Not test here, output goes to stdout.
15+
end
16+
endmodule
17+
18+
module ipc_in_test;
19+
reg[7:0] device_id;
20+
reg clk;
21+
output[31:0] value;
22+
23+
IPCIn dut(.value(value[31:0]), .device_id(device_id[7:0]), .clk(clk));
24+
25+
integer f;
26+
initial begin
27+
# 5
28+
f = $fopen("/tmp/ourpc_input", "w");
29+
$fwrite(f,"00000000000000000000000000000001\n");
30+
$fwrite(f,"11111111111111111111111111111111\n");
31+
$fwrite(f,"01010101010101010101010101010101\n");
32+
$fwrite(f,"10101010101010101010101010101010\n");
33+
$fwrite(f,"00000000000000000000000011111111\n");
34+
$fwrite(f,"11111111000000000000000000000000\n");
35+
$fwrite(f,"01010101101010100101010110101010\n");
36+
$fwrite(f,"10101010010101011010101001010101\n");
37+
$fclose(f);
38+
39+
device_id = 1;
40+
clk = 0;
41+
# 5
42+
clk = 1;
43+
# 5
44+
if (value !== 32'b11111111111111111111111111111111) begin
45+
$error("ipc input failed, got: %b", value);
46+
$fatal(1);
47+
end
48+
device_id = 6;
1449
# 1
15-
value = 25;
16-
# 1
17-
value = 30;
50+
if (value !== 32'b01010101101010100101010110101010) begin
51+
$error("ipc input failed, got: %b", value);
52+
$fatal(1);
53+
end
54+
1855
end
1956
endmodule
2057

emulator/seq/io.c

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

emulator/seq/io_devices.v

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
`define CONSDEV_ID 3
44
`define PROM_ID 2
55

6-
`define IO_DIR "build/emulator/io"
7-
8-
// Import the function called "system_init" implemented in C code
9-
106
module IODevices(
117
output[31:0] value_out,
128
input[7:0] device_id,
@@ -16,55 +12,34 @@ module IODevices(
1612

1713
integer fio;
1814

19-
reg[31:0] _data [255:0];
20-
initial begin
21-
// $fseek(fio, 0, 0);
22-
// system_init();
23-
end
24-
reg[15:0] process_id;
25-
// assign
2615
reg[31:0] value;
27-
IPCOut ipcout(.process_id(process_id[15:0]), .value(value[31:0]));
16+
output[31:0] value_ipc_in;
17+
18+
IPCOut ipcout(.device_id(device_id[7:0]), .value(value[31:0]));
19+
IPCIn ipcin(.value(value_ipc_in[31:0]), .device_id(device_id[7:0]), .clk(clk));
2820

2921
always @(negedge clk) begin
3022
// Write are triggered at negedge
3123
if (is_write) begin
32-
_data[device_id] <= value_in;
33-
process_id <= {8'b00000000, device_id};
3424
value <= value_in;
35-
36-
37-
// fio = $fopen("build/emulator/io/output.txt","w");
38-
// $fseek(fio, 0, 0);
39-
// $fwrite(fio, "%b\n", value_in);
40-
// $fflush(fio);
41-
// $fclose(fio);
4225
$display("IO:output[%x] <= %x", device_id, value_in);
4326
end
4427
end
4528

46-
reg[31:0] _ipc_input[0:15];
47-
// integer i;
48-
always @(posedge clk) begin
49-
// At some random interval
50-
$readmemb("/tmp/ourpc_input.txt", _ipc_input);
51-
// for (i=0; i<16; i=i+1) begin
52-
// $display("INPUT[%d]: %x", i, _ipc_input[i]);
53-
// end
54-
end
55-
5629
// PROM
5730
wire[31:0] prom_value;
58-
ROM_PINGPONG prom(.out(prom_value), .address(_data[`PROM_ID][15:0]));
31+
ROM_PINGPONG prom(.out(prom_value), .address(value_in[15:0]));
5932

6033
reg[31:0] _value;
6134
always @(device_id) begin
6235
case (device_id)
36+
// TODO: Is it ok to use continous circuit with value_in as address?
6337
`PROM_ID: _value <= prom_value;
38+
`CONSDEV_ID: _value <= value_in;
6439
default:
40+
// Goes via IPC
6541
begin
66-
_value <= _ipc_input[device_id];
67-
// $display("IO:input[%x] <= %x", device_id, _value);
42+
_value <= value_ipc_in;
6843
end
6944
endcase
7045
end

emulator/seq/io_devices_test.v

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,38 @@ module IODevices_test;
2020

2121
initial begin
2222
device_id = 1;
23-
is_write = 1;
23+
is_write = 0;
2424
value_in = INPUT1;
2525
clk = 1;
2626
# 10
2727
clk = 0;
2828
# 10
29-
device_id = 0;
29+
device_id = 3; // const
30+
# 5
3031
$display("IO_DEVICES_TEST: device_id=%b value_out=%b", device_id, value_out);
31-
if (value_out === INPUT1) begin
32+
if (value_out !== INPUT1) begin
3233
$error("io failed");
3334
$fatal(1);
3435
end
3536
# 10
36-
device_id = 1;
37+
device_id = 2; // PROM
38+
value_in = 0;
3739
# 10
3840
$display("IO_DEVICES_TEST: device_id=%b value_out=%b", device_id, value_out);
39-
if (value_out !== INPUT1) begin
41+
if (value_out === INPUT1) begin
42+
// not a great test but ok.
4043
$error("io failed");
4144
$fatal(1);
4245
end
46+
# 10
47+
device_id = 5; // IPC
48+
value_in = 10;
49+
is_write = 1;
50+
# 10
51+
clk = 0;
52+
# 10
53+
clk = 1;
54+
// trigger write
55+
// no verification, but it should generate logs.
4356
end
4457
endmodule

emulator/specs.py

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

0 commit comments

Comments
 (0)