Subject: Re: rdmsr() function
To: Rui Paulo <phlox-netbsd-i386@fnop.net>
From: Jason Thorpe <thorpej@shagadelic.org>
List: port-i386
Date: 09/22/2004 14:35:36
--Apple-Mail-29--529864477
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed


On Sep 22, 2004, at 1:45 PM, Rui Paulo wrote:

> +static __inline u_int64_t
> +rdmsr64(u_int msr)
> +{
> +	u_int64_t rv;
> +	u_int32_t regs[2];
> +
> +	__asm __volatile("rdmsr" : "=A" (regs[0]), "=D" (regs[1]) : "c" 
> (msr));
> +	rv = ((u_int64_t) regs[1] << 32) + regs[0];

I'd use | rather than + here.

> +
> +	return (rv);
> +
> +}
> +
>  static __inline void
>  wrmsr(u_int msr, u_int64_t newval)
>  {
> @@ -252,6 +265,17 @@
>  }
>
>  static __inline void
> +wrmsr64(u_int msr, u_int64_t newval)
> +{
> +	u_int32_t regs[2];
> +	
> +	regs[0] = (u_int32_t) (newval >> 32);
> +	regs[1] = (u_int32_t) newval;
> +	
> +	__asm __volatile("wrmsr" : : "A" (regs[0]), "D" (regs[1]), "c" 
> (msr));

There's no need for regs[] in this one.  Write the asm statement like:

	__asm __volatile("wrmsr" : : "A" (newval >> 32), "D" (newval & 
0xffffffff), "c" (msr));

> +}
> +
> +static __inline void
>  wbinvd(void)
>  {
>  	__asm __volatile("wbinvd");
>
> -- 
> Rui Paulo                          "Simplicity is the ultimate 
> sophistication."
>                                       -- Leonardo da Vinci
>
         -- Jason R. Thorpe <thorpej@wasabisystems.com>


--Apple-Mail-29--529864477
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFBUfAnOpVKkaBm8XkRAuQsAKCoeNovA8L2Vn6eEeeX5Y8KbMtFDACdFQ7z
zbA7wHXUcBrqrlqwRr6icx0=
=/+Pt
-----END PGP SIGNATURE-----

--Apple-Mail-29--529864477--