summaryrefslogtreecommitdiff
path: root/Makefile
blob: 090e85fa4e5c095a5706250cfdf6078df93311a2 (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

    #####################
    #			#
    # FoolOS Build Sys.	#
    #			#
    #####################

############ some constants ############

#take care to set this properly!
USB_STICK=/dev/sdf	

#here our kernel will be loaded by the bootloader.
KERNEL_START=0x100000

#use our cross compiler
CC=i686-elf-gcc

############ compiler flags ############
CFLAGS=
CFLAGS+=-ffreestanding 
CFLAGS+=-nostdlib 
CFLAGS+=-std=gnu11
CFLAGS+= -I.
#CFLAGS+=-lgcc 
CFLAGS+=-Werror-implicit-function-declaration
#CFLAGS+= -O4
#CFLAGS+=-fdata-sections -ffunction-sections
#CFLAGS+= -Werror

############ source and object files ############

#kernel sources (asm and c)
SOURCES=
SOURCES+=$(wildcard ./kernel/*.c)
SOURCES+=$(wildcard ./video/*.c)
SOURCES+=$(wildcard ./lib/*/*.c)
SOURCES+=$(wildcard ./fs/*.c)

ASMSOURCES=$(wildcard ./asm/*.asm)

#kernel object files
OBJECTS=$(patsubst %.c, %.o, $(SOURCES))
ASMOBJECTS=$(patsubst %.asm, %.o, $(ASMSOURCES))
KERNEL_ENTRY=./boot2/kernel_entry.o

# deps
DEPS=$(patsubst %.c, %.d, $(SOURCES))

############ final image (default target) ############
all: FoolOS.vdi

new: clean all
newrun: clean run

include Makefile.common
-include $(DEPS)

######### RECURSIVE MAKES ########################

# master boot record
MBR=./boot1/mbr.bin
$(MBR):
	make -C boot1 mbr.bin

# stage 2 bootloader
STAGE2=./boot2/stage2.bin
$(STAGE2):
	make -C boot2 stage2.bin

# multiprocessor binary entry
MP_BIN=./boot2/mp.bin
$(MP_BIN):
	make -C boot2 mp.bin

# fonts
FOOLFONT=./font/binfont.bin
$(FOOLFONT):
	make -C font binfont.bin

# userspace
USERSPACE=./userspace/ext2.img
$(USERSPACE):
	make -C userspace ext2.img
	
############ linking kernel binary ############

FILLUP=fill.img
$(FILLUP):
	dd if=/dev/zero of=$(FILLUP) bs=512 count=50000


# the kernel_entry.o needs to be FIRST!!
kernel.bin: $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) 
	$(CC) $(CFLAGS) -o $@ -Wl,-Ttext,$(KERNEL_START),--oformat,binary $^ 


############ assembling of final image ############

# master boot record, kernel binary and fool-font 

FoolOS.img: $(MBR) $(STAGE2) kernel.bin $(FILLUP) FoolData.img
	cp $(FILLUP) $@
	dd if=$(MBR) of=$@ bs=512 seek=0 conv=notrunc
	dd if=$(STAGE2) of=$@ bs=512 seek=1 conv=notrunc
	dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc 	#will end up at 0x100000 in ram (this is what the booloader starts loading secotr: 10)
	dd if=FoolData.img of=$@ bs=512 seek=842 conv=notrunc	#data starts at 0x168000

FoolData.img: $(FOOLFONT) $(MP_BIN) $(USERSPACE)
	dd if=$(MP_BIN) of=$@ bs=512 seek=0 conv=notrunc
	dd if=$(FOOLFONT) of=$@ bs=512 seek=1 conv=notrunc
	dd if=$(USERSPACE) of=$@ bs=512 seek=4 conv=notrunc #will end up at 0x80800 in ram


############ virtual machines stuff ############

# vdi image for VirtualBox
FoolOS.vdi: FoolOS.img
	-rm FoolOS.vdi
	VBoxManage convertfromraw FoolOS.img FoolOS.vdi  --uuid 2f11ca11-c35d-4240-b77e-79e37d32616c 

# run in our local bochs (we need cirrus support for our vesa mode)
run: all
	~/opt/bochs-2.6.6/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug 

############ create bootable usb image ############

stick:  FoolOS.img
	cat FoolOS.img > $(USB_STICK) && sync
	xxd $(USB_STICK)  | head -n 50

############ cleanup ############

clean_release:
	-rm *.bin FoolData.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt $(STAGE2) $(DEPS)
	make -C boot1 clean
	make -C boot2 clean
	make -C userspace clean
	make -C font clean

clean: clean_release
	-rm FoolOS.img FoolOS.vdi

release: new
	-mv FoolOS.img release/
	make clean_release