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 | |
---|
131 | SYS_OBJS_0 = build/syscalls/sys_thread_exit.o \ |
---|
132 | build/syscalls/sys_thread_yield.o \ |
---|
133 | build/syscalls/sys_thread_create.o \ |
---|
134 | build/syscalls/sys_thread_join.o \ |
---|
135 | build/syscalls/sys_thread_detach.o \ |
---|
136 | build/syscalls/sys_thread_cancel.o \ |
---|
137 | build/syscalls/sys_sem.o \ |
---|
138 | build/syscalls/sys_condvar.o \ |
---|
139 | build/syscalls/sys_barrier.o \ |
---|
140 | build/syscalls/sys_mutex.o |
---|
141 | |
---|
142 | SYS_OBJS_1 = build/syscalls/sys_exit.o \ |
---|
143 | build/syscalls/sys_munmap.o \ |
---|
144 | build/syscalls/sys_open.o \ |
---|
145 | build/syscalls/sys_mmap.o \ |
---|
146 | build/syscalls/sys_read.o \ |
---|
147 | build/syscalls/sys_write.o \ |
---|
148 | build/syscalls/sys_lseek.o \ |
---|
149 | build/syscalls/sys_close.o \ |
---|
150 | build/syscalls/sys_unlink.o \ |
---|
151 | build/syscalls/sys_pipe.o |
---|
152 | |
---|
153 | SYS_OBJS_2 = build/syscalls/sys_chdir.o \ |
---|
154 | build/syscalls/sys_mkdir.o \ |
---|
155 | build/syscalls/sys_mkfifo.o \ |
---|
156 | build/syscalls/sys_opendir.o \ |
---|
157 | build/syscalls/sys_readdir.o \ |
---|
158 | build/syscalls/sys_closedir.o \ |
---|
159 | build/syscalls/sys_getcwd.o \ |
---|
160 | build/syscalls/sys_isatty.o \ |
---|
161 | build/syscalls/sys_alarm.o \ |
---|
162 | build/syscalls/sys_rmdir.o |
---|
163 | |
---|
164 | SYS_OBJS_3 = build/syscalls/sys_utls.o \ |
---|
165 | build/syscalls/sys_chmod.o \ |
---|
166 | build/syscalls/sys_signal.o \ |
---|
167 | build/syscalls/sys_timeofday.o \ |
---|
168 | build/syscalls/sys_kill.o \ |
---|
169 | build/syscalls/sys_getpid.o \ |
---|
170 | build/syscalls/sys_fork.o \ |
---|
171 | build/syscalls/sys_exec.o \ |
---|
172 | build/syscalls/sys_stat.o \ |
---|
173 | build/syscalls/sys_wait.o |
---|
174 | |
---|
175 | SYS_OBJS_4 = build/syscalls/sys_get_config.o \ |
---|
176 | build/syscalls/sys_get_core.o \ |
---|
177 | build/syscalls/sys_get_cycle.o \ |
---|
178 | build/syscalls/sys_display.o \ |
---|
179 | build/syscalls/sys_place_fork.o \ |
---|
180 | build/syscalls/sys_thread_sleep.o \ |
---|
181 | build/syscalls/sys_thread_wakeup.o \ |
---|
182 | build/syscalls/sys_trace.o \ |
---|
183 | build/syscalls/sys_fg.o \ |
---|
184 | build/syscalls/sys_is_fg.o |
---|
185 | |
---|
186 | VFS_OBJS = build/fs/vfs.o \ |
---|
187 | build/fs/fatfs.o \ |
---|
188 | build/fs/devfs.o \ |
---|
189 | build/fs/ramfs.o |
---|
190 | |
---|
191 | # List of directories to be searched for included files |
---|
192 | # when compiling for kernel.elf generation |
---|
193 | KERNEL_INCLUDE = -I. \ |
---|
194 | -Ikern \ |
---|
195 | -Idevices \ |
---|
196 | -Isyscalls \ |
---|
197 | -I$(SHARED_INCLUDE) \ |
---|
198 | -I$(HAL_ARCH)/drivers \ |
---|
199 | -Isyscalls \ |
---|
200 | -Ilibk \ |
---|
201 | -Imm \ |
---|
202 | -Ifs \ |
---|
203 | -I../tools/arch_info \ |
---|
204 | -I$(HAL)/generic \ |
---|
205 | -I$(HAL_ARCH)/core \ |
---|
206 | -I.. |
---|
207 | |
---|
208 | # Rule to generate kernel.elf. |
---|
209 | compile: dirs \ |
---|
210 | build/kernel.elf |
---|
211 | |
---|
212 | # Rule to create the build directories. |
---|
213 | dirs: |
---|
214 | @mkdir -p build |
---|
215 | @mkdir -p build/kern |
---|
216 | @mkdir -p build/hal |
---|
217 | @mkdir -p build/devices |
---|
218 | @mkdir -p build/mm |
---|
219 | @mkdir -p build/libk |
---|
220 | @mkdir -p build/drivers |
---|
221 | @mkdir -p build/fs |
---|
222 | @mkdir -p build/syscalls |
---|
223 | |
---|
224 | |
---|
225 | ############################## |
---|
226 | # rules to compile the drivers and hal |
---|
227 | $(HAL_ARCH)/build/%: |
---|
228 | $(MAKE) -C $(HAL_ARCH) |
---|
229 | |
---|
230 | ####################################### |
---|
231 | # Rules to generate kernel/kern objects |
---|
232 | build/kern/%.o: kern/%.c \ |
---|
233 | kern/%.h \ |
---|
234 | kernel_config.h \ |
---|
235 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
236 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
237 | |
---|
238 | |
---|
239 | ###################################### |
---|
240 | # Rules to generate kernel/dev objects |
---|
241 | build/devices/%.o: devices/%.c \ |
---|
242 | devices/%.h \ |
---|
243 | kernel_config.h \ |
---|
244 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
245 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
246 | |
---|
247 | ##################################### |
---|
248 | # Rules to generate kernel/mm objects |
---|
249 | build/mm/%.o: mm/%.c \ |
---|
250 | mm/%.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/libk objects |
---|
257 | build/libk/%.o: libk/%.c \ |
---|
258 | libk/%.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/syscalls objects |
---|
265 | build/syscalls/%.o: syscalls/%.c \ |
---|
266 | syscalls/syscalls.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/fs objects |
---|
273 | build/fs/%.o: fs/%.c \ |
---|
274 | fs/%.h \ |
---|
275 | kernel_config.h \ |
---|
276 | $(HAL_ARCH)/core/hal_kernel_types.h |
---|
277 | $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $< |
---|
278 | |
---|
279 | ############################## |
---|
280 | # Rule to generate kernel.elf |
---|
281 | build/kernel.elf: $(KERN_OBJS) \ |
---|
282 | $(HAL_OBJS_0) \ |
---|
283 | $(HAL_OBJS_1) \ |
---|
284 | $(DEV_OBJS) \ |
---|
285 | $(MM_OBJS) \ |
---|
286 | $(LIBK_OBJS) \ |
---|
287 | $(DRIVERS_OBJS) \ |
---|
288 | $(VFS_OBJS) \ |
---|
289 | $(SYS_OBJS_0) \ |
---|
290 | $(SYS_OBJS_1) \ |
---|
291 | $(SYS_OBJS_2) \ |
---|
292 | $(SYS_OBJS_3) \ |
---|
293 | $(SYS_OBJS_4) \ |
---|
294 | $(HAL_ARCH)/kernel.ld |
---|
295 | $(LD) -o $@ -T $(HAL_ARCH)/kernel.ld $(LIBGCC) \ |
---|
296 | $(KERN_OBJS) $(HAL_OBJS) $(DEV_OBJS) $(MM_OBJS) \ |
---|
297 | $(LIBK_OBJS) $(DRIVERS_OBJS) $(VFS_OBJS) \ |
---|
298 | $(SYS_OBJS_0) $(SYS_OBJS_1) $(SYS_OBJS_2) \ |
---|
299 | $(SYS_OBJS_3) $(SYS_OBJS_4) -lgcc |
---|
300 | $(DU) -D $@ > $@.txt |
---|
301 | |
---|
302 | clean: |
---|
303 | rm -rf build/* |
---|