未验证 提交 4c494e36 编写于 作者: J Jay 提交者: GitHub

Use blackbox to rebuild AXI-flash (#726)

* AXIFlash: use blackbox to rebuild flash

* device.cpp: add init_flash

* Add flash.cpp for DPI-C funtion

* Flash: use USE_BIN to enable FI from flash

* AXIFlash: delete original flash
上级 5c5bd416
......@@ -107,6 +107,11 @@ ifeq ($(DUALCORE),1)
EMU_CXXFLAGS += -DDUALCORE
endif
USE_BIN ?= 0
ifeq ($(USE_BIN),1)
EMU_CXXFLAGS += -DUSE_BIN
endif
# --trace
VERILATOR_FLAGS = --top-module $(EMU_TOP) \
+define+VERILATOR=1 \
......
......@@ -6,6 +6,38 @@ import chipsalliance.rocketchip.config.Parameters
import freechips.rocketchip.diplomacy.AddressSet
import utils._
class FlashHelper extends BlackBox with HasBlackBoxInline {
val io = IO(new Bundle {
val clk = Input(Clock())
val ren = Input(Bool())
val data = Output(UInt(64.W))
val addr = Input(UInt(32.W))
})
setInline("FlashHelper.v",
s"""
|import "DPI-C" function void flash_read
|(
| input int addr,
| output longint data
|);
|
|module FlashHelper (
| input clk,
| input [31:0] addr,
| input ren,
| output reg [63:0] data
|);
|
| always @(posedge clk) begin
| if (ren) flash_read(addr, data);
| end
|
|endmodule
""".stripMargin)
}
class AXI4Flash
(
address: Seq[AddressSet]
......@@ -14,23 +46,13 @@ class AXI4Flash
{
override lazy val module = new AXI4SlaveModuleImp(this){
val jmpToDramInstr1 = "h0010029b".U // addiw t0,zero,1
val jmpToDramInstr2 = "h01f29293".U // slli t0,t0,0x1f
val jmpToDramInstr3 = "h00028067".U // jr t0
val mapping = Map(
RegMap(0x0, jmpToDramInstr1, RegMap.Unwritable),
RegMap(0x4, jmpToDramInstr2, RegMap.Unwritable),
RegMap(0x8, jmpToDramInstr3, RegMap.Unwritable)
)
def getOffset(addr: UInt) = addr(12,0)
val rdata = Wire(Vec(2,UInt(32.W)))
(0 until 2).map{ i =>
RegMap.generate(mapping, getOffset(raddr + (i * 4).U), rdata(i),
getOffset(waddr), in.w.fire(), in.w.bits.data, MaskExpand(in.w.bits.strb))
}
in.r.bits.data := rdata.asUInt
def getOffset(addr: UInt) = addr(15,0)
val flash = Module(new FlashHelper)
flash.io.clk := clock
flash.io.ren := in.ar.fire()
flash.io.addr := Cat(0.U(16.W), getOffset(raddr))
in.r.bits.data := flash.io.data
}
}
......@@ -7,6 +7,7 @@ void init_sdl(void);
void init_uart(void);
extern "C" void init_sd(void);
extern "C" void init_flash(void);
static struct timeval boot = {};
......@@ -14,6 +15,7 @@ void init_device(void) {
init_sdl();
init_uart();
init_sd();
init_flash();
gettimeofday(&boot, NULL);
}
......
......@@ -51,7 +51,11 @@ void init_difftest() {
}
for (int i = 0; i < NumCore; i++) {
nemu_this_pc[i] = 0x80000000;
#ifdef USE_BIN
nemu_this_pc[i] = 0x10000000;
#else
nemu_this_pc[i] = 0x80000000;
#endif
pc_retire_pointer[i] = DEBUG_RETIRE_TRACE_SIZE-1;
}
}
......
......@@ -611,12 +611,22 @@ uint64_t Emulator::execute(uint64_t max_cycle, uint64_t max_instr) {
}
for (int i = 0; i < NumCore; i++) {
#ifdef USE_BIN
#ifdef DUALCORE
int first_instr_commit = (i == 0) ? dut_ptr->io_difftest_commit && dut_ptr->io_difftest_thisPC == 0x10000000u :
dut_ptr->io_difftest2_commit && dut_ptr->io_difftest2_thisPC == 0x10000000u;
#else
int first_instr_commit = dut_ptr->io_difftest_commit && dut_ptr->io_difftest_thisPC == 0x10000000u;
#endif
#else
#ifdef DUALCORE
int first_instr_commit = (i == 0) ? dut_ptr->io_difftest_commit && dut_ptr->io_difftest_thisPC == 0x80000000u :
dut_ptr->io_difftest2_commit && dut_ptr->io_difftest2_thisPC == 0x80000000u;
#else
int first_instr_commit = dut_ptr->io_difftest_commit && dut_ptr->io_difftest_thisPC == 0x80000000u;
#endif
#endif
if (!hascommit[i] && first_instr_commit) {
hascommit[i] = 1;
#ifdef DUALCORE
......
#include "common.h"
#include "flash.h"
FILE *flash_fp = NULL;
extern "C" {
void flash_read(uint32_t addr, uint64_t *data) {
#ifdef USE_BIN
fseek(flash_fp, addr, SEEK_SET);
fread(data, 8, 1, flash_fp);
#else
uint32_t index = addr & 0x00000fff;
switch(index>>3){
case 0 :
*data = 0x01f292930010029b;
break;
case 1 :
*data = 0x00028067;
break;
default :
*data = 0;
}
#endif
}
void init_flash(void) {
#ifdef USE_BIN
flash_fp = fopen("/home/jy/Project/nexus-am/tests/cputest/build/dummy-riscv64-noop.bin", "r");
if(!flash_fp)
{
eprintf(ANSI_COLOR_MAGENTA "[warning] flash img not found\n");
}
printf("use bin as a flash!\n");
#else
printf("use fixed 3 instructions!\n");
#endif
}
}
#ifndef __FLASH_H
#define __FLASH_H
#include "common.h"
#endif // __FLASH_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册