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

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


############ phony targets ############

.PHONY: all clean run


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

USB_STICK=/dev/sdf	#take care!

MP_IMG_START=26112	#code for the other processors intialllly at 0x6600

FONT_DATA_START=26624	#fool font initially at 0x6800

DATA_START=32768	#0x8000 here we put some "files" later a fs.

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


############ flags ############

CFLAGS=-ffreestanding -std=gnu99 -m32 -fno-asynchronous-unwind-tables -O0 
CFLAGS+= -I.
#CFLAGS+=-fdata-sections -ffunction-sections
#CFLAGS+= -Werror


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

#kernel sources (asm and c)

SOURCES=$(wildcard ./kernel/*.c)
SOURCES+=$(wildcard ./lib/*/*.c)
ASMSOURCES=$(wildcard ./asm/*.asm)

#kernel object files

OBJECTS=$(patsubst %.c, %.o, $(SOURCES))
ASMOBJECTS=$(patsubst %.asm, %.o, $(ASMSOURCES))
KERNEL_ENTRY=./boot/kernel_entry.o

#master boot record asm

MBR=./boot/mbr.bin


#multiprocessor binary entry

MP_BIN=./boot/mp.bin


#some fillup data (zeros)

FILLUP=./data/fill.bin


############ final image (default target) ############

all: FoolOS.img 


############ nasm assembling rules ############

%.o: %.asm
	nasm -f elf $^ -o $@

%.bin: %.asm
	nasm -f bin $^ -o $@


############ linking kernel binary ############

# the kernel_entry.o needs to be FIRST!!
kernel.bin: $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) 
	ld -o $@ -Ttext $(KERNEL_START) --oformat binary -melf_i386 $^ -O0 # --gc-sections --entry=kernel_main -v


############ fool-font ############

binfont.bin: data/binfont.src
	python tools/binarize.py $< $@


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

# master boot record, kernel binary and fool-font 

FoolOS.img: $(MBR) kernel.bin $(MP_BIN) binfont.img $(FILLUP) data.img
	cp $(FILLUP) $@
	dd if=$(MBR) of=$@ bs=1 seek=0 conv=notrunc
	dd if=kernel.bin of=$@ bs=1 seek=512 conv=notrunc
	dd if=$(MP_BIN) of=$@ bs=1 seek=$(MP_IMG_START) conv=notrunc
	dd if=binfont.img of=$@ bs=1 seek=$(FONT_DATA_START) conv=notrunc
	dd if=data.img of=$@ bs=1 seek=$(DATA_START) conv=notrunc

data.img: data/testdata
	cp $^ $@


binfont.img:  binfont.bin
	cat $^ > $@


############ vm stuff ############

# run in our local bochs (we need cirrus support for our vesa mode)

run: FoolOS.img
	~/opt/bochs-2.6.6/bochs -q -rc bochsdebug


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

clean:
	-rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt

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



##### floppy operations #######
floppy_losetup_on:
	sudo losetup /dev/loop0 data/floppy.img
floppy_losetup_off:
	sudo losetup -d /dev/loop0 
floppy_init:
	sudo dd if=/dev/zero of=data/floppy.img count=2880 bs=512