-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (103 loc) · 3.17 KB
/
Makefile
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
CC = gcc
CCFLAGS := -c -march=i386 -nostdlib -ffreestanding -Wall
CCFLAGS += -Iinclude -lgcc -fno-PIE -nostartfiles
CCFLAGS += -m32 -masm=intel
AS = nasm
ASFLAGS = -felf32
LD = ld
LDFLAGS = -m elf_i386 -N --oformat binary
BOCHS = bochs
BOCHSFLAGS = -q -f bochsrc.bxrc
BUILD = build
IMG = bootflpy.img
KERNEL = bootloader.bin kernel.bin
HARDDISK = mydisk.hdd
USRDIR = usr
USR = prg1.com prg2.com prg3.com prg4.com box.com syscall.com
USR += fork.out fork2.out bank.out fruit.out pro-con.out hello.out matmal.out file.out
ifdef DEBUG
CCFLAGS += -DDEBUG
DEBUGFILES = kernel.s
endif
all: build osker
-rm -f $(IMG)
/sbin/mkfs.msdos -C $(IMG) 1440
dd if=$(BUILD)/bootloader.bin of=$(IMG) conv=notrunc
dd if=$(BUILD)/kernel.bin of=$(IMG) seek=1 conv=notrunc # 2nd sector
build:
-mkdir $(BUILD)
osker: $(KERNEL)
bootloader.bin: bootloader.asm
$(AS) -fbin $< -o $(BUILD)/$@
kernel.bin: kernel_entry.o kernel.o
$(LD) $(LDFLAGS) -Ttext 0x7e00 $(BUILD)/kernel_entry.o $(BUILD)/kernel.o -o $(BUILD)/$@
kernel_entry.o : kernel_entry.asm
$(AS) $(ASFLAGS) $< -o $(BUILD)/$@
kernel.o : kernel.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/$@
# user programs
disk:
-rm $(HARDDISK)
/sbin/mkfs.msdos -C $(HARDDISK) 1440
-mkdir disk
mount $(HARDDISK) disk
mkdir disk/myfolder
mkdir disk/myfolder/folder
mkdir disk/testfold
cp $(BUILD)/usr/*.com disk
cp $(BUILD)/usr/*.out disk
cp usr/test.txt disk/myfolder/folder/test.txt
umount disk
-rm -rf disk
programs: buildprg $(foreach prg,$(USR),$(USRDIR)/$(prg)) $(DEBUGFILES)
buildprg:
-mkdir $(BUILD)
-mkdir $(BUILD)/$(USRDIR)
%.com : %.asm
$(AS) $< -o $(BUILD)/$@
# generate elf file
# %.out : %.c
# $(CC) $(CCFLAGS) $< -o $(BUILD)/$@
# $(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/$@.o -o $(BUILD)/$@
usr/fork.out: usr/fork.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/fork.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/fork.o -o $(BUILD)/$@
usr/fork2.out: usr/fork2.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/fork2.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/fork2.o -o $(BUILD)/$@
usr/bank.out: usr/bank.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/bank.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/bank.o -o $(BUILD)/$@
usr/fruit.out: usr/fruit.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/fruit.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/fruit.o -o $(BUILD)/$@
usr/pro-con.out: usr/pro-con.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/pro-con.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/pro-con.o -o $(BUILD)/$@
usr/hello.out: usr/hello.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/hello.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/hello.o -o $(BUILD)/$@
usr/matmal.out: usr/matmal.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/matmal.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/matmal.o -o $(BUILD)/$@
usr/file.out: usr/file.c
$(CC) $(CCFLAGS) $< -o $(BUILD)/file.o
$(LD) -m elf_i386 -Tusr/link.ld $(BUILD)/file.o -o $(BUILD)/$@
# debug
%.s : %.c
$(CC) $(CCFLAGS) -S $< -o $@
# readelf -h fork.out ## show hex
# readelf -S fork.out ## show section headers
# readelf -l fork.out ## show program headers
# objdump -d fork.out ## show assembly
# hd fork.out
# emulation
run: bochs
bochs:
$(BOCHS) $(BOCHSFLAGS)
.PHONY : clean
clean :
-rm -rf $(BUILD)
-rm -f *.o *.bin *.com *.elf *.s $(IMG) $(PROGS) *.lock bochsout.txt
cleandisk:
-rm $(HARDDISK)