pariscid.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/usr/bin/env perl
  2. $flavour = shift;
  3. $output = shift;
  4. open STDOUT,">$output";
  5. if ($flavour =~ /64/) {
  6. $LEVEL ="2.0W";
  7. $SIZE_T =8;
  8. $ST ="std";
  9. } else {
  10. $LEVEL ="1.1";
  11. $SIZE_T =4;
  12. $ST ="stw";
  13. }
  14. $rp="%r2";
  15. $sp="%r30";
  16. $rv="%r28";
  17. $code=<<___;
  18. .LEVEL $LEVEL
  19. .SPACE \$TEXT\$
  20. .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
  21. .EXPORT OPENSSL_cpuid_setup,ENTRY
  22. .ALIGN 8
  23. OPENSSL_cpuid_setup
  24. .PROC
  25. .CALLINFO NO_CALLS
  26. .ENTRY
  27. bv ($rp)
  28. .EXIT
  29. nop
  30. .PROCEND
  31. .EXPORT OPENSSL_rdtsc,ENTRY
  32. .ALIGN 8
  33. OPENSSL_rdtsc
  34. .PROC
  35. .CALLINFO NO_CALLS
  36. .ENTRY
  37. mfctl %cr16,$rv
  38. bv ($rp)
  39. .EXIT
  40. nop
  41. .PROCEND
  42. .EXPORT OPENSSL_wipe_cpu,ENTRY
  43. .ALIGN 8
  44. OPENSSL_wipe_cpu
  45. .PROC
  46. .CALLINFO NO_CALLS
  47. .ENTRY
  48. xor %r0,%r0,%r1
  49. fcpy,dbl %fr0,%fr4
  50. xor %r0,%r0,%r19
  51. fcpy,dbl %fr0,%fr5
  52. xor %r0,%r0,%r20
  53. fcpy,dbl %fr0,%fr6
  54. xor %r0,%r0,%r21
  55. fcpy,dbl %fr0,%fr7
  56. xor %r0,%r0,%r22
  57. fcpy,dbl %fr0,%fr8
  58. xor %r0,%r0,%r23
  59. fcpy,dbl %fr0,%fr9
  60. xor %r0,%r0,%r24
  61. fcpy,dbl %fr0,%fr10
  62. xor %r0,%r0,%r25
  63. fcpy,dbl %fr0,%fr11
  64. xor %r0,%r0,%r26
  65. fcpy,dbl %fr0,%fr22
  66. xor %r0,%r0,%r29
  67. fcpy,dbl %fr0,%fr23
  68. xor %r0,%r0,%r31
  69. fcpy,dbl %fr0,%fr24
  70. fcpy,dbl %fr0,%fr25
  71. fcpy,dbl %fr0,%fr26
  72. fcpy,dbl %fr0,%fr27
  73. fcpy,dbl %fr0,%fr28
  74. fcpy,dbl %fr0,%fr29
  75. fcpy,dbl %fr0,%fr30
  76. fcpy,dbl %fr0,%fr31
  77. bv ($rp)
  78. .EXIT
  79. ldo 0($sp),$rv
  80. .PROCEND
  81. ___
  82. {
  83. my $inp="%r26";
  84. my $len="%r25";
  85. $code.=<<___;
  86. .EXPORT OPENSSL_cleanse,ENTRY,ARGW0=GR,ARGW1=GR
  87. .ALIGN 8
  88. OPENSSL_cleanse
  89. .PROC
  90. .CALLINFO NO_CALLS
  91. .ENTRY
  92. cmpib,*= 0,$len,Ldone
  93. nop
  94. cmpib,*>>= 15,$len,Little
  95. ldi $SIZE_T-1,%r1
  96. Lalign
  97. and,*<> $inp,%r1,%r28
  98. b,n Laligned
  99. stb %r0,0($inp)
  100. ldo -1($len),$len
  101. b Lalign
  102. ldo 1($inp),$inp
  103. Laligned
  104. andcm $len,%r1,%r28
  105. Lot
  106. $ST %r0,0($inp)
  107. addib,*<> -$SIZE_T,%r28,Lot
  108. ldo $SIZE_T($inp),$inp
  109. and,*<> $len,%r1,$len
  110. b,n Ldone
  111. Little
  112. stb %r0,0($inp)
  113. addib,*<> -1,$len,Little
  114. ldo 1($inp),$inp
  115. Ldone
  116. bv ($rp)
  117. .EXIT
  118. nop
  119. .PROCEND
  120. ___
  121. }
  122. {
  123. my ($out,$cnt,$max)=("%r26","%r25","%r24");
  124. my ($tick,$lasttick)=("%r23","%r22");
  125. my ($diff,$lastdiff)=("%r21","%r20");
  126. $code.=<<___;
  127. .EXPORT OPENSSL_instrument_bus,ENTRY,ARGW0=GR,ARGW1=GR
  128. .ALIGN 8
  129. OPENSSL_instrument_bus
  130. .PROC
  131. .CALLINFO NO_CALLS
  132. .ENTRY
  133. copy $cnt,$rv
  134. mfctl %cr16,$tick
  135. copy $tick,$lasttick
  136. ldi 0,$diff
  137. fdc 0($out)
  138. ldw 0($out),$tick
  139. add $diff,$tick,$tick
  140. stw $tick,0($out)
  141. Loop
  142. mfctl %cr16,$tick
  143. sub $tick,$lasttick,$diff
  144. copy $tick,$lasttick
  145. fdc 0($out)
  146. ldw 0($out),$tick
  147. add $diff,$tick,$tick
  148. stw $tick,0($out)
  149. addib,<> -1,$cnt,Loop
  150. addi 4,$out,$out
  151. bv ($rp)
  152. .EXIT
  153. sub $rv,$cnt,$rv
  154. .PROCEND
  155. .EXPORT OPENSSL_instrument_bus2,ENTRY,ARGW0=GR,ARGW1=GR
  156. .ALIGN 8
  157. OPENSSL_instrument_bus2
  158. .PROC
  159. .CALLINFO NO_CALLS
  160. .ENTRY
  161. copy $cnt,$rv
  162. sub %r0,$cnt,$cnt
  163. mfctl %cr16,$tick
  164. copy $tick,$lasttick
  165. ldi 0,$diff
  166. fdc 0($out)
  167. ldw 0($out),$tick
  168. add $diff,$tick,$tick
  169. stw $tick,0($out)
  170. mfctl %cr16,$tick
  171. sub $tick,$lasttick,$diff
  172. copy $tick,$lasttick
  173. Loop2
  174. copy $diff,$lastdiff
  175. fdc 0($out)
  176. ldw 0($out),$tick
  177. add $diff,$tick,$tick
  178. stw $tick,0($out)
  179. addib,= -1,$max,Ldone2
  180. nop
  181. mfctl %cr16,$tick
  182. sub $tick,$lasttick,$diff
  183. copy $tick,$lasttick
  184. cmpclr,<> $lastdiff,$diff,$tick
  185. ldi 1,$tick
  186. ldi 1,%r1
  187. xor %r1,$tick,$tick
  188. addb,<> $tick,$cnt,Loop2
  189. shladd,l $tick,2,$out,$out
  190. Ldone2
  191. bv ($rp)
  192. .EXIT
  193. add $rv,$cnt,$rv
  194. .PROCEND
  195. ___
  196. }
  197. $code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
  198. $code =~ s/,\*/,/gm if ($SIZE_T==4);
  199. print $code;
  200. close STDOUT;