2 * relocate_kernel.S - put the kernel image in place to boot
3 * Copyright (C) 2002-2004 Eric Biederman <ebiederm@xmission.com>
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
9 #include <linux/linkage.h>
11 #include <asm/kexec.h>
12 #include <asm/processor-flags.h>
13 #include <asm/pgtable.h>
16 * Must be relocatable PIC code callable as a C function
19 #define PTR(x) (x << 2)
20 #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
21 #define PAE_PGD_ATTR (_PAGE_PRESENT)
25 .globl relocate_kernel
27 movl 8(%esp), %ebp /* list of pages */
30 /* map the control page at its virtual address */
32 movl PTR(VA_PGD)(%ebp), %edi
33 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
34 andl $0xc0000000, %eax
38 movl PTR(PA_PMD_0)(%ebp), %edx
39 orl $PAE_PGD_ATTR, %edx
42 movl PTR(VA_PMD_0)(%ebp), %edi
43 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
44 andl $0x3fe00000, %eax
48 movl PTR(PA_PTE_0)(%ebp), %edx
52 movl PTR(VA_PTE_0)(%ebp), %edi
53 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
54 andl $0x001ff000, %eax
58 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
62 /* identity map the control page at its physical address */
64 movl PTR(VA_PGD)(%ebp), %edi
65 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
66 andl $0xc0000000, %eax
70 movl PTR(PA_PMD_1)(%ebp), %edx
71 orl $PAE_PGD_ATTR, %edx
74 movl PTR(VA_PMD_1)(%ebp), %edi
75 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
76 andl $0x3fe00000, %eax
80 movl PTR(PA_PTE_1)(%ebp), %edx
84 movl PTR(VA_PTE_1)(%ebp), %edi
85 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
86 andl $0x001ff000, %eax
90 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
94 /* map the control page at its virtual address */
96 movl PTR(VA_PGD)(%ebp), %edi
97 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
98 andl $0xffc00000, %eax
102 movl PTR(PA_PTE_0)(%ebp), %edx
106 movl PTR(VA_PTE_0)(%ebp), %edi
107 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
108 andl $0x003ff000, %eax
112 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
116 /* identity map the control page at its physical address */
118 movl PTR(VA_PGD)(%ebp), %edi
119 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
120 andl $0xffc00000, %eax
124 movl PTR(PA_PTE_1)(%ebp), %edx
128 movl PTR(VA_PTE_1)(%ebp), %edi
129 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
130 andl $0x003ff000, %eax
134 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
140 /* read the arguments and say goodbye to the stack */
141 movl 4(%esp), %ebx /* page_list */
142 movl 8(%esp), %ebp /* list of pages */
143 movl 12(%esp), %edx /* start address */
144 movl 16(%esp), %ecx /* cpu_has_pae */
146 /* zero out flags, and disable interrupts */
150 /* get physical address of control page now */
151 /* this is impossible after page table switch */
152 movl PTR(PA_CONTROL_PAGE)(%ebp), %edi
154 /* switch to new set of page tables */
155 movl PTR(PA_PGD)(%ebp), %eax
158 /* setup a new stack at the end of the physical control page */
159 lea PAGE_SIZE(%edi), %esp
161 /* jump to identity mapped page */
163 addl $(identity_mapped - relocate_kernel), %eax
168 /* store the start address on the stack */
171 /* Set cr0 to a known state:
173 * - Alignment check disabled
174 * - Write protect disabled
176 * - Don't do FP software emulation.
177 * - Proctected mode enabled
180 andl $~(X86_CR0_PG | X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
181 orl $(X86_CR0_PE), %eax
184 /* clear cr4 if applicable */
187 /* Set cr4 to a known state:
188 * Setting everything to zero seems safe.
196 /* Flush the TLB (needed?) */
204 0: /* top, read another word from the indirection page */
208 testl $0x1, %ecx /* is it a destination page */
211 andl $0xfffff000, %edi
214 testl $0x2, %ecx /* is it an indirection page */
217 andl $0xfffff000, %ebx
220 testl $0x4, %ecx /* is it the done indicator */
224 testl $0x8, %ecx /* is it the source indicator */
225 jz 0b /* Ignore it otherwise */
226 movl %ecx, %esi /* For every source page do a copy */
227 andl $0xfffff000, %esi
235 /* To be certain of avoiding problems with self-modifying code
236 * I need to execute a serializing instruction here.
237 * So I flush the TLB, it's handy, and not processor dependent.
242 /* set all of the registers to known values */
243 /* leave %esp alone */