[Etherboot-users] Re: Via RNG xstore in Etherboot
Brought to you by:
marty_connor,
stefanhajnoczi
From: Robert H. <rob...@ya...> - 2006-01-10 23:16:31
|
I've figured it out after paying closer attention to the Via padlock programmers guide! If I set bit 9 on CR4 using the following bit of assembly (from the Linux kernel) it works. Something to do with a dependency on the SSE instructions, according to the docs. static inline void set_in_cr4 (unsigned long mask) { __asm__("movl %%cr4,%%eax\n\t" "orl %0,%%eax\n\t" "movl %%eax,%%cr4\n" : : "irg" (mask) :"ax"); } and call with: set_in_cr4( 0x0200 ); Hope the info is useful to someone! Robert > BTW the processor is a VIA Eden, with Nehemiah core > (stepping 8), and the xstore call works once the > Linux > kernel is up and running - so I know that it can > work... > > --- Robert Hamilton <rob...@ya...> > wrote: > > > Hi all, > > > > OK this question may be a bit obscure, but I hope > > someone might have some insight as to what is > going > > on... > > > > I am trying to call the Via RNG (xstore > instruction) > > from etherboot, and my platform resets every time > I > > call it. > > > > I have copied the xstore asm() code from the > > hw_random.c driver in Linux. I have made sure the > > Via > > MSR 0x110b is set up correctly. I've checked that > > the > > assembler and byte code looks OK (the same as the > > hwrandom driver), but I still get the reset. > > > > Do I have to set something else up on the > processor, > > or call xstore in a different way? > > > > Thanks, > > > > Robert > > > > The following is the code I am using showing the > MSR > > initialization and the xstore call. Though the > first > > read of the MSR indicates that the RNG is enabled > by > > default anyway. It is pretty much a straight copy > > from > > hw_random.c. > > > > #define MSR_VIA_RNG 0x110b > > enum { > > VIA_STRFILT_CNT_SHIFT = 16, > > VIA_STRFILT_FAIL = (1 << 15), > > VIA_STRFILT_ENABLE = (1 << 14), > > VIA_RAWBITS_ENABLE = (1 << 13), > > VIA_RNG_ENABLE = (1 << 6), > > VIA_XSTORE_CNT_MASK = 0x0F, > > > > VIA_RNG_CHUNK_8 = 0x00, /* 64 rand bits, 64 > > stored > > bits */ > > VIA_RNG_CHUNK_4 = 0x01, /* 32 rand bits, 32 > > stored > > bits */ > > VIA_RNG_CHUNK_4_MASK = 0xFFFFFFFF, > > VIA_RNG_CHUNK_2 = 0x02, /* 16 rand bits, 32 > > stored > > bits */ > > VIA_RNG_CHUNK_2_MASK = 0xFFFF, > > VIA_RNG_CHUNK_1 = 0x03, /* 8 rand bits, 32 > > stored > > bits */ > > > > VIA_RNG_CHUNK_1_MASK = 0xFF, > > }; > > > > #define rdmsr(msr,val1,val2) \ > > __asm__ __volatile__("rdmsr" \ > > : "=a" (val1), "=d" (val2) \ > > : "c" (msr)) > > > > #define wrmsr(msr,val1,val2) \ > > __asm__ __volatile__("wrmsr" \ > > : /* no outputs */ \ > > : "c" (msr), "a" (val1), "d" (val2)) > > > > static int via_RNGinit( void ) > > { > > u32 lo, hi, old_lo; > > > > printf( "VIA init\n" ); > > rdmsr(MSR_VIA_RNG, lo, hi); > > printf( "lo = %#x, hi = %#x\n", lo, hi ); > > > > old_lo = lo; > > lo &= ~(0x7f << VIA_STRFILT_CNT_SHIFT); > > lo &= ~VIA_XSTORE_CNT_MASK; > > lo |= (VIA_STRFILT_ENABLE | VIA_STRFILT_FAIL | > > VIA_RAWBITS_ENABLE); > > lo |= VIA_RNG_ENABLE; > > lo |= ( 0x3 << 8 ); > > > > if (lo != old_lo) > > wrmsr(MSR_VIA_RNG, lo, hi); > > > > rdmsr(MSR_VIA_RNG, lo, hi); > > printf( "lo = %#x, hi = %#x\n", lo, hi ); > > if ((lo & VIA_RNG_ENABLE) == 0) { > > printf( "cannot enable VIA C3 RNG, > > aborting\n"); > > return -1; > > } > > > > printf( "Done!\n" ); > > > > return 0; > > } > > > > static inline u32 xstore(u32 *addr, u32 edx_in) > > { > > u32 eax_out; > > > > asm volatile (".byte 0x0f,0xa7,0xc0 /* xstore > > %%edi (addr=%0) */" > > : "=a"(eax_out), "=m"(*addr) > > : "D"(addr), "d"(edx_in)); > > > > return eax_out; > > } > > > > > > > > > > __________________________________________ > > Yahoo! DSL Something to write home about. > > Just $16.99/mo. or less. > > dsl.yahoo.com > > > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam > protection around > http://mail.yahoo.com > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |