Makefile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. arch ?= riscv64
  2. target := $(arch)imac-unknown-none-elf
  3. mode := release
  4. kernel := target/$(target)/$(mode)/riscv
  5. img := target/$(target)/$(mode)/img
  6. sysroot := $(shell rustc --print sysroot)
  7. objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch)
  8. objcopy := $(shell find $(sysroot) -name llvm-objcopy)
  9. BUILD_ARGS += --target $(target)
  10. ifeq ($(mode), release)
  11. BUILD_ARGS += --release
  12. endif
  13. .PHONY: kernel build clean qemu run env
  14. build: $(bin)
  15. env:
  16. rustup component add llvm-tools-preview rustfmt
  17. rustup target add $(target)
  18. kernel:
  19. cargo build $(BUILD_ARGS)
  20. asm:
  21. $(objdump) -d $(kernel) | less
  22. sym:
  23. $(objdump) -t $(kernel) | less
  24. header:
  25. $(objdump) -x $(kernel) | less
  26. clean:
  27. cargo clean
  28. qemu-legacy: kernel $(img)
  29. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  30. ( sleep 4 && nc localhost 5555 -v < /dev/null) &
  31. qemu-system-$(arch) \
  32. $(QEMU_ARGS) \
  33. -machine virt \
  34. -serial mon:stdio \
  35. -bios default \
  36. -kernel $(kernel) \
  37. -drive file=$(img),if=none,format=raw,id=x0 \
  38. -device virtio-blk-device,drive=x0 \
  39. -device virtio-gpu-device \
  40. -device virtio-mouse-device \
  41. -device virtio-net-device,netdev=net0 \
  42. -netdev user,id=net0,hostfwd=tcp::5555-:5555
  43. qemu: kernel $(img)
  44. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  45. ( sleep 4 && nc localhost 5555 -v < /dev/null) &
  46. qemu-system-$(arch) \
  47. $(QEMU_ARGS) \
  48. -machine virt \
  49. -serial mon:stdio \
  50. -bios default \
  51. -kernel $(kernel) \
  52. -global virtio-mmio.force-legacy=false \
  53. -drive file=$(img),if=none,format=raw,id=x0 \
  54. -device virtio-blk-device,drive=x0 \
  55. -device virtio-gpu-device \
  56. -device virtio-mouse-device \
  57. -device virtio-net-device,netdev=net0 \
  58. -netdev user,id=net0,hostfwd=tcp::5555-:5555
  59. $(img):
  60. dd if=/dev/zero of=$@ bs=512 count=32
  61. run: build qemu-legacy qemu