]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/RdRand.nasm
MdePkg: Replace Opcode with the corresponding instructions.
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / RdRand.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; RdRand.nasm
9 ;
10 ; Abstract:
11 ;
12 ; Generates random number through CPU RdRand instruction under 64-bit platform.
13 ;
14 ; Notes:
15 ;
16 ;------------------------------------------------------------------------------
17
18 DEFAULT REL
19 SECTION .text
20
21 ;------------------------------------------------------------------------------
22 ; Generates a 16 bit random number through RDRAND instruction.
23 ; Return TRUE if Rand generated successfully, or FALSE if not.
24 ;
25 ; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
26 ;------------------------------------------------------------------------------
27 global ASM_PFX(InternalX86RdRand16)
28 ASM_PFX(InternalX86RdRand16):
29 rdrand eax ; generate a 16 bit RN into eax,
30 ; CF=1 if RN generated ok, otherwise CF=0
31 jc rn16_ok ; jmp if CF=1
32 xor rax, rax ; reg=0 if CF=0
33 ret ; return with failure status
34 rn16_ok:
35 mov [rcx], ax
36 mov rax, 1
37 ret
38
39 ;------------------------------------------------------------------------------
40 ; Generates a 32 bit random number through RDRAND instruction.
41 ; Return TRUE if Rand generated successfully, or FALSE if not.
42 ;
43 ; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
44 ;------------------------------------------------------------------------------
45 global ASM_PFX(InternalX86RdRand32)
46 ASM_PFX(InternalX86RdRand32):
47 rdrand eax ; generate a 32 bit RN into eax,
48 ; CF=1 if RN generated ok, otherwise CF=0
49 jc rn32_ok ; jmp if CF=1
50 xor rax, rax ; reg=0 if CF=0
51 ret ; return with failure status
52 rn32_ok:
53 mov [rcx], eax
54 mov rax, 1
55 ret
56
57 ;------------------------------------------------------------------------------
58 ; Generates a 64 bit random number through one RDRAND instruction.
59 ; Return TRUE if Rand generated successfully, or FALSE if not.
60 ;
61 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
62 ;------------------------------------------------------------------------------
63 global ASM_PFX(InternalX86RdRand64)
64 ASM_PFX(InternalX86RdRand64):
65 rdrand rax ; generate a 64 bit RN into rax,
66 ; CF=1 if RN generated ok, otherwise CF=0
67 jc rn64_ok ; jmp if CF=1
68 xor rax, rax ; reg=0 if CF=0
69 ret ; return with failure status
70 rn64_ok:
71 mov [rcx], rax
72 mov rax, 1
73 ret
74