Makefile 1.9 KB

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