Merge pull request #17 from sifive/set-isa-abi

Allow users to set the ISA and ABI of the target machine
This commit is contained in:
Palmer Dabbelt 2017-11-15 11:33:35 -08:00 committed by GitHub
commit daf02061f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
RISCV ?= $(CURDIR)/toolchain RISCV ?= $(CURDIR)/toolchain
PATH := $(RISCV)/bin:$(PATH) PATH := $(RISCV)/bin:$(PATH)
ISA ?= rv64imafdc
ABI ?= lp64d
srcdir := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) srcdir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
srcdir := $(srcdir:/=) srcdir := $(srcdir:/=)
@ -43,13 +45,17 @@ target := riscv64-unknown-linux-gnu
.PHONY: all .PHONY: all
all: $(hex) all: $(hex)
@echo @echo
@echo This image has been generated for an ISA of $(ISA) and an ABI of $(ABI)
@echo Find the SD-card image in work/bbl.bin @echo Find the SD-card image in work/bbl.bin
@echo Program it with: dd if=work/bbl.bin of=/dev/sd-your-card bs=1M @echo Program it with: dd if=work/bbl.bin of=/dev/sd-your-card bs=1M
@echo @echo
$(toolchain_dest)/bin/$(target)-gcc: $(toolchain_srcdir) $(toolchain_dest)/bin/$(target)-gcc: $(toolchain_srcdir)
mkdir -p $(toolchain_wrkdir) mkdir -p $(toolchain_wrkdir)
cd $(toolchain_wrkdir); $(toolchain_srcdir)/configure --prefix=$(toolchain_dest) cd $(toolchain_wrkdir); $(toolchain_srcdir)/configure \
--prefix=$(toolchain_dest) \
--with-isa=$(ISA) \
--with-abi=$(ABI)
$(MAKE) -C $(toolchain_wrkdir) linux $(MAKE) -C $(toolchain_wrkdir) linux
sed 's/^#define LINUX_VERSION_CODE.*/#define LINUX_VERSION_CODE 263682/' -i $(toolchain_dest)/sysroot/usr/include/linux/version.h sed 's/^#define LINUX_VERSION_CODE.*/#define LINUX_VERSION_CODE 263682/' -i $(toolchain_dest)/sysroot/usr/include/linux/version.h
@ -70,6 +76,17 @@ $(linux_wrkdir)/.config: $(linux_defconfig) $(linux_srcdir)
mkdir -p $(dir $@) mkdir -p $(dir $@)
cp -p $< $@ cp -p $< $@
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
echo $(ISA)
echo $(filter rv32%,$(ISA))
ifeq (,$(filter rv%c,$(ISA)))
sed 's/^.*CONFIG_RISCV_ISA_C.*$$/CONFIG_RISCV_ISA_C=n/' -i $@
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
endif
ifeq ($(ISA),$(filter rv32%,$(ISA)))
sed 's/^.*CONFIG_ARCH_RV32I.*$$/CONFIG_ARCH_RV32I=y/' -i $@
sed 's/^.*CONFIG_ARCH_RV64I.*$$/CONFIG_ARCH_RV64I=n/' -i $@
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
endif
$(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(sysroot_stamp) $(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(sysroot_stamp)
$(MAKE) -C $< O=$(linux_wrkdir) \ $(MAKE) -C $< O=$(linux_wrkdir) \
@ -94,7 +111,7 @@ $(bbl): $(pk_srcdir) $(vmlinux_stripped)
--with-payload=$(vmlinux_stripped) \ --with-payload=$(vmlinux_stripped) \
--enable-logo \ --enable-logo \
--with-logo=$(abspath conf/sifive_logo.txt) --with-logo=$(abspath conf/sifive_logo.txt)
CFLAGS="-mabi=lp64d -march=rv64imafdc" $(MAKE) -C $(pk_wrkdir) CFLAGS="-mabi=$(ABI) -march=$(ISA)" $(MAKE) -C $(pk_wrkdir)
$(bin): $(bbl) $(bin): $(bbl)
$(target)-objcopy -S -O binary --change-addresses -0x80000000 $< $@ $(target)-objcopy -S -O binary --change-addresses -0x80000000 $< $@
@ -134,4 +151,4 @@ clean:
.PHONY: sim .PHONY: sim
sim: $(spike) $(bbl) sim: $(spike) $(bbl)
$(spike) -p4 $(bbl) $(spike) --isa=$(ISA) -p4 $(bbl)