x86cpuid.masm 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. IF @Version LT 800
  2. ECHO MASM version 8.00 or later is strongly recommended.
  3. ENDIF
  4. .686
  5. .XMM
  6. IF @Version LT 800
  7. XMMWORD STRUCT 16
  8. DQ 2 dup (?)
  9. XMMWORD ENDS
  10. ENDIF
  11. .MODEL FLAT
  12. OPTION DOTNAME
  13. IF @Version LT 800
  14. .text$ SEGMENT PAGE 'CODE'
  15. ELSE
  16. .text$ SEGMENT ALIGN(64) 'CODE'
  17. ENDIF
  18. ALIGN 16
  19. _OPENSSL_ia32_cpuid PROC PUBLIC
  20. $L_OPENSSL_ia32_cpuid_begin::
  21. push ebp
  22. push ebx
  23. push esi
  24. push edi
  25. xor edx,edx
  26. pushfd
  27. pop eax
  28. mov ecx,eax
  29. xor eax,2097152
  30. push eax
  31. popfd
  32. pushfd
  33. pop eax
  34. xor ecx,eax
  35. xor eax,eax
  36. mov esi,DWORD PTR 20[esp]
  37. mov DWORD PTR 8[esi],eax
  38. bt ecx,21
  39. jnc $L000nocpuid
  40. cpuid
  41. mov edi,eax
  42. xor eax,eax
  43. cmp ebx,1970169159
  44. setne al
  45. mov ebp,eax
  46. cmp edx,1231384169
  47. setne al
  48. or ebp,eax
  49. cmp ecx,1818588270
  50. setne al
  51. or ebp,eax
  52. jz $L001intel
  53. cmp ebx,1752462657
  54. setne al
  55. mov esi,eax
  56. cmp edx,1769238117
  57. setne al
  58. or esi,eax
  59. cmp ecx,1145913699
  60. setne al
  61. or esi,eax
  62. jnz $L001intel
  63. mov eax,2147483648
  64. cpuid
  65. cmp eax,2147483649
  66. jb $L001intel
  67. mov esi,eax
  68. mov eax,2147483649
  69. cpuid
  70. or ebp,ecx
  71. and ebp,2049
  72. cmp esi,2147483656
  73. jb $L001intel
  74. mov eax,2147483656
  75. cpuid
  76. movzx esi,cl
  77. inc esi
  78. mov eax,1
  79. xor ecx,ecx
  80. cpuid
  81. bt edx,28
  82. jnc $L002generic
  83. shr ebx,16
  84. and ebx,255
  85. cmp ebx,esi
  86. ja $L002generic
  87. and edx,4026531839
  88. jmp $L002generic
  89. $L001intel:
  90. cmp edi,4
  91. mov esi,-1
  92. jb $L003nocacheinfo
  93. mov eax,4
  94. mov ecx,0
  95. cpuid
  96. mov esi,eax
  97. shr esi,14
  98. and esi,4095
  99. $L003nocacheinfo:
  100. mov eax,1
  101. xor ecx,ecx
  102. cpuid
  103. and edx,3220176895
  104. cmp ebp,0
  105. jne $L004notintel
  106. or edx,1073741824
  107. and ah,15
  108. cmp ah,15
  109. jne $L004notintel
  110. or edx,1048576
  111. $L004notintel:
  112. bt edx,28
  113. jnc $L002generic
  114. and edx,4026531839
  115. cmp esi,0
  116. je $L002generic
  117. or edx,268435456
  118. shr ebx,16
  119. cmp bl,1
  120. ja $L002generic
  121. and edx,4026531839
  122. $L002generic:
  123. and ebp,2048
  124. and ecx,4294965247
  125. mov esi,edx
  126. or ebp,ecx
  127. cmp edi,7
  128. mov edi,DWORD PTR 20[esp]
  129. jb $L005no_extended_info
  130. mov eax,7
  131. xor ecx,ecx
  132. cpuid
  133. mov DWORD PTR 8[edi],ebx
  134. $L005no_extended_info:
  135. bt ebp,27
  136. jnc $L006clear_avx
  137. xor ecx,ecx
  138. DB 15,1,208
  139. and eax,6
  140. cmp eax,6
  141. je $L007done
  142. cmp eax,2
  143. je $L006clear_avx
  144. $L008clear_xmm:
  145. and ebp,4261412861
  146. and esi,4278190079
  147. $L006clear_avx:
  148. and ebp,4026525695
  149. and DWORD PTR 8[edi],4294967263
  150. $L007done:
  151. mov eax,esi
  152. mov edx,ebp
  153. $L000nocpuid:
  154. pop edi
  155. pop esi
  156. pop ebx
  157. pop ebp
  158. ret
  159. _OPENSSL_ia32_cpuid ENDP
  160. ;EXTERN _OPENSSL_ia32cap_P:NEAR
  161. ALIGN 16
  162. _OPENSSL_rdtsc PROC PUBLIC
  163. $L_OPENSSL_rdtsc_begin::
  164. xor eax,eax
  165. xor edx,edx
  166. lea ecx,DWORD PTR _OPENSSL_ia32cap_P
  167. bt DWORD PTR [ecx],4
  168. jnc $L009notsc
  169. rdtsc
  170. $L009notsc:
  171. ret
  172. _OPENSSL_rdtsc ENDP
  173. ALIGN 16
  174. _OPENSSL_instrument_halt PROC PUBLIC
  175. $L_OPENSSL_instrument_halt_begin::
  176. lea ecx,DWORD PTR _OPENSSL_ia32cap_P
  177. bt DWORD PTR [ecx],4
  178. jnc $L010nohalt
  179. DD 2421723150
  180. and eax,3
  181. jnz $L010nohalt
  182. pushfd
  183. pop eax
  184. bt eax,9
  185. jnc $L010nohalt
  186. rdtsc
  187. push edx
  188. push eax
  189. hlt
  190. rdtsc
  191. sub eax,DWORD PTR [esp]
  192. sbb edx,DWORD PTR 4[esp]
  193. add esp,8
  194. ret
  195. $L010nohalt:
  196. xor eax,eax
  197. xor edx,edx
  198. ret
  199. _OPENSSL_instrument_halt ENDP
  200. ALIGN 16
  201. _OPENSSL_far_spin PROC PUBLIC
  202. $L_OPENSSL_far_spin_begin::
  203. pushfd
  204. pop eax
  205. bt eax,9
  206. jnc $L011nospin
  207. mov eax,DWORD PTR 4[esp]
  208. mov ecx,DWORD PTR 8[esp]
  209. DD 2430111262
  210. xor eax,eax
  211. mov edx,DWORD PTR [ecx]
  212. jmp $L012spin
  213. ALIGN 16
  214. $L012spin:
  215. inc eax
  216. cmp edx,DWORD PTR [ecx]
  217. je $L012spin
  218. DD 529567888
  219. ret
  220. $L011nospin:
  221. xor eax,eax
  222. xor edx,edx
  223. ret
  224. _OPENSSL_far_spin ENDP
  225. ALIGN 16
  226. _OPENSSL_wipe_cpu PROC PUBLIC
  227. $L_OPENSSL_wipe_cpu_begin::
  228. xor eax,eax
  229. xor edx,edx
  230. lea ecx,DWORD PTR _OPENSSL_ia32cap_P
  231. mov ecx,DWORD PTR [ecx]
  232. bt DWORD PTR [ecx],1
  233. jnc $L013no_x87
  234. and ecx,83886080
  235. cmp ecx,83886080
  236. jne $L014no_sse2
  237. pxor xmm0,xmm0
  238. pxor xmm1,xmm1
  239. pxor xmm2,xmm2
  240. pxor xmm3,xmm3
  241. pxor xmm4,xmm4
  242. pxor xmm5,xmm5
  243. pxor xmm6,xmm6
  244. pxor xmm7,xmm7
  245. $L014no_sse2:
  246. DD 4007259865,4007259865,4007259865,4007259865
  247. DD 2430851995
  248. $L013no_x87:
  249. lea eax,DWORD PTR 4[esp]
  250. ret
  251. _OPENSSL_wipe_cpu ENDP
  252. ALIGN 16
  253. _OPENSSL_atomic_add PROC PUBLIC
  254. $L_OPENSSL_atomic_add_begin::
  255. mov edx,DWORD PTR 4[esp]
  256. mov ecx,DWORD PTR 8[esp]
  257. push ebx
  258. nop
  259. mov eax,DWORD PTR [edx]
  260. $L015spin:
  261. lea ebx,DWORD PTR [ecx*1+eax]
  262. nop
  263. DD 447811568
  264. jne $L015spin
  265. mov eax,ebx
  266. pop ebx
  267. ret
  268. _OPENSSL_atomic_add ENDP
  269. ALIGN 16
  270. _OPENSSL_cleanse PROC PUBLIC
  271. $L_OPENSSL_cleanse_begin::
  272. mov edx,DWORD PTR 4[esp]
  273. mov ecx,DWORD PTR 8[esp]
  274. xor eax,eax
  275. cmp ecx,7
  276. jae $L016lot
  277. cmp ecx,0
  278. je $L017ret
  279. $L018little:
  280. mov BYTE PTR [edx],al
  281. sub ecx,1
  282. lea edx,DWORD PTR 1[edx]
  283. jnz $L018little
  284. $L017ret:
  285. ret
  286. ALIGN 16
  287. $L016lot:
  288. test edx,3
  289. jz $L019aligned
  290. mov BYTE PTR [edx],al
  291. lea ecx,DWORD PTR [ecx-1]
  292. lea edx,DWORD PTR 1[edx]
  293. jmp $L016lot
  294. $L019aligned:
  295. mov DWORD PTR [edx],eax
  296. lea ecx,DWORD PTR [ecx-4]
  297. test ecx,-4
  298. lea edx,DWORD PTR 4[edx]
  299. jnz $L019aligned
  300. cmp ecx,0
  301. jne $L018little
  302. ret
  303. _OPENSSL_cleanse ENDP
  304. ALIGN 16
  305. _CRYPTO_memcmp PROC PUBLIC
  306. $L_CRYPTO_memcmp_begin::
  307. push esi
  308. push edi
  309. mov esi,DWORD PTR 12[esp]
  310. mov edi,DWORD PTR 16[esp]
  311. mov ecx,DWORD PTR 20[esp]
  312. xor eax,eax
  313. xor edx,edx
  314. cmp ecx,0
  315. je $L020no_data
  316. $L021loop:
  317. mov dl,BYTE PTR [esi]
  318. lea esi,DWORD PTR 1[esi]
  319. xor dl,BYTE PTR [edi]
  320. lea edi,DWORD PTR 1[edi]
  321. or al,dl
  322. dec ecx
  323. jnz $L021loop
  324. neg eax
  325. shr eax,31
  326. $L020no_data:
  327. pop edi
  328. pop esi
  329. ret
  330. _CRYPTO_memcmp ENDP
  331. ALIGN 16
  332. _OPENSSL_instrument_bus PROC PUBLIC
  333. $L_OPENSSL_instrument_bus_begin::
  334. push ebp
  335. push ebx
  336. push esi
  337. push edi
  338. mov eax,0
  339. lea edx,DWORD PTR _OPENSSL_ia32cap_P
  340. bt DWORD PTR [edx],4
  341. jnc $L022nogo
  342. bt DWORD PTR [edx],19
  343. jnc $L022nogo
  344. mov edi,DWORD PTR 20[esp]
  345. mov ecx,DWORD PTR 24[esp]
  346. rdtsc
  347. mov esi,eax
  348. mov ebx,0
  349. clflush DWORD PTR [edi]
  350. DB 240
  351. add DWORD PTR [edi],ebx
  352. jmp $L023loop
  353. ALIGN 16
  354. $L023loop:
  355. rdtsc
  356. mov edx,eax
  357. sub eax,esi
  358. mov esi,edx
  359. mov ebx,eax
  360. clflush DWORD PTR [edi]
  361. DB 240
  362. add DWORD PTR [edi],eax
  363. lea edi,DWORD PTR 4[edi]
  364. sub ecx,1
  365. jnz $L023loop
  366. mov eax,DWORD PTR 24[esp]
  367. $L022nogo:
  368. pop edi
  369. pop esi
  370. pop ebx
  371. pop ebp
  372. ret
  373. _OPENSSL_instrument_bus ENDP
  374. ALIGN 16
  375. _OPENSSL_instrument_bus2 PROC PUBLIC
  376. $L_OPENSSL_instrument_bus2_begin::
  377. push ebp
  378. push ebx
  379. push esi
  380. push edi
  381. mov eax,0
  382. lea edx,DWORD PTR _OPENSSL_ia32cap_P
  383. bt DWORD PTR [edx],4
  384. jnc $L024nogo
  385. bt DWORD PTR [edx],19
  386. jnc $L024nogo
  387. mov edi,DWORD PTR 20[esp]
  388. mov ecx,DWORD PTR 24[esp]
  389. mov ebp,DWORD PTR 28[esp]
  390. rdtsc
  391. mov esi,eax
  392. mov ebx,0
  393. clflush DWORD PTR [edi]
  394. DB 240
  395. add DWORD PTR [edi],ebx
  396. rdtsc
  397. mov edx,eax
  398. sub eax,esi
  399. mov esi,edx
  400. mov ebx,eax
  401. jmp $L025loop2
  402. ALIGN 16
  403. $L025loop2:
  404. clflush DWORD PTR [edi]
  405. DB 240
  406. add DWORD PTR [edi],eax
  407. sub ebp,1
  408. jz $L026done2
  409. rdtsc
  410. mov edx,eax
  411. sub eax,esi
  412. mov esi,edx
  413. cmp eax,ebx
  414. mov ebx,eax
  415. mov edx,0
  416. setne dl
  417. sub ecx,edx
  418. lea edi,DWORD PTR [edx*4+edi]
  419. jnz $L025loop2
  420. $L026done2:
  421. mov eax,DWORD PTR 24[esp]
  422. sub eax,ecx
  423. $L024nogo:
  424. pop edi
  425. pop esi
  426. pop ebx
  427. pop ebp
  428. ret
  429. _OPENSSL_instrument_bus2 ENDP
  430. ALIGN 16
  431. _OPENSSL_ia32_rdrand_bytes PROC PUBLIC
  432. $L_OPENSSL_ia32_rdrand_bytes_begin::
  433. push edi
  434. push ebx
  435. xor eax,eax
  436. mov edi,DWORD PTR 12[esp]
  437. mov ebx,DWORD PTR 16[esp]
  438. cmp ebx,0
  439. je $L027done
  440. mov ecx,8
  441. $L028loop:
  442. DB 15,199,242
  443. jc $L029break
  444. loop $L028loop
  445. jmp $L027done
  446. ALIGN 16
  447. $L029break:
  448. cmp ebx,4
  449. jb $L030tail
  450. mov DWORD PTR [edi],edx
  451. lea edi,DWORD PTR 4[edi]
  452. add eax,4
  453. sub ebx,4
  454. jz $L027done
  455. mov ecx,8
  456. jmp $L028loop
  457. ALIGN 16
  458. $L030tail:
  459. mov BYTE PTR [edi],dl
  460. lea edi,DWORD PTR 1[edi]
  461. inc eax
  462. shr edx,8
  463. dec ebx
  464. jnz $L030tail
  465. $L027done:
  466. xor edx,edx
  467. pop ebx
  468. pop edi
  469. ret
  470. _OPENSSL_ia32_rdrand_bytes ENDP
  471. ALIGN 16
  472. _OPENSSL_ia32_rdseed_bytes PROC PUBLIC
  473. $L_OPENSSL_ia32_rdseed_bytes_begin::
  474. push edi
  475. push ebx
  476. xor eax,eax
  477. mov edi,DWORD PTR 12[esp]
  478. mov ebx,DWORD PTR 16[esp]
  479. cmp ebx,0
  480. je $L031done
  481. mov ecx,8
  482. $L032loop:
  483. DB 15,199,250
  484. jc $L033break
  485. loop $L032loop
  486. jmp $L031done
  487. ALIGN 16
  488. $L033break:
  489. cmp ebx,4
  490. jb $L034tail
  491. mov DWORD PTR [edi],edx
  492. lea edi,DWORD PTR 4[edi]
  493. add eax,4
  494. sub ebx,4
  495. jz $L031done
  496. mov ecx,8
  497. jmp $L032loop
  498. ALIGN 16
  499. $L034tail:
  500. mov BYTE PTR [edi],dl
  501. lea edi,DWORD PTR 1[edi]
  502. inc eax
  503. shr edx,8
  504. dec ebx
  505. jnz $L034tail
  506. $L031done:
  507. xor edx,edx
  508. pop ebx
  509. pop edi
  510. ret
  511. _OPENSSL_ia32_rdseed_bytes ENDP
  512. .text$ ENDS
  513. .bss SEGMENT 'BSS'
  514. COMM _OPENSSL_ia32cap_P:DWORD:4
  515. .bss ENDS
  516. .CRT$XCU SEGMENT DWORD PUBLIC 'DATA'
  517. EXTERN _OPENSSL_cpuid_setup:NEAR
  518. DD _OPENSSL_cpuid_setup
  519. .CRT$XCU ENDS
  520. END