CpuIA32.asm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. ;
  2. ; This file contains an 'Intel Sample Driver' and is
  3. ; licensed for Intel CPUs and chipsets under the terms of your
  4. ; license agreement with Intel or your vendor. This file may
  5. ; be modified by the user, subject to additional terms of the
  6. ; license agreement
  7. ;
  8. ;
  9. ; Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
  10. ;
  11. ; SPDX-License-Identifier: BSD-2-Clause-Patent
  12. ;
  13. ;
  14. ;Module Name:
  15. ;
  16. ; CpuIA32.c
  17. ;
  18. ;Abstract:
  19. ;
  20. ;--*/
  21. ;#include "CpuIA32.h"
  22. ;---------------------------------------------------------------------------
  23. .586p
  24. .model flat,C
  25. .code
  26. ;---------------------------------------------------------------------------
  27. ;VOID
  28. ;EfiHalt (
  29. ; VOID
  30. ;)
  31. EfiHalt PROC C PUBLIC
  32. hlt
  33. ret
  34. EfiHalt ENDP
  35. ;VOID
  36. ;EfiWbinvd (
  37. ; VOID
  38. ;)
  39. EfiWbinvd PROC C PUBLIC
  40. wbinvd
  41. ret
  42. EfiWbinvd ENDP
  43. ;VOID
  44. ;EfiInvd (
  45. ; VOID
  46. ;)
  47. EfiInvd PROC C PUBLIC
  48. invd
  49. ret
  50. EfiInvd ENDP
  51. ;VOID
  52. ;EfiCpuid (IN UINT32 RegisterInEax,
  53. ; OUT EFI_CPUID_REGISTER *Reg OPTIONAL)
  54. EfiCpuid PROC C PUBLIC
  55. push ebp
  56. mov ebp, esp
  57. push ebx
  58. push esi
  59. push edi
  60. pushad
  61. mov eax, dword ptr[ebp + 8] ;egisterInEax
  62. cpuid
  63. cmp dword ptr[ebp + 0Ch], 0 ; Reg
  64. je @F
  65. mov edi,dword ptr [ebp+0Ch] ; Reg
  66. mov dword ptr [edi],eax ; Reg->RegEax
  67. mov dword ptr [edi+4],ebx ; Reg->RegEbx
  68. mov dword ptr [edi+8],ecx ; Reg->RegEcx
  69. mov dword ptr [edi+0Ch],edx ; Reg->RegEdx
  70. @@:
  71. popad
  72. pop edi
  73. pop esi
  74. pop ebx
  75. pop ebp
  76. ret
  77. EfiCpuid ENDP
  78. ;UINT64
  79. ;EfiReadMsr (
  80. ; IN UINT32 Index
  81. ; );
  82. EfiReadMsr PROC C PUBLIC
  83. mov ecx, dword ptr [esp + 4]; Index
  84. rdmsr
  85. ret
  86. EfiReadMsr ENDP
  87. ;VOID
  88. ;EfiWriteMsr (
  89. ; IN UINT32 Index,
  90. ; IN UINT64 Value
  91. ; );
  92. EfiWriteMsr PROC C PUBLIC
  93. mov ecx, dword ptr [esp+4]; Index
  94. mov eax, dword ptr [esp+8]; DWORD PTR Value[0]
  95. mov edx, dword ptr [esp+0Ch]; DWORD PTR Value[4]
  96. wrmsr
  97. ret
  98. EfiWriteMsr ENDP
  99. ;UINT64
  100. ;EfiReadTsc (
  101. ; VOID
  102. ; )
  103. EfiReadTsc PROC C PUBLIC
  104. rdtsc
  105. ret
  106. EfiReadTsc ENDP
  107. ;VOID
  108. ;EfiDisableCache (
  109. ; VOID
  110. ;)
  111. EfiDisableCache PROC C PUBLIC
  112. mov eax, cr0
  113. bswap eax
  114. and al, 60h
  115. cmp al, 60h
  116. je @F
  117. mov eax, cr0
  118. or eax, 060000000h
  119. mov cr0, eax
  120. wbinvd
  121. @@:
  122. ret
  123. EfiDisableCache ENDP
  124. ;VOID
  125. ;EfiEnableCache (
  126. ; VOID
  127. ; )
  128. EfiEnableCache PROC C PUBLIC
  129. wbinvd
  130. mov eax, cr0
  131. and eax, 09fffffffh
  132. mov cr0, eax
  133. ret
  134. EfiEnableCache ENDP
  135. ;UINT32
  136. ;EfiGetEflags (
  137. ; VOID
  138. ; )
  139. EfiGetEflags PROC C PUBLIC
  140. pushfd
  141. pop eax
  142. ret
  143. EfiGetEflags ENDP
  144. ;VOID
  145. ;EfiDisableInterrupts (
  146. ; VOID
  147. ; )
  148. EfiDisableInterrupts PROC C PUBLIC
  149. cli
  150. ret
  151. EfiDisableInterrupts ENDP
  152. ;VOID
  153. ;EfiEnableInterrupts (
  154. ; VOID
  155. ; )
  156. EfiEnableInterrupts PROC C PUBLIC
  157. sti
  158. ret
  159. EfiEnableInterrupts ENDP
  160. ;VOID
  161. ;EfiCpuidExt (
  162. ; IN UINT32 RegisterInEax,
  163. ; IN UINT32 CacheLevel,
  164. ; OUT EFI_CPUID_REGISTER *Regs
  165. ; )
  166. EfiCpuidExt PROC C PUBLIC USES ebx edi esi
  167. pushad
  168. mov eax, dword ptr [esp + 30h] ; RegisterInEax
  169. mov ecx, dword ptr [esp + 34h] ; CacheLevel
  170. cpuid
  171. mov edi, dword ptr [esp + 38h] ; DWORD PTR Regs
  172. mov dword ptr [edi], eax ; Reg->RegEax
  173. mov dword ptr [edi + 4], ebx ; Reg->RegEbx
  174. mov dword ptr [edi + 8], ecx ; Reg->RegEcx
  175. mov dword ptr [edi + 0Ch], edx ; Reg->RegEdx
  176. popad
  177. ret
  178. EfiCpuidExt ENDP
  179. END