Files
riscv64-kernel/justfile

79 lines
2.6 KiB
Makefile

release := ""
qemu_flags := ""
cargo_flags := "" + if release != "" { "--release" } else { "" }
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
GDB := "gf2"
default: run
mount_filesystem:
@# Add some permissions to be able to do next operations without sudo
mountpoint -q mnt || sudo mount -o umask=0022,gid=$(id -g),uid=$(id -u) disk.img mnt
update-std:
@cd library/std && {{ just_executable() }} update-std
build-sysroot:
@cd library/std && {{ just_executable() }} build-sysroot
build_user_prog prog:
RUSTFLAGS="-Clink-arg=-Tuser.ld -C relocation-model=pic -C link-arg=-pie --sysroot {{ justfile_directory() / "sysroot" }}" \
cargo b {{ cargo_flags }} --package {{ prog }}
cp {{ bin_path / prog }} {{ bin_path / prog + "-stripped" }}
if command -v riscv64-elf-strip >/dev/null 2>&1; then \
riscv64-elf-strip {{ bin_path / prog + "-stripped" }}; \
fi
cp {{ bin_path / prog + "-stripped" }} {{ "mnt/usr/bin" / prog }}
make-symbols:
cd build-tools && cargo r --bin gen-symbols --release
build: mount_filesystem
#!/usr/bin/env bash
set -e
for file in `ls user`; do
{{ just_executable() }} release="{{ release }}" cargo_flags="{{ cargo_flags }}" build_user_prog $file;
done
RUSTFLAGS="-Cforce-frame-pointers=yes -Clink-arg=-Tilm.ld --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }}
{{ just_executable() }} make-symbols
sync
run: build (runner f"{{bin_path / "kernel-rust"}}")
QEMU := f"qemu-system-riscv64 \
-machine virt \
-serial mon:stdio \
-device bochs-display \
-device virtio-keyboard-pci \
-device virtio-mouse-pci \
-device loader,file=disk.img,addr=0xA0000000 \
-device loader,file=target/symbols.bin,addr=0xB0000000 \
-bios none -m 1024M {{qemu_flags}}"
# -trace \"virtio*\"
# -d guest_errors,unimp,int"
perf: build
{{ QEMU }} -perfmap -kernel {{ bin_path / "kernel-rust" }}&
perf record --output=/tmp/perf.data --call-graph=dwarf -F 999 -p $(pidof qemu-system-riscv64) -- sleep 20; exit 0
cd /tmp && hotspot perf.data
dbg: build
{{ QEMU }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
{{ GDB }}
dbg-user prog addr: build
{{ QEMU }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
{{ GDB }} -nx \
-ex "target remote localhost:1234" \
-ex "break *{{ addr }}" \
-ex "add-symbol-file target/riscv64/debug/{{ prog }} {{ addr }}" \
-ex "c"
runner args:
{{ QEMU }} -kernel {{ args }}
clean:
cd library && {{ just_executable() }} clean
cargo clean