pariscid.pl 4.8 KB

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