A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
5.2 KiB

  1. #! /usr/bin/env perl
  2. # Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. $flavour = shift;
  9. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  10. ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
  11. ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
  12. die "can't locate ppc-xlate.pl";
  13. open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
  14. if ($flavour=~/64/) {
  15. $CMPLI="cmpldi";
  16. $SHRLI="srdi";
  17. $SIGNX="extsw";
  18. } else {
  19. $CMPLI="cmplwi";
  20. $SHRLI="srwi";
  21. $SIGNX="mr";
  22. }
  23. $code=<<___;
  24. .machine "any"
  25. .text
  26. .globl .OPENSSL_fpu_probe
  27. .align 4
  28. .OPENSSL_fpu_probe:
  29. fmr f0,f0
  30. blr
  31. .long 0
  32. .byte 0,12,0x14,0,0,0,0,0
  33. .size .OPENSSL_fpu_probe,.-.OPENSSL_fpu_probe
  34. .globl .OPENSSL_ppc64_probe
  35. .align 4
  36. .OPENSSL_ppc64_probe:
  37. fcfid f1,f1
  38. extrdi r0,r0,32,0
  39. blr
  40. .long 0
  41. .byte 0,12,0x14,0,0,0,0,0
  42. .size .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
  43. .globl .OPENSSL_altivec_probe
  44. .align 4
  45. .OPENSSL_altivec_probe:
  46. .long 0x10000484 # vor v0,v0,v0
  47. blr
  48. .long 0
  49. .byte 0,12,0x14,0,0,0,0,0
  50. .size .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
  51. .globl .OPENSSL_crypto207_probe
  52. .align 4
  53. .OPENSSL_crypto207_probe:
  54. lvx_u v0,0,r1
  55. vcipher v0,v0,v0
  56. blr
  57. .long 0
  58. .byte 0,12,0x14,0,0,0,0,0
  59. .size .OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe
  60. .globl .OPENSSL_madd300_probe
  61. .align 4
  62. .OPENSSL_madd300_probe:
  63. xor r0,r0,r0
  64. maddld r3,r0,r0,r0
  65. maddhdu r3,r0,r0,r0
  66. blr
  67. .long 0
  68. .byte 0,12,0x14,0,0,0,0,0
  69. .globl .OPENSSL_wipe_cpu
  70. .align 4
  71. .OPENSSL_wipe_cpu:
  72. xor r0,r0,r0
  73. fmr f0,f31
  74. fmr f1,f31
  75. fmr f2,f31
  76. mr r3,r1
  77. fmr f3,f31
  78. xor r4,r4,r4
  79. fmr f4,f31
  80. xor r5,r5,r5
  81. fmr f5,f31
  82. xor r6,r6,r6
  83. fmr f6,f31
  84. xor r7,r7,r7
  85. fmr f7,f31
  86. xor r8,r8,r8
  87. fmr f8,f31
  88. xor r9,r9,r9
  89. fmr f9,f31
  90. xor r10,r10,r10
  91. fmr f10,f31
  92. xor r11,r11,r11
  93. fmr f11,f31
  94. xor r12,r12,r12
  95. fmr f12,f31
  96. fmr f13,f31
  97. blr
  98. .long 0
  99. .byte 0,12,0x14,0,0,0,0,0
  100. .size .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
  101. .globl .OPENSSL_atomic_add
  102. .align 4
  103. .OPENSSL_atomic_add:
  104. Ladd: lwarx r5,0,r3
  105. add r0,r4,r5
  106. stwcx. r0,0,r3
  107. bne- Ladd
  108. $SIGNX r3,r0
  109. blr
  110. .long 0
  111. .byte 0,12,0x14,0,0,0,2,0
  112. .long 0
  113. .size .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
  114. .globl .OPENSSL_rdtsc
  115. .align 4
  116. .OPENSSL_rdtsc:
  117. ___
  118. $code.=<<___ if ($flavour =~ /64/);
  119. mftb r3
  120. ___
  121. $code.=<<___ if ($flavour !~ /64/);
  122. Loop_rdtsc:
  123. mftbu r5
  124. mftb r3
  125. mftbu r4
  126. cmplw r4,r5
  127. bne Loop_rdtsc
  128. ___
  129. $code.=<<___;
  130. blr
  131. .long 0
  132. .byte 0,12,0x14,0,0,0,0,0
  133. .size .OPENSSL_rdtsc,.-.OPENSSL_rdtsc
  134. .globl .OPENSSL_cleanse
  135. .align 4
  136. .OPENSSL_cleanse:
  137. $CMPLI r4,7
  138. li r0,0
  139. bge Lot
  140. $CMPLI r4,0
  141. beqlr-
  142. Little: mtctr r4
  143. stb r0,0(r3)
  144. addi r3,r3,1
  145. bdnz \$-8
  146. blr
  147. Lot: andi. r5,r3,3
  148. beq Laligned
  149. stb r0,0(r3)
  150. subi r4,r4,1
  151. addi r3,r3,1
  152. b Lot
  153. Laligned:
  154. $SHRLI r5,r4,2
  155. mtctr r5
  156. stw r0,0(r3)
  157. addi r3,r3,4
  158. bdnz \$-8
  159. andi. r4,r4,3
  160. bne Little
  161. blr
  162. .long 0
  163. .byte 0,12,0x14,0,0,0,2,0
  164. .long 0
  165. .size .OPENSSL_cleanse,.-.OPENSSL_cleanse
  166. globl .CRYPTO_memcmp
  167. .align 4
  168. .CRYPTO_memcmp:
  169. $CMPLI r5,0
  170. li r0,0
  171. beq Lno_data
  172. mtctr r5
  173. Loop_cmp:
  174. lbz r6,0(r3)
  175. addi r3,r3,1
  176. lbz r7,0(r4)
  177. addi r4,r4,1
  178. xor r6,r6,r7
  179. or r0,r0,r6
  180. bdnz Loop_cmp
  181. Lno_data:
  182. li r3,0
  183. sub r3,r3,r0
  184. extrwi r3,r3,1,0
  185. blr
  186. .long 0
  187. .byte 0,12,0x14,0,0,0,3,0
  188. .long 0
  189. .size .CRYPTO_memcmp,.-.CRYPTO_memcmp
  190. ___
  191. {
  192. my ($out,$cnt,$max)=("r3","r4","r5");
  193. my ($tick,$lasttick)=("r6","r7");
  194. my ($diff,$lastdiff)=("r8","r9");
  195. $code.=<<___;
  196. .globl .OPENSSL_instrument_bus
  197. .align 4
  198. .OPENSSL_instrument_bus:
  199. mtctr $cnt
  200. mftb $lasttick # collect 1st tick
  201. li $diff,0
  202. dcbf 0,$out # flush cache line
  203. lwarx $tick,0,$out # load and lock
  204. add $tick,$tick,$diff
  205. stwcx. $tick,0,$out
  206. stwx $tick,0,$out
  207. Loop: mftb $tick
  208. sub $diff,$tick,$lasttick
  209. mr $lasttick,$tick
  210. dcbf 0,$out # flush cache line
  211. lwarx $tick,0,$out # load and lock
  212. add $tick,$tick,$diff
  213. stwcx. $tick,0,$out
  214. stwx $tick,0,$out
  215. addi $out,$out,4 # ++$out
  216. bdnz Loop
  217. mr r3,$cnt
  218. blr
  219. .long 0
  220. .byte 0,12,0x14,0,0,0,2,0
  221. .long 0
  222. .size .OPENSSL_instrument_bus,.-.OPENSSL_instrument_bus
  223. .globl .OPENSSL_instrument_bus2
  224. .align 4
  225. .OPENSSL_instrument_bus2:
  226. mr r0,$cnt
  227. slwi $cnt,$cnt,2
  228. mftb $lasttick # collect 1st tick
  229. li $diff,0
  230. dcbf 0,$out # flush cache line
  231. lwarx $tick,0,$out # load and lock
  232. add $tick,$tick,$diff
  233. stwcx. $tick,0,$out
  234. stwx $tick,0,$out
  235. mftb $tick # collect 1st diff
  236. sub $diff,$tick,$lasttick
  237. mr $lasttick,$tick
  238. mr $lastdiff,$diff
  239. Loop2:
  240. dcbf 0,$out # flush cache line
  241. lwarx $tick,0,$out # load and lock
  242. add $tick,$tick,$diff
  243. stwcx. $tick,0,$out
  244. stwx $tick,0,$out
  245. addic. $max,$max,-1
  246. beq Ldone2
  247. mftb $tick
  248. sub $diff,$tick,$lasttick
  249. mr $lasttick,$tick
  250. cmplw 7,$diff,$lastdiff
  251. mr $lastdiff,$diff
  252. mfcr $tick # pull cr
  253. not $tick,$tick # flip bits
  254. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  255. sub. $cnt,$cnt,$tick # conditional --$cnt
  256. add $out,$out,$tick # conditional ++$out
  257. bne Loop2
  258. Ldone2:
  259. srwi $cnt,$cnt,2
  260. sub r3,r0,$cnt
  261. blr
  262. .long 0
  263. .byte 0,12,0x14,0,0,0,3,0
  264. .long 0
  265. .size .OPENSSL_instrument_bus2,.-.OPENSSL_instrument_bus2
  266. ___
  267. }
  268. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  269. print $code;
  270. close STDOUT;