# FreeBSD and rdrand()



## san83 (May 19, 2013)

Hello,

I have a server platform Intel R1208GZ4GC and E5-2620 processors. I'm trying to use RDRAND to generate random numbers. To put this code:

```
int _rdrand16_step(unsigned short *therand) {   
 unsigned char err;   
 asm volatile("rdrand %0 ; setc %1"   
 : "=r" (*therand), "=qm" (err));   
 return (int) err;   
  }
```
However, when compiling the error:

```
{standard input}: Assembler messages:  
{standard input}:7191: Error: no such instruction: `rdrand %dx'  
gmake: *** [../../main/main.o] Error 1
```
Operating system: FreeBsd FreeBSD 8.3

Updated files:
stable/8/sys/amd64/amd64/identcpu.c
stable/8/sys/amd64/include/specialreg.h
stable/8/sys/i386/conf/XENHVM
stable/8/sys/i386/i386/identcpu.c
stable/8/sys/i386/include/specialreg.h
http://svnweb.freebsd.org/base?view=revision&revision=240135

I recompiled the kernel and made a restart. But to no avail.

Help me, please.


----------



## Anonymous (May 19, 2013)

The RDRAND instruction is a new instruction available on Ivy Bridge processors. Your E5-2620 are Sandy-Bridge-based Xeon processors, so, seems that you are out of luck with that.


----------



## san83 (May 19, 2013)

Thanks for the reply. That's the first thing I thought. So I asked a question on the Intel forum: http://communities.intel.com/thread/41604. However, I was sent here.


----------



## Anonymous (May 19, 2013)

san83 said:
			
		

> Thanks for the reply. That's the first thing I thought. So I asked a question on the Intel forum: http://communities.intel.com/thread/41604. However, I was sent here.



Regarding your general question, whether your E5-2620 processors support the RDRAND instruction, they should have simply answered no.

Regarding the error, when compiling your code, it was indeed correct to send you to the FreeBSD forum. The standard FreeBSD-GCC-4.2.1 on Ivy Bridge processors wouldn't compile your code either. On the other hand, the latest clang-3.4 lang/clang-devel from the ports does compile it, even on non-Ivy-Bridge machines. Executing the code on non-Ivy-Bridge machines dumps the core, though: (Illegal instruction: 4 (core dumped)).

Conclusion: To get your code running, you need an Ivy Bridge machine and a modern compiler.


----------



## francisco (Jan 4, 2016)

Please, same error here on my  E5-2630. 
I need to run IPSEC VPN so added this to /usr/src/sys/amd64/conf/kernel-ipsec:

```
options  IPSEC       #VPN vivo
options  IPSEC_NAT_T
device  crypto
```

`make cleandepend && make depend` == ok

But
make fails with the error:

```
{standard input}: Assembler messages:
{standard input}:90: Error: no such instruction: `rdrand %rax'
*** [ivy.o] Error code 1

Stop in /usr/src/sys/amd64/compile/kernel-ipsec
```

Is there a way to run IPSEC on this machine?

```
FreeBSD 9.2-PRERELEASE #0: Fri Jul 12 23:07:12 BRT 2013 amd64
```


----------



## SirDice (Jan 5, 2016)

A -PRERELEASE version is not supported if there's been a final release. And FreeBSD 9.2-RELEASE has been End-of-Life since December 2014 and is also not supported any more. Please update to a supported version, the issue may already have been fixed.


Thread topics-about-unsupported-freebsd-versions.40469/
https://www.freebsd.org/security/unsupported.html


----------

