Add a file with fingerprints that have recently been used to sign
[openssl.git] / crypto / x86cpuid.pl
index da3e5bcaca185e112fdf1d869150251c113b9c44..894c49c0a3e359d53bd38df178235d2a6290c829 100644 (file)
@@ -38,6 +38,40 @@ require "x86asm.pl";
        &ret    ();
 &function_end_B("OPENSSL_rdtsc");
 
+# This works in Ring 0 only [read DJGPP+MS-DOS+privileged DPMI host],
+# but it's safe to call it on any [supported] 32-bit platform...
+# Just check for [non-]zero return value...
+&function_begin_B("OPENSSL_instrument_halt","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
+       &picmeup("ecx","OPENSSL_ia32cap_P");
+       &bt     (&DWP(0,"ecx"),4);
+       &jnc    (&label("nohalt"));     # no TSC
+
+       &data_word(0x9058900e);         # push %cs; pop %eax
+       &and    ("eax",3);
+       &jnz    (&label("nohalt"));     # not enough privileges
+
+       &pushf  ();
+       &pop    ("eax")
+       &bt     ("eax",9);
+       &jnc    (&label("nohalt"));     # interrupts are disabled
+
+       &rdtsc  ();
+       &push   ("edx");
+       &push   ("eax");
+       &halt   ();
+       &rdtsc  ();
+
+       &sub    ("eax",&DWP(0,"esp"));
+       &sbb    ("edx",&DWP(4,"esp"));
+       &add    ("esp",8);
+       &ret    ();
+
+&set_label("nohalt");
+       &xor    ("eax","eax");
+       &xor    ("edx","edx");
+       &ret    ();
+&function_end_B("OPENSSL_instrument_halt");
+
 &initseg("OPENSSL_cpuid_setup");
 
 &asm_finish();