]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check.
authorQin Long <qin.long@intel.com>
Fri, 4 Nov 2016 07:31:28 +0000 (15:31 +0800)
committerQin Long <qin.long@intel.com>
Wed, 16 Nov 2016 08:49:10 +0000 (16:49 +0800)
Add one wrapper implementation over assembly RdRand access to check
possible NULL parameter, for better alignment with comment description.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Library/BaseLib/BaseLib.inf
MdePkg/Library/BaseLib/BaseLibInternals.h
MdePkg/Library/BaseLib/Ia32/RdRand.S
MdePkg/Library/BaseLib/Ia32/RdRand.asm
MdePkg/Library/BaseLib/Ia32/RdRand.nasm
MdePkg/Library/BaseLib/X64/RdRand.S
MdePkg/Library/BaseLib/X64/RdRand.asm
MdePkg/Library/BaseLib/X64/RdRand.nasm
MdePkg/Library/BaseLib/X86RdRand.c [new file with mode: 0644]

index 1ffe870e7ee44503ceedc479528c405eb3c802c4..320ac457ea3d2668c1e71487b1bea229d6149042 100644 (file)
   X86EnablePaging32.c\r
   X86DisablePaging64.c\r
   X86DisablePaging32.c\r
+  X86RdRand.c\r
 \r
 [Sources.X64]\r
   X64/Thunk16.nasm\r
   X86EnablePaging32.c\r
   X86DisablePaging64.c\r
   X86DisablePaging32.c\r
+  X86RdRand.c\r
   X64/GccInline.c | GCC\r
   X64/Thunk16.S | XCODE \r
   X64/SwitchStack.nasm| GCC\r
index fe416a0c38b50d552a7007c9f2c9908afeea70df..a8f712b1addedcd7fdc8bbe442a9cf9e7a684121 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declaration of internal functions in BaseLib.\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -728,6 +728,52 @@ InternalX86DisablePaging64 (
   IN      UINT32                    NewStack\r
   );\r
 \r
+/**\r
+  Generates a 16-bit random number through RDRAND instruction.\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+ **/\r
+BOOLEAN\r
+EFIAPI\r
+InternalX86RdRand16 (\r
+  OUT     UINT16                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 32-bit random number through RDRAND instruction.\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalX86RdRand32 (\r
+  OUT     UINT32                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 64-bit random number through RDRAND instruction.\r
+\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalX86RdRand64  (\r
+  OUT     UINT64                    *Rand\r
+  );\r
+\r
 \r
 #elif defined (MDE_CPU_IPF)\r
 //\r
index 503f65a72107c8e8c388b305360045903f99907f..d00075afe778339068d4e3c065f884cf5c4479a7 100644 (file)
@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------ ;\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 //  Generates a 16 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand16)\r
-ASM_PFX(AsmRdRand16):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand16)\r
+ASM_PFX(InternalX86RdRand16):\r
     .byte  0x0f, 0xc7, 0xf0        // rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
     jc     rn16_ok                 // jmp if CF=1\r
     xor    %eax, %eax              // reg=0 if CF=0\r
@@ -42,10 +42,10 @@ rn16_ok:
 //  Generates a 32 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand32)\r
-ASM_PFX(AsmRdRand32):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand32)\r
+ASM_PFX(InternalX86RdRand32):\r
     .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
     jc     rn32_ok                 // jmp if CF=1\r
     xor    %eax, %eax              // reg=0 if CF=0\r
@@ -60,10 +60,10 @@ rn32_ok:
 //  Generates a 64 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand64)\r
-ASM_PFX(AsmRdRand64):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand64)\r
+ASM_PFX(InternalX86RdRand64):\r
     .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
     jnc    rn64_ret                // jmp if CF=0\r
     mov    0x4(%esp), %edx\r
index 21349b0918d4ec6e511da3d849360ae091561697..cb4e811098bd6cf9991a3675ba3bddea9fd94489 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -30,9 +30,9 @@
 ;  Generates a 16 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand16  PROC\r
