[NSWI004] Bug report

Jura Pelc jirik.pelc1998 at gmail.com
Wed Dec 16 00:50:39 CET 2020


Hello,

after nontrivial time spent scanning your assembly code, I figured out that
during a context switch the entryHi register is not loaded nor stored in
contexts.
With your implementation of context.S, tests were failing, caused by
thread_kill call in global_exception_handler because memory was access with
an ASID unset.

I coincide it as a bug since context switch should preserve the entire
context_t structure but entryHi nor CONTEXT_CP0_ENTRYHI_OFFSET was not used
anywhere in SAVE_REGISTERS nor LOAD_REGISTERS.

I made the following changes, I want someone to concur with my findings.
```
diff --git a/kernel/src/proc/context.S b/kernel/src/proc/context.S
index 3da3a0c..a43ddef 100644
--- a/kernel/src/proc/context.S
+++ b/kernel/src/proc/context.S
@@ -42,6 +42,8 @@ cpu_switch_context:
     mflo $t1
     sw $t0, CONTEXT_HI_OFFSET($a0)
     sw $t1, CONTEXT_LO_OFFSET($a0)
+    mfc0 $t0, $10
+    sw $t0, CONTEXT_CP0_ENTRYHI_OFFSET($a0)

     /*
      * Save the CP0 Status register and disable interrupts (by
@@ -71,6 +73,8 @@ cpu_switch_context:
     lw $t1, CONTEXT_LO_OFFSET($a1)
     mthi $t0
     mtlo $t1
+    lw $t0, CONTEXT_CP0_ENTRYHI_OFFSET($a1)
+    mtc0 $t0, $10

     move $k0, $a1
     LOAD_REGISTERS $k0
```


-- 
S pozdravem Jiří Pelc
Matematicko-fyzikální fakulta
Univerzita Karlova
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://d3s.mff.cuni.cz/pipermail/nswi004/attachments/20201216/0e44bc42/attachment.htm>


More information about the NSWI004 mailing list