1 #------------------------------------------------------------------------------ ;
2 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
3 # This program and the accompanying materials
4 # are licensed and made available under the terms and conditions of the BSD License
5 # which accompanies this distribution. The full text of the license may be found at
6 # http://opensource.org/licenses/bsd-license.php.
8 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 # Generates random number through CPU RdRand instruction under 64-bit platform.
21 #------------------------------------------------------------------------------
23 //------------------------------------------------------------------------------
24 // Generates a 16 bit random number through RDRAND instruction.
25 // Return TRUE if Rand generated successfully, or FALSE if not.
27 // BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
28 //------------------------------------------------------------------------------
29 ASM_GLOBAL ASM_PFX(AsmRdRand16)
31 .byte 0x0f, 0xc7, 0xf0 // rdrand r16: "0f c7 /6 ModRM:r/m(w)"
32 jc rn16_ok // jmp if CF=1
33 xor %rax, %rax // reg=0 if CF=0
34 ret // return with failure status
40 //------------------------------------------------------------------------------
41 // Generates a 32 bit random number through RDRAND instruction.
42 // Return TRUE if Rand generated successfully, or FALSE if not.
44 // BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
45 //------------------------------------------------------------------------------
46 ASM_GLOBAL ASM_PFX(AsmRdRand32)
48 .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"
49 jc rn32_ok // jmp if CF=1
50 xor %rax, %rax // reg=0 if CF=0
51 ret // return with failure status
57 //------------------------------------------------------------------------------
58 // Generates a 64 bit random number through RDRAND instruction.
59 // Return TRUE if Rand generated successfully, or FALSE if not.
61 // BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
62 //------------------------------------------------------------------------------
63 ASM_GLOBAL ASM_PFX(AsmRdRand64)
65 .byte 0x48, 0x0f, 0xc7, 0xf0 // rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
66 jc rn64_ok // jmp if CF=1
67 xor %rax, %rax // reg=0 if CF=0
68 ret // return with failure status