]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/x86cpuid.pl
3 $0 =~ m/(.*[\/\\])[^\
/\\]+$/; $dir=$1;
4 push(@INC, "${dir}perlasm", "perlasm");
7 &asm_init
($ARGV[0],"x86cpuid");
9 for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
11 &function_begin
("OPENSSL_ia32_cpuid");
23 &jnc
(&label
("done"));
27 &cmp ("ebx",0x756e6547); # "Genu"
30 &cmp ("edx",0x49656e69); # "ineI"
33 &cmp ("ecx",0x6c65746e); # "ntel"
39 &jne
(&label
("notP4"));
40 &and (&HB
("eax"),15); # familiy ID
41 &cmp (&HB
("eax"),15); # P4?
42 &jne
(&label
("notP4"));
43 &or ("edx",1<<20); # use reserved bit to engage RC4_CHAR
45 &bt
("edx",28); # test hyper-threading bit
46 &jnc
(&label
("done"));
48 &cmp (&LB
("ebx"),1); # see if cache is shared(*)
50 &and ("edx",0xefffffff); # clear hyper-threading bit if not
54 &function_end
("OPENSSL_ia32_cpuid");
55 # (*) on Core2 this value is set to 2 denoting the fact that L2
56 # cache is shared between cores.
58 &external_label
("OPENSSL_ia32cap_P");
60 &function_begin_B
("OPENSSL_rdtsc","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
63 &picmeup
("ecx","OPENSSL_ia32cap_P");
64 &bt
(&DWP
(0,"ecx"),4);
65 &jnc
(&label
("notsc"));
69 &function_end_B
("OPENSSL_rdtsc");
71 # This works in Ring 0 only [read DJGPP+MS-DOS+privileged DPMI host],
72 # but it's safe to call it on any [supported] 32-bit platform...
73 # Just check for [non-]zero return value...
74 &function_begin_B
("OPENSSL_instrument_halt","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
75 &picmeup
("ecx","OPENSSL_ia32cap_P");
76 &bt
(&DWP
(0,"ecx"),4);
77 &jnc
(&label
("nohalt")); # no TSC
79 &data_word
(0x9058900e); # push %cs; pop %eax
81 &jnz
(&label
("nohalt")); # not enough privileges
86 &jnc
(&label
("nohalt")); # interrupts are disabled
94 &sub ("eax",&DWP
(0,"esp"));
95 &sbb
("edx",&DWP
(4,"esp"));
103 &function_end_B
("OPENSSL_instrument_halt");
105 # Essentially there is only one use for this function. Under DJGPP:
109 # i=OPENSSL_far_spin(_dos_ds,0x46c);
111 # to obtain the number of spins till closest timer interrupt.
113 &function_begin_B
("OPENSSL_far_spin");
117 &jnc
(&label
("nospin")); # interrupts are disabled
119 &mov
("eax",&DWP
(4,"esp"));
120 &mov
("ecx",&DWP
(8,"esp"));
121 &data_word
(0x90d88e1e); # push %ds, mov %eax,%ds
123 &mov
("edx",&DWP
(0,"ecx"));
124 &jmp
(&label
("spin"));
129 &cmp ("edx",&DWP
(0,"ecx"));
130 &je
(&label
("spin"));
132 &data_word
(0x1f909090); # pop %ds
135 &set_label
("nospin");
139 &function_end_B
("OPENSSL_far_spin");
141 &function_begin_B
("OPENSSL_wipe_cpu","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
144 &picmeup
("ecx","OPENSSL_ia32cap_P");
145 &mov
("ecx",&DWP
(0,"ecx"));
146 &bt
(&DWP
(0,"ecx"),1);
147 &jnc
(&label
("no_x87"));
149 &bt
(&DWP
(0,"ecx"),26);
150 &jnc
(&label
("no_sse2"));
151 &pxor
("xmm0","xmm0");
152 &pxor
("xmm1","xmm1");
153 &pxor
("xmm2","xmm2");
154 &pxor
("xmm3","xmm3");
155 &pxor
("xmm4","xmm4");
156 &pxor
("xmm5","xmm5");
157 &pxor
("xmm6","xmm6");
158 &pxor
("xmm7","xmm7");
159 &set_label
("no_sse2");
161 # just a bunch of fldz to zap the fp/mm bank followed by finit...
162 &data_word
(0xeed9eed9,0xeed9eed9,0xeed9eed9,0xeed9eed9,0x90e3db9b);
163 &set_label
("no_x87");
164 &lea
("eax",&DWP
(4,"esp"));
166 &function_end_B
("OPENSSL_wipe_cpu");
168 &function_begin_B
("OPENSSL_atomic_add");
169 &mov
("edx",&DWP
(4,"esp")); # fetch the pointer, 1st arg
170 &mov
("ecx",&DWP
(8,"esp")); # fetch the increment, 2nd arg
173 &mov
("eax",&DWP
(0,"edx"));
175 &lea
("ebx",&DWP
(0,"eax","ecx"));
177 &data_word
(0x1ab10ff0); # lock; cmpxchg %ebx,(%edx) # %eax is envolved and is always reloaded
178 &jne
(&label
("spin"));
179 &mov
("eax","ebx"); # OpenSSL expects the new value
182 &function_end_B
("OPENSSL_atomic_add");
184 # This function can become handy under Win32 in situations when
185 # we don't know which calling convention, __stdcall or __cdecl(*),
186 # indirect callee is using. In C it can be deployed as
188 #ifdef OPENSSL_CPUID_OBJ
189 # type OPENSSL_indirect_call(void *f,...);
191 # OPENSSL_indirect_call(func,[up to $max arguments]);
194 # (*) it's designed to work even for __fastcall if number of
195 # arguments is 1 or 2!
196 &function_begin_B
("OPENSSL_indirect_call");
198 my $i,$max=7; # $max has to be chosen as 4*n-1
199 # in order to preserve eventual
204 &mov
("ecx",&DWP
(12,"ebp"));
205 &mov
(&DWP
(0,"esp"),"ecx");
206 &mov
("edx",&DWP
(16,"ebp"));
207 &mov
(&DWP
(4,"esp"),"edx");
208 for($i=2;$i<$max;$i++)
210 # Some copies will be redundant/bogus...
211 &mov
("eax",&DWP
(12+$i*4,"ebp"));
212 &mov
(&DWP
(0+$i*4,"esp"),"eax");
214 &call_ptr
(&DWP
(8,"ebp"));# make the call...
215 &mov
("esp","ebp"); # ... and just restore the stack pointer
216 # without paying attention to what we called,
217 # (__cdecl *func) or (__stdcall *one).
221 &function_end_B
("OPENSSL_indirect_call");
223 &function_begin_B
("OPENSSL_cleanse");
224 &mov
("edx",&wparam
(0));
225 &mov
("ecx",&wparam
(1));
228 &jae
(&label
("lot"));
229 &set_label
("little");
230 &mov
(&BP
(0,"edx"),"al");
232 &lea
("edx",&DWP
(1,"edx"));
233 &jnz
(&label
("little"));
236 &set_label
("lot",16);
238 &jz
(&label
("aligned"));
239 &mov
(&BP
(0,"edx"),"al");
240 &lea
("ecx",&DWP
(-1,"ecx"));
241 &lea
("edx",&DWP
(1,"edx"));
242 &jmp
(&label
("lot"));
243 &set_label
("aligned");
244 &mov
(&DWP
(0,"edx"),"eax");
245 &lea
("ecx",&DWP
(-4,"ecx"));
247 &lea
("edx",&DWP
(4,"edx"));
248 &jnz
(&label
("aligned"));
250 &jne
(&label
("little"));
252 &function_end_B
("OPENSSL_cleanse");
254 &initseg
("OPENSSL_cpuid_setup");