]> git.proxmox.com Git - grub2.git/blob - grub-core/lib/i386/relocator32.S
Import grub2_2.02+dfsg1.orig.tar.xz
[grub2.git] / grub-core / lib / i386 / relocator32.S
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009,2010 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /* The code segment of the protected mode. */
20 #define CODE_SEGMENT 0x10
21
22 /* The data segment of the protected mode. */
23 #define DATA_SEGMENT 0x18
24
25 #include "relocator_common.S"
26
27 .p2align 4 /* force 16-byte alignment */
28
29 VARIABLE(grub_relocator32_start)
30 PREAMBLE
31
32 RELOAD_GDT
33 .code32
34 /* Update other registers. */
35 movl $DATA_SEGMENT, %eax
36 movl %eax, %ds
37 movl %eax, %es
38 movl %eax, %fs
39 movl %eax, %gs
40 movl %eax, %ss
41
42 DISABLE_PAGING
43
44 #ifdef __x86_64__
45 /* Disable amd64. */
46 movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
47 rdmsr
48 andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
49 wrmsr
50 #endif
51
52 /* Turn off PAE. */
53 movl %cr4, %eax
54 andl $(~GRUB_MEMORY_CPU_CR4_PAE_ON), %eax
55 movl %eax, %cr4
56
57 jmp LOCAL(cont2)
58 LOCAL(cont2):
59 .code32
60
61 /* mov imm32, %eax */
62 .byte 0xb8
63 VARIABLE(grub_relocator32_esp)
64 .long 0
65
66 movl %eax, %esp
67
68 /* mov imm32, %eax */
69 .byte 0xb8
70 VARIABLE(grub_relocator32_ebp)
71 .long 0
72
73 movl %eax, %ebp
74
75 /* mov imm32, %eax */
76 .byte 0xb8
77 VARIABLE(grub_relocator32_esi)
78 .long 0
79
80 movl %eax, %esi
81
82 /* mov imm32, %eax */
83 .byte 0xb8
84 VARIABLE(grub_relocator32_edi)
85 .long 0
86
87 movl %eax, %edi
88
89 /* mov imm32, %eax */
90 .byte 0xb8
91 VARIABLE(grub_relocator32_eax)
92 .long 0
93
94 /* mov imm32, %ebx */
95 .byte 0xbb
96 VARIABLE(grub_relocator32_ebx)
97 .long 0
98
99 /* mov imm32, %ecx */
100 .byte 0xb9
101 VARIABLE(grub_relocator32_ecx)
102 .long 0
103
104 /* mov imm32, %edx */
105 .byte 0xba
106 VARIABLE(grub_relocator32_edx)
107 .long 0
108
109 /* Cleared direction flag is of no problem with any current
110 payload and makes this implementation easier. */
111 cld
112
113 .byte 0xea
114 VARIABLE(grub_relocator32_eip)
115 .long 0
116 .word CODE_SEGMENT
117
118 /* GDT. Copied from loader/i386/linux.c. */
119 .p2align 4
120 LOCAL(gdt):
121 /* NULL. */
122 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
123
124 /* Reserved. */
125 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
126
127 /* Code segment. */
128 .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
129
130 /* Data segment. */
131 .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
132 LOCAL(gdt_end):
133
134 VARIABLE(grub_relocator32_end)