Merge branch 'master' of github.com:MPSU/APS

This commit is contained in:
Andrei Solodovnikov
2024-09-12 09:20:06 +03:00
18 changed files with 335 additions and 350 deletions

View File

@@ -11,33 +11,36 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
module lab_01_tb_fulladder();
logic tb_a_i;
logic tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic tb_sum_o;
logic [2:0] test_case;
logic tb_a_i;
logic tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic tb_sum_o;
logic [2:0] test_case;
fulladder DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
fulladder DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
initial begin
$display("\nTest has been started\n");
initial begin
$display("\nTest has been started\n");
#5ns;
test_case = 3'd0;
repeat(8) begin
#5ns;
test_case = 3'd0;
repeat(8) begin
#5ns;
test_case++;
end
$display("\nTest has been finished. Check results at waveform window.\n");
$finish();
test_case++;
end
$display("\nTest has been finished. Check results at waveform window.\n");
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
endmodule

View File

@@ -11,72 +11,75 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
module lab_01_tb_fulladder32();
logic [31:0] tb_a_i;
logic [31:0] tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic [31:0] tb_sum_o;
logic [31:0] tb_a_i;
logic [31:0] tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic [31:0] tb_sum_o;
logic clk = 0;
always #5ns clk = ~clk;
logic clk = 0;
always #5ns clk = ~clk;
int err_cnt = 0;
int err_cnt = 0;
fulladder32 DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
fulladder32 DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
initial begin
$display("Test has been started");
sequential_add_test();
random_test();
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
$finish();
end
initial begin
$display("Test has been started");
sequential_add_test();
random_test();
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
task sequential_add_test();
@(posedge clk);
tb_a_i = 0;
tb_b_i = 0;
tb_carry_i = 0;
@(posedge clk);
for(int i = 0; i < 16; i++) begin
tb_a_i += 256;
for(int j = 0; j < 16; j++) begin
tb_b_i += 256;
tb_carry_i = ~tb_carry_i;
@(posedge clk);
end
end
endtask
task random_test();
repeat(1e4) begin
tb_a_i = $urandom();
tb_b_i = $urandom();
tb_carry_i = $urandom_range(1);
task sequential_add_test();
@(posedge clk);
tb_a_i = 0;
tb_b_i = 0;
tb_carry_i = 0;
@(posedge clk);
for(int i = 0; i < 16; i++) begin
tb_a_i += 256;
for(int j = 0; j < 16; j++) begin
tb_b_i += 256;
tb_carry_i = ~tb_carry_i;
@(posedge clk);
end
endtask
logic [32:0] reference;
assign reference = {1'b0, tb_a_i} + {1'b0, tb_b_i} + tb_carry_i;
sum_check: assert property (
@(negedge clk)
reference === {tb_carry_o, tb_sum_o}
)
else begin
err_cnt++;
$error("\noperands : a_i = 0x%08h, b_i = 0x%08h, carry_i = %b\nyour res : sum = 0x%08h, carry_o = %b\nreference: sum = 0x%08h, carry_o = %b",
tb_a_i, tb_b_i, tb_carry_i, tb_sum_o, tb_carry_o, reference[31:0], reference [32]);
if(err_cnt == 10) begin
$display("\nTest has been stopped after 10 errors");
$stop();
end
end
endtask
task random_test();
repeat(1e4) begin
tb_a_i = $urandom();
tb_b_i = $urandom();
tb_carry_i = $urandom_range(1);
@(posedge clk);
end
endtask
logic [32:0] reference;
assign reference = {1'b0, tb_a_i} + {1'b0, tb_b_i} + tb_carry_i;
sum_check: assert property (
@(negedge clk)
reference === {tb_carry_o, tb_sum_o}
)
else begin
err_cnt++;
$error("\noperands : a_i = 0x%08h, b_i = 0x%08h, carry_i = %b\nyour res : sum = 0x%08h, carry_o = %b\nreference: sum = 0x%08h, carry_o = %b",
tb_a_i, tb_b_i, tb_carry_i, tb_sum_o, tb_carry_o, reference[31:0], reference [32]);
if(err_cnt == 10) begin
$display("\nTest has been stopped after 10 errors");
$stop();
end
end
endmodule

View File

