1 | ############################################################################# |
---|
2 | # ALMOS-MKH Makefile for Kernel # |
---|
3 | ############################################################################# |
---|
4 | |
---|
5 | -include ../params-soft.mk |
---|
6 | ifeq ($(ARCH_NAME),) |
---|
7 | $(error Please define in ARCH_NAME parameter in params-soft.mk!) |
---|
8 | endif |
---|
9 | |
---|
10 | # We choose drivers and hal file to be linked with kernel.elf |
---|
11 | ifeq ($(ARCH_NAME), tsar_mips32) |
---|
12 | |
---|
13 | DRIVERS_OBJS = $(HAL_ARCH)/build/drivers/soclib_tty.o \ |
---|
14 | $(HAL_ARCH)/build/drivers/soclib_mty.o \ |
---|
15 | $(HAL_ARCH)/build/drivers/soclib_bdv.o \ |
---|
16 | $(HAL_ARCH)/build/drivers/soclib_hba.o \ |
---|
17 | $(HAL_ARCH)/build/drivers/soclib_mmc.o \ |
---|
18 | $(HAL_ARCH)/build/drivers/soclib_pic.o \ |
---|
19 | $(HAL_ARCH)/build/drivers/soclib_nic.o \ |
---|
20 | $(HAL_ARCH)/build/drivers/soclib_dma.o \ |
---|
21 | $(HAL_ARCH)/build/drivers/soclib_fbf.o \ |
---|
22 | $(HAL_ARCH)/build/drivers/soclib_iob.o |
---|
23 | |
---|
24 | HAL_OBJS = $(HAL_ARCH)/build/core/hal_special.o \ |
---|
25 | $(HAL_ARCH)/build/core/hal_context.o \ |
---|
26 | $(HAL_ARCH)/build/core/hal_atomic.o \ |
---|
27 | $(HAL_ARCH)/build/core/hal_remote.o \ |
---|
28 | $(HAL_ARCH)/build/core/hal_uspace.o \ |
---|
29 | $(HAL_ARCH)/build/core/hal_irqmask.o \ |
---|
30 | $(HAL_ARCH)/build/core/hal_gpt.o \ |
---|
31 | $(HAL_ARCH)/build/core/hal_ppm.o \ |
---|
32 | $(HAL_ARCH)/build/core/hal_vmm.o \ |
---|
33 | $(HAL_ARCH)/build/core/hal_kentry.o \ |
---|
34 | $(HAL_ARCH)/build/core/hal_switch.o \ |
---|
35 | $(HAL_ARCH)/build/core/hal_syscall.o \ |
---|
36 | $(HAL_ARCH)/build/core/hal_exception.o \ |
---|
37 | $(HAL_ARCH)/build/core/hal_interrupt.o \ |
---|
38 | $(HAL_ARCH)/build/core/hal_drivers.o |
---|
39 | endif |
---|
40 | |
---|
41 | ifeq ($(ARCH_NAME), x86_64) |
---|
42 | |
---|
43 | DRIVERS_OBJS = $(HAL_ARCH)/build/drivers/ioc_ata.o \ |
---|
44 | $(HAL_ARCH)/build/drivers/pic_apic.o \ |
---|
45 | $(HAL_ARCH)/build/drivers/txt_rs232.o |
---|
46 | |
---|
47 | HAL_OBJS = $(HAL_ARCH)/build/core/hal_boot.o \ |
---|
48 | $(HAL_ARCH)/build/core/hal_smpboot.o \ |
---|
49 | $(HAL_ARCH)/build/core/hal_init.o \ |
---|
50 | $(HAL_ARCH)/build/core/hal_cpu.o \ |
---|
51 | $(HAL_ARCH)/build/core/hal_kentry.o \ |
---|
52 | $(HAL_ARCH)/build/core/hal_acpi.o \ |
---|
53 | $(HAL_ARCH)/build/core/hal_apic.o \ |
---|
54 | $(HAL_ARCH)/build/core/x86_printf.o \ |
---|
55 | $(HAL_ARCH)/build/core/hal_drivers.o \ |
---|
56 | $(HAL_ARCH)/build/core/hal_special.o \ |
---|
57 | $(HAL_ARCH)/build/core/hal_context.o \ |
---|
58 | $(HAL_ARCH)/build/core/hal_atomic.o \ |
---|
59 | $(HAL_ARCH)/build/core/hal_remote.o \ |
---|
60 | $(HAL_ARCH)/build/core/hal_uspace.o \ |
---|
61 | $(HAL_ARCH)/build/core/hal_irqmask.o \ |
---|
62 | $(HAL_ARCH)/build/core/hal_gpt.o \ |
---|
63 | $(HAL_ARCH)/build/core/hal_ppm.o \ |
---|
64 | $(HAL_ARCH)/build/core/hal_exception.o \ |
---|
65 | $(HAL_ARCH)/build/core/hal_interrupt.o \ |
---|
66 | $(HAL_ARCH)/build/core/hal_syscall.o |
---|
67 | endif |
---|
68 | |
---|
69 | LIBGCC = -L$(shell $(CC) -print-libgcc-file-name | sed 's/libgcc.a//') #todo ? |
---|
70 | |
---|
71 | # Rules that don't build target files |
---|
72 | # always out-of-date, need to be regenerated everytime they are called |
---|
73 | .PHONY: compile \ |
---|
74 | dirs \ |
---|
75 | clean \ |
---|
76 | build/kernel.elf |
---|
77 | |
---|
78 | |
---|
79 | # Objects to be linked for kernel.elf generation |
---|
80 | KERN_OBJS = build/kern/kernel_init.o \ |
---|
81 | build/kern/printk.o \ |
---|
82 | build/kern/thread.o \ |
---|
83 | build/kern/process.o \ |
---|
84 | build/kern/chdev.o \ |
---|
85 | build/kern/cluster.o \ |
---|
86 | build/kern/scheduler.o \ |
---|
87 | build/kern/core.o \ |
---|
88 | build/kern/dqdt.o \ |
---|
89 | build/kern/do_syscall.o \ |
---|
90 | build/kern/rpc.o |
---|
91 | |
---|
92 | DEV_OBJS = build/devices/dev_txt.o \ |
---|
93 | build/devices/dev_ioc.o \ |
---|
94 | build/devices/dev_mmc.o \ |
---|
95 | build/devices/dev_nic.o \ |
---|
96 | build/devices/dev_pic.o \ |
---|
97 | build/devices/dev_dma.o \ |
---|
98 | build/devices/dev_fbf.o \ |
---|
99 | build/devices/dev_iob.o |
---|
100 | |
---|
101 | MM_OBJS = build/mm/ppm.o \ |
---|
102 | build/mm/vmm.o \ |
---|
103 | build/mm/vseg.o \ |
---|
104 | build/mm/page.o \ |
---|
105 | build/mm/kcm.o \ |
---|
106 | build/mm/khm.o \ |
---|
107 | build/mm/mapper.o \ |
---|
108 | build/mm/kmem.o |
---|
109 | |
---|
110 | LIBK_OBJS = build/libk/grdxt.o \ |
---|
111 | build/libk/bits.o \ |
---|
112 | build/libk/elf.o \ |
---|
113 | build/libk/string.o \ |
---|
114 | build/libk/ctype.o \ |
---|
115 | build/libk/rwlock.o \ |
---|
116 | build/libk/busylock.o \ |
---|
117 | build/libk/queuelock.o \ |
---|
118 | build/libk/barrier.o \ |
---|
119 | build/libk/xbarrier.o \ |
---|
120 | build/libk/remote_busylock.o \ |
---|
121 | build/libk/remote_queuelock.o \ |
---|
122 | build/libk/remote_rwlock.o \ |
---|
123 | build/libk/remote_fifo.o \ |
---|
124 | build/libk/remote_mutex.o \ |
---|
125 | build/libk/remote_sem.o \ |
---|
126 | build/libk/remote_condvar.o \ |
---|
127 | build/libk/remote_barrier.o \ |
---|
128 | build/libk/memcpy.o \ |
---|
129 | build/libk/htab.o \ |
---|
130 | build/libk/xhtab.o \ |
---|
131 | build/libk/user_dir.o |
---|
132 | |
---|
133 | SYS_OBJS_0 = build/syscalls/sys_thread_exit.o \ |
---|
134 | build/syscalls/sys_thread_yield.o \ |
---|
135 | build/syscalls/sys_thread_create.o \ |
---|
136 | build/syscalls/sys_thread_join.o \ |
---|
137 | build/syscalls/sys_thread_detach.o \ |
---|
138 | build/syscalls/sys_thread_cancel.o \ |
---|
139 | build/syscalls/sys_sem.o \ |
---|
140 | build/syscalls/sys_condvar.o \ |
---|
141 | build/syscalls/sys_barrier.o \ |
---|
142 | build/syscalls/sys_mutex.o |
---|
143 | |
---|
144 | SYS_OBJS_1 = build/syscalls/sys_rename.o \ |
---|
145 | build/syscalls/sys_munmap.o \ |
---|
146 | build/syscalls/sys_open.o \ |
---|
147 | build/syscalls/sys_mmap.o \ |
---|
148 | build/syscalls/sys_read.o \ |
---|
149 | build/syscalls/sys_write.o \ |
---|
150 | build/syscalls/sys_lseek.o \ |
---|
151 | build/syscalls/sys_close.o \ |
---|
152 | build/syscalls/sys_unlink.o \ |
---|
153 | build/syscalls/sys_pipe.o |
---|
154 | |
---|
155 | SYS_OBJS_2 = build/syscalls/sys_chdir.o \ |
---|
156 | build/syscalls/sys_mkdir.o \ |
---|
157 | build/syscalls/sys_mkfifo.o \ |
---|
158 | build/syscalls/sys_opendir.o \ |
---|
159 | build/syscalls/sys_readdir.o \ |
---|
160 | build/syscalls/sys_closedir.o \ |
---|
161 | build/syscalls/sys_getcwd.o \ |
---|
162 | build/syscalls/sys_isatty.o \ |
---|
163 | build/syscalls/sys_alarm.o \ |
---|
164 | build/syscalls/sys_rmdir.o |
---|
165 | |
---|
166 | SYS_OBJS_3 = build/syscalls/sys_utls.o \ |
---|
167 | build/syscalls/sys_chmod.o \ |
---|
168 | build/syscalls/sys_signal.o \ |
---|
169 | build/syscalls/sys_timeofday.o \ |
---|
170 | build/syscalls/sys_kill.o \ |
---|
171 | build/syscalls/sys_getpid.o \ |
---|
172 | build/syscalls/sys_fork.o \ |
---|
173 | build/syscalls/sys_exec.o \ |
---|
174 | build/syscalls/sys_stat.o \ |
---|
175 | build/syscalls/sys_wait.o |
---|
176 | |
---|
177 | SYS_OBJS_4 = build/syscalls/sys_get_config.o \ |
---|
178 | build/syscalls/sys_get_core_id.o \ |
---|
179 | build/syscalls/sys_get_cycle.o \ |
---|
180 | build/syscalls/sys_display.o \ |
---|
181 | build/syscalls/sys_place_fork.o \ |
---|
182 | build/syscalls/sys_thread_sleep.o \ |
---|
183 | build/syscalls/sys_thread_wakeup.o \ |
---|
184 | build/syscalls/sys_trace.o \ |
---|
185 | build/syscalls/sys_fg.o \ |
---|
186 | build/syscalls/sys_is_fg.o |
---|
187 | |
---|
188 | SYS_OBJS_5 = build/syscalls/sys_exit.o \ |
---|
189 | build/syscalls/sys_sync.o \ |
---|
190 | build/syscalls/sys_fsync.o \ |
---|
191 | build/syscalls/sys_get_best_core.o \ |
---|
192 | build/syscalls/sys_get_nb_cores.o \ |
---|
193 | build/syscalls/sys_get_thread_info.o \ |
---|
194 | build/syscalls/sys_fbf.o |
---|
195 | |
---|
196 | VFS_OBJS = build/fs/vfs.o \ |
---|
197 | build/fs/fatfs.o \ |
---|
198 | build/fs/devfs.o \ |
---|
199 | build/fs/ramfs.o |
---|
200 | |
---|
201 | # List of directories to be searched for included files |
---|
202 | # when compiling for kernel.elf generation |
---|
203 | KERNEL_INCLUDE = -I. \ |
---|
204 | -Ikern \ |
---|
205 | -Idevices \ |
---|
206 | -Isyscalls \ |
---|
207 | -I$(SHARED_INCLUDE) \ |
---|
208 | -I$(HAL_ARCH)/drivers \ |
---|
209 | -Isyscalls \ |
---|
210 | -Ilibk \ |
---|
211 | -Imm \ |
---|
212 | -Ifs \ |
---|
213 | -I../tools/arch_info \ |
---|
214 | -I$(HAL)/generic \ |
---|
215 | -I$(HAL_ARCH)/core \ |
---|
216 | -I.. |
---|
217 | |
---|
218 | # Rule to generate kernel.elf. |
---|
219 | compile: dirs \ |
---|
220 | build/kernel.elf |
---|
221 | |
---|
222 | # Rule to create the build directories. |
---|
223 | dirs: |
---|
224 | @mkdir -p build |
---|
225 | @mkdir -p build/kern |
---|
226 | @mkdir -p build/hal |
---|
227 | @mkdir -p build/devices |
---|
228 | @mkdir -p build/mm |
---|
229 | @mkdir -p build/libk |
---|
230 | @mkdir -p build/drivers |
---|
231 | @mkdir -p build/fs |
---|
232 | @mkdir -p build/syscalls |
---|
233 | |
---|
234 | |
---|
235 | ###################################### |
---|
236 | # rules to compile the drivers and hal |
---|
237 | $(HAL_ARCH)/build/%: |
---|
238 | $(MAKE) -C $(HAL_ARCH) |
---|
239 | |
---|
240 | ####################################### |
---|
241 | # Rules to generate kernel/kern objects |
---|
242 | build/kern/%.o: kern/%.c \ |
---|
243 | kern/%.h \ |
---|
244 | kernel_config.h \ |
---|
245 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
246 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
247 | |
---|
248 | |
---|
249 | ###################################### |
---|
250 | # Rules to generate kernel/dev objects |
---|
251 | build/devices/%.o: devices/%.c \ |
---|
252 | devices/%.h \ |
---|
253 | kernel_config.h \ |
---|
254 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
255 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
256 | |
---|
257 | ##################################### |
---|
258 | # Rules to generate kernel/mm objects |
---|
259 | build/mm/%.o: mm/%.c \ |
---|
260 | mm/%.h \ |
---|
261 | kernel_config.h \ |
---|
262 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
263 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
264 | |
---|
265 | ####################################### |
---|
266 | # Rules to generate kernel/libk objects |
---|
267 | build/libk/%.o: libk/%.c \ |
---|
268 | libk/%.h \ |
---|
269 | kernel_config.h \ |
---|
270 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
271 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
272 | |
---|
273 | ########################################### |
---|
274 | # Rules to generate kernel/syscalls objects |
---|
275 | build/syscalls/%.o: syscalls/%.c \ |
---|
276 | syscalls/syscalls.h \ |
---|
277 | kernel_config.h \ |
---|
278 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
279 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
280 | |
---|
281 | ####################################### |
---|
282 | # Rules to generate kernel/fs objects |
---|
283 | build/fs/%.o: fs/%.c \ |
---|
284 | fs/%.h \ |
---|
285 | kernel_config.h \ |
---|
286 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
287 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
288 | |
---|
289 | ############################## |
---|
290 | # Rule to generate kernel.elf |
---|
291 | build/kernel.elf: $(KERN_OBJS) \ |
---|
292 | $(HAL_OBJS_0) \ |
---|
293 | $(HAL_OBJS_1) \ |
---|
294 | $(DEV_OBJS) \ |
---|
295 | $(MM_OBJS) \ |
---|
296 | $(LIBK_OBJS) \ |
---|
297 | $(DRIVERS_OBJS) \ |
---|
298 | $(VFS_OBJS) \ |
---|
299 | $(SYS_OBJS_0) \ |
---|
300 | $(SYS_OBJS_1) \ |
---|
301 | $(SYS_OBJS_2) \ |
---|
302 | $(SYS_OBJS_3) \ |
---|
303 | $(SYS_OBJS_4) \ |
---|
304 | $(SYS_OBJS_5) \ |
---|
305 | $(HAL_ARCH)/kernel.ld |
---|
306 | $(LD) -o $@ -T $(HAL_ARCH)/kernel.ld $(LIBGCC) \ |
---|
307 | $(KERN_OBJS) $(HAL_OBJS) $(DEV_OBJS) $(MM_OBJS) \ |
---|
308 | $(LIBK_OBJS) $(DRIVERS_OBJS) $(VFS_OBJS) \ |
---|
309 | $(SYS_OBJS_0) $(SYS_OBJS_1) $(SYS_OBJS_2) \ |
---|
310 | $(SYS_OBJS_3) $(SYS_OBJS_4) $(SYS_OBJS_5) -lgcc |
---|
311 | $(DU) -D $@ > $@.txt |
---|
312 | |
---|
313 | clean: |
---|
314 | rm -rf build/* |
---|