mirror of
https://gitlab.com/brendanhaines/cpu.git
synced 2024-11-09 21:14:57 -07:00
build software project in same makefile as hardware project
This commit is contained in:
parent
4580631939
commit
5c59c97797
44
Makefile
44
Makefile
|
@ -1,20 +1,56 @@
|
|||
BUILD_DIR = build
|
||||
|
||||
# ================
|
||||
# Hardware options
|
||||
# ================
|
||||
# SOURCE_V = $(wildcard hdl/*.v)
|
||||
# TESTBENCH_V = $(wildcard hdl/tb/*.v)
|
||||
SOURCE_V = hdl/core.v
|
||||
TESTBENCH_V = hdl/tb/core_tb.v
|
||||
|
||||
# ================
|
||||
# Software options
|
||||
# ================
|
||||
CC = riscv64-linux-gnu-gcc
|
||||
# CFLAGS = -march=rv32i -mabi=ilp32
|
||||
CFLAGS = -march=rv64i -mabi=lp64
|
||||
|
||||
AS = riscv64-linux-gnu-as
|
||||
ASFLAGS = $(CFLAGS)
|
||||
|
||||
LD = riscv64-linux-gnu-ld
|
||||
LDFLAGS = -T
|
||||
|
||||
all: sim
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
## Hardware
|
||||
$(BUILD_DIR)/tb.out: $(SOURCE_V) $(TESTBENCH_V) | $(BUILD_DIR)
|
||||
iverilog $^ -o $@
|
||||
|
||||
sim: $(BUILD_DIR)/tb.out
|
||||
## Software
|
||||
$(BUILD_DIR)/%.o: test/%.S | $(BUILD_DIR)
|
||||
$(AS) $(ASFLAGS) $^ -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: test/%.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(BUILD_DIR)/%.elf: test/%.ld $(BUILD_DIR)/%.o | $(BUILD_DIR)
|
||||
$(LD) $(LDFLAGS) $^ -o $@
|
||||
|
||||
$(BUILD_DIR)/text.hex: $(BUILD_DIR)/test.elf
|
||||
riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
|
||||
|
||||
$(BUILD_DIR)/data.hex: $(BUILD_DIR)/test.elf
|
||||
riscv64-linux-gnu-objdump -s $^ | sed -n '/.data/,$$p' | tail -n+2 | sed -n '/.bss/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
|
||||
|
||||
sim: $(BUILD_DIR)/tb.out $(BUILD_DIR)/text.hex $(BUILD_DIR)/data.hex
|
||||
cd $(BUILD_DIR) && ./tb.out
|
||||
|
||||
|
||||
## General
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ initial begin: mem_inst_init
|
|||
for (i=0; i<MEM_INST_LENGTH; i=i+1) begin
|
||||
mem_inst[i] = INST_NOP;
|
||||
end
|
||||
$readmemh("../test/text.hex", mem_inst);
|
||||
$readmemh("text.hex", mem_inst);
|
||||
end
|
||||
|
||||
// Data memory
|
||||
|
@ -48,7 +48,7 @@ initial begin: mem_data_init
|
|||
for (i=0; i<MEM_DATA_LENGTH; i=i+1) begin
|
||||
mem_data[i] = DATA_DEFAULT;
|
||||
end
|
||||
$readmemh("../test/data.hex", mem_data);
|
||||
$readmemh("data.hex", mem_data);
|
||||
end
|
||||
|
||||
initial begin
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
BUILD_DIR = build
|
||||
CC = riscv64-linux-gnu-gcc
|
||||
# CFLAGS = -march=rv32i -mabi=ilp32
|
||||
CFLAGS = -march=rv64i -mabi=lp64
|
||||
|
||||
AS = riscv64-linux-gnu-as
|
||||
ASFLAGS = $(CFLAGS)
|
||||
|
||||
LD = riscv64-linux-gnu-ld
|
||||
LDFLAGS = -T test.ld
|
||||
|
||||
all: $(BUILD_DIR)/text.hex $(BUILD_DIR)/data.hex
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.S | $(BUILD_DIR)
|
||||
$(AS) $(ASFLAGS) $^ -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.o %.ld
|
||||
$(LD) $(LDFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/text.hex: $(BUILD_DIR)/test.elf
|
||||
riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
|
||||
|
||||
$(BUILD_DIR)/data.hex: $(BUILD_DIR)/test.elf
|
||||
riscv64-linux-gnu-objdump -s $^ | sed -n '/.data/,$$p' | tail -n+2 | sed -n '/.bss/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
Loading…
Reference in New Issue
Block a user