pariscid.pl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #! /usr/bin/env perl
  2. # Copyright 2009-2020 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. $output = shift;
  10. open STDOUT,">$output";
  11. if ($flavour =~ /64/) {
  12. $LEVEL ="2.0W";
  13. $SIZE_T =8;
  14. $ST ="std";
  15. } else {
  16. $LEVEL ="1.1";
  17. $SIZE_T =4;
  18. $ST ="stw";
  19. }
  20. $rp="%r2";
  21. $sp="%r30";
  22. $rv="%r28";
  23. $code=<<___;
  24. .LEVEL $LEVEL
  25. .SPACE \$TEXT\$
  26. .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
  27. .EXPORT OPENSSL_cpuid_setup,ENTRY
  28. .ALIGN 8
  29. OPENSSL_cpuid_setup
  30. .PROC
  31. .CALLINFO NO_CALLS
  32. .ENTRY
  33. bv ($rp)
  34. .EXIT
  35. nop
  36. .PROCEND
  37. .EXPORT OPENSSL_rdtsc,ENTRY
  38. .ALIGN 8
  39. OPENSSL_rdtsc
  40. .PROC
  41. .CALLINFO NO_CALLS
  42. .ENTRY
  43. mfctl %cr16,$rv
  44. bv ($rp)
  45. .EXIT
  46. nop
  47. .PROCEND
  48. .EXPORT OPENSSL_wipe_cpu,ENTRY
  49. .ALIGN 8
  50. OPENSSL_wipe_cpu
  51. .PROC
  52. .CALLINFO NO_CALLS
  53. .ENTRY
  54. xor %r0,%r0,%r1
  55. fcpy,dbl %fr0,%fr4
  56. xor %r0,%r0,%r19
  57. fcpy,dbl %fr0,%fr5
  58. xor %r0,%r0,%r20
  59. fcpy,dbl %fr0,%fr6
  60. xor %r0,%r0,%r21
  61. fcpy,dbl %fr0,%fr7
  62. xor %r0,%r0,%r22
  63. fcpy,dbl %fr0,%fr8
  64. xor %r0,%r0,%r23
  65. fcpy,dbl %fr0,%fr9
  66. xor %r0,%r0,%r24
  67. fcpy,dbl %fr0,%fr10
  68. xor %r0,%r0,%r25
  69. fcpy,dbl %fr0,%fr11
  70. xor %r0,%r0,%r26
  71. fcpy,dbl %fr0,%fr22
  72. xor %r0,%r0,%r29
  73. fcpy,dbl %fr0,%fr23
  74. xor %r0,%r0,%r31
  75. fcpy,dbl %fr0,%fr24
  76. fcpy,dbl %fr0,%fr25
  77. fcpy,dbl %fr0,%fr26
  78. fcpy,dbl %fr0,%fr27
  79. fcpy,dbl %fr0,%fr28
  80. fcpy,dbl %fr0,%fr29
  81. fcpy,dbl %fr0,%fr30
  82. fcpy,dbl %fr0,%fr31
  83. bv ($rp)
  84. .EXIT
  85. ldo 0($sp),$rv
  86. .PROCEND
  87. ___
  88. {
  89. my $inp="%r26";
  90. my $len="%r25";
  91. $code.=<<___;
  92. .EXPORT OPENSSL_cleanse,ENTRY,ARGW0=GR,ARGW1=GR
  93. .ALIGN 8
  94. OPENSSL_cleanse
  95. .PROC
  96. .CALLINFO NO_CALLS
  97. .ENTRY
  98. cmpib,*= 0,$len,L\$done
  99. nop
  100. cmpib,*>>= 15,$len,L\$ittle
  101. ldi $SIZE_T-1,%r1
  102. L\$align
  103. and,*<> $inp,%r1,%r28
  104. b,n L\$aligned
  105. stb %r0,0($inp)
  106. ldo -1($len),$len
  107. b L\$align
  108. ldo 1($inp),$inp
  109. L\$aligned
  110. andcm $len,%r1,%r28
  111. L\$ot
  112. $ST %r0,0($inp)
  113. addib,*<> -$SIZE_T,%r28,L\$ot
  114. ldo $SIZE_T($inp),$inp
  115. and,*<> $len,%r1,$len
  116. b,n L\$done
  117. L\$ittle
  118. stb %r0,0($inp)
  119. addib,*<> -1,$len,L\$ittle
  120. ldo 1($inp),$inp
  121. L\$done
  122. bv ($rp)
  123. .EXIT
  124. nop
  125. .PROCEND
  126. ___
  127. }
  128. {
  129. my ($in1,$in2,$len)=("%r26","%r25","%r24");
  130. $code.=<<___;
  131. .EXPORT CRYPTO_memcmp,ENTRY,ARGW0=GR,ARGW1=GR,ARGW1=GR
  132. .ALIGN 8
  133. CRYPTO_memcmp
  134. .PROC
  135. .CALLINFO NO_CALLS
  136. .ENTRY
  137. cmpib,*= 0,$len,L\$no_data
  138. xor $rv,$rv,$rv
  139. L\$oop_cmp
  140. ldb 0($in1),%r19
  141. ldb 0($in2),%r20
  142. ldo 1($in1),$in1
  143. ldo 1($in2),$in2
  144. xor %r19,%r20,%r29
  145. addib,*<> -1,$len,L\$oop_cmp
  146. or %r29,$rv,$rv
  147. sub %r0,$rv,%r29
  148. extru %r29,0,1,$rv
  149. L\$no_data
  150. bv ($rp)
  151. .EXIT
  152. nop
  153. .PROCEND
  154. ___
  155. }
  156. {
  157. my ($out,$cnt,$max)=("%r26","%r25","%r24");
  158. my ($tick,$lasttick)=("%r23","%r22");
  159. my ($diff,$lastdiff)=("%r21","%r20");
  160. $code.=<<___;
  161. .EXPORT OPENSSL_instrument_bus,ENTRY,ARGW0=GR,ARGW1=GR
  162. .ALIGN 8
  163. OPENSSL_instrument_bus
  164. .PROC
  165. .CALLINFO NO_CALLS
  166. .ENTRY
  167. copy $cnt,$rv
  168. mfctl %cr16,$tick
  169. copy $tick,$lasttick
  170. ldi 0,$diff
  171. fdc 0($out)
  172. ldw 0($out),$tick
  173. add $diff,$tick,$tick
  174. stw $tick,0($out)
  175. L\$oop
  176. mfctl %cr16,$tick
  177. sub $tick,$lasttick,$diff
  178. copy $tick,$lasttick
  179. fdc 0($out)
  180. ldw 0($out),$tick
  181. add $diff,$tick,$tick
  182. stw $tick,0($out)
  183. addib,<> -1,$cnt,L\$oop
  184. addi 4,$out,$out
  185. bv ($rp)
  186. .EXIT
  187. sub $rv,$cnt,$rv
  188. .PROCEND
  189. .EXPORT OPENSSL_instrument_bus2,ENTRY,ARGW0=GR,ARGW1=GR
  190. .ALIGN 8
  191. OPENSSL_instrument_bus2
  192. .PROC
  193. .CALLINFO NO_CALLS
  194. .ENTRY
  195. copy $cnt,$rv
  196. sub %r0,$cnt,$cnt
  197. mfctl %cr16,$tick
  198. copy $tick,$lasttick
  199. ldi 0,$diff
  200. fdc 0($out)
  201. ldw 0($out),$tick
  202. add $diff,$tick,$tick
  203. stw $tick,0($out)
  204. mfctl %cr16,$tick
  205. sub $tick,$lasttick,$diff
  206. copy $tick,$lasttick
  207. L\$oop2
  208. copy $diff,$lastdiff
  209. fdc 0($out)
  210. ldw 0($out),$tick
  211. add $diff,$tick,$tick
  212. stw $tick,0($out)
  213. addib,= -1,$max,L\$done2
  214. nop
  215. mfctl %cr16,$tick
  216. sub $tick,$lasttick,$diff
  217. copy $tick,$lasttick
  218. cmpclr,<> $lastdiff,$diff,$tick
  219. ldi 1,$tick
  220. ldi 1,%r1
  221. xor %r1,$tick,$tick
  222. addb,<> $tick,$cnt,L\$oop2
  223. shladd,l $tick,2,$out,$out
  224. L\$done2
  225. bv ($rp)
  226. .EXIT
  227. add $rv,$cnt,$rv
  228. .PROCEND
  229. ___
  230. }
  231. if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
  232. =~ /GNU assembler/) {
  233. $gnuas = 1;
  234. }
  235. foreach(split("\n",$code)) {
  236. s/(\.LEVEL\s+2\.0)W/$1w/ if ($gnuas && $SIZE_T==8);
  237. s/\.SPACE\s+\$TEXT\$/.text/ if ($gnuas && $SIZE_T==8);
  238. s/\.SUBSPA.*// if ($gnuas && $SIZE_T==8);
  239. s/cmpib,\*/comib,/ if ($SIZE_T==4);
  240. s/,\*/,/ if ($SIZE_T==4);
  241. s/\bbv\b/bve/ if ($SIZE_T==8);
  242. print $_,"\n";
  243. }
  244. close STDOUT or die "error closing STDOUT: $!";