Files
lk/arch/arm64/rules.mk
Travis Geiselbrecht e47183725d [arch][arm64] move secondary cpu entry point to separate function
- Make the secondary entry point be logically separate function, though
  declared in the same file.
- Add a trick where the kernel base + 4 is the secondary entry point.
  Not really useful except makes it easy to compute the offset
  elsewhere.
- Changed the entry point to arm64_reset and move _start to the linker
  script, which is what most other arches do.
- While was in the linker script, make sure the text segment is aligned
  on MAXPAGESIZE, though doesn't make any real difference currently.
- Generally clean up the assembly in start.S with newer macros from
  Fuchsia, and avoid using ldr X, =value as much as possible.
- Fix and make sure arm64 can build and run with WITH_SMP set to false.
  Add a new no-smp project to test this.

Note this will likely break systems where all of the cpus enter the
kernel simultaneously, which we can fix if that becomes an issue.
Secondary code now completely assumes the cpu number is passed in x0.
This can be emulated with platform specific trampoline code if it needs
to that then just directs into the the secondary entry point, instead of
trying to make the arch code have to deal with all cases.
2025-10-12 19:47:33 -07:00

141 lines
3.8 KiB
Makefile

LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
GLOBAL_DEFINES += \
ARM64_CPU_$(ARM_CPU)=1 \
ARM_ISA_ARMV8=1 \
IS_64BIT=1
MODULE_SRCS += \
$(LOCAL_DIR)/arch.c \
$(LOCAL_DIR)/asm.S \
$(LOCAL_DIR)/cache-ops.S \
$(LOCAL_DIR)/exceptions.S \
$(LOCAL_DIR)/exceptions_c.c \
$(LOCAL_DIR)/fpu.c \
$(LOCAL_DIR)/spinlock.S \
$(LOCAL_DIR)/start.S \
$(LOCAL_DIR)/thread.c \
$(LOCAL_DIR)/mp.c \
# if its requested we build with SMP, default to 8 cpus
ifeq (true,$(call TOBOOL,$(WITH_SMP)))
SMP_MAX_CPUS ?= 8
GLOBAL_DEFINES += \
WITH_SMP=1 \
SMP_MAX_CPUS=$(SMP_MAX_CPUS)
else
GLOBAL_DEFINES += \
SMP_MAX_CPUS=1
endif
ARCH_OPTFLAGS := -O2
# we have a mmu and want the vmm/pmm
WITH_KERNEL_VM ?= 1
ifeq (true,$(call TOBOOL,$(WITH_KERNEL_VM)))
MODULE_SRCS += \
$(LOCAL_DIR)/mmu.c
ARM64_PAGE_SIZE ?= 4096
# platform/target/project is allowed to override the page size the kernel
# and user space will run at.
ifeq ($(ARM64_PAGE_SIZE), 4096)
# 48 bits of kernel and user address space (4 levels of page tables)
KERNEL_ASPACE_BASE ?= 0xffff000000000000
KERNEL_ASPACE_SIZE ?= 0x0001000000000000
USER_ASPACE_BASE ?= 0x0000000001000000
USER_ASPACE_SIZE ?= 0x0000fffffe000000
else ifeq ($(ARM64_PAGE_SIZE), 16384)
# 47 bits of kernel and user address space (3 levels of page tables)
GLOBAL_DEFINES += ARM64_LARGE_PAGESIZE_16K=1
KERNEL_ASPACE_BASE ?= 0xffff800000000000
KERNEL_ASPACE_SIZE ?= 0x0000800000000000
USER_ASPACE_BASE ?= 0x0000000001000000
USER_ASPACE_SIZE ?= 0x00007ffffe000000
else ifeq ($(ARM64_PAGE_SIZE), 65536)
# 42 bits of kernel and user address space (2 levels of page tables)
GLOBAL_DEFINES += ARM64_LARGE_PAGESIZE_64K=1
KERNEL_ASPACE_BASE ?= 0xfffffc0000000000
KERNEL_ASPACE_SIZE ?= 0x0000040000000000
USER_ASPACE_BASE ?= 0x0000000001000000
USER_ASPACE_SIZE ?= 0x000003fffe000000
else
$(error unsupported ARM64_PAGE_SIZE)
endif
GLOBAL_DEFINES += \
KERNEL_ASPACE_BASE=$(KERNEL_ASPACE_BASE) \
KERNEL_ASPACE_SIZE=$(KERNEL_ASPACE_SIZE) \
USER_ASPACE_BASE=$(USER_ASPACE_BASE) \
USER_ASPACE_SIZE=$(USER_ASPACE_SIZE) \
ARCH_HAS_MMU=1
KERNEL_BASE ?= $(KERNEL_ASPACE_BASE)
KERNEL_LOAD_OFFSET ?= 0
else # !WITH_KERNEL_VM
KERNEL_BASE ?= $(MEMBASE)
KERNEL_LOAD_OFFSET ?= 0
endif
GLOBAL_DEFINES += \
KERNEL_BASE=$(KERNEL_BASE) \
KERNEL_LOAD_OFFSET=$(KERNEL_LOAD_OFFSET)
GLOBAL_DEFINES += \
MEMBASE=$(MEMBASE) \
MEMSIZE=$(MEMSIZE)
# try to find the toolchain
include $(LOCAL_DIR)/toolchain.mk
TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX)
ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
ARCH_COMPILEFLAGS += -ffixed-x18
ARCH_COMPILEFLAGS += -fno-omit-frame-pointer
ARCH_COMPILEFLAGS_NOFLOAT := -mgeneral-regs-only
ARCH_COMPILEFLAGS_FLOAT :=
ARCH_LDFLAGS += -z max-page-size=$(ARM64_PAGE_SIZE)
# Note: assumes the use of gcc and the user is not overriding CC which is set later in engine.mk
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
# make sure some bits were set up
MEMVARS_SET := 0
ifneq ($(MEMBASE),)
MEMVARS_SET := 1
endif
ifneq ($(MEMSIZE),)
MEMVARS_SET := 1
endif
ifeq ($(MEMVARS_SET),0)
$(error missing MEMBASE or MEMSIZE variable, please set in target rules.mk)
endif
# potentially generated files that should be cleaned out with clean make rule
GENERATED += \
$(BUILDDIR)/system-onesegment.ld
# rules for generating the linker script
$(BUILDDIR)/system-onesegment.ld: $(LOCAL_DIR)/system-onesegment.ld $(wildcard arch/*.ld) linkerscript.phony
@echo generating $@
@$(MKDIR)
$(NOECHO)sed "s/%MEMBASE%/$(MEMBASE)/;s/%MEMSIZE%/$(MEMSIZE)/;s/%KERNEL_BASE%/$(KERNEL_BASE)/;s/%KERNEL_LOAD_OFFSET%/$(KERNEL_LOAD_OFFSET)/" < $< > $@.tmp
@$(call TESTANDREPLACEFILE,$@.tmp,$@)
linkerscript.phony:
.PHONY: linkerscript.phony
MODULE_OPTIONS := extra_warnings
include make/module.mk