Makefile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. qemu-system-$(arch) \
  30. -machine virt \
  31. -serial mon:stdio \
  32. -bios default \
  33. -kernel $(kernel) \
  34. -drive file=$(img),if=none,format=raw,id=x0 \
  35. -device virtio-blk-device,drive=x0 \
  36. -device virtio-gpu-device \
  37. -device virtio-mouse-device \
  38. # -netdev type=tap,id=net0,script=no,downscript=no \
  39. # -device virtio-net-device,netdev=net0
  40. qemu: kernel $(img)
  41. qemu-system-$(arch) \
  42. -machine virt \
  43. -serial mon:stdio \
  44. -bios default \
  45. -kernel $(kernel) \
  46. -global virtio-mmio.force-legacy=false \
  47. -drive file=$(img),if=none,format=raw,id=x0 \
  48. -device virtio-blk-device,drive=x0 \
  49. -device virtio-gpu-device \
  50. -device virtio-mouse-device \
  51. # -netdev type=tap,id=net0,script=no,downscript=no \
  52. # -device virtio-net-device,netdev=net0
  53. $(img):
  54. dd if=/dev/zero of=$@ bs=512 count=32
  55. run: build qemu-legacy qemu