]>
Commit | Line | Data |
---|---|---|
3cfc7813 | 1 | #------------------------------------------------------------------------------ ;\r |
9ec9a7a5 | 2 | # Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r |
3cfc7813 QL |
3 | # This program and the accompanying materials\r |
4 | # are licensed and made available under the terms and conditions of the BSD License\r | |
5 | # which accompanies this distribution. The full text of the license may be found at\r | |
6 | # http://opensource.org/licenses/bsd-license.php.\r | |
7 | #\r | |
8 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
9 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
10 | #\r | |
11 | # Module Name:\r | |
12 | #\r | |
13 | # RdRand.S\r | |
14 | #\r | |
15 | # Abstract:\r | |
16 | #\r | |
17 | # Generates random number through CPU RdRand instruction under 32-bit platform.\r | |
18 | #\r | |
19 | # Notes:\r | |
20 | #\r | |
21 | #------------------------------------------------------------------------------\r | |
22 | \r | |
23 | //------------------------------------------------------------------------------\r | |
24 | // Generates a 16 bit random number through RDRAND instruction.\r | |
25 | // Return TRUE if Rand generated successfully, or FALSE if not.\r | |
26 | //\r | |
9ec9a7a5 | 27 | // BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r |
3cfc7813 | 28 | //------------------------------------------------------------------------------\r |
9ec9a7a5 QL |
29 | ASM_GLOBAL ASM_PFX(InternalX86RdRand16)\r |
30 | ASM_PFX(InternalX86RdRand16):\r | |
3cfc7813 QL |
31 | .byte 0x0f, 0xc7, 0xf0 // rdrand r16: "0f c7 /6 ModRM:r/m(w)"\r |
32 | jc rn16_ok // jmp if CF=1\r | |
33 | xor %eax, %eax // reg=0 if CF=0\r | |
34 | ret // return with failure status\r | |
35 | rn16_ok:\r | |
36 | mov 0x4(%esp), %edx\r | |
37 | mov %ax, (%edx)\r | |
38 | mov $0x1, %eax\r | |
39 | ret\r | |
40 | \r | |
41 | //------------------------------------------------------------------------------\r | |
42 | // Generates a 32 bit random number through RDRAND instruction.\r | |
43 | // Return TRUE if Rand generated successfully, or FALSE if not.\r | |
44 | //\r | |
9ec9a7a5 | 45 | // BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r |
3cfc7813 | 46 | //------------------------------------------------------------------------------\r |
9ec9a7a5 QL |
47 | ASM_GLOBAL ASM_PFX(InternalX86RdRand32)\r |
48 | ASM_PFX(InternalX86RdRand32):\r | |
3cfc7813 QL |
49 | .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r |
50 | jc rn32_ok // jmp if CF=1\r | |
51 | xor %eax, %eax // reg=0 if CF=0\r | |
52 | ret // return with failure status\r | |
53 | rn32_ok:\r | |
54 | mov 0x4(%esp), %edx\r | |
55 | mov %eax, (%edx)\r | |
56 | mov $0x1, %eax\r | |
57 | ret\r | |
58 | \r | |
59 | //------------------------------------------------------------------------------\r | |
60 | // Generates a 64 bit random number through RDRAND instruction.\r | |
61 | // Return TRUE if Rand generated successfully, or FALSE if not.\r | |
62 | //\r | |
9ec9a7a5 | 63 | // BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r |
3cfc7813 | 64 | //------------------------------------------------------------------------------\r |
9ec9a7a5 QL |
65 | ASM_GLOBAL ASM_PFX(InternalX86RdRand64)\r |
66 | ASM_PFX(InternalX86RdRand64):\r | |
3cfc7813 QL |
67 | .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r |
68 | jnc rn64_ret // jmp if CF=0\r | |
69 | mov 0x4(%esp), %edx\r | |
70 | mov %eax, (%edx)\r | |
71 | \r | |
72 | .byte 0x0f, 0xc7, 0xf0 // generate another 32 bit RN\r | |
73 | jnc rn64_ret // jmp if CF=0\r | |
74 | mov %eax, 0x4(%edx)\r | |
75 | \r | |
76 | mov $0x1, %eax\r | |
77 | ret\r | |
78 | rn64_ret:\r | |
79 | xor %eax, %eax\r | |
80 | ret // return with failure status\r |