blob: 716e38320af2479d7128450ee2af17b4c6b365ce [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001LOCAL_DIR := $(GET_LOCAL_DIR)
2
3MODULE := $(LOCAL_DIR)
4
5# can override this in local.mk
6ENABLE_THUMB?=true
7
8# default to the regular arm subarch
9SUBARCH := arm
10
11GLOBAL_DEFINES += \
12 ARM_CPU_$(ARM_CPU)=1
13
14# do set some options based on the cpu core
15HANDLED_CORE := false
16ifeq ($(ARM_CPU),cortex-m0)
17GLOBAL_DEFINES += \
18 ARM_CPU_CORTEX_M0=1 \
19 ARM_ISA_ARMV6M=1 \
20 ARM_WITH_THUMB=1
21HANDLED_CORE := true
22ENABLE_THUMB := true
23SUBARCH := arm-m
24endif
25ifeq ($(ARM_CPU),cortex-m0plus)
26GLOBAL_DEFINES += \
27 ARM_CPU_CORTEX_M0_PLUS=1 \
28 ARM_ISA_ARMV6M=1 \
29 ARM_WITH_THUMB=1
30HANDLED_CORE := true
31ENABLE_THUMB := true
32SUBARCH := arm-m
33endif
34ifeq ($(ARM_CPU),cortex-m3)
35GLOBAL_DEFINES += \
36 ARM_CPU_CORTEX_M3=1 \
37 ARM_ISA_ARMv7=1 \
38 ARM_ISA_ARMv7M=1 \
39 ARM_WITH_THUMB=1 \
40 ARM_WITH_THUMB2=1
41HANDLED_CORE := true
42ENABLE_THUMB := true
43SUBARCH := arm-m
44endif
45ifeq ($(ARM_CPU),cortex-m4)
46GLOBAL_DEFINES += \
47 ARM_CPU_CORTEX_M4=1 \
48 ARM_ISA_ARMv7=1 \
49 ARM_ISA_ARMv7M=1 \
50 ARM_WITH_THUMB=1 \
51 ARM_WITH_THUMB2=1
52HANDLED_CORE := true
53ENABLE_THUMB := true
54SUBARCH := arm-m
55endif
56ifeq ($(ARM_CPU),cortex-m4f)
57GLOBAL_DEFINES += \
58 ARM_CPU_CORTEX_M4=1 \
59 ARM_CPU_CORTEX_M4F=1 \
60 ARM_ISA_ARMv7=1 \
61 ARM_ISA_ARMv7M=1 \
62 ARM_WITH_THUMB=1 \
63 ARM_WITH_THUMB2=1 \
64 ARM_WITH_VFP=1 \
65 __FPU_PRESENT=1
66HANDLED_CORE := true
67ENABLE_THUMB := true
68SUBARCH := arm-m
69endif
70ifeq ($(ARM_CPU),cortex-m7)
71GLOBAL_DEFINES += \
72 ARM_CPU_CORTEX_M7=1 \
73 ARM_ISA_ARMv7=1 \
74 ARM_ISA_ARMv7M=1 \
75 ARM_WITH_THUMB=1 \
76 ARM_WITH_THUMB2=1 \
77 ARM_WITH_CACHE=1
78HANDLED_CORE := true
79ENABLE_THUMB := true
80SUBARCH := arm-m
81endif
82ifeq ($(ARM_CPU),cortex-a7)
83GLOBAL_DEFINES += \
84 ARM_WITH_CP15=1 \
85 ARM_WITH_MMU=1 \
86 ARM_ISA_ARMv7=1 \
87 ARM_ISA_ARMv7A=1 \
88 ARM_WITH_VFP=1 \
89 ARM_WITH_NEON=1 \
90 ARM_WITH_THUMB=1 \
91 ARM_WITH_THUMB2=1 \
92 ARM_WITH_CACHE=1
93HANDLED_CORE := true
94endif
95ifeq ($(ARM_CPU),cortex-a15)
96GLOBAL_DEFINES += \
97 ARM_WITH_CP15=1 \
98 ARM_WITH_MMU=1 \
99 ARM_ISA_ARMv7=1 \
100 ARM_ISA_ARMv7A=1 \
101 ARM_WITH_THUMB=1 \
102 ARM_WITH_THUMB2=1 \
103 ARM_WITH_CACHE=1 \
104 ARM_WITH_L2=1
105ifneq ($(ARM_WITHOUT_VFP_NEON),true)
106GLOBAL_DEFINES += \
107 ARM_WITH_VFP=1 \
108 ARM_WITH_NEON=1
109endif
110HANDLED_CORE := true
111endif
112ifeq ($(ARM_CPU),cortex-a8)
113GLOBAL_DEFINES += \
114 ARM_WITH_CP15=1 \
115 ARM_WITH_MMU=1 \
116 ARM_ISA_ARMv7=1 \
117 ARM_ISA_ARMv7A=1 \
118 ARM_WITH_VFP=1 \
119 ARM_WITH_NEON=1 \
120 ARM_WITH_THUMB=1 \
121 ARM_WITH_THUMB2=1 \
122 ARM_WITH_CACHE=1 \
123 ARM_WITH_L2=1
124HANDLED_CORE := true
125endif
126ifeq ($(ARM_CPU),cortex-a9)
127GLOBAL_DEFINES += \
128 ARM_WITH_CP15=1 \
129 ARM_WITH_MMU=1 \
130 ARM_ISA_ARMv7=1 \
131 ARM_ISA_ARMv7A=1 \
132 ARM_WITH_THUMB=1 \
133 ARM_WITH_THUMB2=1 \
134 ARM_WITH_CACHE=1
135HANDLED_CORE := true
136endif
137ifeq ($(ARM_CPU),cortex-a9-neon)
138GLOBAL_DEFINES += \
139 ARM_CPU_CORTEX_A9=1 \
140 ARM_WITH_CP15=1 \
141 ARM_WITH_MMU=1 \
142 ARM_ISA_ARMv7=1 \
143 ARM_ISA_ARMv7A=1 \
144 ARM_WITH_VFP=1 \
145 ARM_WITH_NEON=1 \
146 ARM_WITH_THUMB=1 \
147 ARM_WITH_THUMB2=1 \
148 ARM_WITH_CACHE=1
149HANDLED_CORE := true
150endif
151ifeq ($(ARM_CPU),arm1136j-s)
152GLOBAL_DEFINES += \
153 ARM_WITH_CP15=1 \
154 ARM_WITH_MMU=1 \
155 ARM_ISA_ARMv6=1 \
156 ARM_WITH_THUMB=1 \
157 ARM_WITH_CACHE=1 \
158 ARM_CPU_ARM1136=1
159HANDLED_CORE := true
160endif
161ifeq ($(ARM_CPU),arm1176jzf-s)
162GLOBAL_DEFINES += \
163 ARM_WITH_CP15=1 \
164 ARM_WITH_MMU=1 \
165 ARM_ISA_ARMv6=1 \
166 ARM_WITH_VFP=1 \
167 ARM_WITH_THUMB=1 \
168 ARM_WITH_CACHE=1 \
169 ARM_CPU_ARM1136=1
170HANDLED_CORE := true
171endif
172ifeq ($(ARM_CPU),armemu)
173# flavor of emulated cpu by the armemu project
174GLOBAL_DEFINES += \
175 ARM_WITH_CP15=1 \
176 ARM_ISA_ARMv7=1 \
177 ARM_ISA_ARMv7A=1 \
178 ARM_WITH_CACHE=1
179HANDLED_CORE := true
180ENABLE_THUMB := false # armemu doesn't currently support thumb properly
181endif
182
183ifneq ($(HANDLED_CORE),true)
184$(error $(LOCAL_DIR)/rules.mk doesnt have logic for arm core $(ARM_CPU))
185endif
186
187THUMBCFLAGS :=
188THUMBINTERWORK :=
189ifeq ($(ENABLE_THUMB),true)
190THUMBCFLAGS := -mthumb -D__thumb__
191endif
192
193GLOBAL_INCLUDES += \
194 $(LOCAL_DIR)/$(SUBARCH)/include
195
196ifeq ($(SUBARCH),arm)
197MODULE_SRCS += \
198 $(LOCAL_DIR)/arm/start.S \
199 $(LOCAL_DIR)/arm/asm.S \
200 $(LOCAL_DIR)/arm/cache-ops.S \
201 $(LOCAL_DIR)/arm/cache.c \
202 $(LOCAL_DIR)/arm/debug.c \
203 $(LOCAL_DIR)/arm/ops.S \
204 $(LOCAL_DIR)/arm/exceptions.S \
205 $(LOCAL_DIR)/arm/faults.c \
206 $(LOCAL_DIR)/arm/fpu.c \
207 $(LOCAL_DIR)/arm/mmu.c \
208 $(LOCAL_DIR)/arm/thread.c
209
210MODULE_ARM_OVERRIDE_SRCS := \
211 $(LOCAL_DIR)/arm/arch.c
212
213GLOBAL_DEFINES += \
214 ARCH_DEFAULT_STACK_SIZE=4096
215
216ARCH_OPTFLAGS := -O2
217WITH_LINKER_GC ?= 1
218
219# we have a mmu and want the vmm/pmm
220WITH_KERNEL_VM ?= 1
221
222# for arm, have the kernel occupy the entire top 3GB of virtual space,
223# but put the kernel itself at 0x80000000.
224# this leaves 0x40000000 - 0x80000000 open for kernel space to use.
225GLOBAL_DEFINES += \
226 KERNEL_ASPACE_BASE=0x40000000 \
227 KERNEL_ASPACE_SIZE=0xc0000000
228
229KERNEL_BASE ?= 0x80000000
230KERNEL_LOAD_OFFSET ?= 0
231
232GLOBAL_DEFINES += \
233 KERNEL_BASE=$(KERNEL_BASE) \
234 KERNEL_LOAD_OFFSET=$(KERNEL_LOAD_OFFSET)
235
236# if its requested we build with SMP, arm generically supports 4 cpus
237ifeq ($(WITH_SMP),1)
238SMP_MAX_CPUS ?= 4
239SMP_CPU_CLUSTER_SHIFT ?= 8
240SMP_CPU_ID_BITS ?= 24
241
242GLOBAL_DEFINES += \
243 WITH_SMP=1 \
244 SMP_MAX_CPUS=$(SMP_MAX_CPUS) \
245 SMP_CPU_CLUSTER_SHIFT=$(SMP_CPU_CLUSTER_SHIFT) \
246 SMP_CPU_ID_BITS=$(SMP_CPU_ID_BITS)
247
248MODULE_SRCS += \
249 $(LOCAL_DIR)/arm/mp.c
250else
251GLOBAL_DEFINES += \
252 SMP_MAX_CPUS=1
253endif
254
255ifeq (true,$(call TOBOOL,$(WITH_NS_MAPPING)))
256GLOBAL_DEFINES += \
257 WITH_ARCH_MMU_PICK_SPOT=1
258endif
259
260endif
261ifeq ($(SUBARCH),arm-m)
262MODULE_SRCS += \
263 $(LOCAL_DIR)/arm-m/arch.c \
264 $(LOCAL_DIR)/arm-m/cache.c \
265 $(LOCAL_DIR)/arm-m/exceptions.c \
266 $(LOCAL_DIR)/arm-m/start.c \
267 $(LOCAL_DIR)/arm-m/spin_cycles.c \
268 $(LOCAL_DIR)/arm-m/thread.c \
269 $(LOCAL_DIR)/arm-m/vectab.c
270
271GLOBAL_INCLUDES += \
272 $(LOCAL_DIR)/arm-m/CMSIS/Include
273
274# we're building for small binaries
275GLOBAL_DEFINES += \
276 ARM_ONLY_THUMB=1 \
277 ARCH_DEFAULT_STACK_SIZE=1024 \
278 SMP_MAX_CPUS=1
279
280ARCH_OPTFLAGS := -Os
281WITH_LINKER_GC ?= 1
282endif
283
284# try to find toolchain
285include $(LOCAL_DIR)/toolchain.mk
286TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX)
287$(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
288
289ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
290
291
292# set the max page size to something more reasonables (defaults to 64K or above)
293GLOBAL_LDFLAGS += -z max-page-size=4096
294
295$(info GLOBAL_COMPILEFLAGS = $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(THUMBCFLAGS))
296
297# make sure some bits were set up
298MEMVARS_SET := 0
299ifneq ($(MEMBASE),)
300MEMVARS_SET := 1
301endif
302ifneq ($(MEMSIZE),)
303MEMVARS_SET := 1
304endif
305ifeq ($(MEMVARS_SET),0)
306$(error missing MEMBASE or MEMSIZE variable, please set in target rules.mk)
307endif
308
309GLOBAL_DEFINES += \
310 MEMBASE=$(MEMBASE) \
311 MEMSIZE=$(MEMSIZE)
312
313# potentially generated files that should be cleaned out with clean make rule
314GENERATED += \
315 $(BUILDDIR)/system-onesegment.ld \
316 $(BUILDDIR)/system-twosegment.ld
317
318# rules for generating the linker scripts
319$(BUILDDIR)/system-onesegment.ld: $(LOCAL_DIR)/system-onesegment.ld $(wildcard arch/*.ld) linkerscript.phony
320 @echo generating $@
321 @$(MKDIR)
322 $(NOECHO)sed "s/%MEMBASE%/$(MEMBASE)/;s/%MEMSIZE%/$(MEMSIZE)/;s/%KERNEL_BASE%/$(KERNEL_BASE)/;s/%KERNEL_LOAD_OFFSET%/$(KERNEL_LOAD_OFFSET)/" < $< > $@.tmp
323 @$(call TESTANDREPLACEFILE,$@.tmp,$@)
324
325$(BUILDDIR)/system-twosegment.ld: $(LOCAL_DIR)/system-twosegment.ld $(wildcard arch/*.ld) linkerscript.phony
326 @echo generating $@
327 @$(MKDIR)
328 $(NOECHO)sed "s/%ROMBASE%/$(ROMBASE)/;s/%MEMBASE%/$(MEMBASE)/;s/%MEMSIZE%/$(MEMSIZE)/" < $< > $@.tmp
329 @$(call TESTANDREPLACEFILE,$@.tmp,$@)
330
331linkerscript.phony:
332.PHONY: linkerscript.phony
333
334# arm specific script to try to guess stack usage
335$(OUTELF).stack: LOCAL_DIR:=$(LOCAL_DIR)
336$(OUTELF).stack: $(OUTELF)
337 $(NOECHO)echo generating stack usage $@
338 $(NOECHO)$(OBJDUMP) -Mreg-names-raw -d $< | $(LOCAL_DIR)/stackusage | $(CPPFILT) | sort -n -k 1 -r > $@
339
340EXTRA_BUILDDEPS += $(OUTELF).stack
341GENERATED += $(OUTELF).stack
342
343include make/module.mk