RISC-VのLinuxブート環境を構築したので、次にこれをRTL環境で実行している。
Buildrootで必要なシリアルデバイスを用意して、Spikeシミュレーションで一致検証ができるようにした。 C++側のシリアルデバイスのモデルを作成して、Spikeに動的ライブラリとしてロードし、一方でRTL側も同じメモリアドレスにシリアルデバイスのハードウェアモデルをロードして、一致検証が走るようにした。
serialdevice.cpp
class serialdevice_t : public abstract_device_t { FILE *serial_log_fp; public: serialdevice_t(std::string name); bool load(reg_t addr, size_t len, uint8_t* bytes); bool store(reg_t addr, size_t len, const uint8_t* bytes); private: }; ... static mmio_plugin_registration_t<serialdevice_t> serialdevice_mmio_plugin_registration("serialdevice");
- ハードウェア側のモデル
module msrh_serialdevice #( parameter DATA_W = 256, parameter TAG_W = 4, parameter ADDR_W = 12, parameter BASE_ADDR = 'h5400_0000, parameter SIZE = 'h1000, parameter RD_LAT = 10 ) ( input logic i_clk, input logic i_reset_n, input logic i_req_valid, input msrh_lsu_pkg::mem_cmd_t i_req_cmd, input logic [ ADDR_W-1:0] i_req_addr, input logic [ TAG_W-1:0] i_req_tag, input logic [ DATA_W-1:0] i_req_data, input logic [DATA_W/8-1:0] i_req_byte_en, output logic o_req_ready, output logic o_resp_valid, output logic [ TAG_W-1:0] o_resp_tag, output logic [DATA_W-1:0] o_resp_data, input logic i_resp_ready );
HiFive用のbuildrootのバイナリを渡して、まずはOpenSBIの部分を動かした。シリアルデバイスに無事にデータが書き込まれている様子が観測できている。まずは第一歩だ。

OpenSBI v0.9
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : ucbbar,spike-bare
Platform Features : timer,mfdeleg
Platform HART Count : 1
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.2
Domain0 Name : root
Domain0 Boot HART : 0
Domain0 HARTs : 0*
Domain0 Region00 : 0x0000000080000000-0x000000008001ffff ()
Domain0 Region01 : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address : 0x0000000080200000
Domain0 Next Arg1 : 0x0000000082200000
Domain0 Next Mode : S-mode
Domain0 SysReset : yes
Boot HART ID : 0
Boot HART Domain : root
Boot HART ISA : rv64imacsu
Boot HART Features : scounteren,mcounteren
Boot HART PMP Count : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count : 0
Boot HART MHPM Count : 0
Boot HART MIDELEG : 0x0000000000000222
Boot HART MEDELEG : 0x000000000000b109