Home | History | Annotate | Download | only in IA32
      1 #
      2 #
      3 # Copyright (c)  1999  - 2014, Intel Corporation. All rights reserved
      4 #
      5 # This program and the accompanying materials are licensed and made available under
      7 # the terms and conditions of the BSD License that accompanies this distribution.
      9 # The full text of the license may be found at
     11 # http://opensource.org/licenses/bsd-license.php.
     13 #
     15 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     17 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     19 #
     21 #
     23 #
     24 #Module Name:
     25 #
     26 #  CpuIA32.c
     27 #
     28 #Abstract:
     29 #
     30 #--*/
     31 
     32 ##include "CpuIA32.h"
     33 #include "EfiBind.h"
     34 
     35 #---------------------------------------------------------------------------
     36     .586p:
     37     #.MODEL flat,C
     38     .code:
     39 
     40 #---------------------------------------------------------------------------
     41 
     42 .globl ASM_PFX(EfiHalt)
     43 .globl ASM_PFX(EfiWbinvd)
     44 .globl ASM_PFX(EfiInvd)
     45 .globl ASM_PFX(EfiCpuid)
     46 .globl ASM_PFX(EfiReadMsr)
     47 .globl ASM_PFX(EfiWriteMsr)
     48 .globl ASM_PFX(EfiReadTsc)
     49 .globl ASM_PFX(EfiDisableCache)
     50 .globl ASM_PFX(EfiEnableCache)
     51 .globl ASM_PFX(EfiGetEflags)
     52 .globl ASM_PFX(EfiDisableInterrupts)
     53 .globl ASM_PFX(EfiEnableInterrupts)
     54 .globl ASM_PFX(EfiCpuidExt)
     55 
     56 
     57 #VOID
     58 #EfiHalt (
     59 #  VOID
     60 #)
     61 ASM_PFX(EfiHalt):
     62     hlt
     63     ret
     64 #EfiHalt ENDP
     65 
     66 #VOID
     67 #EfiWbinvd (
     68 #  VOID
     69 #)
     70 ASM_PFX(EfiWbinvd):
     71     wbinvd
     72     ret
     73 #EfiWbinvd ENDP
     74 
     75 #VOID
     76 #EfiInvd (
     77 # VOID
     78 #)
     79 ASM_PFX(EfiInvd):
     80     invd
     81     ret
     82 #EfiInvd ENDP
     83 
     84 #VOID
     85 #EfiCpuid (IN UINT32 RegisterInEax,
     86 #          OUT EFI_CPUID_REGISTER *Reg OPTIONAL)
     87 ASM_PFX(EfiCpuid):
     88     pushl %ebp
     89     movl %esp, %ebp
     90     pushl %ebx
     91     pushl %esi
     92     pushl %edi
     93     pushal
     94 
     95     movl   8(%ebp), %eax           #RegisterInEax
     96     cpuid
     97     cmpl   $0, 0xC(%ebp)           # Reg
     98     je     L1
     99     movl        0xC(%ebp), %edi         # Reg
    100 
    101     movl        %eax, (%edi)        # Reg->RegEax
    102     movl        %ebx, 4(%edi)         # Reg->RegEbx
    103     movl        %ecx, 8(%edi)         # Reg->RegEcx
    104     movl        %edx, 0xC(%edi)         # Reg->RegEdx
    105 
    106 L1:
    107     popal
    108     popl        %edi
    109     popl        %esi
    110     popl        %ebx
    111     popl        %ebp
    112 
    113     ret
    114 #EfiCpuid ENDP
    115 
    116 
    117 #UINT64
    118 #EfiReadMsr (
    119 #  IN UINT32 Index
    120 #  );
    121 ASM_PFX(EfiReadMsr):
    122     movl   4(%esp), %ecx           # Index
    123     rdmsr
    124     ret
    125 #EfiReadMsr ENDP
    126 
    127 #VOID
    128 #EfiWriteMsr (
    129 #  IN   UINT32  Index,
    130 #  IN   UINT64  Value
    131 #  );
    132 ASM_PFX(EfiWriteMsr):
    133     movl   4(%esp), %ecx         # Index
    134     movl   8(%esp), %eax         # DWORD PTR Value[0]
    135     movl   0xC(%esp), %edx         # DWORD PTR Value[4]
    136     wrmsr
    137     ret
    138 #EfiWriteMsr ENDP
    139 
    140 #UINT64
    141 #EfiReadTsc (
    142 #  VOID
    143 #  )
    144 ASM_PFX(EfiReadTsc):
    145     rdtsc
    146     ret
    147 #EfiReadTsc ENDP
    148 
    149 #VOID
    150 #EfiDisableCache (
    151 #  VOID
    152 #)
    153 ASM_PFX(EfiDisableCache):
    154     movl  %cr0, %eax
    155     bswapl %eax
    156     andb  $0x60, %al
    157     cmpb  $0x60, %al
    158     je    L2
    159     movl  %cr0, %eax
    160     orl   $0x60000000, %eax
    161     movl  %eax, %cr0
    162     wbinvd
    163 L2:
    164     ret
    165 #EfiDisableCache ENDP
    166 
    167 #VOID
    168 #EfiEnableCache (
    169 #  VOID
    170 #  )
    171 ASM_PFX(EfiEnableCache):
    172     wbinvd
    173     movl  %cr0, %eax
    174     andl  $0x9fffffff, %eax
    175     movl  %eax, %cr0
    176     ret
    177 #EfiEnableCache ENDP
    178 
    179 #UINT32
    180 #EfiGetEflags (
    181 #  VOID
    182 #  )
    183 ASM_PFX(EfiGetEflags):
    184     pushfl
    185     popl %eax
    186     ret
    187 #EfiGetEflags ENDP
    188 
    189 #VOID
    190 #EfiDisableInterrupts (
    191 #  VOID
    192 #  )
    193 ASM_PFX(EfiDisableInterrupts):
    194     cli
    195     ret
    196 #EfiDisableInterrupts ENDP
    197 
    198 #VOID
    199 #EfiEnableInterrupts (
    200 #  VOID
    201 #  )
    202 ASM_PFX(EfiEnableInterrupts):
    203     sti
    204     ret
    205 #EfiEnableInterrupts ENDP
    206 
    207 #VOID
    208 #EfiCpuidExt (
    209 #  IN   UINT32              RegisterInEax,
    210 #  IN   UINT32              CacheLevel,
    211 #  OUT  EFI_CPUID_REGISTER  *Regs
    212 #  )
    213 ASM_PFX(EfiCpuidExt):
    214     push   %ebx
    215     push   %edi
    216     push   %esi
    217     pushal
    218 
    219     movl   0x30(%esp), %eax           # RegisterInEax
    220     movl   0x34(%esp), %ecx           # CacheLevel
    221     cpuid
    222     movl   0x38(%esp), %edi           # DWORD PTR Regs
    223 
    224     movl   %eax, (%edi)                 # Reg->RegEax
    225     movl   %ebx, 4(%edi)                # Reg->RegEbx
    226     movl   %ecx, 8(%edi)                # Reg->RegEcx
    227     movl   %edx, 0xC(%edi)              # Reg->RegEdx
    228 
    229     popal
    230     pop    %esi
    231     pop    %edi
    232     pop    %ebx
    233     ret
    234 #EfiCpuidExt ENDP
    235 
    236 
    237 
    238