加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Makefile.emu 5.44 KB
一键复制 编辑 原始数据 按行查看 历史
falcon 提交于 2017-11-15 22:16 . Makefile: fix up hda-install
# Allow to run kernel on different emulators with different prebuilt rootfs
# Rootfs preparation
hda:
$(Q)(cd $(ROOTFS_DIR); make $@)
flp:
$(Q)(cd $(ROOTFS_DIR); make $@)
ramfs:
$(Q)(cd $(ROOTFS_DIR); make $@)
hda-install:
$(Q)(cd $(ROOTFS_DIR); make $@)
hd-install: hda-install
install-hd: hd-install
flp-install:
$(Q)(cd $(ROOTFS_DIR); make $@)
fd-install: flp-install
install-fd: fd-install
ramfs-install:
$(Q)(cd $(ROOTFS_DIR); make $@)
install-ramfs: ramfs-install
hda-mount:
$(Q)(cd $(ROOTFS_DIR); make $@)
hda-umount:
$(Q)(cd $(ROOTFS_DIR); make $@)
hd-mount: hda-mount
mount-hd: hd-mount
hd-umount: hda-umount
umount-hd: hd-umount
flp-mount:
$(Q)(cd $(ROOTFS_DIR); make $@)
flp-umount:
$(Q)(cd $(ROOTFS_DIR); make $@)
fd-mount: flp-mount
mount-fd: fd-mount
fd-umount: flp-umount
umount-fd: fd-umount
ramfs-mount:
$(Q)(cd $(ROOTFS_DIR); make $@)
ramfs-umount:
$(Q)(cd $(ROOTFS_DIR); make $@)
mount-ramfs: ramfs-mount
umount-ramfs: ramfs-umount
# VM (Qemu/Bochs) Setting for different rootfs
ROOT_RAM = 0000
ROOT_FDB = 021d
ROOT_HDA = 0301
SETROOTDEV_CMD = $(SETROOTDEV) $(LINUX_IMAGE)
SETROOTDEV_CMD_RAM = $(SETROOTDEV_CMD) $(ROOT_RAM) $(ROOTFS_DIR)/$(RAM_IMG)
SETROOTDEV_CMD_FDB = $(SETROOTDEV_CMD) $(ROOT_FDB)
SETROOTDEV_CMD_HDA = $(SETROOTDEV_CMD) $(ROOT_HDA)
QEMU_CMD = $(QEMU)
_QEMU_CMD = $(QEMU)
ifeq ($(QEMU_PREBUILT),1)
QEMU_STATUS = $(shell $(QEMU_PATH)/$(QEMU) --help >/dev/null 2>&1; echo $$?)
ifeq ($(QEMU_STATUS), 0)
QEMU_CMD := $(QEMU_PATH)/$(QEMU) $(QEMU_XOPTS)
_QEMU_CMD := $(QEMU_PATH)/$(QEMU) $(QEMU_XOPTS)
endif
endif
_BOCHS_CMD = $(BOCHS)
ifeq ($(BOCHS_PREBUILT),1)
BOCHS_STATUS = $(shell $(BOCHS_PATH)/$(BOCHS) --help >/dev/null 2>&1; echo $$?)
ifeq ($(BOCHS_STATUS), 0)
_BOCHS_CMD := $(BOCHS_PATH)/$(BOCHS)
endif
endif
_QEMU_CMD += $(_QEMU_OPTS)
QEMU_CMD += $(QEMU_OPTS)
QEMU_CMD_FDB = $(QEMU_CMD) -fdb $(ROOTFS_DIR)/$(FLP_IMG)
QEMU_CMD_HDA = $(QEMU_CMD) -hda $(ROOTFS_DIR)/$(HDA_IMG)
_QEMU_CMD_HDA = $(_QEMU_CMD) -hda $(ROOTFS_DIR)/$(HDA_IMG)
nullstring :=
QEMU_DBG = $(nullstring) -s -S #-nographic #-serial '/dev/ttyS0'"
BOCHS_CFG = $(TOOL_DIR)/bochs/bochsrc
BOCHS_CMD = $(_BOCHS_CMD) -q -f $(BOCHS_CFG)/bochsrc-fda.bxrc
BOCHS_CMD_FDB = $(_BOCHS_CMD) -q -f $(BOCHS_CFG)/bochsrc-fdb.bxrc
BOCHS_CMD_HDA = $(_BOCHS_CMD) -q -f $(BOCHS_CFG)/bochsrc-hd.bxrc
BOCHS_DBG = .dbg
ifneq ($(VM),)
NEW_VM = $(VM)
else
VM ?= $(shell cat $(VM_CFG) 2>/dev/null)
ifeq ($(VM), bochs)
NEW_VM=qemu
else
NEW_VM=bochs
endif
endif
switch:
$(Q)echo "Switch to use emulator: $(NEW_VM)"
$(Q)echo $(NEW_VM) > $(VM_CFG)
VM=$(shell cat $(VM_CFG) 2>/dev/null)
ifeq ($(VM), bochs)
VM_CMD = $(BOCHS_CMD)
VM_CMD_FDB = $(BOCHS_CMD_FDB)
VM_CMD_HDA = $(BOCHS_CMD_HDA)
VM_DBG = $(BOCHS_DBG)
else
VM_CMD = $(QEMU_CMD)
VM_CMD_FDB = $(QEMU_CMD_FDB)
VM_CMD_HDA = $(QEMU_CMD_HDA)
_VM_CMD_HDA = $(_QEMU_CMD_HDA)
VM_DBG = $(QEMU_DBG)
endif
# Allow to use curses based console via ssh
# Exit with 'ESC + 2' + quit
ifneq ($(SSH_TTY),)
G ?= 0
endif
VM_DISPLAY =
ifeq ($(G),0)
ifeq ($(VM), bochs)
VM_DISPLAY = .term
else
VM_DISPLAY = $(nullstring) -curses
endif
endif
# Running on emulators with differrent rootfs
ramdisk-boot: ramfs $(LINUX_SRC)
@# Force init/main.o build with ramdisk support
$(Q)(cd $(LINUX_SRC); make -B init/main.o \
RAMDISK_SIZE=$(shell wc -c $(ROOTFS_DIR)/$(RAM_IMG) | tr -C -d '[0-9]' | xargs -i echo {}/1024 + 1 | bc))
$(Q)(cd $(LINUX_SRC); make -B kernel/blk_drv/blk_drv.a RAMDISK_START=$(RAMDISK_START))
# Boot with Image and Rootfs from harddisk
hd-boot: hd-start
# Boot with rootfs from ramfs, floppy and hardisk
boot-hd: start-hd
boot-fd: start-fd
boot: start
_boot: _start
start: ramdisk-boot Image
$(SETROOTDEV_CMD_RAM)
$(VM_CMD)$(VM_DISPLAY)
start-fd: Image flp
$(SETROOTDEV_CMD_FDB)
$(VM_CMD_FDB)$(VM_DISPLAY)
ifeq ($(OS), Linux)
MINIX_FS = $(shell lsmod | grep minix >/dev/null; echo $$?)
ifeq ($(MINIX_FS), 0)
HDA_INSTALL = hda-install
else
MINIX_FS = $(shell sudo modprobe minix >/dev/null; echo $$?)
ifeq ($(MINIX_FS), 0)
HDA_INSTALL = hda-install
endif
endif
endif
start-hd: Image hda $(HDA_INSTALL)
$(SETROOTDEV_CMD_HDA)
$(VM_CMD_HDA)$(VM_DISPLAY)
hd-start: Image hda $(HDA_INSTALL)
$(_VM_CMD_HDA)$(VM_DISPLAY)
# For any other images
_start:
$(VM_CMD)$(VM_DISPLAY)
# see examples/linux-0.11/README.md
LINUX_000 ?= $(ROOTFS_DIR)/_hda/usr/root/examples/linux-0.00/Image
linux-0.00:
$(Q)(cd $(ROOTFS_DIR); make hda-mount)
$(Q)sudo make _start LINUX_IMAGE=$(LINUX_000)
$(Q)(cd $(ROOTFS_DIR); make hda-umount)
# Debugging the above targets
GDB_CMD ?= $(GDB) --quiet $(DST)
XTERM_CMD ?= $(Q)$(XTERM) --working-directory=$(CURDIR) -T "$(GDB_CMD)" -e "$(GDB_CMD)"
XTERM_STATUS = $(shell $(XTERM) --help >/dev/null 2>&1; echo $$?)
ifeq ($(XTERM_STATUS), 0)
DEBUG_CMD = $(XTERM_CMD)
else
DEBUG_CMD = $(Q)echo "\nLOG: Please run this in another terminal:\n\n " $(GDB_CMD) "\n"
endif
gdbinit:
$(Q)echo "add-auto-load-safe-path .gdbinit" > $(HOME)/.gdbinit
ifeq ($(findstring kernel,$(DST)),kernel)
$(Q)cp .kernel_gdbinit .gdbinit
else
$(Q)cp .boot_gdbinit .gdbinit
endif
ifeq ($(OS), Darwin)
$(Q)cd tools/mac && [ -f gdb.xz ] && tar Jxf gdb.xz
endif
debug: ramdisk-boot Image gdbinit
$(SETROOTDEV_CMD_RAM)
$(DEBUG_CMD) &
$(VM_CMD)$(VM_DBG)$(VM_DISPLAY)
debug-fd: Image flp gdbinit
$(SETROOTDEV_CMD_FDB)
$(DEBUG_CMD) &
$(VM_CMD_FDB)$(VM_DBG)$(VM_DISPLAY)
debug-hd: Image hda gdbinit
$(SETROOTDEV_CMD_HDA)
$(DEBUG_CMD) &
$(VM_CMD_HDA)$(VM_DBG)$(VM_DISPLAY)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化