Skip to content

Commit

Permalink
G4MH: Fix IRQ context switch on g4mh
Browse files Browse the repository at this point in the history
During the IRQ context switch the SP of the calling task was not correctly updated in the kernel strucutres.
Fix the issue an make the code more readable.
  • Loading branch information
fsylvestre committed Nov 30, 2023
1 parent da75f97 commit 33c9a3b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions machines/rh850/tpl_irq_handler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ __irq_handler:
pushsp r21, r31

; Save the current context.
mov TPL_KERN_OFFSET_S_RUNNING, r10
movhi HIGHW1(#_tpl_kern), r10, r11 ; get pointer to the descriptor of the running task
ld.w LOWW(#_tpl_kern)[r11], r10

st.w r3, [r10] ; save running task sp
mov #_tpl_kern, r10
addi TPL_KERN_OFFSET_S_RUNNING, r10, r11 ; get pointer to the descriptor of the running task
ld.w [r11], r10 ; get pointer to the running task context
ld.w [r10], r11
st.w r3, [r11] ; save running task sp

; Switch back to kernel stack
mov r4, r3
Expand All @@ -79,12 +79,11 @@ __irq_handler:
jarl _tpl_run_elected, r31

; Update the current context according to SP given by the OS
mov TPL_KERN_OFFSET_S_RUNNING, r10
movhi HIGHW1(#_tpl_kern), r10, r11 ; Get pointer to the descriptor of the new running task
ld.w LOWW(#_tpl_kern)[r11], r10

ld.w [r10], r11 ; Get SP of elected task
ld.w [r11], r3
mov #_tpl_kern, r10
addi TPL_KERN_OFFSET_S_RUNNING, r10, r11 ; get pointer to the descriptor of the running task
ld.w [r11], r10 ; Get SP of elected task
ld.w [r10], r11
ld.w [r11], r3 ; load running task sp

; epilogue
popsp r21, r31
Expand Down

0 comments on commit 33c9a3b

Please sign in to comment.