From 1b599a8844928752905be4363df64010fb97a540 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Sat, 6 Dec 2025 19:18:37 +0000 Subject: [PATCH] arch/arm64: Add an alternative entry point for ramstage code This change prepares an alternative entry point for the ARM64 ramstage. It is written in assembly language, avoids the usage of the stack, and overrides the program stack pointer (SP register) if the `preram_stack` and `postram_stack` point to different addresses. Previous Boot Flow: - header.ld -> jump into `stage_entry` C code for ROMSTAGE onwards -> `stage_entry` being called and followed by `main` function Updated Boot Flow: - header.ld -> jump into `_start` (assembly entry point) for ramstage specifically -> Update the existing SP (stack pointer) register if the `preram_` or `postram_` stack address is not same -> call into `stage_entry` and follow the `main` function. BUG=b:456953373 BRANCH=None TEST=Able to build google/bluey. Change-Id: I4eec24aff1c9d01180c3452a3631dd344656c771 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/90403 Reviewed-by: Julius Werner Reviewed-by: Jayvik Desai Reviewed-by: Kapil Porwal Tested-by: build bot (Jenkins) --- src/arch/arm64/armv8/Makefile.mk | 1 + src/arch/arm64/armv8/ramstage_entry.S | 34 +++++++++++++++++++++++++++ src/arch/arm64/include/arch/header.ld | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/arch/arm64/armv8/ramstage_entry.S diff --git a/src/arch/arm64/armv8/Makefile.mk b/src/arch/arm64/armv8/Makefile.mk index 15d80e64e8..85c83d74da 100644 --- a/src/arch/arm64/armv8/Makefile.mk +++ b/src/arch/arm64/armv8/Makefile.mk @@ -73,6 +73,7 @@ endif ################################################################################ ifeq ($(CONFIG_ARCH_RAMSTAGE_ARMV8_64),y) +ramstage-y += ramstage_entry.S ramstage-y += cache.c ramstage-y += cpu.S ramstage-y += exception.c diff --git a/src/arch/arm64/armv8/ramstage_entry.S b/src/arch/arm64/armv8/ramstage_entry.S new file mode 100644 index 0000000000..823b12d13a --- /dev/null +++ b/src/arch/arm64/armv8/ramstage_entry.S @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Ramstage entrypoint code for aarch64 (a.k.a. armv8) + */ + +#include + +ENTRY(_start) + /* + * Note: x0 must be preserved as it contains the CBMEM top pointer + * for the next stage entry. + */ + ldr x10, =_preram_stack + ldr x11, =_postram_stack + + cmp x10, x11 + beq stack_init_done + + /* Initialize stack with sentinel value to later check overflow. */ + ldr x9, =0xdeadbeefdeadbeef + ldr x10, =_epostram_stack +1: + stp x9, x9, [x11], #16 + cmp x11, x10 + bne 1b + + /* Update stack pointer with DRAM mapped stack base */ + /* Leave a line of beef dead for easier visibility in stack dumps. */ + sub sp, x11, #16 + +stack_init_done: + /* Call the C function. */ + bl stage_entry +ENDPROC(_start) diff --git a/src/arch/arm64/include/arch/header.ld b/src/arch/arm64/include/arch/header.ld index c6d48e704f..4590be1f8b 100644 --- a/src/arch/arm64/include/arch/header.ld +++ b/src/arch/arm64/include/arch/header.ld @@ -9,7 +9,7 @@ PHDRS to_load PT_LOAD; } -#if ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_RMODULE +#if ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_RMODULE || ENV_RAMSTAGE ENTRY(_start) #else ENTRY(stage_entry)