-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
182 lines (121 loc) · 3.68 KB
/
makefile
File metadata and controls
182 lines (121 loc) · 3.68 KB
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
173
174
175
176
177
178
179
180
181
182
# Makefile code mashup of
# https://github.com/mit-pdos/xv6-public/blob/master/Makefile
# https://github.com/berkus/jamesm-tutorials/blob/master/Makefile
# Compiles every file in SOURCES, then links them together into one ELF binary (aka kernel)
# Setup -----------------------------
# Source paths
SRCDIR = src/
VPATH = $(SRCDIR)
# C files
CSOURCES = \
main.c \
$(SRCDIR)common.c \
$(SRCDIR)monitor.c \
$(SRCDIR)descriptorTables.c \
$(SRCDIR)interrupts.c \
$(SRCDIR)timer.c \
$(SRCDIR)kernelHeap.c \
$(SRCDIR)paging.c \
$(SRCDIR)orderedArray.c \
$(SRCDIR)fileSystem.c \
$(SRCDIR)initialRamDisk.c
COBJECTS = \
main.o \
$(SRCDIR)common.o \
$(SRCDIR)monitor.o \
$(SRCDIR)descriptorTables.o \
$(SRCDIR)interrupts.o \
$(SRCDIR)timer.o \
$(SRCDIR)kernelHeap.o \
$(SRCDIR)paging.o \
$(SRCDIR)orderedArray.o \
$(SRCDIR)fileSystem.o \
$(SRCDIR)initialRamDisk.o
# Assembly files
SSOURCES = \
boot.s \
$(SRCDIR)descriptorTables_.s \
$(SRCDIR)interrupts_.s
SOBJECTS = \
boot.o \
$(SRCDIR)descriptorTables_.o \
$(SRCDIR)interrupts_.o
# Images
ELF = kernel
INITRD = initialRamDisk.img
# Other makefiles
FSMAKEPATH = tools/make_fs
# 32 bit flags
CFLAGS = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Wall -g
ASFLAGS = -f elf -F dwarf -g
LDFLAGS = -T link.ld -m elf_i386
# 64 bit flags
# CFLAGS = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -Wall -g
# ASFLAGS = -f elf64 -F dwarf -g
# LDFLAGS = -T link.ld
# Generate ELF ----------------------
all:
make clean
@echo "Making all the things!"
make _all
make subsystem
_all: $(SOBJECTS) $(COBJECTS) link
clean:
@echo "Removing object files ..."
-rm *.o $(SRCDIR)*.o $(ELF)
link:
@echo "Linking ..."
ld $(LDFLAGS) -o $(ELF) $(SOBJECTS) $(COBJECTS)
.s.o:
@echo "Assembling" $< "..."
nasm $(ASFLAGS) $<
.c.o:
@echo "Compiling" $< "..."
gcc -c $(CFLAGS) $< -o $@
# Generate initrd -------------------
subsystem:
cd $(FSMAKEPATH) && $(MAKE)
# Run QEMU --------------------------
# Path to QEMU
QEMU = qemu-system-i386
# Flags
# QEMUOPTS = -kernel $(ELF)
# QEMUOPTS = -kernel $(ELF) -D logfile -d cpu_reset
QEMUOPTS = -kernel $(ELF) -initrd $(INITRD)
# QEMUOPTS = -kernel $(ELF) -initrd $(INITRD) -D logfile -d cpu_reset
# Try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
# QEMU's gdb stub command line changed in 0.11
QEMUGDB = \
$(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
# Prompt user to setup GDB appropriately
gdbinit:
@echo "\nOpen gdb in another window and type the following:"
@#echo " set architecture i386"
@echo " file kernel"
@echo " target remote :"$(GDBPORT)
@echo "Use 'break' to set breakpoints, and 'continue' to execute.\n"
qemu:
make all
@echo "Starting QEMU ..."
@echo "If using curses, press Esc+2 then type 'quit' to exit"
@# $(QEMU) $(QEMUOPTS)
$(QEMU) -display curses $(QEMUOPTS)
qemu-nox:
make all
@echo "Starting QEMU ..."
$(QEMU) -nographic -monitor stdio $(QEMUOPTS)
qemu-gdb:
make all
make gdbinit
@echo "Starting QEMU ..."
@#$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
$(QEMU) -display curses $(QEMUOPTS) -S $(QEMUGDB)
qemu-nox-gdb:
make all
make gdbinit
@echo "Starting QEMU ..."
@echo "If using curses, press Esc+2 then type 'quit' to exit"
$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)