@@ -11,33 +11,36 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
module lab_01_tb_fulladder4();
logic [3:0] tb_a_i;
logic [3:0] tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic [3:0] tb_sum_o;
logic [8:0] test_case;
logic [3:0] tb_a_i;
logic [3:0] tb_b_i;
logic tb_carry_i;
logic tb_carry_o;
logic [3:0] tb_sum_o;
logic [8:0] test_case;
fulladder4 DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
fulladder4 DUT (
.a_i(tb_a_i),
.b_i(tb_b_i),
.sum_o(tb_sum_o),
.carry_i(tb_carry_i),
.carry_o(tb_carry_o)
);
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
initial begin
$display("Test has been started");
initial begin
$display("Test has been started");
#5ns;
test_case = 9'd0;
repeat(512) begin
#5ns;
test_case = 9'd0;
repeat(512) begin
#5ns;
test_case++;
end
$display("\nTest has been finished Check results at waveform window.\n");
$finish();
test_case++;
end
$display("\nTest has been finished Check results at waveform window.\n");
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
endmodule

View File

@@ -45,7 +45,7 @@ module nexys_alu(
logic [31:0] result;
logic flag;
alu_riscv alu_riscv (
alu alu_riscv (
.alu_op_i (operator),
.a_i (operand_a),
.b_i (operand_b),

View File

@@ -63,6 +63,9 @@ initial
direct_test();
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
task X_test();
@@ -247,23 +250,22 @@ end
endmodule
parameter ALUOP_W = 5;
parameter OP_W = 32;
parameter SHIFT_W = $clog2(OP_W);
parameter STAGE_LEN = OP_W+1;
parameter HASH_LEN = 1000;
parameter START_CODING = 10366;
parameter START_MUX = START_CODING+100;
module alu_ref (
input logic [ALUOP_W-1:0] alu_op_i,
input logic [OP_W-1:0] a_i,
input logic [OP_W-1:0] b_i,
output logic [OP_W-1:0] result_o,
output logic flag_o
input logic [ 4:0] alu_op_i,
input logic [31:0] a_i,
input logic [31:0] b_i,
output logic [31:0] result_o,
output logic flag_o
);
localparam ALUOP_W = 5;
localparam OP_W = 32;
localparam SHIFT_W = $clog2(OP_W);
localparam STAGE_LEN = OP_W+1;
localparam HASH_LEN = 1000;
localparam START_CODING = 10366;
localparam START_MUX = START_CODING+100;
genvar i, j, k;

View File

@@ -34,7 +34,7 @@ module nexys_rf_riscv(
logic [7:0][3:0] rd1;
logic [7:0][3:0] rd2;
rf_riscv rf_riscv (
register_file rf_riscv (
.clk_i (clk_i),
.read_addr1_i (ra1 ),
.read_addr2_i (ra2 ),

View File

@@ -10,146 +10,177 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
*/
module lab_03_tb_register_file();
logic CLK;
logic [ 4:0] RA1;
logic [ 4:0] RA2;
logic [ 4:0] WA;
logic [31:0] WD;
logic WE;
logic CLK;
logic [ 4:0] RA1;
logic [ 4:0] RA2;
logic [ 4:0] WA;
logic [31:0] WD;
logic WE;
logic [31:0] RD1;
logic [31:0] RD2;
logic [31:0] RD1ref;
logic [31:0] RD2ref;
logic [31:0] RD1;
logic [31:0] RD2;
logic [31:0] RD1ref;
logic [31:0] RD2ref;
register_file DUT(
.clk_i (CLK),
.read_addr1_i (RA1),
.read_addr2_i (RA2),
.write_addr_i (WA ),
.write_data_i (WD ),
.write_enable_i(WE ),
.read_data1_o (RD1),
.read_data2_o (RD2)
);
register_file DUT(
.clk_i (CLK),
.read_addr1_i (RA1),
.read_addr2_i (RA2),
.write_addr_i (WA ),
.write_data_i (WD ),
.write_enable_i(WE ),
.read_data1_o (RD1),
.read_data2_o (RD2)
);
register_file_ref DUTref(
.clk_i (CLK ),
.read_addr1_i (RA1 ),
.read_addr2_i (RA2 ),
.write_addr_i (WA ),
.write_data_i (WD ),
.write_enable_i(WE ),
.read_data1_o (RD1ref),
.read_data2_o (RD2ref)
);
register_file_ref DUTref(
.clk_i (CLK ),
.read_addr1_i (RA1 ),
.read_addr2_i (RA2 ),
.write_addr_i (WA ),
.write_data_i (WD ),
.write_enable_i(WE ),
.read_data1_o (RD1ref),
.read_data2_o (RD2ref)
);
integer i, err_count = 0;
integer i, err_count = 0;
parameter CLK_FREQ_MHz = 100;
parameter CLK_SEMI_PERIOD= 1e3/CLK_FREQ_MHz/2;
parameter CLK_FREQ_MHz = 100;
parameter CLK_SEMI_PERIOD= 1e3/CLK_FREQ_MHz/2;
parameter address_length = 32;
parameter address_length = 32;
initial CLK <= 0;
always begin
#CLK_SEMI_PERIOD CLK = ~CLK;
if (err_count >= 10) begin
$display("\n\nThe test was stopped due to errors"); $stop();
end
initial CLK <= 0;
always begin
#CLK_SEMI_PERIOD CLK = ~CLK;
if (err_count >= 10) begin
$display("\n\nThe test was stopped due to errors"); $stop();
end
end
initial begin
$timeformat (-9, 2, "ns");
$display("Test has been started");
RA1 = 'b1;
initial begin
$timeformat (-9, 2, "ns");
$display("Test has been started");
RA1 = 'b1;
@(posedge CLK);
if (32'hx !== RD1) begin
$display("The register file should not be initialized by the $readmemh function");
err_count = err_count + 1;
end
@(posedge CLK);
DUT.rf_mem[32] = 32'd1;
if(DUT.rf_mem[32]=== 32'd1) begin
$display("invalid memory size");
err_count = err_count + 1;
end
RA1 <= 'b0;
RA2 <= 'b0;
@(posedge CLK);
if( RD1 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD1 = %h", $time, RD1);
err_count = err_count + 1;
end
if( RD2 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD2 = %h", $time, RD2);
err_count = err_count + 1;
end
@(posedge CLK);
WD <= 32'd1;
WA <= '0;
WE <= 1'b1;
@(posedge CLK);
WE <= 'b0;
RA1 <= 'b0;
@(posedge CLK);
if( RD1 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD1 = %h", $time, RD1);
err_count = err_count + 1;
end
@(posedge CLK);
//------initial
CLK <= 'b0;
RA1 <= 'b0;
RA2 <= 'b0;
WA <= 'b0;
WD <= 'b0;
WE <= 'b0;
@(posedge CLK);
//----- reset
for( i = 1; i < address_length; i = i + 1) begin
@(posedge CLK);
if (32'hx !== RD1) begin
$display("The register file should not be initialized by the $readmemh function");
err_count = err_count + 1;
end
@(posedge CLK);
DUT.rf_mem[32] = 32'd1;
if(DUT.rf_mem[32]=== 32'd1) begin
$display("invalid memory size");
err_count = err_count + 1;
end
RA1 <= 'b0;
RA2 <= 'b0;
@(posedge CLK);
if( RD1 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD1 = %h", $time, RD1);
err_count = err_count + 1;
end
if( RD2 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD2 = %h", $time, RD2);
err_count = err_count + 1;
end
@(posedge CLK);
WD <= 32'd1;
WA <= '0;
WE <= 1'b1;
@(posedge CLK);
WE <= 'b0;
RA1 <= 'b0;
@(posedge CLK);
if( RD1 !== 'b0 ) begin
$display("time = %0t. invalid data when reading at address 0: RD1 = %h", $time, RD1);
err_count = err_count + 1;
end
@(posedge CLK);
//------initial
CLK <= 'b0;
RA1 <= 'b0;
RA2 <= 'b0;
WA <= 'b0;
WD <= 'b0;
WE <= 'b0;
@(posedge CLK);
//----- reset
for( i = 1; i < address_length; i = i + 1) begin
@(posedge CLK);
WA <= i;
WD <= 'b0;
WE <= 'b1;
end
@(posedge CLK);
WA <= 'b0;
WD <= 'b1;
WA <= i;
WD <= 'b0;
WE <= 'b1;
end
@(posedge CLK);
WA <= 'b0;
WD <= 'b1;
WE <= 'b1;
@(posedge CLK);
WE <= 'b0;
RA2 <= 'b0;
@(posedge CLK);
if( RD2 !== 'b0 )begin
$display("time = %0t. invalid data when reading at address 0: RD2 = %h", $time, RD2);
err_count = err_count + 1;
end
@(posedge CLK);
for( i = 1; i < address_length; i = i + 1) begin
@(posedge CLK);
WE <= 'b0;
RA2 <= 'b0;
WA <= i;
WD <= $urandom;
WE <= $urandom % 2;
end
@(posedge CLK);
WE <= 'b0;
for( i = 0; i < address_length; i = i + 1) begin
@(posedge CLK);
if( RD2 !== 'b0 )begin
$display("time = %0t. invalid data when reading at address 0: RD2 = %h", $time, RD2);
RA1 <= i;
RA2 <= address_length - (i + 1);
@(posedge CLK);
if(RD1ref !== RD1) begin
$display("time = %0t, address %h, RD1. Invalid data %h, correct data %h", $time, RA1, RD1, RD1ref);
err_count = err_count + 1;
end
if(RD2ref !== RD2) begin
$display("time = %0t, address %h, RD2. Invalid data %h, correct data %h", $time, RA2, RD2, RD2ref);
err_count = err_count + 1;
end
end
//Incorrect read check
@(posedge CLK);
WA <= 5'd1;
WD <= 1;
WE <= 1'b1;
@(posedge CLK);
WA <= 5'd2;
WD <= 2;
WE <= 1'b1;
@(posedge CLK);
WE <= 1'b0;
RA1 <= 5'd1;
RA2 <= 5'd1;
@(posedge CLK);
WA <= 5'd31;
WE <= 1'b1;
WD <= 0;
RA1 <= 5'd2;
RA2 <= 5'd2;
@(posedge CLK);
if(RD1ref !== RD1) begin
$display("time = %0t, address %h, RD1. Invalid data %h, correct data %h", $time, RA1, RD1, RD1ref);
err_count = err_count + 1;
end
@(posedge CLK);
for( i = 1; i < address_length; i = i + 1) begin
@(posedge CLK);
WA <= i;
WD <= $urandom;
WE <= $urandom % 2;
end
@(posedge CLK);
WE <= 'b0;
for( i = 0; i < address_length; i = i + 1) begin
@(posedge CLK);
RA1 <= i;
RA2 <= address_length - (i + 1);
@(posedge CLK);
if(RD1ref !== RD1) begin
$display("time = %0t, address %h, RD1. Invalid data %h, correct data %h", $time, RA1, RD1, RD1ref);
err_count = err_count + 1;
end
if(RD2ref !== RD2) begin
$display("time = %0t, address %h, RD2. Invalid data %h, correct data %h", $time, RA2, RD2, RD2ref);
err_count = err_count + 1;
end
end
if( !err_count ) $display("\nregister file SUCCESS!!!\n");
$finish();
end
if(RD2ref !== RD2) begin
$display("time = %0t, address %h, RD2. Invalid data %h, correct data %h", $time, RA2, RD2, RD2ref);
err_count = err_count + 1;
end
$display("\nTest has been finished\nNumber of errors: %d\n", err_count);
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.")
$fatal();
end
endmodule

View File

@@ -36,6 +36,9 @@ module lab_04_tb_CYBERcobra();
#10000;
$display("\n The test is over \n See the internal signals of the CYBERcobra on the waveform \n");
$finish;
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
endmodule

View File

@@ -15,7 +15,7 @@ module lab_05_tb_decoder();
typedef class riscv_instr;
riscv_instr instr = new();
logic clk, test_has_been_finished;
logic clk;
logic [31:0] fetched_instr_i = '0;
int err_count;
@@ -136,8 +136,10 @@ module lab_05_tb_decoder();
illegal_instrs_random_test();
$display("\nTest has been finished\nNumber of errors: %d\n", err_count);
test_has_been_finished = 1'b1;
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
function void randomize_with_given_opcode(input logic[4:0] given_opcode);
@@ -348,17 +350,12 @@ module lab_05_tb_decoder();
bit test_paused_by_errs;
initial begin
clk = '0;
test_has_been_finished = '0;
err_count = '0;
test_paused_by_errs = '0;
end
always #5 clk = ~clk;
always @(posedge clk) begin
if(test_has_been_finished) begin
$finish();
end
end
always @(posedge clk) begin
if((err_count >= 10) & !test_paused_by_errs) begin

View File

@@ -30,8 +30,6 @@ module lab_06_tb_data_mem;
int err_cnt = 0;
static bit simulation_finished;
data_mem DUT (.*);
task read_request(input logic [31:0] address, output logic [31:0] data);
@@ -173,8 +171,10 @@ module lab_06_tb_data_mem;
random_test();
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
simulation_finished = 1;
$finish;
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
logic [31:0] ram_data;
@@ -275,13 +275,6 @@ module lab_06_tb_data_mem;
$display("Error at %t. ram[%d][31:24] is unstable without write request", $time(), $sampled(addr_reg));
end
always @(posedge clk_i) begin
if(simulation_finished) begin
$finish;
end
end
always @(posedge clk_i) begin
if (err_cnt >= 10) begin
$display("\nTest has been stopped after 10 errors"); $stop();

View File

@@ -98,7 +98,7 @@ module nexys_riscv_unit(
.O (bufg_clk )
);
riscv_unit unit(
processor_system unit(
.clk_i (bufg_clk),
.rst_i (!arstn_i)
);

View File

@@ -18,17 +18,20 @@ module lab_07_tb_processor_system();
.rst_i(rst)
);
initial clk = 0;
initial clk = 0;
always #10 clk = ~clk;
initial begin
$display( "\nTest has been started.");
rst = 1;
#40;
rst = 0;
#800;
$display("\n The test is over \n See the internal signals of the module on the waveform \n");
$finish;
end
$display( "\nTest has been started.");
rst = 1;
#40;
rst = 0;
#800;
$display("\n The test is over \n See the internal signals of the module on the waveform \n");
$finish;
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
stall_seq: assert property (
@(posedge system.core.clk_i) disable iff ( system.core.rst_i )

View File

@@ -63,6 +63,9 @@ initial begin
repeat(3e3)@(posedge clk_i);
$display("Simulation finished. Number of errors: %d", err_count);
$finish();
#5;
$display("You're trying to run simulation that has finished. Aborting simulation.");
$fatal();
end
initial begin

View File

@@ -1,6 +1,6 @@
/* -----------------------------------------------------------------------------
* Project Name : Architectures of Processor Systems (APS) lab work
* File : alu_riscv.sv
* File : alu.sv
* Organization : National Research University of Electronic Technology (MIET)
* Department : Institute of Microdevices and Control Systems
* Author(s) : Alexey Kozin
@@ -10,22 +10,22 @@ See LICENSE file for licensing details.
* ------------------------------------------------------------------------------
*/
parameter ALUOP_W = 5;
parameter OP_W = 32;
parameter SHIFT_W = $clog2(OP_W);
parameter STAGE_LEN = OP_W+1;
parameter HASH_LEN = 1000;
parameter START_CODING = 10366;
parameter START_MUX = START_CODING+100;
module alu_riscv (
input logic [ALUOP_W-1:0] alu_op_i,
input logic [OP_W-1:0] a_i,
input logic [OP_W-1:0] b_i,
output logic [OP_W-1:0] result_o,
output logic flag_o
module alu (
input logic [4:0] alu_op_i,
input logic [31:0] a_i,
input logic [31:0] b_i,
output logic [31:0] result_o,
output logic flag_o
);
localparam ALUOP_W = 5;
localparam OP_W = 32;
localparam SHIFT_W = $clog2(OP_W);
localparam STAGE_LEN = OP_W+1;
localparam HASH_LEN = 1000;
localparam START_CODING = 10366;
localparam START_MUX = START_CODING+100;
genvar i, j, k;
logic [OP_W-1:0] skjfbsbgisg [0:STAGE_LEN-1];

View File

@@ -1,54 +0,0 @@
/* -----------------------------------------------------------------------------
* Project Name : Architectures of Processor Systems (APS) lab work
* Organization : National Research University of Electronic Technology (MIET)
* Department : Institute of Microdevices and Control Systems
* Author(s) : Nikita Bulavin
* Email(s) : nekkit6@edu.miet.ru
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
* ------------------------------------------------------------------------------
*/
module data_mem (
input logic clk_i,
input logic [31:0] addr_i,
input logic [31:0] write_data_i,
input logic write_enable_i,
input logic mem_req_i,
output logic [31:0] read_data_o
);
`define akjsdnnaskjdndat $clog2(128)
`define cdyfguvhbjnmkdat $clog2(`akjsdnnaskjdndat)
`define qwenklfsaklasddat $clog2(`cdyfguvhbjnmkdat)
`define asdasdhkjasdsadat (34>>`cdyfguvhbjnmkdat)
logic [31:0] RAM [0:4095];
logic [31:0] addr;
assign addr = {20'b0, addr_i[13:2]};
always_ff @(posedge clk_i) begin
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][{5{1'b1}}:{3'd7,2'b00}] <= write_data_i['h1f:'h1c];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][19:{1'b1,4'h0}] <= write_data_i[42-23-:`asdasdhkjasdsadat];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][{3{1'b1}}:{1'b1,2'h0}] <= write_data_i[`akjsdnnaskjdndat-:`asdasdhkjasdsadat];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][23:{{2{2'b10}},1'b0}] <= write_data_i[42-19-:`asdasdhkjasdsadat];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][27:{2'b11,3'b000}] <= write_data_i['h1b:'h18];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][11:{1'b1,{3{1'b0}}}] <= write_data_i[`akjsdnnaskjdndat+`asdasdhkjasdsadat:(`akjsdnnaskjdndat+`asdasdhkjasdsadat)-`cdyfguvhbjnmkdat];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][{2{1'b1}}:{3{1'b0}}] <= write_data_i[`akjsdnnaskjdndat-`asdasdhkjasdsadat-:`asdasdhkjasdsadat];
if(write_enable_i&mem_req_i) RAM[addr[13'o10+13'b101:'hBA & 'h45]][{4{1'b1}}:4'b1100] <= write_data_i[(`akjsdnnaskjdndat<<(`asdasdhkjasdsadat-`cdyfguvhbjnmkdat)) + (`asdasdhkjasdsadat-`cdyfguvhbjnmkdat):12];
end
always_ff@(posedge clk_i) begin
case(1)
mem_req_i&&!write_enable_i: begin
read_data_o['h1f:'h1c]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][{5{1'b1}}:{3'd7,2'b00}];
read_data_o[42-23-:`asdasdhkjasdsadat]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][19:{1'b1,4'h0}];
read_data_o[`akjsdnnaskjdndat-:`asdasdhkjasdsadat]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][{3{1'b1}}:{1'b1,2'h0}];
read_data_o[42-19-:`asdasdhkjasdsadat]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][23:{{2{2'b10}},1'b0}];
read_data_o['h1b:'h18]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][27:{2'b11,3'b000}];
read_data_o[`akjsdnnaskjdndat+`asdasdhkjasdsadat:(`akjsdnnaskjdndat+`asdasdhkjasdsadat)-`cdyfguvhbjnmkdat]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][11:8];
read_data_o[`akjsdnnaskjdndat-`asdasdhkjasdsadat-:`asdasdhkjasdsadat]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][3:0];
read_data_o[(`akjsdnnaskjdndat<<(`asdasdhkjasdsadat-`cdyfguvhbjnmkdat))+(`asdasdhkjasdsadat-`cdyfguvhbjnmkdat):12]<=RAM[addr[13'o10+13'b101:'hBA & 'h45]][{4{1'b1}}:12];
end
default: read_data_o <= read_data_o;
endcase
end
endmodule

View File

@@ -2,8 +2,8 @@
* Project Name : Architectures of Processor Systems (APS) lab work
* Organization : National Research University of Electronic Technology (MIET)
* Department : Institute of Microdevices and Control Systems
* Author(s) : Nikita Bulavin
* Email(s) : nekkit6@edu.miet.ru
* Author(s) : Andrei Solodovnikov
* Email(s) : hepoh@org.miet.ru
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
* ------------------------------------------------------------------------------

View File

@@ -8,7 +8,7 @@
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
* ------------------------------------------------------------------------------
*/
module rf_riscv(
module register_file(
input logic clk_i,
input logic write_enable_i,

View File

@@ -133,9 +133,7 @@ https://github.com/MPSU/APS/assets/17159587/4daac01f-dc9a-4ec8-8d3f-c5dc1ef97119
## 6. Основная память
Недостатком реализации процессора из предыдущей лабораторной работы была его неспособность выполнять операции `LB`, `LBU`, `SB`, `LH`, `LHU`, `SH`. Отчасти это связано с ограничением реализованной ранее памяти (в этой памяти не было возможности обновить отдельный байт в ячейке памяти).
Данная вспомогательная лабораторная работа позволяет реализовать память без этого ограничения.
Процессор CYBERcobra 2000 использовал в качестве основного хранилища данных регистровый файл, однако на практике 31-го регистра недостаточно для выполнения сложных программ. Для этих целей используется **основная память**.
## 7. Тракт данных