Makefile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. tcp ?= 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. ifeq ($(tcp), on)
  15. BUILD_ARGS += --features tcp
  16. else
  17. BUILD_ARGS += --no-default-features
  18. endif
  19. .PHONY: kernel build clean qemu run env
  20. build: $(bin)
  21. env:
  22. rustup component add llvm-tools-preview rustfmt
  23. rustup target add $(target)
  24. kernel:
  25. cargo build $(BUILD_ARGS)
  26. asm:
  27. $(objdump) -d $(kernel) | less
  28. sym:
  29. $(objdump) -t $(kernel) | less
  30. header:
  31. $(objdump) -x $(kernel) | less
  32. clean:
  33. cargo clean
  34. qemu-legacy: kernel $(img)
  35. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  36. ( sleep 4 && echo "hello" | nc localhost 5555 -N -v) &
  37. qemu-system-$(arch) \
  38. $(QEMU_ARGS) \
  39. -machine virt \
  40. -serial mon:stdio \
  41. -bios default \
  42. -kernel $(kernel) \
  43. -drive file=$(img),if=none,format=raw,id=x0 \
  44. -device virtio-blk-device,drive=x0 \
  45. -device virtio-gpu-device \
  46. -device virtio-mouse-device \
  47. -device virtio-net-device,netdev=net0 \
  48. -netdev user,id=net0,hostfwd=tcp::5555-:5555
  49. qemu: kernel $(img)
  50. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  51. ( sleep 4 && echo "hello" | nc localhost 5555 -N -v) &
  52. qemu-system-$(arch) \
  53. $(QEMU_ARGS) \
  54. -machine virt \
  55. -serial mon:stdio \
  56. -bios default \
  57. -kernel $(kernel) \
  58. -global virtio-mmio.force-legacy=false \
  59. -drive file=$(img),if=none,format=raw,id=x0 \
  60. -device virtio-blk-device,drive=x0 \
  61. -device virtio-gpu-device \
  62. -device virtio-mouse-device \
  63. -device virtio-net-device,netdev=net0 \
  64. -netdev user,id=net0,hostfwd=tcp::5555-:5555
  65. $(img):
  66. dd if=/dev/zero of=$@ bs=512 count=32
  67. run: build qemu-legacy qemu