Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 28 changed files with 3,171 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ members = [
"boards/nano33ble",
"boards/nano33ble_rev2",
"boards/qemu_rv32_virt",
"boards/qemu_cheri_virt",
"boards/swervolf",
"boards/weact_f401ccu6/",
"boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256",
Expand Down Expand Up @@ -93,6 +94,7 @@ members = [
"chips/stm32f4xx",
"chips/swerv",
"chips/swervolf-eh1",
"chips/uarts",
"chips/virtio",
"kernel",
"libraries/enum_primitive",
Expand Down
1 change: 1 addition & 0 deletions arch/cortex-m/src/mpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use kernel::utilities::math;
use kernel::utilities::registers::interfaces::{Readable, Writeable};
use kernel::utilities::registers::{register_bitfields, FieldValue, ReadOnly, ReadWrite};
use kernel::utilities::StaticRef;
use kernel::{ErrorCode, ProcessId};

/// Smallest allowable MPU region across all CortexM cores
/// Individual cores may have bigger min sizes, but never lower than 32
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition.workspace = true
kernel = { path = "../../kernel" }
tock-registers = { path = "../../libraries/tock-register-interface" }
riscv-csr = { path = "../../libraries/riscv-csr" }
misc = { path = "../../libraries/misc" }

[features]
page_align_pmp = []
Expand Down
9 changes: 4 additions & 5 deletions boards/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PLATFORM := $(firstword $(shell $(CARGO) tree))
# Set `TARGET` if not already defined. Note: this only works on nightly.
ifeq ($(TARGET),)
# Get the specified target using the unstable `cargo config get` command.
TARGET_QUOTES := $(shell $(CARGO) config get --format json-value build.target)
TARGET_QUOTES := $(shell $(CARGO) -Z unstable-options config get --format json-value build.target)
# Remove the quotes from around the target name.
TARGET := $(patsubst "%",%,$(TARGET_QUOTES))
endif
Expand Down Expand Up @@ -189,7 +189,6 @@ endif

# Dump configuration for verbose builds
ifeq ($(VERBOSE_MODE),1)
RUST_FLAGS = $(shell $(CARGO) -Zunstable-options config get build.rustflags --format json-value 2> /dev/null || echo "Listing Rust flags only accessible on nightly cargo")
$(info )
$(info *******************************************************)
$(info TOCK KERNEL BUILD SYSTEM -- VERBOSE BUILD CONFIGURATION)
Expand All @@ -201,7 +200,7 @@ RUST_FLAGS = $(shell $(CARGO) -Zunstable-options config get build.rustflags --fo
$(info PLATFORM = $(PLATFORM))
$(info TARGET = $(TARGET))
$(info TOCK_KERNEL_VERSION = $(TOCK_KERNEL_VERSION))
$(info RUSTFLAGS = $(RUST_FLAGS))
$(info RUSTFLAGS = $(RUSTC_FLAGS_TOCK))
$(info MAKEFLAGS = $(MAKEFLAGS))
$(info OBJDUMP_FLAGS = $(OBJDUMP_FLAGS))
$(info OBJCOPY_FLAGS = $(OBJCOPY_FLAGS))
Expand Down Expand Up @@ -299,10 +298,10 @@ $(TOCK_ROOT_DIRECTORY)tools/sha256sum/target/debug/sha256sum:

.PHONY: $(TARGET_PATH)/release/$(PLATFORM)
$(TARGET_PATH)/release/$(PLATFORM):
$(Q)$(CARGO) rustc $(VERBOSE_FLAGS) --bin $(PLATFORM) --release
$(Q)RUSTFLAGS="$(RUSTC_FLAGS_TOCK)" $(CARGO) rustc $(CARGO_FLAGS_TOCK) --bin $(PLATFORM) --release -- $(RUSTC_FLAGS_FOR_BIN)
$(Q)$(SIZE) $(SIZE_FLAGS) $@

.PHONY: $(TARGET_PATH)/debug/$(PLATFORM)
$(TARGET_PATH)/debug/$(PLATFORM):
$(Q)$(CARGO) build $(VERBOSE_FLAGS) --bin $(PLATFORM)
$(Q)RUSTFLAGS="$(RUSTC_FLAGS_TOCK)" $(CARGO) rustc $(CARGO_FLAGS_TOCK) --bin $(PLATFORM) -- $(RUSTC_FLAGS_FOR_BIN)
$(Q)$(SIZE) $(SIZE_FLAGS) $@
4 changes: 2 additions & 2 deletions boards/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
// If you are intentionally not using the standard Tock config files, set
// `cfg-tock-buildflagssentinel` in your cargo config to prevent this
// error.
if std::env::var("HOST") != std::env::var("TARGET") {
/*if std::env::var("HOST") != std::env::var("TARGET") {
let rust_flags = std::env::var("CARGO_ENCODED_RUSTFLAGS");
if !rust_flags
.iter()
Expand All @@ -49,7 +49,7 @@ fn main() {
Verify you have not unintentionally set the RUSTFLAGS environment variable."
);
}
}
}*/

// Include the folder where the board's Cargo.toml is in the linker file
// search path.
Expand Down
21 changes: 21 additions & 0 deletions boards/qemu_cheri_virt/Cargo.toml
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
103 changes: 103 additions & 0 deletions boards/qemu_cheri_virt/Makefile
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,$^)
4 changes: 4 additions & 0 deletions boards/qemu_cheri_virt/build.rs
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");
}
15 changes: 15 additions & 0 deletions boards/qemu_cheri_virt/layout.ld
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
Loading

0 comments on commit 9dcf42a

Please sign in to comment.