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