git: 9front

Download patch

ref: 2b0c40e36b698afea304173050b7726be4d57fdd
parent: a49be83bd06ebf3318d3a4ddf16939994f58b634
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu May 7 19:27:27 EDT 2020

bcm64: fix kernels cmpswap() function

spectacular bug. cmpswap() had a sign extension bug
using sign extending MOV to load the old compare
value and LDXRW using zero extension while the CMP
instruction compared 64 bit registers.

this caused cmpswap with negative old value always
to fail.

interestingly, libc's version of this function was
fine.

--- a/sys/src/9/bcm64/l.s
+++ b/sys/src/9/bcm64/l.s
@@ -229,8 +229,8 @@
 
 TEXT cas(SB), 1, $-4
 TEXT cmpswap(SB), 1, $-4
-	MOVW	ov+8(FP), R1
-	MOVW	nv+16(FP), R2
+	MOVWU	ov+8(FP), R1
+	MOVWU	nv+16(FP), R2
 _cas1:
 	LDXRW	(R0), R3
 	CMP	R3, R1
--