Makefile.src 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # disable kvm to debug triple faults
  2. QEMU_BIN=##PLACEHOLDER_1##
  3. GDB_BIN=##PLACEHOLDER_2##
  4. QEMU_ACCELERATION_FLAG=##PLACEHOLDER_3##
  5. QEMU_DEBUG_FLAG=#-d cpu_reset,int -D build/qemu.log
  6. ARCH=##PLACEHOLDER_6##
  7. ifeq ($(ARCH),x86_64)
  8. MACHINE_TYPE=q35
  9. QEMU_ARGS=-machine $(MACHINE_TYPE) -drive id=disk,file=build/boot.img,format=raw,if=none \
  10. -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -smp 4 \
  11. -no-reboot -no-shutdown $(QEMU_ACCELERATION_FLAG) $(QEMU_DEBUG_FLAG)
  12. else ifeq ($(ARCH),riscv64)
  13. MACHINE_TYPE=virt
  14. QEMU_ARGS=-machine $(MACHINE_TYPE) -drive id=disk,file=build/boot.img,format=raw,if=none \
  15. -device virtio-blk-device,drive=disk -smp 4 \
  16. -no-reboot -no-shutdown $(QEMU_ACCELERATION_FLAG) $(QEMU_DEBUG_FLAG)
  17. endif
  18. FDISK_BIN ?= ##PLACEHOLDER_5##
  19. CROSS_COMPILE=##PLACEHOLDER_4##
  20. .PHONY: run
  21. run: build
  22. $(QEMU_BIN) $(QEMU_ARGS) -display curses -S -s
  23. .PHONY: srun
  24. srun: build
  25. $(QEMU_BIN) $(QEMU_ARGS) -display none -S -s -serial mon:stdio
  26. .PHONY: nativerun
  27. nativerun: build
  28. $(QEMU_BIN) $(QEMU_ARGS) -display none -serial mon:stdio
  29. .PHONY: prepare
  30. prepare:
  31. cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug $(CROSS_COMPILE) -DARCH=$(ARCH)
  32. cp build/compile_commands.json .
  33. .PHONY: reprepare
  34. reprepare: clean prepare
  35. true
  36. .PHONY: build
  37. build:
  38. cmake --build build -j 6 --target boot.img
  39. .PHONY: clean
  40. clean:
  41. -rm -rf build
  42. -rm compile_commands.json
  43. .PHONY: clean-all
  44. clean-all: clean
  45. -rm Makefile
  46. .PHONY: debug
  47. debug:
  48. -$(GDB_BIN) --symbols=build/kernel.out \
  49. -iex 'source pretty-print.py' \
  50. -iex 'set pagination off' \
  51. -iex 'set output-radix 16' \
  52. -iex 'set print asm-demangle on' \
  53. -iex 'set print pretty on' \
  54. -iex 'target remote:1234'
  55. -killall $(QEMU_BIN)
  56. .PHONY: tmux-debug
  57. tmux-debug:
  58. tmux new-session -s gbos-debug -d
  59. -tmux split-window -t gbos-debug -hf
  60. -tmux send-keys -t gbos-debug:1.1 'make srun' C-m
  61. -tmux send-keys -t gbos-debug:1.2 'make debug' C-m C-m
  62. -tmux attach -t gbos-debug
  63. tmux kill-session -t gbos-debug
  64. build/fs.img: init_script.sh
  65. sh script/build-img.sh
  66. build/boot.img: build/fs.img build/mbr_hole.bin
  67. dd if=build/mbr_hole.bin of=build/boot.img
  68. ifeq ($(ARCH),x86_64)
  69. dd if=build/fs.img of=build/boot.img bs=$(shell expr 4 \* 1024 \* 1024) seek=1 conv=notrunc
  70. sh -c 'echo n; echo; echo; echo 8192; echo; echo a; echo w' | $(FDISK_BIN) build/boot.img
  71. else
  72. dd if=build/fs.img of=build/boot.img bs=$(shell expr 4 \* 1024 \* 1024) seek=1 conv=notrunc
  73. @echo "Note: Using default partitioning for $(ARCH)"
  74. endif
  75. build/boot.vdi: build/boot.img
  76. -rm build/boot.vdi
  77. VBoxManage convertfromraw $< $@ --format VDI
  78. .PHONY: image
  79. image: build/boot.img