1 ! Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
3 ! Licensed under the OpenSSL license (the "License"). You may not use
4 ! this file except in compliance with the License. You can obtain a copy
5 ! in the file LICENSE in the source distribution or at
6 ! https://www.openssl.org/source/license.html
8 #ifdef OPENSSL_FIPSCANISTER
9 #include <openssl/fipssyms.h>
12 #if defined(__SUNPRO_C) && defined(__sparcv9)
13 # define ABI64 /* They've said -xarch=v9 at command line */
14 #elif defined(__GNUC__) && defined(__arch64__)
15 # define ABI64 /* They've said -m64 at command line */
19 .register %g2,#scratch
20 .register %g3,#scratch
30 .global OPENSSL_wipe_cpu
31 .type OPENSSL_wipe_cpu,#function
32 ! Keep in mind that this does not excuse us from wiping the stack!
33 ! This routine wipes registers, but not the backing store [which
34 ! resides on the stack, toward lower addresses]. To facilitate for
35 ! stack wiping I return pointer to the top of stack of the *caller*.
52 ! Following is V9 "rd %ccr,%o0" instruction. However! V8
53 ! specification says that it ("rd %asr2,%o0" in V8 terms) does
54 ! not cause illegal_instruction trap. It therefore can be used
55 ! to determine if the CPU the code is executing on is V8- or
56 ! V9-compliant, as V9 returns a distinct value of 0x99,
57 ! "negative" and "borrow" bits set in both %icc and %xcc.
58 .word 0x91408000 !rd %ccr,%o0
62 ! Even though we do not use %fp register bank,
63 ! we wipe it as memcpy might have used it...
64 .word 0xbfa00040 !fmovd %f0,%f62
79 .word 0x83a00040 !fmovd %f0,%f32
137 add %fp,BIAS,%i0 ! return pointer to callerĀ“s top of stack
147 .global walk_reg_wins
148 .type walk_reg_wins,#function
156 cmp %o7,0 ! compiler never cleans %o7...
157 be 1f ! could have been a leaf function...
174 add %o0,1,%i0 ! used for debugging
177 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
179 .global OPENSSL_atomic_add
180 .type OPENSSL_atomic_add,#function
185 .word 0x95408000 !rd %ccr,%o2, see comment above
193 ! Note that you do not have to link with libthread to call thr_yield,
194 ! as libc provides a stub, which is overloaded the moment you link
195 ! with *either* libpthread or libthread...
196 #define YIELD_CPU thr_yield
198 ! applies at least to Linux and FreeBSD... Feedback expected...
199 #define YIELD_CPU sched_yield
201 .spin: call YIELD_CPU
220 .word 0xd7e2100a !cas [%o0],%o2,%o3, compare [%o0] with %o2 and swap %o3
223 mov %o3,%o2 ! cas is always fetching to dest. register
224 add %o1,%o2,%o0 ! OpenSSL expects the new value
226 sra %o0,%g0,%o0 ! we return signed int, remember?
227 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
229 .global _sparcv9_rdtick
233 .word 0x91408000 !rd %ccr,%o0
237 .word 0x91410000 !rd %tick,%o0
239 .word 0x93323020 !srlx %o0,32,%o1
243 .type _sparcv9_rdtick,#function
244 .size _sparcv9_rdtick,.-_sparcv9_rdtick
246 .global _sparcv9_vis1_probe
250 .word 0xc19a5a40 !ldda [%o1]ASI_FP16_P,%f0
252 .word 0x81b00d80 !fxor %f0,%f0,%f0
253 .type _sparcv9_vis1_probe,#function
254 .size _sparcv9_vis1_probe,.-_sparcv9_vis1_probe
256 ! Probe and instrument VIS1 instruction. Output is number of cycles it
257 ! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
258 ! is slow (documented to be 6 cycles on T2) and the core is in-order
259 ! single-issue, it should be possible to distinguish Tx reliably...
260 ! Observed return values are:
267 ! (*) result has lesser to do with VIS instruction latencies, rdtick
268 ! appears that slow, but it does the trick in sense that FP and
269 ! VIS code paths are still slower than integer-only ones.
271 ! Numbers for T2 and SPARC64 V-VII are more than welcomed.
273 ! It would be possible to detect specifically US-T1 by instrumenting
274 ! fmul8ulx16, which is emulated on T1 and as such accounts for quite
275 ! a lot of %tick-s, couple of thousand on Linux...
276 .global _sparcv9_vis1_instrument
278 _sparcv9_vis1_instrument:
279 .word 0x81b00d80 !fxor %f0,%f0,%f0
280 .word 0x85b08d82 !fxor %f2,%f2,%f2
281 .word 0x91410000 !rd %tick,%o0
282 .word 0x81b00d80 !fxor %f0,%f0,%f0
283 .word 0x85b08d82 !fxor %f2,%f2,%f2
284 .word 0x93410000 !rd %tick,%o1
285 .word 0x81b00d80 !fxor %f0,%f0,%f0
286 .word 0x85b08d82 !fxor %f2,%f2,%f2
287 .word 0x95410000 !rd %tick,%o2
288 .word 0x81b00d80 !fxor %f0,%f0,%f0
289 .word 0x85b08d82 !fxor %f2,%f2,%f2
290 .word 0x97410000 !rd %tick,%o3
291 .word 0x81b00d80 !fxor %f0,%f0,%f0
292 .word 0x85b08d82 !fxor %f2,%f2,%f2
293 .word 0x99410000 !rd %tick,%o4
295 ! calculate intervals
303 .word 0x38680002 !bgu,a %xcc,.+8
306 .word 0x38680002 !bgu,a %xcc,.+8
309 .word 0x38680002 !bgu,a %xcc,.+8
314 .type _sparcv9_vis1_instrument,#function
315 .size _sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
317 .global _sparcv9_vis2_probe
321 .word 0x81b00980 !bshuffle %f0,%f0,%f0
322 .type _sparcv9_vis2_probe,#function
323 .size _sparcv9_vis2_probe,.-_sparcv9_vis2_probe
325 .global _sparcv9_fmadd_probe
327 _sparcv9_fmadd_probe:
328 .word 0x81b00d80 !fxor %f0,%f0,%f0
329 .word 0x85b08d82 !fxor %f2,%f2,%f2
331 .word 0x81b80440 !fmaddd %f0,%f0,%f2,%f0
332 .type _sparcv9_fmadd_probe,#function
333 .size _sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
335 .global _sparcv9_rdcfr
339 .word 0x91468000 !rd %asr26,%o0
340 .type _sparcv9_rdcfr,#function
341 .size _sparcv9_rdcfr,.-_sparcv9_rdcfr
343 .global _sparcv9_vis3_probe
347 .word 0x81b022a0 !xmulx %g0,%g0,%g0
348 .type _sparcv9_vis3_probe,#function
349 .size _sparcv9_vis3_probe,.-_sparcv9_vis3_probe
351 .global _sparcv9_random
355 .word 0x91b002a0 !random %o0
356 .type _sparcv9_random,#function
357 .size _sparcv9_random,.-_sparcv9_vis3_probe
359 .global _sparcv9_fjaesx_probe
361 _sparcv9_fjaesx_probe:
362 .word 0x81b09206 !faesencx %f2,%f6,%f0
365 .size _sparcv9_fjaesx_probe,.-_sparcv9_fjaesx_probe
367 .global OPENSSL_cleanse
394 ! see above for explanation
395 .word 0x83408000 !rd %ccr,%g1
401 .v9lot: andcc %o0,7,%g0
410 .word 0xc0720000 !stx %g0,[%o0]
414 .word 0x126ffffd !bnz %xcc,.v9aligned
416 .word 0x124ffffd !bnz %icc,.v9aligned
426 .v8lot: andcc %o0,3,%g0
447 .type OPENSSL_cleanse,#function
448 .size OPENSSL_cleanse,.-OPENSSL_cleanse
450 .global CRYPTO_memcmp
455 beq,pn %xcc,.Lno_data
481 .type CRYPTO_memcmp,#function
482 .size CRYPTO_memcmp,.-CRYPTO_memcmp
484 .global _sparcv9_vis1_instrument_bus
486 _sparcv9_vis1_instrument_bus:
487 mov %o1,%o3 ! save cnt
488 .word 0x99410000 !rd %tick,%o4 ! tick
489 mov %o4,%o5 ! lasttick = tick
493 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
494 .word 0x8143e040 !membar #Sync
495 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
496 .word 0x8143e040 !membar #Sync
499 .word 0xc9e2100c !cas [%o0],%o4,%g4
501 .Loop: .word 0x99410000 !rd %tick,%o4
502 sub %o4,%o5,%g4 ! diff=tick-lasttick
503 mov %o4,%o5 ! lasttick=tick
506 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
507 .word 0x8143e040 !membar #Sync
508 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
509 .word 0x8143e040 !membar #Sync
512 .word 0xc9e2100c !cas [%o0],%o4,%g4
513 subcc %o1,1,%o1 ! --$cnt
515 add %o0,4,%o0 ! ++$out
519 .type _sparcv9_vis1_instrument_bus,#function
520 .size _sparcv9_vis1_instrument_bus,.-_sparcv9_vis1_instrument_bus
522 .global _sparcv9_vis1_instrument_bus2
524 _sparcv9_vis1_instrument_bus2:
525 mov %o1,%o3 ! save cnt
526 sll %o1,2,%o1 ! cnt*=4
528 .word 0x99410000 !rd %tick,%o4 ! tick
529 mov %o4,%o5 ! lasttick = tick
533 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
534 .word 0x8143e040 !membar #Sync
535 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
536 .word 0x8143e040 !membar #Sync
539 .word 0xc9e2100c !cas [%o0],%o4,%g4
541 .word 0x99410000 !rd %tick,%o4 ! tick
542 sub %o4,%o5,%g4 ! diff=tick-lasttick
543 mov %o4,%o5 ! lasttick=tick
544 mov %g4,%g5 ! lastdiff=diff
547 .word 0xc1985e00 !ldda [%g1]0xf0,%f0 ! block load
548 .word 0x8143e040 !membar #Sync
549 .word 0xc1b85c00 !stda %f0,[%g1]0xe0 ! block store and commit
550 .word 0x8143e040 !membar #Sync
553 .word 0xc9e2100c !cas [%o0],%o4,%g4
555 subcc %o2,1,%o2 ! --max
559 .word 0x99410000 !rd %tick,%o4 ! tick
560 sub %o4,%o5,%g4 ! diff=tick-lasttick
561 mov %o4,%o5 ! lasttick=tick
563 mov %g4,%g5 ! lastdiff=diff
565 .word 0x83408000 !rd %ccr,%g1
566 and %g1,4,%g1 ! isolate zero flag
567 xor %g1,4,%g1 ! flip zero flag
569 subcc %o1,%g1,%o1 ! conditional --$cnt
571 add %o0,%g1,%o0 ! conditional ++$out
577 .type _sparcv9_vis1_instrument_bus2,#function
578 .size _sparcv9_vis1_instrument_bus2,.-_sparcv9_vis1_instrument_bus2
580 .section ".init",#alloc,#execinstr
581 call OPENSSL_cpuid_setup