forked from tock/tock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I am still sorting these changes into PRs Change-Id: I6bec3a148935f7b653d1111221276d002162cf06 Change-Id: Ib6f0186a1363661ce2457cdda6b9c5d7dcc0d7eb
- Loading branch information
Lawrence Esswood
committed
Oct 2, 2024
1 parent
a6cbf7e
commit 9dcf42a
Showing
28 changed files
with
3,171 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "qemu_cheri_virt" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
components = { path = "../components", features = ["use_static_init"] } | ||
capsules-core = { path = "../../capsules/core", features = ["use_static_init"] } | ||
capsules-extra = { path = "../../capsules/extra", features = ["use_static_init"] } | ||
capsules-system = { path = "../../capsules/system", features = ["use_static_init"] } | ||
kernel = { path = "../../kernel", features = ["use_static_init", "counted_grant_refs"] } | ||
misc = { path = "../../libraries/misc" } | ||
uarts = { path = "../../chips/uarts", features = ["ns16550_u8"]} | ||
riscv = { path = "../../arch/riscv", features = ["use_static_init"]} | ||
cheri = { path = "../../arch/cheri" } | ||
sifive = { path = "../../chips/sifive" , features = ["use_static_init"]} | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Makefile for building qemu CHERI virt board | ||
|
||
# If not provided, assume cheri sdk installed in default location | ||
CHERI_SDK ?= $(abspath ${HOME}/cheri/output/sdk) | ||
|
||
# Default 64-bit | ||
BITS ?= 64 | ||
|
||
# Default cheri on (pure/hybrid controls only userspace) | ||
CHERI ?= pure | ||
|
||
# Other config | ||
export NUM_PROCS ?= 4 | ||
export PLIC_BASE_ADDR ?= 0xc000000 | ||
export BAUD_RATE ?=115200 | ||
export N_REGIONS ?= 4 | ||
export STACK_SIZE ?= 0x2000 | ||
export UART0_BASE_ADDR ?= 0x10000000 | ||
export UART0_IRQ ?=10 | ||
|
||
TARGET=riscv${BITS}imac-unknown-none-cheri-hybrid-elf | ||
|
||
# When using "no_std" (which Tock does), rust builds its own compiler_builtins. | ||
# memcpy is broken using upstream rust based compiler builtins because it | ||
# uses usize, not a pointer type (as well as going out of bounds) | ||
# I have a rewritten version, but can't work out how to add that as | ||
# dependency while not also building the upstream compiler builtins. | ||
# In the mean time, I am linking in the cheribuild baremetal libc which | ||
# will override the weak symbols provided by the rust compiler builtins | ||
|
||
CHERI_LIBC ?= $(CHERI_SDK)/baremetal/baremetal-newlib-riscv$(BITS)-hybrid/riscv$(BITS)-unknown-elf | ||
|
||
EXTRA_FLAGS = -lstatic=c -L$(CHERI_LIBC)/lib | ||
|
||
PLATFORM=qemu_cheri_virt | ||
|
||
RUSTC_FLAGS_TOCK += \ | ||
-C link-arg=-Tlayout.ld \ | ||
-C linker=${CHERI_SDK}/bin/ld.lld \ | ||
-C linker-flavor=ld.lld \ | ||
-C relocation-model=static \ | ||
-C link-arg=-nmagic \ | ||
-C link-arg=-icf=all \ | ||
$(EXTRA_FLAGS) \ | ||
-Z macro-backtrace \ | ||
|
||
RUSTC_FLAGS_FOR_BIN ?= \ | ||
-C link-arg=-L$(abspath .) \ | ||
|
||
RUSTC_FLAGS_TOCK ?= \ | ||
$(RUSTC_FLAGS) \ | ||
--remap-path-prefix=$(TOCK_ROOT_DIRECTORY)= \ | ||
--remap-path-prefix=$(RUSTC_SYSROOT)/lib/rustlib/src/rust/library/core=/core/ | ||
|
||
# Our CARGO is still just too old to not still do everything in make, so bring | ||
# back some of the old makefile just for this board | ||
|
||
CARGO_FLAGS_TOCK ?= \ | ||
$(VERBOSE_FLAGS) \ | ||
-Z build-std=core,compiler_builtins \ | ||
--target=$(TARGET) \ | ||
--package $(PLATFORM) \ | ||
--target-dir=$(TARGET_DIRECTORY) $(CARGO_FLAGS) | ||
|
||
|
||
# We do have rustup, we just don't want the Makefile.common to try any of the | ||
# toolchain commands with it because it is a custom one and that always causes | ||
# an error. | ||
NO_RUSTUP=1 | ||
TOOLCHAIN ?= ${CHERI_SDK}/bin/llvm | ||
|
||
include ../Makefile.common | ||
|
||
# Pad to flash size | ||
$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_pad.bin: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin | ||
cp $^ $@ | ||
dd if=/dev/null of=$@ bs=1 seek=33554431 count=1 | ||
|
||
$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_app.bin : $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin $(APP_BIN) | ||
cp $< $@ | ||
dd if=/dev/null of=$@ bs=1 seek=4194304 count=1 | ||
cat $(APP_BIN) >> $@ | ||
dd if=/dev/null of=$@ bs=1 seek=33554431 count=1 | ||
|
||
|
||
invoke_qemu = ${CHERI_SDK}/bin/qemu-system-riscv${BITS}cheri \ | ||
-M virt \ | ||
-cpu any,Xcheri_v9=true \ | ||
-m 10M \ | ||
-bios none \ | ||
-drive if=pflash,file=$(1),format=raw,readonly=on -nographic \ | ||
-D /tmp/qemu.log \ | ||
-d instr,mmu | ||
|
||
# Run just the kernel on QEMU | ||
.PHONY: run | ||
run: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_pad.bin | ||
$(call invoke_qemu,$^) | ||
|
||
# Run the kernel with a bundled app on QEMU | ||
.PHONY: run_app | ||
run_app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_app.bin | ||
$(call invoke_qemu,$^) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
println!("cargo:rerun-if-changed=layout.ld"); | ||
println!("cargo:rerun-if-changed=../kernel_layout.ld"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* The QEMU virt board | ||
*/ | ||
|
||
|
||
MEMORY | ||
{ | ||
rom (rx) : ORIGIN = 0x20000000, LENGTH = 0x400000 | ||
prog (rx) : ORIGIN = 0x20400000, LENGTH = 0x4000000-0x400000 | ||
ram (rwx) : ORIGIN = 0x80000000, LENGTH = 0x800000 | ||
} | ||
|
||
MPU_MIN_ALIGN = 1; | ||
WORD_SIZE = 16; | ||
|
||
INCLUDE ../kernel_layout.ld |
Oops, something went wrong.