ちょっと自作CPUの検証環境を調整したくて、リセット時のPC=0として実行して検証を走らせたいのだが、どうにもSpikeがエラーを出してしまう。
0x0にブートコードを含んでいるELFをロードすると、invalid write to 0
のような感じでエラーが出力して実行できない。
これを回避する方法をいろいろ調べていたのだが、どうもSpikeはデフォルトで0x0にデバッグユニットが入っていて、そこにELFを書くことはできないらしい。
bool mmu_t::mmio_ok(reg_t addr, access_type type) { // Disallow access to debug region when not in debug mode if (addr >= DEBUG_START && addr <= DEBUG_END && proc && !proc->state.debug_mode) return false; return true; }
#define DEBUG_START 0x0 #define DEBUG_END (0x1000 - 1)
これをコメントアウトして、シミュレーションを実行した。
../spike_dpi/riscv-isa-sim/spike --pc=0 -l --log-commits --disable-dtb -m0x0:0x100000,0xc000000:0x400000,0x10000000:0x1000000 ../tests/litex_soc/software/bios/bios.elf
一応シミュレーションが動き始めたようだ。途中で割り込みが入っているが、入りっぱなしになっている。
core 0: 0x00000000000000a0 (0x00813f03) ld t5, 8(sp) core 0: 3 0x00000000000000a0 (0x00813f03) x30 0x0000000000000000 mem 0x0000000010001ec8 core 0: 0x00000000000000a4 (0x00013f83) ld t6, 0(sp) core 0: 3 0x00000000000000a4 (0x00013f83) x31 0x0000000000000000 mem 0x0000000010001ec0 core 0: 0x00000000000000a8 (0x08010113) addi sp, sp, 128 core 0: 3 0x00000000000000a8 (0x08010113) x 2 0x0000000010001f40 core 0: 0x00000000000000ac (0x30200073) mret core 0: 3 0x00000000000000ac (0x30200073) c768_mstatus 0x0000000a00000088 core 0: exception interrupt #7, epc 0x0000000000003f08 core 0: >>>> trap_entry core 0: 0x0000000000000020 (0xfe113c23) sd ra, -8(sp) core 0: 3 0x0000000000000020 (0xfe113c23) mem 0x0000000010001f38 0x0000000000001778 core 0: 0x0000000000000024 (0xfe513823) sd t0, -16(sp) core 0: 3 0x0000000000000024 (0xfe513823) mem 0x0000000010001f30 0x0000000010000b48 core 0: 0x0000000000000028 (0xfe613423) sd t1, -24(sp) core 0: 3 0x0000000000000028 (0xfe613423) mem 0x0000000010001f28 0x0000000010000b48 core 0: 0x000000000000002c (0xfe713023) sd t2, -32(sp) core 0: 3 0x000000000000002c (0xfe713023) mem 0x0000000010001f20 0x0000000000005d70 core 0: 0x0000000000000030 (0xfca13c23) sd a0, -40(sp) core 0: 3 0x0000000000000030 (0xfca13c23) mem 0x0000000010001f18 0x0000000000000880 core 0: 0x0000000000000034 (0xfcb13823) sd a1, -48(sp) core 0: 3 0x0000000000000034 (0xfcb13823) mem 0x0000000010001f10 0x0000000000000000 core 0: 0x0000000000000038 (0xfcc13423) sd a2, -56(sp) core 0: 3 0x0000000000000038 (0xfcc13423) mem 0x0000000010001f08 0x0000000000000000 core 0: 0x000000000000003c (0xfcd13023) sd a3, -64(sp) core 0: 3 0x000000000000003c (0xfcd13023) mem 0x0000000010001f00 0x0000000000000000 core 0: 0x0000000000000040 (0xfae13c23) sd a4, -72(sp) core 0: 3 0x0000000000000040 (0xfae13c23) mem 0x0000000010001ef8 0x00000000000001fe core 0: 0x0000000000000044 (0xfaf13823) sd a5, -80(sp)
あとは、PLICを接続するだけかな。