verify_cpu_64.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. *
  3. * verify_cpu.S - Code for cpu long mode and SSE verification. This
  4. * code has been borrowed from boot/setup.S and was introduced by
  5. * Andi Kleen.
  6. *
  7. * Copyright (c) 2007 Andi Kleen (ak@suse.de)
  8. * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
  9. * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
  10. *
  11. * This source code is licensed under the GNU General Public License,
  12. * Version 2. See the file COPYING for more details.
  13. *
  14. * This is a common code for verification whether CPU supports
  15. * long mode and SSE or not. It is not called directly instead this
  16. * file is included at various places and compiled in that context.
  17. * Following are the current usage.
  18. *
  19. * This file is included by both 16bit and 32bit code.
  20. *
  21. * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
  22. * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
  23. * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
  24. * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
  25. *
  26. * verify_cpu, returns the status of cpu check in register %eax.
  27. * 0: Success 1: Failure
  28. *
  29. * The caller needs to check for the error code and take the action
  30. * appropriately. Either display a message or halt.
  31. */
  32. #include <asm/cpufeature.h>
  33. verify_cpu:
  34. pushfl # Save caller passed flags
  35. pushl $0 # Kill any dangerous flags
  36. popfl
  37. pushfl # standard way to check for cpuid
  38. popl %eax
  39. movl %eax,%ebx
  40. xorl $0x200000,%eax
  41. pushl %eax
  42. popfl
  43. pushfl
  44. popl %eax
  45. cmpl %eax,%ebx
  46. jz verify_cpu_no_longmode # cpu has no cpuid
  47. movl $0x0,%eax # See if cpuid 1 is implemented
  48. cpuid
  49. cmpl $0x1,%eax
  50. jb verify_cpu_no_longmode # no cpuid 1
  51. xor %di,%di
  52. cmpl $0x68747541,%ebx # AuthenticAMD
  53. jnz verify_cpu_noamd
  54. cmpl $0x69746e65,%edx
  55. jnz verify_cpu_noamd
  56. cmpl $0x444d4163,%ecx
  57. jnz verify_cpu_noamd
  58. mov $1,%di # cpu is from AMD
  59. verify_cpu_noamd:
  60. movl $0x1,%eax # Does the cpu have what it takes
  61. cpuid
  62. andl $REQUIRED_MASK0,%edx
  63. xorl $REQUIRED_MASK0,%edx
  64. jnz verify_cpu_no_longmode
  65. movl $0x80000000,%eax # See if extended cpuid is implemented
  66. cpuid
  67. cmpl $0x80000001,%eax
  68. jb verify_cpu_no_longmode # no extended cpuid
  69. movl $0x80000001,%eax # Does the cpu have what it takes
  70. cpuid
  71. andl $REQUIRED_MASK1,%edx
  72. xorl $REQUIRED_MASK1,%edx
  73. jnz verify_cpu_no_longmode
  74. verify_cpu_sse_test:
  75. movl $1,%eax
  76. cpuid
  77. andl $SSE_MASK,%edx
  78. cmpl $SSE_MASK,%edx
  79. je verify_cpu_sse_ok
  80. test %di,%di
  81. jz verify_cpu_no_longmode # only try to force SSE on AMD
  82. movl $0xc0010015,%ecx # HWCR
  83. rdmsr
  84. btr $15,%eax # enable SSE
  85. wrmsr
  86. xor %di,%di # don't loop
  87. jmp verify_cpu_sse_test # try again
  88. verify_cpu_no_longmode:
  89. popfl # Restore caller passed flags
  90. movl $1,%eax
  91. ret
  92. verify_cpu_sse_ok:
  93. popfl # Restore caller passed flags
  94. xorl %eax, %eax
  95. ret