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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
####################
# FoolOS Build Sys #
####################
.PHONY: all new run newrun stick clean tags mount umount
############ compiler ############
GIT_REVISION=$(shell git rev-parse HEAD)
QEMU=/home/miguel/git/EXT/qemu-3.0.0/i386-softmmu/qemu-system-i386
#QEMU=qemu-system-i386
#use our cross compiler
CC=i686-foolos-gcc
AS=i686-foolos-as
#sorry just this
#CC=i686-elf-gcc
#AS=i686-elf-as
#try arm
#CC=arm-none-eabi-gcc
#CC=arm-none-eabi-as
############ compiler flags ############
#https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
CFLAGS=
#CFLAGS+=-fvar-tracking
CFLAGS+=-DGIT_REVISION=\"$(GIT_REVISION)\"
CFLAGS+=-DFOOLOS_KERNEL
CFLAGS+=-ffreestanding # do we need this if using own compiler?
CFLAGS+=-nostdlib
#CFLAGS+=-Og
CFLAGS+=-O0
#CFLAGS+=-O3
CFLAGS+=-I.
CFLAGS+=-I/home/miguel/temp/foolos/usr/i686-foolos/include/
CFLAGS+=-I./asm
CFLAGS+=-I./kernel
CFLAGS+=-I./driver
CFLAGS+=-I./fs
CFLAGS+=-I./net
CFLAGS+=-I./video
CFLAGS+=-gstabs
#CFLAGS+=-fstack-protector-all
#CFLAGS+=-fno-zero-initialized-in-bss
#CFLAGS+=-fdata-sections -ffunction-sections
#CFLAGS+= -w # disable all warnings
#CFLAGS+= -Wimplicit-function-declaration
CFLAGS+= -Wall
#CFLAGS+= -Wextra
#CFLAGS+= -pedantic
CFLAGS+= -Werror
CFLAGS+= -Werror=implicit-function-declaration
CFLAGS+= -Wno-unused-variable
CFLAGS+= -Wno-unused-function
CFLAGS+= -Wno-int-conversion
CFLAGS+= -Wno-implicit-int
CFLAGS+= -Wno-incompatible-pointer-types
CFLAGS+= -Wno-discarded-qualifiers
CFLAGS+= -Wno-unused-but-set-variable
CFLAGS+= -Wno-pointer-sign
#CFLAGS+ = -Wall -Wextra -std=c89 -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition
######## linker flags ####################
LDFLAGS=
LDLIBS+=-lgcc
########## assembler flags #################
ASFLAGS=
ASFLAGS+=-gstabs
########## verbosity ##################3
V = 0
#CC = @echo "Compiling (i686-elf-gcc) $<..."; i686-elf-gcc
#AS = @echo "Assembling (i686-elf-as) $<..."; i686-elf-as
#CC_1 = $(CCC)
#CC = $(CC_$(V))
############ source and object files and their deps ############
#kernel sources (asm and c)
SOURCES=
SOURCES+=$(wildcard ./kernel/*.c)
SOURCES+=$(wildcard ./fs/*.c)
SOURCES+=$(wildcard ./driver/*.c)
SOURCES+=$(wildcard ./terminal/*.c)
SOURCES+=$(wildcard ./lib/*/*.c)
SOURCES+=$(wildcard ./testing/*.c)
SOURCES+=$(wildcard ./net/*.c)
SOURCES+=$(wildcard ./video/*.c)
#derive kernel object files
OBJECTS=$(patsubst %.c, %.o, $(SOURCES))
#derive deps
DEPS=$(patsubst %.c, %.d, $(SOURCES))
####### ASM STUFF #####
ASM_SOURCES=$(wildcard ./asm/*.asm)
ASM_OBJECTS=$(patsubst %.asm, %.o, $(ASM_SOURCES))
ASM_MULTIBOOT=$(wildcard ./asm/*.s)
ASM_MULTIBOOT_OBJ=$(patsubst %.s, %.o, $(ASM_MULTIBOOT))
ASM_MULTIBOOT2=$(wildcard ./asm/*.S)
ASM_MULTIBOOT_OBJ2=$(patsubst %.S, %.o, $(ASM_MULTIBOOT2))
ASM_OBJECTS+=$(ASM_MULTIBOOT_OBJ)
ASM_OBJECTS+=$(ASM_MULTIBOOT_OBJ2)
#### BINARIES AND SUBMODULES ########
FOOLOS_ISO=fool-os-i386.iso
FOOLOS_ISO_EFI=fool-os-i386-efi.iso
KERNEL_IMG=foolos.img
BIN_KERNEL=kernel.bin
BIN_MBR=./boot1/mbr.bin
BIN_STAGE2=./boot2/stage2.bin
BIN_MP=./boot2/mp.bin
BIN_FOOLFONT=./font/binfont.bin
SUBDIRS=userspace
IMG_FILLUP=fill.img
IMG_USERSPACE=./userspace/ext2.img
############ Final Targets ############
all: tags $(FOOLOS_ISO) #$(FOOLOS) # tags # $(FOOLOS_VDI)
new: clean all
newrun: clean run
run: qemu-run
debug: qemu-debug
########## INCLUDES ###################
include Makefile.common
-include $(DEPS)
######### RECURSIVE MAKES ########################
CLEANDIRS=$(SUBDIRS:%=clean-%)
.PHONY: $(SUBDIRS) $(CLEANDIRS)
$(SUBDIRS):
@echo "-- Recursing make to [$@]..."; $(MAKE) --no-print-directory -C $@
@echo "-- Returned from [$@]"
$(CLEANDIRS):
@echo "-- Recursing clean to [$(@:clean-%=%)]..."; $(MAKE) --no-print-directory -C $(@:clean-%=%) clean
@echo "-- Returned from [$(@:clean-%=%)]"
############ linking kernel binary ############
$(KERNEL_IMG): $(ASM_OBJECTS) $(OBJECTS)
@echo "linking kernel..."
$(CC) $(CFLAGS) $(LDFLAGS) -T linker.ld -o $@ $^ $(LDLIBS)
############ assembling of final image ############
# master boot record, kernel binary and fool-font
#
#$(FOOLOS): $(KERNEL_IMG) $(SUBDIRS)
# sudo cp $(KERNEL_IMG) /mnt/vdi/boot
# sudo cp $(IMG_USERSPACE) /mnt/vdi/boot
# sync
############ virtual machines stuff ############
# vdi image for VirtualBox
#$(FOOLOS_VDI): disk.img
# -rm FoolOS.vdi
# #VBoxManage convertfromraw $< $@ --uuid 2f11ca11-c35d-4240-b77e-79e37d32616c
# VBoxManage convertfromraw disk.img $@ --uuid 2f11ca11-c35d-4240-b77e-79e37d32616c
# run in our local bochs (we need cirrus support for our vesa mode)
#run-bochs: all
# ~/opt/bochs-2.6.8/bin/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug
# run in qemu
qemu-run: all
#qemu-system-i386 -enable-kvm disk.img -smp 4 -s
#qemu-system-i386 -enable-kvm -s -kernel foolos.img -smp 4 -initrd userspace/ext2.img
echo XDOTOOL HACK...&& sleep 0.2 && xdotool search --name "QEMU" windowsize 100 100 && echo XDOTOOL HACK END. &
$(QEMU) -enable-kvm $(FOOLOS_ISO) -smp 4 -serial stdio \
-net nic,model=e1000 \
-net tap,ifname=tap0,script=no,downscript=no \
-vga virtio \
-m 2048
#-nographic \
#-vnc :0 \
#-net dump,file=./netfool
qemu-debug: all
echo XDOTOOL HACK...&& sleep 0.2 && xdotool search --name "QEMU" windowsize 100 100 && echo XDOTOOL HACK END. &
$(QEMU) -enable-kvm $(FOOLOS_ISO) -smp 4 -serial stdio \
-net nic,model=e1000 \
-net tap,ifname=tap0,script=no,downscript=no \
-vga virtio \
-m 1024 -s -S
# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
# qemu -enable-kvm -s -singlestep disk.img
# qemu-system-i386 -enable-kvm -s -S -kernel foolos.img -smp 4 -initrd userspace/ext2.img
#-net dump,file=./netfool \
monitor:
echo XDOTOOL HACK...&& sleep 0.2 && xdotool search --name "QEMU" windowsize 100 100 && echo XDOTOOL HACK END. &
qemu-system-i386 -s -S $(FOOLOS_ISO) -smp 4 -monitor stdio # -serial stdio #-enable-kvm -smp 1
qemu-kill:
killall qemu-system-i386
############ create bootable usb image ############
#stick: $(FOOLOS)
# cat $< > $(USB_STICK) && sync
# xxd $(USB_STICK) | head -n 50
############ cleanup ############
clean: $(CLEANDIRS)
@echo "Cleaning..."; rm -f *.bin $(FOOLOS) $(FOOLOS_ISO) $(FOOLOS_ISO_EFI) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(KERNEL_IMG) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt tags grubiso/boot/foolos.bin grubiso/boot/ext2.img
@echo "Cleaning Documentation..."; rm -f ./doc/ -r
tags:
@echo "Generating ctags..."; ctags --recurse=yes .
############ mounting #############
#mount: disk.img
# echo "* mounting disk image"
# sudo losetup /dev/loop1 $< -o 1048576
# sudo mount /dev/loop1 /mnt/vdi
#umount:
# echo "* unmounting disk image"
# sudo umount /mnt/vdi
# sudo losetup -d /dev/loop1
##### ISO #####
$(FOOLOS_ISO): $(KERNEL_IMG) userspace
@echo "------------------------"
@echo "Create ISO..."
@cp $(KERNEL_IMG) grubiso/boot/foolos.bin
@cp $(IMG_USERSPACE) grubiso/boot
# @grub-mkrescue -d /usr/lib/grub/x86_64-efi -o $(FOOLOS_ISO_EFI) grubiso/
@grub-mkrescue -d /usr/lib/grub/i386-pc -o $(FOOLOS_ISO) grubiso/
# @grub-mkrescue -d /usr/lib/grub/i386-pc -d /usr/lib/grub/i386-efi -d /usr/lib/grub/x86_64-efi -o $(FOOLOS_ISO) grubiso/
@echo "Finished ISO"
@echo "------------------------"
#### README ###
gitweb_readme:
markdown README.md | ssh git readme miguel/fool-os set
### DOC ###
doxygen: clean
doxygen doxy.cfg
## headers ##
list_headers:
find asm/ driver/ fs/ kernel/ lib/ -iname *.h -exec basename {} \; | sort | uniq -c
#tap interface#
create_tap:
sudo tunctl -t tap0 -u miguel
sudo ip link set tap0 up
sudo route add -host 192.168.0.20 dev tap0
#qemu-system-i386 -netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no -enable-kvm fool-os-i386.iso -smp 4 -serial stdio
# tunctl -u <username>
#-net user,hostfwd=tcp::10022-:22\
#echo 1 > /proc/sys/net/ipv4/ip_forward
#echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp
#echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp
#https://blog.elastocloud.org/2015/07/qemukvm-bridged-network-with-tap.html
create_bridged:
sudo ip link add br0 type bridge
sudo ip addr flush dev eth0
sudo ip link set eth0 master br0
sudo ip tuntap add dev tap0 mode tap user miguel
sudo ip link set tap0 master br0
sudo ip link set dev br0 up
sudo ip link set dev tap0 up
sudo dhclient
|