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
/** @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
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
#------------------------------------------------------------------------------ ;\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
// 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
// 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
;------------------------------------------------------------------------------\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
-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
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
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
rn64_ret:\r
xor eax, eax\r
ret ; return with failure status\r
-AsmRdRand64 ENDP\r
+InternalX86RdRand64 ENDP\r
\r
END\r
;------------------------------------------------------------------------------\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 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
; 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
; 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
#------------------------------------------------------------------------------ ;\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
// 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
// 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
;------------------------------------------------------------------------------\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
-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
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
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
mov [rcx], rax\r
mov rax, 1\r
ret\r
-AsmRdRand64 ENDP\r
+InternalX86RdRand64 ENDP\r
\r
END\r
;------------------------------------------------------------------------------\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
; 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
; 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
--- /dev/null
+/** @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