-
Notifications
You must be signed in to change notification settings - Fork 137
/
kernel.mk
174 lines (128 loc) · 4.41 KB
/
kernel.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
CFLAGS+=$(KERNCFLAGS) -DKERNEL -O3
CFLAGS+=-Wno-address # lwIP build sadness
CFLAGS+=$(INCLUDES)
ifneq (,$(findstring ftrace,$(TRACE)))
CFLAGS+= -DCONFIG_FTRACE -pg
SRCS-kernel.elf+= \
$(SRCDIR)/unix/ftrace.c \
$(ARCHDIR)/ftrace.s
endif
ifneq (,$(findstring tracelog,$(TRACE)))
CFLAGS+= -DCONFIG_TRACELOG
SRCS-kernel.elf+= \
$(SRCDIR)/kernel/tracelog.c
ifneq ($(TRACELOG_FILE),)
TRACELOG_MKFS_OPTS="-t (tracelog:(file:$(TRACELOG_FILE)))"
endif
endif
ifneq (,$(findstring lockstats,$(TRACE)))
CFLAGS+= -DLOCK_STATS
SRCS-kernel.elf+= \
$(SRCDIR)/kernel/lockstats.c
endif
ifeq ($(MANAGEMENT),telnet)
CFLAGS+= -DMANAGEMENT_TELNET
SRCS-kernel.elf+= \
$(SRCDIR)/kernel/management_telnet.c
endif
ifneq ($(NOSMP),)
CFLAGS+= -DSPIN_LOCK_DEBUG_NOSMP
else
CFLAGS+= -DSMP_ENABLE
endif
VDSOGEN= $(TOOLDIR)/vdsogen
VDSO_SRCDIR= $(SRCDIR)/kernel
VDSO_OBJDIR= $(OBJDIR)/vdso
VDSO_SRCS= $(VDSO_SRCDIR)/vdso.c $(VDSO_SRCDIR)/vdso-now.c
VDSO_OBJS= $(patsubst $(VDSO_SRCDIR)/%.c,$(VDSO_OBJDIR)/%.o,$(VDSO_SRCS))
VDSO_CFLAGS= $(TARGET_CFLAGS) -DKERNEL -DBUILD_VDSO -I$(INCLUDES) -I$(OBJDIR) -I$(OUTDIR) -I$(SRCDIR) -fPIC -c
VDSO_LDFLAGS= -nostdlib -fPIC -shared --build-id=none --hash-style=both --eh-frame-hdr -T$(ARCHDIR)/vdso.lds
VDSO_DEPS= $(patsubst %.o,%.d,$(VDSO_OBJS))
LDFLAGS+= $(KERNLDFLAGS) --undefined=_start -T linker_script
STRIPFLAGS= -g
msg_vdsogen= VDSOGEN $@
cmd_vdsogen= $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so $@
msg_vdso_cc= CC $@
cmd_vdso_cc= $(CC) $(DEPFLAGS) $(VDSO_CFLAGS) -c $< -o $@
msg_vdso_ld= LD $@
cmd_vdso_ld= $(LD) $(VDSO_LDFLAGS) $(VDSO_OBJS) -o $@
msg_objcopy= OBJCOPY $@
cmd_objcopy= $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
msg_objdump= OBJDUMP $@
cmd_objdump= $(OBJDUMP) $(OBJDUMPFLAGS) $(OBJDUMPFLAGS_$(@F)) $< $< >$@
msg_sed= SED $@
cmd_sed= $(SED) -e 's/\#/%/' <$^ >$@
msg_version= VERSION $@
cmd_version= $(MKDIR) $(dir $@); ( $(ECHO) "\#include <runtime.h>"; $(ECHO) "const sstring gitversion = ss_static_init(\"$(shell $(GIT) rev-parse HEAD)\");" ) >$@
include ../../klib/klib.mk
include ../../rules.mk
.PHONY: mkfs vdsogen boot kernel kernel.dis target image
mkfs vdsogen:
$(Q) $(MAKE) -C $(ROOTDIR)/tools $@
target:
ifeq ($(TARGET),)
@echo TARGET variable not specified
@false
endif
$(Q) $(MAKE) -C $(ROOTDIR)/test/runtime $(TARGET)
ifneq ($(NANOS_TARGET_ROOT),)
TARGET_ROOT_OPT= -r $(NANOS_TARGET_ROOT)
endif
$(OBJDIR)/gitversion.c: $(ROOTDIR)/.git/index $(ROOTDIR)/.git/HEAD
$(call cmd,version)
$(VDSOGEN):
@$(MAKE) -C $(ROOTDIR)/tools vdsogen
$(VDSO_OBJDIR)/%.o: $(VDSO_SRCDIR)/%.c
@$(MKDIR) $(dir $@)
$(call cmd,vdso_cc)
$(VDSO_OBJDIR)/vdso.so: $(VDSO_OBJS)
$(call cmd,vdso_ld)
$(VDSO_OBJDIR)/vdso-image.c: $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so
$(call cmd,vdsogen)
$(PROG-kernel.elf): linker_script klib-syms $(VDSO_OBJDIR)/vdso-image.c
$(KERNEL): $(PROG-kernel.elf)
$(call cmd,strip)
$(OBJDIR)/kernel.dis: $(KERNEL)
$(call cmd,objdump)
msg_klib_cc= $(msg_cc)
cmd_klib_cc= $(CC) $(DEPFLAGS) $(KLIB_CFLAGS) -c $< -o $@
msg_klib_ld= $(msg_ld)
cmd_klib_ld= $(LD) $(KLIB_LDFLAGS) $^ -o $@
msg_add_syms= KLIB_SYMS $@
cmd_add_syms= $(foreach prog, $(KLIB_BINARIES), $(call add_syms,$(prog)))
define build_klib
PROG-$1= $(OBJDIR)/bin/$1
OBJS-$1= $$(foreach s,$$(filter %.c %.s %.S,$$(SRCS-$1)),$$(call objfile,.o,$$s))
OBJDIRS-$1= $$(sort $$(dir $$(OBJS-$1)))
DEPS-$1= $$(patsubst %.o,%.d,$$(OBJS-$1))
$1: $$(PROG-$1)
ifneq ($$(OBJS-$1),)
$$(PROG-$1).dbg: $$(OBJS-$1)
@$(MKDIR) $$(dir $$@)
$$(call cmd,klib_ld)
$$(PROG-$1): $$(PROG-$1).dbg
$$(call cmd,strip)
endif
DEPFILES+= $$(DEPS-$1)
CLEANFILES+= $$(PROG-$1) $$(PROG-$1).dbg $$(OBJS-$1) $$(DEPS-$1) $$(GENHEADERS-$1)
CLEANDIRS+= $$(OBJDIRS-$1)
endef
# append list of undefined symbols to linker script
define add_syms
$(Q) $(OBJDUMP) -R $1 | $(SED) -n -E 's/.*(GLOB_DAT|JUMP_SLOT|RISCV_64)[[:space:]]*/EXTERN(/p' | $(SED) -n 's/$$/)/p' >> $(KLIB_SYMS)
endef
$(foreach klib, $(KLIBS), $(eval $(call build_klib,$(klib))))
klib-syms: $(KLIB_SYMS)
$(KLIB_SYMS): $(KLIB_BINARIES)
$(Q) $(RM) $(KLIB_SYMS)
$(call cmd,add_syms)
# remove duplicated lines in linker script
$(Q) $(SED) -i.bak -n 'G; s/\n/&&/; /^\([^\n]*\n\).*\n\1/d; s/\n//; h; P' $(KLIB_SYMS)
# delete linker script backup file
$(Q) $(RM) $(KLIB_SYMS).bak
$(OBJDIR)/klib/%.o: $(KLIB_DIR)/%.c $(GENHEADERS)
@$(MKDIR) $(dir $@)
$(call cmd,klib_cc)
$(OBJDIR)/vendor/mbedtls/%.o: $(MBEDTLS_DIR)/%.c $(GENHEADERS)
@$(MKDIR) $(dir $@)
$(call cmd,klib_cc)