source: trunk/Makefile @ 344

Last change on this file since 344 was 317, checked in by alain, 7 years ago

1) Introduce the TSAR hal_cpu_context_switch() function.
2) Introduce the generic vfs_kernel_move() function.

File size: 20.4 KB
Line 
1#############################################################################
2#                       ALMOS-MKH  Makefile for TSAR                        #
3#############################################################################
4
5-include params.mk
6
7# Compilation flags.
8CFLAGS = -Wall -ffreestanding -mno-gpopt -mips32 -g -O2 \
9                 -fno-delete-null-pointer-checks
10#                -fno-delete-null-pointer-checks -std=c99
11
12export
13CC = mipsel-unknown-elf-gcc
14AS = mipsel-unknown-elf-as
15LD = mipsel-unknown-elf-ld
16DU = mipsel-unknown-elf-objdump
17AR = mipsel-unknown-elf-ar
18
19LIBGCC = -L$(shell $(CC) -print-libgcc-file-name | sed 's/libgcc.a//')
20# Default values for hardware parameters.
21# These parameters should be defined in the 'params.mk' file.
22ARCH            ?= /users/alain/soc/tsar-trunk-svn-2013/platforms/tsar_generic_iob
23X_SIZE          ?= 2
24Y_SIZE          ?= 2
25NB_PROCS        ?= 2
26NB_TTYS         ?= 3
27FBF_WIDTH       ?= 256
28IOC_TYPE        ?= IOC_BDV
29
30
31# Checking hardware platform definition.
32ifeq ($(wildcard $(ARCH)),)
33$(error Please define in ARCH parameter the path to the hardware platform!)
34endif
35
36# Rules that don't build target files
37# always out-of-date, need to be regenerated everytime they are called
38.PHONY: compile                         \
39                dirs                                \
40                list                                \
41                extract                             \
42                fsck                                \
43                clean                               \
44                build-disk                          \
45                build/boot/boot.elf         \
46                build/kernel/kernel.elf
47
48# Objects to be linked for boot.elf generation
49BOOT_OBJS       = build/boot/boot.o            \
50                          build/boot/boot_fat32.o      \
51                          build/boot/boot_utils.o      \
52                          build/boot/boot_entry.o      \
53              build/boot/boot_tty_driver.o \
54              build/boot/boot_hba_driver.o \
55                          build/boot/boot_bdv_driver.o \
56                          build/boot/boot_mmc_driver.o 
57
58# List of directories to be searched for included files
59# when compiling for boot.elf generation
60BOOT_INCLUDE = -Itools/bootloader_tsar  \
61                       -Itools/arch_info        \
62               -Ihal/tsar_mips32/core   \
63               -I.
64
65# Objects to be linked for the soclib drivers library
66DRIVERS_OBJS = build/kernel/drivers/soclib_tty.o  \
67               build/kernel/drivers/soclib_bdv.o  \
68               build/kernel/drivers/soclib_hba.o  \
69               build/kernel/drivers/soclib_mmc.o  \
70               build/kernel/drivers/soclib_pic.o  \
71               build/kernel/drivers/soclib_nic.o  \
72               build/kernel/drivers/soclib_dma.o  \
73               build/kernel/drivers/soclib_iob.o
74
75# Objects to be linked for kernel.elf generation
76KERN_OBJS       = build/kernel/kern/kernel_init.o     \
77              build/kernel/kern/printk.o          \
78              build/kernel/kern/thread.o          \
79              build/kernel/kern/process.o         \
80              build/kernel/kern/chdev.o           \
81              build/kernel/kern/cluster.o         \
82              build/kernel/kern/scheduler.o       \
83              build/kernel/kern/core.o            \
84              build/kernel/kern/dqdt.o            \
85              build/kernel/kern/do_syscall.o      \
86              build/kernel/kern/do_interrupt.o    \
87              build/kernel/kern/do_exception.o    \
88              build/kernel/kern/rpc.o             \
89              build/kernel/kern/signal.o
90
91HAL_OBJS    = build/kernel/hal/hal_special.o      \
92              build/kernel/hal/hal_context.o      \
93              build/kernel/hal/hal_atomic.o       \
94              build/kernel/hal/hal_remote.o       \
95              build/kernel/hal/hal_uspace.o       \
96              build/kernel/hal/hal_irqmask.o      \
97              build/kernel/hal/hal_gpt.o          \
98              build/kernel/hal/hal_ppm.o          \
99              build/kernel/hal/hal_exception.o    \
100              build/kernel/hal/hal_interrupt.o    \
101              build/kernel/hal/hal_syscall.o      \
102              build/kernel/hal/hal_drivers.o      \
103              build/kernel/hal/hal_kentry.o       \
104              build/kernel/hal/hal_switch.o
105
106DEV_OBJS    = build/kernel/devices/dev_txt.o      \
107              build/kernel/devices/dev_ioc.o      \
108              build/kernel/devices/dev_mmc.o      \
109              build/kernel/devices/dev_nic.o      \
110              build/kernel/devices/dev_pic.o      \
111              build/kernel/devices/dev_dma.o      \
112              build/kernel/devices/dev_fbf.o      \
113              build/kernel/devices/dev_iob.o
114
115MM_OBJS     = build/kernel/mm/ppm.o               \
116              build/kernel/mm/vmm.o               \
117              build/kernel/mm/vseg.o              \
118              build/kernel/mm/page.o              \
119              build/kernel/mm/kcm.o               \
120              build/kernel/mm/khm.o               \
121              build/kernel/mm/mapper.o            \
122              build/kernel/mm/kmem.o
123
124LIBK_OBJS   = build/kernel/libk/grdxt.o           \
125              build/kernel/libk/bits.o            \
126              build/kernel/libk/elf.o             \
127              build/kernel/libk/string.o          \
128              build/kernel/libk/ctype.o           \
129              build/kernel/libk/rwlock.o          \
130              build/kernel/libk/spinlock.o        \
131              build/kernel/libk/barrier.o         \
132              build/kernel/libk/remote_barrier.o  \
133              build/kernel/libk/remote_spinlock.o \
134              build/kernel/libk/remote_rwlock.o   \
135              build/kernel/libk/remote_fifo.o     \
136              build/kernel/libk/remote_mutex.o    \
137              build/kernel/libk/remote_sem.o      \
138              build/kernel/libk/remote_condvar.o  \
139              build/kernel/libk/memcpy.o          \
140              build/kernel/libk/htab.o            \
141              build/kernel/libk/xhtab.o
142
143SYS_OBJS_0  = build/kernel/syscalls/sys_thread_exit.o     \
144              build/kernel/syscalls/sys_mmap.o            \
145              build/kernel/syscalls/sys_thread_create.o   \
146              build/kernel/syscalls/sys_thread_join.o     \
147              build/kernel/syscalls/sys_thread_detach.o   \
148              build/kernel/syscalls/sys_thread_yield.o    \
149              build/kernel/syscalls/sys_sem.o             \
150              build/kernel/syscalls/sys_condvar.o         \
151              build/kernel/syscalls/sys_barrier.o         \
152              build/kernel/syscalls/sys_mutex.o
153
154SYS_OBJS_1  = build/kernel/syscalls/sys_thread_sleep.o    \
155              build/kernel/syscalls/sys_thread_wakeup.o   \
156              build/kernel/syscalls/sys_open.o            \
157              build/kernel/syscalls/sys_creat.o           \
158              build/kernel/syscalls/sys_read.o            \
159              build/kernel/syscalls/sys_write.o           \
160              build/kernel/syscalls/sys_lseek.o           \
161              build/kernel/syscalls/sys_close.o           \
162              build/kernel/syscalls/sys_unlink.o          \
163              build/kernel/syscalls/sys_pipe.o
164
165SYS_OBJS_2  = build/kernel/syscalls/sys_chdir.o           \
166              build/kernel/syscalls/sys_mkdir.o           \
167              build/kernel/syscalls/sys_mkfifo.o          \
168              build/kernel/syscalls/sys_opendir.o         \
169              build/kernel/syscalls/sys_readdir.o         \
170              build/kernel/syscalls/sys_closedir.o        \
171              build/kernel/syscalls/sys_getcwd.o          \
172              build/kernel/syscalls/sys_clock.o           \
173              build/kernel/syscalls/sys_alarm.o           \
174              build/kernel/syscalls/sys_rmdir.o
175
176SYS_OBJS_3  = build/kernel/syscalls/sys_utls.o            \
177              build/kernel/syscalls/sys_chmod.o           \
178              build/kernel/syscalls/sys_signal.o          \
179              build/kernel/syscalls/sys_timeofday.o       \
180              build/kernel/syscalls/sys_kill.o            \
181              build/kernel/syscalls/sys_getpid.o          \
182              build/kernel/syscalls/sys_fork.o            \
183              build/kernel/syscalls/sys_exec.o            \
184              build/kernel/syscalls/sys_stat.o            \
185              build/kernel/syscalls/sys_trace.o
186
187VFS_OBJS    = build/kernel/vfs/vfs.o              \
188              build/kernel/vfs/fatfs.o            \
189              build/kernel/vfs/devfs.o            \
190              build/kernel/vfs/ramfs.o
191
192# List of directories to be searched for included files
193# when compiling for kernel.elf generation
194KERNEL_INCLUDE = -Ikernel                \
195                 -Ikernel/kern           \
196                 -Ikernel/devices        \
197                 -Ikernel/syscalls       \
198                 -Ihal/tsar_mips32/drivers \
199                 -Ikernel/syscalls       \
200                 -Ikernel/libk           \
201                 -Ikernel/mm             \
202                 -Ikernel/vfs            \
203                 -Ikernel/fatfs          \
204                 -Ikernel/sysfs          \
205                 -Ikernel/ramfs          \
206                 -Ikernel/devfs          \
207                 -Itools/arch_info       \
208                 -Ihal/generic           \
209                 -Ihal/tsar_mips32/core  \
210                 -I.
211
212# Macros to be processed by the C preprocessor.
213MACROS           = -DARCHINFO_PATHNAME="\"arch_info.bin\""              \
214                           -DKERNEL_PATHNAME="\"/bin/kernel/kernel.elf\""
215
216# Virtual disk path
217DISK_IMAGE      := hdd/virt_hdd.dmg
218
219# The Mtools used to build the FAT32 disk image perfom a few sanity checks, to
220# make sure that the disk is indeed an MS-DOS disk. However, the size of the
221# disk image used by ALMOS-VM is not MS-DOS compliant.
222# Setting this variable prevents these checks.
223MTOOLS_SKIP_CHECK := 1
224
225# Rule to generate compile boot.elf, kernel.elf, init.elf and update virtual disk.
226compile: dirs                     \
227         build_disk               \
228         hard_config.h            \
229                 build/boot/boot.elf      \
230         build/kernel/kernel.elf  \
231         build/user/init/init.elf \
232         list
233
234# Rule to create the build directories.
235dirs:
236        @mkdir -p build/boot
237        @mkdir -p build/kernel
238        @mkdir -p build/kernel/kern
239        @mkdir -p build/kernel/hal
240        @mkdir -p build/kernel/devices
241        @mkdir -p build/kernel/mm
242        @mkdir -p build/kernel/libk
243        @mkdir -p build/kernel/drivers
244        @mkdir -p build/kernel/vfs
245        @mkdir -p build/kernel/syscalls
246        @mkdir -p build/user
247        @mkdir -p build/user/init
248        @mkdir -p build/user/ksh
249        @mkdir -p hdd
250
251# Rule to make a recursive list of the virtual disk content.
252list:
253        mdir -/ -b -i $(DISK_IMAGE) ::/
254
255##############################################################
256# Rule to copy the files generated by the virtual prototype
257# from the virtual disk 'home' directory to the current directory.
258extract:
259        mcopy -o -i $(DISK_IMAGE) ::/home .
260
261# Rules to delete all binary files from Unix File System
262# without modifying the virtual disk.
263clean:
264        rm -f *.o *.elf *.bin *.txt core
265        rm -f hard_config.h arch_info.xml arch_info.bin
266        rm -rf build
267        cd user/init   &&  $(MAKE) clean  &&  cd ../..
268
269####################################################   
270# Rule for building a new virtual disk from scratch.
271# It creates the bin, bin/kernel, bin/init, and home directories.
272# This requires the generic Linux/MacOS 'create_dmg' script, that should be
273# placed in the same directory as this Makefile.
274build_disk:
275        rm -f $(DISK_IMAGE)
276        ./create_dmg    create $(basename $(DISK_IMAGE))
277        dd                              if=$(DISK_IMAGE) of=temp.dmg count=65536
278        mv                              temp.dmg $(DISK_IMAGE)
279        mmd                     -o -i $(DISK_IMAGE) ::/bin         || true
280        mmd                     -o -i $(DISK_IMAGE) ::/bin/kernel  || true
281        mmd                     -o -i $(DISK_IMAGE) ::/bin/init    || true
282        mmd                     -o -i $(DISK_IMAGE) ::/home        || true
283        mdir             -/ -b -i $(DISK_IMAGE) ::/
284       
285##############################################################
286# Rules to generate hardware description files (hard_config.h,
287# arch_info.bin and arch_info.xml), and update the virtual disk.
288hard_config.h: $(ARCH)/arch_info.py
289        tools/arch_info/genarch.py      --arch=$(ARCH)                  \
290                                                                --x_size=$(X_SIZE)              \
291                                                                --y_size=$(Y_SIZE)              \
292                                                                --nb_cores=$(NB_PROCS)  \
293                                                                --nb_ttys=$(NB_TTYS)    \
294                                                                --fbf_size=$(FBF_WIDTH) \
295                                                                --ioc_type=$(IOC_TYPE)  \
296                                                                --hard=.                                \
297                                                                --bin=.                                 \
298                                                                --xml=.                                 
299        mcopy -o -i $(DISK_IMAGE) arch_info.bin ::/   || true
300        mdir             -/ -b -i $(DISK_IMAGE) ::/
301
302################################################
303# Rules to compile boot drivers used by boot.elf
304build/boot/boot_tty_driver.o:   tools/bootloader_tsar/boot_tty_driver.c \
305                                                                tools/bootloader_tsar/boot_tty_driver.h \
306                                                                tools/bootloader_tsar/boot_utils.h      \
307                                                                tools/bootloader_tsar/boot_config.h     \
308                                                                hal/tsar_mips32/core/hal_types.h        \
309                                                                hard_config.h
310        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
311        $(DU) -D $@ > $@.txt
312
313build/boot/boot_bdv_driver.o:   tools/bootloader_tsar/boot_bdv_driver.c \
314                                                                tools/bootloader_tsar/boot_bdv_driver.h \
315                                                                tools/bootloader_tsar/boot_utils.h      \
316                                                                tools/bootloader_tsar/boot_config.h     \
317                                                                hal/tsar_mips32/core/hal_types.h        \
318                                                                hard_config.h
319        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
320        $(DU) -D $@ > $@.txt
321
322build/boot/boot_hba_driver.o:   tools/bootloader_tsar/boot_hba_driver.c \
323                                                                tools/bootloader_tsar/boot_hba_driver.h \
324                                                                tools/bootloader_tsar/boot_utils.h      \
325                                                                tools/bootloader_tsar/boot_config.h     \
326                                                                hal/tsar_mips32/core/hal_types.h        \
327                                                                hard_config.h
328        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
329        $(DU) -D $@ > $@.txt
330
331build/boot/boot_mmc_driver.o:   tools/bootloader_tsar/boot_mmc_driver.c \
332                                                                tools/bootloader_tsar/boot_mmc_driver.h \
333                                                                tools/bootloader_tsar/boot_utils.h      \
334                                                                tools/bootloader_tsar/boot_config.h     \
335                                                                hal/tsar_mips32/core/hal_types.h        \
336                                                                hard_config.h
337        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
338        $(DU) -D $@ > $@.txt
339
340##############################
341# Rule to compile boot_fat32.o
342build/boot/boot_fat32.o:                tools/bootloader_tsar/boot_fat32.c      \
343                                                                tools/bootloader_tsar/boot_fat32.h      \
344                                                                tools/bootloader_tsar/boot_utils.h      \
345                                                                tools/bootloader_tsar/boot_config.h     \
346                                                                hal/tsar_mips32/core/hal_types.h        \
347                                                                hard_config.h                   
348        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
349        $(DU) -D $@ > $@.txt
350
351##############################
352# Rule to compile boot_utils.o
353build/boot/boot_utils.o:                tools/bootloader_tsar/boot_utils.c       \
354                                                                tools/bootloader_tsar/boot_utils.h       \
355                                                                tools/bootloader_tsar/boot_tty_driver.h  \
356                                                                hal/tsar_mips32/core/hal_types.h         \
357                                                                hard_config.h
358        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
359        $(DU) -D $@ > $@.txt
360
361########################
362# Rule to compile boot.o
363build/boot/boot.o:                              tools/bootloader_tsar/boot.c             \
364                                                                tools/bootloader_tsar/boot_utils.h       \
365                                                                tools/bootloader_tsar/boot_fat32.h       \
366                                                                tools/bootloader_tsar/boot_tty_driver.h  \
367                                                                tools/bootloader_tsar/boot_hba_driver.h  \
368                                                                tools/bootloader_tsar/boot_bdv_driver.h  \
369                                                                tools/bootloader_tsar/boot_mmc_driver.h  \
370                                                                tools/bootloader_tsar/boot_config.h      \
371                                                                hal/tsar_mips32/core/hal_types.h         \
372                                                                hard_config.h                           
373        $(CC) $(BOOT_INCLUDE) $(CFLAGS) $(MACROS) -c -o $@ $<
374        $(DU) -D $@ > $@.txt
375
376##############################
377# Rule to compile boot_entry.o
378build/boot/boot_entry.o:                tools/bootloader_tsar/boot_entry.S   \
379                                                                tools/bootloader_tsar/boot_config.h  \
380                                                                hard_config.h
381        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
382        $(DU) -D $@ > $@.txt
383
384#####################################################################
385# Rule to generate boot.elf and place it in sector #2 of virtual disk
386build/boot/boot.elf:                            $(BOOT_OBJS) \
387                                                                        tools/bootloader_tsar/boot.ld                                   
388        $(LD) -o $@ -T tools/bootloader_tsar/boot.ld $(BOOT_OBJS)
389        $(DU) -D $@ > $@.txt
390        dd if=build/boot/boot.elf of=$(DISK_IMAGE) seek=2 conv=notrunc
391
392
393##############################
394# rules to compile the drivers
395build/kernel/drivers/%.o:       hal/tsar_mips32/drivers/%.c \
396                                hal/tsar_mips32/drivers/%.h \
397                                kernel_config.h             \
398                                hal/tsar_mips32/core/hal_types.h
399        $(CC) $(KERNEL_INCLUDE) $(CFLAGS)  -c -o $@ $<
400        $(DU) -D $@ > $@.txt
401
402#######################################
403# Rules to generate kernel/kern objects
404build/kernel/kern/%.o:              kernel/kern/%.c             \
405                                kernel/kern/%.h             \
406                                kernel_config.h             \
407                                hal/tsar_mips32/core/hal_types.h
408        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
409        $(DU) -D $@ > $@.txt
410
411######################################
412# Rules to generate kernel/hal objects
413build/kernel/hal/%.o:           hal/tsar_mips32/core/%.c    \
414                                hal/generic/%.h             \
415                                kernel_config.h             \
416                                hal/tsar_mips32/core/hal_types.h
417        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
418        $(DU) -D $@ > $@.txt
419
420build/kernel/hal/hal_kentry.o:  hal/tsar_mips32/core/hal_kentry.S \
421                                hal/tsar_mips32/core/hal_kentry.h \
422                                kernel_config.h                   \
423                                hal/tsar_mips32/core/hal_types.h
424        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
425        $(DU) -D $@ > $@.txt
426
427build/kernel/hal/hal_switch.o:  hal/tsar_mips32/core/hal_switch.S \
428                                hal/tsar_mips32/core/hal_switch.h
429        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
430        $(DU) -D $@ > $@.txt
431
432######################################
433# Rules to generate kernel/dev objects
434build/kernel/devices/%.o:       kernel/devices/%.c          \
435                                kernel/devices/%.h          \
436                                kernel_config.h             \
437                                hal/tsar_mips32/core/hal_types.h
438        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
439        $(DU) -D $@ > $@.txt
440
441#####################################
442# Rules to generate kernel/mm objects
443build/kernel/mm/%.o:            kernel/mm/%.c               \
444                                kernel/mm/%.h               \
445                                kernel_config.h             \
446                                hal/tsar_mips32/core/hal_types.h
447        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
448        $(DU) -D $@ > $@.txt
449
450#######################################
451# Rules to generate kernel/libk objects
452build/kernel/libk/%.o:          kernel/libk/%.c             \
453                                kernel/libk/%.h             \
454                                kernel_config.h             \
455                                hal/tsar_mips32/core/hal_types.h
456        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
457        $(DU) -D $@ > $@.txt
458
459###########################################
460# Rules to generate kernel/syscalls objects
461build/kernel/syscalls/%.o:      kernel/syscalls/%.c         \
462                                kernel/syscalls/syscalls.h  \
463                                kernel_config.h             \
464                                hal/tsar_mips32/core/hal_types.h
465        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
466        $(DU) -D $@ > $@.txt
467
468#######################################
469# Rules to generate kernel/vfs objects
470build/kernel/vfs/%.o:           kernel/vfs/%.c              \
471                                kernel/vfs/%.h              \
472                                kernel_config.h             \
473                                hal/tsar_mips32/core/hal_types.h
474        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
475        $(DU) -D $@ > $@.txt
476
477###########################################################
478# Rule to generate kernel.elf and place it on virtual disk
479build/kernel/kernel.elf:            $(KERN_OBJS)                \
480                                $(HAL_OBJS)                 \
481                                $(DEV_OBJS)                 \
482                                $(MM_OBJS)                  \
483                                $(LIBK_OBJS)                \
484                                $(DRIVERS_OBJS)             \
485                                $(VFS_OBJS)                 \
486                                $(SYS_OBJS_0)               \
487                                $(SYS_OBJS_1)               \
488                                $(SYS_OBJS_2)               \
489                                $(SYS_OBJS_3)               \
490                                                                hal/tsar_mips32/kernel.ld
491        $(LD) -o $@ -T hal/tsar_mips32/kernel.ld $(LIBGCC)      \
492          $(KERN_OBJS) $(HAL_OBJS) $(DEV_OBJS) $(MM_OBJS)   \
493          $(LIBK_OBJS) $(DRIVERS_OBJS) $(VFS_OBJS)          \
494          $(SYS_OBJS_0) $(SYS_OBJS_1) $(SYS_OBJS_2)         \
495          $(SYS_OBJS_3) -lgcc
496
497        $(DU) -D $@ > $@.txt
498        mcopy -o -i $(DISK_IMAGE) build/kernel/kernel.elf ::/bin/kernel
499
500############################################################
501# Rule to generate the init.elf and place it on virtual disk
502build/user/init/init.elf : user/init/init.c
503        $(MAKE) -C user/init
504        mcopy -o -i $(DISK_IMAGE) user/init/init.elf ::/bin/init
505 
506
Note: See TracBrowser for help on using the repository browser.