1 | ############################################################################# |
---|
2 | # ALMOS-MK Makefile for TSAR # |
---|
3 | ############################################################################# |
---|
4 | |
---|
5 | -include params.mk |
---|
6 | |
---|
7 | # Compilation flags. |
---|
8 | CFLAGS = -Wall -ffreestanding -mno-gpopt -mips32 -g -O2 \ |
---|
9 | -fno-delete-null-pointer-checks |
---|
10 | # -fno-delete-null-pointer-checks -std=c99 |
---|
11 | |
---|
12 | # Export all variables to applications sub-Makefile. |
---|
13 | export |
---|
14 | CC = mipsel-unknown-elf-gcc |
---|
15 | AS = mipsel-unknown-elf-as |
---|
16 | LD = mipsel-unknown-elf-ld |
---|
17 | DU = mipsel-unknown-elf-objdump |
---|
18 | AR = mipsel-unknown-elf-ar |
---|
19 | |
---|
20 | # Default values for hardware parameters. |
---|
21 | # These parameters should be defined in the 'params.mk' file. |
---|
22 | ARCH ?= /users/alain/soc/tsar-trunk-svn-2013/platforms/tsar_generic_iob |
---|
23 | X_SIZE ?= 2 |
---|
24 | Y_SIZE ?= 2 |
---|
25 | NB_PROCS ?= 2 |
---|
26 | NB_TTYS ?= 1 |
---|
27 | FBF_WIDTH ?= 256 |
---|
28 | IOC_TYPE ?= IOC_BDV |
---|
29 | MWR_TYPE ?= MWR_CPY |
---|
30 | |
---|
31 | |
---|
32 | # Checking hardware platform definition. |
---|
33 | ifeq ($(wildcard $(ARCH)),) |
---|
34 | $(error Please define in ARCH parameter the path to the hardware platform!) |
---|
35 | endif |
---|
36 | |
---|
37 | # Rules that don't build target files |
---|
38 | # always out-of-date, need to be regenerated everytime they are called |
---|
39 | .PHONY: compile \ |
---|
40 | dirs \ |
---|
41 | list \ |
---|
42 | extract \ |
---|
43 | fsck \ |
---|
44 | clean \ |
---|
45 | build-disk \ |
---|
46 | build/boot/boot.elf \ |
---|
47 | build/kernel/kernel.elf |
---|
48 | |
---|
49 | # Objects to be linked for boot.elf generation |
---|
50 | BOOT_OBJS = build/boot/boot.o \ |
---|
51 | build/boot/boot_fat32.o \ |
---|
52 | build/boot/boot_utils.o \ |
---|
53 | build/boot/boot_entry.o \ |
---|
54 | build/boot/boot_tty_driver.o \ |
---|
55 | build/boot/boot_hba_driver.o \ |
---|
56 | build/boot/boot_bdv_driver.o \ |
---|
57 | build/boot/boot_mmc_driver.o |
---|
58 | |
---|
59 | # List of directories to be searched for included files |
---|
60 | # when compiling for boot.elf generation |
---|
61 | BOOT_INCLUDE = -Itools/bootloader_tsar \ |
---|
62 | -Itools/arch_info \ |
---|
63 | -Ihal/tsar_mips32 \ |
---|
64 | -I. |
---|
65 | |
---|
66 | # Objects to be linked for the soclib drivers library |
---|
67 | DRIVERS_OBJS = build/kernel/drivers/soclib_tty.o \ |
---|
68 | build/kernel/drivers/soclib_bdv.o \ |
---|
69 | build/kernel/drivers/soclib_hba.o \ |
---|
70 | build/kernel/drivers/soclib_mmc.o \ |
---|
71 | build/kernel/drivers/soclib_xcu.o \ |
---|
72 | build/kernel/drivers/soclib_pic.o \ |
---|
73 | build/kernel/drivers/soclib_nic.o \ |
---|
74 | build/kernel/drivers/soclib_iob.o |
---|
75 | |
---|
76 | # Objects to be linked for kernel.elf generation |
---|
77 | KERN_OBJS = build/kernel/kern/kernel_init.o \ |
---|
78 | build/kernel/kern/printk.o \ |
---|
79 | build/kernel/kern/thread.o \ |
---|
80 | build/kernel/kern/process.o \ |
---|
81 | build/kernel/kern/device.o \ |
---|
82 | build/kernel/kern/cluster.o \ |
---|
83 | build/kernel/kern/scheduler.o \ |
---|
84 | build/kernel/kern/core.o \ |
---|
85 | build/kernel/kern/dqdt.o \ |
---|
86 | build/kernel/kern/remote_sem.o \ |
---|
87 | build/kernel/kern/rpc.o |
---|
88 | |
---|
89 | HAL_OBJS = build/kernel/hal/hal_special.o \ |
---|
90 | build/kernel/hal/hal_context.o \ |
---|
91 | build/kernel/hal/hal_atomic.o \ |
---|
92 | build/kernel/hal/hal_remote.o \ |
---|
93 | build/kernel/hal/hal_uspace.o \ |
---|
94 | build/kernel/hal/hal_irqmask.o \ |
---|
95 | build/kernel/hal/hal_gpt.o |
---|
96 | |
---|
97 | DEV_OBJS = build/kernel/devices/dev_txt.o \ |
---|
98 | build/kernel/devices/dev_ioc.o \ |
---|
99 | build/kernel/devices/dev_icu.o \ |
---|
100 | build/kernel/devices/dev_mmc.o \ |
---|
101 | build/kernel/devices/dev_nic.o \ |
---|
102 | build/kernel/devices/dev_pic.o \ |
---|
103 | build/kernel/devices/dev_iox.o |
---|
104 | |
---|
105 | MM_OBJS = build/kernel/mm/ppm.o \ |
---|
106 | build/kernel/mm/vmm.o \ |
---|
107 | build/kernel/mm/vseg.o \ |
---|
108 | build/kernel/mm/page.o \ |
---|
109 | build/kernel/mm/kcm.o \ |
---|
110 | build/kernel/mm/khm.o \ |
---|
111 | build/kernel/mm/mapper.o \ |
---|
112 | build/kernel/mm/kmem.o |
---|
113 | |
---|
114 | LIBK_OBJS = build/kernel/libk/grdxt.o \ |
---|
115 | build/kernel/libk/bits.o \ |
---|
116 | build/kernel/libk/elf.o \ |
---|
117 | build/kernel/libk/string.o \ |
---|
118 | build/kernel/libk/ctype.o \ |
---|
119 | build/kernel/libk/rwlock.o \ |
---|
120 | build/kernel/libk/spinlock.o \ |
---|
121 | build/kernel/libk/remote_barrier.o \ |
---|
122 | build/kernel/libk/remote_spinlock.o \ |
---|
123 | build/kernel/libk/remote_rwlock.o \ |
---|
124 | build/kernel/libk/remote_fifo.o \ |
---|
125 | build/kernel/libk/memcpy.o \ |
---|
126 | build/kernel/libk/xhtab.o |
---|
127 | |
---|
128 | SYS_OBJS = build/kernel/syscalls/sys_exec.o \ |
---|
129 | build/kernel/syscalls/sys_thread_create.o |
---|
130 | |
---|
131 | VFS_OBJS = build/kernel/vfs/vfs.o \ |
---|
132 | build/kernel/vfs/fatfs.o \ |
---|
133 | build/kernel/vfs/ramfs.o |
---|
134 | |
---|
135 | # List of directories to be searched for included files |
---|
136 | # when compiling for kernel.elf generation |
---|
137 | KERNEL_INCLUDE = -Ikernel \ |
---|
138 | -Ikernel/kern \ |
---|
139 | -Ikernel/devices \ |
---|
140 | -Ikernel/drivers/soclib \ |
---|
141 | -Ikernel/syscalls \ |
---|
142 | -Ikernel/libk \ |
---|
143 | -Ikernel/mm \ |
---|
144 | -Ikernel/vfs \ |
---|
145 | -Ikernel/fs/fatfs \ |
---|
146 | -Ikernel/fs/sysfs \ |
---|
147 | -Ikernel/fs/ramfs \ |
---|
148 | -Ikernel/fs/devfs \ |
---|
149 | -Itools/arch_info \ |
---|
150 | -Ihal/tsar_mips32 \ |
---|
151 | -I. |
---|
152 | |
---|
153 | # Macros to be processed by the C preprocessor. |
---|
154 | MACROS = -DARCHINFO_PATHNAME="\"arch_info.bin\"" \ |
---|
155 | -DKERNEL_PATHNAME="\"/bin/kernel/kernel.elf\"" |
---|
156 | |
---|
157 | # Virtual disk path |
---|
158 | DISK_IMAGE := hdd/virt_hdd.dmg |
---|
159 | |
---|
160 | # The Mtools used to build the FAT32 disk image perfom a few sanity checks, to |
---|
161 | # make sure that the disk is indeed an MS-DOS disk. However, the size of the |
---|
162 | # disk image used by ALMOS-VM is not MS-DOS compliant. |
---|
163 | # Setting this variable prevents these checks. |
---|
164 | MTOOLS_SKIP_CHECK := 1 |
---|
165 | |
---|
166 | # Rule to compile boot.elf, kernel.elf, and update virtual disk. |
---|
167 | compile: dirs \ |
---|
168 | hard_config.h \ |
---|
169 | build/boot/boot.elf \ |
---|
170 | build/kernel/kernel.elf \ |
---|
171 | list |
---|
172 | |
---|
173 | # Rule to create the build directories. |
---|
174 | dirs: |
---|
175 | @mkdir -p build/boot |
---|
176 | @mkdir -p build/kernel |
---|
177 | @mkdir -p build/kernel/kern |
---|
178 | @mkdir -p build/kernel/hal |
---|
179 | @mkdir -p build/kernel/devices |
---|
180 | @mkdir -p build/kernel/mm |
---|
181 | @mkdir -p build/kernel/libk |
---|
182 | @mkdir -p build/kernel/drivers |
---|
183 | @mkdir -p build/kernel/vfs |
---|
184 | @mkdir -p hdd |
---|
185 | |
---|
186 | # Rule to make a recursive list of the virtual disk content. |
---|
187 | list: |
---|
188 | mdir -/ -w -i $(DISK_IMAGE) ::/ |
---|
189 | |
---|
190 | # Rule to make a file system check for the virtual disk. |
---|
191 | fsck: |
---|
192 | fsck.msdos $(DISK_IMAGE) |
---|
193 | |
---|
194 | ############################################################## |
---|
195 | # Rule to copy the files generated by the virtual prototype |
---|
196 | # from the virtual disk 'home' directory to the current directory. |
---|
197 | extract: |
---|
198 | mcopy -o -i $(DISK_IMAGE) ::/home . |
---|
199 | |
---|
200 | # Rules to delete all binary files from Unix File System |
---|
201 | # without modifying the virtual disk. |
---|
202 | clean: |
---|
203 | rm -f *.o *.elf *.bin *.txt core |
---|
204 | rm -f hard_config.h arch_info.xml arch_info.bin |
---|
205 | rm -rf build |
---|
206 | |
---|
207 | #################################################### |
---|
208 | # Rule for building a new virtual disk from scratch. |
---|
209 | # It creates the bin / home directories. |
---|
210 | # This requires the generic Linux/MacOS 'create_dmg' script, that should be |
---|
211 | # placed in the same directory as this Makefile. |
---|
212 | build-disk: |
---|
213 | rm -f $(DISK_IMAGE) |
---|
214 | ./create_dmg create $(basename $(DISK_IMAGE)) |
---|
215 | dd if=$(DISK_IMAGE) of=temp.dmg count=65536 |
---|
216 | mv temp.dmg $(DISK_IMAGE) |
---|
217 | mmd -o -i $(DISK_IMAGE) ::/bin || true |
---|
218 | mmd -o -i $(DISK_IMAGE) ::/bin/kernel || true |
---|
219 | mmd -o -i $(DISK_IMAGE) ::/home || true |
---|
220 | mdir -/ -b -i $(DISK_IMAGE) ::/ |
---|
221 | |
---|
222 | ############################################################## |
---|
223 | # Rules to generate hardware description files (hard_config.h, |
---|
224 | # arch_info.bin and arch_info.xml), and update the virtual disk. |
---|
225 | hard_config.h: $(ARCH)/arch_info.py |
---|
226 | tools/arch_info/genarch.py --arch=$(ARCH) \ |
---|
227 | --x_size=$(X_SIZE) \ |
---|
228 | --y_size=$(Y_SIZE) \ |
---|
229 | --nb_cores=$(NB_PROCS) \ |
---|
230 | --nb_ttys=$(NB_TTYS) \ |
---|
231 | --fbf_size=$(FBF_WIDTH) \ |
---|
232 | --ioc_type=$(IOC_TYPE) \ |
---|
233 | --mwr_type=$(MWR_TYPE) \ |
---|
234 | --hard=. \ |
---|
235 | --bin=. \ |
---|
236 | --xml=. |
---|
237 | mcopy -o -i $(DISK_IMAGE) arch_info.bin ::/ || true |
---|
238 | |
---|
239 | ################################################ |
---|
240 | # Rules to compile boot drivers used by boot.elf |
---|
241 | build/boot/boot_tty_driver.o: tools/bootloader_tsar/boot_tty_driver.c \ |
---|
242 | tools/bootloader_tsar/boot_tty_driver.h \ |
---|
243 | tools/bootloader_tsar/boot_utils.h \ |
---|
244 | tools/bootloader_tsar/boot_config.h \ |
---|
245 | hal/tsar_mips32/hal_types.h \ |
---|
246 | hard_config.h |
---|
247 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
248 | $(DU) -D $@ > $@.txt |
---|
249 | |
---|
250 | build/boot/boot_bdv_driver.o: tools/bootloader_tsar/boot_bdv_driver.c \ |
---|
251 | tools/bootloader_tsar/boot_bdv_driver.h \ |
---|
252 | tools/bootloader_tsar/boot_utils.h \ |
---|
253 | tools/bootloader_tsar/boot_config.h \ |
---|
254 | hal/tsar_mips32/hal_types.h \ |
---|
255 | hard_config.h |
---|
256 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
257 | $(DU) -D $@ > $@.txt |
---|
258 | |
---|
259 | build/boot/boot_hba_driver.o: tools/bootloader_tsar/boot_hba_driver.c \ |
---|
260 | tools/bootloader_tsar/boot_hba_driver.h \ |
---|
261 | tools/bootloader_tsar/boot_utils.h \ |
---|
262 | tools/bootloader_tsar/boot_config.h \ |
---|
263 | hal/tsar_mips32/hal_types.h \ |
---|
264 | hard_config.h |
---|
265 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
266 | $(DU) -D $@ > $@.txt |
---|
267 | |
---|
268 | build/boot/boot_mmc_driver.o: tools/bootloader_tsar/boot_mmc_driver.c \ |
---|
269 | tools/bootloader_tsar/boot_mmc_driver.h \ |
---|
270 | tools/bootloader_tsar/boot_utils.h \ |
---|
271 | tools/bootloader_tsar/boot_config.h \ |
---|
272 | hal/tsar_mips32/hal_types.h \ |
---|
273 | hard_config.h |
---|
274 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
275 | $(DU) -D $@ > $@.txt |
---|
276 | |
---|
277 | ############################## |
---|
278 | # Rule to compile boot_fat32.o |
---|
279 | build/boot/boot_fat32.o: tools/bootloader_tsar/boot_fat32.c \ |
---|
280 | tools/bootloader_tsar/boot_fat32.h \ |
---|
281 | tools/bootloader_tsar/boot_utils.h \ |
---|
282 | tools/bootloader_tsar/boot_config.h \ |
---|
283 | hal/tsar_mips32/hal_types.h \ |
---|
284 | hard_config.h |
---|
285 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
286 | $(DU) -D $@ > $@.txt |
---|
287 | |
---|
288 | ############################## |
---|
289 | # Rule to compile boot_utils.o |
---|
290 | build/boot/boot_utils.o: tools/bootloader_tsar/boot_utils.c \ |
---|
291 | tools/bootloader_tsar/boot_utils.h \ |
---|
292 | tools/bootloader_tsar/boot_tty_driver.h \ |
---|
293 | hal/tsar_mips32/hal_types.h \ |
---|
294 | hard_config.h |
---|
295 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
296 | $(DU) -D $@ > $@.txt |
---|
297 | |
---|
298 | ######################## |
---|
299 | # Rule to compile boot.o |
---|
300 | build/boot/boot.o: tools/bootloader_tsar/boot.c \ |
---|
301 | tools/bootloader_tsar/boot_utils.h \ |
---|
302 | tools/bootloader_tsar/boot_fat32.h \ |
---|
303 | tools/bootloader_tsar/boot_tty_driver.h \ |
---|
304 | tools/bootloader_tsar/boot_hba_driver.h \ |
---|
305 | tools/bootloader_tsar/boot_bdv_driver.h \ |
---|
306 | tools/bootloader_tsar/boot_mmc_driver.h \ |
---|
307 | tools/bootloader_tsar/boot_config.h \ |
---|
308 | hal/tsar_mips32/hal_types.h \ |
---|
309 | hard_config.h |
---|
310 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) $(MACROS) -c -o $@ $< |
---|
311 | $(DU) -D $@ > $@.txt |
---|
312 | |
---|
313 | ############################## |
---|
314 | # Rule to compile boot_entry.o |
---|
315 | build/boot/boot_entry.o: tools/bootloader_tsar/boot_entry.S \ |
---|
316 | tools/bootloader_tsar/boot_config.h \ |
---|
317 | hard_config.h |
---|
318 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
319 | $(DU) -D $@ > $@.txt |
---|
320 | |
---|
321 | ##################################################################### |
---|
322 | # Rule to generate boot.elf and place it in sector #2 of virtual disk |
---|
323 | build/boot/boot.elf: $(BOOT_OBJS) \ |
---|
324 | tools/bootloader_tsar/boot.ld |
---|
325 | $(LD) -o $@ -T tools/bootloader_tsar/boot.ld $(BOOT_OBJS) |
---|
326 | $(DU) -D $@ > $@.txt |
---|
327 | dd if=build/boot/boot.elf of=$(DISK_IMAGE) seek=2 conv=notrunc |
---|
328 | |
---|
329 | |
---|
330 | ############################## |
---|
331 | # rules to compile the drivers |
---|
332 | build/kernel/drivers/%.o: kernel/drivers/soclib/%.c \ |
---|
333 | kernel/drivers/soclib/%.h \ |
---|
334 | almos_config.h \ |
---|
335 | hal/tsar_mips32/hal_types.h |
---|
336 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
337 | $(DU) -D $@ > $@.txt |
---|
338 | |
---|
339 | ####################################### |
---|
340 | # Rules to generate kernel/kern objects |
---|
341 | build/kernel/kern/%.o: kernel/kern/%.c \ |
---|
342 | kernel/kern/%.h \ |
---|
343 | almos_config.h \ |
---|
344 | hal/tsar_mips32/hal_types.h |
---|
345 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
346 | $(DU) -D $@ > $@.txt |
---|
347 | |
---|
348 | ###################################### |
---|
349 | # Rules to generate kernel/hal objects |
---|
350 | build/kernel/hal/%.o: hal/tsar_mips32/%.c \ |
---|
351 | hal/tsar_mips32/%.h \ |
---|
352 | almos_config.h \ |
---|
353 | hal/tsar_mips32/hal_types.h |
---|
354 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
355 | $(DU) -D $@ > $@.txt |
---|
356 | |
---|
357 | ###################################### |
---|
358 | # Rules to generate kernel/dev objects |
---|
359 | build/kernel/devices/%.o: kernel/devices/%.c \ |
---|
360 | kernel/devices/%.h \ |
---|
361 | almos_config.h \ |
---|
362 | hal/tsar_mips32/hal_types.h |
---|
363 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
364 | $(DU) -D $@ > $@.txt |
---|
365 | |
---|
366 | ##################################### |
---|
367 | # Rules to generate kernel/mm objects |
---|
368 | build/kernel/mm/%.o: kernel/mm/%.c \ |
---|
369 | kernel/mm/%.h \ |
---|
370 | almos_config.h \ |
---|
371 | hal/tsar_mips32/hal_types.h |
---|
372 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
373 | $(DU) -D $@ > $@.txt |
---|
374 | |
---|
375 | ####################################### |
---|
376 | # Rules to generate kernel/libk objects |
---|
377 | build/kernel/libk/%.o: kernel/libk/%.c \ |
---|
378 | kernel/libk/%.h \ |
---|
379 | almos_config.h \ |
---|
380 | hal/tsar_mips32/hal_types.h |
---|
381 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
382 | $(DU) -D $@ > $@.txt |
---|
383 | |
---|
384 | ####################################### |
---|
385 | # Rules to generate kernel/vfs objects |
---|
386 | build/kernel/vfs/%.o: kernel/vfs/%.c \ |
---|
387 | kernel/vfs/vfs.h \ |
---|
388 | almos_config.h \ |
---|
389 | hal/tsar_mips32/hal_types.h |
---|
390 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
391 | $(DU) -D $@ > $@.txt |
---|
392 | |
---|
393 | ########################################################### |
---|
394 | # Rule to generate kernel.elf and place it on virtual disk |
---|
395 | build/kernel/kernel.elf: $(KERN_OBJS) \ |
---|
396 | $(HAL_OBJS) \ |
---|
397 | $(DEV_OBJS) \ |
---|
398 | $(MM_OBJS) \ |
---|
399 | $(LIBK_OBJS) \ |
---|
400 | $(DRIVERS_OBJS) \ |
---|
401 | $(VFS_OBJS) \ |
---|
402 | kernel/kernel.ld |
---|
403 | $(LD) -o $@ -T kernel/kernel.ld \ |
---|
404 | $(KERN_OBJS) $(HAL_OBJS) $(DEV_OBJS) $(MM_OBJS) \ |
---|
405 | $(LIBK_OBJS) $(DRIVERS_OBJS) $(VFS_OBJS) |
---|
406 | $(DU) -D $@ > $@.txt |
---|
407 | mcopy -o -i $(DISK_IMAGE) build/kernel/kernel.elf ::/bin/kernel |
---|
408 | |
---|