rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | LOCAL_DIR := $(GET_LOCAL_DIR) |
| 2 | |
| 3 | MODULE := $(LOCAL_DIR) |
| 4 | |
| 5 | # can override this in local.mk |
| 6 | ENABLE_THUMB?=true |
| 7 | |
| 8 | # default to the regular arm subarch |
| 9 | SUBARCH := arm |
| 10 | |
| 11 | GLOBAL_DEFINES += \ |
| 12 | ARM_CPU_$(ARM_CPU)=1 |
| 13 | |
| 14 | # do set some options based on the cpu core |
| 15 | HANDLED_CORE := false |
| 16 | ifeq ($(ARM_CPU),cortex-m0) |
| 17 | GLOBAL_DEFINES += \ |
| 18 | ARM_CPU_CORTEX_M0=1 \ |
| 19 | ARM_ISA_ARMV6M=1 \ |
| 20 | ARM_WITH_THUMB=1 |
| 21 | HANDLED_CORE := true |
| 22 | ENABLE_THUMB := true |
| 23 | SUBARCH := arm-m |
| 24 | endif |
| 25 | ifeq ($(ARM_CPU),cortex-m0plus) |
| 26 | GLOBAL_DEFINES += \ |
| 27 | ARM_CPU_CORTEX_M0_PLUS=1 \ |
| 28 | ARM_ISA_ARMV6M=1 \ |
| 29 | ARM_WITH_THUMB=1 |
| 30 | HANDLED_CORE := true |
| 31 | ENABLE_THUMB := true |
| 32 | SUBARCH := arm-m |
| 33 | endif |
| 34 | ifeq ($(ARM_CPU),cortex-m3) |
| 35 | GLOBAL_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 |
| 41 | HANDLED_CORE := true |
| 42 | ENABLE_THUMB := true |
| 43 | SUBARCH := arm-m |
| 44 | endif |
| 45 | ifeq ($(ARM_CPU),cortex-m4) |
| 46 | GLOBAL_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 |
| 52 | HANDLED_CORE := true |
| 53 | ENABLE_THUMB := true |
| 54 | SUBARCH := arm-m |
| 55 | endif |
| 56 | ifeq ($(ARM_CPU),cortex-m4f) |
| 57 | GLOBAL_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 |
| 66 | HANDLED_CORE := true |
| 67 | ENABLE_THUMB := true |
| 68 | SUBARCH := arm-m |
| 69 | endif |
| 70 | ifeq ($(ARM_CPU),cortex-m7) |
| 71 | GLOBAL_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 |
| 78 | HANDLED_CORE := true |
| 79 | ENABLE_THUMB := true |
| 80 | SUBARCH := arm-m |
| 81 | endif |
| 82 | ifeq ($(ARM_CPU),cortex-a7) |
| 83 | GLOBAL_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 |
| 93 | HANDLED_CORE := true |
| 94 | endif |
| 95 | ifeq ($(ARM_CPU),cortex-a15) |
| 96 | GLOBAL_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 |
| 105 | ifneq ($(ARM_WITHOUT_VFP_NEON),true) |
| 106 | GLOBAL_DEFINES += \ |
| 107 | ARM_WITH_VFP=1 \ |
| 108 | ARM_WITH_NEON=1 |
| 109 | endif |
| 110 | HANDLED_CORE := true |
| 111 | endif |
| 112 | ifeq ($(ARM_CPU),cortex-a8) |
| 113 | GLOBAL_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 |
| 124 | HANDLED_CORE := true |
| 125 | endif |
| 126 | ifeq ($(ARM_CPU),cortex-a9) |
| 127 | GLOBAL_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 |
| 135 | HANDLED_CORE := true |
| 136 | endif |
| 137 | ifeq ($(ARM_CPU),cortex-a9-neon) |
| 138 | GLOBAL_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 |
| 149 | HANDLED_CORE := true |
| 150 | endif |
| 151 | ifeq ($(ARM_CPU),arm1136j-s) |
| 152 | GLOBAL_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 |
| 159 | HANDLED_CORE := true |
| 160 | endif |
| 161 | ifeq ($(ARM_CPU),arm1176jzf-s) |
| 162 | GLOBAL_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 |
| 170 | HANDLED_CORE := true |
| 171 | endif |
| 172 | ifeq ($(ARM_CPU),armemu) |
| 173 | # flavor of emulated cpu by the armemu project |
| 174 | GLOBAL_DEFINES += \ |
| 175 | ARM_WITH_CP15=1 \ |
| 176 | ARM_ISA_ARMv7=1 \ |
| 177 | ARM_ISA_ARMv7A=1 \ |
| 178 | ARM_WITH_CACHE=1 |
| 179 | HANDLED_CORE := true |
| 180 | ENABLE_THUMB := false # armemu doesn't currently support thumb properly |
| 181 | endif |
| 182 | |
| 183 | ifneq ($(HANDLED_CORE),true) |
| 184 | $(error $(LOCAL_DIR)/rules.mk doesnt have logic for arm core $(ARM_CPU)) |
| 185 | endif |
| 186 | |
| 187 | THUMBCFLAGS := |
| 188 | THUMBINTERWORK := |
| 189 | ifeq ($(ENABLE_THUMB),true) |
| 190 | THUMBCFLAGS := -mthumb -D__thumb__ |
| 191 | endif |
| 192 | |
| 193 | GLOBAL_INCLUDES += \ |
| 194 | $(LOCAL_DIR)/$(SUBARCH)/include |
| 195 | |
| 196 | ifeq ($(SUBARCH),arm) |
| 197 | MODULE_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 | |
| 210 | MODULE_ARM_OVERRIDE_SRCS := \ |
| 211 | $(LOCAL_DIR)/arm/arch.c |
| 212 | |
| 213 | GLOBAL_DEFINES += \ |
| 214 | ARCH_DEFAULT_STACK_SIZE=4096 |
| 215 | |
| 216 | ARCH_OPTFLAGS := -O2 |
| 217 | WITH_LINKER_GC ?= 1 |
| 218 | |
| 219 | # we have a mmu and want the vmm/pmm |
| 220 | WITH_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. |
| 225 | GLOBAL_DEFINES += \ |
| 226 | KERNEL_ASPACE_BASE=0x40000000 \ |
| 227 | KERNEL_ASPACE_SIZE=0xc0000000 |
| 228 | |
| 229 | KERNEL_BASE ?= 0x80000000 |
| 230 | KERNEL_LOAD_OFFSET ?= 0 |
| 231 | |
| 232 | GLOBAL_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 |
| 237 | ifeq ($(WITH_SMP),1) |
| 238 | SMP_MAX_CPUS ?= 4 |
| 239 | SMP_CPU_CLUSTER_SHIFT ?= 8 |
| 240 | SMP_CPU_ID_BITS ?= 24 |
| 241 | |
| 242 | GLOBAL_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 | |
| 248 | MODULE_SRCS += \ |
| 249 | $(LOCAL_DIR)/arm/mp.c |
| 250 | else |
| 251 | GLOBAL_DEFINES += \ |
| 252 | SMP_MAX_CPUS=1 |
| 253 | endif |
| 254 | |
| 255 | ifeq (true,$(call TOBOOL,$(WITH_NS_MAPPING))) |
| 256 | GLOBAL_DEFINES += \ |
| 257 | WITH_ARCH_MMU_PICK_SPOT=1 |
| 258 | endif |
| 259 | |
| 260 | endif |
| 261 | ifeq ($(SUBARCH),arm-m) |
| 262 | MODULE_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 | |
| 271 | GLOBAL_INCLUDES += \ |
| 272 | $(LOCAL_DIR)/arm-m/CMSIS/Include |
| 273 | |
| 274 | # we're building for small binaries |
| 275 | GLOBAL_DEFINES += \ |
| 276 | ARM_ONLY_THUMB=1 \ |
| 277 | ARCH_DEFAULT_STACK_SIZE=1024 \ |
| 278 | SMP_MAX_CPUS=1 |
| 279 | |
| 280 | ARCH_OPTFLAGS := -Os |
| 281 | WITH_LINKER_GC ?= 1 |
| 282 | endif |
| 283 | |
| 284 | # try to find toolchain |
| 285 | include $(LOCAL_DIR)/toolchain.mk |
| 286 | TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX) |
| 287 | $(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX)) |
| 288 | |
| 289 | ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS) |
| 290 | |
| 291 | |
| 292 | # set the max page size to something more reasonables (defaults to 64K or above) |
| 293 | GLOBAL_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 |
| 298 | MEMVARS_SET := 0 |
| 299 | ifneq ($(MEMBASE),) |
| 300 | MEMVARS_SET := 1 |
| 301 | endif |
| 302 | ifneq ($(MEMSIZE),) |
| 303 | MEMVARS_SET := 1 |
| 304 | endif |
| 305 | ifeq ($(MEMVARS_SET),0) |
| 306 | $(error missing MEMBASE or MEMSIZE variable, please set in target rules.mk) |
| 307 | endif |
| 308 | |
| 309 | GLOBAL_DEFINES += \ |
| 310 | MEMBASE=$(MEMBASE) \ |
| 311 | MEMSIZE=$(MEMSIZE) |
| 312 | |
| 313 | # potentially generated files that should be cleaned out with clean make rule |
| 314 | GENERATED += \ |
| 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 | |
| 331 | linkerscript.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 | |
| 340 | EXTRA_BUILDDEPS += $(OUTELF).stack |
| 341 | GENERATED += $(OUTELF).stack |
| 342 | |
| 343 | include make/module.mk |