]>
Commit | Line | Data |
---|---|---|
3cfc7813 QL |
1 | #------------------------------------------------------------------------------ ;\r |
2 | # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
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 64-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 | |
27 | // BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);\r | |
28 | //------------------------------------------------------------------------------\r | |
29 | ASM_GLOBAL ASM_PFX(AsmRdRand16)\r | |
30 | ASM_PFX(AsmRdRand16):\r | |
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 %rax, %rax // reg=0 if CF=0\r | |
34 | ret // return with failure status\r | |
35 | rn16_ok:\r | |
36 | mov %ax, (%rcx)\r | |
37 | mov $0x1, %rax\r | |
38 | ret\r | |
39 | \r | |
40 | //------------------------------------------------------------------------------\r | |
41 | // Generates a 32 bit random number through RDRAND instruction.\r | |
42 | // Return TRUE if Rand generated successfully, or FALSE if not.\r | |
43 | //\r | |
44 | // BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);\r | |
45 | //------------------------------------------------------------------------------\r | |
46 | ASM_GLOBAL ASM_PFX(AsmRdRand32)\r | |
47 | ASM_PFX(AsmRdRand32):\r | |
48 | .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r | |
49 | jc rn32_ok // jmp if CF=1\r | |
50 | xor %rax, %rax // reg=0 if CF=0\r | |
51 | ret // return with failure status\r | |
52 | rn32_ok:\r | |
53 | mov %eax, (%rcx)\r | |
54 | mov $0x1, %rax\r | |
55 | ret\r | |
56 | \r | |
57 | //------------------------------------------------------------------------------\r | |
58 | // Generates a 64 bit random number through RDRAND instruction.\r | |
59 | // Return TRUE if Rand generated successfully, or FALSE if not.\r | |
60 | //\r | |
61 | // BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);\r | |
62 | //------------------------------------------------------------------------------\r | |
63 | ASM_GLOBAL ASM_PFX(AsmRdRand64)\r | |
64 | ASM_PFX(AsmRdRand64):\r | |
65 | .byte 0x48, 0x0f, 0xc7, 0xf0 // rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"\r | |
66 | jc rn64_ok // jmp if CF=1\r | |
67 | xor %rax, %rax // reg=0 if CF=0\r | |
68 | ret // return with failure status\r | |
69 | rn64_ok:\r | |
70 | mov %rax, (%rcx)\r | |
71 | mov $0x1, %rax\r | |
72 | ret\r |