From 16cb391342cdf309c7ea24d768c3a47b4f75abb9 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:19:43 -0700 Subject: [PATCH 1/9] Reference Spike and real hardware * Support for these is not complete --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e684945..3468a91 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Note: you will be [billed](https://cloud.google.com/run/pricing) by Google for a ## Run Diosix from source in a container -To build Diosix from source and boot it with a prebuilt guest OS within a Docker container on your own system, create a container image of the software: +To build Diosix from source and boot it within Qemu with a prebuilt guest OS within a Docker container on your own system, create a container image of the software: ``` git clone https://github.com/diodesign/diosix.git @@ -84,7 +84,7 @@ As with Google Cloud Run, log into the provided guest Linux OS environment as `r ## Run Diosix from source without a container -To build and run Diosix from its latest source code without using Docker, follow [these instructions](docs/running.md). +To build and run Diosix on real hardware, or within Qemu or Spike, from its latest source code without using Docker, follow [these instructions](docs/running.md). ## Frequently anticipated questions From 735a507705b124ded35e023c9715801ef0b3784b Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:20:18 -0700 Subject: [PATCH 2/9] Include recipes for running on Spike * Provide a receipe for installing Diosix on a storage device --- justfile | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/justfile b/justfile index dd297da..0bc5778 100644 --- a/justfile +++ b/justfile @@ -7,6 +7,9 @@ # Build and run diosix in Qemu, using the defaults: # just # +# Build and run diosix in Spike, using the defaults: +# just spike +# # Only build diosix using the defaults: # just build # @@ -32,8 +35,14 @@ # Set target to the architecture you want to build for. Eg: # just target=riscv64imac-unknown-none-elf # -# Set emubin to the Qemu system emulator binary you want to use to run diosix, Eg: -# just emubin=qemu-system-riscv64 +# Set qemubin to the path of the Qemu system emulator binary you want to use to run diosix, Eg: +# just qemubin=qemu-system-riscv64 +# +# Set spikebin to the path of the Spike binary you want to use to run diosix, Eg: +# just spikebin=$HOME/src/riscv-isa-sim/build/spike +# +# Set spikeisa to the RISC-V ISA to use with Spike, eg: +# just spikeisa=RV64IMAC # # Set objcopybin to the objcopy suitable for the target architecture. Eg: # just objcopybin=riscv64-linux-gnu-objcopy install @@ -46,8 +55,8 @@ # Set to yes to only report warnings and errors. Eg: # just quiet=no # just quiet=yes -# -# Set cpus to the number of CPU cores to run within qemu, eg: +# +# Set cpus to the number of CPU cores to run within qemu and spike, eg: # just cpus=1 # # Force debug text output via Qemu's serial port by setting qemuprint to yes, eg: @@ -56,6 +65,9 @@ # Force debug text output via SiFive's serial port by setting sifiveprint to yes, eg: # just sifiveprint=yes # +# Force debug text output via Spike's HTIF by setting htifprint to yes, eg: +# just htifprint=yes +# # Disable hypervisor's regular integrity checks by setting integritychecks to no, eg: # just integritychecks=no # @@ -72,13 +84,17 @@ # just guests-build=no # # The defaults are: -# emubin qemu-system-riscv64 +# qemubin qemu-system-riscv64 +# spikebin spike +# spikeisa RV64IMAFDC # target riscv64gc-unknown-none-elf # objcopybin riscv64-linux-gnu-objcopy # quality debug # quiet yes # cpus 4 # qemuprint no +# sifiveprint no +# htifprint no # integritychecks yes # services yes # guests yes @@ -98,18 +114,22 @@ cleanmsg := msgprefix + "Cleaning build tree" rustupmsg := msgprefix + "Ensuring Rust can build for" builtmsg := msgprefix + "Diosix built and ready to use at" qemumsg := msgprefix + "Running Diosix in Qemu" +spikemsg := msgprefix + "Running Diosix in Spike" installmsg := msgprefix + "Installing" installedmsg := msgprefix + "Diosix installed on disk" # define defaults, these are overriden by the command line target := "riscv64gc-unknown-none-elf" -emubin := "qemu-system-riscv64" +qemubin := "qemu-system-riscv64" +spikebin := "spike" +spikeisa := "RV64IMAFDC" objcopybin := "riscv64-linux-gnu-objcopy" quality := "debug" quiet := "yes" cpus := "4" qemuprint := "no" sifiveprint := "no" +htifprint := "no" integritychecks := "yes" services := "yes" guests := "yes" @@ -127,6 +147,7 @@ quiet_redir_sw := if quiet == "yes" { "> /dev/null " } else { "" } verbose_sw := if quiet == "no" { "--verbose " } else { "" } qemuprint_sw := if qemuprint == "yes" { "--features qemuprint" } else { "" } sifiveprint_sw := if sifiveprint == "yes" { "--features sifiveprint" } else { "" } +htifprint_sw := if htifprint == "yes" { "--features htifprint" } else { "" } cargo_sw := quiet_sw + release_sw + "--target " + target integritychecks_sw := if integritychecks == "yes" { "--features integritychecks" } else { "" } services_sw := if services == "no" { "--skip-services" } else { "" } @@ -138,7 +159,12 @@ builds_sw := if guests-build == "no" { "--skip-buildroot" } else { "" } # build diosix with its components, and run it within qemu @qemu: build echo "{{qemumsg}}" - {{emubin}} -bios none -nographic -machine virt -smp {{cpus}} -m 1G -kernel {{final-exe-path}} + {{qemubin}} -bios none -nographic -machine virt -smp {{cpus}} -m 1G -kernel {{final-exe-path}} + +# build diosix, and run it within spike +@spike: build + echo "{{spikemsg}}" + {{spikebin}} --isa={{spikeisa}} -p{{cpus}} -m1024 {{final-exe-path}} # build and install diosix with its components onto a disk (requires root via sudo) @install: build @@ -161,7 +187,7 @@ builds_sw := if guests-build == "no" { "--skip-buildroot" } else { "" } # build the hypervisor and ensure it has a boot file system to include @_hypervisor: _mkdmfs echo "{{buildmsg}} hypervisor" - cd src/hypervisor && cargo build {{cargo_sw}} {{qemuprint_sw}} {{sifiveprint_sw}} {{integritychecks_sw}} + cd src/hypervisor && cargo build {{cargo_sw}} {{qemuprint_sw}} {{sifiveprint_sw}} {{htifprint_sw}} {{integritychecks_sw}} # build and run the dmfs generator to include banners and system services. # mkdmfs is configured by manifest.toml in the project root directory. From 1c75656c79764bff60df8c9faf3a30141654cda5 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:20:39 -0700 Subject: [PATCH 3/9] Support directly writing debug to HTIF --- src/hypervisor/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hypervisor/Cargo.toml b/src/hypervisor/Cargo.toml index ad8d477..4cd80ea 100644 --- a/src/hypervisor/Cargo.toml +++ b/src/hypervisor/Cargo.toml @@ -20,6 +20,7 @@ serde_derive = "1.0.118" [features] qemuprint = [] # enable to force debug text through Qemu's serial port sifiveprint = [] # enable to force debug text through SiFive's standard serial port +htifprint = [] # enable to force debug text through Spike's HTIF integritychecks = [] # enable to check integrity of per-CPU structures from overwrites */ # local and special dependencies From 25948de8bf2d5cc1a1aa973efaba6c477ce90f18 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:20:56 -0700 Subject: [PATCH 4/9] Use HTIF-supporting platform code --- src/hypervisor/src/platform-riscv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hypervisor/src/platform-riscv b/src/hypervisor/src/platform-riscv index b9ca6b5..a66d625 160000 --- a/src/hypervisor/src/platform-riscv +++ b/src/hypervisor/src/platform-riscv @@ -1 +1 @@ -Subproject commit b9ca6b58e57a1dfa047d26bb37a3c9f20075e9e2 +Subproject commit a66d62552e80a2670eec96e78e8465ff52377147 From 323110615b8b81f61b1bae4440d04b5e7d80835f Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:21:23 -0700 Subject: [PATCH 5/9] In case it wasn't clear, only one core does the DMFS unpacking at boot time --- src/hypervisor/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hypervisor/src/main.rs b/src/hypervisor/src/main.rs index b484d5a..bfb224d 100644 --- a/src/hypervisor/src/main.rs +++ b/src/hypervisor/src/main.rs @@ -201,6 +201,7 @@ fn hvmain(cpu_nr: PhysicalCoreID, dtb_ptr: *const u8, dtb_len: u32) -> Result<() as such, only allow supervisor-mode capable CPU cores to build capasules */ if pcore::PhysicalCore::smode_supported() == true { + /* only allow one core to do the unpacking */ let mut flag = MANIFEST_UNPACKED.lock(); if *flag == false From 969f69ca7fc2f1b95e0acede15cad27f3119d588 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:23:51 -0700 Subject: [PATCH 6/9] Support direct-to-HTIF debug output feature --- src/hypervisor/src/debug.rs | 8 ++++++++ src/hypervisor/src/devicetree | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hypervisor/src/debug.rs b/src/hypervisor/src/debug.rs index 8a801e7..edc3458 100644 --- a/src/hypervisor/src/debug.rs +++ b/src/hypervisor/src/debug.rs @@ -141,6 +141,14 @@ impl fmt::Write for ConsoleWriter unsafe { *(tx_register as *mut u32) = *c as u32 }; } } + else if cfg!(feature = "htifprint") + { + extern "C" { fn platform_write_to_htif(byte: u8); } + for c in s.as_bytes() + { + unsafe { platform_write_to_htif(*c) } + } + } else { /* queue the output for printing out later when ready */ diff --git a/src/hypervisor/src/devicetree b/src/hypervisor/src/devicetree index 080adab..87c23af 160000 --- a/src/hypervisor/src/devicetree +++ b/src/hypervisor/src/devicetree @@ -1 +1 @@ -Subproject commit 080adab23c412133f0fd02000b4ab8722bcda129 +Subproject commit 87c23afedf37d12213a9cc8606d5df839fb0ac4d From bbe250f6dc9a417e83488f9cfda4dca875438a0d Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:24:27 -0700 Subject: [PATCH 7/9] Include instructions on running Diosix on Spike and SiFive hardware * This support isn't complete --- docs/running.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/running.md b/docs/running.md index f0aa6af..19e2233 100644 --- a/docs/running.md +++ b/docs/running.md @@ -11,6 +11,8 @@ The outcome will booting one or more guest operating systems, such as Linux, on 1. [Getting started](#prep) 1. [Run Diosix in Qemu](#qemu) 1. [Using the system console](#console) +1. [Run Diosix in Spike](#spike) +1. [Run Diosix on real hardware](#realhw) 1. [Build without running](#buildonly) 1. [Options for building and running](#opts) 1. [Output build diagnostic messages](#opt_quiet) @@ -69,6 +71,37 @@ By default, Diosix will run a system service called `gooey` that provides a very Currently, `gooey` displays output text from all capsules, though when typing into it, either via Qemu or a real system's serial port, that input text is sent only to the first guest. The coloring of the input and output text can be temporarily altered by the guest, for example when listing files with `ls` and displaying executables in a special color. The exact colors seen may vary depending on the color scheme used by your terminal. +## Run Diosix in Spike + +Once you have completed the [preparatory steps](#prep), run Diosix in the Spike RISC-V simulator: + +``` +just spike +``` + +Press `Control-c` to enter Spike's interactive debug mode. Instructions on how to use this mode are [here](https://github.com/riscv/riscv-isa-sim#interactive-debug-mode). Enter the command `q` or press `Control-c` again to quit the simulator from the debug mode. + +## Run Diosix on real hardware + +**Warning: Follow the next steps with care! The storage device specified below will be reformatted with a new GPT-based partitioning scheme, with the hypervisor and its dmfs image stored in partition 1. This will render any prior data on the device inaccessible. See [LICENSE](../LICENSE) for more information on the conditions and terms of use of this documentation** + +Once you have completed the [preparatory steps](#prep), build Diosix and install it on an SD card or similar storage device for use in a physical system: + +``` +just disk=/dev/sdX install +``` + +Replace `/dev/sdX` with the path of the storage device you wish to install Diosix on. The installation process will require superuser privileges via `sudo`, and so your user account must be a `sudoer` for this just recipe to work. Once complete, the device can be used in a compatible computer. So far, this recipe supports: + +* SiFive's [HiFive Unleashed](https://www.sifive.com/boards/hifive-unleashed) + 1. Ensure the Unleashed board's boot mode switches are all set to `1`. + 1. Insert a microSD card into the host building Diosix and run the above command, replacing `/dev/sdX` with the card's path to install the hypervisor to the card. + 1. Remove the microSD card and insert it into the Unleashed board. + 1. Connect the host to the Unleashed board's microUSB port via a suitable USB cable. + 1. Power on or reset the Unleashed board. + 1. Run the command `sudo screen /dev/ttyUSBX 115200` on the host to access the board's serial port console. You should replace `/dev/ttyUSBX` with the Unleashed's USB-to-serial interface. Typically, `X` is `1`. + 1. You should see Diosix's output in the serial port console. + ## Build without running To build Diosix without running the software: From f7977a5de20f103c33f5e1916059cb337ca33a66 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 02:26:55 -0700 Subject: [PATCH 8/9] Acknowledge that Spike and SiFIve support is incomplete --- docs/running.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/running.md b/docs/running.md index 19e2233..1310ce9 100644 --- a/docs/running.md +++ b/docs/running.md @@ -79,7 +79,7 @@ Once you have completed the [preparatory steps](#prep), run Diosix in the Spike just spike ``` -Press `Control-c` to enter Spike's interactive debug mode. Instructions on how to use this mode are [here](https://github.com/riscv/riscv-isa-sim#interactive-debug-mode). Enter the command `q` or press `Control-c` again to quit the simulator from the debug mode. +Press `Control-c` to enter Spike's interactive debug mode. Instructions on how to use this mode are [here](https://github.com/riscv/riscv-isa-sim#interactive-debug-mode). Enter the command `q` or press `Control-c` again to quit the simulator from the debug mode. Note that support for Spike is not yet complete. ## Run Diosix on real hardware @@ -93,7 +93,7 @@ just disk=/dev/sdX install Replace `/dev/sdX` with the path of the storage device you wish to install Diosix on. The installation process will require superuser privileges via `sudo`, and so your user account must be a `sudoer` for this just recipe to work. Once complete, the device can be used in a compatible computer. So far, this recipe supports: -* SiFive's [HiFive Unleashed](https://www.sifive.com/boards/hifive-unleashed) +* SiFive's [HiFive Unleashed](https://www.sifive.com/boards/hifive-unleashed). To run Diosix on this system: 1. Ensure the Unleashed board's boot mode switches are all set to `1`. 1. Insert a microSD card into the host building Diosix and run the above command, replacing `/dev/sdX` with the card's path to install the hypervisor to the card. 1. Remove the microSD card and insert it into the Unleashed board. @@ -102,6 +102,8 @@ Replace `/dev/sdX` with the path of the storage device you wish to install Diosi 1. Run the command `sudo screen /dev/ttyUSBX 115200` on the host to access the board's serial port console. You should replace `/dev/ttyUSBX` with the Unleashed's USB-to-serial interface. Typically, `X` is `1`. 1. You should see Diosix's output in the serial port console. +Note that support for real hardware is not yet complete. + ## Build without running To build Diosix without running the software: From d2773459bafa093383d8a2320e98e35f21b48e70 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Sun, 21 Mar 2021 07:02:23 -0700 Subject: [PATCH 9/9] Use latest submodules with riscv asm fix * Thanks to @Stupremee for fixing the riscv dependency build breakage --- src/mason | 2 +- src/services/src/supervisor-riscv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mason b/src/mason index 2bad0dd..8da6657 160000 --- a/src/mason +++ b/src/mason @@ -1 +1 @@ -Subproject commit 2bad0dd76c6db5b2d3451aaca3dda76580f0f1a5 +Subproject commit 8da66577e3e8497a0f1359f29af79f23bdf971cc diff --git a/src/services/src/supervisor-riscv b/src/services/src/supervisor-riscv index 19ddbe9..8fc7bad 160000 --- a/src/services/src/supervisor-riscv +++ b/src/services/src/supervisor-riscv @@ -1 +1 @@ -Subproject commit 19ddbe9ac404ad09963fde7f9060125dfb98f53f +Subproject commit 8fc7bad8e4ccf076bb77d513a0aad099cc82ca22