diff --git a/.gitignore b/.gitignore index 6ba393481..e1be4ea72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ *.pdf +zig-out/ +zig-cache/ diff --git a/board/qemu_arm_virt_hyp/systems/two_vms.system b/board/qemu_arm_virt_hyp/systems/two_vms.system deleted file mode 100644 index 787a9f745..000000000 --- a/board/qemu_arm_virt_hyp/systems/two_vms.system +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/simple/Makefile b/examples/simple/Makefile new file mode 100644 index 000000000..b5bddeabd --- /dev/null +++ b/examples/simple/Makefile @@ -0,0 +1,143 @@ +# +# Copyright 2021, Breakaway Consulting Pty. Ltd. +# Copyright 2022, UNSW (ABN 57 195 873 179) +# +# SPDX-License-Identifier: BSD-2-Clause +# +ifeq ($(strip $(BUILD_DIR)),) +$(error BUILD_DIR must be specified) +endif + +ifeq ($(strip $(SEL4CP_SDK)),) +$(error SEL4CP_SDK must be specified) +endif + +ifeq ($(strip $(BOARD)),) +$(error BOARD must be specified) +endif + +ifeq ($(strip $(CONFIG)),) +$(error CONFIG must be specified) +endif + +ifeq ($(strip $(SYSTEM)),) +$(error SYSTEM must be specified) +endif + +# @ivanv: Check for dependencies and make sure they are installed/in the path + +# @ivanv: check that all dependencies exist +# Specify that we use bash for all shell commands +SHELL=/bin/bash +# All dependencies needed to compile the VMM +QEMU := qemu-system-aarch64 +DTC := dtc + +ifndef TOOLCHAIN + # Get whether the common toolchain triples exist + TOOLCHAIN_AARCH64_LINUX_GNU := $(shell command -v aarch64-linux-gnu-gcc 2> /dev/null) + TOOLCHAIN_AARCH64_UNKNOWN_LINUX_GNU := $(shell command -v aarch64-unknown-linux-gnu-gcc 2> /dev/null) + # Then check if they are defined and select the appropriate one + ifdef TOOLCHAIN_AARCH64_LINUX_GNU + TOOLCHAIN := aarch64-linux-gnu + else ifdef TOOLCHAIN_AARCH64_UNKNOWN_LINUX_GNU + TOOLCHAIN := aarch64-unknown-linux-gnu + else + $(error "Could not find an AArch64 cross-compiler") + endif +endif + +CC := $(TOOLCHAIN)-gcc +LD := $(TOOLCHAIN)-ld +AS := $(TOOLCHAIN)-as +SEL4CP_TOOL ?= $(SEL4CP_SDK)/bin/sel4cp + +# @ivanv: need to have a step for putting in the initrd node into the DTB, +# right now it is unfortunately hard-coded. + +# @ivanv: check that the path of SDK_PATH/BOARD exists +# @ivanv: Have a list of supported boards to check with, if it's not one of those +# have a helpful message that lists all the support boards. + +# @ivanv: incremental builds don't work with IMAGE_DIR changing + +BOARD_DIR := $(SEL4CP_SDK)/board/$(BOARD)/$(CONFIG) +VMM_SRC_DIR := ../../src +SYSTEM_DESCRIPTION := board/$(BOARD)/$(SYSTEM) + +IMAGE_DIR := board/$(BOARD) +KERNEL_IMAGE := $(IMAGE_DIR)/linux +DTS := $(IMAGE_DIR)/linux.dts +DTB_IMAGE := $(BUILD_DIR)/linux.dtb +INITRD_IMAGE := $(IMAGE_DIR)/rootfs.cpio.gz +IMAGES := vmm.elf +IMAGE_FILE = $(BUILD_DIR)/loader.img +REPORT_FILE = $(BUILD_DIR)/report.txt + +# @ivanv: should only compile printf.o in debug +VMM_OBJS := vmm.o printf.o virq.o linux.o guest.o psci.o smc.o fault.o util.o vgic.o package_guest_images.o + +# @ivanv: hack... +# This step should be done based on the DTB +ifeq ($(BOARD),imx8mm_evk) + VMM_OBJS += vgic_v3.o +else + VMM_OBJS += vgic_v2.o +endif + +# Toolchain flags +# FIXME: For optimisation we should consider providing the flag -mcpu. +# FIXME: We should also consider whether -mgeneral-regs-only should be +# used to avoid the use of the FPU and therefore seL4 does not have to +# context switch the FPU. +CFLAGS := -mstrict-align -nostdlib -ffreestanding -g3 -O3 -Wall -Wno-unused-function -Werror -I$(VMM_SRC_DIR)/arch/aarch64 -I$(VMM_SRC_DIR)/util -I$(BOARD_DIR)/include -DBOARD_$(BOARD) -DCONFIG_$(CONFIG) +LDFLAGS := -L$(BOARD_DIR)/lib +LIBS := -lsel4cp -Tsel4cp.ld + +all: directories $(IMAGE_FILE) + +run: all + # @ivanv: check that the amount of RAM given to QEMU is at least the number of RAM that QEMU is setup with for seL4. + if ! command -v $(QEMU) &> /dev/null; then echo "Could not find dependenyc: qemu-system-aarch64"; exit 1; fi + $(QEMU) -machine virt,virtualization=on,highmem=off,secure=off \ + -cpu cortex-a53 \ + -serial mon:stdio \ + -device loader,file=$(IMAGE_FILE),addr=0x70000000,cpu-num=0 \ + -m size=2G \ + -nographic + +directories: + $(shell mkdir -p $(BUILD_DIR)) + +$(DTB_IMAGE): $(DTS) + if ! command -v $(DTC) &> /dev/null; then echo "Could not find dependency: Device Tree Compiler (dtc)"; exit 1; fi + # @ivanv: Shouldn't supress warnings + $(DTC) -q -I dts -O dtb $< > $@ + +$(BUILD_DIR)/package_guest_images.o: package_guest_images.S $(IMAGE_DIR) $(KERNEL_IMAGE) $(INITRD_IMAGE) $(DTB_IMAGE) + $(CC) -c -g3 -x assembler-with-cpp \ + -DGUEST_KERNEL_IMAGE_PATH=\"$(KERNEL_IMAGE)\" \ + -DGUEST_DTB_IMAGE_PATH=\"$(DTB_IMAGE)\" \ + -DGUEST_INITRD_IMAGE_PATH=\"$(INITRD_IMAGE)\" \ + $< -o $@ + +$(BUILD_DIR)/%.o: %.c Makefile + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/%.c Makefile + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/util/%.c Makefile + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/arch/aarch64/%.c Makefile + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/arch/aarch64/vgic/%.c Makefile + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/vmm.elf: $(addprefix $(BUILD_DIR)/, $(VMM_OBJS)) + $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ + +$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) $(SYSTEM_DESCRIPTION) $(IMAGE_DIR) + $(SEL4CP_TOOL) $(SYSTEM_DESCRIPTION) --search-path $(BUILD_DIR) $(IMAGE_DIR) --board $(BOARD) --config $(CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) diff --git a/board/qemu_arm_virt_hyp/images/README.md b/examples/simple/board/qemu_arm_virt_hyp/README.md similarity index 100% rename from board/qemu_arm_virt_hyp/images/README.md rename to examples/simple/board/qemu_arm_virt_hyp/README.md diff --git a/board/qemu_arm_virt_hyp/images/buildroot_config b/examples/simple/board/qemu_arm_virt_hyp/buildroot_config similarity index 100% rename from board/qemu_arm_virt_hyp/images/buildroot_config rename to examples/simple/board/qemu_arm_virt_hyp/buildroot_config diff --git a/board/qemu_arm_virt_hyp/images/linux b/examples/simple/board/qemu_arm_virt_hyp/linux similarity index 100% rename from board/qemu_arm_virt_hyp/images/linux rename to examples/simple/board/qemu_arm_virt_hyp/linux diff --git a/board/qemu_arm_virt_hyp/images/linux.dts b/examples/simple/board/qemu_arm_virt_hyp/linux.dts similarity index 100% rename from board/qemu_arm_virt_hyp/images/linux.dts rename to examples/simple/board/qemu_arm_virt_hyp/linux.dts diff --git a/board/qemu_arm_virt_hyp/images/linux_config b/examples/simple/board/qemu_arm_virt_hyp/linux_config similarity index 100% rename from board/qemu_arm_virt_hyp/images/linux_config rename to examples/simple/board/qemu_arm_virt_hyp/linux_config diff --git a/board/qemu_arm_virt_hyp/images/rootfs.cpio.gz b/examples/simple/board/qemu_arm_virt_hyp/rootfs.cpio.gz similarity index 100% rename from board/qemu_arm_virt_hyp/images/rootfs.cpio.gz rename to examples/simple/board/qemu_arm_virt_hyp/rootfs.cpio.gz diff --git a/board/qemu_arm_virt_hyp/systems/simple.system b/examples/simple/board/qemu_arm_virt_hyp/simple.system similarity index 95% rename from board/qemu_arm_virt_hyp/systems/simple.system rename to examples/simple/board/qemu_arm_virt_hyp/simple.system index 2dc6e74f2..e87fcdea6 100644 --- a/board/qemu_arm_virt_hyp/systems/simple.system +++ b/examples/simple/board/qemu_arm_virt_hyp/simple.system @@ -1,6 +1,6 @@ @@ -35,7 +35,7 @@ starting address of RAM is 0x40000000, so we map in the guest RAM at the same address in the VMMs virutal address space. --> - +