6 &asm_init($ARGV[0],"x86cpuid");
8 &function_begin("OPENSSL_ia32_cpuid");
20 &jnc (&label("nocpuid"));
23 &set_label("nocpuid");
26 &function_end("OPENSSL_ia32_cpuid");
28 &external_label("OPENSSL_ia32cap_P");
30 &function_begin_B("OPENSSL_rdtsc","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
33 &picmeup("ecx","OPENSSL_ia32cap_P");
34 &bt (&DWP(0,"ecx"),4);
35 &jnc (&label("notsc"));
39 &function_end_B("OPENSSL_rdtsc");
41 # This works in Ring 0 only [read DJGPP+MS-DOS+privileged DPMI host],
42 # but it's safe to call it on any [supported] 32-bit platform...
43 # Just check for [non-]zero return value...
44 &function_begin_B("OPENSSL_instrument_halt","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
45 &picmeup("ecx","OPENSSL_ia32cap_P");
46 &bt (&DWP(0,"ecx"),4);
47 &jnc (&label("nohalt")); # no TSC
49 &data_word(0x9058900e); # push %cs; pop %eax
51 &jnz (&label("nohalt")); # not enough privileges
56 &jnc (&label("nohalt")); # interrupts are disabled
64 &sub ("eax",&DWP(0,"esp"));
65 &sbb ("edx",&DWP(4,"esp"));
73 &function_end_B("OPENSSL_instrument_halt");
75 # Essentially there is only one use for this function. Under DJGPP:
79 # i=OPENSSL_far_spin(_dos_ds,0x46c);
81 # to obtain the number of spins till closest timer interrupt.
83 &function_begin_B("OPENSSL_far_spin");
87 &jnc (&label("nospin")); # interrupts are disabled
89 &mov ("eax",&DWP(4,"esp"));
90 &mov ("ecx",&DWP(8,"esp"));
91 &data_word (0x90d88e1e); # push %ds, mov %eax,%ds
93 &mov ("edx",&DWP(0,"ecx"));
94 &jmp (&label("spin"));
99 &cmp ("edx",&DWP(0,"ecx"));
100 &je (&label("spin"));
102 &data_word (0x1f909090); # pop %ds
105 &set_label("nospin");
109 &function_end_B("OPENSSL_far_spin");
111 &function_begin_B("OPENSSL_wipe_cpu","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
114 &picmeup("ecx","OPENSSL_ia32cap_P");
115 &mov ("ecx",&DWP(0,"ecx"));
116 &bt (&DWP(0,"ecx"),1);
117 &jnc (&label("no_x87"));
118 &bt (&DWP(0,"ecx"),26);
119 &jnc (&label("no_sse2"));
120 &pxor ("xmm0","xmm0");
121 &pxor ("xmm1","xmm1");
122 &pxor ("xmm2","xmm2");
123 &pxor ("xmm3","xmm3");
124 &pxor ("xmm4","xmm4");
125 &pxor ("xmm5","xmm5");
126 &pxor ("xmm6","xmm6");
127 &pxor ("xmm7","xmm7");
128 &set_label("no_sse2");
129 # just a bunch of fldz to zap the fp/mm bank...
130 &data_word(0xeed9eed9,0xeed9eed9,0xeed9eed9,0xeed9eed9);
132 &set_label("no_x87");
133 &lea ("eax",&DWP(4,"esp"));
135 &function_end_B("OPENSSL_wipe_cpu");
137 &function_begin_B("OPENSSL_atomic_add");
138 &mov ("edx",&DWP(4,"esp")); # fetch the pointer, 1st arg
139 &mov ("ecx",&DWP(8,"esp")); # fetch the increment, 2nd arg
142 &mov ("eax",&DWP(0,"edx"));
144 &lea ("ebx",&DWP(0,"eax","ecx"));
146 &data_word(0x1ab10ff0); # lock; cmpxchg %ebx,(%edx) # %eax is envolved and is always reloaded
147 &jne (&label("spin"));
148 &mov ("eax","ebx"); # OpenSSL expects the new value
151 &function_end_B("OPENSSL_atomic_add");
153 &initseg("OPENSSL_cpuid_setup");