Makefile 1.6 KB

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