This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 93803cf17503a6b818300f0eb721c2a379f7c202
Author: raiden00pl <[email protected]>
AuthorDate: Tue Sep 1 11:34:33 2026 +0200

    arch/intel64: start IDLE stacks below the register save area
    
    The initial IDLE RSP was placed inside the IDLE register save area that
    up_initial_state() later carves out of the stack top, so the idle thread
    ran on its own saved context and corrupted it, causing a #GP/#PF panic
    under interrupt load.  Compute the save area position exactly and start
    RSP below it.
    
    Assisted-by: Claude Code
    Signed-off-by: raiden00pl <[email protected]>
---
 arch/x86_64/src/intel64/intel64_head.S | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86_64/src/intel64/intel64_head.S 
b/arch/x86_64/src/intel64/intel64_head.S
index abccf511bb0..0403f7ccd95 100644
--- a/arch/x86_64/src/intel64/intel64_head.S
+++ b/arch/x86_64/src/intel64/intel64_head.S
@@ -388,8 +388,11 @@ start64:
        movabs  $g_idle_topstack,    %rbx
        mov     (%rbx),   %rsp
 
-       /* Allocate space XCPTCONTEXT */
+       /* Start RSP below the IDLE register save area which up_initial_state()
+        * places at ALIGN_DOWN(topstack - XCPTCONTEXT_SIZE).
+        */
        leaq    -XCPTCONTEXT_SIZE(%rsp), %rsp
+       and     $(~(XCPTCONTEXT_ALIGN - 1)), %rsp
 
        /* Set bsp_done flag */
        movl     $1, bsp_done
@@ -416,8 +419,11 @@ ap_start:
        imulq   $CONFIG_IDLETHREAD_STACKSIZE, %rax, %rax
        add     %rax, %rsp
 
-       /* Move initial RSP below IDLE TCB regs */
-       sub     $XCPTCONTEXT_SIZE, %rsp
+       /* Start RSP below the IDLE register save area which up_initial_state()
+        * places at ALIGN_DOWN(topstack - 8 - XCPTCONTEXT_SIZE) for AP CPUs
+        * (up_cpu_idlestack() adjusts the stack size by 8).
+        */
+       sub     $(XCPTCONTEXT_SIZE + 8), %rsp
        and     $(~(XCPTCONTEXT_ALIGN - 1)), %rsp
 
        /* Jump to ap_start routine */

Reply via email to