Corrected win64 cpuid() code. Report and patch by Mann Ern Kang.
[gnutls:gnutls.git] / devel / perlasm / cpuid-x86.pl
1 #!/usr/bin/env perl
2 #
3 # ====================================================================
4 # Written by Nikos Mavrogiannopoulos
5 # Placed under the LGPL
6 # ====================================================================
7 #
8
9 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10 push(@INC,"${dir}","${dir}../../crypto/perlasm");
11 require "x86asm.pl";
12
13 &asm_init($ARGV[0],$0);
14
15 &function_begin_B("gnutls_cpuid");
16         &push   ("ebp");
17         &mov    ("ebp", "esp");
18         &sub    ("esp", 12);
19         &mov    (&DWP(0,"esp"), "ebx");
20         &mov    ("eax",&DWP(8,"ebp"));
21         &mov    (&DWP(4,"esp"), "esi");
22         &mov    (&DWP(8,"esp"), "edi");
23         &push   ("ebx");
24         &cpuid  ();
25         &mov    ("edi", "ebx");
26         &pop    ("ebx");
27         &mov    ("esi","edx");
28         &mov    ("edx",&DWP(12,"ebp"));
29         &mov    (&DWP(0,"edx"), "eax");
30         &mov    ("eax",&DWP(16,"ebp"));
31         &mov    (&DWP(0,"eax"), "edi");
32         &mov    ("eax",&DWP(20,"ebp"));
33         &mov    (&DWP(0,"eax"), "ecx");
34         &mov    ("eax",&DWP(24,"ebp"));
35         &mov    (&DWP(0,"eax"), "esi");
36         &mov    ("ebx",&DWP(0,"esp"));
37         &mov    ("esi",&DWP(4,"esp"));
38         &mov    ("edi",&DWP(8,"esp"));
39         &mov    ("esp","ebp");
40         &pop    ("ebp");
41         &ret    ();
42 &function_end_B("gnutls_cpuid");
43
44 &function_begin_B("gnutls_have_cpuid");
45         &pushf  ();
46         &pop    ("eax");
47         &or     ("eax",0x200000);
48         &push   ("eax");
49         &popf   ();
50         &pushf  ();
51         &pop    ("eax");
52         &and     ("eax",0x200000);
53         &ret    ();
54 &function_end_B("gnutls_have_cpuid");
55
56 &asciz("CPUID for x86");
57 &asm_finish();