Lean Sheng Tan submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Patrick Rudolph: Looks good to me, approved
arch/x86/c_start.S: Add proper x86_64 code

Don't truncate upper bits in assembly code and thus allow loading
of ramstage above 4GiB.

Tested on qemu with cbmem_top set to TOUUD.

Change-Id: Ifc9b45f69d0b7534b2faacaad0d099cef2667478
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Co-authored-by: Benjamin Doron <benjamin.doron@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/59874
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
M src/arch/x86/c_start.S
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/arch/x86/c_start.S b/src/arch/x86/c_start.S
index 02ddf75..6bea8db 100644
--- a/src/arch/x86/c_start.S
+++ b/src/arch/x86/c_start.S
@@ -59,6 +59,24 @@
leal _stack, %edi
#endif

+#if ENV_X86_64
+ /** poison the stack. Code should not count on the
+ * stack being full of zeros. This stack poisoning
+ * recently uncovered a bug in the broadcast SIPI
+ * code.
+ */
+ movabs $_estack, %rcx
+ sub %rdi, %rcx
+ shr $3, %rcx /* it is 64 bit aligned, right? */
+ movq $0xDEADBEEFDEADBEEF, %rax
+ rep
+ stosq
+
+ /* Set new stack with enforced alignment. */
+ movabs $_estack, %rsp
+ movq $(0xfffffffffffffff0), %rax
+ and %rax, %rsp
+#else
/** poison the stack. Code should not count on the
* stack being full of zeros. This stack poisoning
* recently uncovered a bug in the broadcast SIPI
@@ -74,6 +92,7 @@
/* Set new stack with enforced alignment. */
movl $_estack, %esp
andl $(0xfffffff0), %esp
+#endif

/*
* Now we are finished. Memory is up, data is copied and
@@ -82,7 +101,12 @@
*/
post_code(POSTCODE_PRE_HARDWAREMAIN) /* post 6e */

+#if ENV_X86_64
+ movq $0xFFFFFFFFFFFFFFF0, %rax
+ and %rax, %rsp
+#else
andl $0xFFFFFFF0, %esp
+#endif

#if CONFIG(ASAN_IN_RAMSTAGE)
call asan_init

To view, visit change 59874. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: Ifc9b45f69d0b7534b2faacaad0d099cef2667478
Gerrit-Change-Number: 59874
Gerrit-PatchSet: 7
Gerrit-Owner: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: Jérémy Compostella <jeremy.compostella@intel.com>
Gerrit-Reviewer: Lean Sheng Tan <sheng.tan@9elements.com>
Gerrit-Reviewer: Martin L Roth <gaumless@gmail.com>
Gerrit-Reviewer: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Benjamin Doron <benjamin.doron00@gmail.com>
Gerrit-CC: Felix Singer <service+coreboot-gerrit@felixsinger.de>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-CC: Stefan Reinauer <stefan.reinauer@coreboot.org>
Gerrit-CC: Tim Wawrzynczak <inforichland@gmail.com>
Gerrit-MessageType: merged