6 &asm_init($ARGV[0],"x86cpuid");
8 for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
10 &function_begin("OPENSSL_ia32_cpuid");
22 &jnc (&label("nocpuid"));
25 &set_label("nocpuid");
28 &function_end("OPENSSL_ia32_cpuid");
30 &external_label("OPENSSL_ia32cap_P");
32 &function_begin_B("OPENSSL_rdtsc","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
35 &picmeup("ecx","OPENSSL_ia32cap_P");
36 &bt (&DWP(0,"ecx"),4);
37 &jnc (&label("notsc"));
41 &function_end_B("OPENSSL_rdtsc");
43 # This works in Ring 0 only [read DJGPP+MS-DOS+privileged DPMI host],
44 # but it's safe to call it on any [supported] 32-bit platform...
45 # Just check for [non-]zero return value...
46 &function_begin_B("OPENSSL_instrument_halt","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
47 &picmeup("ecx","OPENSSL_ia32cap_P");
48 &bt (&DWP(0,"ecx"),4);
49 &jnc (&label("nohalt")); # no TSC
51 &data_word(0x9058900e); # push %cs; pop %eax
53 &jnz (&label("nohalt")); # not enough privileges
58 &jnc (&label("nohalt")); # interrupts are disabled
66 &sub ("eax",&DWP(0,"esp"));
67 &sbb ("edx",&DWP(4,"esp"));
75 &function_end_B("OPENSSL_instrument_halt");
77 # Essentially there is only one use for this function. Under DJGPP:
81 # i=OPENSSL_far_spin(_dos_ds,0x46c);
83 # to obtain the number of spins till closest timer interrupt.
85 &function_begin_B("OPENSSL_far_spin");
89 &jnc (&label("nospin")); # interrupts are disabled
91 &mov ("eax",&DWP(4,"esp"));
92 &mov ("ecx",&DWP(8,"esp"));
93 &data_word (0x90d88e1e); # push %ds, mov %eax,%ds
95 &mov ("edx",&DWP(0,"ecx"));
96 &jmp (&label("spin"));
101 &cmp ("edx",&DWP(0,"ecx"));
102 &je (&label("spin"));
104 &data_word (0x1f909090); # pop %ds
107 &set_label("nospin");
111 &function_end_B("OPENSSL_far_spin");
113 &function_begin_B("OPENSSL_wipe_cpu","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
116 &picmeup("ecx","OPENSSL_ia32cap_P");
117 &mov ("ecx",&DWP(0,"ecx"));
118 &bt (&DWP(0,"ecx"),1);
119 &jnc (&label("no_x87"));
121 &bt (&DWP(0,"ecx"),26);
122 &jnc (&label("no_sse2"));
123 &pxor ("xmm0","xmm0");
124 &pxor ("xmm1","xmm1");
125 &pxor ("xmm2","xmm2");
126 &pxor ("xmm3","xmm3");
127 &pxor ("xmm4","xmm4");
128 &pxor ("xmm5","xmm5");
129 &pxor ("xmm6","xmm6");
130 &pxor ("xmm7","xmm7");
131 &set_label("no_sse2");
133 # just a bunch of fldz to zap the fp/mm bank followed by finit...
134 &data_word(0xeed9eed9,0xeed9eed9,0xeed9eed9,0xeed9eed9,0x90e3db9b);
135 &set_label("no_x87");
136 &lea ("eax",&DWP(4,"esp"));
138 &function_end_B("OPENSSL_wipe_cpu");
140 &function_begin_B("OPENSSL_atomic_add");
141 &mov ("edx",&DWP(4,"esp")); # fetch the pointer, 1st arg
142 &mov ("ecx",&DWP(8,"esp")); # fetch the increment, 2nd arg
145 &mov ("eax",&DWP(0,"edx"));
147 &lea ("ebx",&DWP(0,"eax","ecx"));
149 &data_word(0x1ab10ff0); # lock; cmpxchg %ebx,(%edx) # %eax is envolved and is always reloaded
150 &jne (&label("spin"));
151 &mov ("eax","ebx"); # OpenSSL expects the new value
154 &function_end_B("OPENSSL_atomic_add");
156 &initseg("OPENSSL_cpuid_setup");