[PATCH 1/2] sparc: Fix missed restoring of PSR in syscall_lazy_fp_switch

Maksim E. Kozlov maksim.e.kozlov at gmail.com
Wed Jun 5 19:22:36 UTC 2019


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).
---
 cpukit/score/cpu/sparc/syscall.S | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cpukit/score/cpu/sparc/syscall.S b/cpukit/score/cpu/sparc/syscall.S
index 603ed7a738..bfd070a214 100644
--- a/cpukit/score/cpu/sparc/syscall.S
+++ b/cpukit/score/cpu/sparc/syscall.S
@@ -241,12 +241,16 @@ SYM(syscall_lazy_fp_switch):
 
 .Lfp_restore_done:
 
+	mov	%l0, %psr	! Resore condition codes. PSR[EF] is 1 here
+	nop; nop		! PSR write delay
+
 	/* Now, retry the floating point instruction with PSR[EF] == 1 */
 	jmp	%l1
 	 rett	%l2
 
 .Lillegal_use_of_floating_point_unit:
 
+	mov	%l0, %psr  ! Restore condition codes. Write delay 3 instr
 	sethi	%hi(_Internal_error), %l1
 	or	%l1, %lo(_Internal_error), %l1
 	mov	38, %i0
-- 
2.17.1




More information about the devel mailing list