Skip to content

Commit 8e627a9

Browse files
committed
Fix FPU stack order issue and Improve FPU checking flow
1 parent 8225a7f commit 8e627a9

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

portable/CCRH/F1Kx/portasm.s

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ portSAVE_CONTEXT .macro
8484
stsr FPEPC, r19
8585
pushsp r18, r19
8686

87+
pushsp r14, r15
88+
8789
; Get current TCB, the return value is stored in r10 (CCRH compiler)
8890
jarl _pvPortGetCurrentTCB, lp
8991
st.w sp, 0[r10]
@@ -101,14 +103,13 @@ portRESTORE_CONTEXT .macro
101103

102104
; Restore FPU registers if FPU is enabled
103105
mov FPU_MSK, r19
104-
stsr PSW, r18
105-
tst r18, r19
106-
107-
; Jump over next 3 instructions: stsr (4 bytes)*2 + popsp (4 bytes)
106+
popsp r14, r15
107+
tst r15, r19
108+
; Jump over next 3 instructions: stsr (4 bytes)*2 + popsp (4 bytes)
108109
bz 12
109110
popsp r18, r19
110-
ldsr r18, FPEPC
111-
ldsr r19, FPSR
111+
ldsr r19, FPEPC
112+
ldsr r18, FPSR
112113

113114
;Restore general-purpose registers and EIPSW, EIPC, EIIC, CTPSW, CTPC
114115
popsp r15, r19
@@ -146,30 +147,30 @@ SAVE_REGISTER .macro
146147
mov ep, r15
147148
stsr CTPSW, r14
148149
stsr CTPC, r13
149-
pushsp r13, r19
150+
pushsp r13, r18
150151

151152
mov FPU_MSK, r16
152153
tst r16, r19
153-
bz 12
154-
stsr FPSR, r18
155-
stsr FPEPC, r19
156-
pushsp r18, r19
154+
bz 8
155+
stsr FPSR, r17
156+
stsr FPEPC, r18
157+
158+
pushsp r17, r19
157159

158160
.endm
159161
;------------------------------------------------------------------------------
160162
; Restore used registers
161163
;------------------------------------------------------------------------------
162164
RESTORE_REGISTER .macro
163165

164-
mov FPU_MSK, r16
165-
stsr PSW, r18
166-
tst r18, r19
167-
bz 12
168-
popsp r18, r19
166+
mov FPU_MSK, r15
167+
popsp r17, r19
168+
tst r19, r15
169+
bz 8
169170
ldsr r18, FPEPC
170-
ldsr r19, FPSR
171+
ldsr r17, FPSR
171172

172-
popsp r13, r19
173+
popsp r13, r18
173174
ldsr r13, CTPC
174175
ldsr r14, CTPSW
175176
mov r15, ep

0 commit comments

Comments
 (0)