Giter Club home page Giter Club logo

loader's Introduction

The Hermit Loader

This project is a loader to run the Hermit kernel within QEMU.

Requirements

Building

$ cargo xtask build --target <TARGET> --release

With <TARGET> being either x86_64, x86_64-uefi, or aarch64.

Afterward, the loader is located at target/<TARGET>/release/hermit-loader.

Running

x86-64

On x86-64 Linux with KVM, you can boot Hermit like this:

$ qemu-system-x86_64 \
    -enable-kvm \
    -cpu host \
    -smp 1 \
    -m 128M \
    -device isa-debug-exit,iobase=0xf4,iosize=0x04 \
    -display none -serial stdio \
    -kernel <LOADER> \
    -initrd <APP>

No KVM

If you want to emulate x86-64 instead of using KVM, omit -enable-kvm and set the CPU explicitly to a model of your choice, for example -cpu Skylake-Client.

Benchmarking

If you want to benchmark Hermit, make sure to enable the invariant TSC (invtsc) feature by setting -cpu host,migratable=no,+invtsc,enforce.

Providing Arguments

Unikernel arguments can be provided like this:

$ qemu-system-x86_64 ... \
    -append "[KERNEL_ARGS] [--] [APP_ARGS]"

AArch64

On AArch64, the base command is as follows:

$ qemu-system-aarch64 \
                  -machine virt,gic-version=3 \
                  -cpu cortex-a76 \
                  -smp 1 \
                  -m 512M  \
                  -semihosting \
                  -display none -serial stdio \
                  -kernel <LOADER> \
                  -device guest-loader,addr=0x48000000,initrd=<APP>

Debugging

You can use QEMU to debug the loaded Hermit images:

  1. Start your Hermit image normally.

    Look for the following line:

    [LOADER][INFO] Loading kernel to <START>..<END> (len = <LEN> B)
    

    We need to know <START> to tell GDB later where the program is loaded.

  2. Add -S -s to your QEMU command.

    -S makes QEMU start with a stopped CPU, which can be started explicitly. -s is a shorthand for -gdb tcp::1234 for accepting GDB connections.

  3. Start GDB without arguments.

    You should use the rust-gdb or rust-gdbgui wrappers for Rust's pretty printing. Both respect the RUST_GDB environment variable for cross-debugging (e.g., aarch64-elf-gdb).

  4. Connect to QEMU.

    target remote :1234
  5. Load the Hermit image to the correct address.

    We can now tell GDB where the Hermit image will be located:

    symbol-file -o <START> <IMAGE_PATH>
  6. Debug away!

    You can now add breakpoints and start execution:

    b hermit::boot_processor_main
    c

    For fast iteration times, consider creating a .gdbinit.

Using QEMU as microvm

QEMU provides the microvm virtual platform, which is a minimalist machine type without PCI nor ACPI support. Microvms have a smaller memory footprint and a faster boot time.

To use this VM type, PCI and ACPI support have to be disabled for your app (using no-default-features).

$ qemu-system-x86_64 ... \
    -M microvm,x-option-roms=off,pit=off,pic=off,rtc=on,auto-kernel-cmdline=off \
    -nodefaults -no-user-config \
    -append "-freq 2800"

Depending on the virtualized processor, the processor frequency has to be passed as kernel argument (-freq, in MHz).

Network support

To enable an Ethernet device, we have to set up a tap device on the host system. The following commands establish the tap device tap10 on Linux:

# ip tuntap add tap10 mode tap
# ip addr add 10.0.5.1/24 broadcast 10.0.5.255 dev tap10
# ip link set dev tap10 up
# echo 1 > /proc/sys/net/ipv4/conf/tap10/proxy_arp

If you want Hermit to be accessible from outside the host, you have to enable IP forwarding:

# sysctl -w net.ipv4.ip_forward=1

You need to enable the tcp feature of the kernel.

The network configuration can be set via environment variables during compile time. By default, it is:

HERMIT_IP="10.0.5.3"
HERMIT_GATEWAY="10.0.5.1"
HERMIT_MASK="255.255.255.0"

Currently, Hermit only supports Virtio:

$ qemu-system-x86_64 ... \
    -netdev tap,id=net0,ifname=tap10,script=no,downscript=no,vhost=on \
    -device virtio-net-pci,netdev=net0,disable-legacy=on

You can now access the files in SHARED_DIRECTORY under the virtiofs tag like /myfs/testfile.

License

Licensed under either of

at your option.

loader's People

Contributors

bors[bot] avatar cagatay-y avatar dependabot[bot] avatar duanyu-yu avatar jounathaen avatar jschwe avatar mkroening avatar n-eiling avatar simonschoening avatar stlankes avatar tlambertz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loader's Issues

Remove lib.rs

Only having main.rs would make detecting unused code easier.

Properly support small bootloaders

When the code section of the bootloader is smaller than normal, the free physical memory starts at 0x600000 instead of 0x800000 and booting fails:

[LOADER] Loader: [0x100000 - 0x116008]
[LOADER] Found Multiboot information at 0x9500
[LOADER] Found module: [0x118000 - 0x49c1d0]
[LOADER] Module length: 0x3841d0
[LOADER] Found an ELF module at 0x118000
[LOADER] Map 232 pages at 0x118000 (page size 4 KByte)
[LOADER] Map 2 pages at 0x200000 (page size 2048 KByte)
[LOADER] Found entry point: 0x82f410
[LOADER] File Size: 2627224 Bytes
[LOADER] Mem Size: 3147104 B
[LOADER] start 0x118000, size 0x300560
[LOADER] Load HermitCore Application at 0x600000
[LOADER] Copy kernel from 0x600000 to 0x800000
[LOADER] Loader: [0x100000 - 0x116008]
... (loop)

QEMU 6.2 support

Upgrading to QEMU 6.2 results in

Could not open option rom 'multiboot_dma.bin': No such file or directory

Rename to hermit-loader

This would be a clearer name and fit better with our non-existing naming guidelines ๐Ÿ˜‰

UEFI support

UEFI (or more specific OVMF) is needed for AMD SEV which would be a nice addition to RustyHermit. Any chance in getting UEFI support?

ASLR support

uhyve should load the application at random start addresses. This is an important step to support ASLR.

Outdated data layout

When building with make release=1, one gets:

warning: Linking two modules of different data layouts: '' is 'e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128' whereas 'rusty_loader.7uo39jl7-cgu.0' is 'e-m:e-i64:64-f80:128-n8:16:32:64-S128'

rust-lang/rust@8b19922 updated the data layouts to include new X86 address spaces in preparation for LLVM 10 rust-lang/rust#67900.

I think, it would be best to update our data layouts. I'll prepare PRs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.