From 67ec6c23e7aca70d7a9f6182ce56e687be530d80 Mon Sep 17 00:00:00 2001
From: Robin Randhawa <robin.randhawa@arm.com>
Date: Sun, 17 Jan 2021 10:09:03 +0000
Subject: [PATCH] aarch64: Move tpidr_el0 setup from spawn to switch

---
 src/context/list.rs   | 1 -
 src/context/switch.rs | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/context/list.rs b/src/context/list.rs
index 2e85ae8e..fbc92dbb 100644
--- a/src/context/list.rs
+++ b/src/context/list.rs
@@ -92,7 +92,6 @@ impl ContextList {
             #[cfg(target_arch = "aarch64")]
             {
                 let context_id = context.id.into();
-                context.arch.set_tcb(context_id);
                 context.arch.set_lr(func as usize);
                 context.arch.set_context_handle();
             }
diff --git a/src/context/switch.rs b/src/context/switch.rs
index 2e17b428..634aff32 100644
--- a/src/context/switch.rs
+++ b/src/context/switch.rs
@@ -151,6 +151,11 @@ pub unsafe fn switch() -> bool {
             }
             gdt::set_tcb((*to_ptr).id.into());
         }
+        #[cfg(target_arch = "aarch64")]
+        {
+            let pid = (*to_ptr).id.into();
+            (*to_ptr).arch.set_tcb(pid);
+        }
         CONTEXT_ID.store((*to_ptr).id, Ordering::SeqCst);
     }
 
-- 
GitLab