Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Nov 1998 16:26:35 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        current@FreeBSD.ORG, dyson@iquest.net
Subject:   Re: Fix for incorrect clobbers in asm's
Message-ID:  <199811280526.QAA22443@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>Specifically, it is totally incorrect to clobber any of the input
>or output operands.  The workaround is to indicate that the clobbered
>registers are output operands, with no subsequent usage.  It might
>be counter-intuitive, but is the suggested solution to the problem.

This is best written using constraints that say that some output
operands are the same as input operands.  There is no other way if
the input operands aren't in fixed registers.

>Index: i386/include/cpufunc.h
>===================================================================
>RCS file: /local/home/ncvs/src/sys/i386/include/cpufunc.h,v
>retrieving revision 1.81
>diff -C1 -r1.81 cpufunc.h
>*** cpufunc.h	1998/08/17 08:57:05	1.81
>--- cpufunc.h	1998/11/28 00:46:45
>***************
>*** 192,196 ****
>  {
>  	__asm __volatile("cld; rep; insb"
>! 			 : : "d" (port), "D" (addr), "c" (cnt)
>! 			 : "di", "cx", "memory");
>  }
>--- 192,198 ----
>  {
>+ 	int ndi, ncx;
>  	__asm __volatile("cld; rep; insb"
>! 			 : "=D"(ndi), "=c"(ncx)
>! 			 : "d" (port), "D" (addr), "c" (cnt)
>! 			 : "memory");
>  }

Rewritten using constraints:

 	__asm __volatile("cld; rep; insb"
 			 : "=D" (addr), "=c" (cnt)
 			 : "0"  (addr), "1"  (cnt), "d" (port)
 			 : "memory");

This discards the output operands in the input variables to avoid extra
local variables.  This is harmless because the input variables are dead,
and more natural because it is normal for pointers to be incremented and
counts to be decremented.

Bruce

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811280526.QAA22443>