1 | ############################################################################# |
---|
2 | # ALMOS-MKH Makefile for x86_64 # |
---|
3 | ############################################################################# |
---|
4 | |
---|
5 | # Compilation flags. |
---|
6 | CFLAGS = -Wall -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-avx -g \ |
---|
7 | -fno-delete-null-pointer-checks -mcmodel=large -std=gnu89 |
---|
8 | |
---|
9 | # Export all variables to applications sub-Makefile. |
---|
10 | export |
---|
11 | CC = gcc |
---|
12 | AS = as |
---|
13 | LD = ld |
---|
14 | DU = objdump |
---|
15 | AR = ar |
---|
16 | |
---|
17 | # Rules that don't build target files |
---|
18 | # always out-of-date, need to be regenerated everytime they are called |
---|
19 | .PHONY: compile \ |
---|
20 | dirs \ |
---|
21 | list \ |
---|
22 | extract \ |
---|
23 | fsck \ |
---|
24 | clean \ |
---|
25 | build-disk \ |
---|
26 | build/kernel/kernel.elf |
---|
27 | |
---|
28 | # Objects to be linked for the x86 drivers library |
---|
29 | DRIVERS_OBJS = build/kernel/drivers/ioc_ata.o \ |
---|
30 | build/kernel/drivers/pic_apic.o \ |
---|
31 | build/kernel/drivers/txt_rs232.o |
---|
32 | |
---|
33 | # Objects to be linked for kernel.elf generation |
---|
34 | KERN_OBJS = build/kernel/kern/kernel_init.o \ |
---|
35 | build/kernel/kern/printk.o \ |
---|
36 | build/kernel/kern/thread.o \ |
---|
37 | build/kernel/kern/process.o \ |
---|
38 | build/kernel/kern/chdev.o \ |
---|
39 | build/kernel/kern/cluster.o \ |
---|
40 | build/kernel/kern/scheduler.o \ |
---|
41 | build/kernel/kern/core.o \ |
---|
42 | build/kernel/kern/dqdt.o \ |
---|
43 | build/kernel/kern/do_syscall.o \ |
---|
44 | build/kernel/kern/do_interrupt.o \ |
---|
45 | build/kernel/kern/rpc.o \ |
---|
46 | build/kernel/kern/signal.o |
---|
47 | |
---|
48 | HAL_OBJS = \ |
---|
49 | build/kernel/hal/hal_boot.o \ |
---|
50 | build/kernel/hal/hal_smpboot.o \ |
---|
51 | build/kernel/hal/hal_init.o \ |
---|
52 | build/kernel/hal/hal_cpu.o \ |
---|
53 | build/kernel/hal/hal_kentry.o \ |
---|
54 | build/kernel/hal/hal_acpi.o \ |
---|
55 | build/kernel/hal/hal_apic.o \ |
---|
56 | build/kernel/hal/x86_printf.o \ |
---|
57 | build/kernel/hal/hal_drivers.o \ |
---|
58 | build/kernel/hal/hal_special.o \ |
---|
59 | build/kernel/hal/hal_context.o \ |
---|
60 | build/kernel/hal/hal_atomic.o \ |
---|
61 | build/kernel/hal/hal_remote.o \ |
---|
62 | build/kernel/hal/hal_uspace.o \ |
---|
63 | build/kernel/hal/hal_irqmask.o \ |
---|
64 | build/kernel/hal/hal_gpt.o \ |
---|
65 | build/kernel/hal/hal_ppm.o \ |
---|
66 | build/kernel/hal/hal_exception.o \ |
---|
67 | build/kernel/hal/hal_interrupt.o \ |
---|
68 | build/kernel/hal/hal_syscall.o |
---|
69 | |
---|
70 | DEV_OBJS = build/kernel/devices/dev_txt.o \ |
---|
71 | build/kernel/devices/dev_ioc.o \ |
---|
72 | build/kernel/devices/dev_mmc.o \ |
---|
73 | build/kernel/devices/dev_nic.o \ |
---|
74 | build/kernel/devices/dev_pic.o \ |
---|
75 | build/kernel/devices/dev_dma.o \ |
---|
76 | build/kernel/devices/dev_fbf.o \ |
---|
77 | build/kernel/devices/dev_iob.o |
---|
78 | |
---|
79 | MM_OBJS = build/kernel/mm/ppm.o \ |
---|
80 | build/kernel/mm/vmm.o \ |
---|
81 | build/kernel/mm/vseg.o \ |
---|
82 | build/kernel/mm/page.o \ |
---|
83 | build/kernel/mm/kcm.o \ |
---|
84 | build/kernel/mm/khm.o \ |
---|
85 | build/kernel/mm/mapper.o \ |
---|
86 | build/kernel/mm/kmem.o |
---|
87 | |
---|
88 | LIBK_OBJS = build/kernel/libk/grdxt.o \ |
---|
89 | build/kernel/libk/bits.o \ |
---|
90 | build/kernel/libk/elf.o \ |
---|
91 | build/kernel/libk/string.o \ |
---|
92 | build/kernel/libk/ctype.o \ |
---|
93 | build/kernel/libk/rwlock.o \ |
---|
94 | build/kernel/libk/spinlock.o \ |
---|
95 | build/kernel/libk/barrier.o \ |
---|
96 | build/kernel/libk/remote_barrier.o \ |
---|
97 | build/kernel/libk/remote_spinlock.o \ |
---|
98 | build/kernel/libk/remote_rwlock.o \ |
---|
99 | build/kernel/libk/remote_fifo.o \ |
---|
100 | build/kernel/libk/remote_mutex.o \ |
---|
101 | build/kernel/libk/remote_sem.o \ |
---|
102 | build/kernel/libk/remote_condvar.o \ |
---|
103 | build/kernel/libk/memcpy.o \ |
---|
104 | build/kernel/libk/htab.o \ |
---|
105 | build/kernel/libk/xhtab.o |
---|
106 | |
---|
107 | SYS_OBJS_0 = build/kernel/syscalls/sys_thread_exit.o \ |
---|
108 | build/kernel/syscalls/sys_mmap.o \ |
---|
109 | build/kernel/syscalls/sys_thread_create.o \ |
---|
110 | build/kernel/syscalls/sys_thread_join.o \ |
---|
111 | build/kernel/syscalls/sys_thread_detach.o \ |
---|
112 | build/kernel/syscalls/sys_thread_yield.o \ |
---|
113 | build/kernel/syscalls/sys_sem.o \ |
---|
114 | build/kernel/syscalls/sys_condvar.o \ |
---|
115 | build/kernel/syscalls/sys_barrier.o \ |
---|
116 | build/kernel/syscalls/sys_mutex.o |
---|
117 | |
---|
118 | SYS_OBJS_1 = build/kernel/syscalls/sys_thread_sleep.o \ |
---|
119 | build/kernel/syscalls/sys_thread_wakeup.o \ |
---|
120 | build/kernel/syscalls/sys_open.o \ |
---|
121 | build/kernel/syscalls/sys_creat.o \ |
---|
122 | build/kernel/syscalls/sys_read.o \ |
---|
123 | build/kernel/syscalls/sys_write.o \ |
---|
124 | build/kernel/syscalls/sys_lseek.o \ |
---|
125 | build/kernel/syscalls/sys_close.o \ |
---|
126 | build/kernel/syscalls/sys_unlink.o \ |
---|
127 | build/kernel/syscalls/sys_pipe.o |
---|
128 | |
---|
129 | SYS_OBJS_2 = build/kernel/syscalls/sys_chdir.o \ |
---|
130 | build/kernel/syscalls/sys_mkdir.o \ |
---|
131 | build/kernel/syscalls/sys_mkfifo.o \ |
---|
132 | build/kernel/syscalls/sys_opendir.o \ |
---|
133 | build/kernel/syscalls/sys_readdir.o \ |
---|
134 | build/kernel/syscalls/sys_closedir.o \ |
---|
135 | build/kernel/syscalls/sys_getcwd.o \ |
---|
136 | build/kernel/syscalls/sys_clock.o \ |
---|
137 | build/kernel/syscalls/sys_alarm.o \ |
---|
138 | build/kernel/syscalls/sys_rmdir.o |
---|
139 | |
---|
140 | SYS_OBJS_3 = build/kernel/syscalls/sys_utls.o \ |
---|
141 | build/kernel/syscalls/sys_chmod.o \ |
---|
142 | build/kernel/syscalls/sys_signal.o \ |
---|
143 | build/kernel/syscalls/sys_timeofday.o \ |
---|
144 | build/kernel/syscalls/sys_kill.o \ |
---|
145 | build/kernel/syscalls/sys_getpid.o \ |
---|
146 | build/kernel/syscalls/sys_fork.o \ |
---|
147 | build/kernel/syscalls/sys_exec.o \ |
---|
148 | build/kernel/syscalls/sys_stat.o \ |
---|
149 | build/kernel/syscalls/sys_trace.o |
---|
150 | |
---|
151 | VFS_OBJS = build/kernel/vfs/vfs.o \ |
---|
152 | build/kernel/vfs/fatfs.o \ |
---|
153 | build/kernel/vfs/devfs.o \ |
---|
154 | build/kernel/vfs/ramfs.o |
---|
155 | |
---|
156 | # List of directories to be searched for included files |
---|
157 | # when compiling for kernel.elf generation |
---|
158 | KERNEL_INCLUDE = -Ikernel \ |
---|
159 | -Ikernel/kern \ |
---|
160 | -Ikernel/devices \ |
---|
161 | -Ikernel/syscalls \ |
---|
162 | -Ihal/x86_64/drivers \ |
---|
163 | -Ikernel/syscalls \ |
---|
164 | -Ikernel/libk \ |
---|
165 | -Ikernel/mm \ |
---|
166 | -Ikernel/vfs \ |
---|
167 | -Ikernel/fatfs \ |
---|
168 | -Ikernel/sysfs \ |
---|
169 | -Ikernel/ramfs \ |
---|
170 | -Ikernel/devfs \ |
---|
171 | -Itools/arch_info \ |
---|
172 | -Ihal/generic \ |
---|
173 | -Ihal/x86_64/core \ |
---|
174 | -I. |
---|
175 | |
---|
176 | # Macros to be processed by the C preprocessor. |
---|
177 | MACROS = -DARCHINFO_PATHNAME="\"arch_info.bin\"" \ |
---|
178 | -DKERNEL_PATHNAME="\"/bin/kernel/kernel.elf\"" |
---|
179 | |
---|
180 | # Virtual disk path |
---|
181 | DISK_IMAGE := hdd/virt_hdd.dmg |
---|
182 | |
---|
183 | # The Mtools used to build the FAT32 disk image perfom a few sanity checks, to |
---|
184 | # make sure that the disk is indeed an MS-DOS disk. However, the size of the |
---|
185 | # disk image used by ALMOS-VM is not MS-DOS compliant. |
---|
186 | # Setting this variable prevents these checks. |
---|
187 | MTOOLS_SKIP_CHECK := 1 |
---|
188 | |
---|
189 | # Rule to compile kernel.elf, and update virtual disk. |
---|
190 | compile: dirs \ |
---|
191 | hard_config.h \ |
---|
192 | build/kernel/kernel.elf \ |
---|
193 | list |
---|
194 | |
---|
195 | # Rule to create the build directories. |
---|
196 | dirs: |
---|
197 | @mkdir -p build/kernel |
---|
198 | @mkdir -p build/kernel/kern |
---|
199 | @mkdir -p build/kernel/hal |
---|
200 | @mkdir -p build/kernel/devices |
---|
201 | @mkdir -p build/kernel/mm |
---|
202 | @mkdir -p build/kernel/libk |
---|
203 | @mkdir -p build/kernel/drivers |
---|
204 | @mkdir -p build/kernel/vfs |
---|
205 | @mkdir -p build/kernel/syscalls |
---|
206 | @mkdir -p hdd |
---|
207 | |
---|
208 | # Rule to make a recursive list of the virtual disk content. |
---|
209 | list: |
---|
210 | mdir -/ -b -i $(DISK_IMAGE) ::/ |
---|
211 | |
---|
212 | # Rule to make a file system check for the virtual disk. |
---|
213 | fsck: |
---|
214 | fsck.msdos $(DISK_IMAGE) |
---|
215 | |
---|
216 | ############################################################## |
---|
217 | # Rule to copy the files generated by the virtual prototype |
---|
218 | # from the virtual disk 'home' directory to the current directory. |
---|
219 | extract: |
---|
220 | mcopy -o -i $(DISK_IMAGE) ::/home . |
---|
221 | |
---|
222 | # Rules to delete all binary files from Unix File System |
---|
223 | # without modifying the virtual disk. |
---|
224 | clean: |
---|
225 | rm -f *.o *.elf *.bin *.txt core |
---|
226 | rm -f hard_config.h |
---|
227 | rm -rf build |
---|
228 | |
---|
229 | #################################################### |
---|
230 | # Rule for building a new virtual disk from scratch. |
---|
231 | # It creates the bin / home directories. |
---|
232 | # This requires the generic Linux/MacOS 'create_dmg' script, that should be |
---|
233 | # placed in the same directory as this Makefile. |
---|
234 | build-disk: |
---|
235 | rm -f $(DISK_IMAGE) |
---|
236 | ./create_dmg create $(basename $(DISK_IMAGE)) |
---|
237 | dd if=$(DISK_IMAGE) of=temp.dmg count=65536 |
---|
238 | mv temp.dmg $(DISK_IMAGE) |
---|
239 | mmd -o -i $(DISK_IMAGE) ::/bin || true |
---|
240 | mmd -o -i $(DISK_IMAGE) ::/bin/kernel || true |
---|
241 | mmd -o -i $(DISK_IMAGE) ::/bin/init || true |
---|
242 | mmd -o -i $(DISK_IMAGE) ::/home || true |
---|
243 | mdir -/ -b -i $(DISK_IMAGE) ::/ |
---|
244 | |
---|
245 | ############################################################## |
---|
246 | # Rules to generate hardware description files (hard_config.h, |
---|
247 | # arch_info.bin and arch_info.xml), and update the virtual disk. |
---|
248 | hard_config.h: |
---|
249 | echo "!!! UNUSED !!!" # XXX: cleanup later |
---|
250 | |
---|
251 | |
---|
252 | ############################## |
---|
253 | # rules to compile the drivers |
---|
254 | build/kernel/drivers/%.o: hal/x86_64/drivers/%.c \ |
---|
255 | hal/x86_64/drivers/%.h \ |
---|
256 | kernel_config.h \ |
---|
257 | hal/x86_64/core/hal_types.h |
---|
258 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
259 | |
---|
260 | ####################################### |
---|
261 | # Rules to generate kernel/kern objects |
---|
262 | build/kernel/kern/%.o: kernel/kern/%.c \ |
---|
263 | kernel/kern/%.h \ |
---|
264 | kernel_config.h \ |
---|
265 | hal/x86_64/core/hal_types.h |
---|
266 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
267 | |
---|
268 | ###################################### |
---|
269 | # Rules to generate kernel/hal objects |
---|
270 | build/kernel/hal/%.o: hal/x86_64/core/%.c \ |
---|
271 | hal/generic/%.h \ |
---|
272 | kernel_config.h \ |
---|
273 | hal/x86_64/core/hal_types.h |
---|
274 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
275 | |
---|
276 | build/kernel/hal/hal_boot.o: hal/x86_64/core/hal_boot.S \ |
---|
277 | hal/x86_64/core/hal_boot.h \ |
---|
278 | hal/x86_64/core/hal_multiboot.h \ |
---|
279 | hal/x86_64/core/hal_segmentation.h \ |
---|
280 | kernel_config.h \ |
---|
281 | hal/x86_64/core/hal_types.h |
---|
282 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
283 | |
---|
284 | build/kernel/hal/hal_smpboot.o: hal/x86_64/core/hal_smpboot.S \ |
---|
285 | hal/x86_64/core/hal_boot.h \ |
---|
286 | hal/x86_64/core/hal_multiboot.h \ |
---|
287 | hal/x86_64/core/hal_segmentation.h \ |
---|
288 | kernel_config.h \ |
---|
289 | hal/x86_64/core/hal_types.h |
---|
290 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
291 | |
---|
292 | build/kernel/hal/hal_init.o: hal/x86_64/core/hal_init.c \ |
---|
293 | hal/x86_64/core/hal_boot.h \ |
---|
294 | hal/x86_64/core/hal_multiboot.h \ |
---|
295 | hal/x86_64/core/hal_segmentation.h \ |
---|
296 | hal/x86_64/core/hal_acpi.h \ |
---|
297 | hal/x86_64/core/hal_apic.h \ |
---|
298 | hal/x86_64/core/hal_internal.h \ |
---|
299 | kernel_config.h \ |
---|
300 | hal/x86_64/core/hal_types.h |
---|
301 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
302 | |
---|
303 | build/kernel/hal/hal_cpu.o: hal/x86_64/core/hal_cpu.S \ |
---|
304 | hal/x86_64/core/hal_boot.h \ |
---|
305 | hal/x86_64/core/hal_segmentation.h \ |
---|
306 | kernel_config.h \ |
---|
307 | hal/x86_64/core/hal_types.h |
---|
308 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
309 | |
---|
310 | build/kernel/hal/hal_kentry.o: hal/x86_64/core/hal_kentry.S \ |
---|
311 | hal/x86_64/core/hal_kentry.h \ |
---|
312 | hal/x86_64/core/hal_boot.h \ |
---|
313 | kernel_config.h \ |
---|
314 | hal/x86_64/core/hal_types.h |
---|
315 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
316 | |
---|
317 | build/kernel/hal/hal_acpi.o: hal/x86_64/core/hal_acpi.c \ |
---|
318 | hal/x86_64/core/hal_acpi.h \ |
---|
319 | kernel_config.h \ |
---|
320 | hal/x86_64/core/hal_types.h |
---|
321 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
322 | |
---|
323 | build/kernel/hal/hal_apic.o: hal/x86_64/core/hal_apic.c \ |
---|
324 | hal/x86_64/core/hal_apic.h \ |
---|
325 | kernel_config.h \ |
---|
326 | hal/x86_64/core/hal_types.h |
---|
327 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
328 | |
---|
329 | build/kernel/hal/x86_printf.o: hal/x86_64/core/x86_printf.c \ |
---|
330 | kernel_config.h \ |
---|
331 | hal/x86_64/core/hal_types.h |
---|
332 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
333 | |
---|
334 | ###################################### |
---|
335 | # Rules to generate kernel/dev objects |
---|
336 | build/kernel/devices/%.o: kernel/devices/%.c \ |
---|
337 | kernel/devices/%.h \ |
---|
338 | kernel_config.h \ |
---|
339 | hal/x86_64/core/hal_types.h |
---|
340 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
341 | |
---|
342 | ##################################### |
---|
343 | # Rules to generate kernel/mm objects |
---|
344 | build/kernel/mm/%.o: kernel/mm/%.c \ |
---|
345 | kernel/mm/%.h \ |
---|
346 | kernel_config.h \ |
---|
347 | hal/x86_64/core/hal_types.h |
---|
348 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
349 | |
---|
350 | ####################################### |
---|
351 | # Rules to generate kernel/libk objects |
---|
352 | build/kernel/libk/%.o: kernel/libk/%.c \ |
---|
353 | kernel/libk/%.h \ |
---|
354 | kernel_config.h \ |
---|
355 | hal/x86_64/core/hal_types.h |
---|
356 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
357 | |
---|
358 | ########################################### |
---|
359 | # Rules to generate kernel/syscalls objects |
---|
360 | build/kernel/syscalls/%.o: kernel/syscalls/%.c \ |
---|
361 | kernel/syscalls/syscalls.h \ |
---|
362 | kernel_config.h \ |
---|
363 | hal/x86_64/core/hal_types.h |
---|
364 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
365 | |
---|
366 | ####################################### |
---|
367 | # Rules to generate kernel/vfs objects |
---|
368 | build/kernel/vfs/%.o: kernel/vfs/%.c \ |
---|
369 | kernel/vfs/%.h \ |
---|
370 | kernel_config.h \ |
---|
371 | hal/x86_64/core/hal_types.h |
---|
372 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
373 | |
---|
374 | ########################################################### |
---|
375 | # Rule to generate kernel.elf and place it on virtual disk |
---|
376 | build/kernel/kernel.elf: $(KERN_OBJS) \ |
---|
377 | $(HAL_OBJS) \ |
---|
378 | $(DEV_OBJS) \ |
---|
379 | $(MM_OBJS) \ |
---|
380 | $(LIBK_OBJS) \ |
---|
381 | $(DRIVERS_OBJS) \ |
---|
382 | $(VFS_OBJS) \ |
---|
383 | $(SYS_OBJS_0) \ |
---|
384 | $(SYS_OBJS_1) \ |
---|
385 | $(SYS_OBJS_2) \ |
---|
386 | $(SYS_OBJS_3) \ |
---|
387 | hal/x86_64/kernel.ld |
---|
388 | $(LD) -o $@ -z max-page-size=0x1000 -T hal/x86_64/kernel.ld \ |
---|
389 | $(KERN_OBJS) $(HAL_OBJS) $(DEV_OBJS) $(MM_OBJS) \ |
---|
390 | $(LIBK_OBJS) $(DRIVERS_OBJS) $(VFS_OBJS) \ |
---|
391 | $(SYS_OBJS_0) $(SYS_OBJS_1) $(SYS_OBJS_2) \ |
---|
392 | $(SYS_OBJS_3) |
---|
393 | |
---|
394 | $(DU) -D $@ > $@.txt |
---|
395 | mcopy -o -i $(DISK_IMAGE) build/kernel/kernel.elf ::/bin/kernel |
---|
396 | |
---|