CpuIA32.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #
  2. #
  3. # Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
  4. #
  5. # SPDX-License-Identifier: BSD-2-Clause-Patent
  6. #
  7. #
  8. #
  9. #Module Name:
  10. #
  11. # CpuIA32.c
  12. #
  13. #Abstract:
  14. #
  15. #--*/
  16. ##include "CpuIA32.h"
  17. #include "EfiBind.h"
  18. #---------------------------------------------------------------------------
  19. .586p:
  20. #.MODEL flat,C
  21. .code:
  22. #---------------------------------------------------------------------------
  23. .globl ASM_PFX(EfiHalt)
  24. .globl ASM_PFX(EfiWbinvd)
  25. .globl ASM_PFX(EfiInvd)
  26. .globl ASM_PFX(EfiCpuid)
  27. .globl ASM_PFX(EfiReadMsr)
  28. .globl ASM_PFX(EfiWriteMsr)
  29. .globl ASM_PFX(EfiReadTsc)
  30. .globl ASM_PFX(EfiDisableCache)
  31. .globl ASM_PFX(EfiEnableCache)
  32. .globl ASM_PFX(EfiGetEflags)
  33. .globl ASM_PFX(EfiDisableInterrupts)
  34. .globl ASM_PFX(EfiEnableInterrupts)
  35. .globl ASM_PFX(EfiCpuidExt)
  36. #VOID
  37. #EfiHalt (
  38. # VOID
  39. #)
  40. ASM_PFX(EfiHalt):
  41. hlt
  42. ret
  43. #EfiHalt ENDP
  44. #VOID
  45. #EfiWbinvd (
  46. # VOID
  47. #)
  48. ASM_PFX(EfiWbinvd):
  49. wbinvd
  50. ret
  51. #EfiWbinvd ENDP
  52. #VOID
  53. #EfiInvd (
  54. # VOID
  55. #)
  56. ASM_PFX(EfiInvd):
  57. invd
  58. ret
  59. #EfiInvd ENDP
  60. #VOID
  61. #EfiCpuid (IN UINT32 RegisterInEax,
  62. # OUT EFI_CPUID_REGISTER *Reg OPTIONAL)
  63. ASM_PFX(EfiCpuid):
  64. pushl %ebp
  65. movl %esp, %ebp
  66. pushl %ebx
  67. pushl %esi
  68. pushl %edi
  69. pushal
  70. movl 8(%ebp), %eax #RegisterInEax
  71. cpuid
  72. cmpl $0, 0xC(%ebp) # Reg
  73. je L1
  74. movl 0xC(%ebp), %edi # Reg
  75. movl %eax, (%edi) # Reg->RegEax
  76. movl %ebx, 4(%edi) # Reg->RegEbx
  77. movl %ecx, 8(%edi) # Reg->RegEcx
  78. movl %edx, 0xC(%edi) # Reg->RegEdx
  79. L1:
  80. popal
  81. popl %edi
  82. popl %esi
  83. popl %ebx
  84. popl %ebp
  85. ret
  86. #EfiCpuid ENDP
  87. #UINT64
  88. #EfiReadMsr (
  89. # IN UINT32 Index
  90. # );
  91. ASM_PFX(EfiReadMsr):
  92. movl 4(%esp), %ecx # Index
  93. rdmsr
  94. ret
  95. #EfiReadMsr ENDP
  96. #VOID
  97. #EfiWriteMsr (
  98. # IN UINT32 Index,
  99. # IN UINT64 Value
  100. # );
  101. ASM_PFX(EfiWriteMsr):
  102. movl 4(%esp), %ecx # Index
  103. movl 8(%esp), %eax # DWORD PTR Value[0]
  104. movl 0xC(%esp), %edx # DWORD PTR Value[4]
  105. wrmsr
  106. ret
  107. #EfiWriteMsr ENDP
  108. #UINT64
  109. #EfiReadTsc (
  110. # VOID
  111. # )
  112. ASM_PFX(EfiReadTsc):
  113. rdtsc
  114. ret
  115. #EfiReadTsc ENDP
  116. #VOID
  117. #EfiDisableCache (
  118. # VOID
  119. #)
  120. ASM_PFX(EfiDisableCache):
  121. movl %cr0, %eax
  122. bswapl %eax
  123. andb $0x60, %al
  124. cmpb $0x60, %al
  125. je L2
  126. movl %cr0, %eax
  127. orl $0x60000000, %eax
  128. movl %eax, %cr0
  129. wbinvd
  130. L2:
  131. ret
  132. #EfiDisableCache ENDP
  133. #VOID
  134. #EfiEnableCache (
  135. # VOID
  136. # )
  137. ASM_PFX(EfiEnableCache):
  138. wbinvd
  139. movl %cr0, %eax
  140. andl $0x9fffffff, %eax
  141. movl %eax, %cr0
  142. ret
  143. #EfiEnableCache ENDP
  144. #UINT32
  145. #EfiGetEflags (
  146. # VOID
  147. # )
  148. ASM_PFX(EfiGetEflags):
  149. pushfl
  150. popl %eax
  151. ret
  152. #EfiGetEflags ENDP
  153. #VOID
  154. #EfiDisableInterrupts (
  155. # VOID
  156. # )
  157. ASM_PFX(EfiDisableInterrupts):
  158. cli
  159. ret
  160. #EfiDisableInterrupts ENDP
  161. #VOID
  162. #EfiEnableInterrupts (
  163. # VOID
  164. # )
  165. ASM_PFX(EfiEnableInterrupts):
  166. sti
  167. ret
  168. #EfiEnableInterrupts ENDP
  169. #VOID
  170. #EfiCpuidExt (
  171. # IN UINT32 RegisterInEax,
  172. # IN UINT32 CacheLevel,
  173. # OUT EFI_CPUID_REGISTER *Regs
  174. # )
  175. ASM_PFX(EfiCpuidExt):
  176. push %ebx
  177. push %edi
  178. push %esi
  179. pushal
  180. movl 0x30(%esp), %eax # RegisterInEax
  181. movl 0x34(%esp), %ecx # CacheLevel
  182. cpuid
  183. movl 0x38(%esp), %edi # DWORD PTR Regs
  184. movl %eax, (%edi) # Reg->RegEax
  185. movl %ebx, 4(%edi) # Reg->RegEbx
  186. movl %ecx, 8(%edi) # Reg->RegEcx
  187. movl %edx, 0xC(%edi) # Reg->RegEdx
  188. popal
  189. pop %esi
  190. pop %edi
  191. pop %ebx
  192. ret
  193. #EfiCpuidExt ENDP