2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
19
#include <grub/symbol.h>
20
#include <grub/i386/memory.h>
23
#define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_backward_ ## x)
25
#define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_forward_ ## x)
39
/* The code segment of the protected mode. */
40
#define CODE_SEGMENT 0x10
42
/* The data segment of the protected mode. */
43
#define DATA_SEGMENT 0x18
45
.p2align 4 /* force 16-byte alignment */
47
RELOCATOR_VARIABLE(start)
56
RELOCATOR_VARIABLE(dest)
62
RELOCATOR_VARIABLE(src)
68
RELOCATOR_VARIABLE(size)
75
RELOCATOR_VARIABLE(dest)
82
RELOCATOR_VARIABLE(src)
89
RELOCATOR_VARIABLE(size)
109
/* Backward movsl is implicitly off-by-four. compensate that. */
126
/* %rax contains now our new 'base'. */
128
add $(LOCAL(cont0) - LOCAL(base)), RAX
131
lea (LOCAL(cont1) - LOCAL(base)) (RSI, 1), RAX
132
movl %eax, (LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
134
lea (LOCAL(gdt) - LOCAL(base)) (RSI, 1), RAX
135
mov RAX, (LOCAL(gdt_addr) - LOCAL(base)) (RSI, 1)
137
/* Switch to compatibility mode. */
139
lgdt (LOCAL(gdtdesc) - LOCAL(base)) (RSI, 1)
142
ljmp *(LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
147
/* Update other registers. */
148
movl $DATA_SEGMENT, %eax
155
/* Disable paging. */
157
andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
161
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
163
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
168
andl $GRUB_MEMORY_CPU_CR4_PAE_ON, %eax
175
/* mov imm32, %eax */
177
RELOCATOR_VARIABLE (esp)
182
/* mov imm32, %eax */
184
RELOCATOR_VARIABLE (eax)
187
/* mov imm32, %ebx */
189
RELOCATOR_VARIABLE (ebx)
192
/* mov imm32, %ecx */
194
RELOCATOR_VARIABLE (ecx)
197
/* mov imm32, %edx */
199
RELOCATOR_VARIABLE (edx)
202
/* Cleared direction flag is of no problem with any current
203
payload and makes this implementation easier. */
207
RELOCATOR_VARIABLE (eip)
211
/* GDT. Copied from loader/i386/linux.c. */
215
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
218
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
221
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
224
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
231
/* Filled by the code. */
234
/* Filled by the code. */
240
/* Jump location. Is filled by the code */
248
RELOCATOR_VARIABLE(end)