You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/05/22 21:44:33 UTC
[mynewt-core] branch master updated: pic32: Fix context switch
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 2170bab pic32: Fix context switch
2170bab is described below
commit 2170bab6210ead74f1dac3bf6093d155cae27ea8
Author: Jerzy Kasenberg <je...@apache.org>
AuthorDate: Sat May 22 21:01:52 2021 +0200
pic32: Fix context switch
At some point task_t was modified and keeps stack
bottom instead of stack top.
t_stacktop -> t_stackbottom
For PIC32 FPU context is stored at the very top of stack
(CPU context is stored at current SP).
Context switch code was not updated and still was
using same storage from task_t that was changed.
Lack of update resulted in writes to random places.
This change computes stack top to restore functionality.
---
kernel/os/src/arch/pic32/asm/ctx.S | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/os/src/arch/pic32/asm/ctx.S b/kernel/os/src/arch/pic32/asm/ctx.S
index 96a9d1a..53043fc 100644
--- a/kernel/os/src/arch/pic32/asm/ctx.S
+++ b/kernel/os/src/arch/pic32/asm/ctx.S
@@ -166,7 +166,8 @@
#define CTX_FP64_REG(r) CTX_FP_OFFS(r)
#define CTX_FP_FCSR CTX_FP_OFFS(32)
-#define TASK_STACK_TOP (4)
+#define TASK_STACK_BOTTOM (4)
+#define TASK_STACK_SIZE (8)
.macro _fpctx_save
sdc1 $f0, CTX_FP_REG(0)(k0)
@@ -243,7 +244,10 @@ _general_exception_context:
# Save FPU context to FPU user
beqz k0, load # if there is an FPU user
- lw k0, TASK_STACK_TOP(k0) # get FPU user stack top
+ lhu k1, TASK_STACK_SIZE(k0) # k1 = stack size in words
+ sll k1, k1, 2 # k1 = stack size in bytes
+ lw k0, TASK_STACK_BOTTOM(k0) # k0 = stack bottom
+ add k0, k1, k0 # k0 = FPU user stack top
_fpctx_save
lw k1, g_current_task # get current task
@@ -252,7 +256,10 @@ load:
beqz k1, return # if there is a current task
la k0, g_fpu_user
sw k1, 0(k0) # set FPU user to current task
- lw k0, TASK_STACK_TOP(k1) # get current task stack top
+ lhu k0, TASK_STACK_SIZE(k1) # k0 = stack size in words
+ sll k0, k0, 2 # k0 = stack size in bytes
+ lw k1, TASK_STACK_BOTTOM(k1) # k1 = stack bottom
+ add k0, k1, k0 # k0 = current task stack top
_fpctx_load
return :