]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm
OvmfPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / OvmfPkg / Library / LoadLinuxLib / X64 / JumpToKernel.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
4 ;
5 ; SPDX-License-Identifier: BSD-2-Clause-Patent
6 ;
7 ;------------------------------------------------------------------------------
8
9 DEFAULT REL
10 SECTION .text
11
12 ;------------------------------------------------------------------------------
13 ; VOID
14 ; EFIAPI
15 ; JumpToKernel (
16 ; VOID *KernelStart, // rcx
17 ; VOID *KernelBootParams // rdx
18 ; );
19 ;------------------------------------------------------------------------------
20 global ASM_PFX(JumpToKernel)
21 ASM_PFX(JumpToKernel):
22
23 ; Set up for executing kernel. BP in %esi, entry point on the stack
24 ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)
25 mov rsi, rdx
26 push rcx
27
28 ; Jump into the compatibility mode CS
29 push 0x10
30 lea rax, [.0]
31 push rax
32 DB 0x48, 0xcb ; retfq
33
34 .0:
35 ; Now in compatibility mode.
36
37 DB 0xb8, 0x18, 0x0, 0x0, 0x0 ; movl $0x18, %eax
38 DB 0x8e, 0xd8 ; movl %eax, %ds
39 DB 0x8e, 0xc0 ; movl %eax, %es
40 DB 0x8e, 0xe0 ; movl %eax, %fs
41 DB 0x8e, 0xe8 ; movl %eax, %gs
42 DB 0x8e, 0xd0 ; movl %eax, %ss
43
44 ; Disable paging
45 DB 0xf, 0x20, 0xc0 ; movl %cr0, %eax
46 DB 0xf, 0xba, 0xf8, 0x1f ; btcl $31, %eax
47 DB 0xf, 0x22, 0xc0 ; movl %eax, %cr0
48
49 ; Disable long mode in EFER
50 DB 0xb9, 0x80, 0x0, 0x0, 0xc0 ; movl $0x0c0000080, %ecx
51 DB 0xf, 0x32 ; rdmsr
52 DB 0xf, 0xba, 0xf8, 0x8 ; btcl $8, %eax
53 DB 0xf, 0x30 ; wrmsr
54
55 ; Disable PAE
56 DB 0xf, 0x20, 0xe0 ; movl %cr4, %eax
57 DB 0xf, 0xba, 0xf8, 0x5 ; btcl $5, %eax
58 DB 0xf, 0x22, 0xe0 ; movl %eax, %cr4
59
60 DB 0x31, 0xed ; xor %ebp, %ebp
61 DB 0x31, 0xff ; xor %edi, %edi
62 DB 0x31, 0xdb ; xor %ebx, %ebx
63 DB 0xc3 ; ret
64
65 ;------------------------------------------------------------------------------
66 ; VOID
67 ; EFIAPI
68 ; JumpToUefiKernel (
69 ; EFI_HANDLE ImageHandle, // rcx
70 ; EFI_SYSTEM_TABLE *SystemTable, // rdx
71 ; VOID *KernelBootParams // r8
72 ; VOID *KernelStart, // r9
73 ; );
74 ;------------------------------------------------------------------------------
75 global ASM_PFX(JumpToUefiKernel)
76 ASM_PFX(JumpToUefiKernel):
77
78 mov rdi, rcx
79 mov rsi, rdx
80 mov rdx, r8
81 xor rax, rax
82 mov eax, [r8 + 0x264]
83 add r9, rax
84 add r9, 0x200
85 call r9
86 ret
87