2 * relocate_kernel.S - put the kernel image in place to boot
3 * Copyright (C) 2002-2005 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>
10 #include <asm/page_types.h>
11 #include <asm/kexec.h>
12 #include <asm/processor-flags.h>
13 #include <asm/pgtable_types.h>
16 * Must be relocatable PIC code callable as a C function
19 #define PTR(x) (x << 3)
20 #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
25 .globl relocate_kernel
27 /* %rdi indirection_page
32 /* zero out flags, and disable interrupts */
36 /* get physical address of control page now */
37 /* this is impossible after page table switch */
38 movq PTR(PA_CONTROL_PAGE)(%rsi), %r8
40 /* get physical address of page table now too */
41 movq PTR(PA_TABLE_PAGE)(%rsi), %rcx
43 /* Switch to the identity mapped page tables */
46 /* setup a new stack at the end of the physical control page */
47 lea PAGE_SIZE(%r8), %rsp
49 /* jump to identity mapped page */
50 addq $(identity_mapped - relocate_kernel), %r8
55 /* store the start address on the stack */
58 /* Set cr0 to a known state:
60 * - Alignment check disabled
61 * - Write protect disabled
63 * - Don't do FP software emulation.
64 * - Proctected mode enabled
67 andq $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %rax
68 orl $(X86_CR0_PG | X86_CR0_PE), %eax
71 /* Set cr4 to a known state:
72 * - physical address extension enabled
74 movq $X86_CR4_PAE, %rax
80 /* Flush the TLB (needed?) */
84 movq %rdi, %rcx /* Put the page_list in %rcx */
89 0: /* top, read another word for the indirection page */
94 testq $0x1, %rcx /* is it a destination page? */
97 andq $0xfffffffffffff000, %rdi
100 testq $0x2, %rcx /* is it an indirection page? */
103 andq $0xfffffffffffff000, %rbx
106 testq $0x4, %rcx /* is it the done indicator? */
110 testq $0x8, %rcx /* is it the source indicator? */
111 jz 0b /* Ignore it otherwise */
112 movq %rcx, %rsi /* For ever source page do a copy */
113 andq $0xfffffffffffff000, %rsi
120 /* To be certain of avoiding problems with self-modifying code
121 * I need to execute a serializing instruction here.
122 * So I flush the TLB by reloading %cr3 here, it's handy,
123 * and not processor dependent.
128 /* set all of the registers to known values */
129 /* leave %rsp alone */