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 #* Cpu.asm 27 #* 28 #* Abstract: 29 #* 30 #------------------------------------------------------------------------------ 31 ##include <EfiBind.h> 32 33 .globl ASM_PFX(EfiHalt) 34 .globl ASM_PFX(EfiWbinvd) 35 .globl ASM_PFX(EfiInvd) 36 .globl ASM_PFX(EfiCpuid) 37 .globl ASM_PFX(EfiReadTsc) 38 .globl ASM_PFX(EfiDisableCache) 39 .globl ASM_PFX(EfiEnableCache) 40 .globl ASM_PFX(EfiReadMsr) 41 .globl ASM_PFX(EfiWriteMsr) 42 .globl ASM_PFX(EfiGetEflags) 43 .globl ASM_PFX(EfiDisableInterrupts) 44 .globl ASM_PFX(EfiEnableInterrupts) 45 .globl ASM_PFX(EfiCpuidExt) 46 47 .text 48 49 50 #------------------------------------------------------------------------------ 51 # VOID 52 # EfiHalt ( 53 # VOID 54 # ) 55 #------------------------------------------------------------------------------ 56 ASM_PFX(EfiHalt): 57 hlt 58 retq 59 60 61 #------------------------------------------------------------------------------ 62 # VOID 63 # EfiWbinvd ( 64 # VOID 65 # ) 66 #------------------------------------------------------------------------------ 67 ASM_PFX(EfiWbinvd): 68 wbinvd 69 retq 70 71 72 #------------------------------------------------------------------------------ 73 # VOID 74 # EfiInvd ( 75 # VOID 76 # ) 77 #------------------------------------------------------------------------------ 78 ASM_PFX(EfiInvd): 79 invd 80 retq 81 82 #------------------------------------------------------------------------------ 83 # VOID 84 # EfiCpuid ( 85 # IN UINT32 RegisterInEax, // rcx 86 # OUT EFI_CPUID_REGISTER *Reg OPTIONAL // rdx 87 # ) 88 #------------------------------------------------------------------------------ 89 ASM_PFX(EfiCpuid): 90 push %rbx 91 mov %rdx,%r8 92 mov %rcx,%rax 93 cpuid 94 cmp $0x0,%r8 95 je _Exit 96 mov %eax,(%r8) 97 mov %ebx,0x4(%r8) 98 mov %ecx,0x8(%r8) 99 mov %edx,0xc(%r8) 100 _Exit: 101 pop %rbx 102 retq 103 104 #------------------------------------------------------------------------------ 105 # UINT64 106 # EfiReadMsr ( 107 # IN UINT32 Index, // rcx 108 # ) 109 #------------------------------------------------------------------------------ 110 ASM_PFX(EfiReadMsr): 111 rdmsr 112 shl $0x20,%rdx 113 or %rdx,%rax 114 retq 115 116 #------------------------------------------------------------------------------ 117 # VOID 118 # EfiWriteMsr ( 119 # IN UINT32 Index, // rcx 120 # IN UINT64 Value // rdx 121 # ) 122 #------------------------------------------------------------------------------ 123 ASM_PFX(EfiWriteMsr): 124 mov %rdx,%rax 125 sar $0x20,%rdx 126 wrmsr 127 retq 128 129 #------------------------------------------------------------------------------ 130 # UINT64 131 # EfiReadTsc ( 132 # VOID 133 # ); 134 #------------------------------------------------------------------------------ 135 ASM_PFX(EfiReadTsc): 136 rdtsc 137 shl $0x20,%rax 138 shrd $0x20,%rdx,%rax 139 retq 140 141 #------------------------------------------------------------------------------ 142 # VOID 143 # EfiDisableCache ( 144 # VOID 145 # ); 146 #------------------------------------------------------------------------------ 147 ASM_PFX(EfiDisableCache): 148 # added a check to see if cache is already disabled. If it is, then skip. 149 mov %cr0,%rax 150 and $0x60000000,%rax 151 cmp $0x0,%rax 152 jne 1f 153 mov %cr0,%rax 154 or $0x60000000,%rax 155 mov %rax,%cr0 156 wbinvd 157 1: 158 retq 159 160 #------------------------------------------------------------------------------ 161 # VOID 162 # EfiEnableCache ( 163 # VOID 164 # ); 165 #------------------------------------------------------------------------------ 166 ASM_PFX(EfiEnableCache): 167 wbinvd 168 mov %cr0,%rax 169 and $0xffffffff9fffffff,%rax 170 mov %rax,%cr0 171 retq 172 173 #------------------------------------------------------------------------------ 174 # UINTN 175 # EfiGetEflags ( 176 # VOID 177 # ); 178 #------------------------------------------------------------------------------ 179 ASM_PFX(EfiGetEflags): 180 pushfq 181 pop %rax 182 retq 183 184 #------------------------------------------------------------------------------ 185 # VOID 186 # EfiDisableInterrupts ( 187 # VOID 188 # ); 189 #------------------------------------------------------------------------------ 190 ASM_PFX(EfiDisableInterrupts): 191 cli 192 ret 193 194 #------------------------------------------------------------------------------ 195 # VOID 196 # EfiEnableInterrupts ( 197 # VOID 198 # ); 199 #------------------------------------------------------------------------------ 200 ASM_PFX(EfiEnableInterrupts): 201 sti 202 ret 203 #------------------------------------------------------------------------------ 204 # VOID 205 # EfiCpuidExt ( 206 # IN UINT32 RegisterInEax, 207 # IN UINT32 CacheLevel, 208 # OUT EFI_CPUID_REGISTER *Regs 209 # ) 210 #------------------------------------------------------------------------------ 211 ASM_PFX(EfiCpuidExt): 212 push %rbx 213 mov %rcx,%rax 214 mov %rdx,%rcx 215 cpuid 216 mov %eax,(%r8) 217 mov %ebx,0x4(%r8) 218 mov %ecx,0x8(%r8) 219 mov %edx,0xc(%r8) 220 pop %rbx 221 retq 222