Since a thread is supposed to be returned from Switch_context,
this fixes a bug where the thread is always returned as 0x0 on 64b UP,
hence the idle thread was being called too often instead of a chosen thread.
Also, this fixes a potential future bug with 64b SMP where the non-zero
cpu number is returned as a valid thread and causes a crash.

TESTED: By compiling gnumach on hurd-amd64 with
  
  --enable-ncpus=1 --disable-linux-groups --enable-kdb --enable-apic

  and booting hurd-amd64 in UP on qemu.

---
 x86_64/cswitch.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/x86_64/cswitch.S b/x86_64/cswitch.S
index 9c4640fd..a6b390e8 100644
--- a/x86_64/cswitch.S
+++ b/x86_64/cswitch.S
@@ -83,10 +83,10 @@ ENTRY(Switch_context)
        lea     KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%rcx),%rbx
                                                /* point to stack top */
 
-       CPU_NUMBER(%eax)
+       CPU_NUMBER(%edx)                        /* Don't overwrite returned 
value %rax */
        movq    %rsi,MY(ACTIVE_THREAD)          /* new thread is active */
        movq    %rcx,MY(ACTIVE_STACK)           /* set current stack */
-       movq    %rbx,CX(EXT(kernel_stack),%rax) /* set stack top */
+       movq    %rbx,CX(EXT(kernel_stack),%rdx) /* set stack top */
 
        movq    KSS_ESP(%rcx),%rsp              /* switch stacks */
        movq    KSS_EBP(%rcx),%rbp              /* restore registers */
-- 
2.51.0



Reply via email to