c64xpluscpuid.pl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #! /usr/bin/env perl
  2. # Copyright 2012-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. while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
  9. open STDOUT,">$output";
  10. $code.=<<___;
  11. .text
  12. .if .ASSEMBLER_VERSION<7000000
  13. .asg 0,__TI_EABI__
  14. .endif
  15. .if __TI_EABI__
  16. .asg OPENSSL_rdtsc,_OPENSSL_rdtsc
  17. .asg OPENSSL_cleanse,_OPENSSL_cleanse
  18. .asg CRYPTO_memcmp,_CRYPTO_memcmp
  19. .asg OPENSSL_atomic_add,_OPENSSL_atomic_add
  20. .asg OPENSSL_wipe_cpu,_OPENSSL_wipe_cpu
  21. .asg OPENSSL_instrument_bus,_OPENSSL_instrument_bus
  22. .asg OPENSSL_instrument_bus2,_OPENSSL_instrument_bus2
  23. .endif
  24. .asg B3,RA
  25. .global _OPENSSL_rdtsc
  26. _OPENSSL_rdtsc:
  27. .asmfunc
  28. B RA
  29. MVC TSCL,B0
  30. MVC TSCH,B1
  31. [!B0] MVC B0,TSCL ; start TSC
  32. MV B0,A4
  33. MV B1,A5
  34. .endasmfunc
  35. .global _OPENSSL_cleanse
  36. _OPENSSL_cleanse:
  37. .asmfunc
  38. ZERO A3:A2
  39. || ZERO B2
  40. || SHRU B4,3,B0 ; is length >= 8
  41. || ADD 1,A4,B6
  42. [!B0] BNOP RA
  43. || ZERO A1
  44. || ZERO B1
  45. [B0] MVC B0,ILC
  46. ||[!B0] CMPLT 0,B4,A1
  47. ||[!B0] CMPLT 1,B4,B1
  48. [A1] STB A2,*A4++[2]
  49. || [B1] STB B2,*B6++[2]
  50. ||[!B0] CMPLT 2,B4,A1
  51. ||[!B0] CMPLT 3,B4,B1
  52. [A1] STB A2,*A4++[2]
  53. || [B1] STB B2,*B6++[2]
  54. ||[!B0] CMPLT 4,B4,A1
  55. ||[!B0] CMPLT 5,B4,B1
  56. [A1] STB A2,*A4++[2]
  57. || [B1] STB B2,*B6++[2]
  58. ||[!B0] CMPLT 6,B4,A1
  59. [A1] STB A2,*A4++[2]
  60. SPLOOP 1
  61. STNDW A3:A2,*A4++
  62. || SUB B4,8,B4
  63. SPKERNEL
  64. MV B4,B0 ; remaining bytes
  65. || ADD 1,A4,B6
  66. || BNOP RA
  67. [B0] CMPLT 0,B0,A1
  68. || [B0] CMPLT 1,B0,B1
  69. [A1] STB A2,*A4++[2]
  70. || [B1] STB B2,*B6++[2]
  71. || [B0] CMPLT 2,B0,A1
  72. || [B0] CMPLT 3,B0,B1
  73. [A1] STB A2,*A4++[2]
  74. || [B1] STB B2,*B6++[2]
  75. || [B0] CMPLT 4,B0,A1
  76. || [B0] CMPLT 5,B0,B1
  77. [A1] STB A2,*A4++[2]
  78. || [B1] STB B2,*B6++[2]
  79. || [B0] CMPLT 6,B0,A1
  80. [A1] STB A2,*A4++[2]
  81. .endasmfunc
  82. .global _CRYPTO_memcmp
  83. _CRYPTO_memcmp:
  84. .asmfunc
  85. MV A6,B0
  86. [!B0] BNOP RA
  87. ||[!B0] ZERO A4
  88. [B0] MVC B0,ILC
  89. || [B0] ZERO A0
  90. NOP 4
  91. SPLOOP 1
  92. LDBU *A4++,A1
  93. || LDBU *B4++,B1
  94. NOP 4
  95. XOR.L B1,A1,A2
  96. SPKERNEL 1,0
  97. || OR.S A2,A0,A0
  98. BNOP RA,3
  99. ZERO.L A4
  100. [A0] MVK 1,A4
  101. .endasmfunc
  102. .global _OPENSSL_atomic_add
  103. _OPENSSL_atomic_add:
  104. .asmfunc
  105. MV A4,B0
  106. atomic_add?:
  107. LL *B0,B5
  108. NOP 4
  109. ADD B4,B5,B5
  110. SL B5,*B0
  111. CMTL *B0,B1
  112. NOP 4
  113. [!B1] B atomic_add?
  114. [B1] BNOP RA,4
  115. MV B5,A4
  116. .endasmfunc
  117. .global _OPENSSL_wipe_cpu
  118. _OPENSSL_wipe_cpu:
  119. .asmfunc
  120. ZERO A0
  121. || ZERO B0
  122. || ZERO A1
  123. || ZERO B1
  124. ZERO A3:A2
  125. || MVD B0,B2
  126. || ZERO A4
  127. || ZERO B4
  128. || ZERO A5
  129. || ZERO B5
  130. || BNOP RA
  131. ZERO A7:A6
  132. || ZERO B7:B6
  133. || ZERO A8
  134. || ZERO B8
  135. || ZERO A9
  136. || ZERO B9
  137. ZERO A17:A16
  138. || ZERO B17:B16
  139. || ZERO A18
  140. || ZERO B18
  141. || ZERO A19
  142. || ZERO B19
  143. ZERO A21:A20
  144. || ZERO B21:B20
  145. || ZERO A22
  146. || ZERO B22
  147. || ZERO A23
  148. || ZERO B23
  149. ZERO A25:A24
  150. || ZERO B25:B24
  151. || ZERO A26
  152. || ZERO B26
  153. || ZERO A27
  154. || ZERO B27
  155. ZERO A29:A28
  156. || ZERO B29:B28
  157. || ZERO A30
  158. || ZERO B30
  159. || ZERO A31
  160. || ZERO B31
  161. .endasmfunc
  162. CLFLUSH .macro CONTROL,ADDR,LEN
  163. B passthrough?
  164. || STW ADDR,*CONTROL[0]
  165. STW LEN,*CONTROL[1]
  166. spinlock?:
  167. LDW *CONTROL[1],A0
  168. NOP 3
  169. passthrough?:
  170. NOP
  171. [A0] BNOP spinlock?,5
  172. .endm
  173. .global _OPENSSL_instrument_bus
  174. _OPENSSL_instrument_bus:
  175. .asmfunc
  176. MV B4,B0 ; reassign sizeof(output)
  177. || MV A4,B4 ; reassign output
  178. || MVK 0x00004030,A3
  179. MV B0,A4 ; return value
  180. || MVK 1,A1
  181. || MVKH 0x01840000,A3 ; L1DWIBAR
  182. MVC TSCL,B8 ; collect 1st tick
  183. || MVK 0x00004010,A5
  184. MV B8,B9 ; lasttick = tick
  185. || MVK 0,B7 ; lastdiff = 0
  186. || MVKH 0x01840000,A5 ; L2WIBAR
  187. CLFLUSH A3,B4,A1 ; write-back and invalidate L1D line
  188. CLFLUSH A5,B4,A1 ; write-back and invalidate L2 line
  189. LL *B4,B5
  190. NOP 4
  191. ADD B7,B5,B5
  192. SL B5,*B4
  193. CMTL *B4,B1
  194. NOP 4
  195. STW B5,*B4
  196. bus_loop1?:
  197. MVC TSCL,B8
  198. || [B0] SUB B0,1,B0
  199. SUB B8,B9,B7 ; lastdiff = tick - lasttick
  200. || MV B8,B9 ; lasttick = tick
  201. CLFLUSH A3,B4,A1 ; write-back and invalidate L1D line
  202. CLFLUSH A5,B4,A1 ; write-back and invalidate L2 line
  203. LL *B4,B5
  204. NOP 4
  205. ADD B7,B5,B5
  206. SL B5,*B4
  207. CMTL *B4,B1
  208. STW B5,*B4 ; [!B1] is removed to flatten samples
  209. || ADDK 4,B4
  210. || [B0] BNOP bus_loop1?,5
  211. BNOP RA,5
  212. .endasmfunc
  213. .global _OPENSSL_instrument_bus2
  214. _OPENSSL_instrument_bus2:
  215. .asmfunc
  216. MV A6,B0 ; reassign max
  217. || MV B4,A6 ; reassign sizeof(output)
  218. || MVK 0x00004030,A3
  219. MV A4,B4 ; reassign output
  220. || MVK 0,A4 ; return value
  221. || MVK 1,A1
  222. || MVKH 0x01840000,A3 ; L1DWIBAR
  223. MVC TSCL,B8 ; collect 1st tick
  224. || MVK 0x00004010,A5
  225. MV B8,B9 ; lasttick = tick
  226. || MVK 0,B7 ; lastdiff = 0
  227. || MVKH 0x01840000,A5 ; L2WIBAR
  228. CLFLUSH A3,B4,A1 ; write-back and invalidate L1D line
  229. CLFLUSH A5,B4,A1 ; write-back and invalidate L2 line
  230. LL *B4,B5
  231. NOP 4
  232. ADD B7,B5,B5
  233. SL B5,*B4
  234. CMTL *B4,B1
  235. NOP 4
  236. STW B5,*B4
  237. MVC TSCL,B8 ; collect 1st diff
  238. SUB B8,B9,B7 ; lastdiff = tick - lasttick
  239. || MV B8,B9 ; lasttick = tick
  240. || SUB B0,1,B0
  241. bus_loop2?:
  242. CLFLUSH A3,B4,A1 ; write-back and invalidate L1D line
  243. CLFLUSH A5,B4,A1 ; write-back and invalidate L2 line
  244. LL *B4,B5
  245. NOP 4
  246. ADD B7,B5,B5
  247. SL B5,*B4
  248. CMTL *B4,B1
  249. STW B5,*B4 ; [!B1] is removed to flatten samples
  250. ||[!B0] BNOP bus_loop2_done?,2
  251. || SUB B0,1,B0
  252. MVC TSCL,B8
  253. SUB B8,B9,B8
  254. || MV B8,B9
  255. CMPEQ B8,B7,B2
  256. || MV B8,B7
  257. [!B2] ADDAW B4,1,B4
  258. ||[!B2] ADDK 1,A4
  259. CMPEQ A4,A6,A2
  260. [!A2] BNOP bus_loop2?,5
  261. bus_loop2_done?:
  262. BNOP RA,5
  263. .endasmfunc
  264. ___
  265. print $code;
  266. close STDOUT or die "error closing STDOUT: $!";