1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 ; Generates random number through CPU RdRand instruction under 64-bit platform.
22 ;------------------------------------------------------------------------------
26 ;------------------------------------------------------------------------------
27 ; Generates a 16 bit random number through RDRAND instruction.
28 ; Return TRUE if Rand generated successfully, or FALSE if not.
30 ; BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
31 ;------------------------------------------------------------------------------
33 ; rdrand ax ; generate a 16 bit RN into eax,
34 ; CF=1 if RN generated ok, otherwise CF=0
35 db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"
36 jc rn16_ok ; jmp if CF=1
37 xor rax, rax ; reg=0 if CF=0
38 ret ; return with failure status
45 ;------------------------------------------------------------------------------
46 ; Generates a 32 bit random number through RDRAND instruction.
47 ; Return TRUE if Rand generated successfully, or FALSE if not.
49 ; BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
50 ;------------------------------------------------------------------------------
52 ; rdrand eax ; generate a 32 bit RN into eax,
53 ; CF=1 if RN generated ok, otherwise CF=0
54 db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"
55 jc rn32_ok ; jmp if CF=1
56 xor rax, rax ; reg=0 if CF=0
57 ret ; return with failure status
64 ;------------------------------------------------------------------------------
65 ; Generates a 64 bit random number through one RDRAND instruction.
66 ; Return TRUE if Rand generated successfully, or FALSE if not.
68 ; BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random);
69 ;------------------------------------------------------------------------------
71 ; rdrand rax ; generate a 64 bit RN into rax,
72 ; CF=1 if RN generated ok, otherwise CF=0
73 db 048h, 0fh, 0c7h, 0f0h ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
74 jc rn64_ok ; jmp if CF=1
75 xor rax, rax ; reg=0 if CF=0
76 ret ; return with failure status