Makefile.src 2.7 KB

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