1 #ifdef OPENSSL_FIPSCANISTER
2 #include <openssl/fipssyms.h>
5 #if defined(__SUNPRO_C) && defined(__sparcv9)
6 # define ABI64 /* They've said -xarch=v9 at command line */
7 #elif defined(__GNUC__) && defined(__arch64__)
8 # define ABI64 /* They've said -m64 at command line */
12 .register %g2,#scratch
13 .register %g3,#scratch
23 .global OPENSSL_wipe_cpu
24 .type OPENSSL_wipe_cpu,#function
25 ! Keep in mind that this does not excuse us from wiping the stack!
26 ! This routine wipes registers, but not the backing store [which
27 ! resides on the stack, toward lower addresses]. To facilitate for
28 ! stack wiping I return pointer to the top of stack of the *caller*.
45 ! Following is V9 "rd %ccr,%o0" instruction. However! V8
46 ! specification says that it ("rd %asr2,%o0" in V8 terms) does
47 ! not cause illegal_instruction trap. It therefore can be used
48 ! to determine if the CPU the code is executing on is V8- or
49 ! V9-compliant, as V9 returns a distinct value of 0x99,
50 ! "negative" and "borrow" bits set in both %icc and %xcc.
51 .word 0x91408000 !rd %ccr,%o0
55 ! Even though we do not use %fp register bank,
56 ! we wipe it as memcpy might have used it...
57 .word 0xbfa00040 !fmovd %f0,%f62
72 .word 0x83a00040 !fmovd %f0,%f32
130 add %fp,BIAS,%i0 ! return pointer to callerĀ“s top of stack
140 .global walk_reg_wins
141 .type walk_reg_wins,#function
149 cmp %o7,0 ! compiler never cleans %o7...
150 be 1f ! could have been a leaf function...
167 add %o0,1,%i0 ! used for debugging
170 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
172 .global OPENSSL_atomic_add
173 .type OPENSSL_atomic_add,#function
178 .word 0x95408000 !rd %ccr,%o2, see comment above
186 ! Note that you do not have to link with libthread to call thr_yield,
187 ! as libc provides a stub, which is overloaded the moment you link
188 ! with *either* libpthread or libthread...
189 #define YIELD_CPU thr_yield
191 ! applies at least to Linux and FreeBSD... Feedback expected...
192 #define YIELD_CPU sched_yield
194 .spin: call YIELD_CPU
213 .word 0xd7e2100a !cas [%o0],%o2,%o3, compare [%o0] with %o2 and swap %o3
216 mov %o3,%o2 ! cas is always fetching to dest. register
217 add %o1,%o2,%o0 ! OpenSSL expects the new value
219 sra %o0,%g0,%o0 ! we return signed int, remember?
220 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
222 .global _sparcv9_rdtick
226 .word 0x91408000 !rd %ccr,%o0
230 .word 0x91410000 !rd %tick,%o0
232 .word 0x93323020 !srlx %o0,32,%o1
236 .type _sparcv9_rdtick,#function
237 .size _sparcv9_rdtick,.-_sparcv9_rdtick
239 .global _sparcv9_vis1_probe
242 .word 0x81b00d80 !fxor %f0,%f0,%f0
245 .word 0xc19a5a40 !ldda [%o1]ASI_FP16_P,%f0
246 .type _sparcv9_vis1_probe,#function
247 .size _sparcv9_vis1_probe,.-_sparcv9_vis1_probe
249 ! Probe and instrument VIS1 instruction. Output is number of cycles it
250 ! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
251 ! is slow (documented to be 6 cycles on T2) and the core is in-order
252 ! single-issue, it should be possible to distinguish Tx reliably...
253 ! Observed return values are:
259 ! Numbers for T2 and SPARC64 V-VII are more than welcomed.
261 ! It would be possible to detect specifically US-T1 by instrumenting
262 ! fmul8ulx16, which is emulated on T1 and as such accounts for quite
263 ! a lot of %tick-s, couple of thousand on Linux...
264 .global _sparcv9_vis1_instrument
266 _sparcv9_vis1_instrument:
267 .word 0x91410000 !rd %tick,%o0
268 .word 0x81b00d80 !fxor %f0,%f0,%f0
269 .word 0x85b08d82 !fxor %f2,%f2,%f2
270 .word 0x93410000 !rd %tick,%o1
271 .word 0x81b00d80 !fxor %f0,%f0,%f0
272 .word 0x85b08d82 !fxor %f2,%f2,%f2
273 .word 0x95410000 !rd %tick,%o2
274 .word 0x81b00d80 !fxor %f0,%f0,%f0
275 .word 0x85b08d82 !fxor %f2,%f2,%f2
276 .word 0x97410000 !rd %tick,%o3
277 .word 0x81b00d80 !fxor %f0,%f0,%f0
278 .word 0x85b08d82 !fxor %f2,%f2,%f2
279 .word 0x99410000 !rd %tick,%o4
281 ! calculate intervals
289 .word 0x38680002 !bgu,a %xcc,.+8
292 .word 0x38680002 !bgu,a %xcc,.+8
295 .word 0x38680002 !bgu,a %xcc,.+8
300 .type _sparcv9_vis1_instrument,#function
301 .size _sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
303 .global _sparcv9_vis2_probe
307 .word 0x81b00980 !bshuffle %f0,%f0,%f0
308 .type _sparcv9_vis2_probe,#function
309 .size _sparcv9_vis2_probe,.-_sparcv9_vis2_probe
311 .global _sparcv9_fmadd_probe
313 _sparcv9_fmadd_probe:
314 .word 0x81b00d80 !fxor %f0,%f0,%f0
315 .word 0x85b08d82 !fxor %f2,%f2,%f2
317 .word 0x81b80440 !fmaddd %f0,%f0,%f2,%f0
318 .type _sparcv9_fmadd_probe,#function
319 .size _sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
321 .global OPENSSL_cleanse
348 ! see above for explanation
349 .word 0x83408000 !rd %ccr,%g1
355 .v9lot: andcc %o0,7,%g0
364 .word 0xc0720000 !stx %g0,[%o0]
368 .word 0x126ffffd !bnz %xcc,.v9aligned
370 .word 0x124ffffd !bnz %icc,.v9aligned
380 .v8lot: andcc %o0,3,%g0
401 .type OPENSSL_cleanse,#function
402 .size OPENSSL_cleanse,.-OPENSSL_cleanse
404 .global _sparcv9_vis1_instrument_bus
406 _sparcv9_vis1_instrument_bus:
407 mov %o1,%o3 ! save cnt
408 .word 0x99410000 !rd %tick,%o4 ! tick
409 mov %o4,%o5 ! lasttick = tick
413 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
414 .word 0x8143e040 !membar #Sync
415 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
416 .word 0x8143e040 !membar #Sync
419 .word 0xc9e2100c !cas [%o0],%o4,%g4
421 .Loop: .word 0x99410000 !rd %tick,%o4
422 sub %o4,%o5,%g4 ! diff=tick-lasttick
423 mov %o4,%o5 ! lasttick=tick
426 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
427 .word 0x8143e040 !membar #Sync
428 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
429 .word 0x8143e040 !membar #Sync
432 .word 0xc9e2100c !cas [%o0],%o4,%g4
433 subcc %o1,1,%o1 ! --$cnt
435 add %o0,4,%o0 ! ++$out
439 .type _sparcv9_vis1_instrument_bus,#function
440 .size _sparcv9_vis1_instrument_bus,.-_sparcv9_vis1_instrument_bus
442 .global _sparcv9_vis1_instrument_bus2
444 _sparcv9_vis1_instrument_bus2:
445 mov %o1,%o3 ! save cnt
446 sll %o1,2,%o1 ! cnt*=4
448 .word 0x99410000 !rd %tick,%o4 ! tick
449 mov %o4,%o5 ! lasttick = tick
453 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
454 .word 0x8143e040 !membar #Sync
455 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
456 .word 0x8143e040 !membar #Sync
459 .word 0xc9e2100c !cas [%o0],%o4,%g4
461 .word 0x99410000 !rd %tick,%o4 ! tick
462 sub %o4,%o5,%g4 ! diff=tick-lasttick
463 mov %o4,%o5 ! lasttick=tick
464 mov %g4,%g5 ! lastdiff=diff
467 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
468 .word 0x8143e040 !membar #Sync
469 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
470 .word 0x8143e040 !membar #Sync
473 .word 0xc9e2100c !cas [%o0],%o4,%g4
475 subcc %o2,1,%o2 ! --max
479 .word 0x99410000 !rd %tick,%o4 ! tick
480 sub %o4,%o5,%g4 ! diff=tick-lasttick
481 mov %o4,%o5 ! lasttick=tick
483 mov %g4,%g5 ! lastdiff=diff
485 .word 0x83408000 !rd %ccr,%g1
486 and %g1,4,%g1 ! isolate zero flag
487 xor %g1,4,%g1 ! flip zero flag
489 subcc %o1,%g1,%o1 ! conditional --$cnt
491 add %o0,%g1,%o0 ! conditional ++$out
497 .type _sparcv9_vis1_instrument_bus2,#function
498 .size _sparcv9_vis1_instrument_bus2,.-_sparcv9_vis1_instrument_bus2
500 .section ".init",#alloc,#execinstr
501 call OPENSSL_cpuid_setup