Makefile 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. arch ?= riscv64
  2. target := $(arch)imac-unknown-none-elf
  3. mode := release
  4. kernel := target/$(target)/$(mode)/riscv
  5. bin := target/$(target)/$(mode)/kernel.bin
  6. img := target/$(target)/$(mode)/img
  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 ($(arch), riscv32)
  15. START_ADDR := 0x80400000
  16. else ifeq ($(arch), riscv64)
  17. START_ADDR := 0x80200000
  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. $(bin): kernel
  27. $(objcopy) $(kernel) --strip-all -O binary $@
  28. asm:
  29. $(objdump) -d $(kernel) | less
  30. sym:
  31. $(objdump) -t $(kernel) | less
  32. header:
  33. $(objdump) -x $(kernel) | less
  34. clean:
  35. cargo clean
  36. qemu: $(bin) $(img)
  37. qemu-system-$(arch) \
  38. -machine virt \
  39. -serial mon:stdio \
  40. -bios default \
  41. -device loader,file=$(bin),addr=$(START_ADDR) \
  42. -drive file=$(img),if=none,format=raw,id=x0 \
  43. -device virtio-blk-device,drive=x0 \
  44. -device virtio-gpu-device \
  45. -device virtio-mouse-device
  46. $(img):
  47. dd if=/dev/zero of=$@ bs=512 count=32
  48. run: build qemu