]>
Commit | Line | Data |
---|---|---|
3aa8dc6c LQ |
1 | ;------------------------------------------------------------------------------\r |
2 | ;\r | |
3 | ; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r | |
4 | ; This program and the accompanying materials\r | |
5 | ; are licensed and made available under the terms and conditions of the BSD License\r | |
6 | ; which accompanies this distribution. The full text of the license may be found at\r | |
7 | ; http://opensource.org/licenses/bsd-license.php.\r | |
8 | ;\r | |
9 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | ;\r | |
12 | ; Module Name:\r | |
13 | ;\r | |
14 | ; AsmRdRand.Asm\r | |
15 | ;\r | |
16 | ; Abstract:\r | |
17 | ;\r | |
18 | ; Implementation for 16-, and 32- invocations of RDRAND instruction under 32bit platform.\r | |
19 | ;\r | |
20 | ; Notes:\r | |
21 | ;\r | |
22 | ; Visual Studio coding practices do not use inline asm since multiple compilers and \r | |
23 | ; architectures are supported assembler not recognizing rdrand instruction so using DB's.\r | |
24 | ;\r | |
25 | ;------------------------------------------------------------------------------\r | |
26 | \r | |
27 | .586P\r | |
28 | .model flat, C\r | |
29 | .code\r | |
30 | \r | |
31 | ;------------------------------------------------------------------------------\r | |
32 | ; Generate a 16 bit random number\r | |
33 | ; Return TRUE if Rand generated successfully, or FALSE if not\r | |
34 | ;\r | |
35 | ; BOOLEAN EFIAPI RdRand16Step (UINT16 *Rand); ECX\r | |
36 | ;------------------------------------------------------------------------------\r | |
37 | RdRand16Step PROC\r | |
38 | ; rdrand ax ; generate a 16 bit RN into ax, CF=1 if RN generated ok, otherwise CF=0\r | |
39 | db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"\r | |
40 | jb rn16_ok ; jmp if CF=1\r | |
41 | xor eax, eax ; reg=0 if CF=0\r | |
42 | ret ; return with failure status\r | |
43 | rn16_ok:\r | |
44 | mov [ecx], ax\r | |
45 | mov eax, 1\r | |
46 | ret\r | |
47 | RdRand16Step ENDP\r | |
48 | \r | |
49 | ;------------------------------------------------------------------------------\r | |
50 | ; Generate a 32 bit random number\r | |
51 | ; Return TRUE if Rand generated successfully, or FALSE if not\r | |
52 | ;\r | |
53 | ; BOOLEAN EFIAPI RdRand32Step (UINT32 *Rand); ECX\r | |
54 | ;------------------------------------------------------------------------------\r | |
55 | RdRand32Step PROC\r | |
56 | ; rdrand eax ; generate a 32 bit RN into eax, CF=1 if RN generated ok, otherwise CF=0\r | |
57 | db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r | |
58 | jb rn32_ok ; jmp if CF=1\r | |
59 | xor eax, eax ; reg=0 if CF=0\r | |
60 | ret ; return with failure status\r | |
61 | rn32_ok:\r | |
62 | mov [ecx], eax\r | |
63 | mov eax, 1\r | |
64 | ret\r | |
65 | RdRand32Step ENDP\r | |
66 | \r | |
67 | END\r |