forked from zirandu/linux-0.11-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.emu
252 lines (199 loc) · 5.59 KB
/
Makefile.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# 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),)
override G := 0
endif
ifeq ($(XTERM),null)
override 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 -q minix >/dev/null 2>&1; echo $$?)
ifeq ($(MINIX_FS), 0)
HDA_INSTALL = hda-install
else
MINIX_FS = $(shell sudo modprobe minix >/dev/null 2>&1; 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)
ifneq ($(XTERM), null)
XTERM_CMD ?= $(Q)$(XTERM) --working-directory=$(CURDIR) -T "$(GDB_CMD)" -e "$(GDB_CMD)"
XTERM_STATUS = $(shell $(XTERM) --help >/dev/null 2>&1; echo $$?)
else
XTERM_STATUS := 1
XTERM_CMD := null
endif
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)