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