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