-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (120 loc) · 2.91 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
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
B=boot
K=kernel
D=device
T=thread
U=userprog
L=lib
F=fs
S=shell
LU=lib/user
LK=lib/kernel
# BOCHS相关参数
BOCHS_PATH=/home/cooiboi/bochs/bin/bochs
BOCHS_GDB_PATH=/home/forrest/bochs/bin/bochs
BOCHS_PORt="target remote 127.0.0.1:1234"
BOCHS_GDB_FLAG='gdbstub:enabled=1,port=1234,text_base=0,data_base=0,bss_base=0'
K_OBJS=$K/main.o \
$K/init.o \
$K/interrupt.o\
$K/debug.o \
$K/memory.o
D_OBJS=$D/keyboard.o \
$D/timer.o \
$D/ioqueue.o \
$D/ide.o \
$D/console.o
T_OBJS=$T/sync.o \
$T/thread.o
U_OBJS=$U/tss.o \
$U/process.o \
$U/syscall_init.o \
$U/fork.o \
$U/exec.o \
$U/wait_exit.o
F_OBJS=$F/fs.o \
$F/inode.o \
$F/dir.o \
$F/file.o
S_OBJS=$S/shell.o \
$S/buildin_cmd.o \
$S/pipe.o
L_OBJS=$L/stdio.o \
$L/stdint.o \
$L/string.o
LU_OBJS=${LU}/syscall.o \
${LU}/assert.o
LK_OBJS=${LK}/stdio_kernel.o \
${LK}/bitmap.o \
${LK}/list.o \
${LK}/io.o \
${LK}/print.o
GCC_FLAGS = -c -Wall -m32 -ggdb \
-nostdinc -fno-builtin -fno-stack-protector -mno-sse -g
OBJS=${K_OBJS} \
${D_OBJS} \
${T_OBJS} \
${U_OBJS} \
${LK_OBJS} \
${LU_OBJS} \
${L_OBJS} \
${F_OBJS} \
${S_OBJS}
include= -I $K -I $D -I $T -I $U -I $L -I $F -I $S -I ${LK} -I ${LU}
build:${OBJS}
nasm -I $B/include -o $B/mbr.bin $B/mbr.asm
nasm -I $B/include -o $B/loader.bin $B/loader.asm
nasm -f elf -o $K/kernel.o $K/kernel.asm
nasm -f elf -o $T/switch.o $T/switch.asm
ld -m elf_i386 -T kernel.ld -o kernel.bin ${OBJS} $K/kernel.o $T/switch.o
$K/%.o:$K/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$D/%.o:$D/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$T/%.o:$T/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$U/%.o:$U/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$L/%.o:$L/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$F/%.o:$F/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
$S/%.o:$S/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
${LK}/%.o:${LK}/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
${LU}/%.o:${LU}/%.c
gcc ${include} ${GCC_FLAGS} -o $@ $^
dd: build
dd if=/dev/zero of=$B/boot.img bs=1M count=60
dd if=$B/mbr.bin of=$B/boot.img bs=512 count=1 conv=notrunc
dd if=$B/loader.bin of=$B/boot.img bs=512 count=4 seek=2 conv=notrunc
dd if=kernel.bin of=$B/boot.img bs=512 count=200 seek=9 conv=notrunc
run:dd
# @ rm -rf hd80M.img
# sh partition.sh
# cd command && sh compile.sh
${BOCHS_PATH} -qf bochsrc.disk
make clean
run_gdb:dd
# @ rm -rf hd80M.img
# sh partition.sh
# cd command && sh compile.sh
${BOCHS_GDB_PATH} -qf bochsrc.disk ${BOCHS_GDB_FLAG} &
gdb ./kernel.bin -ex ${BOCHS_PORt}
pkill bochs
make clean
clean:
@ rm -rf *.lock
@ rm -rf boot/*.lock
@ rm -f kernel/*.o
@ rm -f device/*.o
@ rm -f thread/*.o
@ rm -f userprog/*.o
@ rm -f boot/*.bin
@ rm -f *.bin
@ rm -f boot/*.img
@ rm -rf lib/user/*.o
@ rm -rf lib/kernel/*.o
@ rm -rf lib/*.o
@ rm -rf fs/*.o
@ rm -rf command/*.o