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
|
;*************************************************************************
;*************************************************************************
;** **
;** (C)Copyright 1985-2012, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;*************************************************************************
;*************************************************************************
;*************************************************************************
; $Header: /Alaska/SOURCE/Core/Modules/IA32Core/IA32AsmLib/EnableLongMode.asm 2 8/06/12 2:43p Markw $
;
; $Revision: 2 $
;
; $Date: 8/06/12 2:43p $Log:$
;
;
;*************************************************************************
;<AMI_FHDR_START>
;
; Name:
;
; Description:
;
;<AMI_FHDR_END>
;*************************************************************************
.686p
.xmm
.model flat
.code
;*************************************************************************
;<AMI_PHDR_START>
;
; Name: EnableLongMode
;
; Description:
; VOID EnableLongMode(IN VOID *PageTable, IN VOID *Function,
; IN VOID *Parameter1, IN VOID *Parameter2) enables long mode then calls the
; provided function with the provided parameters.
;
; Input:
; IN VOID *PageTable
; Pointer to level 4 page map.
;
; IN VOID *Function
; Pointer to function to call.
;
; IN VOID *Parameter1
; Parameter 1 for above function call.
;
; IN VOID *Parameter2
; Parameter 2 for above function call.
;
; Output:
; VOID.
;
; Modified:
;
; Referrals:
;
; Notes:
;
;<AMI_PHDR_END>
;*************************************************************************
EnableLongMode proc C public PageTable:DWORD, Function:DWORD, Parameter1:DWORD, Parameter2:DWORD
mov eax, PageTable
mov cr3, eax ;Set CR3 to first page directory pointer table
mov eax, cr4
or ax, 620h ;Enable PAE and XMM in case it was turned off.
mov cr4, eax
;Enable long mode in msr register. Doesn't actually enter long mode yet.
mov ecx, 0c0000080h
rdmsr
bts eax, 8
wrmsr
;Enable paging
mov eax, cr0
bts eax, 31
mov cr0, eax ;Now in long mode compatiblity.
jmp @f
@@:
;jmp far segment:offset
db 67h, 0eah
dd offset long_mode_64
dw 38h ;SYS_CODE64_SEL
long_mode_64:
;in 64-bit long mode
db 48h
xor eax, eax ;xor rax, rax
db 48h
xor ebx, ebx ;xor rbx, rbx
db 48h
xor ecx, ecx ;xor rcx, rcx
db 48h
xor edx, edx ;xor rdx, rdx
mov ecx, Parameter1
mov edx, Parameter2
mov ebx, Function
mov ax, 30h ;SYS_DATA64_SEL
mov ds, ax
mov es, ax
mov ss, ax
push 37fh
fldcw word ptr [esp] ;Uses rsp. Set FP control word according UEFI
db 48h
add esp, 8 ;add rsp, 8
mov eax, 0fffffff0h
db 48h
and esp, eax ;rsp must be on a 16 byte boundary. C compiler expects that.
call ebx ;call rbx
ret
EnableLongMode endp
END
;*************************************************************************
;*************************************************************************
;** **
;** (C)Copyright 1985-2012, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;*************************************************************************
;*************************************************************************
|