From f5227e28d3d2470debaf0ce85a9ad07821ee8a46 Mon Sep 17 00:00:00 2001
From: Harry Chen <i@harrychen.xyz>
Date: Sat, 6 Apr 2019 00:55:08 +0800
Subject: [PATCH 1/2] Fix register naming in backtrace

Signed-off-by: Harry Chen <i@harrychen.xyz>
---
 kernel/src/arch/mipsel/context.rs | 11 +++++------
 kernel/src/backtrace.rs           |  4 ++--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/kernel/src/arch/mipsel/context.rs b/kernel/src/arch/mipsel/context.rs
index 1a53b7d..372a186 100644
--- a/kernel/src/arch/mipsel/context.rs
+++ b/kernel/src/arch/mipsel/context.rs
@@ -156,14 +156,13 @@ impl Context {
     /// Push all callee-saved registers at the current kernel stack.
     /// Store current sp, switch to target.
     /// Pop all callee-saved registers, then return to the target.
-    #[naked]
-    #[inline(never)]
-    pub unsafe extern fn switch(&mut self, _target: &mut Self) {
-        extern {
-            fn switch_context(src : &mut Context, dst : &mut Context);
+    #[inline(always)]
+    pub unsafe fn switch(&mut self, target: &mut Self) {
+        extern "C" {
+            fn switch_context(src: *mut Context, dst: *mut Context);
         }
 
-        switch_context(self, _target);
+        switch_context(self as *mut Context, target as *mut Context);
     }
 
     /// Constructs a null Context for the current running thread.
diff --git a/kernel/src/backtrace.rs b/kernel/src/backtrace.rs
index 5d84f7f..af1b045 100644
--- a/kernel/src/backtrace.rs
+++ b/kernel/src/backtrace.rs
@@ -25,7 +25,7 @@ pub fn fp() -> usize {
     #[cfg(any(target_arch = "mips"))]
     unsafe {
         // fp = $30
-        asm!("ori $0, $$$30, 0" : "=r"(ptr));
+        asm!("ori $0, $$30, 0" : "=r"(ptr));
     }
 
     ptr
@@ -51,7 +51,7 @@ pub fn lr() -> usize {
 
     #[cfg(target_arch = "mips")]
     unsafe {
-        asm!("ori $0, $$$31, 0" : "=r"(ptr));
+        asm!("ori $0, $$31, 0" : "=r"(ptr));
     }
 
     ptr

From 06f7b1643d833ba83373bd076ca1d37b9de02383 Mon Sep 17 00:00:00 2001
From: Harry Chen <i@harrychen.xyz>
Date: Sat, 6 Apr 2019 00:58:32 +0800
Subject: [PATCH 2/2] Fix makefile options for mipsel

Signed-off-by: Harry Chen <i@harrychen.xyz>
---
 kernel/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/Makefile b/kernel/Makefile
index 182f78f..b156828 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -295,7 +295,7 @@ else ifeq ($(arch), aarch64)
 else ifeq ($(arch), mipsel)
 	# qemu-system-mipsel accepts ELF file only, so don't use objcopy
 	@cp $(kernel) $(kernel)_orig
-	@$(strip) $(kernel) -o $(kernel)
+	@$(strip) $(kernel) -o $@
 endif
 
 kernel: $(dtb)