blob: bd707ec5b48322a25a4817dbf23657895c2b8f6d (
plain)
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
|
#####################
# #
# FoolOS Build Sys. #
# #
#####################
# main phony targets
.PHONY: all new run newrun stick clean
############ some constants ############
#submodules
SUBDIRS=boot1 boot2 font userspace
FOOLOS=FoolOS.img
FOOLOS_VDI=FoolOS.vdi
#take care to set this properly!
USB_STICK=/dev/sdf
#use our cross compiler
CC=i686-foolos-gcc
############ compiler flags ############
CFLAGS=
CFLAGS+=-fstack-protector-all
CFLAGS+=-Werror-implicit-function-declaration
CFLAGS+=-w
CFLAGS+=-ffreestanding
CFLATS+=-Wall
CFLAGS+=-Wextra
#CFLAGS+=-O3
CFLAGS+=-O0
#CFLAGS+=-nostdlib
CFLAGS+=-std=gnu11
CFLAGS+=-I.
CFLAGS+=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include
#CFLAGS+=-lgcc
#CFLAGS+=-fno-zero-initialized-in-bss
#CFLAGS+= -O4
#CFLAGS+=-fdata-sections -ffunction-sections
#CFLAGS+= -Werror
LDFLAGS=
LDFLAGS+=-nostdlib
LDFLAGS+=-lgcc
#verbosity
#V = 0
#CC = @echo "Compiling $<..."; i686-foolos-gcc
#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 ./video/*.c)
SOURCES+=$(wildcard ./lib/*/*.c)
SOURCES+=$(wildcard ./fs/*.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))
KERNEL_ENTRY=./asm/kernel_entry.o
############ Final Targets ############
all: FoolOS.vdi FoolOS.img
new: clean all
########### INCLUDES ###################3
include Makefile.common
-include $(DEPS)
#### BINARIES AND SUBMODULES ########
BIN_KERNEL=kernel.bin
BIN_MBR=./boot1/mbr.bin
BIN_STAGE2=./boot2/stage2.bin
BIN_MP=./boot2/mp.bin
BIN_FOOLFONT=./font/binfont.bin
IMG_FILLUP=fill.img
IMG_USERSPACE=./userspace/ext2.img
######### RECURSIVE MAKES ########################
CLEANDIRS=$(SUBDIRS:%=clean-%)
.PHONY: $(SUBDIRS) $(CLEANDIRS)
$(SUBDIRS):
$(MAKE) -C $@
$(CLEANDIRS):
$(MAKE) -C $(@:clean-%=%) clean
############ linking kernel binary ############
# the kernel_entry.o needs to be FIRST!!
$(BIN_KERNEL): $(KERNEL_ENTRY) $(ASM_OBJECTS) $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -T linker.ld -o $@ $^
############ assembling of final image ############
# master boot record, kernel binary and fool-font
$(FOOLOS): $(BIN_KERNEL) $(SUBDIRS)
dd if=$(BIN_MBR) of=$@ bs=512 seek=0 conv=notrunc
dd if=$(BIN_STAGE2) of=$@ bs=512 seek=1 conv=notrunc
# kernel will start at 0x100000 in ram (this is what the booloader starts loading secotr: 10)
dd if=$(BIN_KERNEL) of=$@ bs=512 seek=10 conv=notrunc # kernel can be about 128KB (incl bss)
# the data will starts at 0x120000 in ram
dd if=$(IMG_USERSPACE) of=$@ bs=512 seek=266 conv=notrunc
############ virtual machines stuff ############
# vdi image for VirtualBox
$(FOOLOS_VDI): $(FOOLOS)
-rm FoolOS.vdi
VBoxManage convertfromraw $< $@ --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.6/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug
run-qemu: all
qemu-system-i386 $(FOOLOS)
run: run-bochs
newrun: clean run
############ create bootable usb image ############
stick: $(FOOLOS)
cat $< > $(USB_STICK) && sync
xxd $(USB_STICK) | head -n 50
############ cleanup ############
clean: $(CLEANDIRS)
-rm *.bin $(FOOLOS) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt
|