Makefile 1.6 KB

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