ppccpuid.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env perl
  2. $flavour = shift;
  3. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  4. ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
  5. ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
  6. die "can't locate ppc-xlate.pl";
  7. open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
  8. if ($flavour=~/64/) {
  9. $CMPLI="cmpldi";
  10. $SHRLI="srdi";
  11. $SIGNX="extsw";
  12. } else {
  13. $CMPLI="cmplwi";
  14. $SHRLI="srwi";
  15. $SIGNX="mr";
  16. }
  17. $code=<<___;
  18. .machine "any"
  19. .text
  20. .globl .OPENSSL_cpuid_setup
  21. .align 4
  22. .OPENSSL_cpuid_setup:
  23. blr
  24. .globl .OPENSSL_wipe_cpu
  25. .align 4
  26. .OPENSSL_wipe_cpu:
  27. xor r0,r0,r0
  28. mr r3,r1
  29. xor r4,r4,r4
  30. xor r5,r5,r5
  31. xor r6,r6,r6
  32. xor r7,r7,r7
  33. xor r8,r8,r8
  34. xor r9,r9,r9
  35. xor r10,r10,r10
  36. xor r11,r11,r11
  37. xor r12,r12,r12
  38. blr
  39. .globl .OPENSSL_atomic_add
  40. .align 4
  41. .OPENSSL_atomic_add:
  42. Loop: lwarx r5,0,r3
  43. add r0,r4,r5
  44. stwcx. r0,0,r3
  45. bne- Loop
  46. $SIGNX r3,r0
  47. blr
  48. .globl .OPENSSL_rdtsc
  49. .align 4
  50. .OPENSSL_rdtsc:
  51. mftb r3
  52. mftbu r4
  53. blr
  54. .globl .OPENSSL_cleanse
  55. .align 4
  56. .OPENSSL_cleanse:
  57. $CMPLI r4,7
  58. li r0,0
  59. bge Lot
  60. Little: mtctr r4
  61. stb r0,0(r3)
  62. addi r3,r3,1
  63. bdnz- \$-8
  64. blr
  65. Lot: andi. r5,r3,3
  66. beq Laligned
  67. stb r0,0(r3)
  68. subi r4,r4,1
  69. addi r3,r3,1
  70. b Lot
  71. Laligned:
  72. $SHRLI r5,r4,2
  73. mtctr r5
  74. stw r0,0(r3)
  75. addi r3,r3,4
  76. bdnz- \$-8
  77. andi. r4,r4,3
  78. bne Little
  79. blr
  80. ___
  81. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  82. print $code;
  83. close STDOUT;