+InternalX86RdRand16  PROC\r
     ; rdrand   ax                  ; generate a 16 bit RN into ax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0fh, 0c7h, 0f0h         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
@@ -44,15 +44,15 @@ rn16_ok:
     mov    [edx], ax\r
     mov    eax,  1\r
     ret\r
-AsmRdRand16 ENDP\r
+InternalX86RdRand16 ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
 ;  Generates a 32 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand32  PROC\r
+InternalX86RdRand32  PROC\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
@@ -64,15 +64,15 @@ rn32_ok:
     mov    [edx], eax\r
     mov    eax,  1\r
     ret\r
-AsmRdRand32 ENDP\r
+InternalX86RdRand32 ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
 ;  Generates a 64 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand64  PROC\r
+InternalX86RdRand64  PROC\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
@@ -89,6 +89,6 @@ AsmRdRand64  PROC
 rn64_ret:\r
     xor    eax, eax\r
     ret                            ; return with failure status\r
-AsmRdRand64 ENDP\r
+InternalX86RdRand64 ENDP\r
 \r
     END\r
index 1365dfcdbbe13d13c6f3557f2e99d66b4a0297e3..64e8cdbda464419db29a75b163965f3c225bfaac 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -27,10 +27,10 @@ SECTION .text
 ;  Generates a 16 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand16)\r
-ASM_PFX(AsmRdRand16):\r
+global ASM_PFX(InternalX86RdRand16)\r
+ASM_PFX(InternalX86RdRand16):\r
     ; rdrand   ax                  ; generate a 16 bit RN into ax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0xf, 0xc7, 0xf0         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
@@ -47,10 +47,10 @@ rn16_ok:
 ;  Generates a 32 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand32)\r
-ASM_PFX(AsmRdRand32):\r
+global ASM_PFX(InternalX86RdRand32)\r
+ASM_PFX(InternalX86RdRand32):\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
@@ -67,10 +67,10 @@ rn32_ok:
 ;  Generates a 64 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand64)\r
-ASM_PFX(AsmRdRand64):\r
+global ASM_PFX(InternalX86RdRand64)\r
+ASM_PFX(InternalX86RdRand64):\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
index 49b50e69013dd9da503e33026cc8a535fd378fea..55724c08689f4eea683c13cefd056cc9ad77e565 100644 (file)
@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------ ;\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 //  Generates a 16 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand16)\r
-ASM_PFX(AsmRdRand16):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand16)\r
+ASM_PFX(InternalX86RdRand16):\r
     .byte  0x0f, 0xc7, 0xf0        // rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
     jc     rn16_ok                 // jmp if CF=1\r
     xor    %rax, %rax              // reg=0 if CF=0\r
@@ -41,10 +41,10 @@ rn16_ok:
 //  Generates a 32 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand32)\r
-ASM_PFX(AsmRdRand32):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand32)\r
+ASM_PFX(InternalX86RdRand32):\r
     .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
     jc     rn32_ok                 // jmp if CF=1\r
     xor    %rax, %rax              // reg=0 if CF=0\r
@@ -58,10 +58,10 @@ rn32_ok:
 //  Generates a 64 bit random number through RDRAND instruction.\r
 //  Return TRUE if Rand generated successfully, or FALSE if not.\r
 //\r
-//  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);\r
+//  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r
 //------------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(AsmRdRand64)\r
-ASM_PFX(AsmRdRand64):\r
+ASM_GLOBAL ASM_PFX(InternalX86RdRand64)\r
+ASM_PFX(InternalX86RdRand64):\r
     .byte  0x48, 0x0f, 0xc7, 0xf0  // rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"\r
     jc     rn64_ok                 // jmp if CF=1\r
     xor    %rax, %rax              // reg=0 if CF=0\r
index 370cdb607a70b14597a1aa34e98ecd6407ad33c2..8e2074e2d515eff2413cc243bae2f47b11b4a979 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -27,9 +27,9 @@
 ;  Generates a 16 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand16  PROC\r
