66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
NAME=vriscv
 | 
						|
CC=gcc
 | 
						|
CFLAGS=-O3 -Wall -I src
 | 
						|
LDFLAGS=-lpthread
 | 
						|
BUILD_DIR=build
 | 
						|
 | 
						|
# Risc-V toolchain
 | 
						|
RV_LINUX_CCPREFIX=riscv32-unknown-linux-gnu-
 | 
						|
 | 
						|
C_FILES := $(shell find src/ -name '*.c')
 | 
						|
 | 
						|
all: $(BUILD_DIR)/$(NAME)
 | 
						|
 | 
						|
# Top-level target : vriscv
 | 
						|
$(BUILD_DIR)/$(NAME): $(C_FILES) | $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 | 
						|
 | 
						|
# Build directory
 | 
						|
$(BUILD_DIR):
 | 
						|
	mkdir -p $(BUILD_DIR)
 | 
						|
 | 
						|
# Clean : clean build directory
 | 
						|
.PHONY: clean
 | 
						|
clean:
 | 
						|
	rm -rf $(BUILD_DIR)
 | 
						|
 | 
						|
rungdb: all
 | 
						|
	echo $(shell objdump -h ../riscv-pk/build/bbl | grep .payload | awk '{print $4}')
 | 
						|
 | 
						|
# Linux and bootloader, for running linux
 | 
						|
$(BUILD_DIR)/linux:
 | 
						|
	cd $(BUILD_DIR) && git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth 1 -b v6.6
 | 
						|
 | 
						|
$(BUILD_DIR)/linux/.config: hardware/linux.config
 | 
						|
	cp hardware/linux.config $(BUILD_DIR)/linux/.config
 | 
						|
 | 
						|
$(BUILD_DIR)/linux/vmlinux: $(BUILD_DIR)/linux/.config | $(BUILD_DIR)/linux
 | 
						|
	cd $(BUILD_DIR)/linux/ && make ARCH=riscv CROSS_COMPILE=$(RV_LINUX_CCPREFIX) -j7 vmlinux
 | 
						|
 | 
						|
$(BUILD_DIR)/riscv-pk:
 | 
						|
	cd $(BUILD_DIR) && git clone https://github.com/riscv-software-src/riscv-pk --depth 1
 | 
						|
 | 
						|
$(BUILD_DIR)/riscv-pk/build: | $(BUILD_DIR)/riscv-pk
 | 
						|
	mkdir $(BUILD_DIR)/riscv-pk/build
 | 
						|
 | 
						|
$(BUILD_DIR)/riscv-pk/build/bbl: $(BUILD_DIR)/linux/vmlinux hardware/vriscv.dts | $(BUILD_DIR)/riscv-pk/build
 | 
						|
	cd $(BUILD_DIR)/riscv-pk/build && ../configure \
 | 
						|
	--prefix=$(CURDIR)/$(BUILD_DIR)/riscv-pk/build/prefix \
 | 
						|
	--host=riscv32-unknown-elf \
 | 
						|
	--with-arch=rv32ima_zicsr_zifencei --with-abi=ilp32 \
 | 
						|
	--with-dts=../../../hardware/vriscv.dts \
 | 
						|
	--with-payload=../../linux/vmlinux
 | 
						|
	cd $(BUILD_DIR)/riscv-pk/build && make && make install
 | 
						|
 | 
						|
# Run : run linux on the emulator
 | 
						|
.PHONY: run
 | 
						|
.SILENT: run
 | 
						|
run: all $(BUILD_DIR)/riscv-pk/build/bbl
 | 
						|
	./$(BUILD_DIR)/$(NAME) -m4096 $(BUILD_DIR)/riscv-pk/build/bbl
 | 
						|
 | 
						|
# Test : all the tests
 | 
						|
.PHONY: tests
 | 
						|
.SILENT: tests
 | 
						|
tests: all
 | 
						|
	make -C tests
 |