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>
15 * Must be relocatable PIC code callable as a C function
18 #define PTR(x) (x << 2)
19 #define PAGE_ATTR 0x63 /* _PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY */
20 #define PAE_PGD_ATTR 0x01 /* _PAGE_PRESENT */
24 .globl relocate_kernel
26 movl 8(%esp), %ebp /* list of pages */
29 /* map the control page at its virtual address */
31 movl PTR(VA_PGD)(%ebp), %edi
32 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
33 andl $0xc0000000, %eax
37 movl PTR(PA_PMD_0)(%ebp), %edx
38 orl $PAE_PGD_ATTR, %edx
41 movl PTR(VA_PMD_0)(%ebp), %edi
42 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
43 andl $0x3fe00000, %eax
47 movl PTR(PA_PTE_0)(%ebp), %edx
51 movl PTR(VA_PTE_0)(%ebp), %edi
52 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
53 andl $0x001ff000, %eax
57 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
61 /* identity map the control page at its physical address */
63 movl PTR(VA_PGD)(%ebp), %edi
64 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
65 andl $0xc0000000, %eax
69 movl PTR(PA_PMD_1)(%ebp), %edx
70 orl $PAE_PGD_ATTR, %edx
73 movl PTR(VA_PMD_1)(%ebp), %edi
74 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
75 andl $0x3fe00000, %eax
79 movl PTR(PA_PTE_1)(%ebp), %edx
83 movl PTR(VA_PTE_1)(%ebp), %edi
84 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
85 andl $0x001ff000, %eax
89 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
93 /* map the control page at its virtual address */
95 movl PTR(VA_PGD)(%ebp), %edi
96 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
97 andl $0xffc00000, %eax
101 movl PTR(PA_PTE_0)(%ebp), %edx
105 movl PTR(VA_PTE_0)(%ebp), %edi
106 movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
107 andl $0x003ff000, %eax
111 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
115 /* identity map the control page at its physical address */
117 movl PTR(VA_PGD)(%ebp), %edi
118 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
119 andl $0xffc00000, %eax
123 movl PTR(PA_PTE_1)(%ebp), %edx
127 movl PTR(VA_PTE_1)(%ebp), %edi
128 movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
129 andl $0x003ff000, %eax
133 movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
139 /* read the arguments and say goodbye to the stack */
140 movl 4(%esp), %ebx /* page_list */
141 movl 8(%esp), %ebp /* list of pages */
142 movl 12(%esp), %edx /* start address */
143 movl 16(%esp), %ecx /* cpu_has_pae */
145 /* zero out flags, and disable interrupts */
149 /* get physical address of control page now */
150 /* this is impossible after page table switch */
151 movl PTR(PA_CONTROL_PAGE)(%ebp), %edi
153 /* switch to new set of page tables */
154 movl PTR(PA_PGD)(%ebp), %eax
157 /* setup a new stack at the end of the physical control page */
158 lea PAGE_SIZE(%edi), %esp
160 /* jump to identity mapped page */
162 addl $(identity_mapped - relocate_kernel), %eax
167 /* store the start address on the stack */
170 /* Set cr0 to a known state:
172 * - Alignment check disabled
173 * - Write protect disabled
175 * - Don't do FP software emulation.
176 * - Proctected mode enabled
179 andl $~(X86_CR0_PG | X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
180 orl $(X86_CR0_PE), %eax
183 /* clear cr4 if applicable */
186 /* Set cr4 to a known state:
187 * Setting everything to zero seems safe.
195 /* Flush the TLB (needed?) */
203 0: /* top, read another word from the indirection page */
207 testl $0x1, %ecx /* is it a destination page */
210 andl $0xfffff000, %edi
213 testl $0x2, %ecx /* is it an indirection page */
216 andl $0xfffff000, %ebx
219 testl $0x4, %ecx /* is it the done indicator */
223 testl $0x8, %ecx /* is it the source indicator */
224 jz 0b /* Ignore it otherwise */
225 movl %ecx, %esi /* For every source page do a copy */
226 andl $0xfffff000, %esi
234 /* To be certain of avoiding problems with self-modifying code
235 * I need to execute a serializing instruction here.
236 * So I flush the TLB, it's handy, and not processor dependent.
241 /* set all of the registers to known values */
242 /* leave %esp alone */