Line 66... |
Line 66... |
|
|
//
|
//
|
// Testbench mechanics
|
// Testbench mechanics
|
//
|
//
|
reg [7:0] program_mem[(1<<(`MEMORY_ADR_WIDTH+2))-1:0];
|
reg [7:0] program_mem[(1<<(`MEMORY_ADR_WIDTH+2))-1:0];
|
integer initialize, firmware_size, ptr;
|
integer initialize, ptr;
|
reg [8*64:0] file_name;
|
reg [8*64:0] file_name;
|
|
integer firmware_size; // Note that the .hex file size is greater than this, as each byte in the file needs 2 hex characters.
|
|
integer firmware_size_in_header;
|
reg load_file;
|
reg load_file;
|
|
|
initial begin
|
initial begin
|
design_ready = 1'b0;
|
design_ready = 1'b0;
|
uart_echo = 1'b1;
|
uart_echo = 1'b1;
|
Line 103... |
Line 105... |
`endif
|
`endif
|
|
|
//get firmware hex file from command line input
|
//get firmware hex file from command line input
|
if ( load_file ) begin
|
if ( load_file ) begin
|
if ( ! $value$plusargs("file_name=%s", file_name) || file_name == 0 ) begin
|
if ( ! $value$plusargs("file_name=%s", file_name) || file_name == 0 ) begin
|
$display("ERROR: please specify an input file to start.");
|
$display("ERROR: Please specify the name of the firmware file to load on start-up.");
|
$finish;
|
$finish;
|
end
|
end
|
$readmemh(file_name, program_mem);
|
|
// First word comprehends size of program
|
// We are passing the firmware size separately as a command-line argument in order
|
firmware_size = { program_mem[0] , program_mem[1] , program_mem[2] , program_mem[3] };
|
// to avoid this kind of Icarus Verilog warnings:
|
|
// WARNING: minsoc_bench_core.v:111: $readmemh: Standard inconsistency, following 1364-2005.
|
|
// WARNING: minsoc_bench_core.v:111: $readmemh(../../sw/uart/uart.hex): Not enough words in the file for the requested range [0:32767].
|
|
// Apparently, some of the $readmemh() warnigns are even required by the standard. The trouble is,
|
|
// Verilog's $fread() is not widely implemented in the simulators, so from Verilog alone
|
|
// it's not easy to read the firmware file header without getting such warnings.
|
|
if ( ! $value$plusargs("firmware_size=%d", firmware_size) ) begin
|
|
$display("ERROR: Please specify the size of the firmware (in bytes) contained in the hex firmware file.");
|
|
$finish;
|
|
end
|
|
|
|
$readmemh(file_name, program_mem, 0, firmware_size - 1);
|
|
|
|
firmware_size_in_header = { program_mem[0] , program_mem[1] , program_mem[2] , program_mem[3] };
|
|
|
|
if ( firmware_size != firmware_size_in_header ) begin
|
|
$display("ERROR: The firmware size in the file header does not match the firmware size given as command-line argument. Did you forget bin2hex's -size_word flag when generating the firmware file?");
|
|
$finish;
|
|
end
|
|
|
end
|
end
|
|
|
`ifdef INITIALIZE_MEMORY_MODEL
|
`ifdef INITIALIZE_MEMORY_MODEL
|
// Initialize memory with firmware
|
// Initialize memory with firmware
|
initialize = 0;
|
initialize = 0;
|