Files
riscv64-kernel/justfile

64 lines
1.9 KiB
Makefile

release := ""
qemu_flags := ""
cargo_flags := "" + if release != "" { "--release" } else { "" }
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
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 $USER),uid=$(id -u $USER) disk.img mnt
sync_filesystem:
sync
update-std:
@cd library/std && just update-std
build-sysroot:
@cd library/std && just build-sysroot
build_user_prog prog:
RUSTFLAGS="-C relocation-model=pic -C link-arg=-pie --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }} --package {{ prog }}
riscv64-elf-strip {{ bin_path / prog }}
cp {{ bin_path / prog }} {{ "mnt/usr/bin" / prog }}
build: mount_filesystem (map_dir "user" f"just release=\"{{release}}\" cargo_flags=\"{{cargo_flags}}\" build_user_prog")
RUSTFLAGS="-Clink-arg=-Tilm.ld --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }}
just sync_filesystem
run: build (runner f"{{bin_path / "kernel-rust"}}")
map_dir dir recipe:
@for file in `ls {{ dir }}`; do \
{{ recipe }} $file ; \
done
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 \
-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
gdb: build
{{ qemu }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
gf2
runner args:
{{ qemu }} -kernel {{ args }}
clean:
cd library && just clean
cargo clean