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