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