-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode-switch.asm
More file actions
72 lines (56 loc) · 1.18 KB
/
Copy pathmode-switch.asm
File metadata and controls
72 lines (56 loc) · 1.18 KB
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
[BITS 32]
global kReadCPUID, kSwitchAndExecute64bitKernel
SECTION .text
; params: DWORD dwEAXx, DWORD* pdwEAXx, pdwEAX, pdwECX, pdwEDX
kReadCPUID:
push ebp
mov ebp, esp
push eax
push ebx
push ecx
push edx
push esi
mov eax, dword [ebp + 8]
cpuid
; *pdwEAX
mov esi, dword [ebp + 12]
mov dword [esi], eax
; *pdwEBX
mov esi, dword [ebp + 16]
mov dword [esi], ebx
; *pdwECX
mov esi, dword [ebp + 20]
mov dword [esi], ecx
; *pdwEDX
mov esi, dword [ebp + 24]
mov dword [esi], edx
pop esi
pop edx
pop ecx
pop ebx
pop eax
pop ebp
ret
; no params
kSwitchAndExecute64bitKernel:
; set 1 in cr4 PAE bit
mov eax, cr4
or eax, 0x20
mov cr4, eax
; activate cr3 PML4 table and caching
mov eax, 0x100000
mov cr3, eax
; set 1 in IA32_EFER.LME bit for activate IA-32e mode
mov ecx, 0xC0000080
rdmsr
or eax, 0x0100
wrmsr
; set 0 in NW bit and CD bit, set 1 in PG bit at cr0
mov eax, cr0
or eax, 0xE0000000
xor eax, 0x60000000
mov cr0, eax
; jump to kernel cs selector
jmp 0x08:0x200000
; this code is not executed
jmp $