+#define RDRAND_LONG ".byte 0x48,0x0f,0xc7,0xf0"
+#define RDSEED_LONG ".byte 0x48,0x0f,0xc7,0xf8"
+#define RDRAND_RETRY 100
+
+static inline int arch_rand_long(unsigned long *val)
+{
+ int ok;
+
+ asm volatile("1: " RDRAND_LONG "\n\t"
+ "jc 2f\n\t"
+ "decl %0\n\t"
+ "jnz 1b\n\t"
+ "2:"
+ : "=r" (ok), "=a" (*val)
+ : "0" (RDRAND_RETRY));
+
+ return ok;
+}
+
+static inline int arch_rand_seed(unsigned long *seed)
+{
+ unsigned char ok;
+
+ asm volatile(RDSEED_LONG "\n\t"
+ "setc %0"
+ : "=qm" (ok), "=a" (*seed));
+
+ return 0;
+}
+