platformCPUInfo.asm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;-----------------------------------------------------------------------------
  2. ; Copyright (c) 2012 GarageGames, LLC
  3. ;
  4. ; Permission is hereby granted, free of charge, to any person obtaining a copy
  5. ; of this software and associated documentation files (the "Software"), to
  6. ; deal in the Software without restriction, including without limitation the
  7. ; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. ; sell copies of the Software, and to permit persons to whom the Software is
  9. ; furnished to do so, subject to the following conditions:
  10. ;
  11. ; The above copyright notice and this permission notice shall be included in
  12. ; all copies or substantial portions of the Software.
  13. ;
  14. ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. ; IN THE SOFTWARE.
  21. ;-----------------------------------------------------------------------------
  22. segment .text
  23. ; syntax: export_fn <function name>
  24. %macro export_fn 1
  25. %ifidn __OUTPUT_FORMAT__, elf
  26. ; No underscore needed for ELF object files
  27. global %1
  28. %1:
  29. %else
  30. global _%1
  31. _%1:
  32. %endif
  33. %endmacro
  34. ; push registers
  35. %macro pushreg 0
  36. ; pushad
  37. push ebx
  38. push ebp
  39. push esi
  40. push edi
  41. %endmacro
  42. ; pop registers
  43. %macro popreg 0
  44. pop edi
  45. pop esi
  46. pop ebp
  47. pop ebx
  48. ; popad
  49. %endmacro
  50. ; void detectX86CPUInfo(char *vendor, U32 *processor, U32 *properties);
  51. export_fn detectX86CPUInfo
  52. push ebp
  53. mov ebp, esp
  54. pushreg
  55. push edx
  56. push ecx
  57. pushfd
  58. pushfd ; save EFLAGS to stack
  59. pop eax ; move EFLAGS into EAX
  60. mov ebx, eax
  61. xor eax, 0x200000 ; flip bit 21
  62. push eax
  63. popfd ; restore EFLAGS
  64. pushfd
  65. pop eax
  66. cmp eax, ebx
  67. jz EXIT ; doesn't support CPUID instruction
  68. ;
  69. ; get vendor information using CPUID eax == 0
  70. xor eax, eax
  71. cpuid
  72. ; store the vendor tag (12 bytes in ebx, edx, ecx) in the first parameter,
  73. ; which should be a char[13]
  74. push eax ; save eax
  75. mov eax, [ebp+8] ; store the char* address in eax
  76. mov [eax], ebx ; move ebx into the first 4 bytes
  77. add eax, 4 ; advance the char* 4 bytes
  78. mov [eax], edx ; move edx into the next 4 bytes
  79. add eax, 4 ; advance the char* 4 bytes
  80. mov [eax], ecx ; move ecx into the last 4 bytes
  81. pop eax ; restore eax
  82. ; get generic extended CPUID info
  83. mov eax, 1
  84. cpuid ; eax=1, so cpuid queries feature information
  85. and eax, 0x0fff3fff
  86. push ecx
  87. mov ecx, [ebp+12]
  88. mov [ecx], eax ; just store the model bits in processor param
  89. mov ecx, [ebp+16]
  90. mov [ecx], edx ; set properties param
  91. pop ecx
  92. ; want to check for 3DNow(tm).
  93. ; need to see if extended cpuid functions present.
  94. mov eax, 0x80000000
  95. cpuid
  96. cmp eax, 0x80000000
  97. jbe MAYBE_3DLATER
  98. mov eax, 0x80000001
  99. cpuid
  100. ; 3DNow if bit 31 set -> put bit in our properties
  101. and edx, 0x80000000
  102. push eax
  103. mov eax, [ebp+16]
  104. or [eax], edx
  105. pop eax
  106. MAYBE_3DLATER:
  107. EXIT:
  108. popfd
  109. pop ecx
  110. pop edx
  111. popreg
  112. pop ebp
  113. ret