Makefile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. arch := x86_64
  2. target := x86_64-unknown-none
  3. mode := release
  4. kernel := target/$(target)/$(mode)/$(arch)
  5. img := target/$(target)/$(mode)/img
  6. accel := on
  7. sysroot := $(shell rustc --print sysroot)
  8. objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch)
  9. objcopy := $(shell find $(sysroot) -name llvm-objcopy)
  10. BUILD_ARGS += --target $(target)
  11. ifeq ($(mode), release)
  12. BUILD_ARGS += --release
  13. endif
  14. VSOCK_BUILD_ARGS =
  15. ifeq ($(mode), release)
  16. VSOCK_BUILD_ARGS += --release
  17. endif
  18. QEMU_ARGS += \
  19. -machine q35 \
  20. -serial mon:stdio \
  21. -kernel $(kernel) \
  22. -device virtio-gpu-pci -vga none \
  23. -device virtio-blk-pci,drive=x0 -drive file=$(img),if=none,format=raw,id=x0 \
  24. -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:5555
  25. ifeq ($(accel), on)
  26. QEMU_ARGS += -cpu host -accel kvm
  27. endif
  28. .PHONY: kernel clean qemu run env
  29. kernel:
  30. cargo build $(BUILD_ARGS) --config 'build.rustflags="--cfg platform=\"qemu\" -Clink-args=-Tlinker.ld -Clink-args=-no-pie"'
  31. env:
  32. rustup component add llvm-tools-preview rustfmt
  33. rustup target add $(target)
  34. asm: kernel
  35. $(objdump) -d $(kernel) | less
  36. sym: kernel
  37. $(objdump) -t $(kernel) | less
  38. header: kernel
  39. $(objdump) -x $(kernel) | less
  40. clean:
  41. cargo clean
  42. qemu: kernel $(img)
  43. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  44. ( sleep 4 && echo "hello" | nc localhost 5555 -N -v) &
  45. qemu-system-$(arch) $(QEMU_ARGS)
  46. $(img):
  47. dd if=/dev/zero of=$@ bs=512 count=32
  48. run: qemu