1#include "s390x_arch.h" 2 3.text 4 5.globl OPENSSL_s390x_facilities 6.type OPENSSL_s390x_facilities,@function 7.align 16 8OPENSSL_s390x_facilities: 9 lghi %r0,0 10 larl %r4,OPENSSL_s390xcap_P 11 12 stg %r0,S390X_STFLE+8(%r4) # wipe capability vectors 13 stg %r0,S390X_STFLE+16(%r4) 14 stg %r0,S390X_STFLE+24(%r4) 15 16 .long 0xb2b04000 # stfle 0(%r4) 17 brc 8,.Ldone 18 lghi %r0,1 19 .long 0xb2b04000 # stfle 0(%r4) 20 brc 8,.Ldone 21 lghi %r0,2 22 .long 0xb2b04000 # stfle 0(%r4) 23.Ldone: 24 br %r14 25.size OPENSSL_s390x_facilities,.-OPENSSL_s390x_facilities 26 27.globl OPENSSL_s390x_functions 28.type OPENSSL_s390x_functions,@function 29.align 16 30OPENSSL_s390x_functions: 31 lghi %r0,0 32 larl %r4,OPENSSL_s390xcap_P 33 34 stg %r0,S390X_KIMD(%r4) # wipe capability vectors 35 stg %r0,S390X_KIMD+8(%r4) 36 stg %r0,S390X_KLMD(%r4) 37 stg %r0,S390X_KLMD+8(%r4) 38 stg %r0,S390X_KM(%r4) 39 stg %r0,S390X_KM+8(%r4) 40 stg %r0,S390X_KMC(%r4) 41 stg %r0,S390X_KMC+8(%r4) 42 stg %r0,S390X_KMAC(%r4) 43 stg %r0,S390X_KMAC+8(%r4) 44 stg %r0,S390X_KMCTR(%r4) 45 stg %r0,S390X_KMCTR+8(%r4) 46 stg %r0,S390X_KMO(%r4) 47 stg %r0,S390X_KMO+8(%r4) 48 stg %r0,S390X_KMF(%r4) 49 stg %r0,S390X_KMF+8(%r4) 50 stg %r0,S390X_PRNO(%r4) 51 stg %r0,S390X_PRNO+8(%r4) 52 stg %r0,S390X_KMA(%r4) 53 stg %r0,S390X_KMA+8(%r4) 54 stg %r0,S390X_PCC(%r4) 55 stg %r0,S390X_PCC+8(%r4) 56 stg %r0,S390X_KDSA(%r4) 57 stg %r0,S390X_KDSA+8(%r4) 58 59 lmg %r2,%r3,S390X_STFLE(%r4) 60 61 tmhl %r2,0x4000 # check for message-security-assist 62 jz .Lret 63 64 lghi %r0,S390X_QUERY # query kimd capabilities 65 la %r1,S390X_KIMD(%r4) 66 .long 0xb93e0002 # kimd %r0,%r2 67 68 lghi %r0,S390X_QUERY # query klmd capabilities 69 la %r1,S390X_KLMD(%r4) 70 .long 0xb93f0002 # klmd %r0,%r2 71 72 lghi %r0,S390X_QUERY # query km capability vector 73 la %r1,S390X_KM(%r4) 74 .long 0xb92e0042 # km %r4,%r2 75 76 lghi %r0,S390X_QUERY # query kmc capability vector 77 la %r1,S390X_KMC(%r4) 78 .long 0xb92f0042 # kmc %r4,%r2 79 80 lghi %r0,S390X_QUERY # query kmac capability vector 81 la %r1,S390X_KMAC(%r4) 82 .long 0xb91e0042 # kmac %r4,%r2 83 84 tmhh %r3,0x0008 # check for message-security-assist-3 85 jz .Lret 86 87 lghi %r0,S390X_QUERY # query pcc capability vector 88 la %r1,S390X_PCC(%r4) 89 .long 0xb92c0000 # pcc 90 91 tmhh %r3,0x0004 # check for message-security-assist-4 92 jz .Lret 93 94 lghi %r0,S390X_QUERY # query kmctr capability vector 95 la %r1,S390X_KMCTR(%r4) 96 .long 0xb92d2042 # kmctr %r4,%r2,%r2 97 98 lghi %r0,S390X_QUERY # query kmo capability vector 99 la %r1,S390X_KMO(%r4) 100 .long 0xb92b0042 # kmo %r4,%r2 101 102 lghi %r0,S390X_QUERY # query kmf capability vector 103 la %r1,S390X_KMF(%r4) 104 .long 0xb92a0042 # kmf %r4,%r2 105 106 tml %r2,0x40 # check for message-security-assist-5 107 jz .Lret 108 109 lghi %r0,S390X_QUERY # query prno capability vector 110 la %r1,S390X_PRNO(%r4) 111 .long 0xb93c0042 # prno %r4,%r2 112 113 lg %r2,S390X_STFLE+16(%r4) 114 115 tmhl %r2,0x2000 # check for message-security-assist-8 116 jz .Lret 117 118 lghi %r0,S390X_QUERY # query kma capability vector 119 la %r1,S390X_KMA(%r4) 120 .long 0xb9294022 # kma %r2,%r4,%r2 121 122 tmhl %r2,0x0010 # check for message-security-assist-9 123 jz .Lret 124 125 lghi %r0,S390X_QUERY # query kdsa capability vector 126 la %r1,S390X_KDSA(%r4) 127 .long 0xb93a0002 # kdsa %r0,%r2 128 129.Lret: 130 br %r14 131.size OPENSSL_s390x_functions,.-OPENSSL_s390x_functions 132 133.globl OPENSSL_rdtsc 134.type OPENSSL_rdtsc,@function 135.align 16 136OPENSSL_rdtsc: 137 larl %r4,OPENSSL_s390xcap_P 138 tm S390X_STFLE+3(%r4),0x40 # check for store-clock-fast facility 139 jz .Lstck 140 141 .long 0xb27cf010 # stckf 16(%r15) 142 lg %r2,16(%r15) 143 br %r14 144.Lstck: 145 stck 16(%r15) 146 lg %r2,16(%r15) 147 br %r14 148.size OPENSSL_rdtsc,.-OPENSSL_rdtsc 149 150.globl OPENSSL_atomic_add 151.type OPENSSL_atomic_add,@function 152.align 16 153OPENSSL_atomic_add: 154 l %r1,0(%r2) 155.Lspin: lr %r0,%r1 156 ar %r0,%r3 157 cs %r1,%r0,0(%r2) 158 brc 4,.Lspin 159 lgfr %r2,%r0 # OpenSSL expects the new value 160 br %r14 161.size OPENSSL_atomic_add,.-OPENSSL_atomic_add 162 163.globl OPENSSL_wipe_cpu 164.type OPENSSL_wipe_cpu,@function 165.align 16 166OPENSSL_wipe_cpu: 167 xgr %r0,%r0 168 xgr %r1,%r1 169 lgr %r2,%r15 170 xgr %r3,%r3 171 xgr %r4,%r4 172 lzdr %f0 173 lzdr %f1 174 lzdr %f2 175 lzdr %f3 176 lzdr %f4 177 lzdr %f5 178 lzdr %f6 179 lzdr %f7 180 br %r14 181.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu 182 183.globl OPENSSL_cleanse 184.type OPENSSL_cleanse,@function 185.align 16 186OPENSSL_cleanse: 187#if !defined(__s390x__) && !defined(__s390x) 188 llgfr %r3,%r3 189#endif 190 lghi %r4,15 191 lghi %r0,0 192 clgr %r3,%r4 193 jh .Lot 194 clgr %r3,%r0 195 bcr 8,%r14 196.Little: 197 stc %r0,0(%r2) 198 la %r2,1(%r2) 199 brctg %r3,.Little 200 br %r14 201.align 4 202.Lot: tmll %r2,7 203 jz .Laligned 204 stc %r0,0(%r2) 205 la %r2,1(%r2) 206 brctg %r3,.Lot 207.Laligned: 208 srlg %r4,%r3,3 209.Loop: stg %r0,0(%r2) 210 la %r2,8(%r2) 211 brctg %r4,.Loop 212 lghi %r4,7 213 ngr %r3,%r4 214 jnz .Little 215 br %r14 216.size OPENSSL_cleanse,.-OPENSSL_cleanse 217 218.globl CRYPTO_memcmp 219.type CRYPTO_memcmp,@function 220.align 16 221CRYPTO_memcmp: 222#if !defined(__s390x__) && !defined(__s390x) 223 llgfr %r4,%r4 224#endif 225 lghi %r5,0 226 clgr %r4,%r5 227 je .Lno_data 228 229.Loop_cmp: 230 llgc %r0,0(%r2) 231 la %r2,1(%r2) 232 llgc %r1,0(%r3) 233 la %r3,1(%r3) 234 xr %r1,%r0 235 or %r5,%r1 236 brctg %r4,.Loop_cmp 237 238 lnr %r5,%r5 239 srl %r5,31 240.Lno_data: 241 lgr %r2,%r5 242 br %r14 243.size CRYPTO_memcmp,.-CRYPTO_memcmp 244 245.globl OPENSSL_instrument_bus 246.type OPENSSL_instrument_bus,@function 247.align 16 248OPENSSL_instrument_bus: 249 lghi %r2,0 250 br %r14 251.size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus 252 253.globl OPENSSL_instrument_bus2 254.type OPENSSL_instrument_bus2,@function 255.align 16 256OPENSSL_instrument_bus2: 257 lghi %r2,0 258 br %r14 259.size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2 260 261.globl OPENSSL_vx_probe 262.type OPENSSL_vx_probe,@function 263.align 16 264OPENSSL_vx_probe: 265 .word 0xe700,0x0000,0x0044 # vzero %v0 266 br %r14 267.size OPENSSL_vx_probe,.-OPENSSL_vx_probe 268.globl s390x_kimd 269.type s390x_kimd,@function 270.align 16 271s390x_kimd: 272 llgfr %r0,%r4 273 lgr %r1,%r5 274 275 .long 0xb93e0002 # kimd %r0,%r2 276 brc 1,.-4 # pay attention to "partial completion" 277 278 br %r14 279.size s390x_kimd,.-s390x_kimd 280.globl s390x_klmd 281.type s390x_klmd,@function 282.align 32 283s390x_klmd: 284 llgfr %r0,%r6 285 l %r1,96(%r15) 286 287 .long 0xb93f0042 # klmd %r4,%r2 288 brc 1,.-4 # pay attention to "partial completion" 289 290 br %r14 291.size s390x_klmd,.-s390x_klmd 292.globl s390x_km 293.type s390x_km,@function 294.align 16 295s390x_km: 296 lr %r0,%r5 297 lr %r1,%r6 298 299 .long 0xb92e0042 # km %r4,%r2 300 brc 1,.-4 # pay attention to "partial completion" 301 302 br %r14 303.size s390x_km,.-s390x_km 304.globl s390x_kmac 305.type s390x_kmac,@function 306.align 16 307s390x_kmac: 308 lr %r0,%r4 309 lr %r1,%r5 310 311 .long 0xb91e0002 # kmac %r0,%r2 312 brc 1,.-4 # pay attention to "partial completion" 313 314 br %r14 315.size s390x_kmac,.-s390x_kmac 316.globl s390x_kmo 317.type s390x_kmo,@function 318.align 16 319s390x_kmo: 320 lr %r0,%r5 321 lr %r1,%r6 322 323 .long 0xb92b0042 # kmo %r4,%r2 324 brc 1,.-4 # pay attention to "partial completion" 325 326 br %r14 327.size s390x_kmo,.-s390x_kmo 328.globl s390x_kmf 329.type s390x_kmf,@function 330.align 16 331s390x_kmf: 332 lr %r0,%r5 333 lr %r1,%r6 334 335 .long 0xb92a0042 # kmf %r4,%r2 336 brc 1,.-4 # pay attention to "partial completion" 337 338 br %r14 339.size s390x_kmf,.-s390x_kmf 340.globl s390x_kma 341.type s390x_kma,@function 342.align 16 343s390x_kma: 344 st %r6,6*4(%r15) 345 lm %r0,%r1,96(%r15) 346 347 .long 0xb9292064 # kma %r6,%r2,%r4 348 brc 1,.-4 # pay attention to "partial completion" 349 350 l %r6,6*4(%r15) 351 br %r14 352.size s390x_kma,.-s390x_kma 353.globl s390x_pcc 354.type s390x_pcc,@function 355.align 16 356s390x_pcc: 357 lr %r0,%r2 358 lr %r1,%r3 359 lhi %r2,0 360 361 .long 0xb92c0000 # pcc 362 brc 1,.-4 # pay attention to "partial completion" 363 brc 7,.Lpcc_err # if CC==0 return 0, else return 1 364.Lpcc_out: 365 br %r14 366.Lpcc_err: 367 lhi %r2,1 368 j .Lpcc_out 369.size s390x_pcc,.-s390x_pcc 370.globl s390x_kdsa 371.type s390x_kdsa,@function 372.align 16 373s390x_kdsa: 374 lr %r0,%r2 375 lr %r1,%r3 376 lhi %r2,0 377 378 .long 0xb93a0004 # kdsa %r0,%r4 379 brc 1,.-4 # pay attention to "partial completion" 380 brc 7,.Lkdsa_err # if CC==0 return 0, else return 1 381.Lkdsa_out: 382 br %r14 383.Lkdsa_err: 384 lhi %r2,1 385 j .Lkdsa_out 386.size s390x_kdsa,.-s390x_kdsa 387.globl s390x_flip_endian32 388.type s390x_flip_endian32,@function 389.align 16 390s390x_flip_endian32: 391 lrvg %r0,0(%r3) 392 lrvg %r1,8(%r3) 393 lrvg %r4,16(%r3) 394 lrvg %r5,24(%r3) 395 stg %r0,24(%r2) 396 stg %r1,16(%r2) 397 stg %r4,8(%r2) 398 stg %r5,0(%r2) 399 br %r14 400.size s390x_flip_endian32,.-s390x_flip_endian32 401.globl s390x_flip_endian64 402.type s390x_flip_endian64,@function 403.align 16 404s390x_flip_endian64: 405 stmg %r6,%r9,6*4(%r15) 406 407 lrvg %r0,0(%r3) 408 lrvg %r1,8(%r3) 409 lrvg %r4,16(%r3) 410 lrvg %r5,24(%r3) 411 lrvg %r6,32(%r3) 412 lrvg %r7,40(%r3) 413 lrvg %r8,48(%r3) 414 lrvg %r9,56(%r3) 415 stg %r0,56(%r2) 416 stg %r1,48(%r2) 417 stg %r4,40(%r2) 418 stg %r5,32(%r2) 419 stg %r6,24(%r2) 420 stg %r7,16(%r2) 421 stg %r8,8(%r2) 422 stg %r9,0(%r2) 423 424 lmg %r6,%r9,6*4(%r15) 425 br %r14 426.size s390x_flip_endian64,.-s390x_flip_endian64 427.section .init 428 brasl %r14,OPENSSL_cpuid_setup 429