131 lines
4.4 KiB
Makefile
131 lines
4.4 KiB
Makefile
release := ""
|
|
qemu_flags := ""
|
|
cargo_flags := "" + if release != "" { "--release" } else { "" }
|
|
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
|
|
rust_src := `rustc --print sysroot` / "lib/rustlib/src/rust/library/std/src"
|
|
|
|
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
|
|
|
|
cp_std path:
|
|
@echo "Copying {{ path }}"
|
|
@mkdir {{ "crates/std/src" / parent_directory(path) }} -p
|
|
@cp {{ rust_src / path }} {{ "crates/std/src" / path }}
|
|
@sed -i -f patches.sed {{ "crates/std/src" / path }}
|
|
|
|
insert_target line path:
|
|
@sed -i '{{ line }}a \target_os = "survos",' {{ "crates/std/src" / path }}
|
|
|
|
update_std:
|
|
@# Not copied : sys/mod.rs, io.rs, error.rs, thread.rs, sync.rs
|
|
# @just cp_std "process.rs"
|
|
# @just cp_std "fs.rs"
|
|
@just cp_std "time.rs"
|
|
@just cp_std "bstr.rs"
|
|
@just cp_std "io/error.rs"
|
|
@just cp_std "io/error/repr_bitpacked.rs"
|
|
@just cp_std "io/cursor.rs"
|
|
@just cp_std "io/prelude.rs"
|
|
@just cp_std "io/impls.rs"
|
|
@just cp_std "hash/mod.rs"
|
|
@just cp_std "hash/random.rs"
|
|
@just cp_std "num/mod.rs"
|
|
@just cp_std "ffi/c_str.rs"
|
|
@just cp_std "ffi/mod.rs"
|
|
@just cp_std "ffi/os_str.rs"
|
|
@just cp_std "ffi/os_str/tests.rs"
|
|
@just cp_std "thread/local.rs"
|
|
@just cp_std "sys/exit.rs"
|
|
@just cp_std "sys/env_consts.rs"
|
|
@just cp_std "sys/configure_builtins.rs"
|
|
@just cp_std "sys/cmath.rs"
|
|
@just cp_std "sys/sync/condvar/mod.rs"
|
|
@just cp_std "sys/sync/condvar/no_threads.rs"
|
|
@just cp_std "sys/sync/mutex/mod.rs"
|
|
@just cp_std "sys/sync/mutex/no_threads.rs"
|
|
@just cp_std "sys/sync/once/mod.rs"
|
|
@just cp_std "sys/sync/once/no_threads.rs"
|
|
@just cp_std "sys/sync/rwlock/mod.rs"
|
|
@just cp_std "sys/sync/rwlock/no_threads.rs"
|
|
@just cp_std "sys/thread/mod.rs"
|
|
@just cp_std "sys/thread/unsupported.rs"
|
|
@just cp_std "sys/thread_local/no_threads.rs"
|
|
@just cp_std "sys/thread_local/os.rs"
|
|
@just cp_std "sys/time/mod.rs"
|
|
@just cp_std "sys/time/unsupported.rs"
|
|
@just cp_std "sys/random/mod.rs"
|
|
@just cp_std "sys/random/unsupported.rs"
|
|
@just cp_std "sys/env/mod.rs"
|
|
@just cp_std "sys/env/common.rs"
|
|
@just cp_std "sys/env/unsupported.rs"
|
|
@just cp_std "sys/os_str/mod.rs"
|
|
@just cp_std "sys/os_str/bytes.rs"
|
|
@just cp_std "sys/os_str/bytes/tests.rs"
|
|
@just cp_std "sys/path/mod.rs"
|
|
@just cp_std "sys/fs/mod.rs"
|
|
@just cp_std "sys/fs/common.rs"
|
|
@just cp_std "sys/fs/unsupported.rs"
|
|
@just cp_std "sys/io/error/generic.rs"
|
|
@just cp_std "sys/io/io_slice/unsupported.rs"
|
|
@just cp_std "sys/io/is_terminal/unsupported.rs"
|
|
@just cp_std "sys/io/kernel_copy/mod.rs"
|
|
@just cp_std "sys/io/mod.rs"
|
|
@just insert_target 108 "sys/random/mod.rs"
|
|
@just insert_target 125 "sys/random/mod.rs"
|
|
@# Copied but edited for the moment
|
|
# @just cp_std "sys/thread_local/mod.rs"
|
|
# @just cp_std "sys/alloc/mod.rs"
|
|
# @just cp_std "sys/io/error/mod.rs"
|
|
# @just cp_std "alloc.rs"
|
|
# @just cp_std "path.rs"
|
|
# @just cp_std "sys/path/unix.rs"
|
|
|
|
build_user_prog prog:
|
|
RUSTFLAGS="-C relocation-model=pic -C link-arg=-Tuser.ld -C link-arg=-pie" 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")
|
|
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:
|
|
cargo clean
|