+InternalX86RdRand16  PROC\r
     ; rdrand   ax                  ; generate a 16 bit RN into eax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0fh, 0c7h, 0f0h         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
@@ -40,15 +40,15 @@ rn16_ok:
     mov    [rcx], ax\r
     mov    rax,  1\r
     ret\r
-AsmRdRand16 ENDP\r
+InternalX86RdRand16 ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
 ;  Generates a 32 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand32  PROC\r
+InternalX86RdRand32  PROC\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
@@ -59,15 +59,15 @@ rn32_ok:
     mov    [rcx], eax\r
     mov    rax,  1\r
     ret\r
-AsmRdRand32 ENDP\r
+InternalX86RdRand32 ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
 ;  Generates a 64 bit random number through one RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random);\r
+;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);\r
 ;------------------------------------------------------------------------------\r
-AsmRdRand64  PROC\r
+InternalX86RdRand64  PROC\r
     ; rdrand   rax                 ; generate a 64 bit RN into rax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     048h, 0fh, 0c7h, 0f0h   ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"\r
@@ -78,6 +78,6 @@ rn64_ok:
     mov    [rcx], rax\r
     mov    rax, 1\r
     ret\r
-AsmRdRand64 ENDP\r
+InternalX86RdRand64 ENDP\r
 \r
     END\r
index f6d83a3a109615a6c237b2efa71eac672ff0cb77..b9050d287b6977414dc8ed9da993b3a352e16e7e 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
 ;  Generates a 16 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand16)\r
-ASM_PFX(AsmRdRand16):\r
+global ASM_PFX(InternalX86RdRand16)\r
+ASM_PFX(InternalX86RdRand16):\r
     ; rdrand   ax                  ; generate a 16 bit RN into eax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0xf, 0xc7, 0xf0         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"\r
@@ -47,10 +47,10 @@ rn16_ok:
 ;  Generates a 32 bit random number through RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r
+;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand32)\r
-ASM_PFX(AsmRdRand32):\r
+global ASM_PFX(InternalX86RdRand32)\r
+ASM_PFX(InternalX86RdRand32):\r
     ; rdrand   eax                 ; generate a 32 bit RN into eax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"\r
@@ -66,10 +66,10 @@ rn32_ok:
 ;  Generates a 64 bit random number through one RDRAND instruction.\r
 ;  Return TRUE if Rand generated successfully, or FALSE if not.\r
 ;\r
-;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random);\r
+;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(AsmRdRand64)\r
-ASM_PFX(AsmRdRand64):\r
+global ASM_PFX(InternalX86RdRand64)\r
+ASM_PFX(InternalX86RdRand64):\r
     ; rdrand   rax                 ; generate a 64 bit RN into rax,\r
                                    ; CF=1 if RN generated ok, otherwise CF=0\r
     db     0x48, 0xf, 0xc7, 0xf0   ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"\r
diff --git a/MdePkg/Library/BaseLib/X86RdRand.c b/MdePkg/Library/BaseLib/X86RdRand.c
new file mode 100644 (file)
index 0000000..36d5457
--- /dev/null
@@ -0,0 +1,79 @@
+/** @file\r
+  IA-32/x64 AsmRdRandxx()\r
+  Generates random number through CPU RdRand instruction.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "BaseLibInternals.h"\r
+\r
+/**\r
+  Generates a 16-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+ **/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand16 (\r
+  OUT     UINT16                    *Rand\r
+  )\r
+{\r
+  ASSERT (Rand != NULL);\r
+  return InternalX86RdRand16 (Rand);\r
+}\r
+\r
+/**\r
+  Generates a 32-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand32 (\r
+  OUT     UINT32                    *Rand\r
+  )\r
+{\r
+  ASSERT (Rand != NULL);\r
+  return InternalX86RdRand32 (Rand);\r
+}\r
+\r
+/**\r
+  Generates a 64-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand64  (\r
+  OUT     UINT64                    *Rand\r
+  )\r
+{\r
+  ASSERT (Rand != NULL);\r
+  return InternalX86RdRand64 (Rand);\r
+}\r