Re: quick question on 64-bit values with 32-bit inline assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 22 Jan 2008, Ralf Baechle wrote:
> On Mon, Jan 21, 2008 at 12:09:37PM -0600, Chris Friesen wrote:
> > We're running a 64-bit kernel and 32-bit userspace.  We've got some code 
> > that is trying to get a 64-bit timestamp in userspace.
> >
> > The following code seems to work fine in the kernel but in userspace it 
> > appears to be swapping the two words in the result.
> >
> > gethrtime(void)
> > {
> >    unsigned long long result;
> >
> >    asm volatile ("rdhwr %0,$31" : "=r" (result));
> 
> Ah, Cavium.
> 
> >    return result;
> > }
> >
> > Do I need to do something special because userspace is 32-bit?  If so, can 
> > someone point me to a reference?
> 
> Ouch.  You found a nasty special case.  Normally 32-bit userspace should
> not use 64-bit values but since you're running a 64-bit kernel.
> 
> unsigned long long gethrtime(void)
> {
> 	unsigned long result;
        ^^^^^^^^^^^^^
	unsigned long long

> 	asm volatile(
> 	"	.set	mips64r2		\n"
> 	"	rdhwr	%M0, $31		\n"
> 	"	sll	%L0, %M0, 0		\n"
> 	"	dsra	%M0, 32			\n"
> 	"	.set	mips0			\n"
> 	: "=r" (result));
> 
> 	return result;
> }
> 
> Note this wouldn't possibly work on a 32-bit kernel because 32-bit kernels
> will corrupt the upper 32-bit of integer registers so you might lose the
> result value before you can stash it away.  Also 32-bit kernels don't allow
> the execution of 64-bit instructions, not even on 64-bit processors.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux