From eb053503f7f1a8215d4464cd0333a39e24a7dc9f Mon Sep 17 00:00:00 2001 From: Graham Edgecombe Date: Sat, 2 Dec 2017 17:17:26 +0000 Subject: [PATCH] Populate instr_mem with a test assembly program --- .gitignore | 2 ++ Makefile | 26 +++++++++++++++++++++----- progmem.s | 3 +++ rv32_fetch.sv | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 progmem.s diff --git a/.gitignore b/.gitignore index 21350b0..af61409 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ *.asc *.bin *.blif +*.hex +*.o !.git* !.mailmap diff --git a/Makefile b/Makefile index 8e1c59b..8e65359 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SRC = $(wildcard *.sv) TOP = top YS = $(TOP).ys BLIF = $(TOP).blif +ASC_SYN = $(TOP)_syn.asc ASC = $(TOP).asc BIN = $(TOP).bin SPEED = hx @@ -10,27 +11,42 @@ DEVICE = 8k PACKAGE = ct256 PCF = ice40hx8k-b-evn.pcf FREQ_OSC = 12 +TARGET = riscv64-unknown-elf +AS = $(TARGET)-as +ASFLAGS = -march=rv32i -mabi=ilp32 +OBJCOPY = $(TARGET)-objcopy .PHONY: all clean time stat flash all: $(TOP).bin clean: - $(RM) $(BLIF) $(ASC) $(BIN) + $(RM) $(BLIF) $(ASC_SYN) $(ASC) $(BIN) progmem_syn.hex progmem.hex progmem.o -$(BLIF): $(YS) $(SRC) +progmem.hex: progmem.o + $(OBJCOPY) -O srec $< /dev/stdout \ + | srec_cat - -byte-swap 4 -output - -binary \ + | xxd -p -c 4 > $@ + +progmem_syn.hex: + icebram -g 32 256 > $@ + +$(BLIF): $(YS) $(SRC) progmem_syn.hex yosys $(QUIET) -s $< -$(ASC): $(BLIF) $(PCF) +$(ASC_SYN): $(BLIF) $(PCF) arachne-pnr $(QUIET) -d $(DEVICE) -P $(PACKAGE) -o $@ -p $(PCF) $< +$(ASC): $(ASC_SYN) progmem_syn.hex progmem.hex + icebram progmem_syn.hex progmem.hex < $< > $@ + $(BIN): $(ASC) icepack $< $@ -time: $(ASC) $(PCF) +time: $(ASC_SYN) $(PCF) icetime -t -m -d $(SPEED)$(DEVICE) -P $(PACKAGE) -p $(PCF) -c $(FREQ_OSC) $< -stat: $(ASC) +stat: $(ASC_SYN) icebox_stat $< flash: $(BIN) diff --git a/progmem.s b/progmem.s new file mode 100644 index 0000000..7244e4a --- /dev/null +++ b/progmem.s @@ -0,0 +1,3 @@ +start: + addi x31, x31, 1 + j start diff --git a/rv32_fetch.sv b/rv32_fetch.sv index 1e9205e..a6cb032 100644 --- a/rv32_fetch.sv +++ b/rv32_fetch.sv @@ -19,6 +19,9 @@ module rv32_fetch ( logic [31:0] pc = branch_taken_in ? branch_pc_in : next_pc; + initial + $readmemh("progmem_syn.hex", instr_mem); + always_ff @(posedge clk) begin instr_out <= instr_mem[pc[31:2]]; next_pc <= pc + 4;