]>
Commit | Line | Data |
---|---|---|
3aa8dc6c LQ |
1 | /** @file\r |
2 | RDRAND Support Routines for GCC environment.\r | |
3 | \r | |
4 | Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | /**\r | |
16 | Generates a 16-bit random number through RDRAND instruction.\r | |
17 | \r | |
18 | @param[out] Rand Buffer pointer to store the random result.\r | |
19 | \r | |
20 | @retval TRUE RDRAND call was successful.\r | |
21 | @retval FALSE Failed attempts to call RDRAND.\r | |
22 | \r | |
23 | **/\r | |
24 | BOOLEAN\r | |
25 | EFIAPI\r | |
26 | RdRand16Step (\r | |
27 | OUT UINT16 *Rand\r | |
28 | )\r | |
29 | {\r | |
30 | UINT8 Carry;\r | |
31 | \r | |
32 | //\r | |
33 | // Uses byte code for RDRAND instruction,\r | |
34 | // in case that GCC version has no direct support on RDRAND assembly.\r | |
35 | //\r | |
36 | __asm__ __volatile__ (\r | |
37 | ".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r | |
38 | :"=a" (*Rand), \r | |
39 | "=qm" (Carry)\r | |
40 | ); \r | |
41 | \r | |
42 | return (BOOLEAN) Carry;\r | |
43 | }\r | |
44 | \r | |
45 | /**\r | |
46 | Generates a 32-bit random number through RDRAND instruction.\r | |
47 | \r | |
48 | @param[out] Rand Buffer pointer to store the random result.\r | |
49 | \r | |
50 | @retval TRUE RDRAND call was successful.\r | |
51 | @retval FALSE Failed attempts to call RDRAND.\r | |
52 | \r | |
53 | **/\r | |
54 | BOOLEAN\r | |
55 | EFIAPI\r | |
56 | RdRand32Step (\r | |
57 | OUT UINT32 *Rand\r | |
58 | )\r | |
59 | {\r | |
60 | UINT8 Carry;\r | |
61 | \r | |
62 | __asm__ __volatile__ (\r | |
63 | ".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r | |
64 | :"=a" (*Rand), \r | |
65 | "=qm" (Carry)\r | |
66 | );\r | |
67 | \r | |
68 | return (BOOLEAN) Carry;\r | |
69 | } |