source: trunk/Makefile.x86 @ 367

Last change on this file since 367 was 364, checked in by max@…, 7 years ago

Don't include params.mk.

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