[rtems commit] sparc: Fix missed restoring of PSR in syscall_lazy_fp_switch

Sebastian Huber sebh at rtems.org
Thu Jun 6 06:41:34 UTC 2019


Module:    rtems
Branch:    master
Commit:    a38187051863cf4a423c4f00669c6786bc8ff60d
Changeset: http://git.rtems.org/rtems/commit/?id=a38187051863cf4a423c4f00669c6786bc8ff60d

Author:    Maksim E. Kozlov <maksim.e.kozlov at gmail.com>
Date:      Wed Jun  5 22:22:36 2019 +0300

sparc: Fix missed restoring of PSR in syscall_lazy_fp_switch

It is needed to restore PSR just before return because condition
codes are dirty after the CMP instructions and this may cause
undefined program behavior after returning from the switching
procedure (on following branch instruction, for example).

Close #3756.

---

 cpukit/score/cpu/sparc/syscall.S | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/cpukit/score/cpu/sparc/syscall.S b/cpukit/score/cpu/sparc/syscall.S
index 603ed7a..4f4ef32 100644
--- a/cpukit/score/cpu/sparc/syscall.S
+++ b/cpukit/score/cpu/sparc/syscall.S
@@ -241,12 +241,23 @@ SYM(syscall_lazy_fp_switch):
 
 .Lfp_restore_done:
 
+	/*
+	 * Restore condition codes.  PSR[EF] is 1 here.  Take PSR write delay
+	 * into account (maximum is three instructions).
+	 */
+	mov	%l0, %psr
+	nop
+
 	/* Now, retry the floating point instruction with PSR[EF] == 1 */
 	jmp	%l1
 	 rett	%l2
 
 .Lillegal_use_of_floating_point_unit:
 
+	/*
+	 * There is no need to restore the condition codes here, since
+	 * _Internal_error() does not return.
+	 */
 	sethi	%hi(_Internal_error), %l1
 	or	%l1, %lo(_Internal_error), %l1
 	mov	38, %i0



More information about the vc mailing list