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