1 #------------------------------------------------------------------------------ 2 #* 3 #* Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR> 4 #* This program and the accompanying materials 5 #* are licensed and made available under the terms and conditions of the BSD License 6 #* which accompanies this distribution. The full text of the license may be found at 7 #* http://opensource.org/licenses/bsd-license.php 8 #* 9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 #* 12 #* Module Name: 13 #* 14 #* Cpu.asm 15 #* 16 #* Abstract: 17 #* 18 #------------------------------------------------------------------------------ 19 #include <EfiBind.h> 20 21 .globl ASM_PFX(EfiHalt) 22 .globl ASM_PFX(EfiWbinvd) 23 .globl ASM_PFX(EfiInvd) 24 .globl ASM_PFX(EfiCpuid) 25 .globl ASM_PFX(EfiReadTsc) 26 .globl ASM_PFX(EfiDisableCache) 27 .globl ASM_PFX(EfiEnableCache) 28 .globl ASM_PFX(EfiReadMsr) 29 .globl ASM_PFX(EfiWriteMsr) 30 .globl ASM_PFX(EfiGetEflags) 31 .globl ASM_PFX(EfiDisableInterrupts) 32 .globl ASM_PFX(EfiEnableInterrupts) 33 .globl ASM_PFX(EfiCpuidExt) 34 35 .text 36 37 38 #------------------------------------------------------------------------------ 39 # VOID 40 # EfiHalt ( 41 # VOID 42 # ) 43 #------------------------------------------------------------------------------ 44 ASM_PFX(EfiHalt): 45 hlt 46 retq 47 48 49 #------------------------------------------------------------------------------ 50 # VOID 51 # EfiWbinvd ( 52 # VOID 53 # ) 54 #------------------------------------------------------------------------------ 55 ASM_PFX(EfiWbinvd): 56 wbinvd 57 retq 58 59 60 #------------------------------------------------------------------------------ 61 # VOID 62 # EfiInvd ( 63 # VOID 64 # ) 65 #------------------------------------------------------------------------------ 66 ASM_PFX(EfiInvd): 67 invd 68 retq 69 70 #------------------------------------------------------------------------------ 71 # VOID 72 # EfiCpuid ( 73 # IN UINT32 RegisterInEax, // rcx 74 # OUT EFI_CPUID_REGISTER *Reg OPTIONAL // rdx 75 # ) 76 #------------------------------------------------------------------------------ 77 ASM_PFX(EfiCpuid): 78 push %rbx 79 mov %rdx,%r8 80 mov %rcx,%rax 81 cpuid 82 cmp $0x0,%r8 83 je _Exit 84 mov %eax,(%r8) 85 mov %ebx,0x4(%r8) 86 mov %ecx,0x8(%r8) 87 mov %edx,0xc(%r8) 88 _Exit: 89 pop %rbx 90 retq 91 92 #------------------------------------------------------------------------------ 93 # UINT64 94 # EfiReadMsr ( 95 # IN UINT32 Index, // rcx 96 # ) 97 #------------------------------------------------------------------------------ 98 ASM_PFX(EfiReadMsr): 99 rdmsr 100 shl $0x20,%rdx 101 or %rdx,%rax 102 retq 103 104 #------------------------------------------------------------------------------ 105 # VOID 106 # EfiWriteMsr ( 107 # IN UINT32 Index, // rcx 108 # IN UINT64 Value // rdx 109 # ) 110 #------------------------------------------------------------------------------ 111 ASM_PFX(EfiWriteMsr): 112 mov %rdx,%rax 113 sar $0x20,%rdx 114 wrmsr 115 retq 116 117 #------------------------------------------------------------------------------ 118 # UINT64 119 # EfiReadTsc ( 120 # VOID 121 # ); 122 #------------------------------------------------------------------------------ 123 ASM_PFX(EfiReadTsc): 124 rdtsc 125 shl $0x20,%rax 126 shrd $0x20,%rdx,%rax 127 retq 128 129 #------------------------------------------------------------------------------ 130 # VOID 131 # EfiDisableCache ( 132 # VOID 133 # ); 134 #------------------------------------------------------------------------------ 135 ASM_PFX(EfiDisableCache): 136 # added a check to see if cache is already disabled. If it is, then skip. 137 mov %cr0,%rax 138 and $0x60000000,%rax 139 cmp $0x0,%rax 140 jne 1f 141 mov %cr0,%rax 142 or $0x60000000,%rax 143 mov %rax,%cr0 144 wbinvd 145 1: 146 retq 147 148 #------------------------------------------------------------------------------ 149 # VOID 150 # EfiEnableCache ( 151 # VOID 152 # ); 153 #------------------------------------------------------------------------------ 154 ASM_PFX(EfiEnableCache): 155 wbinvd 156 mov %cr0,%rax 157 and $0xffffffff9fffffff,%rax 158 mov %rax,%cr0 159 retq 160 161 #------------------------------------------------------------------------------ 162 # UINTN 163 # EfiGetEflags ( 164 # VOID 165 # ); 166 #------------------------------------------------------------------------------ 167 ASM_PFX(EfiGetEflags): 168 pushfq 169 pop %rax 170 retq 171 172 #------------------------------------------------------------------------------ 173 # VOID 174 # EfiDisableInterrupts ( 175 # VOID 176 # ); 177 #------------------------------------------------------------------------------ 178 ASM_PFX(EfiDisableInterrupts): 179 cli 180 ret 181 182 #------------------------------------------------------------------------------ 183 # VOID 184 # EfiEnableInterrupts ( 185 # VOID 186 # ); 187 #------------------------------------------------------------------------------ 188 ASM_PFX(EfiEnableInterrupts): 189 sti 190 ret 191 #------------------------------------------------------------------------------ 192 # VOID 193 # EfiCpuidExt ( 194 # IN UINT32 RegisterInEax, 195 # IN UINT32 CacheLevel, 196 # OUT EFI_CPUID_REGISTER *Regs 197 # ) 198 #------------------------------------------------------------------------------ 199 ASM_PFX(EfiCpuidExt): 200 push %rbx 201 mov %rcx,%rax 202 mov %rdx,%rcx 203 cpuid 204 mov %eax,(%r8) 205 mov %ebx,0x4(%r8) 206 mov %ecx,0x8(%r8) 207 mov %edx,0xc(%r8) 208 pop %rbx 209 retq 210